Previous 15994 Revisions Next

r7316 Wednesday 10th February, 2010 at 23:01:40 UTC by Fabio Priuli
[SNES] wip:
* moved colour struct to be another layer (simplifying some code)
* updated hires blending to work with two pixel at time.
* fixed clipmasks with hires modes
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mame/video]snes.c

src/mame/machine/snes.c
r7315r7316
11581158            snes_ppu.layer[SNES_OAM].window1_enabled = data & 0x02;
11591159            snes_ppu.layer[SNES_OAM].window2_invert = data & 0x04;
11601160            snes_ppu.layer[SNES_OAM].window2_enabled = data & 0x08;
1161            snes_ppu.colour.window1_invert = data & 0x10;
1162            snes_ppu.colour.window1_enabled = data & 0x20;
1163            snes_ppu.colour.window2_invert = data & 0x40;
1164            snes_ppu.colour.window2_enabled = data & 0x80;
1161            snes_ppu.layer[SNES_COLOR].window1_invert = data & 0x10;
1162            snes_ppu.layer[SNES_COLOR].window1_enabled = data & 0x20;
1163            snes_ppu.layer[SNES_COLOR].window2_invert = data & 0x40;
1164            snes_ppu.layer[SNES_COLOR].window2_enabled = data & 0x80;
11651165            snes_ppu.update_windows = 1;
11661166         }
11671167         break;
r7315r7316
12071207         if (data != snes_ram[offset])
12081208         {
12091209            snes_ppu.layer[SNES_OAM].wlog_mask = data & 0x03;
1210            snes_ppu.colour.wlog_mask = (data & 0x0c) >> 2;
1210            snes_ppu.layer[SNES_COLOR].wlog_mask = (data & 0x0c) >> 2;
12111211            snes_ppu.update_windows = 1;
12121212         }
12131213         break;
r7315r7316
12571257         snes_ppu.layer[SNES_BG3].color_math = data & 0x04;
12581258         snes_ppu.layer[SNES_BG4].color_math = data & 0x08;
12591259         snes_ppu.layer[SNES_OAM].color_math = data & 0x10;
1260         snes_ppu.colour.color_math = data & 0x20;
1260         snes_ppu.layer[SNES_COLOR].color_math = data & 0x20;
12611261         break;
12621262      case COLDATA:   /* Fixed colour data for fixed colour addition/subtraction */
12631263         {
r7315r7316
20192019   int i, j;
20202020
20212021   /* Init VRAM */
2022   memset( snes_vram, 0, SNES_VRAM_SIZE );
2022   memset(snes_vram, 0, SNES_VRAM_SIZE );
20232023
20242024   /* Init Colour RAM */
2025   memset( (UINT8 *)snes_cgram, 0, SNES_CGRAM_SIZE);
2025   memset((UINT8 *)snes_cgram, 0, SNES_CGRAM_SIZE);
20262026
20272027   /* Init oam RAM */
2028   memset( snes_oam, 0xff, SNES_OAM_SIZE );
2028   memset(snes_oam, 0xff, SNES_OAM_SIZE );
20292029
20302030   /* Init work RAM - 0x55 isn't exactly right but it's close */
20312031   /* make sure it happens to the 65816 (CPU 0) */
src/mame/includes/snes.h
r7315r7316
2323#define DOTCLK_NTSC   (MCLK_NTSC/4)
2424#define DOTCLK_PAL   (MCLK_PAL/4)
2525
26#define SNES_LAYER_DEBUG 
26#define SNES_LAYER_DEBUG  1
2727
2828/* Debug definitions */
2929#ifdef MAME_DEBUG
r7315r7316
472472         UINT16 tile_vert;
473473         UINT16 shift_vert;
474474      } offset;
475   } layer[5];   // this is for the BG1 - BG2 - BG3 - BG4 - OBJ layers
475   } layer[6];   // this is for the BG1 - BG2 - BG3 - BG4 - OBJ - color layers
476476
477477   struct
478478   {
479      UINT8 window1_enabled, window1_invert;
480      UINT8 window2_enabled, window2_invert;
481      UINT8 wlog_mask;
482      UINT8 color_math;
483   } colour;   // this is for the color (which is 'seen' as a layer by the window masking code)
484
485   struct
486   {
487479      UINT8 address_low;
488480      UINT8 address_high;
489481      UINT8 saved_address_low;
src/mame/video/snes.c
r7315r7316
136136 * Routine for additive/subtractive blending
137137 * between the main and sub screens.
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 factor, UINT8 clip, UINT8 black_pen_clip )
140140{
141141   if ((black_pen_clip == SNES_CLIP_ALL2) ||
142      (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) ||
143      (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset]))
142      (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset / factor]) ||
143      (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset / factor]))
144144      *colour = 0; //clip to black before color math
145145
146146   if (clip == SNES_CLIP_ALL2) // blending mode 3 == always OFF
r7315r7316
150150   if (!debug_options.transparency_disabled)
151151#endif /* SNES_LAYER_DEBUG */
152152   if ((clip == SNES_CLIP_ALL) ||
153      (clip == SNES_CLIP_IN  && !snes_ppu.clipmasks[SNES_COLOR][offset]) ||
154      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset]))
153      (clip == SNES_CLIP_IN  && !snes_ppu.clipmasks[SNES_COLOR][offset / factor]) ||
154      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset / factor]))
155155   {
156156      UINT16 r, g, b;
157157      int clip_max = 0;   // if add then clip to 0x1f, if sub then clip to 0
r7315r7316
223223   }
224224}
225225
226INLINE void snes_draw_blend_lores(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
227{
228   snes_draw_blend(offset, colour, 1, clip, black_pen_clip);
229}
226230
231INLINE void snes_draw_blend_hires(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
232{
233   snes_draw_blend(offset, colour, 2, clip, black_pen_clip);
234}
235
227236/*****************************************
228237 * snes_draw_tile()
229238 *
r7315r7316
10091018
10101019   for (ii = 0; ii < SNES_SCR_WIDTH + 8; ii++)
10111020   {
1012      /* update bg 1, 2, 3, 4 & obj */
1021      /* update bg 1, 2, 3, 4, obj & color windows */
10131022      /* jj = layer */
1014      for (jj = 0; jj < 5; jj++)
1023      for (jj = 0; jj < 6; jj++)
10151024      {
1016         snes_ppu.clipmasks[jj][ii] = 0xff;
1025         snes_ppu.clipmasks[jj][ii] = 0xff;   /* let's start from un-masked */
10171026         w1 = w2 = -1;
1027
10181028         if (snes_ppu.layer[jj].window1_enabled)
10191029         {
1030            /* Default to mask area inside */
10201031            if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right))
10211032               w1 = 0;
10221033            else
10231034               w1 = 1;
1035
1036            /* If mask area is outside then swap */
10241037            if (snes_ppu.layer[jj].window1_invert)
10251038               w1 = !w1;
10261039         }
1040
10271041         if (snes_ppu.layer[jj].window2_enabled)
10281042         {
10291043            if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right))
r7315r7316
10331047            if (snes_ppu.layer[jj].window2_invert)
10341048               w2 = !w2;
10351049         }
1050
1051         /* mask if the appropriate expression is true */
10361052         if (w1 >= 0 && w2 >= 0)
10371053         {
10381054            switch (snes_ppu.layer[jj].wlog_mask)
r7315r7316
10561072         else if (w2 >= 0)
10571073            snes_ppu.clipmasks[jj][ii] = w2 ? 0x00 : 0xff;
10581074      }
1059
1060      /* update colour window */
1061      snes_ppu.clipmasks[SNES_COLOR][ii] = 0xff;
1062      w1 = w2 = -1;
1063      if (snes_ppu.colour.window1_enabled)
1064      {
1065         /* Default to mask area inside */
1066         if ((ii < snes_ppu.window1_left) || (ii > snes_ppu.window1_right))
1067            w1 = 0;
1068         else
1069            w1 = 1;
1070         /* If mask area is outside then swap */
1071         if (snes_ppu.colour.window1_invert)
1072            w1 = !w1;
1073      }
1074      if (snes_ppu.colour.window2_enabled)
1075      {
1076         if ((ii < snes_ppu.window2_left) || (ii > snes_ppu.window2_right))
1077            w2 = 0;
1078         else
1079            w2 = 1;
1080         if (snes_ppu.colour.window2_invert)
1081            w2 = !w2;
1082      }
1083      if (w1 >= 0 && w2 >= 0)
1084      {
1085         switch (snes_ppu.colour.wlog_mask)
1086         {
1087            case 0x0:   /* OR */
1088               snes_ppu.clipmasks[SNES_COLOR][ii] = w1 | w2 ? 0x00 : 0xff;
1089               break;
1090            case 0x4:   /* AND */
1091               snes_ppu.clipmasks[SNES_COLOR][ii] = w1 & w2 ? 0x00 : 0xff;
1092               break;
1093            case 0x8:   /* XOR */
1094               snes_ppu.clipmasks[SNES_COLOR][ii] = w1 ^ w2 ? 0x00 : 0xff;
1095               break;
1096            case 0xc:   /* XNOR */
1097               snes_ppu.clipmasks[SNES_COLOR][ii] = !(w1 ^ w2) ? 0x00 : 0xff;
1098               break;
1099         }
1100      }
1101      else if (w1 >= 0)
1102         snes_ppu.clipmasks[SNES_COLOR][ii] = w1 ? 0x00 : 0xff;
1103      else if (w2 >= 0)
1104         snes_ppu.clipmasks[SNES_COLOR][ii] = w2 ? 0x00 : 0xff;
11051075   }
11061076}
11071077
r7315r7316
12091179      /* Phew! Draw the line to screen */
12101180      fade = snes_ppu.screen_brightness;
12111181
1212      for (x = 0; x < SNES_SCR_WIDTH * 2; x++)
1182      for (x = 0; x < SNES_SCR_WIDTH * 2; x += 2)
12131183      {
1214         int r, g, b;
1215         c = scanline->buffer[x];
1184         if (snes_ppu.mode != 5 && snes_ppu.mode != 6)
1185         {
1186            int r, g, b;
1187            c = scanline->buffer[x];
12161188
1217         /* perform color math if the layer wants it (except if it's an object > 192) */
1218         if (!scanlines[SNES_MAINSCREEN].blend_exception[x] &&
1219            ((scanlines[SNES_MAINSCREEN].layer[x] != SNES_COLOR && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1220            || (scanlines[SNES_MAINSCREEN].layer[x] == SNES_COLOR && snes_ppu.colour.color_math)))
1221            snes_draw_blend(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1189            /* perform color math if the layer wants it (except if it's an object > 192) */
1190            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1191               snes_draw_blend_lores(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
12221192
1223         r = ((c & 0x1f) * fade) >> 4;
1224         g = (((c & 0x3e0) >> 5) * fade) >> 4;
1225         b = (((c & 0x7c00) >> 10) * fade) >> 4;
1193            r = ((c & 0x1f) * fade) >> 4;
1194            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1195            b = (((c & 0x7c00) >> 10) * fade) >> 4;
12261196
1227         if (snes_htmult == 1)
1228         {
12291197            *BITMAP_ADDR32(bitmap, curline, x * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
12301198            *BITMAP_ADDR32(bitmap, curline, x * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1199
1200            c = scanline->buffer[x + 1];
1201
1202            /* perform color math if the layer wants it (except if it's an object > 192) */
1203            if (!scanlines[SNES_MAINSCREEN].blend_exception[x + 1] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x + 1]].color_math)
1204               snes_draw_blend_lores(x + 1, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1205
1206            r = ((c & 0x1f) * fade) >> 4;
1207            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1208            b = (((c & 0x7c00) >> 10) * fade) >> 4;
1209
1210            *BITMAP_ADDR32(bitmap, curline, (x + 1) * 2 + 0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1211            *BITMAP_ADDR32(bitmap, curline, (x + 1) * 2 + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1212
12311213         }
12321214         else
1215         {
1216            int r, g, b;
1217            UINT16 temp_col;
1218            c = scanline->buffer[x];
1219            temp_col = scanline->buffer[x];
1220
1221            /* perform color math if the layer wants it (except if it's an object > 192) */
1222            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1223               snes_draw_blend_hires(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1224
1225            r = ((c & 0x1f) * fade) >> 4;
1226            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1227            b = (((c & 0x7c00) >> 10) * fade) >> 4;
1228
12331229            *BITMAP_ADDR32(bitmap, curline, x) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1230
1231            c = scanlines[SNES_SUBSCREEN].buffer[x];
1232            scanlines[SNES_SUBSCREEN].buffer[x] = temp_col;
1233
1234            /* perform color math only if it's been done on the previous pixel */
1235            if (!scanlines[SNES_MAINSCREEN].blend_exception[x] && snes_ppu.layer[scanlines[SNES_MAINSCREEN].layer[x]].color_math)
1236               snes_draw_blend_hires(x, &c, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1237
1238            r = ((c & 0x1f) * fade) >> 4;
1239            g = (((c & 0x3e0) >> 5) * fade) >> 4;
1240            b = (((c & 0x7c00) >> 10) * fade) >> 4;
1241
1242            *BITMAP_ADDR32(bitmap, curline, x + 1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
1243         }
12341244      }
12351245   }
12361246

Previous 15994 Revisions Next


© 1998-2018 The MESS Team