Previous 15994 Revisions Next

r7302 Wednesday 10th February, 2010 at 10:15:07 UTC by Fabio Priuli
[SNES] added another couple of registers to snes_ppu struct and fixed color math to work like docs prescribe
[src/mame/includes]snes.h
[src/mame/machine]snes.c
[src/mame/video]snes.c

src/mame/machine/snes.c
r7301r7302
12521252         break;
12531253      case CGADSUB:   /* Addition/Subtraction designation for each screen */
12541254         snes_ppu.color_modes = data & 0xc0;
1255         {
1256            UINT8 sub = (data & 0x80) >> 7;
1257            snes_ppu.layer[SNES_BG1].blend = (data & 0x1) << sub;
1258            snes_ppu.layer[SNES_BG2].blend = ((data & 0x2) >> 1) << sub;
1259            snes_ppu.layer[SNES_BG3].blend = ((data & 0x4) >> 2) << sub;
1260            snes_ppu.layer[SNES_BG4].blend = ((data & 0x8) >> 3) << sub;
1261            snes_ppu.layer[SNES_OAM].blend = ((data & 0x10) >> 4) << sub;
1262         } break;
1255         snes_ppu.layer[SNES_BG1].color_math = data & 0x01;
1256         snes_ppu.layer[SNES_BG2].color_math = data & 0x02;
1257         snes_ppu.layer[SNES_BG3].color_math = data & 0x04;
1258         snes_ppu.layer[SNES_BG4].color_math = data & 0x08;
1259         snes_ppu.layer[SNES_OAM].color_math = data & 0x10;
1260         snes_ppu.colour.color_math = data & 0x20;
1261         break;
12631262      case COLDATA:   /* Fixed colour data for fixed colour addition/subtraction */
12641263         {
12651264            /* Store it in the extra space we made in the CGRAM. It doesn't really go there, but it's as good a place as any. */
src/mame/includes/snes.h
r7301r7302
450450{
451451   struct
452452   {
453      UINT8 blend;
453      UINT8 color_math;
454454      UINT32 data;
455455      UINT32 map;
456456      UINT8 map_size;
r7301r7302
477477      UINT8 window1_enabled, window1_invert;
478478      UINT8 window2_enabled, window2_invert;
479479      UINT8 wlog_mask;
480      UINT8 color_math;
480481   } colour;   // this is for the color (which is 'seen' as a layer by the window masking code)
481482
482483   struct
src/mame/video/snes.c
r7301r7302
7474#include "profiler.h"
7575#include "includes/snes.h"
7676
77#define MAINSCREEN      0
78#define SUBSCREEN       1
79#define SNES_BLEND_NONE 0
80#define SNES_BLEND_ADD  1
81#define SNES_BLEND_SUB  2
82#define SNES_CLIP_ALL   0
83#define SNES_CLIP_IN    1
84#define SNES_CLIP_OUT   2
85#define SNES_CLIP_ALL2  3
77#define SNES_MAINSCREEN    0
78#define SNES_SUBSCREEN     1
79#define SNES_CLIP_ALL      0
80#define SNES_CLIP_IN       1
81#define SNES_CLIP_OUT      2
82#define SNES_CLIP_ALL2     3
8683
8784#ifdef MAME_DEBUG
8885struct DEBUGOPTS
r7301r7302
9087   UINT8 input_count;
9188   UINT8 bg_disabled[6];
9289   UINT8 mode_disabled[8];
93   UINT8 draw_subscreen;
90   UINT8 draw_SNES_SUBSCREEN;
9491   UINT8 windows_disabled;
9592   UINT8 transparency_disabled;
9693};
r7301r7302
137134 * Routine for additive/subtractive blending
138135 * between the main and sub screens.
139136 *****************************************/
140INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 mode, UINT8 clip, UINT8 black_pen_clip )
137INLINE void snes_draw_blend(UINT16 offset, UINT16 *colour, UINT8 clip, UINT8 black_pen_clip )
141138{
142   if( (black_pen_clip == SNES_CLIP_ALL2) ||
139   if ((black_pen_clip == SNES_CLIP_ALL2) ||
143140      (black_pen_clip == SNES_CLIP_IN && snes_ppu.clipmasks[SNES_COLOR][offset]) ||
144141      (black_pen_clip == SNES_CLIP_OUT && !snes_ppu.clipmasks[SNES_COLOR][offset]))
145142      *colour = 0; //clip to black before color math
r7301r7302
148145      return;
149146
150147#ifdef MAME_DEBUG
151   if( !debug_options.transparency_disabled )
148   if (!debug_options.transparency_disabled)
152149#endif /* MAME_DEBUG */
153   if( (clip == SNES_CLIP_ALL) ||
150   if ((clip == SNES_CLIP_ALL) ||
154151      (clip == SNES_CLIP_IN  && !snes_ppu.clipmasks[SNES_COLOR][offset]) ||
155      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset]) )
152      (clip == SNES_CLIP_OUT && snes_ppu.clipmasks[SNES_COLOR][offset]))
156153   {
157154      UINT16 r, g, b;
155      int clip_max = 0;   // if add then clip to 0x1f, if sub then clip to 0
158156
159      if( mode == SNES_BLEND_ADD )
157      if (snes_ppu.sub_add_mode) /* SNES_SUBSCREEN*/
160158      {
161         if( snes_ppu.sub_add_mode ) /* Subscreen*/
159         switch (snes_ppu.color_modes & 0x80)
162160         {
163            r = (*colour & 0x1f) + (scanlines[SUBSCREEN].buffer[offset] & 0x1f);
164            g = ((*colour & 0x3e0) >> 5) + ((scanlines[SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
165            b = ((*colour & 0x7c00) >> 10) + ((scanlines[SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
166
167            /* don't halve for the back colour */
168            if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
169            {
170               r >>= 1;
171               g >>= 1;
172               b >>= 1;
173            }
161         case 0x00:   /* add */
162            r = (*colour & 0x1f) + (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f);
163            g = ((*colour & 0x3e0) >> 5) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
164            b = ((*colour & 0x7c00) >> 10) + ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
165            clip_max = 1;
166            break;
167         case 0x80:   /* sub */
168            r = (*colour & 0x1f) - (scanlines[SNES_SUBSCREEN].buffer[offset] & 0x1f);
169            g = ((*colour & 0x3e0) >> 5) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
170            b = ((*colour & 0x7c00) >> 10) - ((scanlines[SNES_SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
171            if (r > 0x1f) r = 0;
172            if (g > 0x1f) g = 0;
173            if (b > 0x1f) b = 0;
174            break;
174175         }
175         else /* Fixed colour */
176         /* only halve if the color is not the back colour */
177         if ((snes_ppu.color_modes & 0x40) && (scanlines[SNES_SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
176178         {
177            r = (*colour & 0x1f) + (snes_cgram[FIXED_COLOUR] & 0x1f);
178            g = ((*colour & 0x3e0) >> 5) + ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
179            b = ((*colour & 0x7c00) >> 10) + ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
180
181            /* don't halve for the back colour */
182            if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
183            {
184               r >>= 1;
185               g >>= 1;
186               b >>= 1;
187            }
179            r >>= 1;
180            g >>= 1;
181            b >>= 1;
188182         }
189         if( r > 0x1f ) r = 0x1f;
190         if( g > 0x1f ) g = 0x1f;
191         if( b > 0x1f ) b = 0x1f;
192         *colour = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
193183      }
194      else if( mode == SNES_BLEND_SUB )
184      else /* Fixed colour */
195185      {
196         if( snes_ppu.sub_add_mode ) /* Subscreen */
186         switch (snes_ppu.color_modes & 0x80)
197187         {
198            r = (*colour & 0x1f) - (scanlines[SUBSCREEN].buffer[offset] & 0x1f);
199            g = ((*colour & 0x3e0) >> 5) - ((scanlines[SUBSCREEN].buffer[offset] & 0x3e0) >> 5);
200            b = ((*colour & 0x7c00) >> 10) - ((scanlines[SUBSCREEN].buffer[offset] & 0x7c00) >> 10);
201            if( r > 0x1f ) r = 0;
202            if( g > 0x1f ) g = 0;
203            if( b > 0x1f ) b = 0;
204
205            /* don't halve for the back colour */
206            if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
207            {
208               r >>= 1;
209               g >>= 1;
210               b >>= 1;
211            }
212         }
213         else /* Fixed colour */
214         {
188         case 0x00:   /* add */
189            r = (*colour & 0x1f) + (snes_cgram[FIXED_COLOUR] & 0x1f);
190            g = ((*colour & 0x3e0) >> 5) + ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
191            b = ((*colour & 0x7c00) >> 10) + ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
192            clip_max = 1;
193            break;
194         case 0x80:   /* sub */
215195            r = (*colour & 0x1f) - (snes_cgram[FIXED_COLOUR] & 0x1f);
216196            g = ((*colour & 0x3e0) >> 5) - ((snes_cgram[FIXED_COLOUR] & 0x3e0) >> 5);
217197            b = ((*colour & 0x7c00) >> 10) - ((snes_cgram[FIXED_COLOUR] & 0x7c00) >> 10);
218            if( r > 0x1f ) r = 0;
219            if( g > 0x1f ) g = 0;
220            if( b > 0x1f ) b = 0;
221
222            /* don't halve for the back colour */
223            if ((snes_ppu.color_modes & 0x40) && (scanlines[SUBSCREEN].zbuf[offset] || scanlines[SUBSCREEN].buffer[offset] != snes_cgram[FIXED_COLOUR]))
224            {
225               r >>= 1;
226               g >>= 1;
227               b >>= 1;
228            }
198            if (r > 0x1f) r = 0;
199            if (g > 0x1f) g = 0;
200            if (b > 0x1f) b = 0;
201            break;
229202         }
230         *colour = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
203         /* halve if necessary */
204         if (snes_ppu.color_modes & 0x40)
205         {
206            r >>= 1;
207            g >>= 1;
208            b >>= 1;
209         }
231210      }
211
212      /* according to anomie's docs, after addition has been performed, division by 2 happens *before* clipping to max, hence we clip now */
213      if (clip_max)
214      {
215         if (r > 0x1f) r = 0x1f;
216         if (g > 0x1f) g = 0x1f;
217         if (b > 0x1f) b = 0x1f;
218      }
219
220      *colour = ((r & 0x1f) | ((g & 0x1f) << 5) | ((b & 0x1f) << 10));
232221   }
233222}
234223
r7301r7302
274263      }
275264
276265#ifdef MAME_DEBUG
277      if(!debug_options.windows_disabled)
266      if (!debug_options.windows_disabled)
278267#endif /* MAME_DEBUG */
279268      /* Clip to windows */
280      window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
269      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
281270      if (window_enabled)
282271         colour &= snes_ppu.clipmasks[layer][ii];
283272
r7301r7302
286275      {
287276         if ((scanlines[screen].zbuf[ii] <= priority) && (ii >= 0))
288277         {
289            if(direct_colors)
278            if (direct_colors)
290279            {
291280               /* format is  0 | BBb00 | GGGg0 | RRRr0, HW confirms that the data is zero padded. */
292281               c = ((colour & 0x07) << 2) | ((colour & 0x38) << 4) | ((colour & 0xc0) << 7);
r7301r7302
295284            else
296285               c = snes_cgram[pal + colour];
297286
298            if (screen == MAINSCREEN)   /* Only blend main screens */
299               snes_draw_blend(ii/snes_htmult, &c, snes_ppu.layer[layer].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
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);
300290            if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
301291            {
302292               int x_mos;
r7301r7302
326316 *****************************************/
327317INLINE void snes_draw_tile_x2(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors )
328318{
329   if( flip )
319   if (flip)
330320   {
331321      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors);
332322      snes_draw_tile(screen, planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors);
r7301r7302
385375      if (!debug_options.windows_disabled)
386376#endif /* MAME_DEBUG */
387377      /* Clip to windows */
388      window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[4].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled;
378      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[4].main_window_enabled : snes_ppu.layer[SNES_OAM].sub_window_enabled;
389379      if (window_enabled)
390380         colour &= snes_ppu.clipmasks[SNES_OAM][ii];
391381
r7301r7302
395385         if (ii >= 0)
396386         {
397387            c = snes_cgram[pal + colour];
398            if (blend && screen == MAINSCREEN)   /* Only blend main screens */
399               snes_draw_blend(ii/snes_htmult, &c, snes_ppu.layer[SNES_OAM].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
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);
400390
401391            scanlines[screen].buffer[ii] = c;
402392            scanlines[screen].zbuf[ii] = priority;
r7301r7302
445435   if (snes_ppu.layer[layer].mosaic_enabled)
446436      curline -= (curline % (snes_ppu.mosaic_size + 1));
447437
448   if((snes_ppu.interlace == 2) && !hires)
449      curline/=2;
438   if ((snes_ppu.interlace == 2) && !hires)
439      curline /= 2;
450440
451441   /* Find the size of the tiles (8x8 or 16x16) */
452442   tile_size = snes_ppu.layer[layer].tile_size;
r7301r7302
465455      vtilescroll++;   /* pretend we scrolled by 1 tile line */
466456      line -= (8 << tile_size);
467457   }
468   if( vtilescroll >= 128 )
458   if (vtilescroll >= 128)
469459      vtilescroll -= 128;
470460
471461   /* Jump to base map address */
r7301r7302
708698         colour &= 0x7f;
709699      }
710700
711      window_enabled = (screen == MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
701      window_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.layer[layer].main_window_enabled : snes_ppu.layer[layer].sub_window_enabled;
712702      if (window_enabled)
713703         colour &= snes_ppu.clipmasks[layer][xpos];
714704
r7301r7302
725715         else
726716            clr = snes_cgram[colour];
727717         /* Only blend main screens */
728         if (screen == MAINSCREEN)
729            snes_draw_blend(xpos, &clr, snes_ppu.layer[layer].blend, snes_ppu.sub_color_mask, snes_ppu.main_color_mask); /* FIXME: Need to support clip mode */
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 */
730720
731721         scanlines[screen].buffer[xpos] = clr;
732722         scanlines[screen].zbuf[xpos] = priority;
r7301r7302
766756   };
767757
768758#ifdef MAME_DEBUG
769   if( debug_options.bg_disabled[4] )
759   if (debug_options.bg_disabled[4])
770760      return;
771761#endif /* MAME_DEBUG */
772762
773   if( snes_ppu.mode == 5 || snes_ppu.mode == 6 )
763   if (snes_ppu.mode == 5 || snes_ppu.mode == 6)
774764      widemode = 1;
775765
776766   curline/=snes_ppu.interlace;
r7301r7302
779769   oam = 0x1ff;
780770   oam_extra = oam + 0x20;
781771   extra = 0;
782   for( i = 128; i > 0; i-- )
772   for (i = 128; i > 0; i--)
783773   {
784      if( (i % 4) == 0 )
774      if ((i % 4) == 0)
785775         extra = oamram[oam_extra--];
786776
787777      vflip = (oamram[oam] & 0x80) >> 7;
r7301r7302
799789      y*=snes_ppu.obj_interlace;
800790
801791      /* Adjust if past maximum position */
802      if( y >= snes_ppu.beam.last_visible_line*snes_ppu.interlace )
792      if (y >= snes_ppu.beam.last_visible_line*snes_ppu.interlace)
803793         y -= 256*snes_ppu.interlace;
804      if( x > 255 )
794      if (x > 255)
805795         x -= 512;
806796
807797      /* Draw sprite if it intersects the current line */
808      if( curline >= y && curline < (y + (snes_ppu.oam.size[size] << 3)) )
798      if (curline >= y && curline < (y + (snes_ppu.oam.size[size] << 3)))
809799      {
810800         /* Only objects using palettes 4-7 can be transparent */
811801         blend = (pal < 192) ? 0 : 1;
r7301r7302
815805
816806         ys = (curline - y) >> 3;
817807         line = (curline - y) % 8;
818         if( vflip )
808         if (vflip)
819809         {
820810            ys = snes_ppu.oam.size[size] - ys - 1;
821811            line = (-1 * line) + 7;
822812         }
823813         line <<= 1;
824814         tile <<= 5;
825         if( hflip )
815         if (hflip)
826816         {
827817            UINT8 count = 0;
828            for( xs = (snes_ppu.oam.size[size] - 1); xs >= 0; xs-- )
818            for (xs = (snes_ppu.oam.size[size] - 1); xs >= 0; xs--)
829819            {
830               if( (x + (count << 3) < SNES_SCR_WIDTH + 8) )
820               if ((x + (count << 3) < SNES_SCR_WIDTH + 8))
831821               {
832                  if( widemode )
822                  if (widemode)
833823                     snes_draw_tile_object(screen, snes_ppu.layer[SNES_OAM].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, 1);
834824                  else
835825                     snes_draw_tile_object(screen, snes_ppu.layer[SNES_OAM].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (count++ << 3), priority, hflip, pal, blend, 0);
r7301r7302
839829         }
840830         else
841831         {
842            for( xs = 0; xs < snes_ppu.oam.size[size]; xs++ )
832            for (xs = 0; xs < snes_ppu.oam.size[size]; xs++)
843833            {
844               if( (x + (xs << 3) < SNES_SCR_WIDTH + 8) )
834               if ((x + (xs << 3) < SNES_SCR_WIDTH + 8))
845835               {
846                  if( widemode )
836                  if (widemode)
847837                     snes_draw_tile_object(screen, snes_ppu.layer[SNES_OAM].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, 1);
848838                  else
849839                     snes_draw_tile_object(screen, snes_ppu.layer[SNES_OAM].data + name_sel + tile + table_obj_offset[ys][xs] + line, x + (xs << 3), priority, hflip, pal, blend, 0);
r7301r7302
880870static void snes_update_mode_0( UINT8 screen, UINT16 curline )
881871{
882872   UINT8 *bg_enabled;
883   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
873   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
884874
885875   if (bg_enabled[4]) snes_update_objects(screen, 0, curline);
886876   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_2BPP, 0, 7, 10, 0, curline, 0, 0);
r7301r7302
892882static void snes_update_mode_1( UINT8 screen, UINT16 curline )
893883{
894884   UINT8 *bg_enabled;
895   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
885   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
896886
897887   if (!snes_ppu.bg3_priority_bit)
898888   {
r7301r7302
913903static void snes_update_mode_2( UINT8 screen, UINT16 curline )
914904{
915905   UINT8 *bg_enabled;
916   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
906   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
917907
918908   if (bg_enabled[4]) snes_update_objects(screen, 2, curline);
919909   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 0, 2, 6, 0, curline, 1, 0);
r7301r7302
923913static void snes_update_mode_3( UINT8 screen, UINT16 curline )
924914{
925915   UINT8 *bg_enabled;
926   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
916   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
927917
928918   if (bg_enabled[4]) snes_update_objects(screen, 3, curline);
929919   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color);
r7301r7302
933923static void snes_update_mode_4( UINT8 screen, UINT16 curline )
934924{
935925   UINT8 *bg_enabled;
936   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
926   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
937927
938928   if (bg_enabled[4]) snes_update_objects(screen, 4, curline);
939929   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_8BPP, 0, 2, 6, 0, curline, 0, snes_ppu.direct_color);
r7301r7302
943933static void snes_update_mode_5( UINT8 screen, UINT16 curline )
944934{
945935   UINT8 *bg_enabled;
946   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
936   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
947937
948938   if (bg_enabled[4]) snes_update_objects(screen, 5, curline);
949939   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 2, 6, 0, curline, 0, 0);
r7301r7302
953943static void snes_update_mode_6( UINT8 screen, UINT16 curline )
954944{
955945   UINT8 *bg_enabled;
956   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
946   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
957947
958948   if (bg_enabled[4]) snes_update_objects(screen, 6, curline);
959949   if (bg_enabled[0]) snes_update_line(screen, SNES_COLOR_DEPTH_4BPP, 1, 1, 4, 0, curline, 1, 0);
r7301r7302
962952static void snes_update_mode_7( UINT8 screen, UINT16 curline )
963953{
964954   UINT8 *bg_enabled;
965   bg_enabled = (screen == MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
955   bg_enabled = (screen == SNES_MAINSCREEN) ? snes_ppu.main_bg_enabled : snes_ppu.sub_bg_enabled;
966956
967957   if (!snes_ppu.mode7.extbg)
968958   {
r7301r7302
10601050                  break;
10611051            }
10621052         }
1063         else if( w1 >= 0 )
1053         else if (w1 >= 0)
10641054            snes_ppu.clipmasks[jj][ii] = w1 ? 0x00 : 0xff;
1065         else if( w2 >= 0 )
1055         else if (w2 >= 0)
10661056            snes_ppu.clipmasks[jj][ii] = w2 ? 0x00 : 0xff;
10671057      }
10681058
r7301r7302
11221112static void snes_update_offsets(void)
11231113{
11241114   int ii;
1125   for( ii = 0; ii < 4; ii++ )
1115   for (ii = 0; ii < 4; ii++)
11261116   {
11271117      snes_ppu.layer[ii].offset.tile_horz = (snes_ppu.layer[ii].offset.horizontal & 0x3ff) >> (3 + snes_ppu.layer[ii].tile_size);
11281118      snes_ppu.layer[ii].offset.shift_horz = snes_ppu.layer[ii].offset.horizontal & ((8 << snes_ppu.layer[ii].tile_size) - 1);
r7301r7302
11711161         snes_update_offsets();
11721162
11731163      /* Clear zbuffers */
1174      memset(scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1175      memset(scanlines[SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1164      memset(scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
1165      memset(scanlines[SNES_SUBSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2);
11761166
1177      /* Clear subscreen and draw back colour */
1167      /* Clear SNES_SUBSCREEN and draw back colour */
11781168      for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
11791169      {
11801170         /* Not sure if this is correct behaviour, but a few games seem to
11811171             * require it. (SMW, Zelda etc) */
1182         scanlines[SUBSCREEN].buffer[ii] = snes_cgram[FIXED_COLOUR];
1172         scanlines[SNES_SUBSCREEN].buffer[ii] = snes_cgram[FIXED_COLOUR];
11831173         /* Draw back colour */
1184         scanlines[MAINSCREEN].buffer[ii] = snes_cgram[0];
1174         scanlines[SNES_MAINSCREEN].buffer[ii] = snes_cgram[0];
11851175      }
11861176
1187      /* Draw subscreen */
1188      snes_draw_screen(SUBSCREEN, curline);
1177      /* Draw SNES_SUBSCREEN */
1178      snes_draw_screen(SNES_SUBSCREEN, curline);
11891179
11901180      /* Draw the back plane */
11911181#ifdef MAME_DEBUG
11921182      if (!debug_options.bg_disabled[5])
11931183#endif /* MAME_DEBUG */
1194      if (snes_ram[CGADSUB] & 0x20)
1184      if (snes_ppu.colour.color_math)
11951185      {
1196         for(ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++)
1186         for (ii = 0; ii < SNES_SCR_WIDTH * snes_htmult; ii++)
11971187         {
1198            snes_draw_blend(ii/snes_htmult, &scanlines[MAINSCREEN].buffer[ii], (snes_ppu.color_modes & 0x80) ? SNES_BLEND_SUB : SNES_BLEND_ADD, snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
1188            snes_draw_blend(ii/snes_htmult, &scanlines[SNES_MAINSCREEN].buffer[ii], snes_ppu.sub_color_mask, snes_ppu.main_color_mask);
11991189         }
12001190      }
12011191
1202      /* Draw mainscreen */
1203      snes_draw_screen(MAINSCREEN, curline);
1192      /* Draw SNES_MAINSCREEN */
1193      snes_draw_screen(SNES_MAINSCREEN, curline);
12041194
12051195#ifdef MAME_DEBUG
12061196      if (snes_dbg_video(machine, bitmap, curline))
r7301r7302
12091199         return;
12101200      }
12111201
1212      /* Toggle drawing of subscreen or mainscreen */
1213      if (debug_options.draw_subscreen)
1214         scanline = &scanlines[SUBSCREEN];
1202      /* Toggle drawing of SNES_SUBSCREEN or SNES_MAINSCREEN */
1203      if (debug_options.draw_SNES_SUBSCREEN)
1204         scanline = &scanlines[SNES_SUBSCREEN];
12151205      else
12161206#endif /* MAME_DEBUG */
1217         scanline = &scanlines[MAINSCREEN];
1207         scanline = &scanlines[SNES_MAINSCREEN];
12181208
12191209      /* Phew! Draw the line to screen */
12201210      fade = snes_ppu.screen_brightness;
r7301r7302
12251215         int g = (((scanline->buffer[x] & 0x3e0) >> 5) * fade) >> 4;
12261216         int b = (((scanline->buffer[x] & 0x7c00) >> 10) * fade) >> 4;
12271217
1228         if(snes_htmult == 1)
1218         if (snes_htmult == 1)
12291219         {
12301220            *BITMAP_ADDR32(bitmap, curline, x*2+0) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
12311221            *BITMAP_ADDR32(bitmap, curline, x*2+1) = MAKE_RGB(pal5bit(r), pal5bit(g), pal5bit(b));
r7301r7302
12681258   INT8 line;
12691259
12701260   tmap += (curline >> 3) * 64;
1271   for( ii = 0; ii < 64; ii += 2 )
1261   for (ii = 0; ii < 64; ii += 2)
12721262   {
12731263      vflip = (snes_vram[tmap + ii + 1] & 0x80);
12741264      hflip = snes_vram[tmap + ii + 1] & 0x40;
r7301r7302
12761266      tile = (snes_vram[tmap + ii + 1] & 0x3) << 8;
12771267      tile |= snes_vram[tmap + ii];
12781268      line = curline % 8;
1279      if( vflip )
1269      if (vflip)
12801270         line = -line + 7;
12811271
1282      if( tile != 0 )
1272      if (tile != 0)
12831273      {
1284         switch( bpl )
1274         switch (bpl)
12851275         {
12861276            case 1:
1287               snes_draw_tile(MAINSCREEN, 2, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
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);
12881278               break;
12891279            case 2:
12901280               pal <<= 2;
1291               snes_draw_tile(MAINSCREEN, 4, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
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);
12921282               break;
12931283            case 4:
12941284               pal <<= 0;   // n/a
1295               snes_draw_tile(MAINSCREEN, 8, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal, 0);
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);
12961286               break;
12971287         }
12981288      }
r7301r7302
13071297   UINT16 ii, jj, kk;
13081298   UINT32 addr = tileaddr;
13091299
1310   for( jj = 0; jj < 32; jj++ )
1300   for (jj = 0; jj < 32; jj++)
13111301   {
13121302      addr = tileaddr + (jj * bpl * 16 * 32);
1313      for( kk = 0; kk < 8; kk++ )
1303      for (kk = 0; kk < 8; kk++)
13141304      {
13151305         UINT32 *destline = BITMAP_ADDR32(bitmap, jj * 8 + kk, 0);
13161306
13171307         /* Clear buffers */
1318         memset( scanlines[MAINSCREEN].buffer, 0, SNES_SCR_WIDTH * 2 );
1319         memset( scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH * 2 );
1320         for( ii = 0; ii < 32; ii++ )
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++)
13211311         {
1322            switch( bpl )
1312            switch (bpl)
13231313            {
13241314               case 1:
1325                  snes_draw_tile(MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal, 0);
1315                  snes_draw_tile(SNES_MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal, 0);
13261316                  break;
13271317               case 2:
1328                  snes_draw_tile(MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal, 0);
1318                  snes_draw_tile(SNES_MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal, 0);
13291319                  break;
13301320               case 4:
1331                  snes_draw_tile(MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal, 0);
1321                  snes_draw_tile(SNES_MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal, 0);
13321322                  break;
13331323            }
13341324            addr += (bpl * 16);
13351325         }
13361326         for (ii = 0; ii < SNES_SCR_WIDTH * 2; ii++)
13371327         {
1338            int pixdata = scanlines[MAINSCREEN].buffer[ii];
1328            int pixdata = scanlines[SNES_MAINSCREEN].buffer[ii];
13391329            if (pixdata != 200)
13401330               destline[ii] = machine->pens[pixdata];
13411331         }
r7301r7302
13541344#define SNES_DBG_HORZ_POS 545
13551345
13561346   /* Check if the user has enabled or disabled stuff */
1357   if( curline == 0 )
1347   if (curline == 0)
13581348   {
13591349      //UINT16 y = 1;
13601350      static const char WINLOGIC[4] = { '|', '&', '^', '!' };
13611351
1362      if( !debug_options.input_count-- )
1352      if (!debug_options.input_count--)
13631353      {
13641354         UINT8 toggles = input_port_read_safe(machine, "DEBUG2", 0);
1365         if( toggles & 0x1 )
1355         if (toggles & 0x01)
13661356            debug_options.bg_disabled[0] = !debug_options.bg_disabled[0];
1367         if( toggles & 0x2 )
1357         if (toggles & 0x02)
13681358            debug_options.bg_disabled[1] = !debug_options.bg_disabled[1];
1369         if( toggles & 0x4 )
1359         if (toggles & 0x04)
13701360            debug_options.bg_disabled[2] = !debug_options.bg_disabled[2];
1371         if( toggles & 0x8 )
1361         if (toggles & 0x08)
13721362            debug_options.bg_disabled[3] = !debug_options.bg_disabled[3];
1373         if( toggles & 0x10 )
1363         if (toggles & 0x10)
13741364            debug_options.bg_disabled[4] = !debug_options.bg_disabled[4];
1375         if( toggles & 0x20 )
1376            debug_options.draw_subscreen = !debug_options.draw_subscreen;
1377         if( toggles & 0x40 )
1365         if (toggles & 0x20)
1366            debug_options.draw_SNES_SUBSCREEN = !debug_options.draw_SNES_SUBSCREEN;
1367         if (toggles & 0x40)
13781368            debug_options.bg_disabled[5] = !debug_options.bg_disabled[5];
1379         if( toggles & 0x80 )
1369         if (toggles & 0x80)
13801370            debug_options.windows_disabled = !debug_options.windows_disabled;
13811371         toggles = input_port_read_safe(machine, "DEBUG4", 0);
1382         if( toggles & 0x01 )
1372         if (toggles & 0x01)
13831373            debug_options.mode_disabled[0] = !debug_options.mode_disabled[0];
1384         if( toggles & 0x02 )
1374         if (toggles & 0x02)
13851375            debug_options.mode_disabled[1] = !debug_options.mode_disabled[1];
1386         if( toggles & 0x04 )
1376         if (toggles & 0x04)
13871377            debug_options.mode_disabled[2] = !debug_options.mode_disabled[2];
1388         if( toggles & 0x08 )
1378         if (toggles & 0x08)
13891379            debug_options.mode_disabled[3] = !debug_options.mode_disabled[3];
1390         if( toggles & 0x10 )
1380         if (toggles & 0x10)
13911381            debug_options.mode_disabled[4] = !debug_options.mode_disabled[4];
1392         if( toggles & 0x20 )
1382         if (toggles & 0x20)
13931383            debug_options.mode_disabled[5] = !debug_options.mode_disabled[5];
1394         if( toggles & 0x40 )
1384         if (toggles & 0x40)
13951385            debug_options.mode_disabled[6] = !debug_options.mode_disabled[6];
1396         if( toggles & 0x80 )
1386         if (toggles & 0x80)
13971387            debug_options.mode_disabled[7] = !debug_options.mode_disabled[7];
13981388         toggles = input_port_read_safe(machine, "DEBUG3", 0);
1399         if( toggles & 0x4 )
1389         if (toggles & 0x4)
14001390            debug_options.transparency_disabled = !debug_options.transparency_disabled;
14011391         debug_options.input_count = 5;
14021392      }
r7301r7302
15101500      UINT8 inp = input_port_read_safe(machine, "DEBUG3", 0);
15111501      UINT8 dt = 1 << ((dip & 0x3) - 1);
15121502      UINT8 dm = 1 << (((dip & 0xc) >> 2) - 1);
1513      if( dt )
1503      if (dt)
15141504      {
15151505         static INT16 pal = 0;
15161506         static UINT32 addr = 0;
1517         if( curline == 0 )
1507         if (curline == 0)
15181508         {
1519            if( adjust & 0x1 ) addr += (dt * 16);
1520            if( adjust & 0x2 ) addr -= (dt * 16);
1521            if( adjust & 0x4 ) addr += (dt * 16 * 32);
1522            if( adjust & 0x8 ) addr -= (dt * 16 * 32);
1523            if( inp & 0x1 ) pal -= 1;
1524            if( inp & 0x2 ) pal += 1;
1525            if( pal < 0 ) pal = 0;
1526            if( pal > 8 ) pal = 8;
1527            for( ii = 0; ii < SNES_SCR_WIDTH; ii++ )
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++)
15281518            {
1529               scanlines[MAINSCREEN].buffer[ii] = 0;
1519               scanlines[SNES_MAINSCREEN].buffer[ii] = 0;
15301520            }
15311521            snes_dbg_draw_all_tiles(machine, bitmap, addr, dt, pal * 16 );
15321522         }
15331523         return 1;
15341524      }
1535      if( dm )
1525      if (dm)
15361526      {
15371527         static UINT32 tmaddr = 0;
15381528         static INT8 tmbg = 0;
15391529         UINT32 *destline = BITMAP_ADDR32(bitmap, curline, 0);
1540         if( curline == 0 )
1530         if (curline == 0)
15411531         {
1542            if( adjust & 0x1 ) tmaddr += 2;
1543            if( adjust & 0x2 ) tmaddr -= 2;
1544            if( adjust & 0x4 ) tmaddr += 64;
1545            if( adjust & 0x8 ) tmaddr -= 64;
1546            if( inp & 0x1 ) tmbg -= 1;
1547            if( inp & 0x2 ) tmbg += 1;
1548            if( tmbg < 0 ) tmbg = 0;
1549            if( tmbg > 3 ) tmbg = 3;
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;
15501540         }
15511541         /* Clear zbuffer */
1552         memset( scanlines[MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH );
1542         memset( scanlines[SNES_MAINSCREEN].zbuf, 0, SNES_SCR_WIDTH );
15531543         /* Draw back colour */
1554         for( ii = 0; ii < SNES_SCR_WIDTH; ii++ )
1555            scanlines[MAINSCREEN].buffer[ii] = machine->pens[0];
1544         for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
1545            scanlines[SNES_MAINSCREEN].buffer[ii] = machine->pens[0];
15561546         snes_dbg_draw_maps(bitmap, tmaddr, dm, curline, tmbg );
15571547         for (ii = 0; ii < SNES_SCR_WIDTH; ii++)
15581548         {
1559            int pixdata = scanlines[MAINSCREEN].buffer[ii];
1549            int pixdata = scanlines[SNES_MAINSCREEN].buffer[ii];
15601550            if (pixdata != 200)
15611551               destline[ii] = machine->pens[pixdata];
15621552         }
r7301r7302
15701560         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 22) = machine->pens[dbg_mode_colours[snes_ram[BGMODE] & 0x7]];
15711561         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 12) = machine->pens[32767];
15721562         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 2 ) = machine->pens[32767];
1573         for( ii = 0; ii < 5; ii++ )
1563         for (ii = 0; ii < 5; ii++)
15741564         {
15751565         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 19 + ii) = snes_cgram[0];
15761566         *BITMAP_ADDR32(bitmap, curline, SNES_DBG_HORZ_POS - 9  + ii) = snes_cgram[FIXED_COLOUR];
15771567         }
15781568         /* Draw window positions */
1579         scanlines[MAINSCREEN].buffer[snes_ram[WH0]] = machine->pens[dbg_mode_colours[0]];
1580         scanlines[MAINSCREEN].buffer[snes_ram[WH1]] = machine->pens[dbg_mode_colours[0]];
1581         scanlines[MAINSCREEN].buffer[snes_ram[WH2]] = machine->pens[dbg_mode_colours[2]];
1582         scanlines[MAINSCREEN].buffer[snes_ram[WH3]] = machine->pens[dbg_mode_colours[2]];
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]];
15831573#endif
15841574   return 0;
15851575}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team