src/mess/drivers/ql.c
| r1270 | r1271 | |
| 48 | 48 | UINT16 ctr; |
| 49 | 49 | UINT8 idr; |
| 50 | 50 | int ipc_bits; |
| 51 | |
| 52 | int ser1_rxd, ser1_cts; |
| 53 | int ser2_txd, ser2_dtr; |
| 51 | 54 | } zx8302; |
| 52 | 55 | |
| 53 | 56 | static mame_timer *zx8302_txd_timer, *zx8302_ipc_timer, *zx8302_rtc_timer; |
| r1270 | r1271 | |
| 56 | 59 | { |
| 57 | 60 | } |
| 58 | 61 | |
| 62 | static void hack_comctl(void) |
| 63 | { |
| 64 | /* |
| 65 | This function hacks in the COMCTL line state. The real solution would be |
| 66 | to add a WR output line to the i8039 cpu core and monitor that instead. |
| 67 | */ |
| 68 | |
| 69 | offs_t pc = cpunum_get_physical_pc_byte(1); |
| 70 | |
| 71 | switch (pc) |
| 72 | { |
| 73 | case 0x0758: |
| 74 | case 0x075a: |
| 75 | case 0x076b: |
| 76 | case 0x0774: |
| 77 | zx8302.comctl = 0; |
| 78 | |
| 79 | default: |
| 80 | zx8302.comctl = 1; |
| 81 | } |
| 82 | |
| 83 | logerror("PC: %x, comctl: %u\n", pc, zx8302.comctl); |
| 84 | } |
| 85 | |
| 59 | 86 | static TIMER_CALLBACK( zx8302_ipc_tick ) |
| 60 | 87 | { |
| 61 | 88 | zx8302.baudx4 = zx8302.baudx4 ? 0 : 1; |
| 62 | 89 | |
| 90 | hack_comctl(); // HACK |
| 91 | |
| 63 | 92 | if (zx8302.baudx4) |
| 64 | 93 | { |
| 65 | 94 | if (zx8302.comctl) |
| r1270 | r1271 | |
| 146 | 175 | 3 |
| 147 | 176 | 4 DTR |
| 148 | 177 | 5 CTS |
| 149 | | 6 COMCTL ??? |
| 150 | | 7 COMDATA ??? |
| 178 | 6 COMCTL |
| 179 | 7 COMDATA |
| 151 | 180 | |
| 152 | 181 | */ |
| 153 | 182 | |
| r1270 | r1271 | |
| 262 | 291 | |
| 263 | 292 | /* Intelligent Peripheral Controller (IPC) */ |
| 264 | 293 | |
| 265 | | static UINT8 ipc_keylatch; |
| 294 | static struct IPC |
| 295 | { |
| 296 | UINT8 keylatch; |
| 297 | int ser1_txd, ser1_dtr; |
| 298 | int ser2_rxd, ser2_cts; |
| 299 | } ipc; |
| 266 | 300 | |
| 267 | 301 | static WRITE8_HANDLER( ipc_port1_w ) |
| 268 | 302 | { |
| r1270 | r1271 | |
| 281 | 315 | |
| 282 | 316 | */ |
| 283 | 317 | |
| 284 | | ipc_keylatch = data; |
| 318 | ipc.keylatch = data; |
| 285 | 319 | } |
| 286 | 320 | |
| 287 | 321 | static WRITE8_HANDLER( ipc_port2_w ) |
| r1270 | r1271 | |
| 290 | 324 | |
| 291 | 325 | bit description |
| 292 | 326 | |
| 293 | | 0 Serial data input |
| 327 | 0 Serial data input (SER2 RxD, SER1 TxD) |
| 294 | 328 | 1 Speaker output |
| 295 | | 2 Interrupt IPL0-2 output (not used) |
| 296 | | 3 Interrupt IPL1 output (not used) |
| 297 | | 4 SER2 CTS |
| 298 | | 5 SER1 DTR |
| 299 | | 6 N/C |
| 300 | | 7 COMDATA input/output |
| 329 | 2 Interrupt output (IPL0-2) |
| 330 | 3 Interrupt output (IPL1) |
| 331 | 4 Serial Clear-to-Send output (SER2 CTS) |
| 332 | 5 Serial Data Terminal Ready output (SER1 DTR) |
| 333 | 6 not connected |
| 334 | 7 ZX8302 serial link input/output (COMDATA) |
| 301 | 335 | |
| 302 | 336 | */ |
| 303 | 337 | |
| r1270 | r1271 | |
| 306 | 340 | switch (ipl) |
| 307 | 341 | { |
| 308 | 342 | case 0: |
| 309 | | cpunum_set_input_line(0, MC68000_IRQ_7, HOLD_LINE); |
| 343 | cpunum_set_input_line(0, MC68000_IRQ_2, CLEAR_LINE); |
| 344 | cpunum_set_input_line(0, MC68000_IRQ_5, CLEAR_LINE); |
| 345 | cpunum_set_input_line(0, MC68000_IRQ_7, ASSERT_LINE); |
| 310 | 346 | break; |
| 311 | 347 | case 1: |
| 312 | | cpunum_set_input_line(0, MC68000_IRQ_5, HOLD_LINE); |
| 348 | cpunum_set_input_line(0, MC68000_IRQ_2, CLEAR_LINE); |
| 349 | cpunum_set_input_line(0, MC68000_IRQ_5, ASSERT_LINE); |
| 350 | cpunum_set_input_line(0, MC68000_IRQ_7, CLEAR_LINE); |
| 313 | 351 | break; |
| 314 | 352 | case 2: |
| 315 | | cpunum_set_input_line(0, MC68000_IRQ_2, HOLD_LINE); |
| 353 | cpunum_set_input_line(0, MC68000_IRQ_2, ASSERT_LINE); |
| 354 | cpunum_set_input_line(0, MC68000_IRQ_5, CLEAR_LINE); |
| 355 | cpunum_set_input_line(0, MC68000_IRQ_7, CLEAR_LINE); |
| 316 | 356 | break; |
| 317 | 357 | case 3: |
| 318 | 358 | // do nothing |
| 319 | 359 | break; |
| 320 | 360 | } |
| 321 | 361 | |
| 362 | ipc.ser2_cts = BIT(data, 4); |
| 363 | ipc.ser1_dtr = BIT(data, 5); |
| 364 | |
| 322 | 365 | zx8302.comdata = BIT(data, 7); |
| 323 | 366 | } |
| 324 | 367 | |
| r1270 | r1271 | |
| 328 | 371 | |
| 329 | 372 | bit description |
| 330 | 373 | |
| 331 | | 0 Serial data input |
| 374 | 0 Serial data input (SER2 RxD, SER1 TxD) |
| 332 | 375 | 1 Speaker output |
| 333 | | 2 Interrupt IPL0-2 output (not used) |
| 334 | | 3 Interrupt IPL1 output (not used) |
| 335 | | 4 SER2 CTS |
| 336 | | 5 SER1 DTR |
| 337 | | 6 N/C |
| 338 | | 7 COMDATA input/output |
| 376 | 2 Interrupt output (IPL0-2) |
| 377 | 3 Interrupt output (IPL1) |
| 378 | 4 Serial Clear-to-Send output (SER2 CTS) |
| 379 | 5 Serial Data Terminal Ready output (SER1 DTR) |
| 380 | 6 not connected |
| 381 | 7 ZX8302 serial link input/output (COMDATA) |
| 339 | 382 | |
| 340 | 383 | */ |
| 341 | 384 | |
| 342 | | return zx8302.comdata << 7; |
| 385 | int irq = (ipc.ser2_rxd | ipc.ser1_txd); |
| 386 | |
| 387 | cpunum_set_input_line(1, INPUT_LINE_IRQ0, irq); |
| 388 | |
| 389 | return (zx8302.comdata << 7) | irq; |
| 343 | 390 | } |
| 344 | 391 | |
| 345 | 392 | static READ8_HANDLER( ipc_t1_r ) |
| r1270 | r1271 | |
| 364 | 411 | |
| 365 | 412 | */ |
| 366 | 413 | |
| 367 | | if (ipc_keylatch & 0x01) return readinputportbytag("ROW0") | readinputportbytag("JOY0"); |
| 368 | | if (ipc_keylatch & 0x02) return readinputportbytag("ROW1") | readinputportbytag("JOY1"); |
| 369 | | if (ipc_keylatch & 0x04) return readinputportbytag("ROW2"); |
| 370 | | if (ipc_keylatch & 0x08) return readinputportbytag("ROW3"); |
| 371 | | if (ipc_keylatch & 0x10) return readinputportbytag("ROW4"); |
| 372 | | if (ipc_keylatch & 0x20) return readinputportbytag("ROW5"); |
| 373 | | if (ipc_keylatch & 0x40) return readinputportbytag("ROW6"); |
| 374 | | if (ipc_keylatch & 0x80) return readinputportbytag("ROW7") | readinputportbytag("SPECIAL"); |
| 414 | if (BIT(ipc.keylatch, 0)) return readinputportbytag("ROW0") | readinputportbytag("JOY0"); |
| 415 | if (BIT(ipc.keylatch, 1)) return readinputportbytag("ROW1") | readinputportbytag("JOY1"); |
| 416 | if (BIT(ipc.keylatch, 2)) return readinputportbytag("ROW2"); |
| 417 | if (BIT(ipc.keylatch, 3)) return readinputportbytag("ROW3"); |
| 418 | if (BIT(ipc.keylatch, 4)) return readinputportbytag("ROW4"); |
| 419 | if (BIT(ipc.keylatch, 5)) return readinputportbytag("ROW5"); |
| 420 | if (BIT(ipc.keylatch, 6)) return readinputportbytag("ROW6"); |
| 421 | if (BIT(ipc.keylatch, 7)) return readinputportbytag("ROW7") | readinputportbytag("SPECIAL"); |
| 375 | 422 | |
| 376 | 423 | return 0; |
| 377 | 424 | } |
| r1270 | r1271 | |
| 526 | 573 | |
| 527 | 574 | static MACHINE_START( ql ) |
| 528 | 575 | { |
| 576 | // ZX8302 |
| 577 | |
| 529 | 578 | state_save_register_global(zx8302.comdata); |
| 530 | 579 | state_save_register_global(zx8302.comctl); |
| 531 | 580 | state_save_register_global(zx8302.baudx4); |
| r1270 | r1271 | |
| 535 | 584 | state_save_register_global(zx8302.ctr); |
| 536 | 585 | state_save_register_global(zx8302.idr); |
| 537 | 586 | state_save_register_global(zx8302.ipc_bits); |
| 587 | state_save_register_global(zx8302.ser1_rxd); |
| 588 | state_save_register_global(zx8302.ser1_cts); |
| 589 | state_save_register_global(zx8302.ser2_txd); |
| 590 | state_save_register_global(zx8302.ser2_dtr); |
| 538 | 591 | |
| 539 | | state_save_register_global(ipc_keylatch); |
| 540 | | |
| 541 | 592 | memset(&zx8302, 0, sizeof(zx8302)); |
| 542 | 593 | zx8302.comctl = 1; |
| 543 | 594 | zx8302.comdata = 1; |
| r1270 | r1271 | |
| 547 | 598 | zx8302_rtc_timer = mame_timer_alloc(zx8302_rtc_tick); |
| 548 | 599 | |
| 549 | 600 | mame_timer_adjust(zx8302_rtc_timer, time_zero, 0, MAME_TIME_IN_HZ(X2)); |
| 601 | |
| 602 | // IPC |
| 603 | |
| 604 | state_save_register_global(ipc.keylatch); |
| 605 | state_save_register_global(ipc.ser1_txd); |
| 606 | state_save_register_global(ipc.ser1_dtr); |
| 607 | state_save_register_global(ipc.ser2_rxd); |
| 608 | state_save_register_global(ipc.ser2_cts); |
| 609 | |
| 610 | memset(&ipc, 0, sizeof(ipc)); |
| 550 | 611 | } |
| 551 | 612 | |
| 552 | 613 | static MACHINE_DRIVER_START( ql ) |
| r1270 | r1271 | |
| 555 | 616 | MDRV_CPU_PROGRAM_MAP(ql_map, 0) |
| 556 | 617 | MDRV_CPU_VBLANK_INT(zx8302_int, 1) |
| 557 | 618 | |
| 558 | | MDRV_CPU_ADD(I8048, X4) // i8049 |
| 619 | MDRV_CPU_ADD(I8048, X4) // i8749 |
| 559 | 620 | MDRV_CPU_PROGRAM_MAP(ipc_map, 0) |
| 560 | 621 | MDRV_CPU_IO_MAP(ipc_io_map, 0) |
| 561 | 622 | |