Previous 15994 Revisions Next

r7445 Monday 22nd February, 2010 at 11:14:24 UTC by Dirk Best
ins8154: Updated to use devcb calls, cleaned up
[src/emu/machine]ins8154.c ins8154.h
[src/mess/drivers]acrnsys1.c

src/emu/machine/ins8154.c
r7444r7445
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 ****************************************************************************/
1/***************************************************************************
122
3    National Semiconductor INS8154
4
5    N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6
7
8    TODO: Strobed modes
9
10***************************************************************************/
11
1312#include "emu.h"
1413#include "ins8154.h"
1514
1615
16/***************************************************************************
17    CONSTANTS
18***************************************************************************/
19
1720#define VERBOSE 1
18#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
1921
20
2122/* Mode Definition Register */
2223enum
2324{
r7444r7445
2728   MDR_STROBED_OUTPUT_3STATE = 0xe0
2829};
2930
30typedef struct _ins8154_t ins8154_t;
31struct _ins8154_t
31
32/***************************************************************************
33    TYPE DEFINITIONS
34***************************************************************************/
35
36typedef struct _ins8154_state ins8154_state;
37struct _ins8154_state
3238{
33   const ins8154_interface *intf; /* Pointer to our interface */
39   /* i/o lines */
40   devcb_resolved_read8 in_a_func;
41   devcb_resolved_write8 out_a_func;
42   devcb_resolved_read8 in_b_func;
43   devcb_resolved_write8 out_b_func;
44   devcb_resolved_write_line out_irq_func;
3445
46   /* registers */
3547   UINT8 in_a;  /* Input Latch Port A */
3648   UINT8 in_b;  /* Input Latch Port B */
3749   UINT8 out_a; /* Output Latch Port A */
r7444r7445
4254};
4355
4456
45static DEVICE_START( ins8154 )
57/*****************************************************************************
58    INLINE FUNCTIONS
59*****************************************************************************/
60
61INLINE ins8154_state *get_safe_token(running_device *device)
4662{
47   ins8154_t *ins8154 = (ins8154_t *)device->token;
63   assert(device != NULL);
64   assert(device->token != NULL);
65   assert(device->type == INS8154);
4866
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);
67   return (ins8154_state *)device->token;
6368}
6469
6570
66static DEVICE_RESET( ins8154 )
67{
68   ins8154_t *ins8154 = (ins8154_t *)device->token;
71/***************************************************************************
72    IMPLEMENTATION
73***************************************************************************/
6974
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
8075READ8_DEVICE_HANDLER( ins8154_r )
8176{
82   ins8154_t *i = (ins8154_t *)device->token;
77   ins8154_state *ins8154 = get_safe_token(device);
8378   UINT8 val = 0xff;
8479
8580   if (offset > 0x24)
8681   {
87      logerror("INS8154 (%08x): Read from unknown offset %02x!\n",
88         cpu_get_pc( device->machine->firstcpu ), offset);
82      if (VERBOSE)
83         logerror("%s: INS8154 '%s' Read from invalid offset %02x!\n", cpuexec_describe_context(device->machine), device->tag.cstr(), offset);
8984      return 0xff;
9085   }
9186
9287   switch (offset)
9388   {
9489   case 0x20:
95      if (i->intf->in_a_func)
96         val = i->intf->in_a_func(device, 0);
97      i->in_a = val;
90      if (ins8154->in_a_func.read != NULL)
91         val = devcb_call_read8(&ins8154->in_a_func, 0);
92      ins8154->in_a = val;
9893      break;
9994
10095   case 0x21:
101      if (i->intf->in_b_func)
102         val = i->intf->in_b_func(device, 0);
103      i->in_b = val;
96      if (ins8154->in_b_func.read != NULL)
97         val = devcb_call_read8(&ins8154->in_b_func, 0);
98      ins8154->in_b = val;
10499      break;
105100
106101   default:
107102      if (offset < 0x08)
108103      {
109         if (i->intf->in_a_func)
110            val = (i->intf->in_a_func(device, 0) << (8 - offset)) & 0x80;
111         i->in_a = val;
104         if (ins8154->in_a_func.read != NULL)
105            val = (devcb_call_read8(&ins8154->in_a_func, 0) << (8 - offset)) & 0x80;
106         ins8154->in_a = val;
112107      }
113108      else
114109      {
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;
110         if (ins8154->in_b_func.read != NULL)
111            val = (devcb_call_read8(&ins8154->in_b_func, 0) << (8 - (offset >> 4))) & 0x80;
112         ins8154->in_b = val;
118113      }
119114      break;
120115   }
r7444r7445
124119
125120WRITE8_DEVICE_HANDLER( ins8154_porta_w )
126121{
127   ins8154_t *i = (ins8154_t *)device->token;
122   ins8154_state *ins8154 = get_safe_token(device);
128123
129   i->out_a = data;
124   ins8154->out_a = data;
130125
131126   /* 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   }
127   if (ins8154->odra)
128      devcb_call_write8(&ins8154->out_a_func, 0, (data & ins8154->odra) | (ins8154->odra ^ 0xff));
140129}
141130
142
143131WRITE8_DEVICE_HANDLER( ins8154_portb_w )
144132{
145   ins8154_t *i = (ins8154_t *)device->token;
133   ins8154_state *ins8154 = get_safe_token(device);
146134
147   i->out_b = data;
135   ins8154->out_b = data;
148136
149137   /* 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   }
138   if (ins8154->odrb)
139      devcb_call_write8(&ins8154->out_b_func, 0, (data & ins8154->odrb) | (ins8154->odrb ^ 0xff));
158140}
159141
160
161142WRITE8_DEVICE_HANDLER( ins8154_w )
162143{
163   ins8154_t *i = (ins8154_t *)device->token;
144   ins8154_state *ins8154 = get_safe_token(device);
164145
165146   if (offset > 0x24)
166147   {
167      logerror("INS8154 (%04x): Write %02x to invalid offset %02x!\n",
168         cpu_get_pc( device->machine->firstcpu ), data, offset);
148      if (VERBOSE)
149         logerror("%s: INS8154 '%s' Write %02x to invalid offset %02x!\n", cpuexec_describe_context(device->machine), device->tag.cstr(), data, offset);
169150      return;
170151   }
171152
r7444r7445
180161      break;
181162
182163   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;
164      if (VERBOSE)
165         logerror("%s: INS8154 '%s' ODRA set to %02x\n", cpuexec_describe_context(device->machine), device->tag.cstr(), data);
166
167      ins8154->odra = data;
186168      break;
187169
188170   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;
171      if (VERBOSE)
172         logerror("%s: INS8154 '%s' ODRB set to %02x\n", cpuexec_describe_context(device->machine), device->tag.cstr(), data);
173
174      ins8154->odrb = data;
192175      break;
193176
194177   case 0x24:
195      LOG(("INS8154 (%04x): MDR set to %02x\n",
196         cpu_get_pc( device->machine->firstcpu ), data));
197      i->mdr = data;
178      if (VERBOSE)
179         logerror("%s: INS8154 '%s' MDR set to %02x\n", cpuexec_describe_context(device->machine), device->tag.cstr(), data);
180
181      ins8154->mdr = data;
198182      break;
199183
200184   default:
r7444r7445
203187         /* Set bit */
204188         if (offset < 0x08)
205189         {
206            ins8154_porta_w(device, 0, i->out_a |= offset & 0x07);
190            ins8154_porta_w(device, 0, ins8154->out_a |= offset & 0x07);
207191         }
208192         else
209193         {
210            ins8154_portb_w(device, 0, i->out_b |= (offset >> 4) & 0x07);
194            ins8154_portb_w(device, 0, ins8154->out_b |= (offset >> 4) & 0x07);
211195         }
212196      }
213197      else
r7444r7445
215199         /* Clear bit */
216200         if (offset < 0x08)
217201         {
218            ins8154_porta_w(device, 0, i->out_a & ~(offset & 0x07));
202            ins8154_porta_w(device, 0, ins8154->out_a & ~(offset & 0x07));
219203         }
220204         else
221205         {
222            ins8154_portb_w(device, 0, i->out_b & ~((offset >> 4) & 0x07));
206            ins8154_portb_w(device, 0, ins8154->out_b & ~((offset >> 4) & 0x07));
223207         }
224208      }
225209
r7444r7445
228212}
229213
230214
231DEVICE_GET_INFO( ins8154 )
215/*****************************************************************************
216    DEVICE INTERFACE
217*****************************************************************************/
218
219static DEVICE_START( ins8154 )
232220{
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;
221   ins8154_state *ins8154 = get_safe_token(device);
222   const ins8154_interface *intf = (const ins8154_interface *)device->baseconfig().static_config;
239223
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;
224   /* validate some basic stuff */
225   assert(intf != NULL);
244226
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   }
227   /* resolve callbacks */
228   devcb_resolve_read8(&ins8154->in_a_func, &intf->in_a_func, device);
229   devcb_resolve_write8(&ins8154->out_a_func, &intf->out_a_func, device);
230   devcb_resolve_read8(&ins8154->in_b_func, &intf->in_b_func, device);
231   devcb_resolve_write8(&ins8154->out_b_func, &intf->out_b_func, device);
232   devcb_resolve_write_line(&ins8154->out_irq_func, &intf->out_irq_func, device);
233
234   /* register for state saving */
235   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->in_a);
236   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->in_b);
237   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->out_a);
238   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->out_b);
239   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->mdr);
240   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->odra);
241   state_save_register_item(device->machine, "ins8154", device->tag, 0, ins8154->odrb);
252242}
243
244static DEVICE_RESET( ins8154 )
245{
246   ins8154_state *ins8154 = get_safe_token(device);
247
248   ins8154->in_a = 0;
249   ins8154->in_b = 0;
250   ins8154->out_a = 0;
251   ins8154->out_b = 0;
252   ins8154->mdr = 0;
253   ins8154->odra = 0;
254   ins8154->odrb = 0;
255}
256
257
258/***************************************************************************
259    DEVICE GETINFO
260***************************************************************************/
261
262static const char DEVTEMPLATE_SOURCE[] = __FILE__;
263
264#define DEVTEMPLATE_ID(p,s)            p##ins8154##s
265#define DEVTEMPLATE_FEATURES         DT_HAS_START | DT_HAS_RESET
266#define DEVTEMPLATE_NAME            "INS8154"
267#define DEVTEMPLATE_FAMILY            "INS8154"
268#define DEVTEMPLATE_VERSION            "1.1"
269#define DEVTEMPLATE_CREDITS            "Copyright MESS Team"
270#include "devtempl.h"
src/emu/machine/ins8154.h
r7444r7445
1/*****************************************************************************
2 *
3 * machine/ins8154.h
4 *
5 * INS8154 N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6 *
7 ****************************************************************************/
1/***************************************************************************
82
9#ifndef INS8154_H_
10#define INS8154_H_
3    National Semiconductor INS8154
114
12/***************************************************************************
13    MACROS
5    N-Channel 128-by-8 Bit RAM Input/Output (RAM I/O)
6
7                            _____   _____
8                   PB6   1 |*    \_/     | 40  VCC
9                   PB5   2 |             | 39  PB7
10                   PB4   3 |             | 38  NWDS
11                   PB3   4 |             | 37  NRDS
12                   PB2   5 |             | 36  NRST
13                   PB1   6 |             | 35  _CS0
14                   PB0   7 |             | 34  CS1
15                   DB7   8 |             | 33  M/_IO
16                   DB6   9 |             | 32  AD6
17                   DB5  10 |   INS8154   | 31  AD5
18                   DB4  11 |             | 30  AD4
19                   DB3  12 |             | 29  AD3
20                   DB2  13 |             | 28  AD2
21                   DB1  14 |             | 27  AD1
22                   DB0  15 |             | 26  AD0
23                   PA7  16 |             | 25  INTR
24                   PA6  17 |             | 24  PA0
25                   PA5  18 |             | 23  PA1
26                   PA4  19 |             | 22  PA2
27                   GND  20 |_____________| 21  PA3
28
1429***************************************************************************/
1530
16#define INS8154  DEVICE_GET_INFO_NAME(ins8154)
31#ifndef __INS8154_H__
32#define __INS8154_H__
1733
34#include "devcb.h"
35
36
1837/***************************************************************************
1938    TYPE DEFINITIONS
2039***************************************************************************/
2140
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
2741typedef struct _ins8154_interface ins8154_interface;
28
2942struct _ins8154_interface
3043{
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;
44   devcb_read8         in_a_func;
45   devcb_write8      out_a_func;
46   devcb_read8         in_b_func;
47   devcb_write8      out_b_func;
48   devcb_write_line   out_irq_func;
3649};
3750
38DEVICE_GET_INFO( ins8154 );
3951
52/***************************************************************************
53    FUNCTION PROTOTYPES
54***************************************************************************/
4055
41/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/
56DEVICE_GET_INFO( ins8154 );
4257
4358READ8_DEVICE_HANDLER( ins8154_r );
4459WRITE8_DEVICE_HANDLER( ins8154_w );
4560
46
47/******************* 8-bit A/B port interfaces ******************************/
48
4961WRITE8_DEVICE_HANDLER( ins8154_porta_w );
5062WRITE8_DEVICE_HANDLER( ins8154_portb_w );
5163
64
5265/***************************************************************************
5366    DEVICE CONFIGURATION MACROS
5467***************************************************************************/
5568
69#define INS8154  DEVICE_GET_INFO_NAME(ins8154)
70
5671#define MDRV_INS8154_ADD(_tag, _intrf) \
5772   MDRV_DEVICE_ADD(_tag, INS8154, 0) \
5873   MDRV_DEVICE_CONFIG(_intrf)
5974
60#endif /* INS8154_H_ */
75
76#endif /* __INS8154_H__ */
src/mess/drivers/acrnsys1.c
r7444r7445
146146
147147static const ins8154_interface ins8154_b1 =
148148{
149   ins8154_b1_port_a_r,
150   NULL,
151   ins8154_b1_port_a_w,
152   acrnsys1_led_segment_w,
153   NULL
149   DEVCB_HANDLER(ins8154_b1_port_a_r),
150   DEVCB_HANDLER(ins8154_b1_port_a_w),
151   DEVCB_NULL,
152   DEVCB_HANDLER(acrnsys1_led_segment_w),
153   DEVCB_NULL
154154};
155155
156156static MACHINE_DRIVER_START( acrnsys1 )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team