Previous 15994 Revisions Next

r7435 Saturday 20th February, 2010 at 02:53:15 UTC by Dirk Best
Moved ins8154 emulation to MAME
[src/emu]emu.mak
[src/emu/machine]ins8154.c* ins8154.h*
[src/mess]mess.mak
[src/mess/machine]ins8154.c ins8154.h

src/emu/emu.mak
r7434r7435
142142   $(EMUMACHINE)/i2cmem.o \
143143   $(EMUMACHINE)/i2cmemdev.o \
144144   $(EMUMACHINE)/idectrl.o \
145   $(EMUMACHINE)/ins8154.o   \
145146   $(EMUMACHINE)/intelfsh.o \
146147   $(EMUMACHINE)/k033906.o \
147148   $(EMUMACHINE)/k056230.o \
src/emu/machine/ins8154.c
r0r7435
1/*****************************************************************************
2 *
3 * machine/ins8154.h
4 *
5 * INS8154 N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6 *
7 * Written by Dirk Best, January 2008
8 *
9 * TODO: Strobed modes
10 *
11 ****************************************************************************/
12
13#include "emu.h"
14#include "ins8154.h"
15
16
17#define VERBOSE 1
18#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
19
20
21/* Mode Definition Register */
22enum
23{
24   MDR_BASIC                 = 0x00,
25   MDR_STROBED_INPUT         = 0x20,
26   MDR_STROBED_OUTPUT        = 0x60,
27   MDR_STROBED_OUTPUT_3STATE = 0xe0
28};
29
30typedef struct _ins8154_t ins8154_t;
31struct _ins8154_t
32{
33   const ins8154_interface *intf; /* Pointer to our interface */
34
35   UINT8 in_a;  /* Input Latch Port A */
36   UINT8 in_b;  /* Input Latch Port B */
37   UINT8 out_a; /* Output Latch Port A */
38   UINT8 out_b; /* Output Latch Port B */
39   UINT8 mdr;   /* Mode Definition Register */
40   UINT8 odra;  /* Output Definition Register Port A */
41   UINT8 odrb;  /* Output Definition Register Port B */
42};
43
44
45static DEVICE_START( ins8154 )
46{
47   ins8154_t *ins8154 = (ins8154_t *)device->token;
48
49   /* validate arguments */
50   assert(device->tag != NULL);
51
52   /* assign interface */
53   ins8154->intf = (const ins8154_interface*)device->baseconfig().static_config;
54
55   /* register for state saving */
56   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->in_a);
57   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->in_b);
58   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->out_a);
59   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->out_b);
60   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->mdr);
61   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->odra);
62   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->odrb);
63}
64
65
66static DEVICE_RESET( ins8154 )
67{
68   ins8154_t *ins8154 = (ins8154_t *)device->token;
69
70   ins8154->in_a = 0;
71   ins8154->in_b = 0;
72   ins8154->out_a = 0;
73   ins8154->out_b = 0;
74   ins8154->mdr = 0;
75   ins8154->odra = 0;
76   ins8154->odrb = 0;
77}
78
79
80READ8_DEVICE_HANDLER( ins8154_r )
81{
82   ins8154_t *i = (ins8154_t *)device->token;
83   UINT8 val = 0xff;
84
85   if (offset > 0x24)
86   {
87      logerror("INS8154 (%08x): Read from unknown offset %02x!\n",
88         cpu_get_pc( device->machine->firstcpu ), offset);
89      return 0xff;
90   }
91
92   switch (offset)
93   {
94   case 0x20:
95      if (i->intf->in_a_func)
96         val = i->intf->in_a_func(device, 0);
97      i->in_a = val;
98      break;
99
100   case 0x21:
101      if (i->intf->in_b_func)
102         val = i->intf->in_b_func(device, 0);
103      i->in_b = val;
104      break;
105
106   default:
107      if (offset < 0x08)
108      {
109         if (i->intf->in_a_func)
110            val = (i->intf->in_a_func(device, 0) << (8 - offset)) & 0x80;
111         i->in_a = val;
112      }
113      else
114      {
115         if (i->intf->in_a_func)
116            val = (i->intf->in_a_func(device, 0) << (8 - (offset >> 4))) & 0x80;
117         i->in_b = val;
118      }
119      break;
120   }
121
122   return val;
123}
124
125WRITE8_DEVICE_HANDLER( ins8154_porta_w )
126{
127   ins8154_t *i = (ins8154_t *)device->token;
128
129   i->out_a = data;
130
131   /* Test if any pins are set as outputs */
132   if (i->odra)
133   {
134      if (i->intf->out_a_func)
135         i->intf->out_a_func(device, 0, (data & i->odra) | (i->odra ^ 0xff));
136      else
137         logerror("INS8154 (%08x): Write to port A but no write handler defined!\n",
138            cpu_get_pc( device->machine->firstcpu ) );
139   }
140}
141
142
143WRITE8_DEVICE_HANDLER( ins8154_portb_w )
144{
145   ins8154_t *i = (ins8154_t *)device->token;
146
147   i->out_b = data;
148
149   /* Test if any pins are set as outputs */
150   if (i->odrb)
151   {
152      if (i->intf->out_b_func)
153         i->intf->out_b_func(device, 0, (data & i->odrb) | (i->odrb ^ 0xff));
154      else
155         logerror("INS8154 (%08x): Write to port B but no write handler defined!\n",
156            cpu_get_pc( device->machine->firstcpu ) );
157   }
158}
159
160
161WRITE8_DEVICE_HANDLER( ins8154_w )
162{
163   ins8154_t *i = (ins8154_t *)device->token;
164
165   if (offset > 0x24)
166   {
167      logerror("INS8154 (%04x): Write %02x to invalid offset %02x!\n",
168         cpu_get_pc( device->machine->firstcpu ), data, offset);
169      return;
170   }
171
172   switch (offset)
173   {
174   case 0x20:
175      ins8154_porta_w(device, 0, data);
176      break;
177
178   case 0x21:
179      ins8154_portb_w(device, 0, data);
180      break;
181
182   case 0x22:
183      LOG(("INS8154 (%04x): ODR for port A set to %02x\n",
184         cpu_get_pc( device->machine->firstcpu ), data));
185      i->odra = data;
186      break;
187
188   case 0x23:
189      LOG(("INS8154 (%04x): ODR for port B set to %02x\n",
190         cpu_get_pc( device->machine->firstcpu ), data));
191      i->odrb = data;
192      break;
193
194   case 0x24:
195      LOG(("INS8154 (%04x): MDR set to %02x\n",
196         cpu_get_pc( device->machine->firstcpu ), data));
197      i->mdr = data;
198      break;
199
200   default:
201      if (offset & 0x10)
202      {
203         /* Set bit */
204         if (offset < 0x08)
205         {
206            ins8154_porta_w(device, 0, i->out_a |= offset & 0x07);
207         }
208         else
209         {
210            ins8154_portb_w(device, 0, i->out_b |= (offset >> 4) & 0x07);
211         }
212      }
213      else
214      {
215         /* Clear bit */
216         if (offset < 0x08)
217         {
218            ins8154_porta_w(device, 0, i->out_a & ~(offset & 0x07));
219         }
220         else
221         {
222            ins8154_portb_w(device, 0, i->out_b & ~((offset >> 4) & 0x07));
223         }
224      }
225
226      break;
227   }
228}
229
230
231DEVICE_GET_INFO( ins8154 )
232{
233   switch (state)
234   {
235      /* --- the following bits of info are returned as 64-bit signed integers --- */
236      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = 0;                           break;
237      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_PERIPHERAL;            break;
238      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(ins8154_t);               break;
239
240      /* --- the following bits of info are returned as pointers to data or functions --- */
241      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(ins8154);      break;
242      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
243      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME(ins8154);      break;
244
245      /* --- the following bits of info are returned as NULL-terminated strings --- */
246      case DEVINFO_STR_NAME:               strcpy(info->s, "National Semiconductor INS8154");      break;
247      case DEVINFO_STR_FAMILY:            strcpy(info->s, "INS8154");                  break;
248      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");                     break;
249      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);                  break;
250      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MESS Team");         break;
251   }
252}
src/emu/machine/ins8154.h
r0r7435
1/*****************************************************************************
2 *
3 * machine/ins8154.h
4 *
5 * INS8154 N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6 *
7 ****************************************************************************/
8
9#ifndef INS8154_H_
10#define INS8154_H_
11
12/***************************************************************************
13    MACROS
14***************************************************************************/
15
16#define INS8154  DEVICE_GET_INFO_NAME(ins8154)
17
18/***************************************************************************
19    TYPE DEFINITIONS
20***************************************************************************/
21
22typedef void (*ins8154_irq_func)(running_device *device, int state);
23#define INS8154_IRQ(name)   void name(running_device *device, int state )
24
25/******************* Interface **********************************************/
26
27typedef struct _ins8154_interface ins8154_interface;
28
29struct _ins8154_interface
30{
31   read8_device_func in_a_func;
32   read8_device_func in_b_func;
33   write8_device_func out_a_func;
34   write8_device_func out_b_func;
35   ins8154_irq_func irq_func;
36};
37
38DEVICE_GET_INFO( ins8154 );
39
40
41/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/
42
43READ8_DEVICE_HANDLER( ins8154_r );
44WRITE8_DEVICE_HANDLER( ins8154_w );
45
46
47/******************* 8-bit A/B port interfaces ******************************/
48
49WRITE8_DEVICE_HANDLER( ins8154_porta_w );
50WRITE8_DEVICE_HANDLER( ins8154_portb_w );
51
52/***************************************************************************
53    DEVICE CONFIGURATION MACROS
54***************************************************************************/
55
56#define MDRV_INS8154_ADD(_tag, _intrf) \
57   MDRV_DEVICE_ADD(_tag, INS8154, 0) \
58   MDRV_DEVICE_CONFIG(_intrf)
59
60#endif /* INS8154_H_ */
src/mess/machine/ins8154.c
r7434r7435
1/*****************************************************************************
2 *
3 * machine/ins8154.h
4 *
5 * INS8154 N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6 *
7 * Written by Dirk Best, January 2008
8 *
9 * TODO: Strobed modes
10 *
11 ****************************************************************************/
12
13#include "emu.h"
14#include "ins8154.h"
15
16
17#define VERBOSE 1
18#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
19
20
21/* Mode Definition Register */
22enum
23{
24   MDR_BASIC                 = 0x00,
25   MDR_STROBED_INPUT         = 0x20,
26   MDR_STROBED_OUTPUT        = 0x60,
27   MDR_STROBED_OUTPUT_3STATE = 0xe0
28};
29
30typedef struct _ins8154_t ins8154_t;
31struct _ins8154_t
32{
33   const ins8154_interface *intf; /* Pointer to our interface */
34
35   UINT8 in_a;  /* Input Latch Port A */
36   UINT8 in_b;  /* Input Latch Port B */
37   UINT8 out_a; /* Output Latch Port A */
38   UINT8 out_b; /* Output Latch Port B */
39   UINT8 mdr;   /* Mode Definition Register */
40   UINT8 odra;  /* Output Definition Register Port A */
41   UINT8 odrb;  /* Output Definition Register Port B */
42};
43
44
45static DEVICE_START( ins8154 )
46{
47   ins8154_t *ins8154 = (ins8154_t *)device->token;
48
49   /* validate arguments */
50   assert(device->tag != NULL);
51
52   /* assign interface */
53   ins8154->intf = (const ins8154_interface*)device->baseconfig().static_config;
54
55   /* register for state saving */
56   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->in_a);
57   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->in_b);
58   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->out_a);
59   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->out_b);
60   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->mdr);
61   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->odra);
62   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->odrb);
63}
64
65
66static DEVICE_RESET( ins8154 )
67{
68   ins8154_t *ins8154 = (ins8154_t *)device->token;
69
70   ins8154->in_a = 0;
71   ins8154->in_b = 0;
72   ins8154->out_a = 0;
73   ins8154->out_b = 0;
74   ins8154->mdr = 0;
75   ins8154->odra = 0;
76   ins8154->odrb = 0;
77}
78
79
80READ8_DEVICE_HANDLER( ins8154_r )
81{
82   ins8154_t *i = (ins8154_t *)device->token;
83   UINT8 val = 0xff;
84
85   if (offset > 0x24)
86   {
87      logerror("INS8154 (%08x): Read from unknown offset %02x!\n",
88         cpu_get_pc( device->machine->firstcpu ), offset);
89      return 0xff;
90   }
91
92   switch (offset)
93   {
94   case 0x20:
95      if (i->intf->in_a_func)
96         val = i->intf->in_a_func(device, 0);
97      i->in_a = val;
98      break;
99
100   case 0x21:
101      if (i->intf->in_b_func)
102         val = i->intf->in_b_func(device, 0);
103      i->in_b = val;
104      break;
105
106   default:
107      if (offset < 0x08)
108      {
109         if (i->intf->in_a_func)
110            val = (i->intf->in_a_func(device, 0) << (8 - offset)) & 0x80;
111         i->in_a = val;
112      }
113      else
114      {
115         if (i->intf->in_a_func)
116            val = (i->intf->in_a_func(device, 0) << (8 - (offset >> 4))) & 0x80;
117         i->in_b = val;
118      }
119      break;
120   }
121
122   return val;
123}
124
125WRITE8_DEVICE_HANDLER( ins8154_porta_w )
126{
127   ins8154_t *i = (ins8154_t *)device->token;
128
129   i->out_a = data;
130
131   /* Test if any pins are set as outputs */
132   if (i->odra)
133   {
134      if (i->intf->out_a_func)
135         i->intf->out_a_func(device, 0, (data & i->odra) | (i->odra ^ 0xff));
136      else
137         logerror("INS8154 (%08x): Write to port A but no write handler defined!\n",
138            cpu_get_pc( device->machine->firstcpu ) );
139   }
140}
141
142
143WRITE8_DEVICE_HANDLER( ins8154_portb_w )
144{
145   ins8154_t *i = (ins8154_t *)device->token;
146
147   i->out_b = data;
148
149   /* Test if any pins are set as outputs */
150   if (i->odrb)
151   {
152      if (i->intf->out_b_func)
153         i->intf->out_b_func(device, 0, (data & i->odrb) | (i->odrb ^ 0xff));
154      else
155         logerror("INS8154 (%08x): Write to port B but no write handler defined!\n",
156            cpu_get_pc( device->machine->firstcpu ) );
157   }
158}
159
160
161WRITE8_DEVICE_HANDLER( ins8154_w )
162{
163   ins8154_t *i = (ins8154_t *)device->token;
164
165   if (offset > 0x24)
166   {
167      logerror("INS8154 (%04x): Write %02x to invalid offset %02x!\n",
168         cpu_get_pc( device->machine->firstcpu ), data, offset);
169      return;
170   }
171
172   switch (offset)
173   {
174   case 0x20:
175      ins8154_porta_w(device, 0, data);
176      break;
177
178   case 0x21:
179      ins8154_portb_w(device, 0, data);
180      break;
181
182   case 0x22:
183      LOG(("INS8154 (%04x): ODR for port A set to %02x\n",
184         cpu_get_pc( device->machine->firstcpu ), data));
185      i->odra = data;
186      break;
187
188   case 0x23:
189      LOG(("INS8154 (%04x): ODR for port B set to %02x\n",
190         cpu_get_pc( device->machine->firstcpu ), data));
191      i->odrb = data;
192      break;
193
194   case 0x24:
195      LOG(("INS8154 (%04x): MDR set to %02x\n",
196         cpu_get_pc( device->machine->firstcpu ), data));
197      i->mdr = data;
198      break;
199
200   default:
201      if (offset & 0x10)
202      {
203         /* Set bit */
204         if (offset < 0x08)
205         {
206            ins8154_porta_w(device, 0, i->out_a |= offset & 0x07);
207         }
208         else
209         {
210            ins8154_portb_w(device, 0, i->out_b |= (offset >> 4) & 0x07);
211         }
212      }
213      else
214      {
215         /* Clear bit */
216         if (offset < 0x08)
217         {
218            ins8154_porta_w(device, 0, i->out_a & ~(offset & 0x07));
219         }
220         else
221         {
222            ins8154_portb_w(device, 0, i->out_b & ~((offset >> 4) & 0x07));
223         }
224      }
225
226      break;
227   }
228}
229
230
231DEVICE_GET_INFO( ins8154 )
232{
233   switch (state)
234   {
235      /* --- the following bits of info are returned as 64-bit signed integers --- */
236      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = 0;                           break;
237      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_PERIPHERAL;            break;
238      case DEVINFO_INT_TOKEN_BYTES:         info->i = sizeof(ins8154_t);               break;
239
240      /* --- the following bits of info are returned as pointers to data or functions --- */
241      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(ins8154);      break;
242      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
243      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME(ins8154);      break;
244
245      /* --- the following bits of info are returned as NULL-terminated strings --- */
246      case DEVINFO_STR_NAME:               strcpy(info->s, "National Semiconductor INS8154");      break;
247      case DEVINFO_STR_FAMILY:            strcpy(info->s, "INS8154");                  break;
248      case DEVINFO_STR_VERSION:            strcpy(info->s, "1.0");                     break;
249      case DEVINFO_STR_SOURCE_FILE:         strcpy(info->s, __FILE__);                  break;
250      case DEVINFO_STR_CREDITS:            strcpy(info->s, "Copyright MESS Team");         break;
251   }
252}
src/mess/machine/ins8154.h
r7434r7435
1/*****************************************************************************
2 *
3 * machine/ins8154.h
4 *
5 * INS8154 N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6 *
7 ****************************************************************************/
8
9#ifndef INS8154_H_
10#define INS8154_H_
11
12/***************************************************************************
13    MACROS
14***************************************************************************/
15
16#define INS8154  DEVICE_GET_INFO_NAME(ins8154)
17
18/***************************************************************************
19    TYPE DEFINITIONS
20***************************************************************************/
21
22typedef void (*ins8154_irq_func)(running_device *device, int state);
23#define INS8154_IRQ(name)   void name(running_device *device, int state )
24
25/******************* Interface **********************************************/
26
27typedef struct _ins8154_interface ins8154_interface;
28
29struct _ins8154_interface
30{
31   read8_device_func in_a_func;
32   read8_device_func in_b_func;
33   write8_device_func out_a_func;
34   write8_device_func out_b_func;
35   ins8154_irq_func irq_func;
36};
37
38DEVICE_GET_INFO( ins8154 );
39
40
41/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/
42
43READ8_DEVICE_HANDLER( ins8154_r );
44WRITE8_DEVICE_HANDLER( ins8154_w );
45
46
47/******************* 8-bit A/B port interfaces ******************************/
48
49WRITE8_DEVICE_HANDLER( ins8154_porta_w );
50WRITE8_DEVICE_HANDLER( ins8154_portb_w );
51
52/***************************************************************************
53    DEVICE CONFIGURATION MACROS
54***************************************************************************/
55
56#define MDRV_INS8154_ADD(_tag, _intrf) \
57   MDRV_DEVICE_ADD(_tag, INS8154, 0) \
58   MDRV_DEVICE_CONFIG(_intrf)
59
60#endif /* INS8154_H_ */
src/mess/mess.mak
r7434r7435
458458   $(MESS_MACHINE)/i8271.o      \
459459   $(MESS_MACHINE)/i8355.o      \
460460   $(MESS_MACHINE)/ieee488.o   \
461   $(MESS_MACHINE)/ins8154.o   \
462461   $(MESS_MACHINE)/ins8250.o   \
463462   $(MESS_MACHINE)/kb3600.o   \
464463   $(MESS_MACHINE)/kr2376.o   \

Previous 15994 Revisions Next


© 1998-2018 The MESS Team