src/emu/machine/z80pio.c
| r7411 | r7412 | |
| 111 | 111 | { |
| 112 | 112 | pio_port *port = &z80pio->port[index]; |
| 113 | 113 | |
| 114 | if (port->mode == MODE_BIT_CONTROL) |
| 115 | { |
| 116 | /* fetch input data (ignore output lines) */ |
| 117 | UINT8 data = (port->input & port->ior) | (port->output & ~port->ior); |
| 118 | UINT8 mask = ~port->mask; |
| 119 | int match = 0; |
| 120 | |
| 121 | data &= mask; |
| 122 | |
| 123 | if ((port->icw & 0x60) == 0 && data != mask) match = 1; |
| 124 | else if ((port->icw & 0x60) == 0x20 && data != 0) match = 1; |
| 125 | else if ((port->icw & 0x60) == 0x40 && data == 0) match = 1; |
| 126 | else if ((port->icw & 0x60) == 0x60 && data == mask) match = 1; |
| 127 | |
| 128 | if (!port->match && match) |
| 129 | { |
| 130 | /* trigger interrupt */ |
| 131 | port->ip = 1; |
| 132 | if (LOG) logerror("Z80PIO '%s' Port %c Interrupt Pending\n", device->tag.cstr(), 'A' + index); |
| 133 | } |
| 134 | |
| 135 | port->match = match; |
| 136 | } |
| 137 | |
| 114 | 138 | if (port->ie && port->ip && !port->ius) |
| 115 | 139 | { |
| 116 | 140 | state = ASSERT_LINE; |
| 117 | 141 | } |
| 118 | 142 | } |
| 119 | | |
| 143 | |
| 120 | 144 | devcb_call_write_line(&z80pio->out_int_func, state); |
| 121 | 145 | } |
| 122 | 146 | |
| r7411 | r7412 | |
| 254 | 278 | case 0x07: /* set interrupt control word */ |
| 255 | 279 | port->icw = data; |
| 256 | 280 | |
| 281 | if (LOG) |
| 282 | { |
| 283 | logerror("Z80PIO '%s' Port %c Interrupt Enable: %u\n", device->tag.cstr(), 'A' + index, BIT(data, 7)); |
| 284 | logerror("Z80PIO '%s' Port %c Logic: %s\n", device->tag.cstr(), 'A' + index, BIT(data, 6) ? "AND" : "OR"); |
| 285 | logerror("Z80PIO '%s' Port %c Active %s\n", device->tag.cstr(), 'A' + index, BIT(data, 5) ? "High" : "Low"); |
| 286 | logerror("Z80PIO '%s' Port %c Mask Follows: %u\n", device->tag.cstr(), 'A' + index, BIT(data, 4)); |
| 287 | } |
| 288 | |
| 257 | 289 | if (port->icw & ICW_MASK_FOLLOWS) |
| 258 | 290 | { |
| 259 | 291 | /* disable interrupts until mask is written */ |
| r7411 | r7412 | |
| 269 | 301 | /* next word is mask control */ |
| 270 | 302 | port->next_control_word = MASK; |
| 271 | 303 | } |
| 304 | else |
| 305 | { |
| 306 | /* monitor all bits */ |
| 307 | port->mask = 0; |
| 308 | } |
| 272 | 309 | break; |
| 273 | 310 | |
| 274 | 311 | case 0x03: /* set interrupt enable flip-flop */ |
| r7411 | r7412 | |
| 499 | 536 | } |
| 500 | 537 | |
| 501 | 538 | /*------------------------------------------------- |
| 502 | | check_equation - check bit logic equation |
| 503 | | -------------------------------------------------*/ |
| 504 | | |
| 505 | | static void check_equation(running_device *device, int index, UINT8 data) |
| 506 | | { |
| 507 | | z80pio_t *z80pio = get_safe_token(device); |
| 508 | | pio_port *port = &z80pio->port[index]; |
| 509 | | |
| 510 | | if (port->mask == 0xff) return; |
| 511 | | |
| 512 | | int bit; |
| 513 | | int match = 0; |
| 514 | | |
| 515 | | int edge = (port->icw & ICW_HIGH) ? 1 : 0; |
| 516 | | |
| 517 | | UINT8 mask = port->mask; |
| 518 | | UINT8 ior = port->ior; |
| 519 | | UINT8 old_data = port->input; |
| 520 | | |
| 521 | | if (old_data == data) return; |
| 522 | | |
| 523 | | for (bit = 0; bit < 8; bit++) |
| 524 | | { |
| 525 | | if (BIT(mask, bit)) continue; /* masked out */ |
| 526 | | if (!BIT(ior, bit)) continue; /* output bit */ |
| 527 | | |
| 528 | | if ((BIT(old_data, bit) ^ edge) && !(BIT(data, bit) ^ edge)) /* falling edge */ |
| 529 | | { |
| 530 | | /* logic equation is true, until proven otherwise */ |
| 531 | | match = 1; |
| 532 | | |
| 533 | | if (LOG) logerror("Z80PIO '%s' Port %c Edge Transition detected on bit %u, data %02x %02x\n", device->tag.cstr(), 'A' + index, bit, old_data, data); |
| 534 | | } |
| 535 | | else if (port->icw & ICW_AND) |
| 536 | | { |
| 537 | | /* all bits must match in AND mode, so logic equation is false */ |
| 538 | | match = 0; |
| 539 | | break; |
| 540 | | } |
| 541 | | } |
| 542 | | |
| 543 | | if (!port->match && match) /* rising edge */ |
| 544 | | { |
| 545 | | /* latch data */ |
| 546 | | port->input = data; |
| 547 | | |
| 548 | | /* trigger interrupt only once */ |
| 549 | | trigger_interrupt(device, index); |
| 550 | | } |
| 551 | | |
| 552 | | port->match = match; |
| 553 | | } |
| 554 | | |
| 555 | | /*------------------------------------------------- |
| 556 | 539 | z80pio_pa_w - port A write |
| 557 | 540 | -------------------------------------------------*/ |
| 558 | 541 | |
| r7411 | r7412 | |
| 563 | 546 | |
| 564 | 547 | if (port->mode == MODE_BIT_CONTROL) |
| 565 | 548 | { |
| 566 | | check_equation(device, PORT_A, data); |
| 549 | /* latch data */ |
| 550 | port->input = data; |
| 551 | check_interrupts(device); |
| 567 | 552 | } |
| 568 | 553 | } |
| 569 | 554 | |
| r7411 | r7412 | |
| 603 | 588 | |
| 604 | 589 | if (port->mode == MODE_BIT_CONTROL) |
| 605 | 590 | { |
| 606 | | check_equation(device, PORT_B, data); |
| 591 | /* latch data */ |
| 592 | port->input = data; |
| 593 | check_interrupts(device); |
| 607 | 594 | } |
| 608 | 595 | } |
| 609 | 596 | |
| r7411 | r7412 | |
| 761 | 748 | |
| 762 | 749 | /* clear interrupt pending flag */ |
| 763 | 750 | port->ip = 0; |
| 764 | | check_interrupts(device); |
| 765 | 751 | |
| 766 | 752 | /* set interrupt under service flag */ |
| 767 | 753 | port->ius = 1; |
| 768 | 754 | |
| 755 | check_interrupts(device); |
| 756 | |
| 769 | 757 | return port->vector; |
| 770 | 758 | } |
| 771 | 759 | } |