src/emu/machine/z80pio.c
| r7385 | r7386 | |
| 7 | 7 | |
| 8 | 8 | ***************************************************************************/ |
| 9 | 9 | |
| 10 | | /* |
| 11 | | |
| 12 | | TODO: |
| 13 | | |
| 14 | | - save state |
| 15 | | |
| 16 | | */ |
| 17 | | |
| 18 | 10 | #include "emu.h" |
| 19 | 11 | #include "z80pio.h" |
| 20 | 12 | #include "cpu/z80/z80daisy.h" |
| r7385 | r7386 | |
| 23 | 15 | PARAMETERS |
| 24 | 16 | ***************************************************************************/ |
| 25 | 17 | |
| 26 | | #define LOG 1 |
| 18 | #define LOG |
| 27 | 19 | |
| 28 | 20 | enum |
| 29 | 21 | { |
| r7385 | r7386 | |
| 144 | 136 | z80pio_t *z80pio = get_safe_token(device); |
| 145 | 137 | pio_port *port = &z80pio->port[index]; |
| 146 | 138 | |
| 139 | if (port->rdy == state) return; |
| 140 | |
| 147 | 141 | if (LOG) logerror("Z80PIO '%s' Port %c Ready: %u\n", device->tag.cstr(), 'A' + index, state); |
| 148 | 142 | |
| 149 | 143 | port->rdy = state; |
| r7385 | r7386 | |
| 243 | 237 | /* load interrupt vector */ |
| 244 | 238 | port->vector = data; |
| 245 | 239 | if (LOG) logerror("Z80PIO '%s' Port %c Interrupt Vector: %02x\n", device->tag.cstr(), 'A' + index, data); |
| 240 | |
| 241 | /* set interrupt enable */ |
| 242 | port->icw |= ICW_ENABLE_INT; |
| 243 | port->ie = 1; |
| 244 | check_interrupts(device); |
| 246 | 245 | } |
| 247 | 246 | else |
| 248 | 247 | { |
| r7385 | r7386 | |
| 412 | 411 | } |
| 413 | 412 | |
| 414 | 413 | /* assert ready line */ |
| 415 | | set_rdy(device, index, 0); |
| 414 | set_rdy(device, index, 1); |
| 416 | 415 | break; |
| 417 | 416 | |
| 418 | 417 | case MODE_BIT_CONTROL: |
| r7385 | r7386 | |
| 616 | 615 | z80pio_t *z80pio = get_safe_token(device); |
| 617 | 616 | pio_port *port = &z80pio->port[index]; |
| 618 | 617 | |
| 618 | if (LOG) logerror("Z80PIO '%s' Port %c Strobe: %u\n", device->tag.cstr(), 'A' + index, state); |
| 619 | |
| 619 | 620 | if (z80pio->port[PORT_A].mode == MODE_BIDIRECTIONAL) |
| 620 | 621 | { |
| 621 | 622 | pio_port *port_a = &z80pio->port[PORT_A]; |
| r7385 | r7386 | |
| 631 | 632 | } |
| 632 | 633 | else if (!port->stb && state) /* rising edge */ |
| 633 | 634 | { |
| 634 | | trigger_interrupt(device, PORT_A); |
| 635 | | set_rdy(device, PORT_A, 0); |
| 635 | trigger_interrupt(device, index); |
| 636 | |
| 637 | /* clear ready line */ |
| 638 | set_rdy(device, index, 0); |
| 636 | 639 | } |
| 637 | 640 | } |
| 638 | 641 | break; |
| r7385 | r7386 | |
| 646 | 649 | } |
| 647 | 650 | else if (!port->stb && state) /* rising edge */ |
| 648 | 651 | { |
| 649 | | trigger_interrupt(device, PORT_A); |
| 650 | | set_rdy(device, PORT_B, 0); |
| 652 | trigger_interrupt(device, index); |
| 653 | |
| 654 | /* clear ready line */ |
| 655 | set_rdy(device, index, 0); |
| 651 | 656 | } |
| 652 | 657 | } |
| 653 | 658 | break; |
| r7385 | r7386 | |
| 658 | 663 | switch (port->mode) |
| 659 | 664 | { |
| 660 | 665 | case MODE_OUTPUT: |
| 661 | | if (!port->stb && state) /* rising edge */ |
| 666 | if (port->rdy) |
| 662 | 667 | { |
| 663 | | trigger_interrupt(device, index); |
| 664 | | set_rdy(device, index, 0); |
| 668 | if (!port->stb && state) /* rising edge */ |
| 669 | { |
| 670 | trigger_interrupt(device, index); |
| 671 | |
| 672 | /* clear ready line */ |
| 673 | set_rdy(device, index, 0); |
| 674 | } |
| 665 | 675 | } |
| 666 | 676 | break; |
| 667 | 677 | |
| 668 | 678 | case MODE_INPUT: |
| 669 | 679 | if (!state) |
| 670 | 680 | { |
| 681 | /* input port data */ |
| 671 | 682 | port->input = devcb_call_read8(&port->in_p_func, 0); |
| 672 | 683 | } |
| 673 | 684 | else if (!port->stb && state) /* rising edge */ |
| 674 | 685 | { |
| 675 | 686 | trigger_interrupt(device, index); |
| 687 | |
| 688 | /* clear ready line */ |
| 676 | 689 | set_rdy(device, index, 0); |
| 677 | 690 | } |
| 678 | 691 | break; |
| r7385 | r7386 | |
| 807 | 820 | devcb_resolve_write_line(&z80pio->port[PORT_B].out_rdy_func, &intf->out_brdy_func, device); |
| 808 | 821 | |
| 809 | 822 | /* register for state saving */ |
| 810 | | // state_save_register_device_item(device, 0, z80pio->); |
| 823 | for (int index = PORT_A; index < PORT_COUNT; index++) |
| 824 | { |
| 825 | state_save_register_device_item(device, 0, z80pio->port[index].mode); |
| 826 | state_save_register_device_item(device, 0, z80pio->port[index].next_control_word); |
| 827 | state_save_register_device_item(device, 0, z80pio->port[index].input); |
| 828 | state_save_register_device_item(device, 0, z80pio->port[index].output); |
| 829 | state_save_register_device_item(device, 0, z80pio->port[index].ior); |
| 830 | state_save_register_device_item(device, 0, z80pio->port[index].rdy); |
| 831 | state_save_register_device_item(device, 0, z80pio->port[index].stb); |
| 832 | state_save_register_device_item(device, 0, z80pio->port[index].ie); |
| 833 | state_save_register_device_item(device, 0, z80pio->port[index].ip); |
| 834 | state_save_register_device_item(device, 0, z80pio->port[index].ius); |
| 835 | state_save_register_device_item(device, 0, z80pio->port[index].icw); |
| 836 | state_save_register_device_item(device, 0, z80pio->port[index].vector); |
| 837 | state_save_register_device_item(device, 0, z80pio->port[index].mask); |
| 838 | state_save_register_device_item(device, 0, z80pio->port[index].match); |
| 839 | } |
| 811 | 840 | } |
| 812 | 841 | |
| 813 | 842 | /*------------------------------------------------- |