trunk/src/emu/machine/pic8259.c
| r241606 | r241607 | |
| 14 | 14 | #include "emu.h" |
| 15 | 15 | #include "machine/pic8259.h" |
| 16 | 16 | |
| 17 | | #define IRQ_COUNT 8 |
| 18 | | |
| 19 | 17 | #define LOG_ICW 0 |
| 20 | 18 | #define LOG_OCW 0 |
| 21 | 19 | #define LOG_GENERAL 0 |
| r241606 | r241607 | |
| 24 | 22 | |
| 25 | 23 | void pic8259_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 26 | 24 | { |
| 27 | | int irq; |
| 28 | | UINT8 mask; |
| 29 | | |
| 30 | 25 | /* check the various IRQs */ |
| 31 | | for (irq = 0; irq < IRQ_COUNT; irq++) |
| 26 | for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) |
| 32 | 27 | { |
| 33 | | mask = 1 << irq; |
| 28 | UINT8 mask = 1 << irq; |
| 34 | 29 | |
| 35 | | /* is this IRQ in service? */ |
| 36 | | if (m_isr & mask) |
| 30 | /* is this IRQ in service and not cascading and sfnm? */ |
| 31 | if ((m_isr & mask) && !(m_master && m_cascade && m_nested && (m_slave & mask))) |
| 37 | 32 | { |
| 38 | 33 | if (LOG_GENERAL) |
| 39 | 34 | { |
| 40 | | logerror("pic8259_timerproc(): PIC IRQ #%d still in service\n", irq); |
| 35 | logerror("pic8259_timerproc() %s: PIC IRQ #%d still in service\n", tag(), irq); |
| 41 | 36 | } |
| 42 | 37 | break; |
| 43 | 38 | } |
| r241606 | r241607 | |
| 47 | 42 | { |
| 48 | 43 | if (LOG_GENERAL) |
| 49 | 44 | { |
| 50 | | logerror("pic8259_timerproc(): PIC triggering IRQ #%d\n", irq); |
| 45 | logerror("pic8259_timerproc() %s: PIC triggering IRQ #%d\n", tag(), irq); |
| 51 | 46 | } |
| 52 | 47 | if (!BIT(m_ocw3, 2)) |
| 53 | 48 | { |
| r241606 | r241607 | |
| 55 | 50 | } |
| 56 | 51 | return; |
| 57 | 52 | } |
| 53 | // if sfnm and in-service don't continue |
| 54 | if((m_isr & mask) && m_master && m_cascade && m_nested && (m_slave & mask)) |
| 55 | break; |
| 58 | 56 | } |
| 59 | 57 | if (!BIT(m_ocw3, 2)) |
| 60 | 58 | { |
| r241606 | r241607 | |
| 71 | 69 | { |
| 72 | 70 | /* setting IRQ line */ |
| 73 | 71 | if (LOG_GENERAL) |
| 74 | | logerror("pic8259_set_irq_line(): PIC set IRQ line #%d\n", irq); |
| 72 | logerror("pic8259_set_irq_line() %s: PIC set IRQ line #%d\n", tag(), irq); |
| 75 | 73 | |
| 76 | 74 | if(m_level_trig_mode || (!m_level_trig_mode && !(m_irq_lines & mask))) |
| 77 | 75 | { |
| r241606 | r241607 | |
| 84 | 82 | /* clearing IRQ line */ |
| 85 | 83 | if (LOG_GENERAL) |
| 86 | 84 | { |
| 87 | | logerror("pic8259_device::set_irq_line(): PIC cleared IRQ line #%d\n", irq); |
| 85 | logerror("pic8259_device::set_irq_line() %s: PIC cleared IRQ line #%d\n", tag(), irq); |
| 88 | 86 | } |
| 89 | 87 | |
| 90 | 88 | m_irq_lines &= ~mask; |
| r241606 | r241607 | |
| 96 | 94 | |
| 97 | 95 | UINT32 pic8259_device::acknowledge() |
| 98 | 96 | { |
| 99 | | UINT8 mask; |
| 100 | | int irq; |
| 101 | | |
| 102 | | for (irq = 0; irq < IRQ_COUNT; irq++) |
| 97 | for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) |
| 103 | 98 | { |
| 104 | | mask = 1 << irq; |
| 99 | UINT8 mask = 1 << irq; |
| 105 | 100 | |
| 106 | 101 | /* is this IRQ pending and enabled? */ |
| 107 | 102 | if ((m_irr & mask) && !(m_imr & mask)) |
| 108 | 103 | { |
| 109 | 104 | if (LOG_GENERAL) |
| 110 | 105 | { |
| 111 | | logerror("pic8259_acknowledge(): PIC acknowledge IRQ #%d\n", irq); |
| 106 | logerror("pic8259_acknowledge() %s: PIC acknowledge IRQ #%d\n", tag(), irq); |
| 112 | 107 | } |
| 113 | 108 | if (!m_level_trig_mode) |
| 114 | 109 | { |
| r241606 | r241607 | |
| 170 | 165 | |
| 171 | 166 | if ( m_irr & ~m_imr ) |
| 172 | 167 | { |
| 173 | | int irq; |
| 174 | | for ( irq = 0; irq < IRQ_COUNT; irq++ ) |
| 168 | /* check the various IRQs */ |
| 169 | for (int n = 0, irq = m_prio; n < 8; n++, irq = (irq + 1) & 7) |
| 175 | 170 | { |
| 176 | 171 | if ( ( 1 << irq ) & m_irr & ~m_imr ) |
| 177 | 172 | { |
| r241606 | r241607 | |
| 216 | 211 | /* write ICW1 - this pretty much resets the chip */ |
| 217 | 212 | if (LOG_ICW) |
| 218 | 213 | { |
| 219 | | logerror("pic8259_device::write(): ICW1; data=0x%02X\n", data); |
| 214 | logerror("pic8259_device::write() %s: ICW1; data=0x%02X\n", tag(), data); |
| 220 | 215 | } |
| 221 | 216 | |
| 222 | 217 | m_imr = 0x00; |
| r241606 | r241607 | |
| 237 | 232 | /* write OCW3 */ |
| 238 | 233 | if (LOG_OCW) |
| 239 | 234 | { |
| 240 | | logerror("pic8259_device::write(): OCW3; data=0x%02X\n", data); |
| 235 | logerror("pic8259_device::write() %s: OCW3; data=0x%02X\n", tag(), data); |
| 241 | 236 | } |
| 242 | 237 | |
| 243 | 238 | m_ocw3 = data; |
| r241606 | r241607 | |
| 250 | 245 | /* write OCW2 */ |
| 251 | 246 | if (LOG_OCW) |
| 252 | 247 | { |
| 253 | | logerror("pic8259_device::write(): OCW2; data=0x%02X\n", data); |
| 248 | logerror("pic8259_device::write() %s: OCW2; data=0x%02X\n", tag(), data); |
| 254 | 249 | } |
| 255 | 250 | |
| 256 | 251 | switch (data & 0xe0) |
| r241606 | r241607 | |
| 291 | 286 | } |
| 292 | 287 | break; |
| 293 | 288 | case 0xc0: |
| 294 | | m_prio = n & 7; |
| 289 | m_prio = (n + 1) & 7; |
| 295 | 290 | break; |
| 296 | 291 | case 0xe0: |
| 297 | 292 | if( m_isr & mask ) |
| 298 | 293 | { |
| 299 | 294 | m_isr &= ~mask; |
| 300 | | m_prio = (m_prio + 1) & 7; |
| 295 | m_prio = (n + 1) & 7; |
| 301 | 296 | } |
| 302 | 297 | break; |
| 303 | 298 | } |
| r241606 | r241607 | |
| 315 | 310 | /* write ICW2 */ |
| 316 | 311 | if (LOG_ICW) |
| 317 | 312 | { |
| 318 | | logerror("pic8259_device::write(): ICW2; data=0x%02X\n", data); |
| 313 | logerror("pic8259_device::write() %s: ICW2; data=0x%02X\n", tag(), data); |
| 319 | 314 | } |
| 320 | 315 | |
| 321 | 316 | m_base = data & 0xf8; |
| r241606 | r241607 | |
| 334 | 329 | /* write ICW3 */ |
| 335 | 330 | if (LOG_ICW) |
| 336 | 331 | { |
| 337 | | logerror("pic8259_device::write(): ICW3; data=0x%02X\n", data); |
| 332 | logerror("pic8259_device::write() %s: ICW3; data=0x%02X\n", tag(), data); |
| 338 | 333 | } |
| 339 | 334 | |
| 340 | 335 | m_slave = data; |
| r241606 | r241607 | |
| 345 | 340 | /* write ICW4 */ |
| 346 | 341 | if (LOG_ICW) |
| 347 | 342 | { |
| 348 | | logerror("pic8259_device::write(): ICW4; data=0x%02X\n", data); |
| 343 | logerror("pic8259_device::write() %s: ICW4; data=0x%02X\n", tag(), data); |
| 349 | 344 | } |
| 350 | 345 | |
| 351 | 346 | m_nested = (data & 0x10) ? 1 : 0; |