Previous 15994 Revisions Next

r3447 Monday 13th October, 2008 at 15:30:24 UTC by Curt Coder
[MBEE, SUPER80] Fixed Z80PIO regressions (bugs #1704, #1705).
[src/emu/machine]z80pio.c

src/emu/machine/z80pio.c
r3446r3447
189189   z80pio_t *z80pio = get_safe_token(device);
190190   UINT8 data = z80pio->output[channel];
191191
192   if (z80pio->mode[channel] == PIO_MODE_CONTROL)
193   {
194      /* mask out input pins */
195      data &= ~z80pio->ddr[channel];
196   }
197
192198   if (channel == PIO_PORT_A)
193199   {
194200      if (z80pio->intf->port_a_w)
r3446r3447
214220   if (LOG) logerror("Z80PIO Port %c Mode %u\n", 'A' + channel, mode);
215221
216222   /* clear interrupt */
223   z80pio->irq_enable[channel] = 0;
217224   z80pio->irq_pending[channel] = 0;
218225   z80pio->int_state[channel] = 0;
219226   z80pio->match[channel] = 0;
220227
228   z80pio_check_interrupt(device);
229
221230   switch (mode)
222231   {
223232   case PIO_MODE_OUTPUT:
r3446r3447
320329      z80pio->ddr[channel] = data;
321330      z80pio->match[channel] = 0;
322331
332      /* set interrupt enable */
333      z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7);
334      z80pio_check_interrupt(device);
335
323336      z80pio->state[channel] = PIO_STATE_NORMAL;
324337
325338      if (LOG) logerror("Z80PIO Port %c Direction %02x\n", 'A' + channel, data);
r3446r3447
449462
450463   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
451464   {
452      if (z80pio->mode[channel] == PIO_MODE_CONTROL)
465      if ((z80pio->mode[channel] == PIO_MODE_CONTROL) && (z80pio->mask[channel] != 0xff))
453466      {
467         int bit;
454468         int match = 0;
469
470         UINT8 ddr = z80pio->ddr[channel];
471         UINT8 mask = z80pio->mask[channel];
472         UINT8 output = (z80pio->output[channel] & ~ddr);
473         UINT8 old_data = (z80pio->input[channel] & z80pio->ddr[channel]) | output;
455474         UINT8 data;
456
457         /* input data */
475         
458476         z80pio_port_read(device, channel);
459477
460         data = z80pio->input[channel] & z80pio->ddr[channel];
478         data = (z80pio->input[channel] & ddr) | output;
461479
462         /* keep only relevant bits */
463         data &= ~z80pio->mask[channel];
480         for (bit = 0; bit < 8; bit++)
481         {
482            if (!BIT(mask, bit))
483            {
484               if (z80pio->enable[channel] & PIO_IRQ_HIGH_LOW)
485               {
486                  if (!BIT(old_data, bit) && BIT(data, bit)) // rising edge
487                  {
488                     match = 1;
464489
465         /* if active low, invert the bits */
466         if (!(z80pio->enable[channel] & PIO_IRQ_HIGH_LOW))
467            data ^= z80pio->mask[channel];
490                     if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR
491                     {
492                        break;
493                     }
494                  }
495                  else
496                  {
497                     if (z80pio->enable[channel] & PIO_IRQ_AND_OR) // AND
498                     {
499                        match = 0;
500                        break;
501                     }
502                  }
503               }
504               else
505               {
506                  if (BIT(old_data, bit) && !BIT(data, bit)) // falling edge
507                  {
508                     match = 1;
468509
469         /* if AND logic, interrupt if all bits are set */
470         if (z80pio->enable[channel] & PIO_IRQ_AND_OR)
471            match = (data == z80pio->mask[channel]);
472         /* otherwise, interrupt if at least one bit is set */
473         else
474            match = (data != 0);
510                     if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR
511                     {
512                        break;
513                     }
514                  }
515                  else
516                  {
517                     if (z80pio->enable[channel] & PIO_IRQ_AND_OR) // AND
518                     {
519                        match = 0;
520                        break;
521                     }
522                  }
523               }
524            }
525         }
475526
476527         if (match)
477528         {
478            if (!z80pio->match[channel])
479            {
480               /* trigger interrupt */
481               z80pio->match[channel] = 1;
482               z80pio->irq_pending[channel] = 1;
529            /* trigger interrupt */
530            z80pio->irq_pending[channel] = 1;
483531
484               if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel);
532            if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel);
485533
486               z80pio_check_interrupt(device);
487            }
534            z80pio_check_interrupt(device);
488535         }
489         else
490         {
491            z80pio->match[channel] = 0;
492         }
493536      }
494537   }
495538}
r3446r3447
723766   /* allocate poll timers */
724767
725768   z80pio->poll_timer = timer_alloc(z80pio_poll_tick, (void *)device);
726   timer_adjust_periodic(z80pio->poll_timer, attotime_zero, 0, ATTOTIME_IN_HZ(z80pio->clock));
769   timer_adjust_periodic(z80pio->poll_timer, attotime_zero, 0, ATTOTIME_IN_HZ(z80pio->clock / 16));
727770
728771   /* register for state saving */
729772
r3446r3447
764807      /* set mode 1 */
765808      z80pio->mode[channel] = PIO_MODE_INPUT;
766809
810      /* set all inputs */
811      z80pio->ddr[channel] = 0xff;
812
767813      /* reset interrupt */
768814      z80pio->enable[channel] &= 0x7f;
769815      z80pio->irq_enable[channel] = 0;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team