src/emu/machine/z80pio.c
| r3452 | r3453 | |
| 69 | 69 | int state[PIO_PORT_COUNT]; /* control register state */ |
| 70 | 70 | int mode[PIO_PORT_COUNT]; /* mode control register */ |
| 71 | 71 | int irq_enable[PIO_PORT_COUNT]; /* interrupt enable flag */ |
| 72 | int irq_pending[PIO_PORT_COUNT]; /* interrupt pending flag */ |
| 72 | 73 | int int_state[PIO_PORT_COUNT]; /* interrupt status */ |
| 73 | 74 | UINT8 enable[PIO_PORT_COUNT]; /* interrupt control word */ |
| 74 | 75 | UINT8 input[PIO_PORT_COUNT]; /* data input register */ |
| r3452 | r3453 | |
| 116 | 117 | |
| 117 | 118 | for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++) |
| 118 | 119 | { |
| 119 | | if (!(z80pio->irq_enable[channel])) |
| 120 | if (z80pio->irq_enable[channel]) |
| 120 | 121 | { |
| 122 | if (z80pio->irq_pending[channel]) |
| 123 | { |
| 124 | /* trigger interrupt request */ |
| 125 | z80pio->int_state[channel] |= Z80_DAISY_INT; |
| 126 | |
| 127 | /* reset interrupt pending */ |
| 128 | z80pio->irq_pending[channel] = 0; |
| 129 | |
| 130 | LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Request\n", device->tag, 'A' + channel); |
| 131 | } |
| 132 | } |
| 133 | else |
| 134 | { |
| 121 | 135 | /* clear interrupt request */ |
| 122 | 136 | z80pio->int_state[channel] &= ~Z80_DAISY_INT; |
| 123 | 137 | } |
| r3452 | r3453 | |
| 140 | 154 | |
| 141 | 155 | LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Request\n", device->tag, 'A' + channel); |
| 142 | 156 | } |
| 157 | else |
| 158 | { |
| 159 | /* set interrupt pending */ |
| 160 | z80pio->irq_pending[channel] = 1; |
| 161 | z80pio_check_interrupt(device); |
| 162 | |
| 163 | LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Pending\n", device->tag, 'A' + channel); |
| 164 | } |
| 143 | 165 | } |
| 144 | 166 | |
| 145 | 167 | static TIMER_CALLBACK( z80pio_irq_tick ) |
| r3452 | r3453 | |
| 154 | 176 | z80pio->irq_enable[channel] = state; |
| 155 | 177 | |
| 156 | 178 | LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Enable %u\n", device->tag, 'A' + channel, state); |
| 179 | |
| 180 | /* check interrupt status */ |
| 181 | z80pio_check_interrupt(device); |
| 157 | 182 | } |
| 158 | 183 | |
| 159 | 184 | static void z80pio_set_irq_enable(const device_config *device, int channel, int state) |
| r3452 | r3453 | |
| 371 | 396 | { |
| 372 | 397 | /* disable interrupts until mask is written */ |
| 373 | 398 | z80pio_set_irq_enable(device, channel, 0); |
| 399 | |
| 400 | /* reset pending interrupt */ |
| 401 | z80pio->irq_pending[channel] = 0; |
| 374 | 402 | |
| 403 | /* set logic equation to false */ |
| 404 | z80pio->match[channel] = 0; |
| 405 | |
| 375 | 406 | /* next word is mask control */ |
| 376 | 407 | z80pio->state[channel] = PIO_STATE_MASK; |
| 377 | 408 | } |
| r3452 | r3453 | |
| 533 | 564 | UINT8 old_data = z80pio->input[channel] & ddr; |
| 534 | 565 | UINT8 data = z80pio_port_r(device, channel) & ddr; |
| 535 | 566 | |
| 567 | if (old_data == data) continue; |
| 568 | |
| 536 | 569 | for (bit = 0; bit < 8; bit++) |
| 537 | 570 | { |
| 538 | 571 | if (BIT(mask, bit)) continue; /* masked out */ |
| r3452 | r3453 | |
| 840 | 873 | state_save_register_item_array(unique_tag, 0, z80pio->state); |
| 841 | 874 | state_save_register_item_array(unique_tag, 0, z80pio->mode); |
| 842 | 875 | state_save_register_item_array(unique_tag, 0, z80pio->irq_enable); |
| 876 | state_save_register_item_array(unique_tag, 0, z80pio->irq_pending); |
| 843 | 877 | state_save_register_item_array(unique_tag, 0, z80pio->int_state); |
| 844 | 878 | state_save_register_item_array(unique_tag, 0, z80pio->enable); |
| 845 | 879 | state_save_register_item_array(unique_tag, 0, z80pio->input); |
| r3452 | r3453 | |
| 862 | 896 | |
| 863 | 897 | for (channel = 0; channel < 2; channel++) |
| 864 | 898 | { |
| 865 | | /* set port mask register to inhibit all port data bits */ |
| 866 | | z80pio->mask[channel] = 0xff; |
| 867 | | |
| 868 | | /* clear ready line */ |
| 869 | | z80pio_ready_w(device, channel, 0); |
| 870 | | |
| 871 | 899 | /* set mode 1 */ |
| 872 | 900 | z80pio->mode[channel] = PIO_MODE_INPUT; |
| 873 | 901 | |
| 874 | | /* set all inputs */ |
| 875 | | z80pio->ddr[channel] = 0xff; |
| 876 | | |
| 877 | | /* reset interrupt */ |
| 902 | /* disable interrupt */ |
| 878 | 903 | z80pio->enable[channel] &= 0x7f; |
| 879 | 904 | z80pio->irq_enable[channel] = 0; |
| 905 | z80pio->irq_pending[channel] = 0; |
| 880 | 906 | z80pio->int_state[channel] = 0; |
| 881 | 907 | z80pio->match[channel] = 0; |
| 882 | 908 | |
| 909 | /* reset all bits of the data I/O register */ |
| 910 | z80pio->ddr[channel] = 0; |
| 911 | |
| 912 | /* set all bits of the mask control register */ |
| 913 | z80pio->mask[channel] = 0xff; |
| 914 | |
| 883 | 915 | /* reset output register */ |
| 884 | 916 | z80pio->output[channel] = 0; |
| 917 | |
| 918 | /* clear ready line */ |
| 919 | z80pio_ready_w(device, channel, 0); |
| 885 | 920 | } |
| 886 | 921 | |
| 887 | 922 | z80pio_check_interrupt(device); |
| r3452 | r3453 | |
| 930 | 965 | case DEVINFO_STR_NAME: info->s = "Zilog Z8420"; break; |
| 931 | 966 | case DEVINFO_STR_FAMILY: info->s = "Z80 PIO"; break; |
| 932 | 967 | |
| 933 | | default: DEVICE_GET_INFO_CALL(z80pio); |
| 968 | default: DEVICE_GET_INFO_CALL(z80pio); |
| 934 | 969 | } |
| 935 | 970 | } |
| 936 | 971 | |
| r3452 | r3453 | |
| 942 | 977 | case DEVINFO_STR_NAME: info->s = "Sharp LH0081"; break; |
| 943 | 978 | case DEVINFO_STR_FAMILY: info->s = "Z80 PIO"; break; |
| 944 | 979 | |
| 945 | | default: DEVICE_GET_INFO_CALL(z80pio); |
| 980 | default: DEVICE_GET_INFO_CALL(z80pio); |
| 946 | 981 | } |
| 947 | 982 | } |
| 948 | 983 | |
| r3452 | r3453 | |
| 954 | 989 | case DEVINFO_STR_NAME: info->s = "Mostek MK3881"; break; |
| 955 | 990 | case DEVINFO_STR_FAMILY: info->s = "Z80 PIO"; break; |
| 956 | 991 | |
| 957 | | default: DEVICE_GET_INFO_CALL(z80pio); |
| 992 | default: DEVICE_GET_INFO_CALL(z80pio); |
| 958 | 993 | } |
| 959 | 994 | } |