src/mess/drivers/z100.c
| r12306 | r12307 | |
| 6 | 6 | |
| 7 | 7 | TODO: |
| 8 | 8 | - remove parity check IRQ patch (understand what it really wants there!) |
| 9 | - video RAM banks not fully understood |
| 9 | 10 | |
| 10 | 11 | ============================================================================ |
| 11 | 12 | |
| r12306 | r12307 | |
| 148 | 149 | : driver_device(mconfig, type, tag) |
| 149 | 150 | { } |
| 150 | 151 | |
| 152 | UINT8 *m_tvram; |
| 151 | 153 | UINT8 *m_gvram; |
| 152 | | UINT8 m_keyb_press; |
| 154 | UINT8 m_keyb_press,m_keyb_status; |
| 155 | UINT8 m_tbank; |
| 156 | UINT8 m_gbank; |
| 157 | UINT8 m_clr_val; |
| 158 | UINT8 m_crtc_vreg[0x100],m_crtc_index; |
| 159 | |
| 160 | mc6845_device *m_mc6845; |
| 161 | |
| 153 | 162 | }; |
| 154 | 163 | |
| 164 | #define mc6845_h_char_total (state->m_crtc_vreg[0]) |
| 165 | #define mc6845_h_display (state->m_crtc_vreg[1]) |
| 166 | #define mc6845_h_sync_pos (state->m_crtc_vreg[2]) |
| 167 | #define mc6845_sync_width (state->m_crtc_vreg[3]) |
| 168 | #define mc6845_v_char_total (state->m_crtc_vreg[4]) |
| 169 | #define mc6845_v_total_adj (state->m_crtc_vreg[5]) |
| 170 | #define mc6845_v_display (state->m_crtc_vreg[6]) |
| 171 | #define mc6845_v_sync_pos (state->m_crtc_vreg[7]) |
| 172 | #define mc6845_mode_ctrl (state->m_crtc_vreg[8]) |
| 173 | #define mc6845_tile_height (state->m_crtc_vreg[9]+1) |
| 174 | #define mc6845_cursor_y_start (state->m_crtc_vreg[0x0a]) |
| 175 | #define mc6845_cursor_y_end (state->m_crtc_vreg[0x0b]) |
| 176 | #define mc6845_start_addr (((state->m_crtc_vreg[0x0c]<<8) & 0x3f00) | (state->m_crtc_vreg[0x0d] & 0xff)) |
| 177 | #define mc6845_cursor_addr (((state->m_crtc_vreg[0x0e]<<8) & 0x3f00) | (state->m_crtc_vreg[0x0f] & 0xff)) |
| 178 | #define mc6845_light_pen_addr (((state->m_crtc_vreg[0x10]<<8) & 0x3f00) | (state->m_crtc_vreg[0x11] & 0xff)) |
| 179 | #define mc6845_update_addr (((state->m_crtc_vreg[0x12]<<8) & 0x3f00) | (state->m_crtc_vreg[0x13] & 0xff)) |
| 180 | |
| 181 | |
| 155 | 182 | static VIDEO_START( z100 ) |
| 156 | 183 | { |
| 184 | z100_state *state = machine.driver_data<z100_state>(); |
| 157 | 185 | |
| 186 | state->m_tvram = auto_alloc_array_clear(machine, UINT8, 0x30000); |
| 187 | state->m_gvram = auto_alloc_array_clear(machine, UINT8, 0x30000*3); |
| 158 | 188 | } |
| 159 | 189 | |
| 160 | 190 | static SCREEN_UPDATE( z100 ) |
| r12306 | r12307 | |
| 162 | 192 | z100_state *state = screen->machine().driver_data<z100_state>(); |
| 163 | 193 | int x,y,xi,yi; |
| 164 | 194 | int dot; |
| 195 | UINT32 count; |
| 196 | int r,g,b; |
| 165 | 197 | |
| 166 | 198 | bitmap_fill(bitmap, cliprect, 0); |
| 167 | 199 | |
| 168 | | for (y=0;y<25;y++) |
| 200 | count = 0; |
| 201 | for(y=0;y<216;y++) |
| 169 | 202 | { |
| 170 | | for(x=0;x<80;x++) |
| 203 | for(x=0;x<1024;x+=8) |
| 171 | 204 | { |
| 205 | for(xi=0;xi<8;xi++) |
| 206 | { |
| 207 | b = ((state->m_gvram[count+0x20000] >> (7-xi)) & 1) << 0; |
| 208 | r = ((state->m_gvram[count+0x00000] >> (7-xi)) & 1) << 1; |
| 209 | g = ((state->m_gvram[count+0x10000] >> (7-xi)) & 1) << 2; |
| 210 | |
| 211 | if(y < 216 && x+xi < 640) /* TODO: safety check */ |
| 212 | *BITMAP_ADDR16(bitmap, y, x+xi) = screen->machine().pens[r|g|b]; |
| 213 | } |
| 214 | |
| 215 | count++; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | for(y=0;y<mc6845_v_display;y++) |
| 220 | { |
| 221 | for(x=0;x<mc6845_h_display;x++) |
| 222 | { |
| 172 | 223 | UINT32 base_offs,attr_offs; |
| 173 | 224 | int color; |
| 174 | 225 | |
| 175 | 226 | attr_offs = 0x20000 + y * 0x800 + x + 0x500; |
| 176 | 227 | |
| 177 | | color = state->m_gvram[attr_offs] & 7; |
| 228 | color = state->m_tvram[attr_offs] & 7; |
| 178 | 229 | |
| 179 | | for(yi=0;yi<8;yi++) |
| 230 | for(yi=0;yi<mc6845_tile_height;yi++) |
| 180 | 231 | { |
| 181 | 232 | base_offs = 0x20000 + y * 0x800 + yi * 0x80 + x; |
| 182 | 233 | |
| 183 | 234 | for(xi=0;xi<8;xi++) |
| 184 | 235 | { |
| 185 | | dot = ((state->m_gvram[base_offs] >> (7-xi)) & 1); |
| 236 | dot = ((state->m_tvram[base_offs] >> (7-xi)) & 1); |
| 186 | 237 | |
| 187 | 238 | if(dot) |
| 188 | | if(y*8+yi < 216 && x*8+xi < 640) /* TODO: safety check */ |
| 189 | | *BITMAP_ADDR16(bitmap, y*8+yi, x*8+xi) = screen->machine().pens[color]; |
| 239 | if(y*mc6845_tile_height+yi < 216 && x*8+xi < 640) /* TODO: safety check */ |
| 240 | *BITMAP_ADDR16(bitmap, y*mc6845_tile_height+yi, x*8+xi) = screen->machine().pens[color]; |
| 190 | 241 | } |
| 191 | 242 | } |
| 192 | 243 | } |
| r12306 | r12307 | |
| 195 | 246 | return 0; |
| 196 | 247 | } |
| 197 | 248 | |
| 249 | static READ8_HANDLER( z100_vram_r ) |
| 250 | { |
| 251 | z100_state *state = space->machine().driver_data<z100_state>(); |
| 252 | UINT8 res; |
| 253 | |
| 254 | res = 0; |
| 255 | |
| 256 | if(state->m_gbank == 0xf) |
| 257 | res |= state->m_tvram[offset & 0x3ffff]; |
| 258 | else if(state->m_gbank & 7) |
| 259 | res |= state->m_gvram[offset]; |
| 260 | |
| 261 | return res; |
| 262 | } |
| 263 | |
| 264 | static WRITE8_HANDLER( z100_vram_w ) |
| 265 | { |
| 266 | z100_state *state = space->machine().driver_data<z100_state>(); |
| 267 | |
| 268 | if(state->m_gbank == 0xf) |
| 269 | state->m_tvram[offset & 0x3ffff] = data; |
| 270 | else |
| 271 | { |
| 272 | int i; |
| 273 | |
| 274 | for(i=0;i<3;i++) |
| 275 | { |
| 276 | if(state->m_gbank & (1 << i)) |
| 277 | state->m_gvram[(offset & 0xffff)+0x10000*i] = data; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 198 | 282 | static ADDRESS_MAP_START(z100_mem, AS_PROGRAM, 8) |
| 199 | 283 | ADDRESS_MAP_UNMAP_HIGH |
| 200 | 284 | AM_RANGE(0x00000,0x1ffff) AM_RAM // 128 KB RAM |
| 201 | 285 | // AM_RANGE(0xb0000,0xbffff) AM_ROM // expansion ROM |
| 202 | | AM_RANGE(0xc0000,0xeffff) AM_RAM AM_BASE_MEMBER(z100_state,m_gvram) // Blue / Red / Green |
| 286 | AM_RANGE(0xc0000,0xeffff) AM_READWRITE(z100_vram_r,z100_vram_w) // Blue / Red / Green |
| 203 | 287 | // AM_RANGE(0xfbffa,0xfbffb) // expansion ROM check ID 0x4550 |
| 204 | 288 | AM_RANGE(0xfc000,0xfffff) AM_ROM AM_REGION("ipl", 0) |
| 205 | 289 | ADDRESS_MAP_END |
| r12306 | r12307 | |
| 208 | 292 | { |
| 209 | 293 | z100_state *state = space->machine().driver_data<z100_state>(); |
| 210 | 294 | |
| 295 | if(state->m_keyb_press) |
| 296 | { |
| 297 | UINT8 res; |
| 298 | |
| 299 | res = state->m_keyb_press; |
| 300 | |
| 301 | state->m_keyb_press = 0; |
| 302 | return res; |
| 303 | } |
| 304 | |
| 211 | 305 | return state->m_keyb_press; |
| 212 | 306 | } |
| 213 | 307 | |
| 214 | 308 | static READ8_HANDLER(keyb_status_r) |
| 215 | 309 | { |
| 216 | | return 1; |
| 310 | z100_state *state = space->machine().driver_data<z100_state>(); |
| 311 | |
| 312 | if(state->m_keyb_status) |
| 313 | { |
| 314 | state->m_keyb_status = 0; |
| 315 | return 1; |
| 316 | } |
| 317 | |
| 318 | return state->m_keyb_status; |
| 217 | 319 | } |
| 218 | 320 | |
| 219 | 321 | static WRITE8_HANDLER(keyb_command_w) |
| r12306 | r12307 | |
| 221 | 323 | // ... |
| 222 | 324 | } |
| 223 | 325 | |
| 326 | static WRITE8_HANDLER( z100_6845_address_w ) |
| 327 | { |
| 328 | z100_state *state = space->machine().driver_data<z100_state>(); |
| 329 | |
| 330 | state->m_crtc_index = data; |
| 331 | state->m_mc6845->address_w(*space, offset, data); |
| 332 | } |
| 333 | |
| 334 | static WRITE8_HANDLER( z100_6845_data_w ) |
| 335 | { |
| 336 | z100_state *state = space->machine().driver_data<z100_state>(); |
| 337 | |
| 338 | state->m_crtc_vreg[state->m_crtc_index] = data; |
| 339 | state->m_mc6845->register_w(*space, offset, data); |
| 340 | } |
| 341 | |
| 224 | 342 | static ADDRESS_MAP_START( z100_io , AS_IO, 8) |
| 225 | 343 | ADDRESS_MAP_UNMAP_HIGH |
| 226 | 344 | // AM_RANGE (0x98, 0x98) Z-205 max number |
| 227 | 345 | // AM_RANGE (0xae, 0xaf) Z-217 disk controller |
| 228 | 346 | // AM_RANGE (0xb0, 0xb1) Z-207 disk controller |
| 229 | 347 | AM_RANGE (0xd8, 0xdb) AM_DEVREADWRITE_MODERN("pia0", pia6821_device, read, write) |
| 230 | | AM_RANGE (0xdc, 0xdc) AM_DEVWRITE_MODERN("crtc", mc6845_device, address_w) |
| 231 | | AM_RANGE (0xdd, 0xdd) AM_DEVWRITE_MODERN("crtc", mc6845_device, register_w) |
| 348 | AM_RANGE (0xdc, 0xdc) AM_WRITE(z100_6845_address_w) |
| 349 | AM_RANGE (0xdd, 0xdd) AM_WRITE(z100_6845_data_w) |
| 232 | 350 | // AM_RANGE (0xde, 0xde) light pen |
| 233 | 351 | AM_RANGE (0xe0, 0xe3) AM_DEVREADWRITE_MODERN("pia1", pia6821_device, read, write) |
| 234 | 352 | // AM_RANGE (0xe4, 0xe7) 8253 PIT |
| r12306 | r12307 | |
| 254 | 372 | { |
| 255 | 373 | state->m_keyb_press = (UINT8)(FPTR)(param) & 0x7f; |
| 256 | 374 | //pic8259_ir1_w(field.machine().device("pic8259_master"), 1); |
| 375 | state->m_keyb_status = 1; |
| 257 | 376 | } |
| 258 | 377 | |
| 259 | 378 | if(oldval && !newval) |
| 379 | { |
| 260 | 380 | state->m_keyb_press = 0; |
| 381 | state->m_keyb_status = 0; |
| 382 | } |
| 261 | 383 | } |
| 262 | 384 | |
| 263 | 385 | /* Input ports */ |
| r12306 | r12307 | |
| 323 | 445 | PORT_BIT(0x80,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x2f) |
| 324 | 446 | |
| 325 | 447 | PORT_START("KEY6") // 0x30 - 0x37 |
| 326 | | PORT_BIT(0x01,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x30) |
| 327 | | PORT_BIT(0x02,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x31) |
| 328 | | PORT_BIT(0x04,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x32) |
| 329 | | PORT_BIT(0x08,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x33) |
| 330 | | PORT_BIT(0x10,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x34) |
| 331 | | PORT_BIT(0x20,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x35) |
| 332 | | PORT_BIT(0x40,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x36) |
| 333 | | PORT_BIT(0x80,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x37) |
| 448 | PORT_BIT(0x01,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("0") PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_IMPULSE(1) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x30) |
| 449 | PORT_BIT(0x02,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("1") PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x31) |
| 450 | PORT_BIT(0x04,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("2") PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x32) |
| 451 | PORT_BIT(0x08,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("3") PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x33) |
| 452 | PORT_BIT(0x10,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("4") PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x34) |
| 453 | PORT_BIT(0x20,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("5") PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x35) |
| 454 | PORT_BIT(0x40,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("6") PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x36) |
| 455 | PORT_BIT(0x80,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("7") PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x37) |
| 334 | 456 | |
| 335 | 457 | PORT_START("KEY7") // 0x38 - 0x3f |
| 336 | | PORT_BIT(0x01,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x38) |
| 337 | | PORT_BIT(0x02,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x39) |
| 458 | PORT_BIT(0x01,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("8") PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x38) |
| 459 | PORT_BIT(0x02,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_NAME("9") PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x39) |
| 338 | 460 | PORT_BIT(0x04,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x3a) |
| 339 | 461 | PORT_BIT(0x08,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x3b) |
| 340 | 462 | PORT_BIT(0x10,IP_ACTIVE_HIGH,IPT_KEYBOARD) PORT_IMPULSE(1) PORT_CHANGED(key_stroke, 0x3c) |
| r12306 | r12307 | |
| 461 | 583 | NULL /* update address callback */ |
| 462 | 584 | }; |
| 463 | 585 | |
| 464 | | static WRITE8_DEVICE_HANDLER( video_pia_porta_w ) |
| 586 | static WRITE8_DEVICE_HANDLER( video_pia_A_w ) |
| 465 | 587 | { |
| 588 | z100_state *state = device->machine().driver_data<z100_state>(); |
| 589 | |
| 466 | 590 | /* |
| 467 | 591 | x--- ---- -> disable video RAM |
| 468 | 592 | -x-- ---- -> not write multiple blue |
| r12306 | r12307 | |
| 473 | 597 | ---- --x- -> enable green display |
| 474 | 598 | ---- ---x -> enable red display |
| 475 | 599 | */ |
| 600 | if(data != 0x08 && data != 0xf8) |
| 601 | printf("%02x\n",data); |
| 602 | |
| 603 | state->m_gbank = ((data & 0xf0) >> 4) ^ 0xf; |
| 476 | 604 | } |
| 477 | 605 | |
| 606 | /* clear screen */ |
| 607 | static WRITE_LINE_DEVICE_HANDLER( video_pia_CA2_w ) |
| 608 | { |
| 609 | z100_state *drvstate = device->machine().driver_data<z100_state>(); |
| 610 | int i; |
| 611 | |
| 612 | for(i=0;i<0x10000;i++) |
| 613 | drvstate->m_tvram[i] = drvstate->m_clr_val; |
| 614 | |
| 615 | for(i=0;i<0x30000;i++) |
| 616 | drvstate->m_gvram[i] = drvstate->m_clr_val; |
| 617 | } |
| 618 | |
| 619 | static WRITE8_DEVICE_HANDLER( video_pia_CB2_w ) |
| 620 | { |
| 621 | z100_state *state = device->machine().driver_data<z100_state>(); |
| 622 | |
| 623 | state->m_clr_val = (data & 1) ? 0x00 : 0xff; |
| 624 | } |
| 625 | |
| 478 | 626 | static const pia6821_interface pia0_intf = |
| 479 | 627 | { |
| 480 | 628 | DEVCB_NULL, /* port A in */ |
| r12306 | r12307 | |
| 483 | 631 | DEVCB_NULL, /* line CB1 in */ |
| 484 | 632 | DEVCB_NULL, /* line CA2 in */ |
| 485 | 633 | DEVCB_NULL, /* line CB2 in */ |
| 486 | | DEVCB_HANDLER(video_pia_porta_w), /* port A out */ |
| 634 | DEVCB_HANDLER(video_pia_A_w), /* port A out */ |
| 487 | 635 | DEVCB_NULL, /* port B out */ |
| 488 | | DEVCB_NULL, /* line CA2 out */ |
| 489 | | DEVCB_NULL, /* port CB2 out */ |
| 636 | DEVCB_LINE(video_pia_CA2_w), /* line CA2 out */ |
| 637 | DEVCB_HANDLER(video_pia_CB2_w), /* port CB2 out */ |
| 490 | 638 | DEVCB_NULL, /* IRQA */ |
| 491 | 639 | DEVCB_NULL /* IRQB */ |
| 492 | 640 | }; |
| r12306 | r12307 | |
| 514 | 662 | |
| 515 | 663 | static MACHINE_START(z100) |
| 516 | 664 | { |
| 517 | | // z100_state *state = machine.driver_data<z100_state>(); |
| 665 | z100_state *state = machine.driver_data<z100_state>(); |
| 518 | 666 | |
| 519 | 667 | device_set_irq_callback(machine.device("maincpu"), z100_irq_callback); |
| 668 | state->m_mc6845 = machine.device<mc6845_device>("crtc"); |
| 520 | 669 | } |
| 521 | 670 | |
| 522 | 671 | static MACHINE_RESET(z100) |