src/mame/video/stvvdp2.c
| r12665 | r12666 | |
| 494 | 494 | 1 - use bitmap mode */ |
| 495 | 495 | #define STV_VDP2_R0BMEN ((STV_VDP2_CHCTLB & 0x0200) >> 9) |
| 496 | 496 | |
| 497 | | /* R0CHSZ - NBG0 Character (Tile) Size |
| 497 | /* R0CHSZ - RBG0 Character (Tile) Size |
| 498 | 498 | 0 - 1 cell x 1 cell (8x8) |
| 499 | 499 | 1 - 2 cells x 2 cells (16x16) */ |
| 500 | 500 | #define STV_VDP2_R0CHSZ ((STV_VDP2_CHCTLB & 0x0100) >> 8) |
| r12665 | r12666 | |
| 2095 | 2095 | \----------|----------|----------|----------|----------|----------|----------|---------*/ |
| 2096 | 2096 | #define STV_VDP2_COBB (state->m_vdp2_regs[0x11e/2]) |
| 2097 | 2097 | |
| 2098 | #if NEW_VIDEO_CODE |
| 2099 | static void saturn_vdp2_assign_variables(running_machine &machine,UINT32 offset,UINT16 data); |
| 2100 | #endif |
| 2101 | |
| 2098 | 2102 | /*For Debug purposes only*/ |
| 2099 | 2103 | static struct stv_vdp2_debugging |
| 2100 | 2104 | { |
| r12665 | r12666 | |
| 5797 | 5801 | |
| 5798 | 5802 | if(STV_VDP2_VRAMSZ) |
| 5799 | 5803 | 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 |
| 5800 | 5808 | } |
| 5801 | 5809 | |
| 5802 | 5810 | static int get_hblank_duration(running_machine &machine) |
| r12665 | r12666 | |
| 7016 | 7024 | [1] NBG1 |
| 7017 | 7025 | [2] NBG2 |
| 7018 | 7026 | [3] NBG3 |
| 7027 | [4] RBG0 |
| 7028 | [5] BACK |
| 7019 | 7029 | */ |
| 7020 | | static UINT32 layer_buffer[4][704*512]; |
| 7021 | 7030 | |
| 7031 | #define XB_SIZE 1024 |
| 7032 | #define YB_SIZE 1024 |
| 7022 | 7033 | |
| 7034 | static UINT32 layer_buffer[6][XB_SIZE*YB_SIZE]; |
| 7035 | static UINT8 layer_tpen[6][XB_SIZE*YB_SIZE]; |
| 7036 | |
| 7037 | /* TODO: move in state machine */ |
| 7038 | static struct{ |
| 7039 | UINT8 bitmap_en; |
| 7040 | UINT8 bpp; |
| 7041 | UINT8 color_offset_en; |
| 7042 | UINT8 color_offset_sel; |
| 7043 | }m_vdp2_state[6]; |
| 7044 | |
| 7045 | static 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 | |
| 7084 | static 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 | |
| 7023 | 7130 | static void vdp2_palette_entry(running_machine &machine, int *r, int *g, int *b, UINT16 offset); |
| 7024 | 7131 | |
| 7132 | static 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 | |
| 7025 | 7226 | /* copy the vram data into the vram buffer */ |
| 7026 | 7227 | static void vdp2_tile_draw(running_machine &machine, UINT8 layer_name, UINT16 tile, UINT8 color, int x, int y) |
| 7027 | 7228 | { |
| 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>(); |
| 7030 | 7230 | int xi,yi; |
| 7031 | | int r,g,b; |
| 7032 | | UINT8 dot_data; |
| 7231 | int r,g,b,tp; |
| 7033 | 7232 | |
| 7034 | 7233 | for(yi=0;yi<8;yi++) |
| 7035 | 7234 | { |
| 7036 | 7235 | for(xi=0;xi<8;xi++) |
| 7037 | 7236 | { |
| 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); |
| 7040 | 7238 | |
| 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; |
| 7042 | 7241 | } |
| 7043 | 7242 | } |
| 7044 | 7243 | } |
| r12665 | r12666 | |
| 7051 | 7250 | int x,y; |
| 7052 | 7251 | UINT16 datax; |
| 7053 | 7252 | |
| 7054 | | for(y=0;y<32;y++) |
| 7253 | for(y=0;y<64;y++) |
| 7055 | 7254 | { |
| 7056 | | for(x=0;x<32;x++) |
| 7255 | for(x=0;x<64;x++) |
| 7057 | 7256 | { |
| 7058 | 7257 | UINT16 tile; |
| 7059 | 7258 | UINT8 color; |
| 7060 | 7259 | |
| 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); |
| 7062 | 7261 | tile = (datax & 0xff) | 0x3000; |
| 7063 | 7262 | color = ((datax & 0xf000) >> 12) | 0x40; |
| 7064 | 7263 | |
| r12665 | r12666 | |
| 7067 | 7266 | } |
| 7068 | 7267 | } |
| 7069 | 7268 | |
| 7070 | | /* now copy the vram buffer to the screen buffer */ |
| 7269 | static 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 */ |
| 7071 | 7294 | static void draw_normal_screen(running_machine &machine, bitmap_t *bitmap,const rectangle *cliprect, UINT8 layer_name) |
| 7072 | 7295 | { |
| 7073 | 7296 | int x,y; |
| 7297 | int r,g,b; |
| 7074 | 7298 | |
| 7075 | | for(y=0;y<cliprect->max_y;y++) |
| 7299 | |
| 7300 | for(y=0;y<=cliprect->max_y;y++) |
| 7076 | 7301 | { |
| 7077 | | for(x=0;x<cliprect->max_x;x++) |
| 7302 | for(x=0;x<=cliprect->max_x;x++) |
| 7078 | 7303 | { |
| 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 | } |
| 7080 | 7316 | } |
| 7081 | 7317 | } |
| 7082 | 7318 | } |
| r12665 | r12666 | |
| 7104 | 7340 | break; |
| 7105 | 7341 | } |
| 7106 | 7342 | 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) |
| 7108 | 7344 | { |
| 7109 | 7345 | // *cc= ((state->m_vdp2_cram[offset] & 0x80000000) >> 31); |
| 7110 | 7346 | *b = ((state->m_vdp2_cram[offset] & 0x00ff0000) >> 16); |
| r12665 | r12666 | |
| 7117 | 7353 | |
| 7118 | 7354 | SCREEN_UPDATE( saturn ) |
| 7119 | 7355 | { |
| 7356 | saturn_state *state = screen->machine().driver_data<saturn_state>(); |
| 7120 | 7357 | static UINT8 disclaimer; |
| 7121 | 7358 | |
| 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 | |
| 7122 | 7368 | if(disclaimer == 0) |
| 7123 | 7369 | { |
| 7124 | 7370 | disclaimer++; |
| 7125 | 7371 | popmessage("NEW Video code, rm me"); |
| 7126 | 7372 | } |
| 7127 | 7373 | |
| 7128 | | copy_plane(screen->machine(),3); |
| 7129 | 7374 | |
| 7130 | | draw_normal_screen(screen->machine(),bitmap,cliprect,3); |
| 7131 | | |
| 7132 | 7375 | return 0; |
| 7133 | 7376 | } |
| 7377 | |
| 7134 | 7378 | #endif |