src/mess/drivers/mz2500.c
| r8930 | r8931 | |
| 6 | 6 | |
| 7 | 7 | TODO: |
| 8 | 8 | - floppy device; |
| 9 | | - graphics are really a bare minimum, this thing is very complex; |
| 9 | - graphics are really a bare minimum, this system is very complex; |
| 10 | 10 | - keyboard inputs (needs something that actually works); |
| 11 | 11 | |
| 12 | 12 | memory map: |
| r8930 | r8931 | |
| 41 | 41 | static UINT8 kanji_bank; |
| 42 | 42 | static UINT8 fdc_reverse; |
| 43 | 43 | static UINT8 key_mux; |
| 44 | | static UINT8 crtc_reg_index; |
| 45 | | static UINT8 crtc_reg[0x20]; |
| 44 | static UINT8 cg_reg_index; |
| 45 | static UINT8 cg_reg[0x20]; |
| 46 | 46 | |
| 47 | 47 | #define WRAM_RESET 0 |
| 48 | 48 | #define IPL_RESET 1 |
| r8930 | r8931 | |
| 68 | 68 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 69 | 69 | int x,y,count,xi,yi; |
| 70 | 70 | UINT8 *gfx_data; |
| 71 | UINT8 y_step; |
| 71 | 72 | |
| 72 | 73 | count = 0x70000; |
| 73 | 74 | |
| 74 | | for (y=0;y<25;y++) |
| 75 | y_step = (text_font_reg) ? 1 : 2; |
| 76 | |
| 77 | for (y=0;y<25;y+=y_step) |
| 75 | 78 | { |
| 76 | 79 | for (x=0;x<80;x++) |
| 77 | 80 | { |
| r8930 | r8931 | |
| 89 | 92 | |
| 90 | 93 | tile|= tile_bank << 8; |
| 91 | 94 | |
| 92 | | for(yi=0;yi<8;yi++) |
| 95 | for(yi=0;yi<8*y_step;yi++) |
| 93 | 96 | { |
| 94 | 97 | for(xi=0;xi<8;xi++) |
| 95 | 98 | { |
| r8930 | r8931 | |
| 121 | 124 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 122 | 125 | int x,y,count,xi,yi; |
| 123 | 126 | UINT8 *gfx_data; |
| 127 | UINT8 y_step; |
| 124 | 128 | |
| 125 | 129 | count = 0x70000; |
| 126 | 130 | |
| 127 | | // if(tv_mode != 1) |
| 128 | | // popmessage("%02x %02x %02x",tv_mode,text_reg[1],text_reg[2]); |
| 131 | if(tv_mode != 1) |
| 132 | popmessage("%02x %02x %02x",tv_mode,text_reg[1],text_reg[2]); |
| 129 | 133 | |
| 130 | | for (y=0;y<25;y++) |
| 134 | y_step = (text_font_reg) ? 1 : 2; |
| 135 | |
| 136 | for (y=0;y<25;y+=y_step) |
| 131 | 137 | { |
| 132 | 138 | for (x=0;x<40;x++) |
| 133 | 139 | { |
| r8930 | r8931 | |
| 145 | 151 | |
| 146 | 152 | tile|= tile_bank << 8; |
| 147 | 153 | |
| 148 | | for(yi=0;yi<8;yi++) |
| 154 | for(yi=0;yi<8*y_step;yi++) |
| 149 | 155 | { |
| 150 | 156 | for(xi=0;xi<8;xi++) |
| 151 | 157 | { |
| r8930 | r8931 | |
| 178 | 184 | if(text_col_size) |
| 179 | 185 | draw_80x25(machine,bitmap,cliprect); |
| 180 | 186 | else |
| 181 | | { |
| 182 | | //int tv_mode = (text_reg[0] & 0x0c) >> 2; |
| 183 | 187 | draw_40x25(machine,bitmap,cliprect,text_reg[0] >> 2); |
| 184 | | } |
| 185 | 188 | |
| 186 | 189 | #if 0 |
| 187 | 190 | if(text_font_reg) |
| r8930 | r8931 | |
| 230 | 233 | #endif |
| 231 | 234 | } |
| 232 | 235 | |
| 233 | | static void draw_cg16_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) |
| 236 | static void draw_cg16_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int plane,int x_size) |
| 234 | 237 | { |
| 235 | 238 | static UINT32 count; |
| 236 | 239 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 237 | 240 | UINT8 pen,pen_bit[4]; |
| 238 | | int x,y,xi; |
| 241 | int x,y,xi,pen_i; |
| 239 | 242 | |
| 240 | 243 | count = 0x40000; |
| 241 | 244 | |
| 242 | 245 | for(y=0;y<200;y++) |
| 243 | 246 | { |
| 244 | | for(x=0;x<320;x+=8) |
| 247 | for(x=0;x<x_size;x+=8) |
| 245 | 248 | { |
| 246 | 249 | for(xi=0;xi<8;xi++) |
| 247 | 250 | { |
| 248 | | pen_bit[0] = (vram[count+0x0000]>>(xi)) & 1 ? 1 : 0; |
| 249 | | pen_bit[1] = (vram[count+0x4000]>>(xi)) & 1 ? 2 : 0; |
| 250 | | pen_bit[2] = (vram[count+0x8000]>>(xi)) & 1 ? 4 : 0; |
| 251 | | pen_bit[3] = (vram[count+0xc000]>>(xi)) & 1 ? 0 : 8; //FIXME: this should be swapped |
| 251 | pen_bit[0] = (vram[count+0x0000 + plane*0x2000]>>(xi)) & 1 ? 1 : 0; //B |
| 252 | pen_bit[1] = (vram[count+0x4000 + plane*0x2000]>>(xi)) & 1 ? 2 : 0; //R |
| 253 | pen_bit[2] = (vram[count+0x8000 + plane*0x2000]>>(xi)) & 1 ? 4 : 0; //G |
| 254 | pen_bit[3] = (vram[count+0xc000 + plane*0x2000]>>(xi)) & 1 ? 0 : 8; //I FIXME: this should be swapped |
| 252 | 255 | |
| 253 | | pen = pen_bit[0]|pen_bit[1]|pen_bit[2]|pen_bit[3]; |
| 256 | pen = 0; |
| 257 | for(pen_i=0;pen_i<4;pen_i++) |
| 258 | pen |= pen_bit[pen_i]; |
| 254 | 259 | |
| 255 | 260 | if(pen != 8) |
| 256 | 261 | *BITMAP_ADDR16(bitmap, y, x+xi) = machine->pens[pen+0x200]; |
| r8930 | r8931 | |
| 260 | 265 | } |
| 261 | 266 | } |
| 262 | 267 | |
| 268 | /* TODO: this probably allocates CLUT to somewhere ... */ |
| 263 | 269 | static void draw_cg256_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) |
| 264 | 270 | { |
| 265 | 271 | static UINT32 count; |
| 266 | 272 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 267 | | UINT8 pen; |
| 268 | | int x,y,xi; |
| 273 | UINT8 pen,pen_bit[8]; |
| 274 | int x,y,xi,pen_i; |
| 269 | 275 | |
| 270 | 276 | count = 0x40000; |
| 271 | 277 | |
| r8930 | r8931 | |
| 275 | 281 | { |
| 276 | 282 | for(xi=0;xi<8;xi++) |
| 277 | 283 | { |
| 278 | | pen = (vram[count]>>(xi)) & 1 ? 0xff : 0x00; |
| 284 | pen_bit[0] = (vram[count + 0x2000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x10) : 0; // B1 |
| 285 | pen_bit[1] = (vram[count + 0x0000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x01) : 0; // B0 |
| 286 | pen_bit[2] = (vram[count + 0x6000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x20) : 0; // R1 |
| 287 | pen_bit[3] = (vram[count + 0x4000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x02) : 0; // R0 |
| 288 | pen_bit[4] = (vram[count + 0xa000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x40) : 0; // G1 |
| 289 | pen_bit[5] = (vram[count + 0x8000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x04) : 0; // G0 |
| 290 | pen_bit[6] = (vram[count + 0xe000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x80) : 0; // I1 |
| 291 | pen_bit[7] = (vram[count + 0xc000]>>(xi)) & 1 ? (cg_reg[0x18] & 0x08) : 0; // I0 |
| 279 | 292 | |
| 293 | pen = 0; |
| 294 | for(pen_i=0;pen_i<8;pen_i++) |
| 295 | pen |= pen_bit[pen_i]; |
| 296 | |
| 280 | 297 | if(pen) |
| 281 | 298 | *BITMAP_ADDR16(bitmap, y, x+xi) = machine->pens[pen+0x100]; |
| 282 | 299 | } |
| r8930 | r8931 | |
| 287 | 304 | |
| 288 | 305 | static VIDEO_UPDATE( mz2500 ) |
| 289 | 306 | { |
| 307 | bitmap_fill(bitmap, cliprect, MAKE_ARGB(0xff,0x00,0x00,0x00)); |
| 308 | |
| 290 | 309 | if(pal_select) |
| 291 | | { |
| 292 | 310 | draw_tv_screen(screen->machine,bitmap,cliprect); |
| 293 | | draw_cg16_screen(screen->machine,bitmap,cliprect); |
| 294 | | } |
| 295 | 311 | else //4096 mode colors |
| 296 | 312 | { |
| 297 | 313 | // ... |
| 298 | 314 | } |
| 299 | 315 | |
| 300 | | if(crtc_reg[0x0e] == 0x1d) |
| 301 | | draw_cg256_screen(screen->machine,bitmap,cliprect); |
| 302 | 316 | |
| 317 | switch(cg_reg[0x0e]) |
| 318 | { |
| 319 | case 0x03: /* CG 4 color mode */ break; |
| 320 | case 0x14: |
| 321 | draw_cg16_screen(screen->machine,bitmap,cliprect,0,320); |
| 322 | draw_cg16_screen(screen->machine,bitmap,cliprect,1,320); |
| 323 | break; |
| 324 | case 0x15: |
| 325 | draw_cg16_screen(screen->machine,bitmap,cliprect,1,320); |
| 326 | draw_cg16_screen(screen->machine,bitmap,cliprect,0,320); |
| 327 | break; |
| 328 | case 0x17: |
| 329 | draw_cg16_screen(screen->machine,bitmap,cliprect,0,640); |
| 330 | break; |
| 331 | case 0x1d: |
| 332 | draw_cg256_screen(screen->machine,bitmap,cliprect); |
| 333 | break; |
| 334 | } |
| 335 | |
| 303 | 336 | return 0; |
| 304 | 337 | } |
| 305 | 338 | |
| r8930 | r8931 | |
| 674 | 707 | |
| 675 | 708 | */ |
| 676 | 709 | |
| 710 | static READ8_HANDLER( mz2500_rplane_latch_r ) |
| 711 | { |
| 712 | if(cg_reg[0x07] & 0x10) |
| 713 | { |
| 714 | static UINT8 vblank_bit; |
| 677 | 715 | |
| 678 | | static WRITE8_HANDLER( mz2500_crtc_addr_w ) |
| 716 | // ---- ---x clear flag |
| 717 | vblank_bit = space->machine->primary_screen->vblank() ? 0 : 0x80; |
| 718 | |
| 719 | return vblank_bit; |
| 720 | } |
| 721 | else |
| 722 | return 0xff; |
| 723 | } |
| 724 | |
| 725 | static WRITE8_HANDLER( mz2500_cg_addr_w ) |
| 679 | 726 | { |
| 680 | | crtc_reg_index = data; |
| 727 | cg_reg_index = data; |
| 681 | 728 | } |
| 682 | 729 | |
| 683 | | static WRITE8_HANDLER( mz2500_crtc_data_w ) |
| 730 | static WRITE8_HANDLER( mz2500_cg_data_w ) |
| 684 | 731 | { |
| 685 | | crtc_reg[crtc_reg_index & 0x1f] = data; |
| 732 | cg_reg[cg_reg_index & 0x1f] = data; |
| 686 | 733 | |
| 687 | | if((crtc_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg |
| 688 | | crtc_reg[0x09] = 0; |
| 734 | if((cg_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg |
| 735 | cg_reg[0x09] = 0; |
| 689 | 736 | |
| 690 | | if((crtc_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg |
| 691 | | crtc_reg[0x0b] = 0; |
| 737 | if((cg_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg |
| 738 | cg_reg[0x0b] = 0; |
| 692 | 739 | |
| 693 | | if((crtc_reg_index & 0x1f) == 0x05) //clear bitmap buffer |
| 740 | if((cg_reg_index & 0x1f) == 0x05) //clear bitmap buffer |
| 694 | 741 | { |
| 695 | 742 | UINT32 i; |
| 696 | 743 | UINT8 *vram = memory_region(space->machine, "maincpu"); |
| 697 | 744 | |
| 698 | 745 | /* TODO: this isn't yet 100% accurate */ |
| 699 | | if(crtc_reg[0x05] & 1) |
| 746 | if(cg_reg[0x05] & 1) |
| 700 | 747 | { |
| 701 | 748 | for(i=0;i<0x4000;i++) |
| 702 | 749 | vram[i+0x40000] = 0x00; //clear B |
| 703 | 750 | } |
| 704 | | if(crtc_reg[0x05] & 2) |
| 751 | if(cg_reg[0x05] & 2) |
| 705 | 752 | { |
| 706 | 753 | for(i=0;i<0x4000;i++) |
| 707 | 754 | vram[i+0x44000] = 0x00; //clear R |
| 708 | 755 | } |
| 709 | | if(crtc_reg[0x05] & 4) |
| 756 | if(cg_reg[0x05] & 4) |
| 710 | 757 | { |
| 711 | 758 | for(i=0;i<0x4000;i++) |
| 712 | 759 | vram[i+0x48000] = 0x00; //clear G |
| 713 | 760 | } |
| 714 | | if(crtc_reg[0x05] & 8) |
| 761 | if(cg_reg[0x05] & 8) |
| 715 | 762 | { |
| 716 | 763 | for(i=0;i<0x4000;i++) |
| 717 | 764 | vram[i+0x4c000] = 0x00; //clear I |
| 718 | 765 | } |
| 719 | 766 | } |
| 720 | 767 | |
| 721 | | if(crtc_reg_index & 0x80) //enable auto-inc |
| 722 | | crtc_reg_index = (crtc_reg_index & 0xfc) | ((crtc_reg_index + 1) & 0x03); |
| 768 | if(cg_reg_index & 0x80) //enable auto-inc |
| 769 | cg_reg_index = (cg_reg_index & 0xfc) | ((cg_reg_index + 1) & 0x03); |
| 723 | 770 | |
| 724 | 771 | { |
| 725 | 772 | static UINT16 vs,ve,hs,he; |
| 726 | 773 | rectangle visarea; |
| 727 | | static UINT16 x_size; |
| 728 | 774 | |
| 729 | | if(crtc_reg[0x0e] == 0x15) |
| 730 | | x_size = 640; |
| 731 | | else if(crtc_reg[0x0e] == 0x17 || crtc_reg[0x0e] == 0x1d) |
| 732 | | x_size = 320; |
| 733 | | else |
| 734 | | x_size = 640; // TODO |
| 735 | | |
| 736 | 775 | visarea.min_x = 0; |
| 737 | 776 | visarea.min_y = 0; |
| 738 | | visarea.max_x = x_size - 1; |
| 777 | visarea.max_x = 640 - 1; |
| 739 | 778 | visarea.max_y = 200 - 1; |
| 740 | 779 | |
| 741 | | vs = (crtc_reg[0x08]) | ((crtc_reg[0x09]<<8) & 1); |
| 742 | | ve = (crtc_reg[0x0a]) | ((crtc_reg[0x0b]<<8) & 1); |
| 743 | | hs = (crtc_reg[0x0c] & 0x7f)*8; |
| 744 | | he = (crtc_reg[0x0d] & 0x7f)*8; |
| 780 | vs = (cg_reg[0x08]) | ((cg_reg[0x09]<<8) & 1); |
| 781 | ve = (cg_reg[0x0a]) | ((cg_reg[0x0b]<<8) & 1); |
| 782 | hs = (cg_reg[0x0c] & 0x7f)*8; |
| 783 | he = (cg_reg[0x0d] & 0x7f)*8; |
| 745 | 784 | |
| 746 | | // popmessage("%d %d %d %d %02x",vs,ve,hs,he,crtc_reg[0x0e]); |
| 785 | // popmessage("%d %d %d %d %02x",vs,ve,hs,he,cg_reg[0x0e]); |
| 747 | 786 | |
| 748 | 787 | space->machine->primary_screen->configure(720, 480, visarea, space->machine->primary_screen->frame_period().attoseconds); //TODO |
| 749 | 788 | } |
| r8930 | r8931 | |
| 811 | 850 | AM_RANGE(0xb4, 0xb4) AM_READWRITE(mz2500_bank_addr_r,mz2500_bank_addr_w) |
| 812 | 851 | AM_RANGE(0xb5, 0xb5) AM_READWRITE(mz2500_bank_data_r,mz2500_bank_data_w) |
| 813 | 852 | // AM_RANGE(0xb8, 0xb9) AM_READWRITE(kanji_r,kanji_w) |
| 814 | | AM_RANGE(0xbc, 0xbc) AM_WRITE(mz2500_crtc_addr_w) |
| 815 | | AM_RANGE(0xbd, 0xbd) AM_WRITE(mz2500_crtc_data_w) |
| 853 | AM_RANGE(0xbc, 0xbc) AM_WRITE(mz2500_cg_addr_w) |
| 854 | AM_RANGE(0xbd, 0xbd) AM_READ(mz2500_rplane_latch_r) AM_WRITE(mz2500_cg_data_w) |
| 816 | 855 | // AM_RANGE(0xbc, 0xbf) AM_READ(mz2500_crtc_cg_r) //reads plane |
| 817 | 856 | AM_RANGE(0xc6, 0xc6) AM_WRITE(mz2500_irq_sel_w) |
| 818 | 857 | AM_RANGE(0xc7, 0xc7) AM_WRITE(mz2500_irq_data_w) |