Previous 15994 Revisions Next

r7412 Thursday 18th February, 2010 at 07:31:19 UTC by Curt Coder
[Z80PIO] Fixed mode 3 interrupts.
[src/emu/machine]z80pio.c

src/emu/machine/z80pio.c
r7411r7412
111111   {
112112      pio_port *port = &z80pio->port[index];
113113
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
114138      if (port->ie && port->ip && !port->ius)
115139      {
116140         state = ASSERT_LINE;
117141      }
118142   }
119   
143
120144   devcb_call_write_line(&z80pio->out_int_func, state);
121145}
122146
r7411r7412
254278         case 0x07: /* set interrupt control word */
255279            port->icw = data;
256280
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
257289            if (port->icw & ICW_MASK_FOLLOWS)
258290            {
259291               /* disable interrupts until mask is written */
r7411r7412
269301               /* next word is mask control */
270302               port->next_control_word = MASK;
271303            }
304            else
305            {
306               /* monitor all bits */
307               port->mask = 0;
308            }
272309            break;
273310
274311         case 0x03: /* set interrupt enable flip-flop */
r7411r7412
499536}
500537
501538/*-------------------------------------------------
502    check_equation - check bit logic equation
503-------------------------------------------------*/
504
505static 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/*-------------------------------------------------
556539    z80pio_pa_w - port A write
557540-------------------------------------------------*/
558541
r7411r7412
563546   
564547   if (port->mode == MODE_BIT_CONTROL)
565548   {
566      check_equation(device, PORT_A, data);
549      /* latch data */
550      port->input = data;
551      check_interrupts(device);
567552   }
568553}
569554
r7411r7412
603588   
604589   if (port->mode == MODE_BIT_CONTROL)
605590   {
606      check_equation(device, PORT_B, data);
591      /* latch data */
592      port->input = data;
593      check_interrupts(device);
607594   }
608595}
609596
r7411r7412
761748
762749         /* clear interrupt pending flag */
763750         port->ip = 0;
764         check_interrupts(device);
765751
766752         /* set interrupt under service flag */
767753         port->ius = 1;
768754
755         check_interrupts(device);
756
769757         return port->vector;
770758      }
771759   }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team