Previous 15994 Revisions Next

r7310 Wednesday 10th February, 2010 at 14:30:13 UTC by Fabio Priuli
[SNES] wip:
* moved color blending (background & subscreen color addition/subtraction) at the end of the drawing process.
* removed some unused (and not working anymore) debug code
* reverted a small change (entered by mistake) which broke Tokimeki Memorial hires (among other)
[src/mame/machine]snes.c
[src/mame/video]snes.c

src/mame/machine/snes.c
r7309r7310
342342   visarea.max_x = (SNES_SCR_WIDTH * 2) - 1;
343343
344344   // fixme: should compensate for SNES_DBG_video
345   if (snes_ram[SETINI] & 0x08 || snes_ppu.mode == 5 || snes_ppu.mode == 6 )
345   if (snes_ppu.mode == 5 || snes_ppu.mode == 6 )
346346      snes_htmult = 2;
347347   else
348348      snes_htmult = 1;
src/mame/video/snes.c
r7309r7310
8787   UINT8 input_count;
8888   UINT8 bg_disabled[6];
8989   UINT8 mode_disabled[8];
90   UINT8 draw_SNES_SUBSCREEN;
90   UINT8 draw_subscreen;
9191   UINT8 windows_disabled;
9292   UINT8 transparency_disabled;
9393};
r7309r7310
115115struct SCANLINE
116116{
117117   UINT16 buffer[(SNES_SCR_WIDTH * 2) + 16];
118   UINT8  zbuf[(SNES_SCR_WIDTH * 2) + 16];
118   UINT8  priority[(SNES_SCR_WIDTH * 2) + 16];
119   UINT8  layer[(SNES_SCR_WIDTH * 2) + 16];
120   UINT8  blend_exception[(SNES_SCR_WIDTH * 2) + 16];
119121};
120122
121123static struct SCANLINE scanlines[2];
r7309r7310
273275      /* Only draw if we have a colour (0 == transparent) */
274276      if (colour)
275277      {
276         if ((scanlines[screen].zbuf[ii] <= priority) && (ii >= 0))
278         if ((scanlines[screen].priority[ii] <= priority) && (ii >= 0))
277279         {
278280            if (direct_colors)
279281            {
r7309r7310
284286            else
285287               c = snes_cgram[pal + colour];
286288
287            /* Only blend main screens and only if the layer is subject to color_math */
288            if (screen == SNES_MAINSCREEN && snes_ppu.layer[layer].color_math)
289               snes_draw_blend(ii/snes_htmult, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
290289            if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
291290            {
292291               int x_mos;
r7309r7310
295294               for (x_mos = 0; x_mos < (snes_ppu.mosaic_size + 1) ; x_mos++)
296295               {
297296                  scanlines[screen].buffer[ii + x_mos] = c;
298                  scanlines[screen].zbuf[ii + x_mos] = priority;
297                  scanlines[screen].priority[ii + x_mos] = priority;
298                  scanlines[screen].layer[ii + x_mos] = layer;
299299               }
300300               ii += x_mos - 1;
301301            }
302302            else
303303            {
304304               scanlines[screen].buffer[ii] = c;
305               scanlines[screen].zbuf[ii] = priority;
305               scanlines[screen].priority[ii] = priority;
306               scanlines[screen].layer[ii] = layer;
306307            }
307308         }
308309      }
r7309r7310
382383      /* Only draw if we have a colour (0 == transparent) */
383384      if (colour)
384385      {
385         if (ii >= 0)
386         if ((scanlines[screen].priority[ii] <= priority) && (ii >= 0))
386387         {
387388            c = snes_cgram[pal + colour];
388            if (blend && screen == SNES_MAINSCREEN && snes_ppu.layer[SNES_OAM].color_math)   /* Only blend main screens */
389               snes_draw_blend(ii/snes_htmult, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
390389
391390            scanlines[screen].buffer[ii] = c;
392            scanlines[screen].zbuf[ii] = priority;
391            scanlines[screen].priority[ii] = priority;
392            scanlines[screen].layer[ii] = SNES_OAM;
393            scanlines[screen].blend_exception[ii] = blend;
393394            if (wide)
394395            {
395396               scanlines[screen].buffer[ii + 1] = c;
396               scanlines[screen].zbuf[ii + 1] = priority;
397               scanlines[screen].priority[ii + 1] = priority;
398               scanlines[screen].layer[ii + 1] = SNES_OAM;
399               scanlines[screen].blend_exception[ii + 1] = blend;
397400            }
398401         }
399402      }
r7309r7310
703706         colour &= snes_ppu.clipmasks[layer][xpos];
704707
705708      /* Draw pixel if appropriate */
706      if (scanlines[screen].zbuf[xpos] <= priority && colour > 0)
709      if (scanlines[screen].priority[xpos] <= priority && colour > 0)
707710      {
708711         UINT16 clr;
709712         /* Direct select, but only outside EXTBG! */
r7309r7310
714717         }
715718         else
716719            clr = snes_cgram[colour];
717         /* Only blend main screens */
718         if (screen == SNES_MAINSCREEN && snes_ppu.layer[layer].color_math)
719            snes_draw_blend(xpos, &clr, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); /* FIXME: Need to support clip mode */
720720
721721         scanlines[screen].buffer[xpos] = clr;
722         scanlines[screen].zbuf[xpos] = priority;
722         scanlines[screen].priority[xpos] = priority;
723         scanlines[screen].layer[xpos] = layer;
723724      }
724725   }
725726}
r7309r7310
763764   if (snes_ppu.mode == 5 || snes_ppu.mode == 6)
764765      widemode = 1;
765766
766   curline/=snes_ppu.interlace;
767   curline*=snes_ppu.obj_interlace;
767   curline /= snes_ppu.interlace;
768   curline *= snes_ppu.obj_interlace;
768769
769770   oam = 0x1ff;
770771   oam_extra = oam + 0x20;
r7309r7310
798799      if (curline >= y && curline < (y + (snes_ppu.oam.size[size] << 3)))
799800      {
800801         /* Only objects using palettes 4-7 can be transparent */
801         blend = (pal < 192) ? 0 : 1;
802         blend = (pal < 192) ? 1 : 0;
802803
803804         /* Only objects using tiles over 255 use name select */
804805         name_sel = (tile < 256) ? 0 : snes_ppu.oam.name_select;
r7309r7310
11451146   int x;
11461147   int fade;
11471148   struct SCANLINE *scanline;
1149   UINT16 c;
11481150
11491151   profiler_mark_start(PROFILER_VIDEO);
11501152
r7309r7310
11601162      if (snes_ppu.update_offsets)
11611163         snes_update_offsets();
11621164
1163      /* Clear zbuffers */
1164      memset(scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1165      memset(scanlines[SNES_SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1165      /* Clear priority */
1166      memset(scanlines[SNES_MAINSCREEN].priority, 0, SNES_SCR_WIDTH * 2);
1167      memset(scanlines[SNES_SUBSCREEN].priority, 0, SNES_SCR_WIDTH * 2);
11661168
1167      /* Clear SNES_SUBSCREEN and draw back colour */
1169      /* Clear layers */
1170      memset(scanlines[SNES_MAINSCREEN].layer, SNES_COLOR, SNES_SCR_WIDTH * 2);
1171      memset(scanlines[SNES_SUBSCREEN].layer, SNES_COLOR, SNES_SCR_WIDTH * 2);
1172
1173      /* Clear blend_exception (only used for OAM) */
1174      memset(scanlines[SNES_MAINSCREEN].blend_exception, 0, SNES_SCR_WIDTH * 2);
1175      memset(scanlines[SNES_SUBSCREEN].blend_exception, 0, SNES_SCR_WIDTH * 2);
1176
1177      /* Draw back colour */
11681178      for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
11691179      {
1170         /* Not sure if this is correct behaviour, but a few games seem to
1171             * require it. (SMW, Zelda etc) */
1172         scanlines[SNES_SUBSCREEN].buffer[ii] = snes_cgram[FIXED_COLOUR];
1180         if (snes_ppu.mode == 5 || snes_ppu.mode == 6)
1181            scanlines[SNES_SUBSCREEN].buffer[ii] = snes_cgram[0];
1182         else
1183            scanlines[SNES_SUBSCREEN].buffer[ii] = snes_cgram[FIXED_COLOUR];
1184
11731185         /* Draw back colour */
11741186         scanlines[SNES_MAINSCREEN].buffer[ii] = snes_cgram[0];
11751187      }
r7309r7310
11771189      /* Draw SNES_SUBSCREEN */
11781190      snes_draw_screen(SNES_SUBSCREEN, curline);
11791191
1180      /* Draw the back plane */
1181#ifdef MAME_DEBUG
1182      if (!debug_options.bg_disabled[5])
1183#endif /* MAME_DEBUG */
1184      if (snes_ppu.colour.color_math)
1185      {
1186         for (ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++)
1187         {
1188            snes_draw_blend(ii/snes_htmult, &scanlines[SNES_MAINSCREEN].buffer[ii], snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1189         }
1190      }
11911192
11921193      /* Draw SNES_MAINSCREEN */
11931194      snes_draw_screen(SNES_MAINSCREEN, curline);
r7309r7310
12001201      }
12011202
12021203      /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */
1203      if (debug_options.draw_SNES_SUBSCREEN)
1204      if (debug_options.draw_subscreen)
12041205         scanline = &scanlines[SNES_SUBSCREEN];
12051206      else
12061207#endif /* MAME_DEBUG */
r7309r7310
12111212
12121213      for (x = 0; x < SNES_SCR_WIDTH * 2; x++)
12131214      {
1214         int r = ((scanline->buffer[x] & 0x1f) * fade) >> 4;
1215         int g = (((scanline->buffer[x] & 0x3e0) >> 5) * fade) >> 4;
1216         int b = (((scanline->buffer[x] & 0x7c00) >> 10) * fade) >> 4;
1215         c = scanline->buffer[x];
1216         /* perform color math if the layer wants it (except if it's an object > 192) */
1217         if (!scanlines[SNES_MAINSCREEN].blend_exception[x] &&
1218            ((scanlines[SNES_MAINSCREEN].layer[x] != SNES_COLOR && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1219            || (scanlines[SNES_MAINSCREEN].layer[x] == SNES_COLOR && snes_ppu.colour.color_math)))
1220            snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
12171221
1222         int r = ((c & 0x1f) * fade) >> 4;
1223         int g = (((c & 0x3e0) >> 5) * fade) >> 4;
1224         int b = (((c & 0x7c00) >> 10) * fade) >> 4;
1225
12181226         if (snes_htmult == 1)
12191227         {
12201228            *BITMAP_ADDR32(bitmap, curline, x*2+0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
r7309r7310
12511259
12521260#ifdef MAME_DEBUG
12531261
1254static void snes_dbg_draw_maps( bitmap_t *bitmap, UINT32 tmap, UINT8 bpl, UINT16 curline, UINT8 layer )
1255{
1256   UINT32 tile, addr = tmap;
1257   UINT16 ii, vflip, hflip, pal;
1258   INT8 line;
1259
1260   tmap += (curline >> 3) * 64;
1261   for (ii = 0; ii < 64; ii += 2)
1262   {
1263      vflip = (snes_vram[tmap + ii + 1] & 0x80);
1264      hflip = snes_vram[tmap + ii + 1] & 0x40;
1265      pal = (snes_vram[tmap + ii + 1] & 0x1c);      /* 8 palettes of 4 colours */
1266      tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
1267      tile |= snes_vram[tmap + ii];
1268      line = curline % 8;
1269      if (vflip)
1270         line = -line + 7;
1271
1272      if (tile != 0)
1273      {
1274         switch (bpl)
1275         {
1276            case 1:
1277               snes_draw_tile(SNES_MAINSCREEN, 2, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
1278               break;
1279            case 2:
1280               pal <<= 2;
1281               snes_draw_tile(SNES_MAINSCREEN, 4, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
1282               break;
1283            case 4:
1284               pal <<= 0;   // n/a
1285               snes_draw_tile(SNES_MAINSCREEN, 8, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
1286               break;
1287         }
1288      }
1289   }
1290
1291   logerror("%d : %8X  ", layer, addr );
1292   //ui_draw_text( str, 0, 227 );
1293}
1294
1295static void snes_dbg_draw_all_tiles( running_machine *machine, bitmap_t *bitmap, UINT32 tileaddr, UINT8 bpl, UINT16 pal )
1296{
1297   UINT16 ii, jj, kk;
1298   UINT32 addr = tileaddr;
1299
1300   for (jj = 0; jj < 32; jj++)
1301   {
1302      addr = tileaddr + (jj * bpl * 16 * 32);
1303      for (kk = 0; kk < 8; kk++)
1304      {
1305         UINT32 *destline = BITMAP_ADDR32(bitmap, jj * 8 + kk, 0);
1306
1307         /* Clear buffers */
1308         memset(scanlines[SNES_MAINSCREEN].buffer, 0, SNES_SCR_WIDTH * 2);
1309         memset(scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1310         for (ii = 0; ii < 32; ii++)
1311         {
1312            switch (bpl)
1313            {
1314               case 1:
1315                  snes_draw_tile(SNES_MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal, 0);
1316                  break;
1317               case 2:
1318                  snes_draw_tile(SNES_MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal, 0);
1319                  break;
1320               case 4:
1321                  snes_draw_tile(SNES_MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal, 0);
1322                  break;
1323            }
1324            addr += (bpl * 16);
1325         }
1326         for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
1327         {
1328            int pixdata = scanlines[SNES_MAINSCREEN].buffer[ii];
1329            if (pixdata != 200)
1330               destline[ii] = machine->pens[pixdata];
1331         }
1332         addr -= (32 * (bpl * 16)) - 2;
1333      }
1334   }
1335
1336   logerror("  %8X  ", tileaddr );
1337   //ui_draw_text( str, 0, 227 );
1338}
1339
13401262static UINT8 snes_dbg_video( running_machine *machine, bitmap_t *bitmap, UINT16 curline )
13411263{
1342   UINT16 ii;
1343
1344#define SNES_DBG_HORZ_POS 545
1345
13461264   /* Check if the user has enabled or disabled stuff */
13471265   if (curline == 0)
13481266   {
r7309r7310
13631281         if (toggles & 0x10)
13641282            debug_options.bg_disabled[4] = !debug_options.bg_disabled[4];
13651283         if (toggles & 0x20)
1366            debug_options.draw_SNES_SUBSCREEN = !debug_options.draw_SNES_SUBSCREEN;
1284            debug_options.draw_subscreen = !debug_options.draw_subscreen;
13671285         if (toggles & 0x40)
13681286            debug_options.bg_disabled[5] = !debug_options.bg_disabled[5];
13691287         if (toggles & 0x80)
r7309r7310
14931411      logerror("       X %5d Y %5d", snes_ppu.mode7.origin_x, snes_ppu.mode7.origin_y );
14941412      //ui_draw_text( t, SNES_DBG_HORZ_POS, y++ * 9 );
14951413   }
1496   /* Just for testing, draw as many tiles as possible */
1497   {
1498      UINT8 adjust = input_port_read(machine, "PAD1H");
1499      UINT8 dip = input_port_read_safe(machine, "DEBUG1", 0);
1500      UINT8 inp = input_port_read_safe(machine, "DEBUG3", 0);
1501      UINT8 dt = 1 << ((dip & 0x3) - 1);
1502      UINT8 dm = 1 << (((dip & 0xc) >> 2) - 1);
1503      if (dt)
1504      {
1505         static INT16 pal = 0;
1506         static UINT32 addr = 0;
1507         if (curline == 0)
1508         {
1509            if (adjust & 0x1) addr += (dt * 16);
1510            if (adjust & 0x2) addr -= (dt * 16);
1511            if (adjust & 0x4) addr += (dt * 16 * 32);
1512            if (adjust & 0x8) addr -= (dt * 16 * 32);
1513            if (inp & 0x1) pal -= 1;
1514            if (inp & 0x2) pal += 1;
1515            if (pal < 0) pal = 0;
1516            if (pal > 8) pal = 8;
1517            for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
1518            {
1519               scanlines[SNES_MAINSCREEN].buffer[ii] = 0;
1520            }
1521            snes_dbg_draw_all_tiles(machine, bitmap, addr, dt, pal * 16 );
1522         }
1523         return 1;
1524      }
1525      if (dm)
1526      {
1527         static UINT32 tmaddr = 0;
1528         static INT8 tmbg = 0;
1529         UINT32 *destline = BITMAP_ADDR32(bitmap, curline, 0);
1530         if (curline == 0)
1531         {
1532            if (adjust & 0x1) tmaddr += 2;
1533            if (adjust & 0x2) tmaddr -= 2;
1534            if (adjust & 0x4) tmaddr += 64;
1535            if (adjust & 0x8) tmaddr -= 64;
1536            if (inp & 0x1) tmbg -= 1;
1537            if (inp & 0x2) tmbg += 1;
1538            if (tmbg < 0) tmbg = 0;
1539            if (tmbg > 3) tmbg = 3;
1540         }
1541         /* Clear zbuffer */
1542         memset( scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH );
1543         /* Draw back colour */
1544         for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
1545            scanlines[SNES_MAINSCREEN].buffer[ii] = machine->pens[0];
1546         snes_dbg_draw_maps(bitmap, tmaddr, dm, curline, tmbg );
1547         for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
1548         {
1549            int pixdata = scanlines[SNES_MAINSCREEN].buffer[ii];
1550            if (pixdata != 200)
1551               destline[ii] = machine->pens[pixdata];
1552         }
1553         return 1;
1554      }
1555   }
1556#if 0   // 2009-08 FP: what was the purpose of these lines?
1557         /* Draw some useful information about the back/fixed colours and current bg mode etc. */
1558         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 26) = machine->pens[dbg_mode_colours[(snes_ram[CGWSEL] & 0xc0) >> 6]];
1559         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 24) = machine->pens[dbg_mode_colours[(snes_ram[CGWSEL] & 0x30) >> 4]];
1560         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 22) = machine->pens[dbg_mode_colours[snes_ram[BGMODE] & 0x7]];
1561         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 12) = machine->pens[32767];
1562         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 2 ) = machine->pens[32767];
1563         for (ii = 0; ii < 5; ii++)
1564         {
1565         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 19 + ii) = snes_cgram[0];
1566         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 9  + ii) = snes_cgram[FIXED_COLOUR];
1567         }
1568         /* Draw window positions */
1569         scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH0]] = machine->pens[dbg_mode_colours[0]];
1570         scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH1]] = machine->pens[dbg_mode_colours[0]];
1571         scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH2]] = machine->pens[dbg_mode_colours[2]];
1572         scanlines[SNES_MAINSCREEN].buffer[snes_ram[WH3]] = machine->pens[dbg_mode_colours[2]];
1573#endif
1414
15741415   return 0;
15751416}
15761417

Previous 15994 Revisions Next


© 1998-2018 The MESS Team