Previous 15994 Revisions Next

r12666 Friday 19th August, 2011 at 16:57:27 UTC by Angelo Salese
Port from MAME
[src/mame/video]stvvdp2.c

src/mame/video/stvvdp2.c
r12665r12666
494494    1 - use bitmap mode   */
495495   #define STV_VDP2_R0BMEN ((STV_VDP2_CHCTLB & 0x0200) >> 9)
496496
497/*  R0CHSZ - NBG0 Character (Tile) Size
497/*  R0CHSZ - RBG0 Character (Tile) Size
498498    0 - 1 cell  x 1 cell  (8x8)
499499    1 - 2 cells x 2 cells (16x16)  */
500500   #define STV_VDP2_R0CHSZ ((STV_VDP2_CHCTLB & 0x0100) >> 8)
r12665r12666
20952095       \----------|----------|----------|----------|----------|----------|----------|---------*/
20962096   #define STV_VDP2_COBB (state->m_vdp2_regs[0x11e/2])
20972097
2098#if NEW_VIDEO_CODE
2099static void saturn_vdp2_assign_variables(running_machine &machine,UINT32 offset,UINT16 data);
2100#endif
2101
20982102/*For Debug purposes only*/
20992103static struct stv_vdp2_debugging
21002104{
r12665r12666
57975801
57985802   if(STV_VDP2_VRAMSZ)
57995803      printf("VDP2 sets up 8 Mbit VRAM!\n");
5804
5805   #if NEW_VIDEO_CODE
5806   saturn_vdp2_assign_variables(space->machine(),offset,state->m_vdp2_regs[offset]);
5807   #endif
58005808}
58015809
58025810static int get_hblank_duration(running_machine &machine)
r12665r12666
70167024   [1] NBG1
70177025   [2] NBG2
70187026   [3] NBG3
7027   [4] RBG0
7028   [5] BACK
70197029*/
7020static UINT32 layer_buffer[4][704*512];
70217030
7031#define XB_SIZE 1024
7032#define YB_SIZE 1024
70227033
7034static UINT32 layer_buffer[6][XB_SIZE*YB_SIZE];
7035static UINT8  layer_tpen[6][XB_SIZE*YB_SIZE];
7036
7037/* TODO: move in state machine */
7038static struct{
7039   UINT8 bitmap_en;
7040   UINT8 bpp;
7041   UINT8 color_offset_en;
7042   UINT8 color_offset_sel;
7043}m_vdp2_state[6];
7044
7045static void saturn_vdp2_assign_variables(running_machine &machine,UINT32 offset,UINT16 data)
7046{
7047   saturn_state *state = machine.driver_data<saturn_state>();
7048
7049   switch(offset)
7050   {
7051      case 0x028/2:
7052         m_vdp2_state[0].bpp = STV_VDP2_N0CHCN;
7053         m_vdp2_state[1].bpp = STV_VDP2_N1CHCN;
7054         break;
7055      case 0x02a/2:
7056         m_vdp2_state[2].bpp = STV_VDP2_N2CHCN;
7057         m_vdp2_state[3].bpp = STV_VDP2_N3CHCN;
7058         break;
7059      case 0x02c/2:
7060         m_vdp2_state[0].bitmap_en = STV_VDP2_N0BMP;
7061         m_vdp2_state[1].bitmap_en = STV_VDP2_N1BMP;
7062         break;
7063      case 0x110/2:
7064         m_vdp2_state[0].color_offset_en = STV_VDP2_N0COEN;
7065         m_vdp2_state[1].color_offset_en = STV_VDP2_N1COEN;
7066         m_vdp2_state[2].color_offset_en = STV_VDP2_N2COEN;
7067         m_vdp2_state[3].color_offset_en = STV_VDP2_N3COEN;
7068         m_vdp2_state[4].color_offset_en = STV_VDP2_R0COEN;
7069         m_vdp2_state[5].color_offset_en = STV_VDP2_BKCOEN;
7070//         STV_VDP2_SPCOEN
7071         break;
7072      case 0x112/2:
7073         m_vdp2_state[0].color_offset_sel = STV_VDP2_N0COSL;
7074         m_vdp2_state[1].color_offset_sel = STV_VDP2_N1COSL;
7075         m_vdp2_state[2].color_offset_sel = STV_VDP2_N2COSL;
7076         m_vdp2_state[3].color_offset_sel = STV_VDP2_N3COSL;
7077         m_vdp2_state[4].color_offset_sel = STV_VDP2_R0COSL;
7078         m_vdp2_state[5].color_offset_sel = STV_VDP2_BKCOSL;
7079//         STV_VDP2_SPCOEN
7080         break;
7081   }
7082}
7083
7084static void vdp2_draw_back(running_machine &machine, bitmap_t *bitmap, const rectangle *cliprect)
7085{
7086   saturn_state *state = machine.driver_data<saturn_state>();
7087   int x,y;
7088   UINT8* gfxdata = state->m_vdp2.gfx_decode;
7089   UINT32 base_offs,base_mask;
7090   UINT8 interlace;
7091
7092   interlace = (STV_VDP2_LSMD == 3)+1;
7093
7094   /* draw black if BDCLMD and DISP are cleared */
7095   if(!(STV_VDP2_BDCLMD) && !(STV_VDP2_DISP))
7096      bitmap_fill(bitmap, cliprect, get_black_pen(machine));
7097   else
7098   {
7099      base_mask = STV_VDP2_VRAMSZ ? 0x7ffff : 0x3ffff;
7100
7101      for(y=cliprect->min_y;y<=cliprect->max_y;y++)
7102      {
7103         base_offs = ((STV_VDP2_BKTA ) & base_mask) << 1;
7104         if(STV_VDP2_BKCLMD)
7105            base_offs += ((y / interlace) << 1);
7106
7107         for(x=cliprect->min_x;x<=cliprect->max_x;x++)
7108         {
7109            int r,g,b;
7110            UINT16 dot;
7111
7112            dot = (gfxdata[base_offs+0]<<8)|gfxdata[base_offs+1];
7113            b = (dot & 0x7c00) >> 10;
7114            g = (dot & 0x03e0) >> 5;
7115            r = (dot & 0x001f) >> 0;
7116            b <<= 3;
7117            g <<= 3;
7118            r <<= 3;
7119
7120            //if(STV_VDP2_BKCOEN)
7121            //   stv_vdp2_compute_color_offset_RGB555( machine, &r, &g, &b, STV_VDP2_BKCOSL );
7122
7123            /* TODO: this needs post-processing too! */
7124            *BITMAP_ADDR32(bitmap, y,x) = b | g << 8 | r << 16;
7125         }
7126      }
7127   }
7128}
7129
70237130static void vdp2_palette_entry(running_machine &machine, int *r, int *g, int *b, UINT16 offset);
70247131
7132static void get_vdp2_pixel(running_machine &machine, UINT8 layer_name, UINT16 tile,UINT8 color, int xi, int yi, int *r, int *g, int *b, int *tp)
7133{
7134   saturn_state *state = machine.driver_data<saturn_state>();
7135   UINT8 *vram = state->m_vdp2.gfx_decode;
7136   UINT32 vram_offset;
7137   UINT32 vram_mask;
7138   int pix;
7139
7140   vram_mask = 0x7ffff;
7141
7142   switch(m_vdp2_state[layer_name].bpp)
7143   {
7144      case 0:  //2 bpp
7145         if(m_vdp2_state[layer_name].bitmap_en)
7146            vram_offset = tile;
7147         else
7148            vram_offset = tile*0x20+(yi*4)+(xi >> 1);
7149
7150         pix = (vram[vram_offset & vram_mask] >> ((xi & 1) ^ 1)*4) & 0xf;
7151
7152         vdp2_palette_entry(machine,&*r,&*g,&*b,(color<<4|pix) & 0x7ff);
7153
7154         *tp = (pix != 0);
7155         break;
7156      case 1:  //4 bpp
7157         if(m_vdp2_state[layer_name].bitmap_en)
7158            vram_offset = tile;
7159         else
7160            vram_offset = tile*0x40+(yi*8)+(xi);
7161
7162         pix = (vram[vram_offset & vram_mask]) & 0xff;
7163
7164         vdp2_palette_entry(machine,&*r,&*g,&*b,(color<<8|pix) & 0x7ff);
7165
7166         *tp = (pix != 0);
7167         break;
7168      case 2:  //11 bpp
7169         popmessage("bpp == 2 in tilemap");
7170
7171         if(m_vdp2_state[layer_name].bitmap_en)
7172            vram_offset = tile;
7173         else
7174            vram_offset = tile*0x40+(yi*8)+(xi);
7175
7176         /* confused over this, but I should have done correctly: */
7177         pix = (vram[((vram_offset)*2+0) & vram_mask]<<8)|
7178              (vram[((vram_offset)*2+1) & vram_mask]);
7179
7180         vdp2_palette_entry(machine,&*r,&*g,&*b,(pix) & 0x7ff);
7181
7182         *tp = (pix != 0);
7183         break;
7184      case 3:  //RGB5
7185         if(m_vdp2_state[layer_name].bitmap_en)
7186            vram_offset = tile;
7187         else
7188            vram_offset = tile*0x40+(yi*8)+(xi);
7189
7190         pix = (vram[((vram_offset)*2+0) & vram_mask]<<8)|
7191              (vram[((vram_offset)*2+1) & vram_mask]);
7192
7193         *tp= ((pix & 0x8000) >> 15);
7194//         *cc= *tp;
7195         *b = ((pix & 0x7c00) >> 10);
7196         *g = ((pix & 0x03e0) >> 5);
7197         *r = ((pix & 0x001f) >> 0);
7198         *b <<= 3;
7199         *g <<= 3;
7200         *r <<= 3;
7201         break;
7202      case 4:  //RGB8
7203         if(m_vdp2_state[layer_name].bitmap_en)
7204            vram_offset = tile;
7205         else
7206            vram_offset = tile*0x80+(yi*8)+(xi);
7207
7208         pix = (vram[((vram_offset)*4+0) & vram_mask]<<24)|
7209              (vram[((vram_offset)*4+1) & vram_mask]<<16) |
7210              (vram[((vram_offset)*4+2) & vram_mask]<<8)|
7211              (vram[((vram_offset)*4+3) & vram_mask]);
7212
7213           *tp= ((pix & 0x80000000) >> 31);
7214//         *cc= *tp;
7215         *b = ((pix & 0x00ff0000) >> 16);
7216         *g = ((pix & 0x0000ff00) >> 8);
7217         *r = ((pix & 0x000000ff) >> 0);
7218         break;
7219      default:
7220         popmessage("Setting invalid for NBG%d!",layer_name);
7221         *tp = *b = *g = *r = 0;
7222         break;
7223    }
7224}
7225
70257226/* copy the vram data into the vram buffer */
70267227static void vdp2_tile_draw(running_machine &machine, UINT8 layer_name, UINT16 tile, UINT8 color, int x, int y)
70277228{
7028   saturn_state *state = machine.driver_data<saturn_state>();
7029   UINT8 *vram = state->m_vdp2.gfx_decode;
7229   //saturn_state *state = machine.driver_data<saturn_state>();
70307230   int xi,yi;
7031   int r,g,b;
7032   UINT8 dot_data;
7231   int r,g,b,tp;
70337232
70347233   for(yi=0;yi<8;yi++)
70357234   {
70367235      for(xi=0;xi<8;xi++)
70377236      {
7038         dot_data = (vram[tile*0x20+(yi*4)+(xi >> 1)] >> ((xi & 1) ^ 1)*4) & 0xf;
7039         vdp2_palette_entry(machine,&r,&g,&b,(color<<4|dot_data));
7237         get_vdp2_pixel(machine,layer_name,tile,color,xi,yi, &r, &g, &b, &tp);
70407238
7041         layer_buffer[layer_name][(x*8+xi)+((y*8+yi)*512)] = (r << 16) | (g << 8) | (b);
7239         layer_buffer[layer_name][(x*8+xi)+((y*8+yi)*XB_SIZE)] = (r << 16) | (g << 8) | (b);
7240         layer_tpen[layer_name][(x*8+xi)+((y*8+yi)*XB_SIZE)] = tp;
70427241      }
70437242   }
70447243}
r12665r12666
70517250   int x,y;
70527251   UINT16 datax;
70537252
7054   for(y=0;y<32;y++)
7253   for(y=0;y<64;y++)
70557254   {
7056      for(x=0;x<32;x++)
7255      for(x=0;x<64;x++)
70577256      {
70587257         UINT16 tile;
70597258         UINT8 color;
70607259
7061         datax = (vram[(x+y*32+0x31000)*2+0]<<8)|(vram[(x+y*32+0x31000)*2+1]&0xff);
7260         datax = (vram[(x+y*64+0x31000)*2+0]<<8)|(vram[(x+y*64+0x31000)*2+1]&0xff);
70627261         tile = (datax & 0xff) | 0x3000;
70637262         color = ((datax & 0xf000) >> 12) | 0x40;
70647263
r12665r12666
70677266   }
70687267}
70697268
7070/* now copy the vram buffer to the screen buffer */
7269static void vdp2_calc_color_offset(running_machine &machine, UINT8 layer_name, int *r, int *g, int *b)
7270{
7271   saturn_state *state = machine.driver_data<saturn_state>();
7272   int base_offs;
7273   int cor,cog,cob;
7274
7275   base_offs = (0x114 + m_vdp2_state[layer_name].color_offset_sel*6);
7276
7277   cor = (state->m_vdp2_regs[(base_offs+0)/2]) & 0x1ff;
7278   cog = (state->m_vdp2_regs[(base_offs+2)/2]) & 0x1ff;
7279   cob = (state->m_vdp2_regs[(base_offs+4)/2]) & 0x1ff;
7280
7281   *r = (cor & 0x100) ? *r - (0x100 - (cor & 0xff)) : (*r + (cor & 0xff));
7282   *g = (cog & 0x100) ? *g - (0x100 - (cog & 0xff)) : (*g + (cog & 0xff));
7283   *b = (cob & 0x100) ? *b - (0x100 - (cob & 0xff)) : (*b + (cob & 0xff));
7284
7285   if(*r > 0xff) { *r = 0xff; }
7286   if(*g > 0xff) { *g = 0xff; }
7287   if(*b > 0xff) { *b = 0xff; }
7288   if(*r < 0) { *r = 0; }
7289   if(*g < 0) { *g = 0; }
7290   if(*b < 0) { *b = 0; }
7291}
7292
7293/* now copy the vram buffer to the screen buffer, apply post-processing at this stage */
70717294static void draw_normal_screen(running_machine &machine, bitmap_t *bitmap,const rectangle *cliprect, UINT8 layer_name)
70727295{
70737296   int x,y;
7297   int r,g,b;
70747298
7075   for(y=0;y<cliprect->max_y;y++)
7299
7300   for(y=0;y<=cliprect->max_y;y++)
70767301   {
7077      for(x=0;x<cliprect->max_x;x++)
7302      for(x=0;x<=cliprect->max_x;x++)
70787303      {
7079         *BITMAP_ADDR32(bitmap, y, x) = layer_buffer[layer_name][(x)+(y)*512];
7304         if(layer_tpen[layer_name][(x)+(y)*XB_SIZE])
7305         {
7306            b = (layer_buffer[layer_name][(x)+(y)*XB_SIZE] & 0x0000ff);
7307            g = (layer_buffer[layer_name][(x)+(y)*XB_SIZE] & 0x00ff00) >> 8;
7308            r = (layer_buffer[layer_name][(x)+(y)*XB_SIZE] & 0xff0000) >> 16;
7309
7310            /* apply color offset*/
7311            if(m_vdp2_state[layer_name].color_offset_en)
7312               vdp2_calc_color_offset(machine,layer_name,&r,&g,&b);
7313
7314            *BITMAP_ADDR32(bitmap, y, x) = b | g << 8 | r << 16;
7315         }
70807316      }
70817317   }
70827318}
r12665r12666
71047340         break;
71057341      }
71067342      case 2: // RGB8: 1024 color pens
7107      case 3: // (reserved mode but identical to above)
7343      case 3: // (mode 3 is reserved but seems to be identical to above)
71087344      {
71097345//         *cc= ((state->m_vdp2_cram[offset] & 0x80000000) >> 31);
71107346         *b = ((state->m_vdp2_cram[offset] & 0x00ff0000) >> 16);
r12665r12666
71177353
71187354SCREEN_UPDATE( saturn )
71197355{
7356   saturn_state *state = screen->machine().driver_data<saturn_state>();
71207357   static UINT8 disclaimer;
71217358
7359   vdp2_draw_back(screen->machine(),bitmap,cliprect);
7360
7361   if(STV_VDP2_DISP)
7362   {
7363      copy_plane(screen->machine(),3);
7364
7365      draw_normal_screen(screen->machine(),bitmap,cliprect,3);
7366   }
7367
71227368   if(disclaimer == 0)
71237369   {
71247370      disclaimer++;
71257371      popmessage("NEW Video code, rm me");
71267372   }
71277373
7128   copy_plane(screen->machine(),3);
71297374
7130   draw_normal_screen(screen->machine(),bitmap,cliprect,3);
7131
71327375   return 0;
71337376}
7377
71347378#endif

Previous 15994 Revisions Next


© 1998-2018 The MESS Team