src/mess/drivers/x1.c
| r5529 | r5530 | |
| 13 | 13 | - clean-ups! |
| 14 | 14 | - There are various unclear video things, these are: |
| 15 | 15 | - how layer clearance works? Dragon Buster relies on it |
| 16 | | - I bet there's a PCG reset address tied to some bit, find it; |
| 16 | - PCG reset address is tied to the screen beams in some way; |
| 17 | - Support the alternative PCG upload mode; |
| 17 | 18 | - Add the extended gfx hookup; |
| 18 | 19 | - (anything else?) |
| 19 | 20 | |
| r5529 | r5530 | |
| 149 | 150 | static UINT8 io_bank_mode; |
| 150 | 151 | static UINT8 *gfx_bitmap_ram; |
| 151 | 152 | static UINT16 pcg_index[3]; |
| 153 | static UINT8 pcg_reset; |
| 154 | static UINT16 crtc_start_addr; |
| 155 | static struct |
| 156 | { |
| 157 | UINT8 gfx_bank; |
| 158 | UINT8 pcg_mode; |
| 159 | }ply_reg; |
| 152 | 160 | |
| 153 | | |
| 154 | 161 | static VIDEO_START( x1 ) |
| 155 | 162 | { |
| 156 | 163 | colorram = auto_alloc_array(machine, UINT8, 0x1000); |
| 157 | 164 | videoram = auto_alloc_array(machine, UINT8, 0x1000); |
| 158 | | gfx_bitmap_ram = auto_alloc_array(machine, UINT8, 0xc000); |
| 165 | gfx_bitmap_ram = auto_alloc_array(machine, UINT8, 0xc000*2); |
| 159 | 166 | } |
| 160 | 167 | |
| 161 | 168 | static void draw_fgtilemap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w,int pri) |
| 162 | 169 | { |
| 163 | 170 | int y,x,res_x,res_y; |
| 171 | int screen_mask; |
| 164 | 172 | |
| 173 | screen_mask = (w == 2) ? 0xfff : 0x7ff; |
| 174 | |
| 165 | 175 | for (y=0;y<25;y++) |
| 166 | 176 | { |
| 167 | 177 | for (x=0;x<40*w;x++) |
| 168 | 178 | { |
| 169 | | int tile = videoram[x+(y*40*w)]; |
| 170 | | int color = colorram[x+(y*40*w)] & 0x1f; |
| 171 | | int width = (colorram[x+(y*40*w)] & 0x80)>>7; |
| 172 | | int height = (colorram[x+(y*40*w)] & 0x40)>>6; |
| 173 | | int pcg_bank = (colorram[x+(y*40*w)] & 0x20)>>5; |
| 179 | int tile = videoram[(x+(y*40*w)+crtc_start_addr) & screen_mask]; |
| 180 | int color = colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x1f; |
| 181 | int width = (colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x80)>>7; |
| 182 | int height = (colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x40)>>6; |
| 183 | int pcg_bank = (colorram[(x+(y*40*w)+crtc_start_addr) & screen_mask] & 0x20)>>5; |
| 174 | 184 | UINT8 *gfx_data = pcg_bank ? memory_region(machine, "pcg") : memory_region(machine, "cgrom"); |
| 175 | 185 | |
| 176 | 186 | if(((color & 0x8)>>3) != pri) continue; |
| r5529 | r5530 | |
| 218 | 228 | } |
| 219 | 229 | } |
| 220 | 230 | |
| 221 | | static void draw_gfxbitmap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w) |
| 231 | static void draw_gfxbitmap(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int w,int plane) |
| 222 | 232 | { |
| 223 | 233 | int count,xi,yi,x,y; |
| 224 | 234 | int pen_r,pen_g,pen_b,color; |
| 225 | 235 | int yi_size; |
| 226 | 236 | |
| 227 | | count = 0; |
| 237 | count = crtc_start_addr; |
| 228 | 238 | |
| 229 | 239 | yi_size = (w == 1) ? 16 : 8; |
| 230 | 240 | |
| r5529 | r5530 | |
| 236 | 246 | { |
| 237 | 247 | for(xi=0;xi<8;xi++) |
| 238 | 248 | { |
| 239 | | pen_b = (gfx_bitmap_ram[count+0x0000]>>(7-xi)) & 1; |
| 240 | | pen_r = (gfx_bitmap_ram[count+0x4000]>>(7-xi)) & 1; |
| 241 | | pen_g = (gfx_bitmap_ram[count+0x8000]>>(7-xi)) & 1; |
| 249 | pen_b = (gfx_bitmap_ram[count+0x0000+plane*0xc000]>>(7-xi)) & 1; |
| 250 | pen_r = (gfx_bitmap_ram[count+0x4000+plane*0xc000]>>(7-xi)) & 1; |
| 251 | pen_g = (gfx_bitmap_ram[count+0x8000+plane*0xc000]>>(7-xi)) & 1; |
| 242 | 252 | |
| 243 | 253 | color = pen_g<<2 | pen_r<<1 | pen_b<<0; |
| 244 | 254 | |
| r5529 | r5530 | |
| 262 | 272 | } |
| 263 | 273 | } |
| 264 | 274 | count+= (w == 2) ? 48 : 24; |
| 275 | count&=0x3fff; |
| 265 | 276 | } |
| 266 | 277 | } |
| 267 | 278 | |
| r5529 | r5530 | |
| 274 | 285 | bitmap_fill(bitmap, cliprect, screen->machine->pens[0x100]); |
| 275 | 286 | |
| 276 | 287 | draw_fgtilemap(screen->machine,bitmap,cliprect,w,0); |
| 277 | | draw_gfxbitmap(screen->machine,bitmap,cliprect,w); |
| 288 | draw_gfxbitmap(screen->machine,bitmap,cliprect,w,0); |
| 289 | draw_gfxbitmap(screen->machine,bitmap,cliprect,w,1); |
| 278 | 290 | draw_fgtilemap(screen->machine,bitmap,cliprect,w,1); |
| 279 | 291 | |
| 280 | 292 | return 0; |
| 281 | 293 | } |
| 282 | 294 | |
| 295 | static VIDEO_EOF( x1 ) |
| 296 | { |
| 297 | } |
| 283 | 298 | |
| 284 | | |
| 285 | 299 | static UINT8 sub_cmd,sub_val,key_flag; |
| 286 | 300 | |
| 287 | 301 | /* |
| r5529 | r5530 | |
| 522 | 536 | |
| 523 | 537 | addr = (offset & 0x300) >> 8; |
| 524 | 538 | |
| 539 | if(pcg_reset) |
| 540 | { |
| 541 | pcg_index[0] = pcg_index[1] = pcg_index[2] = 0; |
| 542 | pcg_reset = 0; |
| 543 | } |
| 544 | |
| 525 | 545 | if(addr == 0) |
| 526 | 546 | { |
| 547 | /* FIXME: this is wrong (it's for the BIOS GFX ROM, read only) */ |
| 527 | 548 | /* maybe data actually? */ |
| 528 | 549 | pcg_index[0] = data*8; |
| 529 | 550 | pcg_index[1] = data*8; |
| r5529 | r5530 | |
| 531 | 552 | } |
| 532 | 553 | else |
| 533 | 554 | { |
| 534 | | pcg_offset = (pcg_index[addr-1]) & 0x7ff; |
| 535 | | pcg_offset+=((addr-1)*0x800); |
| 536 | | PCG_RAM[pcg_offset] = data; |
| 555 | // if(!ply_reg.pcg_mode) |
| 556 | // { |
| 557 | //( ((V_CNT-CRT_YL)/FNT_YL) + TXT_YL) * TXT_XL |
| 558 | // int v_count = video_screen_get_vpos(space->machine->primary_screen); |
| 559 | // |
| 560 | // } |
| 561 | // else |
| 562 | { |
| 563 | pcg_offset = (pcg_index[addr-1]) & 0x7ff; |
| 564 | pcg_offset+=((addr-1)*0x800); |
| 565 | PCG_RAM[pcg_offset] = data; |
| 537 | 566 | |
| 538 | | pcg_offset &= 0x7ff; |
| 567 | pcg_offset &= 0x7ff; |
| 539 | 568 | |
| 540 | | gfx_element_mark_dirty(space->machine->gfx[4], pcg_offset >> 3); |
| 541 | | gfx_element_mark_dirty(space->machine->gfx[5], pcg_offset >> 3); |
| 542 | | gfx_element_mark_dirty(space->machine->gfx[6], pcg_offset >> 3); |
| 543 | | gfx_element_mark_dirty(space->machine->gfx[7], pcg_offset >> 3); |
| 569 | gfx_element_mark_dirty(space->machine->gfx[4], pcg_offset >> 3); |
| 570 | gfx_element_mark_dirty(space->machine->gfx[5], pcg_offset >> 3); |
| 571 | gfx_element_mark_dirty(space->machine->gfx[6], pcg_offset >> 3); |
| 572 | gfx_element_mark_dirty(space->machine->gfx[7], pcg_offset >> 3); |
| 544 | 573 | |
| 545 | | pcg_index[addr-1]++; |
| 574 | pcg_index[addr-1]++; |
| 575 | } |
| 546 | 576 | } |
| 547 | 577 | } |
| 548 | 578 | |
| 549 | 579 | static READ8_HANDLER( x1_clr_r ) |
| 550 | 580 | { |
| 551 | | //memset(gfx_bitmap_ram,0x00,0xc000); |
| 552 | 581 | |
| 553 | 582 | return 0xff; |
| 554 | 583 | } |
| r5529 | r5530 | |
| 557 | 586 | { |
| 558 | 587 | io_bank_mode = 0; //any read disables the extended mode. |
| 559 | 588 | |
| 560 | | if(offset >= 0x0704 && offset <= 0x0707) { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x0704); } |
| 561 | | else if(offset == 0x07d0) { return x1_clr_r(space, 0); } |
| 589 | if(offset == 0x0000) { return x1_clr_r(space, 0); } |
| 590 | else if(offset >= 0x0704 && offset <= 0x0707) { return z80ctc_r(devtag_get_device(space->machine, "ctc"), offset-0x0704); } |
| 562 | 591 | else if(offset == 0x0e03) { return x1_rom_r(space, 0); } |
| 563 | 592 | else if(offset >= 0x0ff8 && offset <= 0x0fff) { return x1_fdc_r(space, offset-0xff8); } |
| 564 | 593 | else if(offset >= 0x1900 && offset <= 0x19ff) { return sub_io_r(space, 0); } |
| r5529 | r5530 | |
| 570 | 599 | // else if(offset >= 0x1fd0 && offset <= 0x1fdf) { return x1_scrn_r(space,offset-0x1fd0); } |
| 571 | 600 | else if(offset >= 0x2000 && offset <= 0x2fff) { return colorram[offset-0x2000]; } |
| 572 | 601 | else if(offset >= 0x3000 && offset <= 0x3fff) { return videoram[offset-0x3000]; } |
| 573 | | else if(offset >= 0x4000 && offset <= 0xffff) { return gfx_bitmap_ram[offset-0x4000]; } |
| 602 | else if(offset >= 0x4000 && offset <= 0xffff) { return gfx_bitmap_ram[offset-0x4000+(ply_reg.gfx_bank*0xc000)]; } |
| 574 | 603 | else |
| 575 | 604 | { |
| 576 | 605 | logerror("(PC=%06x) Read i/o address %04x\n",cpu_get_pc(space->cpu),offset); |
| r5529 | r5530 | |
| 584 | 613 | // fatalerror("Extended GFX RAM write %02x %04x",data,offset); |
| 585 | 614 | } |
| 586 | 615 | |
| 616 | static WRITE8_HANDLER( x1_ply_w ) |
| 617 | { |
| 618 | ply_reg.pcg_mode = (data & 0x20)>>5; |
| 619 | ply_reg.gfx_bank = (data & 0x10)>>4; |
| 620 | } |
| 621 | |
| 622 | static WRITE8_HANDLER( x1_6845_w ) |
| 623 | { |
| 624 | static int addr_latch; |
| 625 | |
| 626 | if(offset == 0) |
| 627 | { |
| 628 | addr_latch = data; |
| 629 | mc6845_address_w(devtag_get_device(space->machine, "crtc"), 0,data); |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | /* FIXME: this should be inside the MC6845 core! */ |
| 634 | if(addr_latch == 0x0c) |
| 635 | crtc_start_addr = ((data<<8) & 0x3f00) | (crtc_start_addr & 0xff); |
| 636 | else if(addr_latch == 0x0d) |
| 637 | crtc_start_addr = (crtc_start_addr & 0x3f00) | (data & 0xff); |
| 638 | |
| 639 | mc6845_register_w(devtag_get_device(space->machine, "crtc"), 0,data); |
| 640 | } |
| 641 | } |
| 642 | |
| 587 | 643 | static WRITE8_HANDLER( x1_io_w ) |
| 588 | 644 | { |
| 589 | 645 | if(io_bank_mode == 1) { x1_ex_gfxram_w(space, offset, data); } |
| r5529 | r5530 | |
| 595 | 651 | else if(offset >= 0x1000 && offset <= 0x10ff) { x1_pal_b_w(space, 0,data); } |
| 596 | 652 | else if(offset >= 0x1100 && offset <= 0x11ff) { x1_pal_r_w(space, 0,data); } |
| 597 | 653 | else if(offset >= 0x1200 && offset <= 0x12ff) { x1_pal_g_w(space, 0,data); } |
| 598 | | // else if(offset >= 0x1300 && offset <= 0x13ff) { x1_ply_w(space->machine, 0,data; } |
| 654 | else if(offset >= 0x1300 && offset <= 0x13ff) { x1_ply_w(space, 0,data); } |
| 599 | 655 | else if(offset >= 0x1400 && offset <= 0x17ff) { x1_pcg_w(space, offset-0x1400,data); } |
| 600 | | else if(offset == 0x1800 ) { mc6845_address_w(devtag_get_device(space->machine, "crtc"), 0,data); } |
| 601 | | else if(offset == 0x1801 ) { mc6845_register_w(devtag_get_device(space->machine, "crtc"), 0,data); } |
| 656 | else if(offset == 0x1800 || offset == 0x1801) { x1_6845_w(space, offset-0x1800, data); } |
| 602 | 657 | else if(offset >= 0x1900 && offset <= 0x19ff) { sub_io_w(space, 0,data); } |
| 603 | 658 | else if(offset >= 0x1a00 && offset <= 0x1aff) { ppi8255_w(devtag_get_device(space->machine, "ppi8255_0"), (offset-0x1a00) & 3,data); } |
| 604 | 659 | else if(offset >= 0x1b00 && offset <= 0x1bff) { ay8910_data_w(devtag_get_device(space->machine, "ay"), 0,data); } |
| r5529 | r5530 | |
| 612 | 667 | // else if(offset >= 0x1fd0 && offset <= 0x1fdf) { x1_scrn_w(space->machine,offset-0x1fd0,data); } |
| 613 | 668 | else if(offset >= 0x2000 && offset <= 0x2fff) { colorram[offset-0x2000] = data; } |
| 614 | 669 | else if(offset >= 0x3000 && offset <= 0x3fff) { videoram[offset-0x3000] = data; } |
| 615 | | else if(offset >= 0x4000 && offset <= 0xffff) { gfx_bitmap_ram[offset-0x4000] = data; } |
| 670 | else if(offset >= 0x4000 && offset <= 0xffff) { gfx_bitmap_ram[offset-0x4000+(ply_reg.gfx_bank*0xc000)] = data; } |
| 616 | 671 | else |
| 617 | 672 | { |
| 618 | 673 | logerror("(PC=%06x) Write %02x at i/o address %04x\n",cpu_get_pc(space->cpu),data,offset); |
| r5529 | r5530 | |
| 1106 | 1161 | |
| 1107 | 1162 | memory_set_bankptr(machine, 1, &ROM[0x00000]); |
| 1108 | 1163 | |
| 1109 | | memset(gfx_bitmap_ram,0x00,0xc000); |
| 1164 | memset(gfx_bitmap_ram,0x00,0xc000*2); |
| 1110 | 1165 | |
| 1111 | 1166 | for(i=0;i<0x1800;i++) |
| 1112 | 1167 | { |
| r5529 | r5530 | |
| 1150 | 1205 | DEVCB_NULL |
| 1151 | 1206 | }; |
| 1152 | 1207 | |
| 1208 | static INTERRUPT_GEN( x1_vbl ) |
| 1209 | { |
| 1210 | // pcg_reset = 1; |
| 1211 | } |
| 1153 | 1212 | |
| 1154 | 1213 | static MACHINE_DRIVER_START( x1 ) |
| 1155 | 1214 | /* basic machine hardware */ |
| 1156 | 1215 | MDRV_CPU_ADD("maincpu", Z80, XTAL_4MHz) |
| 1157 | 1216 | MDRV_CPU_PROGRAM_MAP(x1_mem) |
| 1158 | 1217 | MDRV_CPU_IO_MAP(x1_io) |
| 1218 | MDRV_CPU_VBLANK_INT("screen", x1_vbl) |
| 1159 | 1219 | |
| 1160 | 1220 | MDRV_Z80CTC_ADD( "ctc", XTAL_4MHz , ctc_intf ) |
| 1161 | 1221 | |
| r5529 | r5530 | |
| 1179 | 1239 | |
| 1180 | 1240 | MDRV_VIDEO_START(x1) |
| 1181 | 1241 | MDRV_VIDEO_UPDATE(x1) |
| 1242 | MDRV_VIDEO_EOF(x1) |
| 1182 | 1243 | |
| 1183 | 1244 | MDRV_MB8877_ADD("fdc",x1_mb8877a_interface) |
| 1184 | 1245 | |