trunk/src/emu/machine/z80pio.c
| r245480 | r245481 | |
| 9 | 9 | |
| 10 | 10 | ***************************************************************************/ |
| 11 | 11 | |
| 12 | /* |
| 13 | |
| 14 | TODO: |
| 15 | |
| 16 | - if port A is bidirectional, port B does not issue interrupts in bit mode |
| 17 | |
| 18 | */ |
| 19 | |
| 12 | 20 | #include "emu.h" |
| 13 | 21 | #include "z80pio.h" |
| 14 | 22 | #include "cpu/z80/z80daisy.h" |
| r245480 | r245481 | |
| 150 | 158 | |
| 151 | 159 | if (port.m_ip) |
| 152 | 160 | { |
| 153 | | if (LOG) logerror("Z80PIO '%s' Interrupt Acknowledge\n", tag()); |
| 161 | if (LOG) logerror("Z80PIO '%s' Port %c Interrupt Acknowledge\n", tag(), 'A' + index); |
| 154 | 162 | |
| 155 | 163 | // clear interrupt pending flag |
| 156 | 164 | port.m_ip = false; |
| r245480 | r245481 | |
| 183 | 191 | |
| 184 | 192 | if (port.m_ius) |
| 185 | 193 | { |
| 186 | | if (LOG) logerror("Z80PIO '%s' Return from Interrupt\n", tag()); |
| 194 | if (LOG) logerror("Z80PIO '%s' Port %c Return from Interrupt\n", tag(), 'A' + index); |
| 187 | 195 | |
| 188 | 196 | // clear interrupt under service flag |
| 189 | 197 | port.m_ius = false; |
| r245480 | r245481 | |
| 266 | 274 | void z80pio_device::check_interrupts() |
| 267 | 275 | { |
| 268 | 276 | int state = CLEAR_LINE; |
| 277 | bool ius = (m_port[PORT_A].m_ius || m_port[PORT_B].m_ius); |
| 269 | 278 | |
| 270 | 279 | for (int index = PORT_A; index < PORT_COUNT; index++) |
| 271 | | if (m_port[index].interrupt_signalled()) |
| 280 | { |
| 281 | if (LOG) logerror("Z80PIO '%s' Port %c IE %s IP %s IUS %s\n", tag(), 'A' + index, m_port[index].m_ie ? "1":"0", m_port[index].m_ip ? "1":"0", m_port[index].m_ius ? "1":"0"); |
| 282 | |
| 283 | if (!ius && m_port[index].m_ie && m_port[index].m_ip) |
| 284 | { |
| 272 | 285 | state = ASSERT_LINE; |
| 286 | } |
| 287 | } |
| 273 | 288 | |
| 289 | if (LOG) logerror("Z80PIO '%s' INT %u\n", tag(), state); |
| 290 | |
| 274 | 291 | m_out_int_cb(state); |
| 275 | 292 | } |
| 276 | 293 | |
| r245480 | r245481 | |
| 284 | 301 | // pio_port - constructor |
| 285 | 302 | //------------------------------------------------- |
| 286 | 303 | |
| 287 | | z80pio_device::pio_port::pio_port() |
| 288 | | : m_device(NULL), |
| 289 | | m_index(0), |
| 290 | | m_mode(0), |
| 291 | | m_next_control_word(0), |
| 292 | | m_input(0), |
| 293 | | m_output(0), |
| 294 | | m_ior(0), |
| 295 | | m_rdy(false), |
| 296 | | m_stb(false), |
| 297 | | m_ie(false), |
| 298 | | m_ip(false), |
| 299 | | m_ius(false), |
| 300 | | m_icw(0), |
| 301 | | m_vector(0), |
| 302 | | m_mask(0), |
| 303 | | m_match(false) |
| 304 | z80pio_device::pio_port::pio_port() : |
| 305 | m_device(NULL), |
| 306 | m_index(0), |
| 307 | m_mode(0), |
| 308 | m_next_control_word(0), |
| 309 | m_input(0), |
| 310 | m_output(0), |
| 311 | m_ior(0), |
| 312 | m_rdy(false), |
| 313 | m_stb(false), |
| 314 | m_ie(false), |
| 315 | m_ip(false), |
| 316 | m_ius(false), |
| 317 | m_icw(0), |
| 318 | m_vector(0), |
| 319 | m_mask(0), |
| 320 | m_match(false) |
| 304 | 321 | { |
| 305 | 322 | } |
| 306 | 323 | |
| r245480 | r245481 | |
| 363 | 380 | |
| 364 | 381 | |
| 365 | 382 | //------------------------------------------------- |
| 366 | | // interrupt_signalled - return true if an |
| 367 | | // interrupt is signalled |
| 368 | | //------------------------------------------------- |
| 369 | | |
| 370 | | bool z80pio_device::pio_port::interrupt_signalled() |
| 371 | | { |
| 372 | | if (m_mode == MODE_BIT_CONTROL) |
| 373 | | { |
| 374 | | // fetch input data (ignore output lines) |
| 375 | | UINT8 data = (m_input & m_ior) | (m_output & ~m_ior); |
| 376 | | UINT8 mask = ~m_mask; |
| 377 | | bool match = false; |
| 378 | | |
| 379 | | data &= mask; |
| 380 | | |
| 381 | | if ((m_icw & 0x60) == 0 && data != mask) match = true; |
| 382 | | else if ((m_icw & 0x60) == 0x20 && data != 0) match = true; |
| 383 | | else if ((m_icw & 0x60) == 0x40 && data == 0) match = true; |
| 384 | | else if ((m_icw & 0x60) == 0x60 && data == mask) match = true; |
| 385 | | |
| 386 | | if (!m_match && match) |
| 387 | | { |
| 388 | | // trigger interrupt |
| 389 | | m_ip = true; |
| 390 | | if (LOG) logerror("Z80PIO '%s' Port %c Interrupt Pending\n", m_device->tag(), 'A' + m_index); |
| 391 | | } |
| 392 | | |
| 393 | | m_match = match; |
| 394 | | } |
| 395 | | |
| 396 | | return (m_ie && m_ip && !m_ius); |
| 397 | | } |
| 398 | | |
| 399 | | |
| 400 | | //------------------------------------------------- |
| 401 | 383 | // trigger_interrupt - trigger an interrupt from |
| 402 | 384 | // this port |
| 403 | 385 | //------------------------------------------------- |
| r245480 | r245481 | |
| 405 | 387 | void z80pio_device::pio_port::trigger_interrupt() |
| 406 | 388 | { |
| 407 | 389 | m_ip = true; |
| 408 | | if (LOG) logerror("Z80PIO '%s' Port %c Interrupt Pending\n", m_device->tag(), 'A' + m_index); |
| 390 | if (LOG) logerror("Z80PIO '%s' Port %c Transfer Mode Interrupt Pending\n", m_device->tag(), 'A' + m_index); |
| 409 | 391 | |
| 410 | 392 | check_interrupts(); |
| 411 | 393 | } |
| r245480 | r245481 | |
| 601 | 583 | { |
| 602 | 584 | // latch data |
| 603 | 585 | m_input = data; |
| 586 | |
| 587 | // fetch input data (ignore output lines) |
| 588 | UINT8 data = (m_input & m_ior) | (m_output & ~m_ior); |
| 589 | UINT8 mask = ~m_mask; |
| 590 | bool match = false; |
| 591 | |
| 592 | data &= mask; |
| 593 | |
| 594 | if ((m_icw & 0x60) == 0 && data != mask) match = true; |
| 595 | else if ((m_icw & 0x60) == 0x20 && data != 0) match = true; |
| 596 | else if ((m_icw & 0x60) == 0x40 && data == 0) match = true; |
| 597 | else if ((m_icw & 0x60) == 0x60 && data == mask) match = true; |
| 598 | |
| 599 | if (!m_match && match && !m_ius) |
| 600 | { |
| 601 | // trigger interrupt |
| 602 | m_ip = true; |
| 603 | if (LOG) logerror("Z80PIO '%s' Port %c Bit Control Mode Interrupt Pending\n", m_device->tag(), 'A' + m_index); |
| 604 | } |
| 605 | |
| 606 | m_match = match; |
| 607 | |
| 604 | 608 | check_interrupts(); |
| 605 | 609 | } |
| 606 | 610 | } |