src/mess/drivers/mz2500.c
| r8928 | r8929 | |
| 57 | 57 | /* video stuff*/ |
| 58 | 58 | static UINT8 text_reg[0x100], text_reg_index; |
| 59 | 59 | static UINT8 text_col_size, text_font_reg; |
| 60 | static UINT8 pal_select; |
| 60 | 61 | |
| 61 | 62 | static VIDEO_START( mz2500 ) |
| 62 | 63 | { |
| 63 | 64 | } |
| 64 | 65 | |
| 65 | | static VIDEO_UPDATE( mz2500 ) |
| 66 | static void draw_80x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) |
| 66 | 67 | { |
| 67 | | UINT8 *vram = memory_region(screen->machine, "maincpu"); |
| 68 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 68 | 69 | int x,y,count,xi,yi; |
| 69 | | // gfx_element *gfx;// = screen->machine->gfx[0]; |
| 70 | | UINT8 *gfx_data;// = pcg_bank ? memory_region(machine, "pcg") : memory_region(machine, "cgrom"); |
| 71 | | int w; |
| 70 | UINT8 *gfx_data; |
| 72 | 71 | |
| 73 | 72 | count = 0x70000; |
| 74 | 73 | |
| 75 | | w = (crtc_reg[0x0e] == 0x17) ? 1 : 2; //TODO |
| 76 | | |
| 77 | | if(text_font_reg) |
| 74 | for (y=0;y<25;y++) |
| 78 | 75 | { |
| 79 | | for (y=0;y<25;y++) |
| 76 | for (x=0;x<80;x++) |
| 80 | 77 | { |
| 81 | | for (x=0;x<40*w/*text_col_size*/;x++) |
| 82 | | { |
| 83 | | int tile = vram[count+0x0000] & 0xff; |
| 84 | | int attr = vram[count+0x0800]; |
| 85 | | int tile_bank = vram[count+0x1000] & 0x3f; |
| 86 | | int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0); |
| 87 | | //int gfx_num; |
| 88 | | int color = attr & 7; |
| 78 | int tile = vram[count+0x0000] & 0xff; |
| 79 | int attr = vram[count+0x0800]; |
| 80 | int tile_bank = vram[count+0x1000] & 0x3f; |
| 81 | int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0); |
| 82 | //int gfx_num; |
| 83 | int color = attr & 7; |
| 89 | 84 | |
| 90 | | if(gfx_sel == 0x80 || gfx_sel == 0xc0) |
| 91 | | gfx_data = memory_region(screen->machine,"kanji"); //TODO |
| 92 | | else |
| 93 | | gfx_data = memory_region(screen->machine,"pcg"); |
| 85 | if(gfx_sel == 0x80 || gfx_sel == 0xc0) |
| 86 | gfx_data = memory_region(machine,"kanji"); //TODO |
| 87 | else |
| 88 | gfx_data = memory_region(machine,"pcg"); |
| 94 | 89 | |
| 95 | | tile|= tile_bank << 8; |
| 90 | tile|= tile_bank << 8; |
| 96 | 91 | |
| 97 | | for(yi=0;yi<8;yi++) |
| 92 | for(yi=0;yi<8;yi++) |
| 93 | { |
| 94 | for(xi=0;xi<8;xi++) |
| 98 | 95 | { |
| 99 | | for(xi=0;xi<8;xi++) |
| 96 | UINT8 pen_bit[3],pen; |
| 97 | |
| 98 | if(gfx_sel & 0x8) |
| 100 | 99 | { |
| 101 | | UINT8 pen_bit[3],pen; |
| 100 | pen_bit[0] = ((gfx_data[tile*8+yi+0x1800]>>(7-xi)) & 1) ? 4 : 0; //G |
| 101 | pen_bit[1] = ((gfx_data[tile*8+yi+0x1000]>>(7-xi)) & 1) ? 2 : 0; //R |
| 102 | pen_bit[2] = ((gfx_data[tile*8+yi+0x0800]>>(7-xi)) & 1) ? 1 : 0; //B |
| 102 | 103 | |
| 103 | | if(gfx_sel & 0x8) |
| 104 | | { |
| 105 | | pen_bit[0] = ((gfx_data[tile*8+yi+0x1800]>>(7-xi)) & 1) ? 4 : 0; //G |
| 106 | | pen_bit[1] = ((gfx_data[tile*8+yi+0x1000]>>(7-xi)) & 1) ? 2 : 0; //R |
| 107 | | pen_bit[2] = ((gfx_data[tile*8+yi+0x0800]>>(7-xi)) & 1) ? 1 : 0; //B |
| 104 | pen = pen_bit[0]|pen_bit[1]|pen_bit[2]; |
| 105 | } |
| 106 | else |
| 107 | pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0; |
| 108 | 108 | |
| 109 | | pen = pen_bit[0]|pen_bit[1]|pen_bit[2]; |
| 110 | | } |
| 111 | | else |
| 112 | | pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0; |
| 109 | *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = machine->pens[pen]; |
| 110 | } |
| 111 | } |
| 112 | //drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile,color,0,0,x*8,(y)*8); |
| 113 | 113 | |
| 114 | | *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = screen->machine->pens[pen]; |
| 114 | count++; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static void draw_40x25(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect,int tv_mode) |
| 120 | { |
| 121 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 122 | int x,y,count,xi,yi; |
| 123 | UINT8 *gfx_data; |
| 124 | |
| 125 | count = 0x70000; |
| 126 | |
| 127 | if(tv_mode != 1) |
| 128 | popmessage("%02x",tv_mode); |
| 129 | |
| 130 | for (y=0;y<25;y++) |
| 131 | { |
| 132 | for (x=0;x<40;x++) |
| 133 | { |
| 134 | int tile = vram[count+0x0000] & 0xff; |
| 135 | int attr = vram[count+0x0800]; |
| 136 | int tile_bank = vram[count+0x1000] & 0x3f; |
| 137 | int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0); |
| 138 | //int gfx_num; |
| 139 | int color = attr & 7; |
| 140 | |
| 141 | if(gfx_sel == 0x80 || gfx_sel == 0xc0) |
| 142 | gfx_data = memory_region(machine,"kanji"); //TODO |
| 143 | else |
| 144 | gfx_data = memory_region(machine,"pcg"); |
| 145 | |
| 146 | tile|= tile_bank << 8; |
| 147 | |
| 148 | for(yi=0;yi<8;yi++) |
| 149 | { |
| 150 | for(xi=0;xi<8;xi++) |
| 151 | { |
| 152 | UINT8 pen_bit[3],pen; |
| 153 | |
| 154 | if(gfx_sel & 0x8) |
| 155 | { |
| 156 | pen_bit[0] = ((gfx_data[tile*8+yi+0x1800]>>(7-xi)) & 1) ? 4 : 0; //G |
| 157 | pen_bit[1] = ((gfx_data[tile*8+yi+0x1000]>>(7-xi)) & 1) ? 2 : 0; //R |
| 158 | pen_bit[2] = ((gfx_data[tile*8+yi+0x0800]>>(7-xi)) & 1) ? 1 : 0; //B |
| 159 | |
| 160 | pen = pen_bit[0]|pen_bit[1]|pen_bit[2]; |
| 115 | 161 | } |
| 162 | else |
| 163 | pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0; |
| 164 | |
| 165 | *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = machine->pens[pen]; |
| 116 | 166 | } |
| 167 | } |
| 117 | 168 | //drawgfx_opaque(bitmap,cliprect,screen->machine->gfx[gfx_num],tile,color,0,0,x*8,(y)*8); |
| 118 | 169 | |
| 119 | | count++; |
| 120 | | } |
| 170 | count++; |
| 121 | 171 | } |
| 122 | 172 | } |
| 173 | } |
| 174 | |
| 175 | static void draw_tv_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) |
| 176 | { |
| 177 | //w = (text_col_size) ? 2 : 1; //80 : 40 |
| 178 | if(text_col_size) |
| 179 | draw_80x25(machine,bitmap,cliprect); |
| 123 | 180 | else |
| 124 | 181 | { |
| 182 | //int tv_mode = (text_reg[0] & 0x0c) >> 2; |
| 183 | draw_40x25(machine,bitmap,cliprect,text_reg[0] >> 2); |
| 184 | } |
| 185 | |
| 186 | #if 0 |
| 187 | if(text_font_reg) |
| 188 | { |
| 189 | |
| 190 | } |
| 191 | else |
| 192 | { |
| 125 | 193 | for (y=0;y<25;y+=2) |
| 126 | 194 | { |
| 127 | 195 | for (x=0;x<40*w;x++) |
| 128 | 196 | { |
| 129 | 197 | int tile = vram[count+0x0000] & 0xfe; |
| 130 | | int attr = vram[count+0x800]; |
| 198 | int attr = vram[count+0x0800]; |
| 131 | 199 | int tile_bank = vram[count+0x1000] & 0x3f; |
| 132 | 200 | int gfx_sel = (attr & 0x38) | (vram[count+0x1000] & 0xc0); |
| 133 | 201 | //int gfx_num; |
| 134 | 202 | int color = attr & 7; |
| 135 | 203 | |
| 136 | 204 | if(gfx_sel == 0x80 || gfx_sel == 0xc0) |
| 137 | | gfx_data = memory_region(screen->machine,"kanji"); //TODO |
| 205 | gfx_data = memory_region(machine,"kanji"); //TODO |
| 138 | 206 | else |
| 139 | | gfx_data = memory_region(screen->machine,"pcg"); |
| 207 | gfx_data = memory_region(machine,"pcg"); |
| 140 | 208 | |
| 141 | 209 | tile|= tile_bank << 8; |
| 142 | 210 | |
| r8928 | r8929 | |
| 148 | 216 | |
| 149 | 217 | pen = ((gfx_data[tile*8+yi]>>(7-xi)) & 1) ? color : 0; |
| 150 | 218 | |
| 151 | | *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = screen->machine->pens[pen]; |
| 219 | *BITMAP_ADDR16(bitmap, (y*8+yi), x*8+xi) = machine->pens[pen]; |
| 152 | 220 | } |
| 153 | 221 | } |
| 154 | 222 | |
| r8928 | r8929 | |
| 159 | 227 | } |
| 160 | 228 | } |
| 161 | 229 | } |
| 230 | #endif |
| 231 | } |
| 162 | 232 | |
| 233 | static void draw_cg256_screen(running_machine *machine, bitmap_t *bitmap,const rectangle *cliprect) |
| 234 | { |
| 235 | static UINT32 count; |
| 236 | UINT8 *vram = memory_region(machine, "maincpu"); |
| 237 | UINT8 pen; |
| 238 | int x,y,xi; |
| 239 | |
| 240 | count = 0x40000; |
| 241 | |
| 242 | for(y=0;y<200;y++) |
| 243 | { |
| 244 | for(x=0;x<320;x+=8) |
| 245 | { |
| 246 | for(xi=0;xi<8;xi++) |
| 247 | { |
| 248 | pen = (vram[count]>>(xi)) & 1 ? 0xff : 0x00; |
| 249 | |
| 250 | if(pen) |
| 251 | *BITMAP_ADDR16(bitmap, y, x+xi) = machine->pens[pen+0x100]; |
| 252 | } |
| 253 | count++; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | static VIDEO_UPDATE( mz2500 ) |
| 259 | { |
| 260 | if(pal_select) |
| 261 | draw_tv_screen(screen->machine,bitmap,cliprect); |
| 262 | else //4096 mode colors |
| 263 | { |
| 264 | // ... |
| 265 | } |
| 266 | |
| 267 | if(crtc_reg[0x0e] == 0x1d) |
| 268 | draw_cg256_screen(screen->machine,bitmap,cliprect); |
| 269 | |
| 163 | 270 | return 0; |
| 164 | 271 | } |
| 165 | 272 | |
| r8928 | r8929 | |
| 304 | 411 | return vblank_bit | hblank_bit; |
| 305 | 412 | } |
| 306 | 413 | |
| 307 | | static WRITE8_HANDLER( mz2500_txt_crtc_w ) |
| 414 | /* |
| 415 | [0] ---x ---- line height (0) 16 (1) 20 |
| 416 | [0] ---- xx-- 40 column mode (0) 64 colors (1) screen 1 (2) screen 2 (3) screen 1 + screen 2 |
| 417 | [1] xxxx xxxx TV map offset low address value |
| 418 | [2] ---- -xxx TV map offset high address value |
| 419 | |
| 420 | [9] ---- xxxx vertical scrolling? (val * 2) |
| 421 | */ |
| 422 | |
| 423 | static UINT8 pal_256_param(int index, int param) |
| 308 | 424 | { |
| 425 | UINT8 val; |
| 426 | |
| 427 | switch(param & 3) |
| 428 | { |
| 429 | case 0: val = index & 0x80 ? 1 : 0; break; |
| 430 | case 1: val = index & 0x08 ? 1 : 0; break; |
| 431 | case 2: val = 1; break; |
| 432 | case 3: val = 0; break; |
| 433 | } |
| 434 | |
| 435 | return val; |
| 436 | } |
| 437 | |
| 438 | static WRITE8_HANDLER( mz2500_tv_crtc_w ) |
| 439 | { |
| 309 | 440 | switch(offset) |
| 310 | 441 | { |
| 311 | 442 | case 0: text_reg_index = data; break; |
| 312 | 443 | case 1: |
| 313 | 444 | text_reg[text_reg_index] = data; |
| 445 | if(text_reg_index == 0x0a) // set 256 color palette |
| 446 | { |
| 447 | int i,r,g,b; |
| 448 | UINT8 b_param,r_param,g_param; |
| 449 | |
| 450 | b_param = (data & 0x03) >> 0; |
| 451 | r_param = (data & 0x0c) >> 2; |
| 452 | g_param = (data & 0x30) >> 4; |
| 453 | |
| 454 | for(i = 0;i < 0x100;i++) |
| 455 | { |
| 456 | int bit0,bit1,bit2; |
| 457 | |
| 458 | bit0 = pal_256_param(i,b_param) ? 1 : 0; |
| 459 | bit1 = i & 0x01 ? 2 : 0; |
| 460 | bit2 = i & 0x10 ? 4 : 0; |
| 461 | b = bit0|bit1|bit2; |
| 462 | bit0 = pal_256_param(i,r_param) ? 1 : 0; |
| 463 | bit1 = i & 0x02 ? 2 : 0; |
| 464 | bit2 = i & 0x20 ? 4 : 0; |
| 465 | r = bit0|bit1|bit2; |
| 466 | bit0 = pal_256_param(i,g_param) ? 1 : 0; |
| 467 | bit1 = i & 0x04 ? 2 : 0; |
| 468 | bit2 = i & 0x40 ? 4 : 0; |
| 469 | g = bit0|bit1|bit2; |
| 470 | |
| 471 | palette_set_color_rgb(space->machine, i+0x100,pal3bit(r),pal3bit(g),pal3bit(b)); |
| 472 | } |
| 473 | } |
| 314 | 474 | //printf("[%02x]<- %02x\n",text_reg[text_reg_index],text_reg_index); |
| 315 | 475 | break; |
| 316 | 476 | case 2: /* CG MASK reg */ break; |
| r8928 | r8929 | |
| 492 | 652 | |
| 493 | 653 | crtc_reg[crtc_reg_index & 0x1f] = data; |
| 494 | 654 | |
| 495 | | if((crtc_reg_index & 0x1f) == 0x08) //accessing vs lo reg clears vs hi reg |
| 655 | if((crtc_reg_index & 0x1f) == 0x08) //accessing VS LO reg clears VS HI reg |
| 496 | 656 | crtc_reg[0x09] = 0; |
| 497 | 657 | |
| 498 | | if((crtc_reg_index & 0x1f) == 0x0a) //accessing ve lo reg clears ve hi reg |
| 658 | if((crtc_reg_index & 0x1f) == 0x0a) //accessing VE LO reg clears VE HI reg |
| 499 | 659 | crtc_reg[0x0b] = 0; |
| 500 | 660 | |
| 501 | 661 | if(crtc_reg_index & 0x80) //enable auto-inc |
| r8928 | r8929 | |
| 523 | 683 | hs = (crtc_reg[0x0c] & 0x7f)*8; |
| 524 | 684 | he = (crtc_reg[0x0d] & 0x7f)*8; |
| 525 | 685 | |
| 526 | | popmessage("%d %d %d %d %02x",vs,ve,hs,he,crtc_reg[0x0e]); |
| 686 | // popmessage("%d %d %d %d %02x",vs,ve,hs,he,crtc_reg[0x0e]); |
| 527 | 687 | |
| 528 | 688 | space->machine->primary_screen->configure(720, 480, visarea, space->machine->primary_screen->frame_period().attoseconds); //TODO |
| 529 | 689 | } |
| r8928 | r8929 | |
| 538 | 698 | pit8253_gate0_w(pit8253, 0); |
| 539 | 699 | pit8253_gate1_w(pit8253, 0); |
| 540 | 700 | pit8253_gate0_w(pit8253, 1); |
| 541 | | pit8253_gate1_w(pit8253, 1); |
| 701 | pit8253_gate1_w(pit8253, 1); |
| 542 | 702 | } |
| 543 | | |
| 703 | |
| 544 | 704 | static ADDRESS_MAP_START(mz2500_io, ADDRESS_SPACE_IO, 8) |
| 545 | 705 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 546 | 706 | // AM_RANGE(0x60, 0x63) AM_WRITE(w3100a_w) |
| r8928 | r8929 | |
| 574 | 734 | AM_RANGE(0xea, 0xeb) AM_DEVREADWRITE("z80pio_1", z80pio_d_r, z80pio_d_w) |
| 575 | 735 | // AM_RANGE(0xef, 0xef) AM_READWRITE(joystick_r,joystick_w) |
| 576 | 736 | AM_RANGE(0xf0, 0xf3) AM_WRITE(timer_w) |
| 577 | | AM_RANGE(0xf4, 0xf7) AM_READ(mz2500_crtc_hvblank_r) AM_WRITE(mz2500_txt_crtc_w) |
| 737 | AM_RANGE(0xf4, 0xf7) AM_READ(mz2500_crtc_hvblank_r) AM_WRITE(mz2500_tv_crtc_w) |
| 578 | 738 | // AM_RANGE(0xf8, 0xf9) AM_READWRITE(extrom_r,extrom_w) |
| 579 | 739 | ADDRESS_MAP_END |
| 580 | 740 | |
| r8928 | r8929 | |
| 932 | 1092 | { |
| 933 | 1093 | UINT8 *RAM = memory_region(machine, "maincpu"); |
| 934 | 1094 | UINT8 *IPL = memory_region(machine, "ipl"); |
| 935 | | int i; |
| 1095 | UINT32 i; |
| 936 | 1096 | |
| 937 | 1097 | mz2500_reset(IPL_RESET); |
| 938 | 1098 | |
| 939 | 1099 | //irq_vector[0] = 0xef; /* RST 28h - vblank */ |
| 940 | 1100 | |
| 941 | | text_col_size = 40; |
| 1101 | text_col_size = 0; |
| 942 | 1102 | text_font_reg = 0; |
| 943 | 1103 | |
| 944 | 1104 | /* copy IPL to its natural bank ROM/RAM position */ |
| r8928 | r8929 | |
| 948 | 1108 | RAM[i+0x68000] = IPL[i]; |
| 949 | 1109 | } |
| 950 | 1110 | |
| 1111 | /* clear CG RAM */ |
| 1112 | for(i=0;i<0x20000;i++) |
| 1113 | RAM[i+0x40000] = 0x00; |
| 1114 | |
| 951 | 1115 | /* disable IRQ */ |
| 952 | 1116 | for(i=0;i<4;i++) |
| 953 | 1117 | irq_mask[i] = 0; |
| r8928 | r8929 | |
| 1083 | 1247 | static WRITE8_DEVICE_HANDLER( mz2500_pio1_porta_w ) |
| 1084 | 1248 | { |
| 1085 | 1249 | // printf("%02x\n",data); |
| 1086 | | text_col_size = (data & 0x20) ? 80 : 40; |
| 1250 | text_col_size = (data & 0x20) ? 1 : 0; |
| 1087 | 1251 | key_mux = data & 0x1f; |
| 1088 | 1252 | } |
| 1089 | 1253 | |
| r8928 | r8929 | |
| 1132 | 1296 | ---- --x- floppy reverse bit (controls wd17xx bits in command registers) |
| 1133 | 1297 | */ |
| 1134 | 1298 | |
| 1135 | | //printf("%02x\n",data); |
| 1136 | | fdc_reverse = data & 2 ? 0x00 : 0xff; |
| 1299 | // printf("%02x\n",data); |
| 1300 | fdc_reverse = (data & 2) ? 0x00 : 0xff; |
| 1301 | pal_select = (data & 4) ? 1 : 0; |
| 1302 | if((data & 4) == 0) |
| 1303 | printf("Warning: 4096 color mode used\n"); |
| 1137 | 1304 | } |
| 1138 | 1305 | |
| 1139 | 1306 | static const ym2203_interface ym2203_interface_1 = |
| r8928 | r8929 | |
| 1220 | 1387 | MDRV_SOUND_ADD("ym", YM2203, 6000000/2) //unknown clock / divider |
| 1221 | 1388 | MDRV_SOUND_CONFIG(ym2203_interface_1) |
| 1222 | 1389 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.60) |
| 1223 | | |
| 1390 | |
| 1224 | 1391 | MDRV_PIT8253_ADD("pit", mz2500_pit8253_intf) |
| 1225 | 1392 | MACHINE_DRIVER_END |
| 1226 | 1393 | |