Previous 15994 Revisions Next

r9073 Wednesday 8th September, 2010 at 22:22:26 UTC by MooglyGuy
[ACAN] Improved mosaic behavior. Improved layer 2 behavior via a hack; possibly not actually a hack. Implemented per-line ROZ priority. Implemented sprite X scaling. Fixed sprite tile flipping.
[src/mess/drivers]supracan.c

src/mess/drivers/supracan.c
r9072r9073
170170    INT32 roz_changed;
171171    INT32 roz_cx;
172172    INT32 roz_cy;
173    UINT16 unk_1d0;
173174
174175   UINT16 video_regs[256];
175176
r9072r9073
203204
204205static VIDEO_START( supracan )
205206{
206    // crash debug: printf("A"); fflush(stdout);
207207    supracan_state *state = machine->driver_data<supracan_state>();
208208    state->roz_bitmap = auto_bitmap_alloc(machine, 1024, 1024, BITMAP_FORMAT_INDEXED16);
209209    state->roz_final_bitmap = auto_bitmap_alloc(machine, 320, 240, BITMAP_FORMAT_INDEXED16);
r9072r9073
218218
219219static UINT16 fetch_8bpp_tile_pixel(running_machine *machine, int tile, int palette, bool xflip, bool yflip, int x, int y)
220220{
221    // crash debug: printf("B"); fflush(stdout);
222221    supracan_state *state = machine->driver_data<supracan_state>();
223222    UINT16 *supracan_vram = state->vram;
224223
r9072r9073
233232
234233static UINT16 fetch_4bpp_tile_pixel(running_machine *machine, int tile, int palette, bool xflip, bool yflip, int x, int y)
235234{
236    // crash debug: printf("C"); fflush(stdout);
237235    supracan_state *state = machine->driver_data<supracan_state>();
238236    UINT16 *supracan_vram = state->vram;
239237
r9072r9073
248246
249247static UINT16 fetch_2bpp_tile_pixel(running_machine *machine, int tile, int palette, bool xflip, bool yflip, int x, int y)
250248{
251    // crash debug: printf("D"); fflush(stdout);
252249    supracan_state *state = machine->driver_data<supracan_state>();
253250    UINT16 *supracan_vram = state->vram;
254251
r9072r9073
258255    UINT32 address = (tile * 8 * 2 + y * 2 + (x >> 2)) >> 1;
259256    UINT8 shift = (7 - (x & 7)) * 2;
260257
261    return (palette << 2) | ((supracan_vram[address] >> shift) & 0x0003);
258    return (palette << 4) | ((supracan_vram[address] >> shift) & 0x0003);
262259}
263260
264static void draw_tile(running_machine *machine, UINT8* primap, bitmap_t *bitmap, const rectangle *cliprect, int tile, int palette, bool xflip, bool yflip, int x, int y, int priority, int depth, int mask)
261static void draw_tile(running_machine *machine, UINT8* primap, bitmap_t *bitmap, const rectangle *cliprect, int tile, int palette, bool xflip, bool yflip, int x, int y, int priority, int depth, int mask, int xprioffset = 0, int yprioffset = 0, UINT32 xwrap = 0, UINT32 ywrap = 0)
265262{
266    // crash debug: printf("E"); fflush(stdout);
267263    for(int tiley = 0; tiley < 8; tiley++)
268264    {
269265        for(int tilex = 0; tilex < 8; tilex++)
r9072r9073
295291
296292            int total_x = x + tilex;
297293            int total_y = y + tiley;
294            if(xwrap)
295            {
296            while(total_x < 0) total_x += xwrap;
297            while(total_x >= xwrap) total_x -= xwrap;
298         }
299            if(ywrap)
300            {
301            while(total_y < 0) total_y += ywrap;
302            while(total_y >= ywrap) total_y -= ywrap;
303         }
298304            if((cliprect != NULL && total_x >= cliprect->min_x && total_y >= cliprect->min_y && total_x < cliprect->max_x && total_y < cliprect->max_y) || cliprect == NULL)
299305            {
300306                if(pixel)
r9072r9073
303309                    {
304310                        case 0: // Default
305311                            *BITMAP_ADDR16(bitmap, total_y, total_x) = pixel;
306                            primap[total_y*1024 + total_x] = (UINT8)priority;
312                            primap[(total_y + yprioffset)*1024 + total_x + xprioffset] = (UINT8)priority;
307313                            break;
308314                        case 1: // Mask against previous alpha
309315                            if(*BITMAP_ADDR16(bitmap, total_y, total_x) & 0x8000)
310316                            {
311317                                *BITMAP_ADDR16(bitmap, total_y, total_x) = pixel | 0x8000;
312                                primap[total_y*1024 + total_x] = (UINT8)priority;
318                                primap[(total_y + yprioffset)*1024 + total_x + xprioffset] = (UINT8)priority;
313319                            }
314320                            break;
315321                        case 2: // Write to alpha
r9072r9073
335341    {
336342        for(int x = 0; x < 320; x++)
337343        {
338            priline[x] = 8;
344            priline[x] = 9;
339345            scanline[x] = 0;
340346        }
341347        return;
r9072r9073
383389            for(int x = 0; x < 320; x++)
384390            {
385391                scanline[x] = 0;
386                priline[x] = 8;
392                priline[x] = 9;
387393            }
388394            return;
389395        }
390396    }
391397
392    int mosaic = (state->tilemap_flags[layer] & 0x001c) >> 2;
393    UINT32 mask = 0xffffffff;
398    int mosaic_count = (state->tilemap_flags[layer] & 0x001c) >> 2;
399    int mosaic_mask = 0xffffffff << mosaic_count;
394400
395    if(mosaic)
396    {
397        mosaic--;
398        mask = ~(1 << mosaic);
399    }
401    UINT16 *src = BITMAP_ADDR16(state->tilemap_bitmap[layer], wrapped_y & mosaic_mask, 0);
402    UINT8 *srcpri = &state->tilemap_pri[layer][1024*(wrapped_y & mosaic_mask)];
400403
401    UINT16 *src = BITMAP_ADDR16(state->tilemap_bitmap[layer], wrapped_y & mask, 0);
402    UINT8 *srcpri = &state->tilemap_pri[layer][1024*(wrapped_y & mask)];
403
404404    if(state->tilemap_flags[layer] & 0x20)
405405    {
406406        while(wrapped_x >= width*8) wrapped_x -= width*8;
r9072r9073
408408
409409        for(int x = 0; x < 320; x++)
410410        {
411            scanline[x] = src[wrapped_x & mask] ? src[wrapped_x & mask] : scanline[x];
412            priline[x] = src[wrapped_x & mask] ? srcpri[wrapped_x & mask] : 8;
411            scanline[x] = src[wrapped_x & mosaic_mask] ? src[wrapped_x & mosaic_mask] : scanline[x];
412            priline[x] = src[wrapped_x & mosaic_mask] ? srcpri[wrapped_x & mosaic_mask] : 9;
413413            wrapped_x++;
414414            while(wrapped_x >= width*8) wrapped_x -= width*8;
415415        }
r9072r9073
420420        {
421421            if(wrapped_x >= 0 && wrapped_x < width*8)
422422            {
423                scanline[x] = src[wrapped_x & mask] ? src[wrapped_x & mask] : scanline[x];
424                priline[x] = src[wrapped_x & mask] ? srcpri[wrapped_x & mask] : 8;
423                scanline[x] = src[wrapped_x & mosaic_mask] ? src[wrapped_x & mosaic_mask] : scanline[x];
424                priline[x] = src[wrapped_x & mosaic_mask] ? srcpri[wrapped_x & mosaic_mask] : 9;
425425            }
426426            else
427427            {
428428                scanline[x] = scanline[x];
429                priline[x] = 8;
429                priline[x] = 9;
430430            }
431431            wrapped_x++;
432432        }
r9072r9073
465465            break;
466466   }
467467
468    UINT8 priority = ((state->tilemap_flags[layer] >> 12) & 7) + 1;
468    UINT8 priority = ((state->tilemap_flags[layer] >> 13) & 7) + 1;
469469
470470    int scrollx = state->tilemap_scrollx[layer];
471471    int scrolly = state->tilemap_scrolly[layer];
r9072r9073
510510
511511    if(layer == 2)
512512    {
513        region = 1;
514        tile_bank = 0x400;
515        palette_bank = 0x00;
513        region = 2;
514        tile_bank = 0x1000;
516515    }
517516
518517    if(state->tilemap_flags[layer] & 0x20)
r9072r9073
524523            for(int x = 0; x < xsize; x++)
525524            {
526525                int tile = (supracan_vram[count] & 0x03ff) + tile_bank;
527                int flipx = (supracan_vram[count] & 0x0800) ? 1 : 0;
528                int flipy = (supracan_vram[count] & 0x0400) ? 1 : 0;
526                bool flipx = (supracan_vram[count] & 0x0800) ? true : false;
527                bool flipy = (supracan_vram[count] & 0x0400) ? true : false;
529528                int palette = ((supracan_vram[count] & 0xf000) >> 12) + palette_bank;
530529
531530                draw_tile(machine, state->tilemap_pri[layer], bitmap, NULL, tile, palette, flipx, flipy, x*8, y*8, priority, region, 0);
r9072r9073
543542            for(int x = 0; x < xsize; x++)
544543            {
545544                int tile = (supracan_vram[count] & 0x03ff) + tile_bank;
546                int flipx = (supracan_vram[count] & 0x0800) ? 1 : 0;
547                int flipy = (supracan_vram[count] & 0x0400) ? 1 : 0;
545                bool flipx = (supracan_vram[count] & 0x0800) ? true : false;
546                bool flipy = (supracan_vram[count] & 0x0400) ? true : false;
548547                int palette = ((supracan_vram[count] & 0xf000) >> 12) + palette_bank;
549548
550549                draw_tile(machine, state->tilemap_pri[layer], bitmap, cliprect, tile, palette, flipx, flipy, x*8/*-scrollx*/, y*8/*-scrolly*/, priority, region, 0);
r9072r9073
557556
558557static void draw_roz_bitmap_scanline(running_machine *machine, bitmap_t *roz_bitmap, UINT16 *scanline, UINT8 *priline, int ypos, INT32 X, INT32 Y, INT32 PA, INT32 PB, INT32 PC, INT32 PD, INT32 *currentx, INT32 *currenty, int changed)
559558{
560    // crash debug: printf("G"); fflush(stdout);
561559    supracan_state *state = machine->driver_data<supracan_state>();
562
560    //UINT16 *supracan_vram = state->vram;
561    //UINT16 roztbl0 = supracan_vram[(state->roz_unk_base0 >> 1) + ypos];
562   //UINT32 roztbl1 = supracan_vram[(state->roz_unk_base1 >> 1) + ypos*2] << 16;
563    //       roztbl1 |= supracan_vram[(state->roz_unk_base1 >> 1) + ypos*2 + 1];
564   //UINT32 roztbl2 = supracan_vram[(state->roz_unk_base2 >> 1) + ypos*2] << 16;
565    //       roztbl2 |= supracan_vram[(state->roz_unk_base2 >> 1) + ypos*2 + 1];
563566    INT32 sx = 0;
564567    INT32 sy = 0;
565568
569    //if(state->roz_mode & 0x20 && (roztbl0 == 0 && roztbl1 == 0 && roztbl2 == 0))
570    {
571        //return;
572    }
573
566574    switch(state->roz_mode & 0x0f00)
567575    {
568576        case 0x600: sx = 64*8; sy = 32*8; break;
r9072r9073
586594
587595    // re-assign parameters for convenience's sake
588596    INT32 dx = PA;
589    INT32 dmx = PB;
597    INT32 dmx = PB;//roztbl1;
590598    INT32 dy = PC;
591    INT32 dmy = PD;
599    INT32 dmy = PD;//roztbl2;
592600    INT32 startx = X;
593601    INT32 starty = Y;
594602
r9072r9073
618626    INT32 rx = *currentx;
619627    INT32 ry = *currenty;
620628
629   //printf("%08x\n", ry);
621630    INT32 pixx = rx >> 8;
622631    INT32 pixy = ry >> 8;
623632
r9072r9073
631640            while(pixy >= sy) pixy -= sy;
632641
633642            scanline[x] = *BITMAP_ADDR16(roz_bitmap, pixy, pixx);
634            priline[x] = state->roz_pri[pixy*1024 + pixx];
643            priline[x] = ((state->roz_mode >> 13) & 7) + 1;
635644        }
636645        else
637646        {
638647            if(pixx >= 0 && pixy >= 0 && pixx < sx && pixy < sy)
639648            {
640649                scanline[x] = *BITMAP_ADDR16(roz_bitmap, pixy, pixx);
641                priline[x] = state->roz_pri[pixy*1024 + pixx];
650                priline[x] = ((state->roz_mode >> 13) & 7) + 1;
642651            }
643652        }
644653
r9072r9073
654663
655664static void draw_roz_bitmap(running_machine *machine, const rectangle *cliprect)
656665{
657    // crash debug: printf("H"); fflush(stdout);
658666    supracan_state *state = machine->driver_data<supracan_state>();
659667    UINT16 *supracan_vram = state->vram;
660668    UINT32 addr = state->roz_tile_bank << 1;
r9072r9073
675683            if(bit)
676684            {
677685                *BITMAP_ADDR16(roz_bitmap, y, x) = bit;
678                state->roz_pri[y*1024 + x] = (state->roz_mode >> 12) & 7;
686                state->roz_pri[y*1024 + x] = ((state->roz_mode >> 13) & 7) + 1;
679687            }
680688        }
681689        for (int x = 0; x < 32; x++)
r9072r9073
684692            if(bit)
685693            {
686694                *BITMAP_ADDR16(roz_bitmap, y, x+32) = bit;
687                state->roz_pri[y*1024 + x + 32] = (state->roz_mode >> 12) & 7;
695                state->roz_pri[y*1024 + x + 32] = ((state->roz_mode >> 13) & 7) + 1;
688696            }
689697        }
690698    }
r9072r9073
692700
693701static void draw_roz(running_machine *machine, const rectangle *cliprect)
694702{
695    // crash debug: printf("I"); fflush(stdout);
696703    supracan_state *state = machine->driver_data<supracan_state>();
697704    UINT16 *supracan_vram = state->vram;
698705    UINT32 roz_base_addr = state->roz_base_addr;
r9072r9073
746753    }
747754
748755    UINT32 count = 0;
749    UINT8 priority = ((state->roz_mode >> 12) & 7) + 1;
756    UINT8 priority = ((state->roz_mode >> 13) & 7) + 1;
750757
751758    bitmap_t *roz_bitmap = state->roz_bitmap;
752759    for (int y = 0; y < ysize; y++)
r9072r9073
765772    }
766773}
767774
775#define DRAW_DEBUG_SPRITE_PRI \
776   tile = 0; xflip = false; yflip = false; palette = 0; \
777   for(int ypix = 0; ypix < 8; ypix++) \
778      for(int xpix = 0; xpix < 8; xpix++) \
779         if((y + ytile*8 + ypix) < 240 && (y + ytile*8 + ypix) >= 0 && \
780            (x + xtile*8 + xpix) < 320 && (x + xtile*8 + xpix) >= 0) \
781            *BITMAP_ADDR16(bitmap, y + ytile*8 + ypix, x + xtile*8 + xpix) = supracan_vram[i+2] >> 9;
782
768783static void draw_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect)
769784{
770    // crash debug: printf("J"); fflush(stdout);
771785    supracan_state *state = machine->driver_data<supracan_state>();
772786   UINT16 *supracan_vram = state->vram;
773787
r9072r9073
776790#endif
777791
778792//      [0]
779//      ---h hhh- ---- ---- Y size
780//      ---- ---y yyyy yyyy Y offset
793//      ---h hhh- ---- ---- Y size (not always right)
794//      ---- ---y yyyy yyyy Y position
781795//      [1]
782//      bbbb ---- ---- ---- sprite offset bank
783//      ---- h--- ---- ---- horizontal flip
784//      ---- -v-- ---- ---- vertical flip
785//      ---- --mm ---- ---- masking
796//      bbbb ---- ---- ---- Tile bank
797//      ---- h--- ---- ---- Horizontal flip
798//      ---- -v-- ---- ---- Vertical flip
799//      ---- --mm ---- ---- Masking mode
786800//      ---- ---- ---- -www X size
787801//      [2]
788//      zzz- uuu- ---- ---- unknown
789//      ---- ---x xxxx xxxx X offset
802//      zzzz ---- ---- ---- X scale
803//      ---- ---x xxxx xxxx X position
790804//      [3]
791//      oooo oooo oooo oooo sprite pointer
805//      oooo oooo oooo oooo Sprite address
792806
793    UINT32 start_word = (state->sprite_base_addr >> 1) + 0 * 4;
794    UINT32 end_word = start_word + state->sprite_count * 4;
807   UINT32 skip_count = 0;
808    UINT32 start_word = (state->sprite_base_addr >> 1) + skip_count * 4;
809    UINT32 end_word = start_word + (state->sprite_count - skip_count) * 4;
795810    for(int i = start_word; i < end_word; i += 4)
796811   {
797812      int x = supracan_vram[i+2] & 0x01ff;
r9072r9073
801816        int mask = (supracan_vram[i+1] & 0x0300) >> 8;
802817      bool hflip = (supracan_vram[i+1] & 0x0800) ? true : false;
803818      bool vflip = (supracan_vram[i+1] & 0x0400) ? true : false;
819        int xscale = (supracan_vram[i+2] & 0xf000) >> 12;
804820#if !(DRAW_DEBUG_UNK_SPRITE)
805        UINT8 priority = ((supracan_vram[i+2] >> 12) & 7) + 1;
821        UINT8 priority = ((supracan_vram[i+0] >> 13) & 7) + 1;
806822#endif
807      while(x > 0x200)
808        {
809            x -= 0x200;
810        }
811823
812      while(y > 0x200)
813        {
814            y -= 0x200;
815        }
824      while(x >= 0x200) x -= 0x200;
825      while(y >= 0x200) y -= 0x200;
816826
817827      if(supracan_vram[i+3] != 0)
818828      {
819829            int xsize = 1 << (supracan_vram[i+1] & 7);
830            //int ysize = ((supracan_vram[i+0] & 0x0700) >> 9) + 1;
831            //ysize += 8 * ((supracan_vram[i+0] & 0x1800) >> 11);
820832            int ysize = ((supracan_vram[i+0] & 0x1e00) >> 9) + 1;
821            //int ysize = (((supracan_vram[i+0] & 0x0600) >> 9) + 1) * (1 << ((supracan_vram[i+0] & 0x1800) >> 11));
822            //if(supracan_vram[i+2] & 0x2000) ysize = xsize;
823            //int ysize = ((supracan_vram[i+2] & 0x1e00) >> 9)+1;
824833
834         // Blit background into working space for final scale
835            bitmap_t *sprite_bitmap = auto_bitmap_alloc(machine, xsize*8, ysize*8, BITMAP_FORMAT_INDEXED16);
836            for(int sy = 0; sy < ysize*8; sy++)
837            {
838                UINT16 *src = BITMAP_ADDR16(bitmap, y + sy, 0);
839                UINT16 *dst = BITMAP_ADDR16(sprite_bitmap, sy, 0);
840                for(int sx = 0; sx < xsize*8; sx++)
841                {
842                    dst[sx] = src[x + sx];
843                }
844            }
845
825846         if(vflip)
826847         {
827848            for(int ytile = (ysize - 1); ytile >= 0; ytile--)
r9072r9073
837858                            int palette = (data & 0xf000) >> 12;
838859
839860#if !(DRAW_DEBUG_UNK_SPRITE)
840                            draw_tile(machine, state->sprite_pri, bitmap, cliprect, tile, palette, xflip, yflip, x+xtile*8, y+ytile*8, priority, region, mask);
861                            draw_tile(machine, state->sprite_pri, /*bitmap*/sprite_bitmap, cliprect, tile, palette, xflip, yflip, ((xsize - 1) - xtile)*8, ((ysize - 1) - ytile)*8, priority, region, mask, x, y, 0x200, 0x200);
841862#else
842                            tile = 0;
843                            xflip = false;
844                            yflip = false;
845                            palette = 0;
846                            for(int ypix = 0; ypix < 8; ypix++)
847                            {
848                                for(int xpix = 0; xpix < 8; xpix++)
849                                {
850                                    if((y + ytile*8 + ypix) < 240 &&
851                                       (y + ytile*8 + ypix) >= 0 &&
852                                       (x + xtile*8 + xpix) < 320 &&
853                                       (x + xtile*8 + xpix) >= 0)
854                                    {
855                                        *BITMAP_ADDR16(bitmap, y + ytile*8 + ypix, x + xtile*8 + xpix) = supracan_vram[i+2] >> 9;
856                                    }
857                                }
858                            }
863                     DRAW_DEBUG_SPRITE_PRI()
859864#endif
860865                  }
861866               }
r9072r9073
870875                            int palette = (data & 0xf000) >> 12;
871876
872877#if !(DRAW_DEBUG_UNK_SPRITE)
873                            draw_tile(machine, state->sprite_pri, bitmap, cliprect, tile, palette, xflip, yflip, x+xtile*8, y+((ysize - 1) - ytile)*8, priority, region, mask);
878                            draw_tile(machine, state->sprite_pri, /*bitmap*/sprite_bitmap, cliprect, tile, palette, xflip, yflip, xtile*8, ((ysize - 1) - ytile)*8, priority, region, mask, x, y, 0x200, 0x200);
874879#else
875                            tile = 0;
876                            xflip = false;
877                            yflip = false;
878                            palette = 0;
879                            for(int ypix = 0; ypix < 8; ypix++)
880                            {
881                                for(int xpix = 0; xpix < 8; xpix++)
882                                {
883                                    if((y + ytile*8 + ypix) < 240 &&
884                                       (y + ytile*8 + ypix) >= 0 &&
885                                       (x + xtile*8 + xpix) < 320 &&
886                                       (x + xtile*8 + xpix) >= 0)
887                                    {
888                                        *BITMAP_ADDR16(bitmap, y + ytile*8 + ypix, x + xtile*8 + xpix) = supracan_vram[i+2] >> 9;
889                                    }
890                                }
891                            }
880                     DRAW_DEBUG_SPRITE_PRI()
892881#endif
893882                  }
894883               }
r9072r9073
909898                            int palette = (data & 0xf000) >> 12;
910899
911900#if !(DRAW_DEBUG_UNK_SPRITE)
912                            draw_tile(machine, state->sprite_pri, bitmap, cliprect, tile, palette, xflip, yflip, x+((xsize - 1) - xtile)*8, y+ytile*8, priority, region, mask);
901                            draw_tile(machine, state->sprite_pri, /*bitmap*/sprite_bitmap, cliprect, tile, palette, xflip, yflip, ((xsize - 1) - xtile)*8, ytile*8, priority, region, mask, x, y, 0x200, 0x200);
913902#else
914                            tile = 0;
915                            xflip = false;
916                            yflip = false;
917                            palette = 0;
918                            for(int ypix = 0; ypix < 8; ypix++)
919                            {
920                                for(int xpix = 0; xpix < 8; xpix++)
921                                {
922                                    if((y + ytile*8 + ypix) < 240 &&
923                                       (y + ytile*8 + ypix) >= 0 &&
924                                       (x + xtile*8 + xpix) < 320 &&
925                                       (x + xtile*8 + xpix) >= 0)
926                                    {
927                                        *BITMAP_ADDR16(bitmap, y + ytile*8 + ypix, x + xtile*8 + xpix) = supracan_vram[i+2] >> 9;
928                                    }
929                                }
930                            }
903                     DRAW_DEBUG_SPRITE_PRI()
931904#endif
932905                  }
933906               }
r9072r9073
942915                            int palette = (data & 0xf000) >> 12;
943916
944917#if !(DRAW_DEBUG_UNK_SPRITE)
945                            draw_tile(machine, state->sprite_pri, bitmap, cliprect, tile, palette, xflip, yflip, x + xtile * 8, y + ytile * 8, priority, region, mask);
918                            draw_tile(machine, state->sprite_pri, /*bitmap*/sprite_bitmap, cliprect, tile, palette, xflip, yflip, xtile*8, ytile*8, priority, region, mask, x, y, 0x200, 0x200);
946919#else
947                            tile = 0;
948                            xflip = false;
949                            yflip = false;
950                            palette = 0;
951                            for(int ypix = 0; ypix < 8; ypix++)
952                            {
953                                for(int xpix = 0; xpix < 8; xpix++)
954                                {
955                                    if((y + ytile*8 + ypix) < 240 &&
956                                       (y + ytile*8 + ypix) >= 0 &&
957                                       (x + xtile*8 + xpix) < 320 &&
958                                       (x + xtile*8 + xpix) >= 0)
959                                    {
960                                        *BITMAP_ADDR16(bitmap, y + ytile*8 + ypix, x + xtile*8 + xpix) = supracan_vram[i+2] >> 9;
961                                    }
962                                }
963                            }
920                     DRAW_DEBUG_SPRITE_PRI()
964921#endif
965922                  }
966923               }
967924            }
968925         }
926
927            if(xscale == 0) continue;
928            UINT32 delta = (1 << 17) / xscale;
929            for(int sy = 0; sy < ysize*8; sy++)
930            {
931                UINT16 *src = BITMAP_ADDR16(sprite_bitmap, sy, 0);
932                UINT16 *dst = BITMAP_ADDR16(bitmap, y + sy, 0);
933                UINT32 dx = x << 16;
934                for(int sx = 0; sx < xsize*8; sx++)
935                {
936                    dst[dx >> 16] = src[sx];
937                    dx += delta;
938                }
939            }
969940      }
970941   }
971942}
r9072r9073
978949
979950    for(int y = 0; y < 240; y++)
980951    {
981        float x = ((float)supracan_vram[state->roz_unk_base0 + y] / 1024.0f) * 256.0f;
982        *BITMAP_ADDR16(bitmap, y, (int)x) = 1;
952        float x = ((float)supracan_vram[(state->roz_unk_base0 >> 1) + y] / 1024.0f) * 256.0f;
953        *BITMAP_ADDR16(bitmap, y, (int)x) = 0x3fff;
983954
984        INT32 temp = supracan_vram[state->roz_unk_base1 + y*2] << 16;
985        temp |= supracan_vram[state->roz_unk_base1 + y*2 + 1];
986        x = ((float)temp / 65536.0f) * 128.0f;
987        temp = supracan_vram[state->roz_unk_base2 + y*2] << 16;
988        temp |= supracan_vram[state->roz_unk_base2 + y*2 + 1];
989        float y = ((float)temp / 65536.0f) * 128.0f;
990        if(x >= -160 && x < 160 && y >= -112 && y < 112)
955        INT32 temp = supracan_vram[(state->roz_unk_base1 >> 1) + y*2] << 16;
956        temp |= supracan_vram[(state->roz_unk_base1 >> 1) + y*2 + 1];
957        x = ((float)temp / 131072.0f) * 128.0f;
958        if(x >= -160 && x < 160)
991959        {
992            *BITMAP_ADDR16(bitmap, (int)y + 112, (int)x + 160) = 2;
960            *BITMAP_ADDR16(bitmap, y, (int)x + 160) = 0x7fff;
993961        }
962        temp = supracan_vram[(state->roz_unk_base2 >> 1) + y*2] << 16;
963        temp |= supracan_vram[(state->roz_unk_base2 >> 1) + y*2 + 1];
964        x = ((float)temp / 131072.0f) * 128.0f;
965        if(x >= -160 && x < 160)
966        {
967            *BITMAP_ADDR16(bitmap, y, (int)x + 160) = 0x5fff;
968        }
994969    }
995970}
996971#endif
997972
998973static VIDEO_UPDATE( supracan )
999974{
1000    // crash debug: printf("K"); fflush(stdout);
1001975    supracan_state *state = (supracan_state *)screen->machine->driver_data<supracan_state>();
1002976
1003977    bitmap_fill(bitmap, cliprect, 0);
1004978
1005979    bitmap_fill(state->sprite_final_bitmap, cliprect, 0);
1006    memset(state->sprite_pri, 8, 1024*1024 * sizeof(UINT8));
980    memset(state->sprite_pri, 9, 1024*1024 * sizeof(UINT8));
1007981
1008982    // VIDEO FLAGS                  ROZ MODE            TILEMAP FLAGS
1009983    //
r9072r9073
1013987    //    7: Tilemap 0 enable       11-8: Dims          11-8: Dims
1014988    //    6: Tilemap 1 enable       7-6: Unknown        7-6: Unknown
1015989    //    5: Tilemap 2 enable?      5: Wrap             5: Wrap
1016    //    3: Sprite enable          4-2: Unknown        4-2: Unknown
990    //    3: Sprite enable          4-2: Unknown        4-2: Mosaic
1017991    //    2: ROZ enable             1-0: Bit Depth      1-0: Bit Depth
1018992    //  1-0: Unknown
1019993
r9072r9073
10401014
10411015#if !(DEBUG_PRIORITY)
10421016            /* Harmony 7/27: THIS CODE IS KNOWN TO BE COMPLETELY WRONG.  DO NOT USE IT AS-IS IN A STANDALONE EMULATOR. */
1043            int pri_order[3] = { 0, 0, 0 };
1044            bitmap_t *bitmaps[3] = { state->tilemap_final_bitmap[0], state->tilemap_final_bitmap[1], state->tilemap_final_bitmap[2] };
1017            int pri_order[5] = { 0, 0, 0, 0, 0 };
1018            bitmap_t *bitmaps[5] = { state->tilemap_final_bitmap[0], state->tilemap_final_bitmap[1], state->tilemap_final_bitmap[2], state->roz_final_bitmap, state->sprite_final_bitmap };
10451019
10461020            pri_order[0] = state->tilemap_final_pri[0][y*320 + x];
10471021            pri_order[1] = state->tilemap_final_pri[1][y*320 + x];
10481022            pri_order[2] = state->tilemap_final_pri[2][y*320 + x];
1023            pri_order[3] = state->roz_final_pri[y*320 + x];
1024            pri_order[4] = 0;//HACK state->sprite_pri[y*1024 + x];
10491025
1050            int current_priority = 8;
1051            for(int index = 0; index < 3; index++)
1026            int current_priority = 9;
1027            for(int index = 0; index < 5; index++)
10521028            {
10531029                UINT16 pixel = *BITMAP_ADDR16(bitmaps[index], y, x) & 0x7fff;
10541030                if(pixel)
10551031                {
1056                    if(pri_order[index] < current_priority )
1032                    if(pri_order[index] < current_priority && pri_order[index] != 9)
10571033                    {
10581034                        *BITMAP_ADDR16(bitmap, y, x) = pixel;
10591035                        current_priority = pri_order[index];
10601036                    }
10611037                }
10621038            }
1063
1064            UINT16 pixel = *BITMAP_ADDR16(state->roz_final_bitmap, y, x) & 0x7fff;
1065            if(pixel)
1066            {
1067                *BITMAP_ADDR16(bitmap, y, x) = pixel;
1068            }
1069
1070            pixel = *BITMAP_ADDR16(state->sprite_final_bitmap, y, x) & 0x7fff;
1071            if(pixel)
1072            {
1073                *BITMAP_ADDR16(bitmap, y, x) = pixel;
1074            }
10751039#else
10761040            switch(0)
10771041            {
r9072r9073
11021066
11031067static WRITE16_HANDLER( supracan_dma_w )
11041068{
1105    // crash debug: printf("L"); fflush(stdout);
11061069    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
11071070   acan_dma_regs_t *acan_dma_regs = &state->acan_dma_regs;
11081071    int ch = (offset < 0x10/2) ? 0 : 1;
r9072r9073
11451108         {
11461109//              if(data & 0x2000)
11471110//                  acan_dma_regs->source-=2;
1148            //verboselog("maincpu", space->machine, 0, "supracan_dma_w: Kicking off a DMA from %08x to %08x, %d bytes (%04x)\n", acan_dma_regs->source[ch], acan_dma_regs->dest[ch], acan_dma_regs->count[ch] + 1, data);
1111            verboselog("maincpu", space->machine, 0, "supracan_dma_w: Kicking off a DMA from %08x to %08x, %d bytes (%04x)\n", acan_dma_regs->source[ch], acan_dma_regs->dest[ch], acan_dma_regs->count[ch] + 1, data);
11491112
11501113            for(int i = 0; i <= acan_dma_regs->count[ch]; i++)
11511114            {
r9072r9073
12041167
12051168static READ8_HANDLER( supracan_6502_soundmem_r )
12061169{
1207    // crash debug: printf("M"); fflush(stdout);
12081170    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
12091171    UINT8 data = state->soundram[offset];
12101172
r9072r9073
12641226
12651227static WRITE8_HANDLER( supracan_6502_soundmem_w )
12661228{
1267    // crash debug: printf("N"); fflush(stdout);
12681229    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
12691230
12701231    switch(offset)
r9072r9073
14371398
14381399static WRITE16_HANDLER( supracan_68k_soundram_w )
14391400{
1440    // crash debug: printf("P"); fflush(stdout);
14411401    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
14421402
14431403    state->soundram[offset*2 + 1] = data & 0xff;
r9072r9073
14621422
14631423static READ16_HANDLER( supracan_68k_soundram_r )
14641424{
1465    // crash debug: printf("Q"); fflush(stdout);
14661425    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
14671426
14681427    UINT16 val = state->soundram[offset*2 + 0] << 8;
r9072r9073
14901449
14911450static READ16_HANDLER( supracan_sound_r )
14921451{
1493    // crash debug: printf("R"); fflush(stdout);
14941452    //supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
14951453    UINT16 data = 0;
14961454
r9072r9073
15061464
15071465static WRITE16_HANDLER( supracan_sound_w )
15081466{
1509    // crash debug: printf("S"); fflush(stdout);
15101467    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
15111468
15121469   switch ( offset )
15131470   {
1471        case 0x000a/2:  /* Sound cpu IRQ request. */
1472            cpu_set_input_line(space->machine->device("soundcpu"), 0, ASSERT_LINE);
1473            break;
15141474      case 0x001c/2:   /* Sound cpu control. Bit 0 tied to sound cpu RESET line */
15151475         if(data & 0x01)
15161476         {
r9072r9073
15191479               /* Reset and enable the sound cpu */
15201480                    #if !(SOUNDCPU_BOOT_HACK)
15211481               cputag_set_input_line(space->machine, "soundcpu", INPUT_LINE_HALT, CLEAR_LINE);
1522               devtag_get_device(space->machine, "soundcpu")->reset();
1482               space->machine->device("soundcpu")->reset();
15231483                    #endif
15241484            }
15251485                state->m6502_reset = data & 0x01;
r9072r9073
15401500
15411501static READ16_HANDLER( supracan_video_r )
15421502{
1543    // crash debug: printf("T"); fflush(stdout);
15441503    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
15451504   UINT16 data = state->video_regs[offset];
15461505
r9072r9073
15771536
15781537static TIMER_CALLBACK( supracan_hbl_callback )
15791538{
1580    // crash debug: printf("U"); fflush(stdout);
15811539    supracan_state *state = machine->driver_data<supracan_state>();
15821540
15831541    timer_adjust_oneshot(state->hbl_timer, attotime_never, 0);
r9072r9073
16031561
16041562static TIMER_CALLBACK( supracan_video_callback )
16051563{
1606    // crash debug: printf("V"); fflush(stdout);
16071564    supracan_state *state = machine->driver_data<supracan_state>();
16081565   int vpos = machine->primary_screen->vpos();
16091566
r9072r9073
16361593        bitmap_fill(state->tilemap_final_bitmap[0], NULL, 0);
16371594        bitmap_fill(state->tilemap_final_bitmap[1], NULL, 0);
16381595        bitmap_fill(state->tilemap_final_bitmap[2], NULL, 0);
1639        //memset(state->roz_pri, 8, 1024*1024 * sizeof(UINT8) );
1640        //memset(state->tilemap_pri[0], 8, 1024*1024 * sizeof(UINT8));
1641        //memset(state->tilemap_pri[1], 8, 1024*1024 * sizeof(UINT8));
1642        //memset(state->tilemap_pri[2], 8, 1024*1024 * sizeof(UINT8));
1643        //memset(state->tilemap_final_pri[0], 8, 320*240 * sizeof(UINT8));
1644        //memset(state->tilemap_final_pri[1], 8, 320*240 * sizeof(UINT8));
1645        //memset(state->tilemap_final_pri[2], 8, 320*240 * sizeof(UINT8));
1596        memset(state->roz_pri, 9, 1024*1024 * sizeof(UINT8) );
1597        memset(state->tilemap_pri[0], 9, 1024*1024 * sizeof(UINT8));
1598        memset(state->tilemap_pri[1], 9, 1024*1024 * sizeof(UINT8));
1599        memset(state->tilemap_pri[2], 9, 1024*1024 * sizeof(UINT8));
1600        memset(state->tilemap_final_pri[0], 9, 320*240 * sizeof(UINT8));
1601        memset(state->tilemap_final_pri[1], 9, 320*240 * sizeof(UINT8));
1602        memset(state->tilemap_final_pri[2], 9, 320*240 * sizeof(UINT8));
16461603        if(state->video_flags & 4)
16471604        {
16481605            draw_roz(machine, &machine->primary_screen->visible_area());
r9072r9073
16551612
16561613        if(state->video_flags & 0x40)
16571614        {
1658            draw_tilemap(machine, state->tilemap_bitmap[1], &machine->primary_screen->visible_area(), 1);
1615              draw_tilemap(machine, state->tilemap_bitmap[1], &machine->primary_screen->visible_area(), 1);
16591616        }
16601617
16611618        if(state->video_flags & 0x20)
r9072r9073
16961653
16971654static WRITE16_HANDLER( supracan_video_w )
16981655{
1699    // crash debug: printf("W"); fflush(stdout);
17001656    supracan_state *state = (supracan_state *)space->machine->driver_data<supracan_state>();
17011657   acan_sprdma_regs_t *acan_sprdma_regs = &state->acan_sprdma_regs;
17021658   int i;
r9072r9073
18411797
18421798      /* ROZ */
18431799        case 0x180/2: state->roz_mode = data; verboselog("maincpu", space->machine, 3, "roz_mode = %04x\n", data); break;
1844        case 0x184/2: state->roz_scrollx = (data << 16) | (state->roz_scrollx & 0xffff); state->roz_changed |= 1; break;
1845        case 0x186/2: state->roz_scrollx = (data) | (state->roz_scrollx & 0xffff0000); state->roz_changed |= 1; break;
1846        case 0x188/2: state->roz_scrolly = (data << 16) | (state->roz_scrolly & 0xffff); state->roz_changed |= 2; break;
1847        case 0x18a/2: state->roz_scrolly = (data) | (state->roz_scrolly & 0xffff0000); state->roz_changed |= 2; break;
1848        case 0x18c/2: state->roz_coeffa = data; break;
1849        case 0x18e/2: state->roz_coeffb = data; break;
1850        case 0x190/2: state->roz_coeffc = data; break;
1851        case 0x192/2: state->roz_coeffd = data; break;
1800        case 0x184/2: state->roz_scrollx = (data << 16) | (state->roz_scrollx & 0xffff); state->roz_changed |= 1; verboselog("maincpu", space->machine, 3, "roz_scrollx = %08x\n", state->roz_scrollx); break;
1801        case 0x186/2: state->roz_scrollx = (data) | (state->roz_scrollx & 0xffff0000); state->roz_changed |= 1; verboselog("maincpu", space->machine, 3, "roz_scrollx = %08x\n", state->roz_scrollx); break;
1802        case 0x188/2: state->roz_scrolly = (data << 16) | (state->roz_scrolly & 0xffff); state->roz_changed |= 2; verboselog("maincpu", space->machine, 3, "roz_scrolly = %08x\n", state->roz_scrolly); break;
1803        case 0x18a/2: state->roz_scrolly = (data) | (state->roz_scrolly & 0xffff0000); state->roz_changed |= 2; verboselog("maincpu", space->machine, 3, "roz_scrolly = %08x\n", state->roz_scrolly); break;
1804        case 0x18c/2: state->roz_coeffa = data; verboselog("maincpu", space->machine, 3, "roz_coeffa = %04x\n", data); break;
1805        case 0x18e/2: state->roz_coeffb = data; verboselog("maincpu", space->machine, 3, "roz_coeffb = %04x\n", data); break;
1806        case 0x190/2: state->roz_coeffc = data; verboselog("maincpu", space->machine, 3, "roz_coeffc = %04x\n", data); break;
1807        case 0x192/2: state->roz_coeffd = data; verboselog("maincpu", space->machine, 3, "roz_coeffd = %04x\n", data); break;
18521808        case 0x194/2: state->roz_base_addr = (data) << 1; verboselog("maincpu", space->machine, 3, "roz_base_addr = %05x\n", data << 2); break;
18531809        case 0x196/2: state->roz_tile_bank = data; verboselog("maincpu", space->machine, 3, "roz_tile_bank = %04x\n", data); break; //tile bank
1854        case 0x198/2: state->roz_unk_base0 = data << 1; verboselog("maincpu", space->machine, 3, "roz_unk_base0 = %05x\n", data << 2); break;
1855        case 0x19a/2: state->roz_unk_base1 = data << 1; verboselog("maincpu", space->machine, 3, "roz_unk_base1 = %05x\n", data << 2); break;
1856        case 0x19e/2: state->roz_unk_base2 = data << 1; verboselog("maincpu", space->machine, 3, "roz_unk_base2 = %05x\n", data << 2); break;
1810        case 0x198/2: state->roz_unk_base0 = data << 2; verboselog("maincpu", space->machine, 3, "roz_unk_base0 = %05x\n", data << 2); break;
1811        case 0x19a/2: state->roz_unk_base1 = data << 2; verboselog("maincpu", space->machine, 3, "roz_unk_base1 = %05x\n", data << 2); break;
1812        case 0x19e/2: state->roz_unk_base2 = data << 2; verboselog("maincpu", space->machine, 3, "roz_unk_base2 = %05x\n", data << 2); break;
18571813
1858        //case 0x1d0/2: state->bg_color = data & 0x00ff; verboselog("maincpu", space->machine, 3, "bg_color = %04x\n", data); break;
1814        case 0x1d0/2: state->unk_1d0 = data; verboselog("maincpu", space->machine, 3, "unk_1d0 = %04x\n", data); break;
18591815
18601816      case 0x1f0/2: //FIXME: this register is mostly not understood
18611817         state->irq_mask = data;//(data & 8) ? 0 : 1;
r9072r9073
18771833
18781834static DEVICE_IMAGE_LOAD( supracan_cart )
18791835{
1880    // crash debug: printf("X"); fflush(stdout);
18811836    UINT8 *cart = memory_region(image.device().machine, "cart");
18821837   UINT32 size;
18831838
r9072r9073
19091864
19101865static MACHINE_START( supracan )
19111866{
1912    // crash debug: printf("Y"); fflush(stdout);
19131867    supracan_state *state = machine->driver_data<supracan_state>();
19141868
19151869   state->video_timer = timer_alloc( machine, supracan_video_callback, NULL );
r9072r9073
19211875
19221876static MACHINE_RESET( supracan )
19231877{
1924    // crash debug: printf("Z"); fflush(stdout);
19251878    supracan_state *state = machine->driver_data<supracan_state>();
19261879
19271880   cputag_set_input_line(machine, "soundcpu", INPUT_LINE_HALT, ASSERT_LINE);
r9072r9073
19881941{
19891942    supracan_state *state = (supracan_state *)device->machine->driver_data<supracan_state>();
19901943
1991    cpu_set_input_line(device, 0, HOLD_LINE);
19921944    state->sound_irq_source_reg |= 0x80;
1945
1946    if(state->sound_irq_enable_reg & state->sound_irq_source_reg)
1947    {
1948        cpu_set_input_line(device->machine->device("soundcpu"), 0, ASSERT_LINE);
1949    }
1950    else
1951    {
1952        cpu_set_input_line(device->machine->device("soundcpu"), 0, CLEAR_LINE);
1953    }
19931954}
19941955
19951956static MACHINE_CONFIG_START( supracan, supracan_state )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team