Previous 15994 Revisions Next

r7522 Saturday 6th March, 2010 at 18:00:06 UTC by Fabio Priuli
[SNES] slightly simplified palette handling
[src/mame/video]snes.c

src/mame/video/snes.c
r7521r7522
249249 * Draw tiles with variable bit planes
250250 *****************************************/
251251
252INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
252INLINE void snes_draw_tile( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
253253{
254254   UINT8 mask, plane[8];
255255   UINT16 c;
r7521r7522
310310                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
311311                  }
312312                  else
313                     c = snes_cgram[pal + clr];
313                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
314314
315315                  if (snes_ppu.layer[SNES_MAINSCREEN].mosaic_enabled) // handle horizontal mosaic
316316                  {
r7521r7522
359359                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
360360                  }
361361                  else
362                     c = snes_cgram[pal + clr];
362                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
363363
364364                  if (snes_ppu.layer[SNES_SUBSCREEN].mosaic_enabled) // handle horizontal mosaic
365365                  {
r7521r7522
410410                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
411411                  }
412412                  else
413                     c = snes_cgram[pal + clr];
413                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
414414
415415                  if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
416416                  {
r7521r7522
458458                     c |= ((pal & 0x04) >> 1) | ((pal & 0x08) << 3) | ((pal & 0x10) << 8);
459459                  }
460460                  else
461                     c = snes_cgram[pal + clr];
461                     c = snes_cgram[(pal + clr) % FIXED_COLOUR];
462462
463463                  if (snes_ppu.layer[layer].mosaic_enabled) // handle horizontal mosaic
464464                  {
r7521r7522
492492 * Draw 2 tiles with variable bit planes
493493 *****************************************/
494494
495INLINE void snes_draw_tile_x2( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal, UINT8 direct_colors, UINT8 hires )
495INLINE void snes_draw_tile_x2( UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT8 direct_colors, UINT16 pal, UINT8 hires )
496496{
497497   if (flip)
498498   {
499      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x, priority, flip, pal, direct_colors, hires);
500      snes_draw_tile(planes, layer, tileaddr, x + 8, priority, flip, pal, direct_colors, hires);
499      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x, priority, flip, direct_colors, pal, hires);
500      snes_draw_tile(planes, layer, tileaddr, x + 8, priority, flip, direct_colors, pal, hires);
501501   }
502502   else
503503   {
504      snes_draw_tile(planes, layer, tileaddr, x, priority, flip, pal, direct_colors, hires);
505      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal, direct_colors, hires);
504      snes_draw_tile(planes, layer, tileaddr, x, priority, flip, direct_colors, pal, hires);
505      snes_draw_tile(planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, direct_colors, pal, hires);
506506   }
507507}
508508
r7521r7522
564564         {
565565            if ((scanlines[SNES_MAINSCREEN].priority[ii] <= priority) && (ii >= 0))
566566            {
567               c = snes_cgram[pal + clr];
567               c = snes_cgram[(pal + clr) % FIXED_COLOUR];
568568
569569               scanlines[SNES_MAINSCREEN].buffer[ii] = c;
570570               scanlines[SNES_MAINSCREEN].priority[ii] = priority;
r7521r7522
590590         {
591591            if ((scanlines[SNES_SUBSCREEN].priority[ii] <= priority) && (ii >= 0))
592592            {
593               c = snes_cgram[pal + clr];
593               c = snes_cgram[(pal + clr) % FIXED_COLOUR];
594594
595595               scanlines[SNES_SUBSCREEN].buffer[ii] = c;
596596               scanlines[SNES_SUBSCREEN].priority[ii] = priority;
r7521r7522
635635{
636636   UINT32 tmap, tile, xoff, yoff;
637637   UINT32 charaddr;
638   UINT16 ii = 0, vflip, hflip, pal;
638   UINT16 ii = 0, vflip, hflip, pal, pal_direct;
639639   INT8 tile_line;
640640   UINT8 priority;
641   UINT32 addr;
642   UINT16 tilemap;
641643   /* scrolling */
642644   UINT16 opt_bit = (layer == SNES_BG1) ? 13 : (layer == SNES_BG2) ? 14 : 0;
643645   UINT8 vshift, hshift, tile_size;
644646   /* variables depending on color_depth */
645   UINT8 color_shift = 0;
646   UINT8 color_planes = 2;
647   UINT8 tile_divider = 1;
648   UINT32 addr;
649   UINT16 tilemap;
647   UINT8 tile_divider = (color_depth == SNES_COLOR_DEPTH_8BPP) ? 4 : 2;
648   UINT8 color_planes = 2 << color_depth;
649   /* 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) */
650   UINT8 color_shift = 2 << color_depth;
650651
651652#ifdef SNES_LAYER_DEBUG
652653   if (debug_options.bg_disabled[layer])
r7521r7522
685686   tmap = snes_ppu.layer[layer].tilemap << 9;
686687   charaddr = snes_ppu.layer[layer].charmap << 13;
687688
688   /* set a couple of variables depending on color_dept */
689   switch (color_depth)
690   {
691      case SNES_COLOR_DEPTH_2BPP:
692         color_shift = 0;
693         color_planes = 2;
694         tile_divider = 2;
695         break;
696      case SNES_COLOR_DEPTH_4BPP:
697         color_shift = 2;
698         color_planes = 4;
699         tile_divider = 2;
700         break;
701      case SNES_COLOR_DEPTH_8BPP:
702         color_shift = 0;   //n/a, pal offset is always zero
703         color_planes = 8;
704         tile_divider = 4;
705         break;
706   }
707
708689   while (ii < 256)
709690   {
710691      // determine the horizontal position (Bishojo Janshi Suchi Pai & Desert Figther have tile_size & hires == 1)
r7521r7522
763744      vflip = BIT(tilemap, 15);
764745      hflip = BIT(tilemap, 14);
765746      priority = BIT(tilemap, 13) ? priority_b : priority_a;
766      pal = (color_depth == SNES_COLOR_DEPTH_8BPP && direct_colors == 0) ? 0 : ((tilemap & 0x1c00) >> 8) << color_shift;   /* 8 palettes of (4 * color_shift) colours */
747      pal_direct = ((tilemap & 0x1c00) >> 8);
767748      tile = tilemap & 0x03ff;
768749
750      pal = ((pal_direct >> 2) << color_shift);
751
769752      /* Mode 0 palettes are layer specific */
770753      if (snes_ppu.mode == 0)
771754      {
r7521r7522
801784      /* below, only color_planes depends on color_depth */
802785      if (hires)   /* Hi-Res: 2bpp & 4bpp */
803786      {
804         snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii * 2, priority, hflip, pal, direct_colors, hires);
787         snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii * 2, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
805788         ii += 8;
806789      }
807790      else   /* tile_size = 0 */
808791      {
809792         if (tile_size)
810793         {
811            snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
794            snes_draw_tile_x2(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
812795            ii += 16;
813796         }
814797         else   /* No Hi-Res: 2bpp, 4bpp & 8bpp */
815798         {
816            snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, pal, direct_colors, hires);
799            snes_draw_tile(color_planes, layer, charaddr + (tile  * 8 * color_planes) + tile_line, ii, priority, hflip, direct_colors, direct_colors ? pal_direct : pal, hires);
817800            ii += 8;
818801         }
819802      }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team