Previous 15994 Revisions Next

r3343 Sunday 28th September, 2008 at 15:37:16 UTC by Wilbert Pol
Converted the z80pio implementation into a device.
[src/emu/machine]z80pio.c z80pio.h
[src/mess/drivers]abc80.c bbcbc.c einstein.c kc.c kramermc.c mbee.c mpf1.c super80.c
[src/mess/includes]kc.h kramermc.h mbee.h
[src/mess/machine]kc.c kramermc.c mbee.c

src/emu/machine/z80pio.c
r3342r3343
5858   UINT8 vector[2];                      /* interrupt vector               */
5959   void (*intr)(running_machine *, int which);            /* interrupt callbacks            */
6060   void (*rdyr[2])(int data);          /* RDY active callback            */
61   read8_machine_func  port_read[2];     /* port read callbacks            */
62   write8_machine_func port_write[2];    /* port write callbacks           */
61   read8_device_func  port_read[2];     /* port read callbacks            */
62   write8_device_func port_write[2];    /* port write callbacks           */
6363   UINT8 mode[2];                        /* mode 00=in,01=out,02=i/o,03=bit*/
6464   UINT8 enable[2];                      /* interrupt enable               */
6565   UINT8 mask[2];                        /* mask folowers                  */
r3342r3343
7070   UINT8 strobe[2];                  /* strobe inputs */
7171   UINT8 int_state[2];                   /* interrupt status (daisy chain) */
7272};
73typedef struct _z80pio z80pio;
73typedef struct _z80pio z80pio_t;
7474
7575
76
7776/***************************************************************************
78    GLOBAL VARIABLES
77    INLINE FUNCTIONS
7978***************************************************************************/
8079
81static z80pio pios[MAX_PIO];
80INLINE z80pio_t *get_safe_token(const device_config *device)
81{
82   assert(device != NULL);
83   assert(device->token != NULL);
84   assert(device->type == Z80PIO);
85   return (z80pio_t *)device->token;
86}
8287
8388
84
8589/***************************************************************************
8690    INTERNAL STATE MANAGEMENT
8791***************************************************************************/
8892
89static void   set_rdy(z80pio *pio, int ch, int state)
93INLINE void set_rdy(const device_config *device, int ch, int state)
9094{
95   z80pio_t *z80pio = get_safe_token( device );
9196   /* set state */
92   pio->rdy[ch] = state;
97   z80pio->rdy[ch] = state;
9398
9499   /* call callback with state */
95   if (pio->rdyr[ch])
96      (*pio->rdyr[ch])(pio->rdy[ch]);
100   if (z80pio->rdyr[ch])
101      z80pio->rdyr[ch](z80pio->rdy[ch]);
97102}
98103
99104
100static void interrupt_check(running_machine *machine, int which)
105INLINE void interrupt_check(const device_config *device)
101106{
102   z80pio *pio = pios + which;
107   z80pio_t *z80pio = get_safe_token( device );
103108
104109   /* if we have a callback, update it with the current state */
105   if (pio->intr)
106      (*pio->intr)(machine, (z80pio_irq_state(which) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
110   if (z80pio->intr)
111      z80pio->intr(device->machine, (z80pio_irq_state(device) & Z80_DAISY_INT) ? ASSERT_LINE : CLEAR_LINE);
107112}
108113
109114
110static void update_irq_state(running_machine *machine, z80pio *pio, int ch)
115static void update_irq_state(const device_config *device, int ch)
111116{
112   int old_state = pio->int_state[ch];
117   z80pio_t *z80pio = get_safe_token( device );
118   int old_state = z80pio->int_state[ch];
113119   int irq = 0;
114120   int data;
115   if (pio->mode[ch] == 0x13 || (pio->enable[ch] & PIO_INT_MASK)) return;
121   if (z80pio->mode[ch] == 0x13 || (z80pio->enable[ch] & PIO_INT_MASK)) return;
116122
117123   /* only check if interrupts are enabled */
118   if (pio->enable[ch] & PIO_INT_ENABLE)
124   if (z80pio->enable[ch] & PIO_INT_ENABLE)
119125   {
120126      /* in mode 3, interrupts are tricky */
121      if (pio->mode[ch] == PIO_MODE3)
127      if (z80pio->mode[ch] == PIO_MODE3)
122128      {
123129         /* fetch input data (ignore output lines) */
124         data = pio->in[ch] & pio->dir[ch];
130         data = z80pio->in[ch] & z80pio->dir[ch];
125131
126132         /* keep only relevant bits */
127         data &= ~pio->mask[ch];
133         data &= ~z80pio->mask[ch];
128134
129135         /* if active low, invert the bits */
130         if (!(pio->enable[ch] & PIO_INT_HIGH))
131            data ^= pio->mask[ch];
136         if (!(z80pio->enable[ch] & PIO_INT_HIGH))
137            data ^= z80pio->mask[ch];
132138
133139         /* if AND logic, interrupt if all bits are set */
134         if (pio->enable[ch] & PIO_INT_AND)
135            irq = (data == pio->mask[ch]);
140         if (z80pio->enable[ch] & PIO_INT_AND)
141            irq = (data == z80pio->mask[ch]);
136142
137143         /* otherwise, interrupt if at least one bit is set */
138144         else
139145            irq = (data != 0);
140146
141147         /* if portB, portA mode 2 check */
142         if (ch && (pio->mode[0] == PIO_MODE2))
148         if (ch && (z80pio->mode[0] == PIO_MODE2))
143149         {
144            if (pio->rdy[ch] == 0)
150            if (z80pio->rdy[ch] == 0)
145151               irq = 1;
146152         }
147153      }
148154
149155      /* otherwise, just interrupt when ready is cleared */
150156      else
151         irq = (pio->rdy[ch] == 0);
157         irq = (z80pio->rdy[ch] == 0);
152158   }
153159
154160   if (irq)
155      pio->int_state[ch] |=  Z80_DAISY_INT;
161      z80pio->int_state[ch] |=  Z80_DAISY_INT;
156162   else
157      pio->int_state[ch] &= ~Z80_DAISY_INT;
163      z80pio->int_state[ch] &= ~Z80_DAISY_INT;
158164
159   if (old_state != pio->int_state[ch])
160      interrupt_check(machine, pio - pios);
165   if (old_state != z80pio->int_state[ch])
166      interrupt_check(device);
161167}
162168
163169
164170
165171/***************************************************************************
166    INITIALIZATION/CONFIGURATION
172    CONTROL REGISTER READ/WRITE
167173***************************************************************************/
168174
169void z80pio_init(int which, const z80pio_interface *intf)
175WRITE8_DEVICE_HANDLER( z80pio_c_w )
170176{
171   z80pio *pio = pios + which;
177   z80pio_t *z80pio = get_safe_token( device );
172178
173   assert(which < MAX_PIO);
179   /* There are only 2 channels */
180   offset &= 0x01;
174181
175   memset(pio, 0, sizeof(*pio));
176
177   pio->intr = intf->intr;
178   pio->port_read[0] = intf->portAread;
179   pio->port_read[1] = intf->portBread;
180   pio->port_write[0] = intf->portAwrite;
181   pio->port_write[1] = intf->portBwrite;
182   pio->rdyr[0] = intf->rdyA;
183   pio->rdyr[1] = intf->rdyB;
184   z80pio_reset(which);
185
186    state_save_register_item_array("z80pio", which, pio->vector);
187    state_save_register_item_array("z80pio", which, pio->mode);
188    state_save_register_item_array("z80pio", which, pio->enable);
189    state_save_register_item_array("z80pio", which, pio->mask);
190    state_save_register_item_array("z80pio", which, pio->dir);
191    state_save_register_item_array("z80pio", which, pio->rdy);
192    state_save_register_item_array("z80pio", which, pio->in);
193    state_save_register_item_array("z80pio", which, pio->out);
194    state_save_register_item_array("z80pio", which, pio->strobe);
195    state_save_register_item_array("z80pio", which, pio->int_state);
196}
197
198
199void z80pio_reset(int which)
200{
201   z80pio *pio = pios + which;
202   int i;
203
204   for (i = 0; i < 2; i++)
205   {
206      pio->mask[i]   = 0xff;   /* mask all on */
207      pio->enable[i] = 0x00;   /* disable     */
208      pio->mode[i]   = 0x01;   /* mode input  */
209      pio->dir[i]    = 0x01;   /* dir  input  */
210      set_rdy(pio, i, 0);   /* RDY = low   */
211      pio->out[i]    = 0x00;   /* outdata = 0 */
212      pio->int_state[i] = 0;
213      pio->strobe[i] = 0;
214   }
215   interrupt_check(Machine, which);
216}
217
218
219
220/***************************************************************************
221    CONTROL REGISTER READ/WRITE
222***************************************************************************/
223
224void z80pio_c_w(running_machine *machine, int which, int ch, UINT8 data)
225{
226   z80pio *pio = pios + which;
227
228182   /* load direction phase ? */
229   if (pio->mode[ch] == 0x13)
183   if (z80pio->mode[offset] == 0x13)
230184   {
231      VPRINTF(("PIO-%c Bits %02x\n", 'A' + ch, data));
232      pio->dir[ch] = data;
233      pio->mode[ch] = 0x03;
185      VPRINTF(("PIO-%c Bits %02x\n", 'A' + offset, data));
186      z80pio->dir[offset] = data;
187      z80pio->mode[offset] = 0x03;
234188      return;
235189   }
236190
237191   /* load mask folows phase ? */
238   if (pio->enable[ch] & PIO_INT_MASK)
192   if (z80pio->enable[offset] & PIO_INT_MASK)
239193   {
240194      /* load mask folows */
241      pio->mask[ch] = data;
242      pio->enable[ch] &= ~PIO_INT_MASK;
243      VPRINTF(("PIO-%c interrupt mask %02x\n",'A'+ch,data ));
195      z80pio->mask[offset] = data;
196      z80pio->enable[offset] &= ~PIO_INT_MASK;
197      VPRINTF(("PIO-%c interrupt mask %02x\n",'A'+offset,data ));
244198      return;
245199   }
246200
247201   switch (data & 0x0f)
248202   {
249203      case PIO_OP_MODE:   /* mode select 0=out,1=in,2=i/o,3=bit */
250         pio->mode[ch] = (data >> 6);
251         VPRINTF(("PIO-%c Mode %x\n", 'A' + ch, pio->mode[ch]));
252         if (pio->mode[ch] == 0x03)
253            pio->mode[ch] = 0x13;
204         z80pio->mode[offset] = (data >> 6);
205         VPRINTF(("PIO-%c Mode %x\n", 'A' + offset, z80pio->mode[offset]));
206         if (z80pio->mode[offset] == 0x03)
207            z80pio->mode[offset] = 0x13;
254208         return;
255209
256210      case PIO_OP_INTC:      /* interrupt control */
257         pio->enable[ch] = data & 0xf0;
258         pio->mask[ch] = 0x00;
211         z80pio->enable[offset] = data & 0xf0;
212         z80pio->mask[offset] = 0x00;
259213         /* when interrupt enable , set vector request flag */
260         VPRINTF(("PIO-%c Controll %02x\n", 'A' + ch, data));
214         VPRINTF(("PIO-%c Controll %02x\n", 'A' + offset, data));
261215         break;
262216
263217      case PIO_OP_INTE:      /* interrupt enable controll */
264         pio->enable[ch] &= ~PIO_INT_ENABLE;
265         pio->enable[ch] |= (data & PIO_INT_ENABLE);
266         VPRINTF(("PIO-%c enable %02x\n", 'A' + ch, data & 0x80));
218         z80pio->enable[offset] &= ~PIO_INT_ENABLE;
219         z80pio->enable[offset] |= (data & PIO_INT_ENABLE);
220         VPRINTF(("PIO-%c enable %02x\n", 'A' + offset, data & 0x80));
267221         break;
268222
269223      default:
270224         if (!(data & 1))
271225         {
272            pio->vector[ch] = data;
273            VPRINTF(("PIO-%c vector %02x\n", 'A' + ch, data));
226            z80pio->vector[offset] = data;
227            VPRINTF(("PIO-%c vector %02x\n", 'A' + offset, data));
274228         }
275229         else
276            VPRINTF(("PIO-%c illegal command %02x\n", 'A' + ch, data));
230            VPRINTF(("PIO-%c illegal command %02x\n", 'A' + offset, data));
277231         break;
278232   }
279233
280234   /* interrupt check */
281   update_irq_state(machine, pio, ch);
235   update_irq_state(device, offset);
282236}
283237
284238
285UINT8 z80pio_c_r(int which, int ch)
239READ8_DEVICE_HANDLER( z80pio_c_r )
286240{
287   VPRINTF(("PIO-%c controll read\n", 'A' + ch ));
241   /* There are only 2 channels */
242   offset &= 0x01;
243
244   VPRINTF(("PIO-%c controll read\n", 'A' + offset ));
288245   return 0;
289246}
290247
r3342r3343
294251    DATA REGISTER READ/WRITE
295252***************************************************************************/
296253
297void z80pio_d_w(running_machine *machine, int which, int ch, UINT8 data)
254WRITE8_DEVICE_HANDLER( z80pio_d_w )
298255{
299   z80pio *pio = pios + which;
256   z80pio_t *z80pio = get_safe_token( device );
300257
301   pio->out[ch] = data;   /* latch out data */
302   if(pio->port_write[ch])
303      pio->port_write[ch](machine, 0, data);
258   /* There are only 2 channels */
259   offset &= 0x01;
304260
305   switch (pio->mode[ch])
261   z80pio->out[offset] = data;   /* latch out data */
262   if(z80pio->port_write[offset])
263      z80pio->port_write[offset](device, 0, data);
264
265   switch (z80pio->mode[offset])
306266   {
307267      case PIO_MODE0:         /* mode 0 output */
308268      case PIO_MODE2:         /* mode 2 i/o */
309         set_rdy(pio, ch, 1); /* ready = H */
310         update_irq_state(machine, pio, ch);
269         set_rdy(device, offset, 1); /* ready = H */
270         update_irq_state(device, offset);
311271         return;
312272
313273      case PIO_MODE1:         /* mode 1 input */
r3342r3343
315275         return;
316276
317277      default:
318         VPRINTF(("PIO-%c data write,bad mode\n",'A'+ch ));
278         VPRINTF(("PIO-%c data write,bad mode\n",'A'+offset ));
319279   }
320280}
321281
322282
323UINT8 z80pio_d_r(running_machine *machine, int which, int ch)
283READ8_DEVICE_HANDLER( z80pio_d_r )
324284{
325   z80pio *pio = pios + which;
285   z80pio_t *z80pio = get_safe_token( device );
326286
327   switch (pio->mode[ch])
287   /* There are only 2 channels */
288   offset &= 0x01;
289
290   switch (z80pio->mode[offset])
328291   {
329292      case PIO_MODE0:         /* mode 0 output */
330         return pio->out[ch];
293         return z80pio->out[offset];
331294
332295      case PIO_MODE1:         /* mode 1 input */
333         set_rdy(pio, ch, 1);   /* ready = H */
334         if(pio->port_read[ch])
335            pio->in[ch] = pio->port_read[ch](machine, 0);
336         update_irq_state(machine, pio, ch);
337         return pio->in[ch];
296         set_rdy(device, offset, 1);   /* ready = H */
297         if(z80pio->port_read[offset])
298            z80pio->in[offset] = z80pio->port_read[offset](device, 0);
299         update_irq_state(device, offset);
300         return z80pio->in[offset];
338301
339302      case PIO_MODE2:         /* mode 2 i/o */
340         if (ch) VPRINTF(("PIO-B mode 2 \n"));
341         set_rdy(pio, 1, 1); /* brdy = H */
342         if(pio->port_read[ch])
343            pio->in[ch] = pio->port_read[ch](machine, 0);
344         update_irq_state(machine, pio, ch);
345         return pio->in[ch];
303         if (offset) VPRINTF(("PIO-B mode 2 \n"));
304         set_rdy(device, 1, 1); /* brdy = H */
305         if(z80pio->port_read[offset])
306            z80pio->in[offset] = z80pio->port_read[offset](device, 0);
307         update_irq_state(device, offset);
308         return z80pio->in[offset];
346309
347310      case PIO_MODE3:         /* mode 3 bit */
348         if(pio->port_read[ch])
349            pio->in[ch] = pio->port_read[ch](machine, 0);
350         return (pio->in[ch] & pio->dir[ch]) | (pio->out[ch] & ~pio->dir[ch]);
311         if(z80pio->port_read[offset])
312            z80pio->in[offset] = z80pio->port_read[offset](device, 0);
313         return (z80pio->in[offset] & z80pio->dir[offset]) | (z80pio->out[offset] & ~z80pio->dir[offset]);
351314   }
352   VPRINTF(("PIO-%c data read,bad mode\n",'A'+ch ));
315   VPRINTF(("PIO-%c data read,bad mode\n",'A'+offset ));
353316   return 0;
354317}
355318
r3342r3343
359322    PORT I/O
360323***************************************************************************/
361324
362void z80pio_p_w(running_machine *machine, int which, UINT8 ch, UINT8 data)
325WRITE8_DEVICE_HANDLER( z80pio_p_w )
363326{
364   z80pio *pio = pios + which;
327   z80pio_t *z80pio = get_safe_token( device );
365328
366   pio->in[ch]  = data;
367   switch (pio->mode[ch])
329   /* There are only 2 channels */
330   offset &= 0x01;
331
332   z80pio->in[offset]  = data;
333   switch (z80pio->mode[offset])
368334   {
369335      case PIO_MODE0:
370         VPRINTF(("PIO-%c OUTPUT mode and data write\n",'A'+ch ));
336         VPRINTF(("PIO-%c OUTPUT mode and data write\n",'A'+offset ));
371337         break;
372338
373339      case PIO_MODE2:   /* only port A */
374         ch = 1;      /* handshake and IRQ is use portB */
340         offset = 1;      /* handshake and IRQ is use portB */
375341
376342      case PIO_MODE1:
377         set_rdy(pio, ch, 0);
378         update_irq_state(machine, pio, ch);
343         set_rdy(device, offset, 0);
344         update_irq_state(device, offset);
379345         break;
380346
381347      case PIO_MODE3:
382348         /* irq check */
383         update_irq_state(machine, pio, ch);
349         update_irq_state(device, offset);
384350         break;
385351   }
386352}
387353
388354
389int z80pio_p_r(running_machine *machine, int which, UINT8 ch)
355READ8_DEVICE_HANDLER( z80pio_p_r )
390356{
391   z80pio *pio = pios + which;
357   z80pio_t *z80pio = get_safe_token( device );
392358
393   switch (pio->mode[ch])
359   /* There are only 2 channels */
360   offset &= 0x01;
361
362   switch (z80pio->mode[offset])
394363   {
395364      case PIO_MODE2:      /* port A only */
396365      case PIO_MODE0:
397         set_rdy(pio, ch, 0);
398         update_irq_state(machine, pio, ch);
366         set_rdy(device, offset, 0);
367         update_irq_state(device, offset);
399368         break;
400369
401370      case PIO_MODE1:
402         VPRINTF(("PIO-%c INPUT mode and data read\n",'A'+ch ));
371         VPRINTF(("PIO-%c INPUT mode and data read\n",'A'+offset ));
403372         break;
404373
405374      case PIO_MODE3:
406         return (pio->in[ch] & pio->dir[ch]) | (pio->out[ch] & ~pio->dir[ch]);
375         return (z80pio->in[offset] & z80pio->dir[offset]) | (z80pio->out[offset] & ~z80pio->dir[offset]);
407376   }
408   return pio->out[ch];
377   return z80pio->out[offset];
409378}
410379
411380
412WRITE8_HANDLER( z80pioA_0_p_w ) { z80pio_p_w(machine, 0, 0, data);   }
413WRITE8_HANDLER( z80pioB_0_p_w ) { z80pio_p_w(machine, 0, 1, data);   }
414READ8_HANDLER( z80pioA_0_p_r )  { return z80pio_p_r(machine, 0, 0);  }
415READ8_HANDLER( z80pioB_0_p_r )  { return z80pio_p_r(machine, 0, 1);  }
416
417WRITE8_HANDLER( z80pioA_1_p_w ) { z80pio_p_w(machine, 1, 0, data);   }
418WRITE8_HANDLER( z80pioB_1_p_w ) { z80pio_p_w(machine, 1, 1, data);   }
419READ8_HANDLER( z80pioA_1_p_r )  { return z80pio_p_r(machine, 1, 0);  }
420READ8_HANDLER( z80pioB_1_p_r )  { return z80pio_p_r(machine, 1, 1);  }
421
422
423
424381/***************************************************************************
425382    STROBE STATE MANAGEMENT
426383***************************************************************************/
427384
428static void z80pio_update_strobe(running_machine *machine, int which, int ch, int state)
385static void z80pio_update_strobe(const device_config *device, int ch, int state)
429386{
430   z80pio *pio = pios + which;
387   z80pio_t *z80pio = get_safe_token( device );
431388
432   switch (pio->mode[ch])
389   switch (z80pio->mode[ch])
433390   {
434391      /* output mode: a positive edge is used by peripheral to acknowledge
435392            the receipt of data */
r3342r3343
439396         state = state & 0x01;
440397
441398         /* strobe changed state? */
442         if ((pio->strobe[ch] ^ state) != 0)
399         if ((z80pio->strobe[ch] ^ state) != 0)
443400         {
444401            /* yes */
445402            if (state != 0)
r3342r3343
448405               VPRINTF(("PIO-%c positive strobe\n",'A' + ch));
449406
450407               /* ready is now inactive */
451               set_rdy(pio, ch, 0);
408               set_rdy(device, ch, 0);
452409
453410               /* int enabled? */
454               if (pio->enable[ch] & PIO_INT_ENABLE)
411               if (z80pio->enable[ch] & PIO_INT_ENABLE)
455412               {
456413                  /* trigger an int request */
457                  pio->int_state[ch] |= Z80_DAISY_INT;
414                  z80pio->int_state[ch] |= Z80_DAISY_INT;
458415               }
459416            }
460417         }
461418
462419         /* store strobe state */
463         pio->strobe[ch] = state;
420         z80pio->strobe[ch] = state;
464421
465422         /* check interrupt */
466         interrupt_check(machine, which);
423         interrupt_check(device);
467424      }
468425      break;
469426
r3342r3343
476433}
477434
478435
479void z80pio_astb_w(running_machine *machine, int which, int state) { z80pio_update_strobe(machine, which, 0, state); }
480void z80pio_bstb_w(running_machine *machine, int which, int state) { z80pio_update_strobe(machine, which, 1, state); }
436void z80pio_astb_w(const device_config *device, int state) { z80pio_update_strobe(device, 0, state); }
437void z80pio_bstb_w(const device_config *device, int state) { z80pio_update_strobe(device, 1, state); }
481438
482439
483440
r3342r3343
485442    DAISY CHAIN INTERFACE
486443***************************************************************************/
487444
488int z80pio_irq_state(int which)
445int z80pio_irq_state(const device_config *device)
489446{
490   z80pio *pio = pios + which;
447   z80pio_t *z80pio = get_safe_token( device );
491448   int state = 0;
492449   int ch;
493450
r3342r3343
495452   for (ch = 0; ch < 2; ch++)
496453   {
497454      /* if we're servicing a request, don't indicate more interrupts */
498      if (pio->int_state[ch] & Z80_DAISY_IEO)
455      if (z80pio->int_state[ch] & Z80_DAISY_IEO)
499456      {
500457         state |= Z80_DAISY_IEO;
501458         break;
502459      }
503      state |= pio->int_state[ch];
460      state |= z80pio->int_state[ch];
504461   }
505462   return state;
506463}
507464
508465
509int z80pio_irq_ack(int which)
466int z80pio_irq_ack(const device_config *device)
510467{
511   z80pio *pio = pios + which;
468   z80pio_t *z80pio = get_safe_token( device );
512469   int ch;
513470
514471   /* loop over all channels */
515472   for (ch = 0; ch < 2; ch++)
516473
517474      /* find the first channel with an interrupt requested */
518      if (pio->int_state[ch] & Z80_DAISY_INT)
475      if (z80pio->int_state[ch] & Z80_DAISY_INT)
519476      {
520477         /* clear interrupt, switch to the IEO state, and update the IRQs */
521         pio->int_state[ch] = Z80_DAISY_IEO;
522         interrupt_check(Machine, which);
523         return pio->vector[ch];
478         z80pio->int_state[ch] = Z80_DAISY_IEO;
479         interrupt_check(device);
480         return z80pio->vector[ch];
524481      }
525482
526483   VPRINTF(("z80pio_irq_ack: failed to find an interrupt to ack!"));
527   return pio->vector[0];
484   return z80pio->vector[0];
528485}
529486
530487
531void z80pio_irq_reti(int which)
488void z80pio_irq_reti(const device_config *device)
532489{
533   z80pio *pio = pios + which;
490   z80pio_t *z80pio = get_safe_token( device );
534491   int ch;
535492
536493   /* loop over all channels */
537494   for (ch = 0; ch < 2; ch++)
538495
539496      /* find the first channel with an IEO pending */
540      if (pio->int_state[ch] & Z80_DAISY_IEO)
497      if (z80pio->int_state[ch] & Z80_DAISY_IEO)
541498      {
542499         /* clear the IEO state and update the IRQs */
543         pio->int_state[ch] &= ~Z80_DAISY_IEO;
544         interrupt_check(Machine, which);
500         z80pio->int_state[ch] &= ~Z80_DAISY_IEO;
501         interrupt_check(device);
545502         return;
546503      }
547504
548505   VPRINTF(("z80pio_irq_reti: failed to find an interrupt to clear IEO on!"));
549506}
550507
508
551509/***************************************************************************
552510    READ/WRITE HANDLERS
553511***************************************************************************/
554READ8_HANDLER(z80pio_0_r)
512READ8_DEVICE_HANDLER(z80pio_r)
555513{
556   return (offset & 2) ? z80pio_c_r(0, offset & 1) : z80pio_d_r(machine, 0, offset & 1);
514   return (offset & 2) ? z80pio_c_r(device, offset & 1) : z80pio_d_r(device, offset & 1);
557515}
558516
559WRITE8_HANDLER(z80pio_0_w)
517WRITE8_DEVICE_HANDLER(z80pio_w)
560518{
561519   if (offset & 2)
562      z80pio_c_w(machine, 0, offset & 1, data);
520      z80pio_c_w(device, offset & 1, data);
563521   else
564      z80pio_d_w(machine, 0, offset & 1, data);
522      z80pio_d_w(device, offset & 1, data);
565523}
566524
567READ8_HANDLER(z80pio_1_r)
525
526static DEVICE_START( z80pio )
568527{
569   return (offset & 2) ? z80pio_c_r(1, offset & 1) : z80pio_d_r(machine, 1, offset & 1);
528   const z80pio_interface *intf = device->static_config;
529   z80pio_t *z80pio = get_safe_token( device );
530   char unique_tag[30];
531
532   z80pio->intr = intf->intr;
533   z80pio->port_read[0] = intf->portAread;
534   z80pio->port_read[1] = intf->portBread;
535   z80pio->port_write[0] = intf->portAwrite;
536   z80pio->port_write[1] = intf->portBwrite;
537   z80pio->rdyr[0] = intf->rdyA;
538   z80pio->rdyr[1] = intf->rdyB;
539
540   /* register for save states */
541   state_save_combine_module_and_tag(unique_tag, "z80pio", device->tag);
542
543   state_save_register_item_array(unique_tag, 0, z80pio->vector);
544   state_save_register_item_array(unique_tag, 0, z80pio->mode);
545   state_save_register_item_array(unique_tag, 0, z80pio->enable);
546   state_save_register_item_array(unique_tag, 0, z80pio->mask);
547   state_save_register_item_array(unique_tag, 0, z80pio->dir);
548   state_save_register_item_array(unique_tag, 0, z80pio->rdy);
549   state_save_register_item_array(unique_tag, 0, z80pio->in);
550   state_save_register_item_array(unique_tag, 0, z80pio->out);
551   state_save_register_item_array(unique_tag, 0, z80pio->strobe);
552   state_save_register_item_array(unique_tag, 0, z80pio->int_state);
553
554   return DEVICE_START_OK;
570555}
571556
572WRITE8_HANDLER(z80pio_1_w)
557
558void z80pio_reset( const device_config *device )
573559{
574   if (offset & 2)
575      z80pio_c_w(machine, 1, offset & 1, data);
576   else
577      z80pio_d_w(machine, 1, offset & 1, data);
560   z80pio_t   *z80pio = get_safe_token( device );
561   int i;
562
563   for (i = 0; i < 2; i++)
564   {
565      z80pio->mask[i]   = 0xff;   /* mask all on */
566      z80pio->enable[i] = 0x00;   /* disable     */
567      z80pio->mode[i]   = 0x01;   /* mode input  */
568      z80pio->dir[i]    = 0x01;   /* dir  input  */
569      set_rdy(device, i, 0);   /* RDY = low   */
570      z80pio->out[i]    = 0x00;   /* outdata = 0 */
571      z80pio->int_state[i] = 0;
572      z80pio->strobe[i] = 0;
573   }
574   interrupt_check(device);
578575}
576
577
578static DEVICE_RESET( z80pio )
579{
580   z80pio_reset( device );
581}
582
583
584static DEVICE_SET_INFO( z80pio )
585{
586   switch (state)
587   {
588      /* no parameters to set */
589   }
590}
591
592
593DEVICE_GET_INFO( z80pio )
594{
595   switch (state)
596   {
597      /* --- the following bits of info are returned as 64-bit signed integers --- */
598      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(z80pio_t);            break;
599      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                     break;
600      case DEVINFO_INT_CLASS:                     info->i = DEVICE_CLASS_PERIPHERAL;      break;
601
602      /* --- the following bits of info are returned as pointers to data or functions --- */
603      case DEVINFO_FCT_SET_INFO:                  info->set_info = DEVICE_SET_INFO_NAME(z80pio); break;
604      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(z80pio);break;
605      case DEVINFO_FCT_STOP:                     /* Nothing */                     break;
606      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(z80pio);break;
607
608      /* --- the following bits of info are returned as NULL-terminated strings --- */
609      case DEVINFO_STR_NAME:                     info->s = "Zilog Z80PIO";            break;
610      case DEVINFO_STR_FAMILY:                  info->s = "Z80PIO";                  break;
611      case DEVINFO_STR_VERSION:                  info->s = "1.0";                  break;
612      case DEVINFO_STR_SOURCE_FILE:               info->s = __FILE__;                  break;
613      case DEVINFO_STR_CREDITS:                  info->s = "Copyright Nicola Salmoria and the MAME Team"; break;
614   }
615}
616
src/emu/machine/z80pio.h
r3342r3343
77
88***************************************************************************/
99
10/***************************************************************************
11    CONSTANTS
12***************************************************************************/
10#ifndef __Z80PIO_H_
11#define __Z80PIO_H_
1312
14#define MAX_PIO 2
1513
16
17
1814/***************************************************************************
1915    TYPE DEFINITIONS
2016***************************************************************************/
r3342r3343
2218struct _z80pio_interface
2319{
2420   void (*intr)(running_machine *machine, int which);    /* callback when change interrupt status */
25   read8_machine_func portAread;    /* port A read callback */
26   read8_machine_func portBread;    /* port B read callback */
27   write8_machine_func portAwrite;  /* port A write callback */
28   write8_machine_func portBwrite;  /* port B write callback */
21   read8_device_func portAread;    /* port A read callback */
22   read8_device_func portBread;    /* port B read callback */
23   write8_device_func portAwrite;  /* port A write callback */
24   write8_device_func portBwrite;  /* port B write callback */
2925   void (*rdyA)(int data);     /* portA ready active callback (do not support yet)*/
3026   void (*rdyB)(int data);     /* portB ready active callback (do not support yet)*/
3127};
3228typedef struct _z80pio_interface z80pio_interface;
3329
3430
35
3631/***************************************************************************
37    INITIALIZATION/CONFIGURATION
32    DEVICE CONFIGURATION MACROS
3833***************************************************************************/
3934
40void z80pio_init(int which, const z80pio_interface *intf);
41void z80pio_reset(int which);
35#define MDRV_Z80PIO_ADD(_tag, _intrf) \
36   MDRV_DEVICE_ADD(_tag, Z80PIO) \
37   MDRV_DEVICE_CONFIG(_intrf)
4238
39#define MDRV_Z80PIO_REMOVE(_tag) \
40   MDRV_DEVICE_REMOVE(_tag, Z80PIO)
4341
4442
43
4544/***************************************************************************
45    INITIALIZATION
46***************************************************************************/
47
48void z80pio_reset( const device_config *device );
49
50
51/***************************************************************************
4652    CONTROL REGISTER READ/WRITE
4753***************************************************************************/
4854
49void z80pio_c_w(running_machine *machine, int which, int ch, UINT8 data);
50UINT8 z80pio_c_r(int which, int ch);
55WRITE8_DEVICE_HANDLER( z80pio_c_w );
56READ8_DEVICE_HANDLER( z80pio_c_r );
5157
5258
53
5459/***************************************************************************
5560    DATA REGISTER READ/WRITE
5661***************************************************************************/
5762
58void z80pio_d_w(running_machine *machine, int which, int ch, UINT8 data);
59UINT8 z80pio_d_r(running_machine *machine, int which, int ch);
63WRITE8_DEVICE_HANDLER( z80pio_d_w );
64READ8_DEVICE_HANDLER( z80pio_d_r );
6065
6166
62
6367/***************************************************************************
6468    PORT I/O
6569***************************************************************************/
6670
67void z80pio_p_w(running_machine *machine, int which, UINT8 ch, UINT8 data);
68int z80pio_p_r(running_machine *machine, int which, UINT8 ch);
71WRITE8_DEVICE_HANDLER( z80pio_p_w );
72READ8_DEVICE_HANDLER( z80pio_p_r );
6973
70WRITE8_HANDLER( z80pioA_0_p_w );
71WRITE8_HANDLER( z80pioB_0_p_w );
72READ8_HANDLER( z80pioA_0_p_r );
73READ8_HANDLER( z80pioB_0_p_r );
74WRITE8_HANDLER( z80pioA_1_p_w );
75WRITE8_HANDLER( z80pioB_1_p_w );
76READ8_HANDLER( z80pioA_1_p_r );
77READ8_HANDLER( z80pioB_1_p_r );
7874
79
80
8175/***************************************************************************
8276    STROBE STATE MANAGEMENT
8377***************************************************************************/
8478
85void z80pio_astb_w(running_machine *machine, int which, int state);
86void z80pio_bstb_w(running_machine *machine, int which, int state);
79void z80pio_astb_w(const device_config *device, int state);
80void z80pio_bstb_w(const device_config *device, int state);
8781
8882
89
9083/***************************************************************************
9184    DAISY CHAIN INTERFACE
9285***************************************************************************/
9386
94int z80pio_irq_state(int which);
95int z80pio_irq_ack(int which);
96void z80pio_irq_reti(int which);
87int z80pio_irq_state(const device_config *device);
88int z80pio_irq_ack(const device_config *device);
89void z80pio_irq_reti(const device_config *device);
9790
91
9892/***************************************************************************
9993    READ/WRITE HANDLERS
10094***************************************************************************/
101READ8_HANDLER(z80pio_0_r);
102WRITE8_HANDLER(z80pio_0_w);
103READ8_HANDLER(z80pio_1_r);
104WRITE8_HANDLER(z80pio_1_w);
95READ8_DEVICE_HANDLER(z80pio_r);
96WRITE8_DEVICE_HANDLER(z80pio_w);
97
98
99/* ----- device interface ----- */
100
101#define Z80PIO DEVICE_GET_INFO_NAME(z80pio)
102DEVICE_GET_INFO( z80pio );
103
104#endif
src/mess/includes/kc.h
r3342r3343
77#ifndef KC_H_
88#define KC_H_
99
10#include "cpu/z80/z80daisy.h"
11#include "machine/z80pio.h"
1012#include "devices/snapquik.h"
1113
1214
r3342r3343
6870READ8_HANDLER(kc85_ctc_r);
6971WRITE8_HANDLER(kc85_ctc_w);
7072
73extern const z80pio_interface kc85_pio_intf;
74extern const struct z80_irq_daisy_chain kc85_daisy_chain[];
7175
76
7277/*** MODULE SYSTEM ***/
7378/* read from xx80 port */
7479READ8_HANDLER(kc85_module_r);
src/mess/includes/mbee.h
r3342r3343
77#ifndef MBEE_H_
88#define MBEE_H_
99
10#include "cpu/z80/z80daisy.h"
1011
1112/*----------- defined in machine/mbee.c -----------*/
1213
r3342r3343
1415MACHINE_START( mbee );
1516
1617extern UINT8 *mbee_workram;
18extern const struct z80_irq_daisy_chain mbee_daisy_chain[];
1719
1820INTERRUPT_GEN( mbee_interrupt );
1921
src/mess/includes/kramermc.h
r3342r3343
77#ifndef KRAMERMC_H_
88#define KRAMERMC_H_
99
10#include "machine/z80pio.h"
1011
1112/*----------- defined in machine/kramermc.c -----------*/
1213
13extern DRIVER_INIT( kramermc );
14extern MACHINE_RESET( kramermc );
14DRIVER_INIT( kramermc );
15MACHINE_RESET( kramermc );
1516
17const z80pio_interface kramermc_z80pio_intf;
18
1619/*----------- defined in video/kramermc.c -----------*/
1720
1821extern const gfx_layout kramermc_charlayout;
1922
20extern VIDEO_START( kramermc );
21extern VIDEO_UPDATE( kramermc );
23VIDEO_START( kramermc );
24VIDEO_UPDATE( kramermc );
2225
2326
2427#endif /* KRAMERMC_h_ */
src/mess/machine/mbee.c
r3342r3343
2929static UINT8 fdc_head = 0;
3030static UINT8 fdc_den = 0;
3131static UINT8 fdc_status = 0;
32static void pio_interrupt(running_machine *machine, int state);
32static const device_config *mbee_z80pio;
3333static void mbee_fdc_callback(running_machine *machine, wd17xx_state_t event, void *param);
3434
3535UINT8 *mbee_workram;
3636
37static const z80pio_interface pio_intf =
37
38static void mbee_z80pio_reset(int which)
3839{
39   pio_interrupt,   /* callback when change interrupt status */
40   NULL,
41   NULL,
42   NULL,
43   NULL,
44   0,            /* portA ready active callback (do not support yet)*/
45   0            /* portB ready active callback (do not support yet)*/
46};
40   z80pio_reset( mbee_z80pio );
41}
4742
48static void pio_interrupt(running_machine *machine, int state)
43static int mbee_z80pio_irq_state(int which)
4944{
50   cpunum_set_input_line(machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE);
45   return z80pio_irq_state( mbee_z80pio );
5146}
5247
48static int mbee_z80pio_irq_ack(int which)
49{
50   return z80pio_irq_ack( mbee_z80pio );
51}
52
53static void mbee_z80pio_irq_reti(int which)
54{
55   z80pio_irq_reti( mbee_z80pio );
56}
57
58const struct z80_irq_daisy_chain mbee_daisy_chain[] =
59{
60   { mbee_z80pio_reset, mbee_z80pio_irq_state, mbee_z80pio_irq_ack, mbee_z80pio_irq_reti, 0 }, /* PIO number 0 */
61   { 0, 0, 0, 0, -1}      /* end mark */
62};
63
64
5365/*
5466  On reset or power on, a circuit forces rom 8000-8FFF to appear at 0000-0FFF, while ram is disabled.
5567  It gets set back to normal on the first attempt to write to memory. (/WR line goes active).
r3342r3343
6476
6577MACHINE_RESET( mbee )
6678{
67   z80pio_init(0, &pio_intf);
79   mbee_z80pio = device_list_find_by_tag( machine->config->devicelist, Z80PIO, "z80pio" );
6880   timer_set(ATTOTIME_IN_USEC(4), NULL, 0, mbee_reset);
6981   memory_set_bank(1, 1);
7082}
r3342r3343
92104READ8_HANDLER ( mbee_pio_r )
93105{
94106   UINT8 data=0;
95   if (offset == 0) return z80pio_d_r(machine,0,0);
96   if (offset == 1) return z80pio_c_r(0,0);
97   if (offset == 3) return z80pio_c_r(0,1);
98   data = z80pio_d_r(machine,0,1) | 1;
107   if (offset == 0) return z80pio_d_r(mbee_z80pio,0);
108   if (offset == 1) return z80pio_c_r(mbee_z80pio,0);
109   if (offset == 3) return z80pio_c_r(mbee_z80pio,1);
110   data = z80pio_d_r(mbee_z80pio,1) | 1;
99111   if (cassette_input(cassette_device_image(machine)) > 0.03)
100112      data &= ~1;
101113   return data;
r3342r3343
103115
104116WRITE8_HANDLER ( mbee_pio_w )
105117{
106   if (offset == 0) z80pio_d_w(machine, 0,0,data);
107   if (offset == 1) z80pio_c_w(machine, 0,0,data);
108   if (offset == 3) z80pio_c_w(machine, 0,1,data);
118   if (offset == 0) z80pio_d_w(mbee_z80pio,0,data);
119   if (offset == 1) z80pio_c_w(mbee_z80pio,0,data);
120   if (offset == 3) z80pio_c_w(mbee_z80pio,1,data);
109121
110122   if( offset == 2 )
111123   {
112      z80pio_d_w(machine, 0,1,data);
113      data = z80pio_p_r(machine,0,1);
124      z80pio_d_w(mbee_z80pio,1,data);
125      data = z80pio_p_r(mbee_z80pio,1);
114126      cassette_output(cassette_device_image(machine), (data & 0x02) ? -1.0 : +1.0);
115127      speaker_level_w(0, (data & 0x40) ? 1 : 0);
116128   }
r3342r3343
171183INTERRUPT_GEN( mbee_interrupt )
172184{
173185   /* once per frame, pulse the PIO B bit 7 */
174   z80pio_p_w(machine, 0, 1, 0x80);
175   z80pio_p_w(machine, 0, 1, 0x00);
186   z80pio_p_w(mbee_z80pio, 1, 0x80);
187   z80pio_p_w(mbee_z80pio, 1, 0x00);
176188}
177189
178190DEVICE_IMAGE_LOAD( mbee_cart )
src/mess/machine/kramermc.c
r3342r3343
1313
1414UINT8 kramermc_key_row;
1515
16READ8_HANDLER (kramermc_port_a_r)
16READ8_DEVICE_HANDLER (kramermc_port_a_r)
1717{
1818   return 0xff;
1919}
2020
21READ8_HANDLER (kramermc_port_b_r)
21READ8_DEVICE_HANDLER (kramermc_port_b_r)
2222{
2323   static const char *keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7" };
2424
25   return input_port_read(machine, keynames[kramermc_key_row]);
25   return input_port_read(device->machine, keynames[kramermc_key_row]);
2626}
2727
28WRITE8_HANDLER (kramermc_port_a_w)
28WRITE8_DEVICE_HANDLER (kramermc_port_a_w)
2929{
3030   kramermc_key_row = ((data >> 1) & 0x07);
3131}
3232
33static const z80pio_interface pio_intf =
33const z80pio_interface kramermc_z80pio_intf =
3434{
3535   NULL,   /* callback when change interrupt status */
3636   kramermc_port_a_r,
r3342r3343
4949MACHINE_RESET( kramermc )
5050{
5151   kramermc_key_row = 0;
52   z80pio_init(0, &pio_intf);
5352}
src/mess/machine/kc.c
r3342r3343
1919#define LOG(x) do { if (KC_DEBUG) logerror x; } while (0)
2020
2121static int kc85_pio_data[2];
22static const device_config *kc85_z80pio;
2223
2324static void kc85_4_update_0x0c000(running_machine *machine);
2425static void kc85_4_update_0x0e000(running_machine *machine);
r3342r3343
410411      bit = 1;
411412
412413   /* update astb with bit */
413   z80pio_astb_w(machine,0,bit & kc_ardy);
414   z80pio_astb_w(kc85_z80pio,bit & kc_ardy);
414415}
415416
416417static void   kc_cassette_init(void)
r3342r3343
865866      LOG_KBD(("kc keyboard sending pulse: %02x\n",pulse_state));
866867
867868      /* set pulse */
868      z80pio_bstb_w(machine,0,pulse_state & kc_brdy);
869      z80pio_bstb_w(kc85_z80pio,pulse_state & kc_brdy);
869870
870871      /* update counts */
871872      keyboard_data.transmit_pulse_count_remaining--;
r3342r3343
920921   keyboard_data.transmit_pulse_count = 0;
921922
922923   /* set initial state */
923   z80pio_bstb_w(machine,0,0);
924   z80pio_bstb_w(kc85_z80pio,0);
924925
925926
926927   for (i=0; i<KC_KEYBOARD_NUM_LINES-1; i++)
r3342r3343
13771378WRITE8_HANDLER ( kc85_4_pio_data_w )
13781379{
13791380   kc85_pio_data[offset] = data;
1380   z80pio_d_w(machine, 0, offset, data);
1381   z80pio_d_w(kc85_z80pio, offset, data);
13811382
13821383   switch (offset)
13831384   {
r3342r3343
16191620WRITE8_HANDLER ( kc85_3_pio_data_w )
16201621{
16211622   kc85_pio_data[offset] = data;
1622   z80pio_d_w(machine, 0, offset, data);
1623   z80pio_d_w(kc85_z80pio, offset, data);
16231624
16241625   switch (offset)
16251626   {
r3342r3343
16931694
16941695 READ8_HANDLER ( kc85_pio_data_r )
16951696{
1696   return z80pio_d_r(machine,0,offset);
1697   return z80pio_d_r(kc85_z80pio,offset);
16971698}
16981699
16991700 READ8_HANDLER ( kc85_pio_control_r )
17001701{
1701   return z80pio_c_r(0,offset);
1702   return z80pio_c_r(kc85_z80pio,offset);
17021703}
17031704
17041705
17051706
17061707WRITE8_HANDLER ( kc85_pio_control_w )
17071708{
1708   z80pio_c_w(machine, 0, offset, data);
1709   z80pio_c_w(kc85_z80pio, offset, data);
17091710}
17101711
17111712
r3342r3343
17601761   }
17611762}
17621763
1763static const z80pio_interface kc85_pio_intf =
1764const z80pio_interface kc85_pio_intf =
17641765{
17651766   kc85_pio_interrupt,      /* callback when change interrupt status */
17661767   NULL,
r3342r3343
17711772   kc85_pio_brdy_callback   /* portB ready active callback */
17721773};
17731774
1775static void kc85_z80pio_reset(int which)
1776{
1777   z80pio_reset(kc85_z80pio);
1778}
1779
1780/* pio is last in chain and therefore has highest priority */
1781
1782const struct z80_irq_daisy_chain kc85_daisy_chain[] =
1783{
1784   {kc85_z80pio_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
1785   {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
1786   {0,0,0,0,-1}
1787};
1788
17741789/* used in cassette write -> K0 */
17751790static WRITE8_HANDLER(kc85_zc0_callback)
17761791{
r3342r3343
18331848
18341849static void   kc85_common_init(running_machine *machine)
18351850{
1836   z80pio_init(0, &kc85_pio_intf);
18371851   z80ctc_init(0, &kc85_ctc_intf);
18381852
18391853   z80ctc_reset(0);
1840   z80pio_reset(0);
18411854
18421855   kc_cassette_init();
18431856   kc_keyboard_init(machine);
r3342r3343
18651878   kc85_pio_data[0] = 0x0f;
18661879   kc85_pio_data[1] = 0x0f1;
18671880
1881   kc85_z80pio = device_list_find_by_tag( machine->config->devicelist, Z80PIO, "z80pio" );
1882
18681883   kc85_4_update_0x04000(machine);
18691884   kc85_4_update_0x08000(machine);
18701885   kc85_4_update_0x0c000(machine);
src/mess/drivers/mbee.c
r3342r3343
279279         colortable_entry_set_value(machine->colortable, (((i<<5)|r)<<1)|1, r|64);
280280}
281281
282static const struct z80_irq_daisy_chain mbee_daisy_chain[] =
282
283static void pio_interrupt(running_machine *machine, int state)
283284{
284   { z80pio_reset, z80pio_irq_state, z80pio_irq_ack, z80pio_irq_reti, 0 }, /* PIO number 0 */
285   { 0, 0, 0, 0, -1}      /* end mark */
285   cpunum_set_input_line(machine, 0, 0, state ? ASSERT_LINE : CLEAR_LINE);
286}
287
288static const z80pio_interface mbee_z80pio_intf =
289{
290   pio_interrupt,   /* callback when change interrupt status */
291   NULL,
292   NULL,
293   NULL,
294   NULL,
295   0,            /* portA ready active callback (do not support yet)*/
296   0            /* portB ready active callback (do not support yet)*/
286297};
287298
288299
r3342r3343
297308
298309   MDRV_MACHINE_RESET( mbee )
299310
311   MDRV_Z80PIO_ADD( "z80pio", mbee_z80pio_intf )
312
300313   MDRV_GFXDECODE(mbee)
301314   MDRV_SCREEN_ADD("main", RASTER)
302315   MDRV_SCREEN_REFRESH_RATE(50)
r3342r3343
336349   MDRV_MACHINE_RESET( mbee )
337350   MDRV_MACHINE_START( mbee )
338351
352   MDRV_Z80PIO_ADD( "z80pio", mbee_z80pio_intf )
353
339354   MDRV_GFXDECODE(mbeeic)
340355   MDRV_SCREEN_ADD("main", RASTER)
341356   MDRV_SCREEN_REFRESH_RATE(50)
src/mess/drivers/abc80.c
r3342r3343
9191#include "devices/printer.h"
9292
9393static emu_timer *abc80_keyboard_timer;
94static const device_config *abc80_z80pio;
9495
9596static const device_config *cassette_device_image(running_machine *machine)
9697{
r3342r3343
207208   }
208209
209210   if (keycode)
210      z80pio_p_w( machine, 0, 0, keycode | 0x80 );
211      z80pio_p_w( abc80_z80pio, 0, keycode | 0x80 );
211212   else
212      z80pio_p_w( machine, 0, 0, 0 );
213      z80pio_p_w( abc80_z80pio, 0, 0 );
213214
214215   if (keycode != keylatch) program_write_byte(0xfdf5, 0x80);
215216
216217   keylatch = keycode;
217218}
218219
219// PIO
220220
221static READ8_HANDLER( abc80_pio_r )
222{
223   switch (offset)
224   {
225   case 0:
226      return z80pio_d_r(machine, 0, 0);
227   case 1:
228      return z80pio_c_r(0, 0);
229   case 2:
230      return z80pio_d_r(machine, 0, 1);
231   case 3:
232      return z80pio_c_r(0, 1);
233   }
234
235   return 0xff;
236}
237
238static WRITE8_HANDLER( abc80_pio_w )
239{
240   switch (offset)
241   {
242   case 0:
243      z80pio_d_w(machine, 0, 0, data);
244      break;
245   case 1:
246      z80pio_c_w(machine, 0, 0, data);
247      break;
248   case 2:
249      z80pio_d_w(machine, 0, 1, data);
250      break;
251   case 3:
252      z80pio_c_w(machine, 0, 1, data);
253      break;
254   }
255}
256
257221/* Memory Maps */
258222
259223static ADDRESS_MAP_START( abc80_map, ADDRESS_SPACE_PROGRAM, 8 )
r3342r3343
275239   AM_RANGE(0x02, 0x05) AM_WRITE(abcbus_command_w)
276240   AM_RANGE(0x06, 0x06) AM_WRITE(abc80_sound_w)
277241   AM_RANGE(0x07, 0x07) AM_READ(abcbus_reset_r)
278   AM_RANGE(0x38, 0x3b) AM_READWRITE(abc80_pio_r, abc80_pio_w)
242   AM_RANGE(0x38, 0x3b) AM_DEVREADWRITE( Z80PIO, "z80pio", z80pio_r, z80pio_w)
279243ADDRESS_MAP_END
280244
281245/* Input Ports */
r3342r3343
413377
414378/* Machine Initialization */
415379
380static void abc80_z80pio_reset(int which)
381{
382   z80pio_reset( abc80_z80pio );
383}
384
385static int abc80_z80pio_irq_state(int which)
386{
387   return z80pio_irq_state( abc80_z80pio );
388}
389
390static int abc80_z80pio_irq_ack(int which)
391{
392   return z80pio_irq_ack( abc80_z80pio );
393}
394
395static void abc80_z80pio_irq_reti(int which)
396{
397   z80pio_irq_reti( abc80_z80pio );
398}
399
416400static const struct z80_irq_daisy_chain abc80_daisy_chain[] =
417401{
418   { z80pio_reset, z80pio_irq_state, z80pio_irq_ack, z80pio_irq_reti, 0 },
402   { abc80_z80pio_reset, abc80_z80pio_irq_state, abc80_z80pio_irq_ack, abc80_z80pio_irq_reti, 0 },
419403   { 0, 0, 0, 0, -1 }
420404};
421405
r3342r3343
451435}
452436#endif
453437
454static READ8_HANDLER( abc80_pio_port_b_r )
438static READ8_DEVICE_HANDLER( abc80_pio_port_b_r )
455439{
456440   /*
457441
r3342r3343
468452
469453   */
470454
471   UINT8 data = (cassette_input(cassette_device_image(machine)) > +1.0) ? 0x80 : 0;
455   UINT8 data = (cassette_input(cassette_device_image(device->machine)) > +1.0) ? 0x80 : 0;
472456
473457   return data;
474458};
475459
476static WRITE8_HANDLER( abc80_pio_port_b_w )
460static WRITE8_DEVICE_HANDLER( abc80_pio_port_b_w )
477461{
478462   /*
479463
r3342r3343
490474
491475   */
492476
493   cassette_change_state(cassette_device_image(machine), BIT(data, 5) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
477   cassette_change_state(cassette_device_image(device->machine), BIT(data, 5) ? CASSETTE_MOTOR_ENABLED : CASSETTE_MOTOR_DISABLED, CASSETTE_MASK_MOTOR);
494478
495   cassette_output(cassette_device_image(machine), BIT(data, 7) ? -1.0 : +1.0);
479   cassette_output(cassette_device_image(device->machine), BIT(data, 7) ? -1.0 : +1.0);
496480};
497481
498482static const z80pio_interface abc80_pio_intf =
r3342r3343
524508      break;
525509   }
526510
511   abc80_z80pio = device_list_find_by_tag( machine->config->devicelist, Z80PIO, "z80pio" );
512
527513   /* register for state saving */
528514
529515   state_save_register_global(keylatch);
530516
531   /* initialize the PIO */
532
533   z80pio_init(0, &abc80_pio_intf);
534
535517   /* allocate the keyboard scan timer */
536518
537519   abc80_keyboard_timer = timer_alloc(abc80_keyboard_tick, NULL);
r3342r3343
552534
553535   MDRV_MACHINE_START(abc80)
554536
537   MDRV_Z80PIO_ADD( "z80pio", abc80_pio_intf )
538
555539   // video hardware
556540
557541   MDRV_SCREEN_ADD("main", RASTER)
src/mess/drivers/kramermc.c
r3342r3343
3131
3232static ADDRESS_MAP_START( kramermc_io, ADDRESS_SPACE_IO, 8 )
3333   ADDRESS_MAP_GLOBAL_MASK(0xff)
34   AM_RANGE(0xfc, 0x0ff) AM_READWRITE(z80pio_0_r, z80pio_0_w)
34   AM_RANGE(0xfc, 0x0ff) AM_DEVREADWRITE(Z80PIO, "z80pio", z80pio_r, z80pio_w)
3535ADDRESS_MAP_END
3636
3737/* Input ports */
r3342r3343
105105
106106/* Machine driver */
107107static MACHINE_DRIVER_START( kramermc )
108  /* basic machine hardware */
109  MDRV_CPU_ADD("main", Z80, 1500000)
110  MDRV_CPU_PROGRAM_MAP(kramermc_mem, 0)
111  MDRV_CPU_IO_MAP(kramermc_io, 0)
112  MDRV_MACHINE_RESET( kramermc )
108   /* basic machine hardware */
109   MDRV_CPU_ADD("main", Z80, 1500000)
110   MDRV_CPU_PROGRAM_MAP(kramermc_mem, 0)
111   MDRV_CPU_IO_MAP(kramermc_io, 0)
112   MDRV_MACHINE_RESET( kramermc )
113113
114  /* video hardware */
114   MDRV_Z80PIO_ADD( "z80pio", kramermc_z80pio_intf )
115
116   /* video hardware */
115117   MDRV_SCREEN_ADD("main", RASTER)
116118   MDRV_SCREEN_REFRESH_RATE(50)
117119   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
r3342r3343
123125   MDRV_PALETTE_LENGTH(2)
124126   MDRV_PALETTE_INIT(black_and_white)
125127
126  MDRV_VIDEO_START(kramermc)
127  MDRV_VIDEO_UPDATE(kramermc)
128   MDRV_VIDEO_START(kramermc)
129   MDRV_VIDEO_UPDATE(kramermc)
128130MACHINE_DRIVER_END
129131
130132/* ROM definition */
131133ROM_START( kramermc )
132  ROM_REGION( 0x10000, "main", ROMREGION_ERASEFF )
133  ROM_LOAD( "io-mon.kmc",   0x0000, 0x0400, CRC(ba230fc8) SHA1(197d4ede31ee8768dd4a17854ee21c468e98b3d6) )
134  ROM_LOAD( "debugger.kmc", 0x0400, 0x0400, CRC(5ea3d9e1) SHA1(42e5ced4f965124ae50ec7ac9861d6b668cfab99) )
135  ROM_LOAD( "reass.kmc",    0x0800, 0x0400, CRC(7cc8e605) SHA1(3319a96aad710441af30dace906b9725e07ca92c) )
136  ROM_LOAD( "basic.kmc",  0x8000, 0x3000, CRC(7531801e) SHA1(61d055495ffcc4a281ef0abc3e299ea95f42544b) )
137  ROM_LOAD( "editor.kmc", 0xc000, 0x0400, CRC(2fd4cb84) SHA1(505615a218865aa8becde13848a23e1241a14b96) )
138  ROM_LOAD( "ass.kmc",      0xc400, 0x1c00, CRC(9a09422e) SHA1(a578d2cf0ea6eb35dcd13e4107e15187de906097) )
134   ROM_REGION( 0x10000, "main", ROMREGION_ERASEFF )
135   ROM_LOAD( "io-mon.kmc",   0x0000, 0x0400, CRC(ba230fc8) SHA1(197d4ede31ee8768dd4a17854ee21c468e98b3d6) )
136   ROM_LOAD( "debugger.kmc", 0x0400, 0x0400, CRC(5ea3d9e1) SHA1(42e5ced4f965124ae50ec7ac9861d6b668cfab99) )
137   ROM_LOAD( "reass.kmc",    0x0800, 0x0400, CRC(7cc8e605) SHA1(3319a96aad710441af30dace906b9725e07ca92c) )
138   ROM_LOAD( "basic.kmc",  0x8000, 0x3000, CRC(7531801e) SHA1(61d055495ffcc4a281ef0abc3e299ea95f42544b) )
139   ROM_LOAD( "editor.kmc", 0xc000, 0x0400, CRC(2fd4cb84) SHA1(505615a218865aa8becde13848a23e1241a14b96) )
140   ROM_LOAD( "ass.kmc",      0xc400, 0x1c00, CRC(9a09422e) SHA1(a578d2cf0ea6eb35dcd13e4107e15187de906097) )
139141   ROM_REGION(0x0800, "gfx1",0)
140142   ROM_LOAD ("chargen.kmc", 0x0000, 0x0800, CRC(1ba52f9f) SHA1(71bbad90dd427d0132c871a4d3848ab3d4d84b8a))
141143ROM_END
src/mess/drivers/mpf1.c
r3342r3343
521521
522522static MACHINE_RESET( mpf1 )
523523{
524   // PIO
525   z80pio_init(0, &pio_intf);
526   z80pio_reset(0);
527
528524   // CTC
529525/*  z80ctc_init(&ctc_intf);
530526    z80ctc_reset(0);*/
r3342r3343
547543
548544   MDRV_MACHINE_RESET( mpf1 )
549545
546   MDRV_Z80PIO_ADD( "z80pio", pio_intf )
547
550548   MDRV_DEVICE_ADD( "ppi8255", PPI8255 )
551549   MDRV_DEVICE_CONFIG( ppi8255_intf )
552550
src/mess/drivers/super80.c
r3342r3343
1616static UINT8 current_palette;   /* for super80m and super80v */
1717static UINT8 current_charset;   /* for super80m */
1818
19static const device_config *super80_z80pio;
20
1921/* the rest are for super80v */
2022static UINT8 *pcgram;
2123static UINT8 framecnt = 0;
r3342r3343
357359};
358360
359361
362static void super80_z80pio_reset(int which)
363{
364   z80pio_reset( super80_z80pio );
365}
366
367static int super80_z80pio_irq_state(int which)
368{
369   return z80pio_irq_state( super80_z80pio );
370}
371
372static int super80_z80pio_irq_ack(int which)
373{
374   return z80pio_irq_ack( super80_z80pio );
375}
376
377static void super80_z80pio_irq_reti(int which)
378{
379   z80pio_irq_reti( super80_z80pio );
380}
381
360382static const struct z80_irq_daisy_chain super80_daisy_chain[] =
361383{
362   { z80pio_reset, z80pio_irq_state, z80pio_irq_ack, z80pio_irq_reti, 0 },
384   { super80_z80pio_reset, super80_z80pio_irq_state, super80_z80pio_irq_ack, super80_z80pio_irq_reti, 0 },
363385   { 0, 0, 0, 0, -1}      /* end mark */
364386};
365387
r3342r3343
401423
402424static TIMER_CALLBACK( super80_timer )
403425{
404   UINT8 cass_ws=0, i, mask=1, out_f8=z80pio_p_r(machine,0,0), in_fa=255;
426   UINT8 cass_ws=0, i, mask=1, out_f8=z80pio_p_r(super80_z80pio,0), in_fa=255;
405427   static const char *keynames[] = { "LINE0", "LINE1", "LINE2", "LINE3", "LINE4", "LINE5", "LINE6", "LINE7" };
406428
407429   for ( i=0; i < 8;i++)
r3342r3343
410432      mask<<=1;
411433   }
412434
413   z80pio_p_w(machine,0,1,in_fa);
435   z80pio_p_w(super80_z80pio,1,in_fa);
414436
415437   cass_data[1]++;
416438   cass_ws = (cassette_input(cassette_device_image(machine)) > +0.03) ? 4 : 0;
r3342r3343
501523   current_charset = data & 1;
502524}
503525
504static READ8_HANDLER( super80_f8_r ) { return z80pio_d_r (machine,0,0); }
505static READ8_HANDLER( super80_f9_r ) { return z80pio_c_r (0,0); }
506static READ8_HANDLER( super80_fa_r ) { return z80pio_d_r (machine,0,1); }
507static READ8_HANDLER( super80_fb_r ) { return z80pio_c_r (0,1); }
508static WRITE8_HANDLER( super80_f8_w ) { z80pio_d_w(machine, 0,0, data); }
509static WRITE8_HANDLER( super80_f9_w ) { z80pio_c_w(machine, 0,0, data); }
510static WRITE8_HANDLER( super80_fa_w ) { z80pio_d_w(machine, 0,1, data); }
511static WRITE8_HANDLER( super80_fb_w ) { z80pio_c_w(machine, 0,1, data); }
526static READ8_HANDLER( super80_f8_r ) { return z80pio_d_r (super80_z80pio,0); }
527static READ8_HANDLER( super80_f9_r ) { return z80pio_c_r (super80_z80pio,0); }
528static READ8_HANDLER( super80_fa_r ) { return z80pio_d_r (super80_z80pio,1); }
529static READ8_HANDLER( super80_fb_r ) { return z80pio_c_r (super80_z80pio,1); }
530static WRITE8_HANDLER( super80_f8_w ) { z80pio_d_w(super80_z80pio,0, data); }
531static WRITE8_HANDLER( super80_f9_w ) { z80pio_c_w(super80_z80pio,0, data); }
532static WRITE8_HANDLER( super80_fa_w ) { z80pio_d_w(super80_z80pio,1, data); }
533static WRITE8_HANDLER( super80_fb_w ) { z80pio_c_w(super80_z80pio,1, data); }
512534
513535/**************************** MEMORY AND I/O MAPPINGS *****************************************************************/
514536
r3342r3343
921943
922944static MACHINE_RESET( super80 )
923945{
924   z80pio_init(0, &pio_intf);
946   super80_z80pio = device_list_find_by_tag( machine->config->devicelist, Z80PIO, "z80pio" );
925947   timer_set(ATTOTIME_IN_USEC(10), NULL, 0, super80_reset);
926948   memory_set_bank(1, 1);
927949}
r3342r3343
942964
943965   MDRV_MACHINE_RESET( super80 )
944966
967   MDRV_Z80PIO_ADD( "z80pio", pio_intf )
968
945969   MDRV_GFXDECODE(super80)
946970   MDRV_SCREEN_ADD("main", RASTER)
947971   MDRV_SCREEN_REFRESH_RATE(48.8)
src/mess/drivers/einstein.c
r3342r3343
108108
109109static int einstein_ctc_trigger = 0;
110110
111static const device_config *einstein_z80pio;
112
111113/* KEYBOARD */
112114static int einstein_keyboard_line = 0;
113115static int einstein_keyboard_data = 0x0ff;
r3342r3343
527529}
528530#endif
529531
532static void einstein_z80pio_reset(int which)
533{
534   z80pio_reset( einstein_z80pio );
535}
536
537static int einstein_z80pio_irq_state(int which)
538{
539   return z80pio_irq_state( einstein_z80pio );
540}
541
542static int einstein_z80pio_irq_ack(int which)
543{
544   return z80pio_irq_ack( einstein_z80pio );
545}
546
547static void einstein_z80pio_irq_reti(int which)
548{
549   z80pio_irq_reti( einstein_z80pio );
550}
551
530552static const struct z80_irq_daisy_chain einstein_daisy_chain[] =
531553{
532554   {einstein_keyboard_int_reset, einstein_keyboard_interrupt, 0, einstein_keyboard_reti, 0},
533555    {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
534556   {einstein_adc_int_reset,einstein_adc_interrupt, 0, einstein_adc_reti, 0},
535   {z80pio_reset, z80pio_irq_state, z80pio_irq_ack, z80pio_irq_reti, 0},
557   {einstein_z80pio_reset, einstein_z80pio_irq_state, einstein_z80pio_irq_ack, einstein_z80pio_irq_reti, 0},
536558//  {einstein_fire_int_reset,einstein_fire_interrupt, einstein_fire_reti, 0},
537559    {0,0,0,0,-1}
538560};
r3342r3343
637659{
638660   logerror("pio w: %04x %02x\n",offset,data);
639661
640   if ((offset & 0x01)==0)
662   if ( ( offset & 0x03 ) == 0x02 )
641663   {
642      switch ((offset>>1) & 0x01)
643      {
644         /* port A */
645         case 0:
646         {
647            /* printer is connected to port A */
648            centronics_write_data(0,data);
649         }
650         break;
651
652         default:
653            break;
654      }
655
656      z80pio_d_w( machine, 0, (offset>>1) & 0x01,data);
657      return;
664      /* printer is connected to port A */
665      centronics_write_data(0,data);
658666   }
659667
660   z80pio_c_w( machine, 0, (offset>>1) & 0x01,data);
668   z80pio_w( einstein_z80pio, offset, data );
661669}
662670
663671static  READ8_HANDLER(einstein_pio_r)
664672{
665673   logerror("pio r: %04x\n",offset);
666674
667   if ((offset & 0x01)==0)
668   {
669      return z80pio_d_r( machine, 0, (offset>>1) & 0x01);
670   }
671
672   return z80pio_c_r( 0, (offset>>1) & 0x01);
675   return z80pio_r( einstein_z80pio, offset );
673676}
674677
675678static  READ8_HANDLER(einstein_ctc_r)
r3342r3343
13681371      if (data & CENTRONICS_ACKNOWLEDGE)
13691372      {
13701373         /* /ack into /astb */
1371         z80pio_astb_w(Machine, 0, 0);
1374         z80pio_astb_w( einstein_z80pio, 0);
13721375      }
13731376      else
13741377      {
1375         z80pio_astb_w(Machine, 0, 1);
1378         z80pio_astb_w( einstein_z80pio, 1);
13761379      }
13771380   }
13781381}
r3342r3343
14251428{
14261429   TMS9928A_configure(&tms9928a_interface);
14271430   wd17xx_init(machine, WD_TYPE_177X, NULL, NULL);
1431
1432   einstein_z80pio = device_list_find_by_tag( machine->config->devicelist, Z80PIO, "z80pio" );
14281433}
14291434
14301435static MACHINE_RESET( einstein )
r3342r3343
14341439   memory_set_bankptr(4, mess_ram+0x02000);
14351440
14361441   z80ctc_init(0, &einstein_ctc_intf);
1437   z80pio_init(0, &einstein_pio_intf);
14381442   msm8251_init(&einstein_msm8251_intf);
14391443
14401444   z80ctc_reset(0);
1441   z80pio_reset(0);
14421445
14431446   TMS9928A_reset ();
14441447
r3342r3343
17271730   MDRV_MACHINE_START( einstein )
17281731   MDRV_MACHINE_RESET( einstein )
17291732
1733   MDRV_Z80PIO_ADD( "z80pio", einstein_pio_intf )
1734
17301735    /* video hardware */
17311736   MDRV_IMPORT_FROM(tms9928a)
17321737   MDRV_SCREEN_MODIFY("main")
src/mess/drivers/bbcbc.c
r3342r3343
2222
2323static ADDRESS_MAP_START( bbcbc_io, ADDRESS_SPACE_IO, 8 )
2424   ADDRESS_MAP_GLOBAL_MASK(0xff)
25   AM_RANGE(0x40, 0x40) AM_READWRITE(z80pioA_0_p_r, z80pioA_0_p_w)
25   AM_RANGE(0x40, 0x40) AM_DEVREADWRITE(Z80PIO, "z80pio", z80pio_p_r, z80pio_p_w)
2626   AM_RANGE(0x80, 0x80) AM_READWRITE(TMS9928A_vram_r, TMS9928A_vram_w)
2727   AM_RANGE(0x81, 0x81) AM_READWRITE(TMS9928A_register_r, TMS9928A_register_w)
2828ADDRESS_MAP_END
r3342r3343
4646};
4747
4848/* TODO */
49static const z80pio_interface pio_intf =
49static const z80pio_interface bbcbc_z80pio_intf =
5050{
5151   NULL,
5252   NULL,
r3342r3343
7575   MDRV_MACHINE_START( bbcbc )
7676   MDRV_MACHINE_RESET( bbcbc )
7777
78   MDRV_Z80PIO_ADD( "z80pio", bbcbc_z80pio_intf )
79
7880   MDRV_CPU_VBLANK_INT("main", bbcbc_interrupt)
7981   MDRV_IMPORT_FROM( tms9928a )
8082   MDRV_SCREEN_MODIFY("main")
src/mess/drivers/kc.c
r3342r3343
2828#include "devices/basicdsk.h"
2929
3030
31/* pio is last in chain and therefore has highest priority */
32
33static const struct z80_irq_daisy_chain kc85_daisy_chain[] =
34{
35   {z80pio_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
36   {z80ctc_reset, z80ctc_irq_state, z80ctc_irq_ack, z80ctc_irq_reti, 0},
37   {0,0,0,0,-1}
38};
39
4031static READ8_HANDLER(kc85_4_port_r)
4132{
4233   int port;
r3342r3343
347338
348339   MDRV_MACHINE_RESET( kc85_3 )
349340
341   MDRV_Z80PIO_ADD( "z80pio", kc85_pio_intf )
342
350343   /* video hardware */
351344   MDRV_SCREEN_ADD("main", RASTER)
352345   MDRV_SCREEN_REFRESH_RATE(50)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team