Previous 15994 Revisions Next

r3450 Tuesday 14th October, 2008 at 16:20:21 UTC by Curt Coder
[SUPER80] Fixed Z80PIO regression. (bug #1708)
[src/emu/machine]z80pio.c z80pio.h

src/emu/machine/z80pio.c
r3449r3450
11/***************************************************************************
22
3    Z80 PIO implementation
3    Z80 PIO Parallel Input/Output Controller emulation
44
5    based on original version (c) 1997, Tatsuyuki Satoh
6
75    Copyright Nicola Salmoria and the MAME Team.
86    Visit http://mamedev.org for licensing and usage restrictions.
97
r3449r3450
1816    DEBUGGING
1917***************************************************************************/
2018
21#define LOG 0
19#define VERBOSE 0
2220
21#define LOGERROR if (VERBOSE) logerror
22
2323/***************************************************************************
2424    CONSTANTS
2525***************************************************************************/
r3449r3450
4646   PIO_PORT_COUNT
4747};
4848
49#define PIO_MODE_CONTROL_WORD   0x0f
50#define PIO_IRQ_CONTROL_WORD   0x07
51#define PIO_IRQ_DISABLE_WORD   0x03
52
4953#define PIO_IRQ_MASK_FOLLOWS   0x10
50#define PIO_IRQ_HIGH_LOW      0x20
51#define PIO_IRQ_AND_OR         0x40
54#define PIO_IRQ_ACTIVE_HIGH      0x20
55#define PIO_IRQ_AND            0x40
5256#define PIO_IRQ_ENABLE         0x80
5357
5458/***************************************************************************
r3449r3450
6569   int state[PIO_PORT_COUNT];            /* control register state */
6670   int mode[PIO_PORT_COUNT];            /* mode control register */
6771   int irq_enable[PIO_PORT_COUNT];         /* interrupt enable flag */
68   int irq_pending[PIO_PORT_COUNT];      /* interrupt pending */
6972   int int_state[PIO_PORT_COUNT];         /* interrupt status */
7073   UINT8 enable[PIO_PORT_COUNT];         /* interrupt control word */
7174   UINT8 input[PIO_PORT_COUNT];         /* data input register */
r3449r3450
7477   UINT8 mask[PIO_PORT_COUNT];            /* mask register */
7578   UINT8 ddr[PIO_PORT_COUNT];            /* input/output select register */
7679   int strobe[PIO_PORT_COUNT];            /* strobe pulse */
80   int match[PIO_PORT_COUNT];            /* control mode bit logic equation match */
7781
7882   /* timers */
7983   emu_timer *poll_timer;               /* mode 3 poll timer */
84   emu_timer *irq_timer;               /* interrupt enable timer */
8085};
8186
8287/***************************************************************************
r3449r3450
111116
112117   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
113118   {
114      if (z80pio->irq_enable[channel])
119      if (!(z80pio->irq_enable[channel]))
115120      {
116         if (z80pio->irq_pending[channel])
117         {
118            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Request\n", device->tag, 'A' + channel);
119
120            /* request interrupt */
121            z80pio->irq_pending[channel] = 0;
122            z80pio->int_state[channel] |= Z80_DAISY_INT;
123            break;
124         }
125      }
126      else
127      {
128121         /* clear interrupt request */
129122         z80pio->int_state[channel] &= ~Z80_DAISY_INT;
130123      }
r3449r3450
136129   }
137130}
138131
139static void z80pio_set_ready_line(const device_config *device, int channel, int level)
132static void z80pio_trigger_interrupt(const device_config *device, int channel)
140133{
141134   z80pio_t *z80pio = get_safe_token(device);
142135
143   if (LOG) logerror("Z80PIO \"%s\" Port %c Ready %u\n", device->tag, 'A' + channel, level);
136   if (z80pio->irq_enable[channel])
137   {
138      z80pio->int_state[channel] |= Z80_DAISY_INT;
139      z80pio_check_interrupt(device);
144140
141      LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Request\n", device->tag, 'A' + channel);
142   }
143}
144
145static TIMER_CALLBACK( z80pio_irq_tick )
146{
147   const device_config *device = (device_config *) ptr;
148   z80pio_t *z80pio = get_safe_token(device);
149
150   int channel = BIT(param, 1);
151   int state = BIT(param, 0);
152
153   /* set interrupt enable */
154   z80pio->irq_enable[channel] = state;
155
156   LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Enable %u\n", device->tag, 'A' + channel, state);
157}
158
159static void z80pio_set_irq_enable(const device_config *device, int channel, int state)
160{
161   z80pio_t *z80pio = get_safe_token(device);
162
163   if (state)
164   {
165      /* enable interrupt on next _M1 */
166      int param = (channel << 1) | state;
167
168      timer_adjust_oneshot(z80pio->irq_timer, ATTOTIME_IN_HZ(z80pio->clock * 4), param);
169   }
170   else
171   {
172      /* disable interrupt immediately */
173      z80pio->irq_enable[channel] = state;
174
175      LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Enable %u\n", device->tag, 'A' + channel, state);
176   }
177}
178
179static void z80pio_ready_w(const device_config *device, int channel, int state)
180{
181   z80pio_t *z80pio = get_safe_token(device);
182
183   LOGERROR("Z80PIO \"%s\" Port %c : Ready %u\n", device->tag, 'A' + channel, state);
184
145185   if (channel == PIO_PORT_A)
146186   {
147187      if (z80pio->intf->on_ardy_changed)
148188      {
149         z80pio->intf->on_ardy_changed(device, level);
189         z80pio->intf->on_ardy_changed(device, state);
150190      }
151191   }
152192   else
153193   {
154194      if (z80pio->intf->on_brdy_changed)
155195      {
156         z80pio->intf->on_brdy_changed(device, level);
196         z80pio->intf->on_brdy_changed(device, state);
157197      }
158198   }
159199}
160200
161static void z80pio_port_read(const device_config *device, int channel)
201static UINT8 z80pio_port_r(const device_config *device, int channel)
162202{
163203   z80pio_t *z80pio = get_safe_token(device);
164204   UINT8 data = 0;
r3449r3450
178218      }
179219   }
180220
181   //if (LOG) logerror("Z80PIO \"%s\" Port %c Read Data %02x\n", device->tag, 'A' + channel, data);
221   //LOGERROR("Z80PIO \"%s\" Port %c : Input Data '%02x'\n", device->tag, 'A' + channel, data);
182222
183   z80pio->input[channel] = data;
223   return data;
184224}
185225
186static void z80pio_port_write(const device_config *device, int channel)
226static void z80pio_port_w(const device_config *device, int channel)
187227{
188228   z80pio_t *z80pio = get_safe_token(device);
189229   UINT8 data = z80pio->output[channel];
190230
191231   if (z80pio->mode[channel] == PIO_MODE_CONTROL)
192232   {
193      /* mask out input pins */
233      /* mask input pins */
194234      data &= ~z80pio->ddr[channel];
195235   }
196236
r3449r3450
209249      }
210250   }
211251
212   if (LOG) logerror("Z80PIO \"%s\" Port %c Write Data %02x\n", device->tag, 'A' + channel, data);
252   //LOGERROR("Z80PIO \"%s\" Port %c : Output Data '%02x'\n", device->tag, 'A' + channel, data);
213253}
214254
215static void z80pio_set_mode(const device_config *device, int channel, int mode)
255static void z80pio_set_mode(const device_config *device, int channel, UINT8 data)
216256{
217257   z80pio_t *z80pio = get_safe_token(device);
218258
219   if (LOG) logerror("Z80PIO \"%s\" Port %c Mode %u\n", device->tag, 'A' + channel, mode);
259   int mode = data >> 6;
220260
221   /* clear interrupt */
222   z80pio->irq_enable[channel] = 0;
223   z80pio->irq_pending[channel] = 0;
224   z80pio->int_state[channel] = 0;
225
226   z80pio_check_interrupt(device);
227
228261   switch (mode)
229262   {
230263   case PIO_MODE_OUTPUT:
264      LOGERROR("Z80PIO \"%s\" Port %c : Mode %u (Byte Output)\n", device->tag, 'A' + channel, mode);
265
266      /* set mode */
231267      z80pio->mode[channel] = mode;
232268
233269      /* enable data output */
234      z80pio_port_write(device, channel);
270      z80pio_port_w(device, channel);
235271
236272      /* assert ready line */
237      z80pio_set_ready_line(device, channel, 1);
273      z80pio_ready_w(device, channel, 1);
238274      break;
239275
240276   case PIO_MODE_INPUT:
277      LOGERROR("Z80PIO \"%s\" Port %c : Mode %u (Byte Input)\n", device->tag, 'A' + channel, mode);
278
279      /* set mode */
241280      z80pio->mode[channel] = mode;
242281      break;
243282
244283   case PIO_MODE_BIDIRECTIONAL:
245284      if (channel == PIO_PORT_A)
246285      {
286         LOGERROR("Z80PIO \"%s\" Port %c : Mode %u (Bidirectional)\n", device->tag, 'A' + channel, mode);
287
288         /* set mode */
247289         z80pio->mode[channel] = mode;
248290      }
249291      break;
250292
251293   case PIO_MODE_CONTROL:
294      LOGERROR("Z80PIO \"%s\" Port %c : Mode %u (Bit Control)\n", device->tag, 'A' + channel, mode);
295
296      /* set mode */
252297      z80pio->mode[channel] = mode;
253298
254299      if ((channel == PIO_PORT_A) || (z80pio->mode[PIO_PORT_A] != PIO_MODE_BIDIRECTIONAL))
255300      {
256301         /* clear ready line */
257         z80pio_set_ready_line(device, channel, 0);
302         z80pio_ready_w(device, channel, 0);
258303      }
304
305      /* disable interrupts until DDR is written */
306      z80pio_set_irq_enable(device, channel, 0);
307
308      /* set logic equation to false */
309      z80pio->match[channel] = 0;
310
311      /* next word is I/O control */
312      z80pio->state[channel] = PIO_STATE_DDR;
259313      break;
260314   }
261315}
r3449r3450
264318    CONTROL REGISTER READ/WRITE
265319***************************************************************************/
266320
321READ8_DEVICE_HANDLER( lh0081_c_r )
322{
323   z80pio_t *z80pio = get_safe_token(device);
324
325   return (z80pio->enable[PIO_PORT_A] & 0xc0) | (z80pio->enable[PIO_PORT_B] >> 4);
326}
327
267328READ8_DEVICE_HANDLER( z80pio_c_r )
268329{
269330   return 0;
r3449r3450
279340   case PIO_STATE_NORMAL:
280341      if (!BIT(data, 0))
281342      {
343         LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Vector Word '%02x'\n", device->tag, 'A' + channel, z80pio->vector[channel]);
344
282345         /* load interrupt vector */
283346         z80pio->vector[channel] = data & 0xfe;
284
285         if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Vector %02x\n", device->tag, 'A' + channel, z80pio->vector[channel]);
286347      }
287      else if ((data & 0x0f) == 0x03)
348      else if ((data & 0x0f) == PIO_IRQ_DISABLE_WORD)
288349      {
350         LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Disable Word '%02x'\n", device->tag, 'A' + channel, data);
351
289352         /* set interrupt enable */
290353         z80pio->enable[channel] = (data & 0x80) | (z80pio->enable[channel] & 0x7f);
291         z80pio->irq_enable[channel] = BIT(data, 7);
292         z80pio_check_interrupt(device);
293
294         if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Enable %u\n", device->tag, 'A' + channel, BIT(data, 7));
354         z80pio_set_irq_enable(device, channel, BIT(data, 7));
295355      }
296      else if ((data & 0x0f) == 0x0f)
356      else if ((data & 0x0f) == PIO_MODE_CONTROL_WORD)
297357      {
298         /* select operating mode */
299         int mode = data >> 6;
358         LOGERROR("Z80PIO \"%s\" Port %c : Mode Control Word '%02x'\n", device->tag, 'A' + channel, data);
300359
301         z80pio_set_mode(device, channel, mode);
302
303         if (mode == PIO_MODE_CONTROL)
304         {
305            z80pio->state[channel] = PIO_STATE_DDR;
306         }
360         /* set operating mode */
361         z80pio_set_mode(device, channel, data);
307362      }
308      else if ((data & 0x0f) == 0x07)
363      else if ((data & 0x0f) == PIO_IRQ_CONTROL_WORD)
309364      {
365         LOGERROR("Z80PIO \"%s\" Port %c : Interrupt Control Word '%02x'\n", device->tag, 'A' + channel, data);
366
310367         /* set interrupt control word */
311368         z80pio->enable[channel] = data & 0xf0;
312369
313370         if (data & PIO_IRQ_MASK_FOLLOWS)
314371         {
315            /* mask follows */
372            /* disable interrupts until mask is written */
373            z80pio_set_irq_enable(device, channel, 0);
374
375            /* next word is mask control */
316376            z80pio->state[channel] = PIO_STATE_MASK;
317
318            /* clear pending interrupt */
319            z80pio->irq_pending[channel] = 0;
320377         }
321378         else
322379         {
323380            /* set interrupt enable */
324            z80pio->irq_enable[channel] = BIT(data, 7);
381            z80pio_set_irq_enable(device, channel, BIT(data, 7));
325382         }
326
327         z80pio_check_interrupt(device);
328
329         if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Control %02x\n", device->tag, 'A' + channel, data);
330383      }
331384      break;
332385
333386   case PIO_STATE_DDR:
387      LOGERROR("Z80PIO \"%s\" Port %c : I/O Control Word '%02x'\n", device->tag, 'A' + channel, data);
388
334389      /* set data direction */
335390      z80pio->ddr[channel] = data;
336391
337392      /* set interrupt enable */
338      z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7);
339      z80pio_check_interrupt(device);
393      z80pio_set_irq_enable(device, channel, BIT(z80pio->enable[channel], 7));
340394
395      /* next word is indeterminate */
341396      z80pio->state[channel] = PIO_STATE_NORMAL;
342
343      if (LOG) logerror("Z80PIO \"%s\" Port %c Direction %02x\n", device->tag, 'A' + channel, data);
344397      break;
345398
346399   case PIO_STATE_MASK:
400      LOGERROR("Z80PIO \"%s\" Port %c : Mask Control Word '%02x'\n", device->tag, 'A' + channel, data);
401
347402      /* set interrupt mask */
348403      z80pio->mask[channel] = data;
349404
350405      /* set interrupt enable */
351      z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7);
352      z80pio_check_interrupt(device);
406      z80pio_set_irq_enable(device, channel, BIT(z80pio->enable[channel], 7));
353407
408      /* next word is indeterminate */
354409      z80pio->state[channel] = PIO_STATE_NORMAL;
355
356      if (LOG) logerror("Z80PIO \"%s\" Port %c Mask %02x\n", device->tag, 'A' + channel, data);
357410      break;
358411   }
359412}
r3449r3450
378431      data = z80pio->input[channel];
379432
380433      /* clear ready line */
381      z80pio_set_ready_line(device, channel, 0);
434      z80pio_ready_w(device, channel, 0);
382435
383436      /* assert ready line */
384      z80pio_set_ready_line(device, channel, 1);
437      z80pio_ready_w(device, channel, 1);
385438      break;
386439
387440   case PIO_MODE_BIDIRECTIONAL:
388441      data = z80pio->input[PIO_PORT_A] | (z80pio->output[PIO_PORT_A] & (~z80pio->ddr[PIO_PORT_A]));
389442
390443      /* clear ready line */
391      z80pio_set_ready_line(device, 1, 0);
444      z80pio_ready_w(device, 1, 0);
392445
393446      /* assert ready line */
394      z80pio_set_ready_line(device, 1, 1);
447      z80pio_ready_w(device, 1, 1);
395448      break;
396449
397450   case PIO_MODE_CONTROL:
398      z80pio_port_read(device, channel);
451      z80pio->input[channel] = z80pio_port_r(device, channel);
452
399453      data = (z80pio->input[channel] & z80pio->ddr[channel]) | (z80pio->output[channel] & (~z80pio->ddr[channel]));
400454      break;
401455   }
402456
403   if (LOG) logerror("Z80PIO \"%s\" Port %c Data Register Read %02x\n", device->tag, 'A' + channel, data);
457   LOGERROR("Z80PIO \"%s\" Port %c : Data Register Read '%02x'\n", device->tag, 'A' + channel, data);
404458
405459   return data;
406460}
r3449r3450
410464   z80pio_t *z80pio = get_safe_token( device );
411465   int channel = offset & 0x01;
412466
413   if (LOG) logerror("Z80PIO \"%s\" Port %c Data Register Write %02x\n", device->tag, 'A' + channel, data);
467   LOGERROR("Z80PIO \"%s\" Port %c : Data Register Write '%02x'\n", device->tag, 'A' + channel, data);
414468
415469   switch (z80pio->mode[channel])
416470   {
417471   case PIO_MODE_OUTPUT:
418472      /* clear ready line */
419      z80pio_set_ready_line(device, channel, 0);
473      z80pio_ready_w(device, channel, 0);
420474
421475      /* output data */
422476      z80pio->output[channel] = data;
423      z80pio_port_write(device, channel);
477      z80pio_port_w(device, channel);
424478
425479      /* assert ready line */
426      z80pio_set_ready_line(device, channel, 1);
480      z80pio_ready_w(device, channel, 1);
427481      break;
428482
429483   case PIO_MODE_INPUT:
r3449r3450
432486
433487   case PIO_MODE_BIDIRECTIONAL:
434488      /* clear ready line */
435      z80pio_set_ready_line(device, PIO_PORT_A, 0);
489      z80pio_ready_w(device, channel, 0);
436490
437491      /* latch output data */
438492      z80pio->output[channel] = data;
439493
440      if (!z80pio->strobe[PIO_PORT_A])
494      if (!z80pio->strobe[channel])
441495      {
442496         /* output data if ASTB active */
443         z80pio_port_write(device, channel);
497         z80pio_port_w(device, channel);
444498      }
445499
446500      /* assert ready line */
447      z80pio_set_ready_line(device, PIO_PORT_A, 1);
501      z80pio_ready_w(device, channel, 1);
448502      break;
449503
450504   case PIO_MODE_CONTROL:
451505      /* output data */
452506      z80pio->output[channel] = data;
453      z80pio_port_write(device, channel);
507      z80pio_port_w(device, channel);
454508      break;
455509   }
456510}
r3449r3450
472526         int bit;
473527         int match = 0;
474528
529         int edge = (z80pio->enable[channel] & PIO_IRQ_ACTIVE_HIGH) ? 1 : 0;
530
531         UINT8 mask = z80pio->mask[channel];
475532         UINT8 ddr = z80pio->ddr[channel];
476         UINT8 mask = z80pio->mask[channel];
477         UINT8 output = (z80pio->output[channel] & ~ddr);
478         UINT8 old_data = (z80pio->input[channel] & z80pio->ddr[channel]) | output;
479         UINT8 data;
480         
481         z80pio_port_read(device, channel);
533         UINT8 old_data = z80pio->input[channel] & ddr;
534         UINT8 data = z80pio_port_r(device, channel) & ddr;
482535
483         data = (z80pio->input[channel] & ddr) | output;
484
485536         for (bit = 0; bit < 8; bit++)
486537         {
487            if (!BIT(mask, bit))
538            if (BIT(mask, bit)) continue; /* masked out */
539            if (!BIT(ddr, bit)) continue; /* output bit */
540
541            if ((BIT(old_data, bit) ^ edge) && !(BIT(data, bit) ^ edge)) /* falling edge */
488542            {
489               if (z80pio->enable[channel] & PIO_IRQ_HIGH_LOW)
490               {
491                  if (!BIT(old_data, bit) && BIT(data, bit)) // rising edge
492                  {
493                     if (LOG) logerror("Z80PIO \"%s\" Port %c Rising Edge detected on bit %u\n", device->tag, 'A' + channel, bit);
543               /* logic equation is true, until proven otherwise */
544               match = 1;
494545
495                     match = 1;
496
497                     if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR
498                     {
499                        break;
500                     }
501                  }
502                  else
503                  {
504                     if (z80pio->enable[channel] & PIO_IRQ_AND_OR) // AND
505                     {
506                        match = 0;
507                        break;
508                     }
509                  }
510               }
511               else
512               {
513                  if (BIT(old_data, bit) && !BIT(data, bit)) // falling edge
514                  {
515                     if (LOG) logerror("Z80PIO \"%s\" Port %c Falling Edge detected on bit %u\n", device->tag, 'A' + channel, bit);
516
517                     match = 1;
518
519                     if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR
520                     {
521                        break;
522                     }
523                  }
524                  else
525                  {
526                     if (z80pio->enable[channel] & PIO_IRQ_AND_OR) // AND
527                     {
528                        match = 0;
529                        break;
530                     }
531                  }
532               }
546               LOGERROR("Z80PIO \"%s\" Port %c : Edge Transition detected on bit %u, data %02x %02x\n", device->tag, 'A' + channel, bit, old_data, data);
533547            }
548            else if (z80pio->enable[channel] & PIO_IRQ_AND)
549            {
550               /* all bits must match in AND mode, so logic equation is false */
551               match = 0;
552               break;
553            }
534554         }
535555
536         if (match)
556         if (!z80pio->match[channel] && match) /* rising edge */
537557         {
538            /* trigger interrupt */
539            z80pio->irq_pending[channel] = 1;
558            /* trigger interrupt only once */
559            z80pio_trigger_interrupt(device, channel);
560            z80pio->input[channel] = data;
561         }
540562
541            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
542
543            z80pio_check_interrupt(device);
544         }
563         z80pio->match[channel] = match;
545564      }
546565   }
547566}
r3449r3450
550569    STROBE STATE MANAGEMENT
551570***************************************************************************/
552571
553static void z80pio_strobe(const device_config *device, int channel, int level)
572static void z80pio_strobe_bidirectional(const device_config *device, int channel, int state)
554573{
555574   z80pio_t *z80pio = get_safe_token(device);
556575
557   if (LOG) logerror("Z80PIO \"%s\" Port %c Strobe %u\n", device->tag, 'A' + channel, level);
558
559   if (z80pio->mode[PIO_PORT_A] == PIO_MODE_BIDIRECTIONAL)
576   switch (channel)
560577   {
561      /* port A bidirectional mode */
562
563      switch (channel)
578   case PIO_PORT_A:
579      if (!state) /* low level */
564580      {
565      case PIO_PORT_A:
566         if (!level)
567         {
568            /* output data */
569            z80pio_port_write(device, PIO_PORT_A);
570         }
571         break;
581         /* output data */
582         z80pio_port_w(device, PIO_PORT_A);
583      }
584      else if (!z80pio->strobe[channel] && state) /* rising edge */
585      {
586         /* trigger interrupt */
587         z80pio_trigger_interrupt(device, channel);
572588
573      case PIO_PORT_B:
574         if (!level)
575         {
576            /* input data */
577            z80pio_port_read(device, PIO_PORT_A);
578         }
579         else if (!z80pio->strobe[PIO_PORT_A] && level) // rising edge
580         {
581            /* generate interrupt */
582            z80pio->irq_pending[channel] = 1;
583            z80pio_check_interrupt(device);
589         /* clear ready line */
590         z80pio_ready_w(device, channel, 0);
591      }
592      break;
584593
585            /* clear ready line */
586            z80pio_set_ready_line(device, channel, 0);
594   case PIO_PORT_B:
595      if (!state) /* low level */
596      {
597         /* input data */
598         z80pio->input[channel] = z80pio_port_r(device, PIO_PORT_A);
599      }
600      else if (!z80pio->strobe[channel] && state) /* rising edge */
601      {
602         /* trigger interrupt */
603         z80pio_trigger_interrupt(device, channel);
587604
588            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
589         }
590         break;
605         /* clear ready line */
606         z80pio_ready_w(device, channel, 0);
591607      }
608      break;
592609   }
593   else
594   {
595      switch (z80pio->mode[channel])
596      {
597      case PIO_MODE_OUTPUT:
598         if (!z80pio->strobe[channel] && level) // rising edge
599         {
600            /* generate interrupt */
601            z80pio->irq_pending[channel] = 1;
602            z80pio_check_interrupt(device);
603610
604            /* clear ready line */
605            z80pio_set_ready_line(device, channel, 0);
611   /* latch strobe state */
612   z80pio->strobe[channel] = state;
613}
606614
607            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
608         }
609         break;
615static void z80pio_strobe(const device_config *device, int channel, int state)
616{
617   z80pio_t *z80pio = get_safe_token(device);
610618
611      case PIO_MODE_INPUT:
612         if (!level)
613         {
614            /* strobe data in */
615            z80pio_port_read(device, channel);
616         }
617         else if (!z80pio->strobe[channel] && level) // rising edge
618         {
619            /* generate interrupt */
620            z80pio->irq_pending[channel] = 1;
621            z80pio_check_interrupt(device);
619   switch (z80pio->mode[channel])
620   {
621   case PIO_MODE_OUTPUT:
622      if (!z80pio->strobe[channel] && state) /* rising edge */
623      {
624         /* trigger interrupt */
625         z80pio_trigger_interrupt(device, channel);
622626
623            /* clear ready line */
624            z80pio_set_ready_line(device, channel, 0);
627         /* clear ready line */
628         z80pio_ready_w(device, channel, 0);
629      }
630      break;
625631
626            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
627         }
628         break;
632   case PIO_MODE_INPUT:
633      if (!state) /* low level */
634      {
635         /* strobe data in */
636         z80pio->input[channel] = z80pio_port_r(device, channel);
637      }
638      else if (!z80pio->strobe[channel] && state) /* rising edge */
639      {
640         /* trigger interrupt */
641         z80pio_trigger_interrupt(device, channel);
629642
630      case PIO_MODE_CONTROL:
631         /* ignore strobes */
632         break;
643         /* clear ready line */
644         z80pio_ready_w(device, channel, 0);
633645      }
646      break;
647
648   case PIO_MODE_CONTROL:
649      /* ignore strobes */
650      break;
634651   }
635652
636   z80pio->strobe[channel] = level;
653   /* latch strobe state */
654   z80pio->strobe[channel] = state;
637655}
638656
639void z80pio_astb_w(const device_config *device, int level)
657static void z80pio_strobe_w(const device_config *device, int channel, int state)
640658{
641   z80pio_strobe(device, PIO_PORT_A, level);
659   z80pio_t *z80pio = get_safe_token(device);
660
661   LOGERROR("Z80PIO \"%s\" Port %c : Strobe %u\n", device->tag, 'A' + channel, state);
662
663   if (z80pio->mode[PIO_PORT_A] == PIO_MODE_BIDIRECTIONAL)
664   {
665      /* port A bidirectional mode */
666      z80pio_strobe_bidirectional(device, channel, state);
667   }
668   else
669   {
670      z80pio_strobe(device, channel, state);
671   }
642672}
643673
644void z80pio_bstb_w(const device_config *device, int level)
674void z80pio_astb_w(const device_config *device, int state)
645675{
646   z80pio_strobe(device, PIO_PORT_B, level);
676   z80pio_strobe_w(device, PIO_PORT_A, state);
647677}
648678
679void z80pio_bstb_w(const device_config *device, int state)
680{
681   z80pio_strobe_w(device, PIO_PORT_B, state);
682}
683
649684/***************************************************************************
650685    DAISY CHAIN INTERFACE
651686***************************************************************************/
r3449r3450
656691   int state = 0;
657692   int channel;
658693
659   if (LOG) logerror("Z80PIO \"%s\" IRQ STATE\n", device->tag);
660
661694   /* loop over all channels */
662695   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
663696   {
r3449r3450
671704      state |= z80pio->int_state[channel];
672705   }
673706
707   LOGERROR("Z80PIO \"%s\" : Interrupt State %u\n", device->tag, state);
708
674709   return state;
675710}
676711
r3449r3450
679714   z80pio_t *z80pio = get_safe_token( device );
680715   int channel;
681716
682   if (LOG) logerror("Z80PIO \"%s\" IRQ ACK\n", device->tag);
717   LOGERROR("Z80PIO \"%s\" Interrupt Acknowledge\n", device->tag);
683718
684719   /* loop over all channels */
685720   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
r3449r3450
695730      }
696731   }
697732
698   if (LOG) logerror("z80pio_irq_ack: failed to find an interrupt to ack!");
733   LOGERROR("z80pio_irq_ack: failed to find an interrupt to ack!");
699734
700735   return z80pio->vector[0];
701736}
r3449r3450
705740   z80pio_t *z80pio = get_safe_token( device );
706741   int channel;
707742
708   if (LOG) logerror("Z80PIO \"%s\" IRQ RETI\n", device->tag);
743   LOGERROR("Z80PIO \"%s\" Return from Interrupt\n", device->tag);
709744
710745   /* loop over all channels */
711746   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
r3449r3450
721756      }
722757   }
723758
724   if (LOG) logerror("z80pio_irq_reti: failed to find an interrupt to clear IEO on!");
759   LOGERROR("z80pio_irq_reti: failed to find an interrupt to clear IEO on!");
725760}
726761
727762/***************************************************************************
r3449r3450
789824      z80pio->clock = intf->clock;
790825   }
791826
792   /* allocate poll timers */
827   /* allocate poll timer */
793828
794829   z80pio->poll_timer = timer_alloc(z80pio_poll_tick, (void *)device);
795830   timer_adjust_periodic(z80pio->poll_timer, attotime_zero, 0, ATTOTIME_IN_HZ(z80pio->clock / 16));
796831
832   /* allocate interrupt enable timer */
833
834   z80pio->irq_timer = timer_alloc(z80pio_irq_tick, (void *)device);
835
797836   /* register for state saving */
798837
799838   state_save_combine_module_and_tag(unique_tag, "z80pio", device->tag);
r3449r3450
801840   state_save_register_item_array(unique_tag, 0, z80pio->state);
802841   state_save_register_item_array(unique_tag, 0, z80pio->mode);
803842   state_save_register_item_array(unique_tag, 0, z80pio->irq_enable);
804   state_save_register_item_array(unique_tag, 0, z80pio->irq_pending);
805843   state_save_register_item_array(unique_tag, 0, z80pio->int_state);
806844   state_save_register_item_array(unique_tag, 0, z80pio->enable);
807845   state_save_register_item_array(unique_tag, 0, z80pio->input);
r3449r3450
810848   state_save_register_item_array(unique_tag, 0, z80pio->mask);
811849   state_save_register_item_array(unique_tag, 0, z80pio->ddr);
812850   state_save_register_item_array(unique_tag, 0, z80pio->strobe);
851   state_save_register_item_array(unique_tag, 0, z80pio->match);
813852
814853   return DEVICE_START_OK;
815854}
r3449r3450
819858   z80pio_t *z80pio = get_safe_token(device);
820859   int channel;
821860
822   if (LOG) logerror("Z80PIO Reset\n");
861   LOGERROR("Z80PIO \"%s\" : Reset\n", device->tag);
823862
824863   for (channel = 0; channel < 2; channel++)
825864   {
r3449r3450
827866      z80pio->mask[channel] = 0xff;
828867
829868      /* clear ready line */
830      z80pio_set_ready_line(device, channel, 0);
869      z80pio_ready_w(device, channel, 0);
831870
832871      /* set mode 1 */
833872      z80pio->mode[channel] = PIO_MODE_INPUT;
r3449r3450
838877      /* reset interrupt */
839878      z80pio->enable[channel] &= 0x7f;
840879      z80pio->irq_enable[channel] = 0;
841      z80pio->irq_pending[channel] = 0;
842880      z80pio->int_state[channel] = 0;
881      z80pio->match[channel] = 0;
843882
844883      /* reset output register */
845884      z80pio->output[channel] = 0;
r3449r3450
882921      case DEVINFO_STR_CREDITS:                  info->s = "Copyright Nicola Salmoria and the MAME Team"; break;
883922   }
884923}
924
925DEVICE_GET_INFO( z8420 )
926{
927   switch (state)
928   {
929      /* --- the following bits of info are returned as NULL-terminated strings --- */
930      case DEVINFO_STR_NAME:                     info->s = "Zilog Z8420";            break;
931      case DEVINFO_STR_FAMILY:                  info->s = "Z80 PIO";               break;
932
933      default: DEVICE_GET_INFO_CALL(z80pio);
934   }
935}
936
937DEVICE_GET_INFO( lh0081 )
938{
939   switch (state)
940   {
941      /* --- the following bits of info are returned as NULL-terminated strings --- */
942      case DEVINFO_STR_NAME:                     info->s = "Sharp LH0081";            break;
943      case DEVINFO_STR_FAMILY:                  info->s = "Z80 PIO";               break;
944
945      default: DEVICE_GET_INFO_CALL(z80pio);
946   }
947}
948
949DEVICE_GET_INFO( mk3881 )
950{
951   switch (state)
952   {
953      /* --- the following bits of info are returned as NULL-terminated strings --- */
954      case DEVINFO_STR_NAME:                     info->s = "Mostek MK3881";            break;
955      case DEVINFO_STR_FAMILY:                  info->s = "Z80 PIO";               break;
956
957      default: DEVICE_GET_INFO_CALL(z80pio);
958   }
959}
src/emu/machine/z80pio.h
r3449r3450
11/***************************************************************************
22
3    Z80 PIO (Z8420) implementation
3    Z80 PIO Parallel Input/Output Controller emulation
44
55    Copyright Nicola Salmoria and the MAME Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
8***************************************************************************
8****************************************************************************
99                            _____   _____
1010                    D2   1 |*    \_/     | 40  D3
1111                    D7   2 |             | 39  D4
r3449r3450
9797READ8_DEVICE_HANDLER( z80pio_c_r );
9898WRITE8_DEVICE_HANDLER( z80pio_c_w );
9999
100READ8_DEVICE_HANDLER( lh0081_c_r );
101
100102/***************************************************************************
101103    DATA REGISTER READ/WRITE
102104***************************************************************************/
r3449r3450
132134#define Z80PIO DEVICE_GET_INFO_NAME(z80pio)
133135DEVICE_GET_INFO( z80pio );
134136
137#define Z8420 DEVICE_GET_INFO_NAME(z8420)
138DEVICE_GET_INFO( z8420 );
139
140#define LH0081 DEVICE_GET_INFO_NAME(lh0081)
141DEVICE_GET_INFO( lh0081 );
142
143#define MK3881 DEVICE_GET_INFO_NAME(mk3881)
144DEVICE_GET_INFO( mk3881 );
145
135146#endif

Previous 15994 Revisions Next


© 1998-2018 The MESS Team