src/emu/machine/z80pio.c
| r3447 | r3448 | |
| 74 | 74 | UINT8 mask[PIO_PORT_COUNT]; /* mask register */ |
| 75 | 75 | UINT8 ddr[PIO_PORT_COUNT]; /* input/output select register */ |
| 76 | 76 | int strobe[PIO_PORT_COUNT]; /* strobe pulse */ |
| 77 | | int match[PIO_PORT_COUNT]; /* mode 3 match equation match */ |
| 78 | 77 | |
| 79 | 78 | /* timers */ |
| 80 | 79 | emu_timer *poll_timer; /* mode 3 poll timer */ |
| r3447 | r3448 | |
| 116 | 115 | { |
| 117 | 116 | if (z80pio->irq_pending[channel]) |
| 118 | 117 | { |
| 119 | | if (LOG) logerror("Z80PIO Port %c Interrupt Request\n", 'A' + channel); |
| 118 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Request\n", device->tag, 'A' + channel); |
| 120 | 119 | |
| 121 | 120 | /* request interrupt */ |
| 122 | 121 | z80pio->irq_pending[channel] = 0; |
| r3447 | r3448 | |
| 141 | 140 | { |
| 142 | 141 | z80pio_t *z80pio = get_safe_token(device); |
| 143 | 142 | |
| 144 | | if (LOG) logerror("Z80PIO Port %c Ready %u\n", 'A' + channel, level); |
| 143 | if (LOG) logerror("Z80PIO \"%s\" Port %c Ready %u\n", device->tag, 'A' + channel, level); |
| 145 | 144 | |
| 146 | 145 | if (channel == PIO_PORT_A) |
| 147 | 146 | { |
| r3447 | r3448 | |
| 179 | 178 | } |
| 180 | 179 | } |
| 181 | 180 | |
| 182 | | //if (LOG) logerror("Z80PIO Port %c Read Data %02x\n", 'A' + channel, data); |
| 181 | //if (LOG) logerror("Z80PIO \"%s\" Port %c Read Data %02x\n", device->tag, 'A' + channel, data); |
| 183 | 182 | |
| 184 | 183 | z80pio->input[channel] = data; |
| 185 | 184 | } |
| r3447 | r3448 | |
| 210 | 209 | } |
| 211 | 210 | } |
| 212 | 211 | |
| 213 | | if (LOG) logerror("Z80PIO Port %c Write Data %02x\n", 'A' + channel, data); |
| 212 | if (LOG) logerror("Z80PIO \"%s\" Port %c Write Data %02x\n", device->tag, 'A' + channel, data); |
| 214 | 213 | } |
| 215 | 214 | |
| 216 | 215 | static void z80pio_set_mode(const device_config *device, int channel, int mode) |
| 217 | 216 | { |
| 218 | 217 | z80pio_t *z80pio = get_safe_token(device); |
| 219 | 218 | |
| 220 | | if (LOG) logerror("Z80PIO Port %c Mode %u\n", 'A' + channel, mode); |
| 219 | if (LOG) logerror("Z80PIO \"%s\" Port %c Mode %u\n", device->tag, 'A' + channel, mode); |
| 221 | 220 | |
| 222 | 221 | /* clear interrupt */ |
| 223 | 222 | z80pio->irq_enable[channel] = 0; |
| 224 | 223 | z80pio->irq_pending[channel] = 0; |
| 225 | 224 | z80pio->int_state[channel] = 0; |
| 226 | | z80pio->match[channel] = 0; |
| 227 | 225 | |
| 228 | 226 | z80pio_check_interrupt(device); |
| 229 | 227 | |
| r3447 | r3448 | |
| 284 | 282 | /* load interrupt vector */ |
| 285 | 283 | z80pio->vector[channel] = data & 0xfe; |
| 286 | 284 | |
| 287 | | if (LOG) logerror("Z80PIO Port %c Interrupt Vector %02x\n", 'A' + channel, z80pio->vector[channel]); |
| 285 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Vector %02x\n", device->tag, 'A' + channel, z80pio->vector[channel]); |
| 288 | 286 | } |
| 287 | else if ((data & 0x0f) == 0x03) |
| 288 | { |
| 289 | /* set interrupt enable */ |
| 290 | z80pio->enable[channel] = (data & 0x80) | (z80pio->enable[channel] & 0x7f); |
| 291 | z80pio->irq_enable[channel] = BIT(data, 7); |
| 292 | z80pio_check_interrupt(device); |
| 293 | |
| 294 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Enable %u\n", device->tag, 'A' + channel, BIT(data, 7)); |
| 295 | } |
| 289 | 296 | else if ((data & 0x0f) == 0x0f) |
| 290 | 297 | { |
| 291 | 298 | /* select operating mode */ |
| r3447 | r3448 | |
| 319 | 326 | |
| 320 | 327 | z80pio_check_interrupt(device); |
| 321 | 328 | |
| 322 | | if (LOG) logerror("Z80PIO Port %c Interrupt Control %02x\n", 'A' + channel, data); |
| 329 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Control %02x\n", device->tag, 'A' + channel, data); |
| 323 | 330 | } |
| 324 | 331 | break; |
| 325 | 332 | |
| 326 | | |
| 327 | 333 | case PIO_STATE_DDR: |
| 328 | 334 | /* set data direction */ |
| 329 | 335 | z80pio->ddr[channel] = data; |
| 330 | | z80pio->match[channel] = 0; |
| 331 | 336 | |
| 332 | 337 | /* set interrupt enable */ |
| 333 | 338 | z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7); |
| r3447 | r3448 | |
| 335 | 340 | |
| 336 | 341 | z80pio->state[channel] = PIO_STATE_NORMAL; |
| 337 | 342 | |
| 338 | | if (LOG) logerror("Z80PIO Port %c Direction %02x\n", 'A' + channel, data); |
| 343 | if (LOG) logerror("Z80PIO \"%s\" Port %c Direction %02x\n", device->tag, 'A' + channel, data); |
| 339 | 344 | break; |
| 340 | 345 | |
| 341 | 346 | case PIO_STATE_MASK: |
| 342 | 347 | /* set interrupt mask */ |
| 343 | 348 | z80pio->mask[channel] = data; |
| 344 | | z80pio->match[channel] = 0; |
| 345 | 349 | |
| 346 | 350 | /* set interrupt enable */ |
| 347 | 351 | z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7); |
| r3447 | r3448 | |
| 349 | 353 | |
| 350 | 354 | z80pio->state[channel] = PIO_STATE_NORMAL; |
| 351 | 355 | |
| 352 | | if (LOG) logerror("Z80PIO Port %c Mask %02x\n", 'A' + channel, data); |
| 356 | if (LOG) logerror("Z80PIO \"%s\" Port %c Mask %02x\n", device->tag, 'A' + channel, data); |
| 353 | 357 | break; |
| 354 | 358 | } |
| 355 | 359 | } |
| r3447 | r3448 | |
| 391 | 395 | break; |
| 392 | 396 | |
| 393 | 397 | case PIO_MODE_CONTROL: |
| 398 | z80pio_port_read(device, channel); |
| 394 | 399 | data = (z80pio->input[channel] & z80pio->ddr[channel]) | (z80pio->output[channel] & (~z80pio->ddr[channel])); |
| 395 | 400 | break; |
| 396 | 401 | } |
| 397 | 402 | |
| 398 | | if (LOG) logerror("Z80PIO Port %c Data Register Read %02x\n", 'A' + channel, data); |
| 403 | if (LOG) logerror("Z80PIO \"%s\" Port %c Data Register Read %02x\n", device->tag, 'A' + channel, data); |
| 399 | 404 | |
| 400 | 405 | return data; |
| 401 | 406 | } |
| r3447 | r3448 | |
| 405 | 410 | z80pio_t *z80pio = get_safe_token( device ); |
| 406 | 411 | int channel = offset & 0x01; |
| 407 | 412 | |
| 408 | | if (LOG) logerror("Z80PIO Port %c Data Register Write %02x\n", 'A' + channel, data); |
| 413 | if (LOG) logerror("Z80PIO \"%s\" Port %c Data Register Write %02x\n", device->tag, 'A' + channel, data); |
| 409 | 414 | |
| 410 | 415 | switch (z80pio->mode[channel]) |
| 411 | 416 | { |
| r3447 | r3448 | |
| 485 | 490 | { |
| 486 | 491 | if (!BIT(old_data, bit) && BIT(data, bit)) // rising edge |
| 487 | 492 | { |
| 493 | if (LOG) logerror("Z80PIO \"%s\" Port %c Rising Edge detected on bit %u\n", device->tag, 'A' + channel, bit); |
| 494 | |
| 488 | 495 | match = 1; |
| 489 | 496 | |
| 490 | 497 | if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR |
| r3447 | r3448 | |
| 505 | 512 | { |
| 506 | 513 | if (BIT(old_data, bit) && !BIT(data, bit)) // falling edge |
| 507 | 514 | { |
| 515 | if (LOG) logerror("Z80PIO \"%s\" Port %c Falling Edge detected on bit %u\n", device->tag, 'A' + channel, bit); |
| 516 | |
| 508 | 517 | match = 1; |
| 509 | 518 | |
| 510 | 519 | if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR |
| r3447 | r3448 | |
| 529 | 538 | /* trigger interrupt */ |
| 530 | 539 | z80pio->irq_pending[channel] = 1; |
| 531 | 540 | |
| 532 | | if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel); |
| 541 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel); |
| 533 | 542 | |
| 534 | 543 | z80pio_check_interrupt(device); |
| 535 | 544 | } |
| r3447 | r3448 | |
| 545 | 554 | { |
| 546 | 555 | z80pio_t *z80pio = get_safe_token(device); |
| 547 | 556 | |
| 548 | | if (LOG) logerror("Z80PIO Port %c Strobe %u\n", 'A' + channel, level); |
| 557 | if (LOG) logerror("Z80PIO \"%s\" Port %c Strobe %u\n", device->tag, 'A' + channel, level); |
| 549 | 558 | |
| 550 | 559 | if (z80pio->mode[PIO_PORT_A] == PIO_MODE_BIDIRECTIONAL) |
| 551 | 560 | { |
| r3447 | r3448 | |
| 576 | 585 | /* clear ready line */ |
| 577 | 586 | z80pio_set_ready_line(device, channel, 0); |
| 578 | 587 | |
| 579 | | if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel); |
| 588 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel); |
| 580 | 589 | } |
| 581 | 590 | break; |
| 582 | 591 | } |
| r3447 | r3448 | |
| 595 | 604 | /* clear ready line */ |
| 596 | 605 | z80pio_set_ready_line(device, channel, 0); |
| 597 | 606 | |
| 598 | | if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel); |
| 607 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel); |
| 599 | 608 | } |
| 600 | 609 | break; |
| 601 | 610 | |
| r3447 | r3448 | |
| 614 | 623 | /* clear ready line */ |
| 615 | 624 | z80pio_set_ready_line(device, channel, 0); |
| 616 | 625 | |
| 617 | | if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel); |
| 626 | if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel); |
| 618 | 627 | } |
| 619 | 628 | break; |
| 620 | 629 | |
| r3447 | r3448 | |
| 647 | 656 | int state = 0; |
| 648 | 657 | int channel; |
| 649 | 658 | |
| 650 | | if (LOG) logerror("Z80PIO IRQ STATE\n"); |
| 659 | if (LOG) logerror("Z80PIO \"%s\" IRQ STATE\n", device->tag); |
| 651 | 660 | |
| 652 | 661 | /* loop over all channels */ |
| 653 | 662 | for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++) |
| r3447 | r3448 | |
| 670 | 679 | z80pio_t *z80pio = get_safe_token( device ); |
| 671 | 680 | int channel; |
| 672 | 681 | |
| 673 | | if (LOG) logerror("Z80PIO IRQ ACK\n"); |
| 682 | if (LOG) logerror("Z80PIO \"%s\" IRQ ACK\n", device->tag); |
| 674 | 683 | |
| 675 | 684 | /* loop over all channels */ |
| 676 | 685 | for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++) |
| r3447 | r3448 | |
| 696 | 705 | z80pio_t *z80pio = get_safe_token( device ); |
| 697 | 706 | int channel; |
| 698 | 707 | |
| 699 | | if (LOG) logerror("Z80PIO IRQ RETI\n"); |
| 708 | if (LOG) logerror("Z80PIO \"%s\" IRQ RETI\n", device->tag); |
| 700 | 709 | |
| 701 | 710 | /* loop over all channels */ |
| 702 | 711 | for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++) |
| r3447 | r3448 | |
| 732 | 741 | z80pio_d_w(device, offset & 1, data); |
| 733 | 742 | } |
| 734 | 743 | |
| 744 | READ8_DEVICE_HANDLER(z80pio_alt_r) |
| 745 | { |
| 746 | int channel = BIT(offset, 1); |
| 747 | |
| 748 | return (offset & 1) ? z80pio_c_r(device, channel) : z80pio_d_r(device, channel); |
| 749 | } |
| 750 | |
| 751 | WRITE8_DEVICE_HANDLER(z80pio_alt_w) |
| 752 | { |
| 753 | int channel = BIT(offset, 1); |
| 754 | |
| 755 | if (offset & 1) |
| 756 | z80pio_c_w(device, channel, data); |
| 757 | else |
| 758 | z80pio_d_w(device, channel, data); |
| 759 | } |
| 760 | |
| 735 | 761 | /*************************************************************************** |
| 736 | 762 | DEVICE INTERFACE |
| 737 | 763 | ***************************************************************************/ |
| r3447 | r3448 | |
| 784 | 810 | state_save_register_item_array(unique_tag, 0, z80pio->mask); |
| 785 | 811 | state_save_register_item_array(unique_tag, 0, z80pio->ddr); |
| 786 | 812 | state_save_register_item_array(unique_tag, 0, z80pio->strobe); |
| 787 | | state_save_register_item_array(unique_tag, 0, z80pio->match); |
| 788 | 813 | |
| 789 | 814 | return DEVICE_START_OK; |
| 790 | 815 | } |
| r3447 | r3448 | |
| 815 | 840 | z80pio->irq_enable[channel] = 0; |
| 816 | 841 | z80pio->irq_pending[channel] = 0; |
| 817 | 842 | z80pio->int_state[channel] = 0; |
| 818 | | z80pio->match[channel] = 0; |
| 819 | 843 | |
| 820 | 844 | /* reset output register */ |
| 821 | 845 | z80pio->output[channel] = 0; |
src/mess/drivers/mbee.c
| r3447 | r3448 | |
| 62 | 62 | return device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette" ); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | | static READ8_DEVICE_HANDLER( mbee_z80pio_r ) |
| 66 | | { |
| 67 | | int channel = BIT(offset, 1); |
| 68 | | |
| 69 | | if (BIT(offset, 0)) |
| 70 | | { |
| 71 | | return z80pio_c_r(device, channel); |
| 72 | | } |
| 73 | | else |
| 74 | | { |
| 75 | | return z80pio_d_r(device, channel); |
| 76 | | } |
| 77 | | } |
| 78 | | |
| 79 | | static WRITE8_DEVICE_HANDLER( mbee_z80pio_w ) |
| 80 | | { |
| 81 | | int channel = BIT(offset, 1); |
| 82 | | |
| 83 | | if (BIT(offset, 0)) |
| 84 | | { |
| 85 | | z80pio_c_w(device, channel, data); |
| 86 | | } |
| 87 | | else |
| 88 | | { |
| 89 | | z80pio_d_w(device, channel, data); |
| 90 | | } |
| 91 | | } |
| 92 | | |
| 93 | 65 | static QUICKLOAD_LOAD( mbee ); |
| 94 | 66 | static Z80BIN_EXECUTE( mbee ); |
| 95 | 67 | |
| r3447 | r3448 | |
| 128 | 100 | static ADDRESS_MAP_START(mbee_ports, ADDRESS_SPACE_IO, 8) |
| 129 | 101 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 130 | 102 | ADDRESS_MAP_UNMAP_HIGH |
| 131 | | AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", mbee_z80pio_r, mbee_z80pio_w) |
| 103 | AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", z80pio_alt_r, z80pio_alt_w) |
| 132 | 104 | AM_RANGE(0x0b, 0x0b) AM_MIRROR(0x10) AM_READWRITE(mbee_video_bank_r, mbee_video_bank_w) |
| 133 | 105 | AM_RANGE(0x0c, 0x0c) AM_MIRROR(0x10) AM_READWRITE(m6545_status_r, m6545_index_w) |
| 134 | 106 | AM_RANGE(0x0d, 0x0d) AM_MIRROR(0x10) AM_READWRITE(m6545_data_r, m6545_data_w) |
| r3447 | r3448 | |
| 137 | 109 | static ADDRESS_MAP_START(mbeeic_ports, ADDRESS_SPACE_IO, 8) |
| 138 | 110 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 139 | 111 | ADDRESS_MAP_UNMAP_HIGH |
| 140 | | AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", mbee_z80pio_r, mbee_z80pio_w) |
| 112 | AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", z80pio_alt_r, z80pio_alt_w) |
| 141 | 113 | AM_RANGE(0x08, 0x08) AM_MIRROR(0x10) AM_READWRITE(mbee_pcg_color_latch_r, mbee_pcg_color_latch_w) |
| 142 | 114 | // AM_RANGE(0x09, 0x09) AM_MIRROR(0x10) Listed as "Colour Wait Off" or "USART 2651" but doesn't appear in the schematics |
| 143 | 115 | AM_RANGE(0x0a, 0x0a) AM_MIRROR(0x10) AM_READWRITE(mbee_color_bank_r, mbee_color_bank_w) |