Previous 15994 Revisions Next

r6722 Wednesday 23rd December, 2009 at 00:41:01 UTC by Barry Rodewald
[FMTOWNS] Basic implementation of sprites.
[src/mess/drivers]fmtowns.c
[src/mess/video]fmtowns.c

src/mess/video/fmtowns.c
r6721r6722
6969 *      YM (bit 2) - unknown
7070 *      peltype (bits 4 and 5)
7171 *
72 *
73 *   Sprite registers:
74 *
75 *    0,1:   Maximum sprite (last one to render?) (10-bit)
76 *
77 *    1 (bit 7):   Enable sprite display
78 *
79 *    2,3:   X offset (9-bit)
80 *
81 *  4,5:   Y offset (9-bit)
82 *
83 *    6 (bit 4):   VRAM location (0=0x40000,1=0x60000)
84 *
7285 */
7386
7487#include "driver.h"
r6721r6722
7790#include "includes/fmtowns.h"
7891
7992//#define CRTC_REG_DISP 1
93//#define SPR_DEBUG 1
8094
8195static UINT8 towns_vram_wplane;
8296static UINT8 towns_vram_rplane;
r6721r6722
92106static UINT16 towns_crtc_reg[32];
93107static UINT8 towns_video_sel;  // selected video register
94108static UINT8 towns_video_reg[2];
109static UINT8 towns_sprite_sel;  // selected sprite register
110static UINT8 towns_sprite_reg[8];
95111static UINT8 towns_tvram_enable;
96112static UINT16 towns_kanji_offset;
97113static UINT8 towns_kanji_code_h;
r6721r6722
106122extern UINT32 towns_mainmem_enable;
107123extern UINT32 towns_ankcg_enable;
108124
125static UINT32 pshift;  // for debugging
126
109127void towns_crtc_refresh_mode(running_machine* machine)
110128{
111129   rectangle scr;
r6721r6722
344362         }
345363         else
346364            return 0x00;
365      case 0x10:
366         return towns_sprite_sel;
367      case 0x12:
368         logerror("SPR: reading register %i (0x452) [%02x]\n",towns_sprite_sel,towns_sprite_reg[towns_sprite_sel]);
369         return towns_sprite_reg[towns_sprite_sel];
347370      default:
348371         logerror("VID: read port %04x\n",offset+0x440);
349372   }
r6721r6722
376399         logerror("Video: writing register %i (0x44a) [%02x]\n",towns_video_sel,data);
377400         towns_video_reg[towns_video_sel] = data;
378401         break;
402      case 0x10:
403         towns_sprite_sel = data & 0x07;
404         break;
405      case 0x12:
406         logerror("SPR: writing register %i (0x452) [%02x]\n",towns_sprite_sel,data);
407         towns_sprite_reg[towns_sprite_sel] = data;
408         break;
379409      default:
380410         logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x440);
381411   }
r6721r6722
559589   }
560590}
561591
562// Should this area return TVRAM if enabled?
563592READ8_HANDLER( towns_spriteram_r)
564593{
565594   return towns_sprram[offset];
r6721r6722
570599   towns_sprram[offset] = data;
571600}
572601
602/*
603 *  Sprites
604 *
605 *    Max. 1024, 16x16, 16 colours per sprite
606 *    128kB Sprite RAM (8kB attributes, 120kB pattern/colour data)
607 *    Sprites are rendered directly to VRAM layer 1 (VRAM offset 0x40000 or 0x60000)
608 *
609 *    Sprite RAM format:
610 *       4 words per sprite
611 *       +0: X position (10-bit)
612 *       +2: Y position (10-bit)
613 *       +4: Sprite Attribute
614 *          bit 15: enforce offsets (regs 2-5)
615 *          bits 10-0: Sprite RAM offset containing sprite pattern
616 *          TODO: other attributes (zoom?)
617 *       +6: Sprite Colour
618 *          bit 15: use colour data in located in sprite RAM offset in bits 11-0 (x32)
619 */
620void render_sprite_4(bitmap_t* bitmap, UINT32 poffset, UINT32 coffset, UINT16 x, UINT16 y, const rectangle* rect)
621{
622   UINT16 xpos,ypos;
623   UINT16 col,pixel;
624   UINT32 voffset;
625   
626   for(ypos=y;ypos<y+16;ypos++)
627   {
628      for(xpos=x;xpos<x+16;xpos+=2)
629      {
630         voffset = 0;
631         pixel = towns_sprram[poffset] & 0x0f;
632         col = towns_sprram[coffset+(pixel*2)] | (towns_sprram[coffset+(pixel*2)+1] << 8);
633         voffset += (towns_crtc_reg[24] * 4) * ypos;  // scanline size in bytes * y pos
634         voffset += (xpos & 0x1ff) * 2;
635         voffset &= 0x3ffff;
636         voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000;
637         if(xpos <= rect->max_x && ypos <= rect->max_y && col != 0)
638         {
639            towns_gfxvram[voffset+1] = (col & 0xff00) >> 8;
640            towns_gfxvram[voffset] = col & 0x00ff;
641         }
642         voffset+=2;
643         pixel = (towns_sprram[poffset] & 0xf0) >> 4;
644         col = towns_sprram[coffset+(pixel*2)] | (towns_sprram[coffset+(pixel*2)+1] << 8);
645         voffset &= 0x3ffff;
646         voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000;
647         if(xpos <= rect->max_x && ypos <= rect->max_y && col != 0)
648         {
649            towns_gfxvram[voffset+1] = (col & 0xff00) >> 8;
650            towns_gfxvram[voffset] = col & 0x00ff;
651         }
652         poffset++;
653      }
654   }
655}
656
657void render_sprite_16(bitmap_t* bitmap, UINT32 poffset, UINT16 x, UINT16 y, const rectangle* rect)
658{
659   UINT16 xpos,ypos;
660   UINT16 col;//,pixel;
661   UINT32 voffset;
662   
663   for(ypos=y;ypos<y+16;ypos++)
664   {
665      for(xpos=x;xpos<x+16;xpos++)
666      {
667         voffset = (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000;
668         col = towns_sprram[poffset] | (towns_sprram[poffset+1] << 8);
669         voffset += (towns_crtc_reg[24] * 4) * ypos;  // scanline size in bytes * y pos
670         voffset += (xpos & 0x1ff) * 2;
671         voffset &= 0x7ffff;
672         if(xpos <= rect->max_x && ypos <= rect->max_y)
673         {
674            towns_gfxvram[voffset+1] = (col & 0xff00) >> 8;
675            towns_gfxvram[voffset] = col & 0x00ff;
676         }
677         poffset+=2;
678      }
679   }
680}
681
682void draw_sprites(running_machine* machine,bitmap_t* bitmap, const rectangle* rect)
683{
684   UINT16 sprite_limit = (towns_sprite_reg[0] | (towns_sprite_reg[1] << 8)) & 0x3ff;
685   int n;
686   UINT16 x,y,attr,colour;
687   UINT16 xoff = (towns_sprite_reg[2] | (towns_sprite_reg[3] << 8)) & 0x1ff;
688   UINT16 yoff = (towns_sprite_reg[4] | (towns_sprite_reg[5] << 8)) & 0x1ff;
689   UINT32 poffset,coffset;
690   
691   if(!(towns_sprite_reg[1] & 0x80))
692      return;
693     
694   // clears VRAM for each frame?
695   memset(towns_gfxvram+0x40000,0x80,0x40000);
696   
697   for(n=sprite_limit;n<1024;n++)
698   {
699      x = towns_sprram[8*n] | (towns_sprram[8*n+1] << 8);
700      y = towns_sprram[8*n+2] | (towns_sprram[8*n+3] << 8);
701      attr = towns_sprram[8*n+4] | (towns_sprram[8*n+5] << 8);
702      colour = towns_sprram[8*n+6] | (towns_sprram[8*n+7] << 8);
703      if(attr & 0x8000)
704      {
705         x += xoff;
706         y += yoff;
707      }
708      x &= 0x1ff;
709      y &= 0x1ff;
710     
711      if(colour & 0x8000)
712      {
713         poffset = (attr & 0x3ff) << 7;
714         coffset = (colour & 0xfff) << 5;
715#ifdef SPR_DEBUG
716         printf("Sprite4 #%i, X %i Y %i Attr %04x Col %04x Poff %05x Coff %05x\n",
717            n,x,y,attr,colour,poffset,coffset);
718#endif
719         if(!(colour & 0x2000))
720            render_sprite_4(bitmap,(poffset+pshift)&0x1ffff,coffset,x,y,rect);
721      }
722      else
723      {
724         poffset = (attr & 0x3ff) << 7;
725         coffset = (colour & 0xfff) << 5;
726#ifdef SPR_DEBUG
727         printf("Sprite16 #%i, X %i Y %i Attr %04x Col %04x Poff %05x Coff %05x\n",
728            n,x,y,attr,colour,poffset,coffset);
729#endif
730         render_sprite_16(bitmap,(poffset+pshift)&0x1ffff,x,y,rect);
731      }
732   }
733}
734
573735void towns_crtc_draw_scan_layer_hicolour(bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline)
574736{
575737   UINT32 off = 0;
r6721r6722
800962   }
801963}
802964
803void towns_crtc_draw_layer(bitmap_t* bitmap,const rectangle* rect,int layer)
965void towns_crtc_draw_layer(running_machine* machine,bitmap_t* bitmap,const rectangle* rect,int layer)
804966{
805967   int line;
806968   int scanline;
r6721r6722
8541016   }
8551017   else
8561018   {
1019      if(towns_sprite_reg[1] & 0x80)  // if sprites are enabled, then sprites are drawn on this layer.
1020         draw_sprites(machine,bitmap,rect);
1021         
8571022      scanline = rect->min_y;
8581023      height = (rect->max_y - rect->min_y);
8591024      if(towns_crtc_reg[27] & 0x1000)
r6721r6722
9901155   if(!(towns_video_reg[1] & 0x01))
9911156   {
9921157      if(!input_code_pressed(screen->machine,KEYCODE_Q))
993         towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[1],1);
1158         towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[1],1);
9941159      if(!input_code_pressed(screen->machine,KEYCODE_W))
995         towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[0],0);
1160         towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[0],0);
9961161   }
9971162   else
9981163   {
9991164      if(!input_code_pressed(screen->machine,KEYCODE_Q))
1000         towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[0],0);
1165         towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[0],0);
10011166      if(!input_code_pressed(screen->machine,KEYCODE_W))
1002         towns_crtc_draw_layer(bitmap,&towns_crtc_layerscr[1],1);
1167         towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[1],1);
10031168   }
10041169
1005   draw_text_layer(screen->machine,bitmap,cliprect);
1170   if(!(towns_sprite_reg[1] & 0x80))  // if sprites are not enabled
1171      draw_text_layer(screen->machine,bitmap,cliprect);
10061172
1173#ifdef SPR_DEBUG
1174   if(input_code_pressed(screen->machine,KEYCODE_O))
1175      pshift+=0x80;
1176   if(input_code_pressed(screen->machine,KEYCODE_I))
1177      pshift-=0x80;
1178   popmessage("Pixel shift = %08x",pshift);
1179#endif
1180
10071181#ifdef CRTC_REG_DISP
10081182   popmessage("CRTC: %i %i %i %i %i %i %i %i %i\n%i %i %i %i | %i %i %i %i\n%i %i %i %i | %i %i %i %i\nZOOM: %04x\nVideo: %02x %02x\nText=%i",
10091183      towns_crtc_reg[0],towns_crtc_reg[1],towns_crtc_reg[2],towns_crtc_reg[3],
src/mess/drivers/fmtowns.c
r6721r6722
16041604  AM_RANGE(0x000f8000, 0x000fffff) AM_READ_BANK("bank11") AM_WRITE_BANK("bank12")
16051605  AM_RANGE(0x00100000, 0x005fffff) AM_RAM  // some extra RAM - seems to be needed to boot
16061606  AM_RANGE(0x80000000, 0x8007ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM
1607  AM_RANGE(0x81000000, 0x8101ffff) AM_RAM // Sprite RAM
1607  AM_RANGE(0x81000000, 0x8101ffff) AM_READWRITE8(towns_spriteram_r,towns_spriteram_w,0xffffffff) // Sprite RAM
16081608  AM_RANGE(0xc2000000, 0xc207ffff) AM_ROM AM_REGION("user",0x000000)  // OS ROM
16091609  AM_RANGE(0xc2080000, 0xc20fffff) AM_ROM AM_REGION("user",0x100000)  // DIC ROM
16101610  AM_RANGE(0xc2100000, 0xc213ffff) AM_ROM AM_REGION("user",0x180000)  // FONT ROM
r6721r6722
16301630  AM_RANGE(0x00600000, 0x0067ffff) AM_ROM AM_REGION("user",0x000000)  // OS
16311631  AM_RANGE(0x00680000, 0x0087ffff) AM_ROM AM_REGION("user",0x280000)  // EX ROM
16321632  AM_RANGE(0x00a00000, 0x00a7ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM
1633  AM_RANGE(0x00c00000, 0x00c1ffff) AM_READWRITE8(towns_spriteram_r,towns_spriteram_w,0xffffffff) // Sprite RAM
16331634  AM_RANGE(0x00e80000, 0x00efffff) AM_ROM AM_REGION("user",0x100000)  // DIC ROM
16341635  AM_RANGE(0x00f00000, 0x00f7ffff) AM_ROM AM_REGION("user",0x180000)  // FONT
16351636  AM_RANGE(0x00fc0000, 0x00ffffff) AM_ROM AM_REGION("user",0x200000)  // SYSTEM ROM
1636  AM_RANGE(0x80000000, 0x8007ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM
1637/*  AM_RANGE(0x80000000, 0x8007ffff) AM_READWRITE8(towns_gfx_high_r,towns_gfx_high_w,0xffffffff) AM_MIRROR(0x180000) // VRAM
16371638  AM_RANGE(0x81000000, 0x8101ffff) AM_READWRITE8(towns_spriteram_r,towns_spriteram_w,0xffffffff) // Sprite RAM
16381639  AM_RANGE(0xc2000000, 0xc207ffff) AM_ROM AM_REGION("user",0x000000)  // OS ROM
16391640  AM_RANGE(0xc2080000, 0xc20fffff) AM_ROM AM_REGION("user",0x100000)  // DIC ROM
16401641  AM_RANGE(0xc2100000, 0xc213ffff) AM_ROM AM_REGION("user",0x180000)  // FONT ROM
16411642  AM_RANGE(0xc2140000, 0xc2141fff) AM_READWRITE8(towns_cmos_r,towns_cmos_w,0xffffffff) // CMOS (mirror?)
16421643  AM_RANGE(0xc2200000, 0xc2200fff) AM_NOP  // WAVE RAM
1643  AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000)  // SYSTEM ROM
1644*/AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000)  // SYSTEM ROM
16441645ADDRESS_MAP_END
16451646
16461647static ADDRESS_MAP_START( towns_io , ADDRESS_SPACE_IO, 32)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team