Previous 15994 Revisions Next

r7518 Saturday 6th March, 2010 at 11:04:21 UTC by Fabio Priuli
[SNES] Fixed remaining issues in hires modes
[src/mame/video]snes.c

src/mame/video/snes.c
r7517r7518
136136 * between the main and sub screens.
137137 *****************************************/
138138
139INLINE void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
139INLINE void snes_draw_blend( UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip, int switch_screens )
140140{
141   /* when color math is applied to subscreen pixels, the blending depends on the blending used by the previous mainscreen
142   pixel, except for subscreen pixel 0 which has no previous mainscreen pixel, see comments in snes_refresh_scanline */
143   if (switch_screens && offset > 0)
144      offset -= 1;
145
141146   if ((black_pen_clip == SNES_CLIP_ALL2) ||
142147      (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) ||
143148      (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset]))
r7517r7518
154159      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset]))
155160   {
156161      UINT16 r, g, b;
162      struct SCANLINE *subscreen;
157163      int clip_max = 0;   // if add then clip to 0x1f, if sub then clip to 0
158164
165#ifdef SNES_LAYER_DEBUG
166      /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */
167      if (debug_options.draw_subscreen)
168      {
169         subscreen = switch_screens ? &scanlines[SNES_SUBSCREEN] : &scanlines[SNES_MAINSCREEN];
170      }
171      else
172#endif /* SNES_LAYER_DEBUG */
173      {
174         subscreen = switch_screens ? &scanlines[SNES_MAINSCREEN] : &scanlines[SNES_SUBSCREEN];
175      }
176
159177      if (snes_ppu.sub_add_mode) /* SNES_SUBSCREEN*/
160178      {
161179         if (!BIT(snes_ppu.color_modes, 7))
162180         {
163181            /* 0x00 add */
164            r = (*colour & 0x1f) + (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f);
165            g = ((*colour & 0x3e0) >> 5) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
166            b = ((*colour & 0x7c00) >> 10) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
182            r = (*colour & 0x1f) + (subscreen->buffer[offset] & 0x1f);
183            g = ((*colour & 0x3e0) >> 5) + ((subscreen->buffer[offset] & 0x3e0) >> 5);
184            b = ((*colour & 0x7c00) >> 10) + ((subscreen->buffer[offset] & 0x7c00) >> 10);
167185            clip_max = 1;
168186         }
169187         else
170188         {
171189            /* 0x80 sub */
172            r = (*colour & 0x1f) - (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f);
173            g = ((*colour & 0x3e0) >> 5) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
174            b = ((*colour & 0x7c00) >> 10) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
190            r = (*colour & 0x1f) - (subscreen->buffer[offset] & 0x1f);
191            g = ((*colour & 0x3e0) >> 5) - ((subscreen->buffer[offset] & 0x3e0) >> 5);
192            b = ((*colour & 0x7c00) >> 10) - ((subscreen->buffer[offset] & 0x7c00) >> 10);
175193            if (r > 0x1f) r = 0;
176194            if (g > 0x1f) g = 0;
177195            if (b > 0x1f) b = 0;
178196         }
179197         /* only halve if the color is not the back colour */
180         if (BIT(snes_ppu.color_modes, 6) && (scanlines[SNES_SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
198         if (BIT(snes_ppu.color_modes, 6) && (subscreen->buffer[offset] != snes_cgram[FIXED_COLOUR]))
181199         {
182200            r >>= 1;
183201            g >>= 1;
r7517r7518
13681386   UINT16 ii;
13691387   int x;
13701388   int fade;
1371   struct SCANLINE *scanline;
1389   struct SCANLINE *scanline1, *scanline2;
13721390   UINT16 c;
13731391
13741392   profiler_mark_start(PROFILER_VIDEO);
r7517r7518
14201438
14211439      /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */
14221440      if (debug_options.draw_subscreen)
1423         scanline = &scanlines[SNES_SUBSCREEN];
1441      {
1442         scanline1 = &scanlines[SNES_SUBSCREEN];
1443         scanline2 = &scanlines[SNES_MAINSCREEN];
1444      }
14241445      else
14251446#endif /* SNES_LAYER_DEBUG */
1426         scanline = &scanlines[SNES_MAINSCREEN];
1447      {
1448         scanline1 = &scanlines[SNES_MAINSCREEN];
1449         scanline2 = &scanlines[SNES_SUBSCREEN];
1450      }
14271451
14281452      /* Phew! Draw the line to screen */
14291453      fade = snes_ppu.screen_brightness;
r7517r7518
14311455      for (x = 0; x < SNES_SCR_WIDTH; x++)
14321456      {
14331457         int r, g, b, hires;
1434         UINT16 temp_col;
14351458         hires = (snes_ppu.mode != 5 && snes_ppu.mode != 6) ? 0 : 1;
1436         c = scanline->buffer[x];
1437         temp_col = scanline->buffer[x];
1459         c = scanline1->buffer[x];
14381460
14391461         /* perform color math if the layer wants it (except if it's an object > 192) */
1440         if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1441            snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1462         if (!scanline1->blend_exception[x] && snes_ppu.layer[scanline1->layer[x]].color_math)
1463            snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask, 0);
14421464
14431465         r = ((c & 0x1f) * fade) >> 4;
14441466         g = (((c & 0x3e0) >> 5) * fade) >> 4;
14451467         b = (((c & 0x7c00) >> 10) * fade) >> 4;
14461468
1447         *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1469         *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
14481470
1471         /* in hires, the first pixel (of 512) is subscreen pixel, then the first mainscreen pixel follows, and so on... */
14491472         if (!hires)
1450            *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1473            *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
14511474         else
14521475         {
1453            c = scanlines[SNES_SUBSCREEN].buffer[x];
1454            scanlines[SNES_SUBSCREEN].buffer[x] = temp_col;
1476            c = scanline2->buffer[x];
14551477
1456            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1457               snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1478            /* in hires, subscreen pixels are blended as well: for each subscreen pixel, color math is applied if
1479            it had been applied to the previous mainscreen pixel. What happens at subscreen pixel 0 (which has no
1480            previous mainscreen pixel) is undocumented. Until more info are discovered, we (arbitrarily) apply to it
1481            the same color math as the *next* mainscreen pixel (i.e. mainscreen pixel 0) */
14581482
1483            if (x == 0 && !scanline1->blend_exception[0] && snes_ppu.layer[scanline1->layer[0]].color_math)
1484               snes_draw_blend(0, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask, 1);
1485            else if (x > 0  && !scanline1->blend_exception[x - 1] && snes_ppu.layer[scanline1->layer[x - 1]].color_math)
1486               snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask, 1);
1487
1488
14591489            r = ((c & 0x1f) * fade) >> 4;
14601490            g = (((c & 0x3e0) >> 5) * fade) >> 4;
14611491            b = (((c & 0x7c00) >> 10) * fade) >> 4;
14621492
1463            *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1493            *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
14641494         }
14651495      }
14661496   }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team