Previous 15994 Revisions Next

r7649 Friday 26th March, 2010 at 19:28:40 UTC by Fabio Priuli
[SNES] wip:
- greatly simplified tile drawing routines
- fixed a couple of small bugs in mosaic support
- reworked debug functions to be detected properly in all games (e.g. they now work in Jurassic Park and SMW2)
[src/mame/machine]snes.c
[src/mame/video]snes.c
[src/mess/drivers]snes.c

src/mame/machine/snes.c
r7648r7649
411411      case WBGLOG:
412412         return snes_ppu.ppu1_open_bus;
413413
414// According to BSNES, these should return snes_open_bus_r!
415//      case OAMADDL:
416//      case OAMADDH:
417//      case VMADDH:
418//      case CGADD:
419//      case CGDATA:
420//          return snes_ram[offset];
421414      case MPYL:      /* Multiplication result (low) */
422415         {
423416            /* Perform 16bit * 8bit multiply */
424            UINT32 c = snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8);
417            UINT32 c = (INT16)snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8);
425418            snes_ppu.ppu1_open_bus = c & 0xff;
426419            return snes_ppu.ppu1_open_bus;
427420         }
428421      case MPYM:      /* Multiplication result (mid) */
429422         {
430423            /* Perform 16bit * 8bit multiply */
431            UINT32 c = snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8);
424            UINT32 c = (INT16)snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8);
432425            snes_ppu.ppu1_open_bus = (c >> 8) & 0xff;
433426            return snes_ppu.ppu1_open_bus;
434427         }
435428      case MPYH:      /* Multiplication result (high) */
436429         {
437430            /* Perform 16bit * 8bit multiply */
438            UINT32 c = snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8);
431            UINT32 c = (INT16)snes_ppu.mode7.matrix_a * (INT8)(snes_ppu.mode7.matrix_b >> 8);
439432            snes_ppu.ppu1_open_bus = (c >> 16) & 0xff;
440433            return snes_ppu.ppu1_open_bus;
441434         }
442435      case SLHV:      /* Software latch for H/V counter */
443436         snes_latch_counters(space->machine);
444         return snes_open_bus_r(space,0);      /* Return value is meaningless */
437         return snes_open_bus_r(space, 0);      /* Return value is meaningless */
445438      case ROAMDATA:   /* Read data from OAM (DR) */
446439         {
447440            int oam_addr = snes_ppu.oam.address;
r7648r7649
489482               snes_ram[VMADDL] = addr & 0xff;
490483               snes_ram[VMADDH] = (addr >> 8) & 0xff;
491484            }
485
486            return snes_ppu.ppu1_open_bus;
492487         }
493         return snes_ppu.ppu1_open_bus;
494488      case RVMDATAH:   /* Read data from VRAM (high) */
495489         {
496490            UINT32 addr = (snes_ram[VMADDH] << 8) | snes_ram[VMADDL];
r7648r7649
515509               snes_ram[VMADDL] = addr & 0xff;
516510               snes_ram[VMADDH] = (addr >> 8) & 0xff;
517511            }
512
513            return snes_ppu.ppu1_open_bus;
518514         }
519         return snes_ppu.ppu1_open_bus;
520515      case RCGDATA:   /* Read data from CGRAM */
521516            if (!(state->cgram_address & 0x01))
522517            {
r7648r7649
570565         state->read_ophct = 0;
571566         state->read_opvct = 0;
572567         value = snes_ram[offset];
573         value |= (snes_ppu.ppu1_open_bus & 0x20);
568         value |= (snes_ppu.ppu2_open_bus & 0x20);
574569         value |= (snes_ppu.ppu2_version & 0x0f);
575570         snes_ram[offset] = value;   // not sure if this is needed...
576571         snes_ppu.ppu2_open_bus = value;
r7648r7649
618613      case VTIMEH:
619614         return snes_ram[offset];
620615      case RDNMI:         /* NMI flag by v-blank and version number */
621         value = (snes_ram[offset] & 0x8f) | (snes_open_bus_r(space,0) & 0x70);
616         value = (snes_ram[offset] & 0x8f) | (snes_open_bus_r(space, 0) & 0x70);
622617         snes_ram[offset] &= 0x7f;   /* NMI flag is reset on read */
623618         return value;
624619      case TIMEUP:      /* IRQ flag by H/V count timer */
625         value = (snes_open_bus_r(space,0) & 0x7f) | (snes_ram[TIMEUP] & 0x80);
620         value = (snes_open_bus_r(space, 0) & 0x7f) | (snes_ram[TIMEUP] & 0x80);
626621         cpu_set_input_line(state->maincpu, G65816_LINE_IRQ, CLEAR_LINE );
627622         snes_ram[TIMEUP] = 0;
628623         return value;
r7648r7649
630625         // electronics test says hcounter 272 is start of hblank, which is beampos 363
631626//          if (video_screen_get_hpos(space->machine->primary_screen) >= 363) snes_ram[offset] |= 0x40;
632627//              else snes_ram[offset] &= ~0x40;
633         return (snes_ram[offset] & 0xc1) | (snes_open_bus_r(space,0) & 0x3e);
628         return (snes_ram[offset] & 0xc1) | (snes_open_bus_r(space, 0) & 0x3e);
634629      case RDIO:         /* Programmable I/O port - echos back what's written to WRIO */
635630         return snes_ram[WRIO];
636631      case RDDIVL:      /* Quotient of divide result (low) */
r7648r7649
654649         return state->joy4l;
655650      case JOY4H:         /* Joypad 4 status register (high) */
656651         return state->joy4h;
657      case DMAP0:
658      case DMAP1:
659      case DMAP2:
660      case DMAP3:
661      case DMAP4:
662      case DMAP5:
663      case DMAP6:
664      case DMAP7:
665//          return (snes_ram[offset] & 0xdf) | (snes_open_bus_r(space,0) & 0x20);
666      case BBAD0: case A1T0L: case A1T0H: case A1B0: case DAS0L:
667      case DAS0H: case DSAB0: case A2A0L: case A2A0H: case NTRL0:
668      case BBAD1: case A1T1L: case A1T1H: case A1B1: case DAS1L:
669      case DAS1H: case DSAB1: case A2A1L: case A2A1H: case NTRL1:
670      case BBAD2: case A1T2L: case A1T2H: case A1B2: case DAS2L:
671      case DAS2H: case DSAB2: case A2A2L: case A2A2H: case NTRL2:
672      case BBAD3: case A1T3L: case A1T3H: case A1B3: case DAS3L:
673      case DAS3H: case DSAB3: case A2A3L: case A2A3H: case NTRL3:
674      case BBAD4: case A1T4L: case A1T4H: case A1B4: case DAS4L:
675      case DAS4H: case DSAB4: case A2A4L: case A2A4H: case NTRL4:
676      case BBAD5: case A1T5L: case A1T5H: case A1B5: case DAS5L:
677      case DAS5H: case DSAB5: case A2A5L: case A2A5H: case NTRL5:
678      case BBAD6: case A1T6L: case A1T6H: case A1B6: case DAS6L:
679      case DAS6H: case DSAB6: case A2A6L: case A2A6H: case NTRL6:
680      case BBAD7: case A1T7L: case A1T7H: case A1B7: case DAS7L:
681      case DAS7H: case DSAB7: case A2A7L: case A2A7H: case NTRL7:
652      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
653      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
654      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
655      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
656      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
657      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
658      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
659      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
660      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
661      case A1B4: case A1B5: case A1B6: case A1B7:
662      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
663      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
664      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
665      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
666      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
667      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
668      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
669      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
670      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
671      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
672      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
673      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
674      case 0x430b: case 0x431b: case 0x432b: case 0x433b: /* according to bsnes, this does not return open_bus (even if its precise effect is unknown) */
675      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
682676         return snes_ram[offset];
683677
684678#ifndef MESS
r7648r7649
696690   //printf("unsupported read: offset == %08x\n", offset);
697691
698692   /* Unsupported reads returns open bus */
699//  printf("%02x %02x\n",offset,snes_open_bus_r(space,0));
693//  printf("%02x %02x\n",offset,snes_open_bus_r(space, 0));
700694   return snes_open_bus_r(space, 0);
701695}
702696
r7648r7649
840834         snes_ppu.update_offsets = 1;
841835         break;
842836      case MOSAIC:   /* Size and screen designation for mosaic */
843         /* FIXME: We support horizontal mosaic only partially */
844837         snes_ppu.mosaic_size = (data & 0xf0) >> 4;
845838         snes_ppu.layer[SNES_BG1].mosaic_enabled = BIT(data, 0);
846839         snes_ppu.layer[SNES_BG2].mosaic_enabled = BIT(data, 1);
r7648r7649
12991292      case TIMEUP:
13001293         snes_ram[TIMEUP] = data &~0x7f;
13011294         return;
1302   /* Following are read-only */
1295      /* Following are read-only */
13031296      case HVBJOY:   /* H/V blank and joypad enable */
13041297      case MPYL:      /* Multiplication result (low) */
13051298      case MPYM:      /* Multiplication result (mid) */
r7648r7649
13211314         logerror( "Write to read-only register: %X value: %X", offset, data );
13221315#endif /* MAME_DEBUG */
13231316         return;
1324   /* Below is all DMA related */
1325      case DMAP0: case BBAD0: case A1T0L: case A1T0H: case A1B0: case DAS0L:
1326      case DAS0H: case DSAB0: case A2A0L: case A2A0H: case NTRL0:
1327      case DMAP1: case BBAD1: case A1T1L: case A1T1H: case A1B1: case DAS1L:
1328      case DAS1H: case DSAB1: case A2A1L: case A2A1H: case NTRL1:
1329      case DMAP2: case BBAD2: case A1T2L: case A1T2H: case A1B2: case DAS2L:
1330      case DAS2H: case DSAB2: case A2A2L: case A2A2H: case NTRL2:
1331      case DMAP3: case BBAD3: case A1T3L: case A1T3H: case A1B3: case DAS3L:
1332      case DAS3H: case DSAB3: case A2A3L: case A2A3H: case NTRL3:
1333      case DMAP4: case BBAD4: case A1T4L: case A1T4H: case A1B4: case DAS4L:
1334      case DAS4H: case DSAB4: case A2A4L: case A2A4H: case NTRL4:
1335      case DMAP5: case BBAD5: case A1T5L: case A1T5H: case A1B5: case DAS5L:
1336      case DAS5H: case DSAB5: case A2A5L: case A2A5H: case NTRL5:
1337      case DMAP6: case BBAD6: case A1T6L: case A1T6H: case A1B6: case DAS6L:
1338      case DAS6H: case DSAB6: case A2A6L: case A2A6H: case NTRL6:
1339      case DMAP7: case BBAD7: case A1T7L: case A1T7H: case A1B7: case DAS7L:
1340      case DAS7H: case DSAB7: case A2A7L: case A2A7H: case NTRL7:
1317      /* Below is all DMA related */
1318      case DMAP0:   case DMAP1: case DMAP2: case DMAP3: /*0x43n0*/
1319      case DMAP4: case DMAP5: case DMAP6: case DMAP7:
1320      case BBAD0: case BBAD1: case BBAD2: case BBAD3: /*0x43n1*/
1321      case BBAD4: case BBAD5: case BBAD6: case BBAD7:
1322      case A1T0L: case A1T1L: case A1T2L: case A1T3L: /*0x43n2*/
1323      case A1T4L: case A1T5L: case A1T6L: case A1T7L:
1324      case A1T0H: case A1T1H: case A1T2H: case A1T3H: /*0x43n3*/
1325      case A1T4H: case A1T5H: case A1T6H: case A1T7H:
1326      case A1B0: case A1B1: case A1B2: case A1B3:     /*0x43n4*/
1327      case A1B4: case A1B5: case A1B6: case A1B7:
1328      case DAS0L: case DAS1L: case DAS2L: case DAS3L: /*0x43n5*/
1329      case DAS4L: case DAS5L: case DAS6L: case DAS7L:
1330      case DAS0H: case DAS1H: case DAS2H: case DAS3H: /*0x43n6*/
1331      case DAS4H: case DAS5H: case DAS6H: case DAS7H:
1332      case DSAB0: case DSAB1: case DSAB2: case DSAB3: /*0x43n7*/
1333      case DSAB4: case DSAB5: case DSAB6: case DSAB7:
1334      case A2A0L: case A2A1L: case A2A2L: case A2A3L: /*0x43n8*/
1335      case A2A4L: case A2A5L: case A2A6L: case A2A7L:
1336      case A2A0H: case A2A1H: case A2A2H: case A2A3H: /*0x43n9*/
1337      case A2A4H: case A2A5H: case A2A6H: case A2A7H:
1338      case NTRL0: case NTRL1: case NTRL2: case NTRL3: /*0x43na*/
1339      case NTRL4: case NTRL5: case NTRL6: case NTRL7:
1340      case 0x430b: case 0x431b: case 0x432b: case 0x433b:
1341      case 0x434b: case 0x435b: case 0x436b: case 0x437b:
13411342         break;
13421343   }
13431344
src/mame/video/snes.c
r7648r7649
8484#ifdef SNES_LAYER_DEBUG
8585struct DEBUGOPTS
8686{
87   UINT8 input_count;
8887   UINT8 bg_disabled[5];
8988   UINT8 mode_disabled[8];
9089   UINT8 draw_subscreen;
r7648r7649
9796static struct DEBUGOPTS debug_options;
9897/*                                    red   green  blue    purple  yellow cyan    grey    white */
9998static const UINT16 dbg_mode_colours[8] = { 0x1f, 0x3e0, 0x7c00, 0x7c1f, 0x3ff, 0x7fe0, 0x4210, 0x7fff };
100static UINT8 snes_dbg_video(running_machine *machine, bitmap_t *bitmap, UINT16 curline);
99static UINT8 snes_dbg_video(running_machine *machine, UINT16 curline);
101100#endif /* SNES_LAYER_DEBUG */
102101
103102static const UINT16 table_obj_offset[8][8] =
r7648r7649
132131   SNES_COLOR_DEPTH_8BPP
133132};
134133
135/**********************************************************************************
136 * TODO: the draw_tile routines below should be merged/reworked to reduce everything
137 * to a single routine with the additional parameters: OAM/BG (to decide if checking
138 * against priority or not) and tile length (16 for hires BG, 8 otherwise)
139 **********************************************************************************/
140
141134/*****************************************
142 * snes_draw_tile()
135 * snes_get_bgcolor()
143136 *
144 * Draw BG tiles with variable bit planes
137 * Get the proper color (direct or from cgram)
145138 *****************************************/
146139
147INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
140INLINE UINT16 snes_get_bgcolor( UINT8 direct_colors, UINT16 palette, UINT8 color )
148141{
149   UINT8 mask, plane[8];
150   UINT16 c;
151   INT16 ii, jj;
142   UINT16 c = 0;
152143
153   for (ii = 0; ii < planes / 2; ii++)
144   if (direct_colors)
154145   {
155      plane[2 * ii] = snes_vram[tileaddr + 16 * ii];
156      plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1];
146      /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
147      c = ((color & 0x07) << 2) | ((color & 0x38) << 4) | ((color & 0xc0) << 7);
148      c |= ((palette & 0x04) >> 1) | ((palette & 0x08) << 3) | ((palette & 0x10) << 8);
157149   }
158
159   if (flip)
160      mask = 0x1;
161150   else
162      mask = 0x80;
151      c = snes_cgram[(palette + color) % FIXED_COLOUR];
163152
164   for (ii = x; ii < (x + 8); ii++)
165   {
166      UINT8 colour = 0;
167      if (flip)
168      {
169         for (jj = 0; jj < planes; jj++)
170            colour |= plane[jj] & mask ? (1 << jj) : 0;
153   return c;
154}
171155
172         mask <<= 1;
173      }
174      else
175      {
176         for (jj = 0; jj < planes; jj++)
177            colour |= plane[jj] & mask ? (1 << jj) : 0;
156/*****************************************
157 * snes_set_scanline_pixel()
158 *
159 * Store pixel color, priority, layer and
160 * color math exception (for OAM) in the
161 * proper scanline
162 *****************************************/
178163
179         mask >>= 1;
180      }
164INLINE void snes_set_scanline_pixel( int screen, INT16 x, UINT16 color, UINT8 priority, UINT8 layer, int blend )
165{
166   scanlines[screen].buffer[x] = color;
167   scanlines[screen].priority[x] = priority;
168   scanlines[screen].layer[x] = layer;
169   scanlines[screen].blend_exception[x] = blend;
170}
181171
172/*************************************************************************************************
173 * SNES tiles
174 *
175 * The way vram is accessed to draw tiles is basically the same for both BG and OAM tiles. Main
176 * differences are bit planes (variable for BG and fixed for OAM) and a few details of the scanline
177 * output (since OAM has neither mosaic, nor hires, nor direct colors).
178 * Hence, we use a common function to take data from VRAM and then we call specific routines for
179 * OAM vs BG vs Hi-Res BG tiles.
180 *************************************************************************************************/
182181
183      if (!hires)
184      {
185         if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && scanlines[SNES_MAINSCREEN].enable)
186         {
187            if (scanlines[SNES_MAINSCREEN].priority[ii] <= priority)
188            {
189               UINT8 clr = colour;
190               UINT8 clipmask = snes_ppu.clipmasks[layer][ii];
191               UINT8 mosaic = snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled;
182/*****************************************
183 * snes_draw_bgtile_lores()
184 * snes_draw_bgtile_hires()
185 * snes_draw_oamtile_()
186 *
187 * Check if a pixel is clipped or not, and
188 * copy it to the scanline buffer when
189 * appropriate. The actual way to perform
190 * such operations depends on the source
191 * (BG or OAM) and on the resolution (hires
192 * or lores)
193 *****************************************/
192194
193#ifdef SNES_LAYER_DEBUG
194               if (debug_options.windows_disabled)
195                  clipmask = 0xff;
196               if (debug_options.mosaic_disabled)
197                  mosaic = 0;
198#endif /* SNES_LAYER_DEBUG */
195INLINE void snes_draw_bgtile_lores( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority )
196{
197   int screen;
198   UINT16 c;
199199
200               /* Clip to windows */
201               if (scanlines[SNES_MAINSCREEN].clip)
202                  clr &= clipmask;
203
204               /* Only draw if we have a colour (0 == transparent) */
205               if (clr)
206               {
207                  if (direct_colors)
208                  {
209                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
210                     c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7);
211                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
212                  }
213                  else
214                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
215
216                  if (mosaic) // handle horizontal mosaic
217                  {
218                     int x_mos;
219
220                     //TODO: 512 modes has the h values doubled.
221                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
222                     {
223                        scanlines[SNES_MAINSCREEN].buffer[ii + x_mos] = c;
224                        scanlines[SNES_MAINSCREEN].priority[ii + x_mos] = priority;
225                        scanlines[SNES_MAINSCREEN].layer[ii + x_mos] = layer;
226                        scanlines[SNES_MAINSCREEN].blend_exception[ii + x_mos] = 0;
227                     }
228
229                     ii += x_mos - 1;
230                  }
231                  else
232                  {
233                     scanlines[SNES_MAINSCREEN].buffer[ii] = c;
234                     scanlines[SNES_MAINSCREEN].priority[ii] = priority;
235                     scanlines[SNES_MAINSCREEN].layer[ii] = layer;
236                     scanlines[SNES_MAINSCREEN].blend_exception[ii] = 0;
237                  }
238               }
239            }
240         }
241
242         if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && scanlines[SNES_SUBSCREEN].enable)
200   for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++)
201   {
202      if (ii >= 0 && ii < SNES_SCR_WIDTH && scanlines[screen].enable)
203      {
204         if (scanlines[screen].priority[ii] <= priority)
243205         {
244            if (scanlines[SNES_SUBSCREEN].priority[ii] <= priority)
245            {
246               UINT8 clr = colour;
247               UINT8 clipmask = snes_ppu.clipmasks[layer][ii];
248               UINT8 mosaic = snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled;
206            UINT8 clr = colour;
207            UINT8 clipmask = snes_ppu.clipmasks[layer][ii];
249208
250209#ifdef SNES_LAYER_DEBUG
251               if (debug_options.windows_disabled)
252                  clipmask = 0xff;
253               if (debug_options.mosaic_disabled)
254                  mosaic = 0;
210            if (debug_options.windows_disabled)
211               clipmask = 0xff;
255212#endif /* SNES_LAYER_DEBUG */
256213
257               /* Clip to windows */
258               if (scanlines[SNES_SUBSCREEN].clip)
259                  clr &= clipmask;
214            /* Clip to windows */
215            if (scanlines[screen].clip)
216               clr &= clipmask;
260217
261               /* Only draw if we have a colour (0 == transparent) */
262               if (clr)
263               {
264                  if (direct_colors)
265                  {
266                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
267                     c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7);
268                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
269                  }
270                  else
271                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
272
273                  if (mosaic) // handle horizontal mosaic
274                  {
275                     int x_mos;
276
277                     //TODO: 512 modes has the h values doubled.
278                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
279                     {
280                        scanlines[SNES_SUBSCREEN].buffer[ii + x_mos] = c;
281                        scanlines[SNES_SUBSCREEN].priority[ii + x_mos] = priority;
282                        scanlines[SNES_SUBSCREEN].layer[ii + x_mos] = layer;
283                        scanlines[SNES_SUBSCREEN].blend_exception[ii + x_mos] = 0;
284                     }
285
286                     ii += x_mos - 1;
287                  }
288                  else
289                  {
290                     scanlines[SNES_SUBSCREEN].buffer[ii] = c;
291                     scanlines[SNES_SUBSCREEN].priority[ii] = priority;
292                     scanlines[SNES_SUBSCREEN].layer[ii] = layer;
293                     scanlines[SNES_SUBSCREEN].blend_exception[ii] = 0;
294                  }
295               }
218            /* Only draw if we have a colour (0 == transparent) */
219            if (clr)
220            {
221               c = snes_get_bgcolor(direct_colors, pal, clr);
222               snes_set_scanline_pixel(screen, ii, c, priority, layer, 0);
296223            }
297224         }
298225      }
299      else /* hires */
226   }
227}
228
229INLINE void snes_draw_bgtile_hires( UINT8 layer, INT16 ii, UINT8 colour, UINT16 pal, UINT8 direct_colors, UINT8 priority )
230{
231   int screen;
232   UINT16 c;
233
234   for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++)
235   {
236      // odd pixels to main screen, even pixels to sub screen
237      if (ii >= 0 && ii < (SNES_SCR_WIDTH << 1) && ((ii & 1) ^ screen) && scanlines[screen].enable)
300238      {
301         if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && (ii & 1) && scanlines[SNES_MAINSCREEN].enable)
239         if (scanlines[screen].priority[ii >> 1] <= priority)
302240         {
303            if (scanlines[SNES_MAINSCREEN].priority[ii >> 1] <= priority)
304            {
305               UINT8 clr = colour;
306               UINT8 clipmask = snes_ppu.clipmasks[layer][ii];
307               UINT8 mosaic = snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled;
241            UINT8 clr = colour;
242            UINT8 clipmask = snes_ppu.clipmasks[layer][ii];
308243
309244#ifdef SNES_LAYER_DEBUG
310               if (debug_options.windows_disabled)
311                  clipmask = 0xff;
312               if (debug_options.mosaic_disabled)
313                  mosaic = 0;
245            if (debug_options.windows_disabled)
246               clipmask = 0xff;
314247#endif /* SNES_LAYER_DEBUG */
315248
316               /* Clip to windows */
317               if (scanlines[SNES_MAINSCREEN].clip)
318                  clr &= clipmask;
249            /* Clip to windows */
250            if (scanlines[screen].clip)
251               clr &= clipmask;
319252
320               /* Only draw if we have a colour (0 == transparent) */
321               if (clr)
322               {
323                  if (direct_colors)
324                  {
325                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
326                     c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7);
327                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
328                  }
329                  else
330                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
331
332                  if (mosaic) // handle horizontal mosaic
333                  {
334                     int x_mos;
335
336                     //TODO: 512 modes has the h values doubled.
337                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
338                     {
339                        scanlines[SNES_MAINSCREEN].buffer[(ii + x_mos) >> 1] = c;
340                        scanlines[SNES_MAINSCREEN].priority[(ii + x_mos) >> 1] = priority;
341                        scanlines[SNES_MAINSCREEN].layer[(ii + x_mos) >> 1] = layer;
342                        scanlines[SNES_MAINSCREEN].blend_exception[(ii + x_mos) >> 1] = 0;
343                     }
344                     ii += x_mos - 1;
345                  }
346                  else
347                  {
348                     scanlines[SNES_MAINSCREEN].buffer[ii >> 1] = c;
349                     scanlines[SNES_MAINSCREEN].priority[ii >> 1] = priority;
350                     scanlines[SNES_MAINSCREEN].layer[ii >> 1] = layer;
351                     scanlines[SNES_MAINSCREEN].blend_exception[ii >> 1] = 0;
352                  }
353               }
253            /* Only draw if we have a colour (0 == transparent) */
254            if (clr)
255            {
256               c = snes_get_bgcolor(direct_colors, pal, clr);
257               snes_set_scanline_pixel(screen, ii >> 1, c, priority, layer, 0);
354258            }
355259         }
260      }
261   }
262}
356263
357         if (ii >= 0 && ii < (SNES_SCR_WIDTH << hires) && !(ii & 1) && scanlines[SNES_SUBSCREEN].enable)
358         {
359            if (scanlines[SNES_SUBSCREEN].priority[ii >> 1] <= priority)
360            {
361               UINT8 clr = colour;
362               UINT8 clipmask = snes_ppu.clipmasks[layer][ii];
363               UINT8 mosaic = snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled;
264INLINE void snes_draw_oamtile( INT16 ii, UINT8 colour, UINT16 pal, UINT8 priority )
265{
266   int screen;
267   int blend;
268   UINT16 c;
269   INT16 pos = ii & 0x1ff;
364270
271   for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++)
272   {
273      if (pos >= 0 && pos < SNES_SCR_WIDTH && scanlines[screen].enable)
274      {
275         UINT8 clr = colour;
276         UINT8 clipmask = snes_ppu.clipmasks[SNES_OAM][pos];
277
365278#ifdef SNES_LAYER_DEBUG
366               if (debug_options.windows_disabled)
367                  clipmask = 0xff;
368               if (debug_options.mosaic_disabled)
369                  mosaic = 0;
279         if (debug_options.windows_disabled)
280            clipmask = 0xff;
370281#endif /* SNES_LAYER_DEBUG */
371282
372               /* Clip to windows */
373               if (scanlines[SNES_SUBSCREEN].clip)
374                  clr &= clipmask;
283         /* Clip to windows */
284         if (scanlines[screen].clip)
285            clr &= clipmask;
375286
376               /* Only draw if we have a colour (0 == transparent) */
377               if (clr)
378               {
379                  if (direct_colors)
380                  {
381                     /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
382                     c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7);
383                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
384                  }
385                  else
386                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
387
388                  if (mosaic) // handle horizontal mosaic
389                  {
390                     int x_mos;
391
392                     //TODO: 512 modes has the h values doubled.
393                     for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
394                     {
395                        scanlines[SNES_SUBSCREEN].buffer[(ii + x_mos) >> 1] = c;
396                        scanlines[SNES_SUBSCREEN].priority[(ii + x_mos) >> 1] = priority;
397                        scanlines[SNES_SUBSCREEN].layer[(ii + x_mos) >> 1] = layer;
398                        scanlines[SNES_SUBSCREEN].blend_exception[(ii + x_mos) >> 1] = 0;
399                     }
400                     ii += x_mos - 1;
401                  }
402                  else
403                  {
404                     scanlines[SNES_SUBSCREEN].buffer[ii >> 1] = c;
405                     scanlines[SNES_SUBSCREEN].priority[ii >> 1] = priority;
406                     scanlines[SNES_SUBSCREEN].layer[ii >> 1] = layer;
407                     scanlines[SNES_SUBSCREEN].blend_exception[ii >> 1] = 0;
408                  }
409               }
410            }
287         /* Only draw if we have a colour (0 == transparent) */
288         if (clr)
289         {
290            c = snes_cgram[(pal + clr) % FIXED_COLOUR];
291            blend = (pal + clr < 192) ? 1 : 0;
292            snes_set_scanline_pixel(screen, pos, c, priority, SNES_OAM, blend);
411293         }
412294      }
413295   }
414296}
415297
416298/*****************************************
417 * snes_draw_tile_x2()
299 * snes_draw_tile()
418300 *
419 * Draw 2 tiles with variable bit planes
301 * Get pixel color with variable bit planes
302 * from snes_vram and draw the tiles by
303 * calling the appropriate routine
420304 *****************************************/
421305
422INLINE void snes_draw_tile_x2( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
306INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, int tile_size, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
423307{
424   if (flip)
425   {
426      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x, priority, flip, direct_colors, pal, hires);
427      snes_draw_tile(planes, layer, tileaddr, x + 8, priority, flip, direct_colors, pal, hires);
428   }
429   else
430   {
431      snes_draw_tile(planes, layer, tileaddr, x, priority, flip, direct_colors, pal, hires);
432      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, direct_colors, pal, hires);
433   }
434}
308   UINT8 plane[8];
309   INT16 ii, jj, start_pixel;
310   int tile, x_mos;
435311
436/*****************************************
437 * snes_draw_tile_object()
438 *
439 * Draw OAM tiles with 4 bit planes(16 colors)
440 *****************************************/
312   start_pixel = x;
441313
442INLINE void snes_draw_tile_object( UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
443{
444   UINT8 mask, plane[4];
445   UINT16 c;
446   int blend;
447   INT16 ii, jj;
448
449   plane[0] = snes_vram[tileaddr];
450   plane[1] = snes_vram[tileaddr + 1];
451   plane[2] = snes_vram[tileaddr + 16];
452   plane[3] = snes_vram[tileaddr + 17];
453
454   if (flip)
455      mask = 0x01;
456   else
457      mask = 0x80;
458
459   for (ii = x; ii < (x + 8); ii++)
314   /* if 8x8 tile we draw once; if 16x16 we draw twice */
315   for (tile = 0; tile < (1 << tile_size); tile++)
460316   {
461      UINT8 colour = 0;
462      if (flip)
317      for (ii = 0; ii < planes / 2; ii++)
463318      {
464         for (jj = 0; jj < 4; jj++)
465            colour |= plane[jj] & mask ? (1 << jj) : 0;
466
467         mask <<= 1;
319         plane[2 * ii] = snes_vram[tileaddr + 16 * ii];
320         plane[2 * ii + 1] = snes_vram[tileaddr + 16 * ii + 1];
468321      }
469      else
470      {
471         for (jj = 0; jj < 4; jj++)
472            colour |= plane[jj] & mask ? (1 << jj) : 0;
473322
474         mask >>= 1;
475      }
476
477      INT16 pos = ii & 0x1ff;
478
479      if (pos >= 0 && pos < SNES_SCR_WIDTH && scanlines[SNES_MAINSCREEN].enable)
323      for (ii = x; ii < (x + 8); ii++)
480324      {
481         {
482            UINT8 clr = colour;
483            UINT8 clipmask = snes_ppu.clipmasks[SNES_OAM][pos];
325         UINT8 colour = 0;
326         UINT8 mosaic = snes_ppu.layer[layer].mosaic_enabled;
484327
485328#ifdef SNES_LAYER_DEBUG
486            if (debug_options.windows_disabled)
487               clipmask = 0xff;
329         if (debug_options.mosaic_disabled)
330            mosaic = 0;
488331#endif /* SNES_LAYER_DEBUG */
489332
490            /* Clip to windows */
491            if (scanlines[SNES_MAINSCREEN].clip)
492               clr &= clipmask;
333         if (flip)
334         {
335            for (jj = 0; jj < planes; jj++)
336               colour |= BIT(plane[jj], ii - x) ? (1 << jj) : 0;
337         }
338         else
339         {
340            for (jj = 0; jj < planes; jj++)
341               colour |= BIT(plane[jj], 7 - (ii - x)) ? (1 << jj) : 0;
342         }
493343
494            /* Only draw if we have a colour (0 == transparent) */
495            if (clr)
344         if (layer == SNES_OAM)
345            snes_draw_oamtile(ii, colour, pal, priority);
346         else if (!hires)
347         {
348            if (mosaic)   
496349            {
497               c = snes_cgram[(pal + clr) % FIXED_COLOUR];
498               blend = (pal + clr < 192) ? 1 : 0;
499
500               scanlines[SNES_MAINSCREEN].buffer[pos] = c;
501               scanlines[SNES_MAINSCREEN].priority[pos] = priority;
502               scanlines[SNES_MAINSCREEN].layer[pos] = SNES_OAM;
503               scanlines[SNES_MAINSCREEN].blend_exception[pos] = blend;
350               for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++)
351                  snes_draw_bgtile_lores(layer, ii + x_mos, colour, pal, direct_colors, priority);
352               ii += x_mos - 1;
504353            }
354            else
355               snes_draw_bgtile_lores(layer, ii, colour, pal, direct_colors, priority);
505356         }
506      }
507
508      if (pos >= 0 && pos < SNES_SCR_WIDTH && scanlines[SNES_SUBSCREEN].enable)
509      {
357         else /* hires */
510358         {
511            UINT8 clr = colour;
512            UINT8 clipmask = snes_ppu.clipmasks[SNES_OAM][pos];
513
514#ifdef SNES_LAYER_DEBUG
515            if (debug_options.windows_disabled)
516               clipmask = 0xff;
517#endif /* SNES_LAYER_DEBUG */
518
519            /* Clip to windows */
520            if (scanlines[SNES_SUBSCREEN].clip)
521               clr &= clipmask;
522
523            /* Only draw if we have a colour (0 == transparent) */
524            if (clr)
359            if (mosaic)   
525360            {
526               c = snes_cgram[(pal + clr) % FIXED_COLOUR];
527               blend = (pal + clr < 192) ? 1 : 0;
528
529               scanlines[SNES_SUBSCREEN].buffer[pos] = c;
530               scanlines[SNES_SUBSCREEN].priority[pos] = priority;
531               scanlines[SNES_SUBSCREEN].layer[pos] = SNES_OAM;
532               scanlines[SNES_SUBSCREEN].blend_exception[pos] = blend;
361               for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1); x_mos++)
362                  snes_draw_bgtile_hires(layer, ii + x_mos, colour, pal, direct_colors, priority);
363               ii += x_mos - 1;
533364            }
365            else
366               snes_draw_bgtile_hires(layer, ii, colour, pal, direct_colors, priority);
534367         }
535368      }
369
370      /* adjust tileaddr & x in case we have to draw again (for 16x16 tiles) */
371      if (!flip)
372         tileaddr += (8 * planes);
373      else
374         tileaddr -= (8 * planes);
375
376      x += 8;
536377   }
537378}
538379
r7648r7649
596437   UINT16 opt_bit = (layer == SNES_BG1) ? 13 : (layer == SNES_BG2) ? 14 : 0;
597438   UINT8 tile_size;
598439   /* variables depending on color_depth */
599   UINT8 tile_divider = (color_depth == SNES_COLOR_DEPTH_8BPP) ? 4 : 2;
600440   UINT8 color_planes = 2 << color_depth;
601441   /* below we cheat to simplify the code: 8BPP should have 0 pal offset, not 0x100 (but we take care of this by later using pal % FIXED_COLOUR) */
602442   UINT8 color_shift = 2 << color_depth;
r7648r7649
703543      }
704544
705545#ifdef SNES_LAYER_DEBUG
706   /* if we want to draw only one of the priorities of this layer */
707   if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) ||
708      ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b)))
709   {
710      if (!hires && tile_size)
711         ii += 16;
712      else
713         ii += 8;
714      continue;
715   }
546      /* if we want to draw only one of the priorities of this layer */
547      if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) ||
548         ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b)))
549      {
550         if (!hires && tile_size)
551            ii += 16;
552         else
553            ii += 8;
554         continue;
555      }
716556#endif /* SNES_LAYER_DEBUG */
717557
718
719558      /* figure out which line to draw */
720559      yscroll = ypos & ((8 << tile_size) - 1);
721560
722      if (yscroll > ((8 << tile_size) - 1))   /* scrolled into the next tile */
723         yscroll -= (8 << tile_size);
561      if (tile_size)
562         if ((yscroll & 8) != vflip)
563            tile += 16;
724564
565      if (yscroll > 7)
566         yscroll &= 7;
567
725568      if (vflip)
726      {
727         if (tile_size)
728         {
729            if (yscroll > 7)
730            {
731               yscroll -= 8;
732            }
733            else
734            {
735               tile += 32 / tile_divider;
736            }
737         }
738569         yscroll = -yscroll + 7;
739      }
740      else
741      {
742         if (yscroll > 7)
743         {
744            tile += 32 / tile_divider;
745            yscroll -= 8;
746         }
747      }
570
748571      yscroll <<= 1;
749572
750      /* below, only color_planes depends on color_depth */
751      if (hires)   /* Hi-Res: 2bpp & 4bpp */
573      if (hires)
752574      {
753         snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + yscroll, (ii - xscroll) * 2, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
575         /* adjust tile for horizontal flip */
576         if (hflip)
577            tile += 1;
578
579         /* draw 16 pixels (the routine will automatically send half of them to the mainscreen scanline and half to the subscreen one) */
580         snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + yscroll, (ii - xscroll) * 2, 1, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
754581         ii += 8;
755582      }
756      else   /* tile_size = 0 */
583      else
757584      {
758         if (tile_size)
759         {
760            snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
761            ii += 16;
762         }
763         else   /* No Hi-Res: 2bpp, 4bpp & 8bpp */
764         {
765            snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + yscroll, ii - xscroll, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
766            ii += 8;
767         }
585         /* adjust tile for horizontal flip */
586         if (tile_size && hflip)
587            tile += 1;
588
589         snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + yscroll, ii - xscroll, tile_size, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
590         ii += (8 << tile_size);
768591      }
769592   }
770593}
r7648r7649
787610   UINT8 colour = 0;
788611   UINT16 *mosaic_x, *mosaic_y;
789612   UINT16 c;
613   int screen;
790614
791615#ifdef SNES_LAYER_DEBUG
792616   if (debug_options.bg_disabled[layer])
r7648r7649
903727         colour &= 0x7f;
904728
905729#ifdef SNES_LAYER_DEBUG
906   /* if we want to draw only one of the priorities of this layer */
907   if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) ||
908      ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b)))
909      continue;
730      /* if we want to draw only one of the priorities of this layer */
731      if (((debug_options.select_pri[layer] & 0x01) && (priority == priority_a)) ||
732         ((debug_options.select_pri[layer] & 0x02) && (priority == priority_b)))
733         continue;
910734#endif /* SNES_LAYER_DEBUG */
911735      }
912736
913      if (scanlines[SNES_MAINSCREEN].enable)
737      for (screen = SNES_MAINSCREEN; screen <= SNES_SUBSCREEN; screen++)
914738      {
915         UINT8 clr = colour;
916         UINT8 clipmask = snes_ppu.clipmasks[layer][xpos];
917
918#ifdef SNES_LAYER_DEBUG
919         if (debug_options.windows_disabled)
920            clipmask = 0xff;
921#endif /* SNES_LAYER_DEBUG */
922
923         /* Clip to windows */
924         if (scanlines[SNES_MAINSCREEN].clip)
925            clr &= clipmask;
926
927         /* Draw pixel if appropriate */
928         if (scanlines[SNES_MAINSCREEN].priority[xpos] <= priority && clr > 0)
739         if (scanlines[screen].enable)
929740         {
930            /* Direct select, but only outside EXTBG! */
931            if (snes_ppu.direct_color && layer == SNES_BG1)
932            {
933               /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
934               c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7);
935            }
936            else
937               c = snes_cgram[clr];
741            UINT8 clr = colour;
742            UINT8 clipmask = snes_ppu.clipmasks[layer][xpos];
938743
939            scanlines[SNES_MAINSCREEN].buffer[xpos] = c;
940            scanlines[SNES_MAINSCREEN].priority[xpos] = priority;
941            scanlines[SNES_MAINSCREEN].layer[xpos] = layer;
942         }
943      }
944
945      if (scanlines[SNES_SUBSCREEN].enable)
946      {
947         UINT8 clr = colour;
948         UINT8 clipmask = snes_ppu.clipmasks[layer][xpos];
949
950744#ifdef SNES_LAYER_DEBUG
951         if (debug_options.windows_disabled)
952            clipmask = 0xff;
745            if (debug_options.windows_disabled)
746               clipmask = 0xff;
953747#endif /* SNES_LAYER_DEBUG */
954748
955         /* Clip to windows */
956         if (scanlines[SNES_SUBSCREEN].clip)
957            clr &= clipmask;
749            /* Clip to windows */
750            if (scanlines[screen].clip)
751               clr &= clipmask;
958752
959         /* Draw pixel if appropriate */
960         if (scanlines[SNES_SUBSCREEN].priority[xpos] <= priority && clr > 0)
961         {
962            /* Direct select, but only outside EXTBG! */
963            if (snes_ppu.direct_color && layer == SNES_BG1)
753            /* Draw pixel if appropriate */
754            if (scanlines[screen].priority[xpos] <= priority && clr > 0)
964755            {
965               /* 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded. */
966               c = ((clr & 0x07) << 2) | ((clr & 0x38) << 4) | ((clr & 0xc0) << 7);
756               /* Direct select, but only outside EXTBG! */
757               // Direct color format is: 0 | BB000 | GGG00 | RRR00, HW confirms that the data is zero padded.
758               // In other words, like normal direct color, with pal = 0
759               c = snes_get_bgcolor(snes_ppu.direct_color && layer == SNES_BG1, 0, clr);
760               snes_set_scanline_pixel(screen, xpos, c, priority, layer, 0);
967761            }
968            else
969               c = snes_cgram[clr];
970
971            scanlines[SNES_SUBSCREEN].buffer[xpos] = c;
972            scanlines[SNES_SUBSCREEN].priority[xpos] = priority;
973            scanlines[SNES_SUBSCREEN].layer[xpos] = layer;
974762         }
975763      }
976764   }
r7648r7649
13271115      }
13281116#endif /* SNES_LAYER_DEBUG */
13291117
1330      snes_draw_tile_object(charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, pri, oam_tilelist[tile].hflip, oam_tilelist[tile].pal);
1118      /* OAM tiles have fixed planes (4), fixed tile_size (8x8), no direct color and no hires, but otherwise work the same as BG ones */
1119      snes_draw_tile(4, SNES_OAM, charaddr + oam_tilelist[tile].tileaddr, oam_tilelist[tile].x, 0, pri, oam_tilelist[tile].hflip, 0, oam_tilelist[tile].pal, 0);
13311120   }
13321121}
13331122
r7648r7649
17631552      snes_update_obsel();
17641553
17651554#ifdef SNES_LAYER_DEBUG
1766      if (snes_dbg_video(machine, bitmap, curline))
1555      if (snes_dbg_video(machine, curline))
17671556      {
17681557         profiler_mark_end();
17691558         return;
r7648r7649
18701659{
18711660#ifdef SNES_LAYER_DEBUG
18721661   memset(&debug_options, 0, sizeof(debug_options));
1873   debug_options.input_count = 5;
18741662#endif
18751663}
18761664
r7648r7649
18911679
18921680#ifdef SNES_LAYER_DEBUG
18931681
1894static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16 curline )
1895{
1896   /* Check if the user has enabled or disabled stuff */
1897   if (curline == 1)
1898   {
1899      if (!debug_options.input_count--)
1900      {
1901         int i;
1902         UINT8 toggles = input_port_read_safe(machine, "DEBUG1", 0);
1903         debug_options.select_pri[SNES_BG1] = (toggles & 0x03);
1904         debug_options.select_pri[SNES_BG2] = (toggles & 0x0c) >> 2;
1905         debug_options.select_pri[SNES_BG3] = (toggles & 0x30) >> 4;
1906         debug_options.select_pri[SNES_BG4] = (toggles & 0xc0) >> 6;
1682#define DEBUG_TOGGLE(bit, debug_settings, MSG1, MSG2) \
1683   if (BIT(toggles, bit) && !debug_settings)       \
1684   {                                               \
1685      debug_settings = 1;                       \
1686      popmessage MSG1;                          \
1687   }                                               \
1688   else if (!BIT(toggles, bit) && debug_settings)  \
1689   {                                               \
1690      debug_settings = 0;                       \
1691      popmessage MSG2;                          \
1692   }                                               \
19071693
1908         toggles = input_port_read_safe(machine, "DEBUG2", 0);
1909         for (i = 0; i < 4; i++)
1910         {
1911            if (BIT(toggles, i))
1912            {
1913               debug_options.bg_disabled[i] = !debug_options.bg_disabled[i];
1914               popmessage("Debug: %s BG%d.\n", debug_options.bg_disabled[i] ? "Disabled" : "Enabled", i + 1);
1915            }
1916         }
1917         if (BIT(toggles, 4))
1918         {
1919            debug_options.bg_disabled[SNES_OAM] = !debug_options.bg_disabled[SNES_OAM];
1920            popmessage("Debug: %s OAM.\n", debug_options.bg_disabled[SNES_OAM] ? "Disabled" : "Enabled");
1921         }
1922         if (BIT(toggles, 5))
1923         {
1924            debug_options.draw_subscreen = !debug_options.draw_subscreen;
1925            popmessage("Debug: Switched screens.\n");
1926         }
1927         if (BIT(toggles, 6))
1928         {
1929            debug_options.colormath_disabled = !debug_options.colormath_disabled;
1930            popmessage("Debug: %s Color Math.\n", debug_options.colormath_disabled ? "Disabled" : "Enabled");
1931         }
1932         if (BIT(toggles, 7))
1933         {
1934            debug_options.windows_disabled = !debug_options.windows_disabled;
1935            popmessage("Debug: %s Window Masks.\n", debug_options.windows_disabled ? "Disabled" : "Enabled");
1936         }
19371694
1938         toggles = input_port_read_safe(machine, "DEBUG4", 0);
1939         for (i = 0; i < 8; i++)
1940         {
1941            if (BIT(toggles, i))
1942            {
1943               debug_options.mode_disabled[i] = !debug_options.mode_disabled[i];
1944               popmessage("Debug: %s Mode %d drawing.\n", debug_options.mode_disabled[i] ? "Disabled" : "Enabled", i);
1945            }
1946         }
1695static UINT8 snes_dbg_video( running_machine *machine, UINT16 curline )
1696{
1697   int i;
1698   UINT8 toggles = input_port_read_safe(machine, "DEBUG1", 0);
1699   debug_options.select_pri[SNES_BG1] = (toggles & 0x03);
1700   debug_options.select_pri[SNES_BG2] = (toggles & 0x0c) >> 2;
1701   debug_options.select_pri[SNES_BG3] = (toggles & 0x30) >> 4;
1702   debug_options.select_pri[SNES_BG4] = (toggles & 0xc0) >> 6;
19471703
1948         toggles = input_port_read_safe(machine, "DEBUG3", 0);
1949         if (toggles & 0x4)
1950         {
1951            debug_options.mosaic_disabled = !debug_options.mosaic_disabled;
1952            popmessage("Debug: %s Mosaic.\n", debug_options.mosaic_disabled ? "Disabled" : "Enabled");
1953         }
1954         debug_options.sprite_reversed = BIT(toggles, 7);
1955         debug_options.select_pri[SNES_OAM] = (toggles & 0x70) >> 4;
1704   toggles = input_port_read_safe(machine, "DEBUG2", 0);
1705   for (i = 0; i < 4; i++)
1706      DEBUG_TOGGLE(i, debug_options.bg_disabled[i], ("Debug: Disabled BG%d.\n", i + 1), ("Debug: Enabled BG%d.\n", i + 1))
1707   DEBUG_TOGGLE(4, debug_options.bg_disabled[SNES_OAM], ("Debug: Disabled OAM.\n"), ("Debug: Enabled OAM.\n"))
1708   DEBUG_TOGGLE(5, debug_options.draw_subscreen, ("Debug: Switched screens.\n"), ("Debug: Switched screens.\n"))
1709   DEBUG_TOGGLE(6, debug_options.colormath_disabled, ("Debug: Disabled Color Math.\n"), ("Debug: Enabled Color Math.\n"))
1710   DEBUG_TOGGLE(7, debug_options.windows_disabled, ("Debug: Disabled Window Masks.\n"), ("Debug: Enabled Window Masks.\n"))
19561711
1957         debug_options.input_count = 5;
1958      }
1712   toggles = input_port_read_safe(machine, "DEBUG4", 0);
1713   for (i = 0; i < 8; i++)
1714      DEBUG_TOGGLE(i, debug_options.mode_disabled[i], ("Debug: Disabled Mode %d drawing.\n", i), ("Debug: Enabled Mode %d drawing.\n", i))
19591715
1716   toggles = input_port_read_safe(machine, "DEBUG3", 0);
1717   DEBUG_TOGGLE(2, debug_options.mosaic_disabled, ("Debug: Disabled Mosaic.\n"), ("Debug: Enabled Mosaic.\n"))
1718   debug_options.sprite_reversed = BIT(toggles, 7);
1719   debug_options.select_pri[SNES_OAM] = (toggles & 0x70) >> 4;
1720
19601721#ifdef MAME_DEBUG
1722   /* Once per frame, log video properties */
1723   if (curline == 1)
1724   {
19611725      static const char WINLOGIC[4] = { '|', '&', '^', '!' };
19621726
19631727      logerror("%s", debug_options.windows_disabled?" ":"W");
r7648r7649
20461810      logerror("Mode7: A %5d B %5d", snes_ppu.mode7.matrix_a, snes_ppu.mode7.matrix_b );
20471811      logerror(" %s%s%s   C %5d D %5d", (snes_ram[M7SEL] & 0xc0)?((snes_ram[M7SEL] & 0x40)?"0":"C"):"R", (snes_ram[M7SEL] & 0x1)?"H":" ", (snes_ram[M7SEL] & 0x2)?"V":" ", snes_ppu.mode7.matrix_c, snes_ppu.mode7.matrix_d );
20481812      logerror("       X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y );
2049#endif
20501813   }
1814#endif
20511815
20521816   return 0;
20531817}
src/mess/drivers/snes.c
r7648r7649
318318   PORT_CONFSETTING(    0x80, "BG4A (higher) only" )
319319
320320   PORT_START("DEBUG2")
321   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 1") PORT_CODE(KEYCODE_1_PAD)
322   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 2") PORT_CODE(KEYCODE_2_PAD)
323   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 3") PORT_CODE(KEYCODE_3_PAD)
324   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 4") PORT_CODE(KEYCODE_4_PAD)
325   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Objects") PORT_CODE(KEYCODE_5_PAD)
326   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Main/Sub") PORT_CODE(KEYCODE_6_PAD)
327   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Color Math") PORT_CODE(KEYCODE_7_PAD)
328   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Windows") PORT_CODE(KEYCODE_8_PAD)
321   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 1") PORT_CODE(KEYCODE_1_PAD) PORT_TOGGLE
322   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 2") PORT_CODE(KEYCODE_2_PAD) PORT_TOGGLE
323   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 3") PORT_CODE(KEYCODE_3_PAD) PORT_TOGGLE
324   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle BG 4") PORT_CODE(KEYCODE_4_PAD) PORT_TOGGLE
325   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Objects") PORT_CODE(KEYCODE_5_PAD) PORT_TOGGLE
326   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Main/Sub") PORT_CODE(KEYCODE_6_PAD) PORT_TOGGLE
327   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Color Math") PORT_CODE(KEYCODE_7_PAD) PORT_TOGGLE
328   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Windows") PORT_CODE(KEYCODE_8_PAD) PORT_TOGGLE
329329
330330   PORT_START("DEBUG3")
331   PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mosaic") PORT_CODE(KEYCODE_9_PAD)
331   PORT_BIT( 0x4, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mosaic") PORT_CODE(KEYCODE_9_PAD) PORT_TOGGLE
332332   PORT_CONFNAME( 0x70, 0x00, "Select OAM priority" )
333333   PORT_CONFSETTING(    0x00, "All" )
334334   PORT_CONFSETTING(    0x10, "OAM0 only" )
r7648r7649
340340   PORT_CONFSETTING(    0x80, DEF_STR( On ) )
341341
342342   PORT_START("DEBUG4")
343   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 0 draw")
344   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 1 draw")
345   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 2 draw")
346   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 3 draw")
347   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 4 draw")
348   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 5 draw")
349   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 6 draw")
350   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 7 draw")
343   PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 0 draw") PORT_TOGGLE
344   PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 1 draw") PORT_TOGGLE
345   PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 2 draw") PORT_TOGGLE
346   PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 3 draw") PORT_TOGGLE
347   PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 4 draw") PORT_TOGGLE
348   PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 5 draw") PORT_TOGGLE
349   PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 6 draw") PORT_TOGGLE
350   PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_OTHER ) PORT_NAME("Toggle Mode 7 draw") PORT_TOGGLE
351351#endif
352352INPUT_PORTS_END
353353

Previous 15994 Revisions Next


© 1998-2018 The MESS Team