Previous 15994 Revisions Next

r5359 Thursday 6th August, 2009 at 11:08:21 UTC by Fabio Priuli
SNES video updates, take two:
* further simplification of tile drawing routines
* added palette index to 8bpp tiles (correct color_shift still unsure, though)
[src/mame/video]snes.c

src/mame/video/snes.c
r5358r5359
270270
271271
272272/*****************************************
273 * snes_draw_tile_common()
273 * snes_draw_tile()
274274 *
275275 * Draw tiles with variable bit planes
276276 *****************************************/
277INLINE void snes_draw_tile_common(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
277INLINE void snes_draw_tile(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
278278{
279279   UINT8 mask, plane[8];
280280   UINT16 c;
r5358r5359
347347}
348348
349349/*****************************************
350 * snes_draw_tile_2()
350 * snes_draw_tile_x2()
351351 *
352 * Draw tiles with 2 bit planes(4 colors)
352 * Draw 2 tiles with variable bit planes
353353 *****************************************/
354INLINE void snes_draw_tile_2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
354INLINE void snes_draw_tile_x2(UINT8 screen, UINT8 planes, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
355355{
356   snes_draw_tile_common(screen, 2, layer, tileaddr, x, priority, flip, pal);
357}
358
359/*****************************************
360 * snes_draw_tile_2x2()
361 *
362 * Draw 2 tiles with 2 bit planes(4 colors)
363 *****************************************/
364INLINE void snes_draw_tile_2x2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
365{
366356   if( flip )
367357   {
368      snes_draw_tile_2(screen, layer, tileaddr + 16, x, priority, flip, pal);
369      snes_draw_tile_2(screen, layer, tileaddr, x + 8, priority, flip, pal);
358      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x, priority, flip, pal);
359      snes_draw_tile(screen, planes, layer, tileaddr, x + 8, priority, flip, pal);
370360   }
371361   else
372362   {
373      snes_draw_tile_2(screen, layer, tileaddr, x, priority, flip, pal);
374      snes_draw_tile_2(screen, layer, tileaddr + 16, x + 8, priority, flip, pal);
363      snes_draw_tile(screen, planes, layer, tileaddr, x, priority, flip, pal);
364      snes_draw_tile(screen, planes, layer, tileaddr + (8 * planes), x + 8, priority, flip, pal);
375365   }
376366}
377367
378368/*****************************************
379 * snes_draw_tile_4()
380 *
381 * Draw tiles with 4 bit planes(16 colors)
382 *****************************************/
383INLINE void snes_draw_tile_4(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
384{
385   snes_draw_tile_common(screen, 4, layer, tileaddr, x, priority, flip, pal);
386}
387
388/*****************************************
389 * snes_draw_tile_4x2()
390 *
391 * Draw 2 tiles with 4 bit planes(16 colors)
392 *****************************************/
393INLINE void snes_draw_tile_4x2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip, UINT16 pal )
394{
395   if( flip )
396   {
397      snes_draw_tile_4(screen, layer, tileaddr + 32, x, priority, flip, pal);
398      snes_draw_tile_4(screen, layer, tileaddr, x + 8, priority, flip, pal);
399   }
400   else
401   {
402      snes_draw_tile_4(screen, layer, tileaddr, x, priority, flip, pal);
403      snes_draw_tile_4(screen, layer, tileaddr + 32, x + 8, priority, flip, pal);
404   }
405}
406
407/*****************************************
408 * snes_draw_tile_8()
409 *
410 * Draw tiles with 8 bit planes(256 colors)
411 *****************************************/
412INLINE void snes_draw_tile_8(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip )
413{
414   snes_draw_tile_common(screen, 8, layer, tileaddr, x, priority, flip, 0);
415}
416
417/*****************************************
418 * snes_draw_tile_8x2()
419 *
420 * Draw 2 tiles with 8 bit planes(256 colors)
421 *****************************************/
422INLINE void snes_draw_tile_8x2(UINT8 screen, UINT8 layer, UINT16 tileaddr, INT16 x, UINT8 priority, UINT8 flip )
423{
424   if( flip )
425   {
426      snes_draw_tile_8(screen, layer, tileaddr + 64, x, priority, flip);
427      snes_draw_tile_8(screen, layer, tileaddr, x + 8, priority, flip);
428   }
429   else
430   {
431      snes_draw_tile_8(screen, layer, tileaddr, x, priority, flip);
432      snes_draw_tile_8(screen, layer, tileaddr + 64, x + 8, priority, flip);
433   }
434}
435
436/*****************************************
437369 * snes_draw_tile_object()
438370 *
439371 * Draw tiles with 4 bit planes(16 colors)
r5358r5359
577509   UINT16 vscroll, hscroll, vtilescroll;
578510   UINT8 vshift, hshift, tile_size;
579511   UINT8 bg3_pty = 0;
580   UINT8 color_shift = 0;
581   UINT8 divider = 1;
512   /* variables depending on color_depth */
513   UINT8 color_shift = 0;
514   UINT8 color_planes = 2;
515   UINT8 tile_divider = 1;
582516
583517#ifdef MAME_DEBUG
584518   if (debug_options.bg_disabled[layer])
r5358r5359
630564   switch (color_depth)
631565   {
632566      case SNES_COLOR_DEPTH_2BPP:
633         divider = 2;
634567         color_shift = 0;
568         color_planes = 2;
569         tile_divider = 2;
635570         break;
636571      case SNES_COLOR_DEPTH_4BPP:
637         divider = 2;
638572         color_shift = 2;
573         color_planes = 4;
574         tile_divider = 2;
639575         break;
640576      case SNES_COLOR_DEPTH_8BPP:
641         divider = 4;
642577         color_shift = 6;   // 2009-08 FP: this should be 6 or 8, if I'm following correctly the drawing code
578         color_planes = 8;
579         tile_divider = 4;
643580         break;
644581   }
645582
r5358r5359
680617            }
681618            else
682619            {
683               tile += 32 / divider;
620               tile += 32 / tile_divider;
684621            }
685622         }
686623         tile_line = -tile_line + 7;
r5358r5359
689626      {
690627         if (line > 7)
691628         {
692            tile += 32 / divider;
629            tile += 32 / tile_divider;
693630            tile_line -= 8;
694631         }
695632      }
r5358r5359
699636      if (layer == 2 && bg3_pty && (snes_vram[tmap + ii + 1] & 0x20))
700637         priority = table_obj_pty[snes_ppu.mode][3] + 1;      /* We want to have the highest priority here */
701638
702      /* The code below can probably simplified even more, by directly calling snes_draw_tile_common... */
639      /* below, only color_planes depends on color_depth */
703640      if (tile_size)
704641      {
705642         if (hires)   /* Hi-Res: 2bpp & 4bpp */
706643         {
707644            if (hflip)
708645            {
709               switch (color_depth)
710               {
711               case SNES_COLOR_DEPTH_2BPP:
712                  snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
713                  snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
714                  break;
715               case SNES_COLOR_DEPTH_4BPP:
716                  snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
717                  snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
718                  break;
719               }
646               snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal);
647               snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + ((tile + 2)  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal);
720648            }
721649            else
722650            {
723               switch (color_depth)
724               {
725               case SNES_COLOR_DEPTH_2BPP:
726                  snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
727                  snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
728                  break;
729
730               case SNES_COLOR_DEPTH_4BPP:
731                  snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
732                  snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + ((tile + 2) << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal );
733                  break;
734               }
651               snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal);
652               snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + ((tile + 2)  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1) + 16, priority, hflip, pal);
735653            }
736654         }
737655         else   /* No Hi-Res: 2bpp, 4bpp & 8bpp */
738656         {
739            switch (color_depth)
740            {
741               case SNES_COLOR_DEPTH_2BPP:
742                  snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
743                  break;
744
745               case SNES_COLOR_DEPTH_4BPP:
746                  snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
747                  break;
748
749               case SNES_COLOR_DEPTH_8BPP:
750                  snes_draw_tile_8x2(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip );
751                  break;
752            }
657            snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal);
753658         }
754659      }
755660      else   /* tile_size = 0 */
756661      {
757662         if (hires)   /* Hi-Res: 2bpp & 4bpp */
758         {
759            switch (color_depth)
760            {
761            case SNES_COLOR_DEPTH_2BPP:
762               snes_draw_tile_2x2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
763               break;
764
765            case SNES_COLOR_DEPTH_4BPP:
766               snes_draw_tile_4x2(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal );
767               break;
768            }
769         }
663            snes_draw_tile_x2(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << (tile_size + 1))) - (hshift << 1), priority, hflip, pal);
770664         else   /* No Hi-Res: 2bpp, 4bpp & 8bpp */
771         {
772            switch (color_depth)
773            {
774            case SNES_COLOR_DEPTH_2BPP:
775               snes_draw_tile_2(screen, layer, snes_ppu.layer[layer].data + (tile << 4) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
776               break;
777
778            case SNES_COLOR_DEPTH_4BPP:
779               snes_draw_tile_4(screen, layer, snes_ppu.layer[layer].data + (tile << 5) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal );
780               break;
781
782            case SNES_COLOR_DEPTH_8BPP:
783               snes_draw_tile_8(screen, layer, snes_ppu.layer[layer].data + (tile << 6) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip );
784               break;
785            }
786         }
665            snes_draw_tile(screen, color_planes, layer, snes_ppu.layer[layer].data + (tile  * 8 * color_planes) + tile_line, ((ii >> 1) * (8 << tile_size)) - hshift, priority, hflip, pal);
787666      }
788667   }
789668}
r5358r5359
15361415         switch( bpl )
15371416         {
15381417            case 1:
1539               snes_draw_tile_2(MAINSCREEN, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal );
1418               snes_draw_tile(MAINSCREEN, 2, layer, snes_ppu.layer[layer].data + (tile << 4) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal);
15401419               break;
15411420            case 2:
15421421               pal <<= 2;
1543               snes_draw_tile_4(MAINSCREEN, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal );
1422               snes_draw_tile(MAINSCREEN, 4, layer, snes_ppu.layer[layer].data + (tile << 5) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal);
15441423               break;
15451424            case 4:
1546               snes_draw_tile_8(MAINSCREEN, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip );
1425               pal <<= 6;   // 2009-08 FP: it might be 8... still to investigate
1426               snes_draw_tile(MAINSCREEN, 8, layer, snes_ppu.layer[layer].data + (tile << 6) + ((curline % 8) * 2), (ii >> 1) * 8, 255, hflip, pal);
15471427               break;
15481428         }
15491429      }
r5358r5359
15731453            switch( bpl )
15741454            {
15751455               case 1:
1576                  snes_draw_tile_2(MAINSCREEN, 0, addr, ii * 8, 255, 0, pal );
1456                  snes_draw_tile(MAINSCREEN, 2, 0, addr, ii * 8, 255, 0, pal);
15771457                  break;
15781458               case 2:
1579                  snes_draw_tile_4(MAINSCREEN, 0, addr, ii * 8, 255, 0, pal );
1459                  snes_draw_tile(MAINSCREEN, 4, 0, addr, ii * 8, 255, 0, pal);
15801460                  break;
15811461               case 4:
1582                  snes_draw_tile_8(MAINSCREEN, 0, addr, ii * 8, 255, 0 );
1462                  snes_draw_tile(MAINSCREEN, 8, 0, addr, ii * 8, 255, 0, pal);
15831463                  break;
15841464            }
15851465            addr += (bpl * 16);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team