Previous 15994 Revisions Next

r3448 Monday 13th October, 2008 at 17:02:08 UTC by Curt Coder
[Z80PIO] Cleanup.
[src/emu/machine]z80pio.c z80pio.h
[src/mess/drivers]abc80.c mbee.c

src/emu/machine/z80pio.c
r3447r3448
7474   UINT8 mask[PIO_PORT_COUNT];            /* mask register */
7575   UINT8 ddr[PIO_PORT_COUNT];            /* input/output select register */
7676   int strobe[PIO_PORT_COUNT];            /* strobe pulse */
77   int match[PIO_PORT_COUNT];            /* mode 3 match equation match */
7877
7978   /* timers */
8079   emu_timer *poll_timer;               /* mode 3 poll timer */
r3447r3448
116115      {
117116         if (z80pio->irq_pending[channel])
118117         {
119            if (LOG) logerror("Z80PIO Port %c Interrupt Request\n", 'A' + channel);
118            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Request\n", device->tag, 'A' + channel);
120119
121120            /* request interrupt */
122121            z80pio->irq_pending[channel] = 0;
r3447r3448
141140{
142141   z80pio_t *z80pio = get_safe_token(device);
143142
144   if (LOG) logerror("Z80PIO Port %c Ready %u\n", 'A' + channel, level);
143   if (LOG) logerror("Z80PIO \"%s\" Port %c Ready %u\n", device->tag, 'A' + channel, level);
145144
146145   if (channel == PIO_PORT_A)
147146   {
r3447r3448
179178      }
180179   }
181180
182   //if (LOG) logerror("Z80PIO Port %c Read Data %02x\n", 'A' + channel, data);
181   //if (LOG) logerror("Z80PIO \"%s\" Port %c Read Data %02x\n", device->tag, 'A' + channel, data);
183182
184183   z80pio->input[channel] = data;
185184}
r3447r3448
210209      }
211210   }
212211
213   if (LOG) logerror("Z80PIO Port %c Write Data %02x\n", 'A' + channel, data);
212   if (LOG) logerror("Z80PIO \"%s\" Port %c Write Data %02x\n", device->tag, 'A' + channel, data);
214213}
215214
216215static void z80pio_set_mode(const device_config *device, int channel, int mode)
217216{
218217   z80pio_t *z80pio = get_safe_token(device);
219218
220   if (LOG) logerror("Z80PIO Port %c Mode %u\n", 'A' + channel, mode);
219   if (LOG) logerror("Z80PIO \"%s\" Port %c Mode %u\n", device->tag, 'A' + channel, mode);
221220
222221   /* clear interrupt */
223222   z80pio->irq_enable[channel] = 0;
224223   z80pio->irq_pending[channel] = 0;
225224   z80pio->int_state[channel] = 0;
226   z80pio->match[channel] = 0;
227225
228226   z80pio_check_interrupt(device);
229227
r3447r3448
284282         /* load interrupt vector */
285283         z80pio->vector[channel] = data & 0xfe;
286284
287         if (LOG) logerror("Z80PIO Port %c Interrupt Vector %02x\n", 'A' + channel, z80pio->vector[channel]);
285         if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Vector %02x\n", device->tag, 'A' + channel, z80pio->vector[channel]);
288286      }
287      else if ((data & 0x0f) == 0x03)
288      {
289         /* set interrupt enable */
290         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));
295      }
289296      else if ((data & 0x0f) == 0x0f)
290297      {
291298         /* select operating mode */
r3447r3448
319326
320327         z80pio_check_interrupt(device);
321328
322         if (LOG) logerror("Z80PIO Port %c Interrupt Control %02x\n", 'A' + channel, data);
329         if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Control %02x\n", device->tag, 'A' + channel, data);
323330      }
324331      break;
325332
326
327333   case PIO_STATE_DDR:
328334      /* set data direction */
329335      z80pio->ddr[channel] = data;
330      z80pio->match[channel] = 0;
331336
332337      /* set interrupt enable */
333338      z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7);
r3447r3448
335340
336341      z80pio->state[channel] = PIO_STATE_NORMAL;
337342
338      if (LOG) logerror("Z80PIO Port %c Direction %02x\n", 'A' + channel, data);
343      if (LOG) logerror("Z80PIO \"%s\" Port %c Direction %02x\n", device->tag, 'A' + channel, data);
339344      break;
340345
341346   case PIO_STATE_MASK:
342347      /* set interrupt mask */
343348      z80pio->mask[channel] = data;
344      z80pio->match[channel] = 0;
345349
346350      /* set interrupt enable */
347351      z80pio->irq_enable[channel] = BIT(z80pio->enable[channel], 7);
r3447r3448
349353
350354      z80pio->state[channel] = PIO_STATE_NORMAL;
351355
352      if (LOG) logerror("Z80PIO Port %c Mask %02x\n", 'A' + channel, data);
356      if (LOG) logerror("Z80PIO \"%s\" Port %c Mask %02x\n", device->tag, 'A' + channel, data);
353357      break;
354358   }
355359}
r3447r3448
391395      break;
392396
393397   case PIO_MODE_CONTROL:
398      z80pio_port_read(device, channel);
394399      data = (z80pio->input[channel] & z80pio->ddr[channel]) | (z80pio->output[channel] & (~z80pio->ddr[channel]));
395400      break;
396401   }
397402
398   if (LOG) logerror("Z80PIO Port %c Data Register Read %02x\n", 'A' + channel, data);
403   if (LOG) logerror("Z80PIO \"%s\" Port %c Data Register Read %02x\n", device->tag, 'A' + channel, data);
399404
400405   return data;
401406}
r3447r3448
405410   z80pio_t *z80pio = get_safe_token( device );
406411   int channel = offset & 0x01;
407412
408   if (LOG) logerror("Z80PIO Port %c Data Register Write %02x\n", 'A' + channel, data);
413   if (LOG) logerror("Z80PIO \"%s\" Port %c Data Register Write %02x\n", device->tag, 'A' + channel, data);
409414
410415   switch (z80pio->mode[channel])
411416   {
r3447r3448
485490               {
486491                  if (!BIT(old_data, bit) && BIT(data, bit)) // rising edge
487492                  {
493                     if (LOG) logerror("Z80PIO \"%s\" Port %c Rising Edge detected on bit %u\n", device->tag, 'A' + channel, bit);
494
488495                     match = 1;
489496
490497                     if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR
r3447r3448
505512               {
506513                  if (BIT(old_data, bit) && !BIT(data, bit)) // falling edge
507514                  {
515                     if (LOG) logerror("Z80PIO \"%s\" Port %c Falling Edge detected on bit %u\n", device->tag, 'A' + channel, bit);
516
508517                     match = 1;
509518
510519                     if (!(z80pio->enable[channel] & PIO_IRQ_AND_OR)) // OR
r3447r3448
529538            /* trigger interrupt */
530539            z80pio->irq_pending[channel] = 1;
531540
532            if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel);
541            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
533542
534543            z80pio_check_interrupt(device);
535544         }
r3447r3448
545554{
546555   z80pio_t *z80pio = get_safe_token(device);
547556
548   if (LOG) logerror("Z80PIO Port %c Strobe %u\n", 'A' + channel, level);
557   if (LOG) logerror("Z80PIO \"%s\" Port %c Strobe %u\n", device->tag, 'A' + channel, level);
549558
550559   if (z80pio->mode[PIO_PORT_A] == PIO_MODE_BIDIRECTIONAL)
551560   {
r3447r3448
576585            /* clear ready line */
577586            z80pio_set_ready_line(device, channel, 0);
578587
579            if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel);
588            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
580589         }
581590         break;
582591      }
r3447r3448
595604            /* clear ready line */
596605            z80pio_set_ready_line(device, channel, 0);
597606
598            if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel);
607            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
599608         }
600609         break;
601610
r3447r3448
614623            /* clear ready line */
615624            z80pio_set_ready_line(device, channel, 0);
616625
617            if (LOG) logerror("Z80PIO Port %c Interrupt Pending\n", 'A' + channel);
626            if (LOG) logerror("Z80PIO \"%s\" Port %c Interrupt Pending\n", device->tag, 'A' + channel);
618627         }
619628         break;
620629
r3447r3448
647656   int state = 0;
648657   int channel;
649658
650   if (LOG) logerror("Z80PIO IRQ STATE\n");
659   if (LOG) logerror("Z80PIO \"%s\" IRQ STATE\n", device->tag);
651660
652661   /* loop over all channels */
653662   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
r3447r3448
670679   z80pio_t *z80pio = get_safe_token( device );
671680   int channel;
672681
673   if (LOG) logerror("Z80PIO IRQ ACK\n");
682   if (LOG) logerror("Z80PIO \"%s\" IRQ ACK\n", device->tag);
674683
675684   /* loop over all channels */
676685   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
r3447r3448
696705   z80pio_t *z80pio = get_safe_token( device );
697706   int channel;
698707
699   if (LOG) logerror("Z80PIO IRQ RETI\n");
708   if (LOG) logerror("Z80PIO \"%s\" IRQ RETI\n", device->tag);
700709
701710   /* loop over all channels */
702711   for (channel = PIO_PORT_A; channel < PIO_PORT_COUNT; channel++)
r3447r3448
732741      z80pio_d_w(device, offset & 1, data);
733742}
734743
744READ8_DEVICE_HANDLER(z80pio_alt_r)
745{
746   int channel = BIT(offset, 1);
747
748   return (offset & 1) ? z80pio_c_r(device, channel) : z80pio_d_r(device, channel);
749}
750
751WRITE8_DEVICE_HANDLER(z80pio_alt_w)
752{
753   int channel = BIT(offset, 1);
754
755   if (offset & 1)
756      z80pio_c_w(device, channel, data);
757   else
758      z80pio_d_w(device, channel, data);
759}
760
735761/***************************************************************************
736762    DEVICE INTERFACE
737763***************************************************************************/
r3447r3448
784810   state_save_register_item_array(unique_tag, 0, z80pio->mask);
785811   state_save_register_item_array(unique_tag, 0, z80pio->ddr);
786812   state_save_register_item_array(unique_tag, 0, z80pio->strobe);
787   state_save_register_item_array(unique_tag, 0, z80pio->match);
788813
789814   return DEVICE_START_OK;
790815}
r3447r3448
815840      z80pio->irq_enable[channel] = 0;
816841      z80pio->irq_pending[channel] = 0;
817842      z80pio->int_state[channel] = 0;
818      z80pio->match[channel] = 0;
819843
820844      /* reset output register */
821845      z80pio->output[channel] = 0;
src/emu/machine/z80pio.h
r3447r3448
3434#define __Z80PIO_H__
3535
3636/***************************************************************************
37    TYPE DEFINITIONS
37    CALLBACK FUNCTION PROTOTYPES
3838***************************************************************************/
3939
4040typedef void (*z80pio_on_int_changed_func) (const device_config *device, int state);
r3447r3448
4646typedef void (*z80pio_on_brdy_changed_func) (const device_config *device, int state);
4747#define Z80PIO_ON_BRDY_CHANGED(name) void name(const device_config *device, int state)
4848
49typedef void (*z80pio_on_bstb_changed_func) (const device_config *device, int state);
50#define Z80PIO_ON_BSTB_CHANGED(name) void name(const device_config *device, int state)
49/***************************************************************************
50    TYPE DEFINITIONS
51***************************************************************************/
5152
5253typedef struct _z80pio_interface z80pio_interface;
5354struct _z80pio_interface
r3447r3448
114115    READ/WRITE HANDLERS
115116***************************************************************************/
116117
118/* A0 = B/A
119   A1 = C/D */
117120READ8_DEVICE_HANDLER(z80pio_r);
118121WRITE8_DEVICE_HANDLER(z80pio_w);
119122
123/* A0 = C/D
124   A1 = B/A */
125READ8_DEVICE_HANDLER(z80pio_alt_r);
126WRITE8_DEVICE_HANDLER(z80pio_alt_w);
127
120128/***************************************************************************
121129    DEVICE INTERFACE
122130***************************************************************************/
src/mess/drivers/mbee.c
r3447r3448
6262   return device_list_find_by_tag( machine->config->devicelist, CASSETTE, "cassette" );
6363}
6464
65static READ8_DEVICE_HANDLER( mbee_z80pio_r )
66{
67   int channel = BIT(offset, 1);
68
69   if (BIT(offset, 0))
70   {
71      return z80pio_c_r(device, channel);
72   }
73   else
74   {
75      return z80pio_d_r(device, channel);
76   }
77}
78
79static WRITE8_DEVICE_HANDLER( mbee_z80pio_w )
80{
81   int channel = BIT(offset, 1);
82
83   if (BIT(offset, 0))
84   {
85      z80pio_c_w(device, channel, data);
86   }
87   else
88   {
89      z80pio_d_w(device, channel, data);
90   }
91}
92
9365static QUICKLOAD_LOAD( mbee );
9466static Z80BIN_EXECUTE( mbee );
9567
r3447r3448
128100static ADDRESS_MAP_START(mbee_ports, ADDRESS_SPACE_IO, 8)
129101   ADDRESS_MAP_GLOBAL_MASK(0xff)
130102   ADDRESS_MAP_UNMAP_HIGH
131   AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", mbee_z80pio_r, mbee_z80pio_w)
103   AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", z80pio_alt_r, z80pio_alt_w)
132104   AM_RANGE(0x0b, 0x0b) AM_MIRROR(0x10) AM_READWRITE(mbee_video_bank_r, mbee_video_bank_w)
133105   AM_RANGE(0x0c, 0x0c) AM_MIRROR(0x10) AM_READWRITE(m6545_status_r, m6545_index_w)
134106   AM_RANGE(0x0d, 0x0d) AM_MIRROR(0x10) AM_READWRITE(m6545_data_r, m6545_data_w)
r3447r3448
137109static ADDRESS_MAP_START(mbeeic_ports, ADDRESS_SPACE_IO, 8)
138110   ADDRESS_MAP_GLOBAL_MASK(0xff)
139111   ADDRESS_MAP_UNMAP_HIGH
140   AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", mbee_z80pio_r, mbee_z80pio_w)
112   AM_RANGE(0x00, 0x03) AM_MIRROR(0x10) AM_DEVREADWRITE(Z80PIO, "z80pio", z80pio_alt_r, z80pio_alt_w)
141113   AM_RANGE(0x08, 0x08) AM_MIRROR(0x10) AM_READWRITE(mbee_pcg_color_latch_r, mbee_pcg_color_latch_w)
142114   // AM_RANGE(0x09, 0x09) AM_MIRROR(0x10)  Listed as "Colour Wait Off" or "USART 2651" but doesn't appear in the schematics
143115   AM_RANGE(0x0a, 0x0a) AM_MIRROR(0x10) AM_READWRITE(mbee_color_bank_r, mbee_color_bank_w)
src/mess/drivers/abc80.c
r3447r3448
9797
9898/* Read/Write Handlers */
9999
100static READ8_DEVICE_HANDLER( abc80_z80pio_r )
101{
102   int channel = BIT(offset, 1);
103
104   if (BIT(offset, 0))
105   {
106      return z80pio_c_r(device, channel);
107   }
108   else
109   {
110      return z80pio_d_r(device, channel);
111   }
112}
113
114static WRITE8_DEVICE_HANDLER( abc80_z80pio_w )
115{
116   int channel = BIT(offset, 1);
117
118   if (BIT(offset, 0))
119   {
120      z80pio_c_w(device, channel, data);
121   }
122   else
123   {
124      z80pio_d_w(device, channel, data);
125   }
126}
127
128100static WRITE8_HANDLER( abc80_sound_w )
129101{
130102   /*
r3447r3448
263235   AM_RANGE(0x02, 0x05) AM_WRITE(abcbus_command_w)
264236   AM_RANGE(0x06, 0x06) AM_WRITE(abc80_sound_w)
265237   AM_RANGE(0x07, 0x07) AM_READ(abcbus_reset_r)
266   AM_RANGE(0x38, 0x3b) AM_DEVREADWRITE(Z80PIO, Z80PIO_TAG, abc80_z80pio_r, abc80_z80pio_w)
238   AM_RANGE(0x38, 0x3b) AM_DEVREADWRITE(Z80PIO, Z80PIO_TAG, z80pio_alt_r, z80pio_alt_w)
267239ADDRESS_MAP_END
268240
269241/* Input Ports */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team