Previous 15994 Revisions Next

r1985 Thursday 13th March, 2008 at 17:54:23 UTC by Dirk Best
Converted machine/ins8154.c to the new device system and updated the Acorn System 1 driver accordingly
[src/mess/drivers]acrnsys1.c
[src/mess/machine]ins8154.c ins8154.h

src/mess/machine/ins8154.c
r1984r1985
1313#include "driver.h"
1414#include "ins8154.h"
1515
16#define MAX_INS8154   2
1716
1817#define VERBOSE 1
1918#define LOG(x)   do { if (VERBOSE) logerror x; } while (0)
r1984r1985
2928};
3029
3130
32typedef struct _ins8154_state ins8154_state;
33struct _ins8154_state
31struct _ins8154_t
3432{
35   /* Pointer to our interface */
36   const ins8154_interface *intf;
37   
33   const ins8154_interface *intf; /* Pointer to our interface */
34
3835   UINT8 in_a;  /* Input Latch Port A */
3936   UINT8 in_b;  /* Input Latch Port B */
4037   UINT8 out_a; /* Output Latch Port A */
r1984r1985
4441   UINT8 odrb;  /* Output Definition Register Port B */
4542};
4643
47static ins8154_state ins8154[MAX_INS8154];
4844
49
50/* Config */
51void ins8154_config(running_machine *machine, int which, const ins8154_interface *intf)
45static DEVICE_START( ins8154 )
5246{
53   assert_always(mame_get_phase(machine) == MAME_PHASE_INIT,
54      "Can only call ins8154_config at init time!");
55   assert_always(which < MAX_INS8154,
56      "'which' exceeds maximum number of configured INS8154s!");
47   ins8154_t *ins8154;
48   char unique_tag[30];
5749
58   /* Assign interface */
59   ins8154[which].intf = intf;
50   /* validate arguments */
51   assert(machine != NULL);
52   assert(tag != NULL);
53   assert(strlen(tag) < 20);
6054
61   /* Initialize */
62   ins8154_reset(which);
55   /* allocate the object that holds the state */
56   ins8154 = auto_malloc(sizeof(*ins8154));
57   memset(ins8154, 0, sizeof(*ins8154));
58
59   /* assign interface */
60   ins8154->intf = static_config;
61
62   /* register for state saving */
63   state_save_combine_module_and_tag(unique_tag, "ins8154", tag);
64   state_save_register_item(unique_tag, 0, ins8154->in_a);
65   state_save_register_item(unique_tag, 0, ins8154->in_b);
66   state_save_register_item(unique_tag, 0, ins8154->out_a);
67   state_save_register_item(unique_tag, 0, ins8154->out_b);
68   state_save_register_item(unique_tag, 0, ins8154->mdr);
69   state_save_register_item(unique_tag, 0, ins8154->odra);
70   state_save_register_item(unique_tag, 0, ins8154->odrb);
71   
72   return ins8154;
6373}
6474
6575
66/* Reset */
67void ins8154_reset(int which)
76static DEVICE_RESET( ins8154 )
6877{
69   ins8154[which].in_a = 0;
70   ins8154[which].in_b = 0;
71   ins8154[which].out_a = 0;
72   ins8154[which].out_b = 0;
73   ins8154[which].mdr = 0;
74   ins8154[which].odra = 0;
75   ins8154[which].odrb = 0;
78   ins8154_t *ins8154 = token;
79   
80   ins8154->in_a = 0;
81   ins8154->in_b = 0;
82   ins8154->out_a = 0;
83   ins8154->out_b = 0;
84   ins8154->mdr = 0;
85   ins8154->odra = 0;
86   ins8154->odrb = 0;
7687}
7788
7889
79static UINT8 ins8154_read(running_machine *machine, int which, offs_t offset)
90READ8_DEVICE_HANDLER( ins8154_r )
8091{
81   ins8154_state *i = &ins8154[which];
92   ins8154_t *i = device->token;
8293   UINT8 val = 0xff;
83   
94
8495   if (offset > 0x24)
8596   {
86      logerror("INS8154 chip #%d (%08x): Read from unknown offset %02x!\n",
87         which, safe_activecpu_get_pc(), offset);
97      logerror("INS8154 (%08x): Read from unknown offset %02x!\n",
98         safe_activecpu_get_pc(), offset);
8899      return 0xff;
89100   }
90101   
r1984r1985
92103   {
93104   case 0x20:
94105      if (i->intf->in_a_func)
95         val = i->intf->in_a_func(machine, 0);
106         val = i->intf->in_a_func(device, 0);
96107      i->in_a = val;
97108      break;
98109     
99110   case 0x21:
100111      if (i->intf->in_b_func)
101         val = i->intf->in_b_func(machine, 0);
112         val = i->intf->in_b_func(device, 0);
102113      i->in_b = val;
103114      break;
104115     
r1984r1985
106117      if (offset < 0x08)
107118      {
108119         if (i->intf->in_a_func)
109            val = (i->intf->in_a_func(machine, 0) << (8 - offset)) & 0x80;
120            val = (i->intf->in_a_func(device, 0) << (8 - offset)) & 0x80;
110121         i->in_a = val;
111122      }
112123      else
113124      {
114125         if (i->intf->in_a_func)
115            val = (i->intf->in_a_func(machine, 0) << (8 - (offset >> 4))) & 0x80;
126            val = (i->intf->in_a_func(device, 0) << (8 - (offset >> 4))) & 0x80;
116127         i->in_b = val;
117128      }
118129      break;
r1984r1985
121132   return val;
122133}
123134
124
125static void ins8154_write_port_a(running_machine *machine, int which, int data)
135WRITE8_DEVICE_HANDLER( ins8154_porta_w )
126136{
127   ins8154_state *i = &ins8154[which];
137   ins8154_t *i = device->token;
128138   
129139   i->out_a = data;
130140
r1984r1985
132142   if (i->odra)
133143   {
134144      if (i->intf->out_a_func)
135         i->intf->out_a_func(machine, 0, (data & i->odra) | (i->odra ^ 0xff));
145         i->intf->out_a_func(device, 0, (data & i->odra) | (i->odra ^ 0xff));
136146      else
137         logerror("INS8154 chip #%d (%08x): Write to port A but no write handler defined!\n",
138            which, safe_activecpu_get_pc());
147         logerror("INS8154 (%08x): Write to port A but no write handler defined!\n",
148            safe_activecpu_get_pc());
139149   }
140150}
141151
142152
143static void ins8154_write_port_b(running_machine *machine, int which, int data)
153WRITE8_DEVICE_HANDLER( ins8154_portb_w )
144154{
145   ins8154_state *i = &ins8154[which];
155   ins8154_t *i = device->token;
146156   
147157   i->out_b = data;
148158   
r1984r1985
150160   if (i->odrb)
151161   {
152162      if (i->intf->out_b_func)
153         i->intf->out_b_func(machine, 0, (data & i->odrb) | (i->odrb ^ 0xff));
163         i->intf->out_b_func(device, 0, (data & i->odrb) | (i->odrb ^ 0xff));
154164      else
155         logerror("INS8154 chip #%d (%08x): Write to port B but no write handler defined!\n",
156            which, safe_activecpu_get_pc());
165         logerror("INS8154 (%08x): Write to port B but no write handler defined!\n",
166            safe_activecpu_get_pc());
157167   }
158168}
159169
160170
161static void ins8154_write(running_machine *machine, int which, offs_t offset, UINT8 data)
171WRITE8_DEVICE_HANDLER( ins8154_w )
162172{
163   ins8154_state *i = &ins8154[which];
173   ins8154_t *i = device->token;
164174   
165175   if (offset > 0x24)
166176   {
167      logerror("INS8154 chip %d (%04x): Write %02x to invalid offset %02x!\n",
168         which, safe_activecpu_get_pc(), data, offset);
177      logerror("INS8154 (%04x): Write %02x to invalid offset %02x!\n",
178         safe_activecpu_get_pc(), data, offset);
169179      return;
170180   }
171181   
172182   switch (offset)
173183   {
174184   case 0x20:
175      ins8154_write_port_a(machine, which, data);
185      ins8154_porta_w(device, 0, data);
176186      break;
177187     
178188   case 0x21:
179      ins8154_write_port_b(machine, which, data);
189      ins8154_portb_w(device, 0, data);
180190      break;
181191     
182192   case 0x22:
183      LOG(("INS8154 chip %d (%04x): ODR for port A set to %02x\n",
184         which, safe_activecpu_get_pc(), data));
193      LOG(("INS8154 (%04x): ODR for port A set to %02x\n",
194         safe_activecpu_get_pc(), data));
185195      i->odra = data;
186196      break;
187197     
188198   case 0x23:
189      LOG(("INS8154 chip %d (%04x): ODR for port B set to %02x\n",
190         which, safe_activecpu_get_pc(), data));
199      LOG(("INS8154 (%04x): ODR for port B set to %02x\n",
200         safe_activecpu_get_pc(), data));
191201      i->odrb = data;
192202      break;
193203     
194204   case 0x24:
195      LOG(("INS8154 chip %d (%04x): MDR set to %02x\n",
196         which, safe_activecpu_get_pc(), data));
205      LOG(("INS8154 (%04x): MDR set to %02x\n",
206         safe_activecpu_get_pc(), data));
197207      i->mdr = data;
198208      break;
199209     
r1984r1985
203213         /* Set bit */
204214         if (offset < 0x08)
205215         {
206            ins8154_write_port_a(machine, which, i->out_a |= offset & 0x07);
216            ins8154_porta_w(device, 0, i->out_a |= offset & 0x07);
207217         }
208218         else
209219         {
210            ins8154_write_port_b(machine, which, i->out_b |= (offset >> 4) & 0x07);
220            ins8154_portb_w(device, 0, i->out_b |= (offset >> 4) & 0x07);
211221         }
212222      }
213223      else
r1984r1985
215225         /* Clear bit */
216226         if (offset < 0x08)
217227         {
218            ins8154_write_port_a(machine, which, i->out_a & ~(offset & 0x07));
228            ins8154_porta_w(device, 0, i->out_a & ~(offset & 0x07));
219229         }
220230         else
221231         {
222            ins8154_write_port_b(machine, which, i->out_b & ~((offset >> 4) & 0x07));
232            ins8154_portb_w(device, 0, i->out_b & ~((offset >> 4) & 0x07));
223233         }
224234      }
225235     
r1984r1985
228238}
229239
230240
241static DEVICE_SET_INFO( ins8154 )
242{
243   switch (state)
244   {
245      /* no parameters to set */
246   }
247}
231248
232/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/
233249
234WRITE8_HANDLER( ins8154_0_w ) {   ins8154_write(machine, 0, offset, data); }
235WRITE8_HANDLER( ins8154_1_w ) {   ins8154_write(machine, 1, offset, data); }
250DEVICE_GET_INFO( ins8154 )
251{
252   switch (state)
253   {
254      /* --- the following bits of info are returned as 64-bit signed integers --- */
255      case DEVINFO_INT_INLINE_CONFIG_BYTES:   info->i = 0;                           break;
256      case DEVINFO_INT_CLASS:               info->i = DEVICE_CLASS_PERIPHERAL;            break;
236257
237READ8_HANDLER( ins8154_0_r ) { return ins8154_read(machine, 0, offset); }
238READ8_HANDLER( ins8154_1_r ) { return ins8154_read(machine, 1, offset); }
258      /* --- the following bits of info are returned as pointers to data or functions --- */
259      case DEVINFO_FCT_SET_INFO:            info->set_info = DEVICE_SET_INFO_NAME(ins8154);   break;
260      case DEVINFO_FCT_START:               info->start = DEVICE_START_NAME(ins8154);      break;
261      case DEVINFO_FCT_STOP:               /* Nothing */                           break;
262      case DEVINFO_FCT_RESET:               info->reset = DEVICE_RESET_NAME(ins8154);      break;
263
264      /* --- the following bits of info are returned as NULL-terminated strings --- */
265      case DEVINFO_STR_NAME:               info->s = "National Semiconductor INS8154";      break;
266      case DEVINFO_STR_FAMILY:            info->s = "INS8154";                     break;
267      case DEVINFO_STR_VERSION:            info->s = "1.0";                        break;
268      case DEVINFO_STR_SOURCE_FILE:         info->s = __FILE__;                        break;
269      case DEVINFO_STR_CREDITS:            info->s = "Copyright MESS Team";            break;
270   }
271}
src/mess/machine/ins8154.h
r1984r1985
99#ifndef INS8154_H_
1010#define INS8154_H_
1111
12#define INS8154  DEVICE_GET_INFO_NAME(ins8154)
1213
14
1315/******************* Interface **********************************************/
1416
17typedef struct _ins8154_t ins8154_t;
1518typedef struct _ins8154_interface ins8154_interface;
19
1620struct _ins8154_interface
1721{
18   read8_machine_func in_a_func;
19   read8_machine_func in_b_func;
20   write8_machine_func out_a_func;
21   write8_machine_func out_b_func;
22   read8_device_func in_a_func;
23   read8_device_func in_b_func;
24   write8_device_func out_a_func;
25   write8_device_func out_b_func;
2226   void (*irq_func)(int state);   
2327};
2428
29DEVICE_GET_INFO( ins8154 );
2530
26/******************* Configuration ******************************************/
2731
28void ins8154_config(running_machine *machine, int which, const ins8154_interface *intf);
29void ins8154_reset(int which);
30
31
3232/******************* Standard 8-bit CPU interfaces, D0-D7 *******************/
3333
34READ8_HANDLER( ins8154_0_r );
35READ8_HANDLER( ins8154_1_r );
36WRITE8_HANDLER( ins8154_0_w );
37WRITE8_HANDLER( ins8154_1_w );
34READ8_DEVICE_HANDLER( ins8154_r );
35WRITE8_DEVICE_HANDLER( ins8154_w );
3836
3937
4038/******************* 8-bit A/B port interfaces ******************************/
4139
42READ8_HANDLER( ins8154_0_porta_r );
43READ8_HANDLER( ins8154_0_portb_r );
44READ8_HANDLER( ins8154_1_porta_r );
45READ8_HANDLER( ins8154_1_portb_r );
46WRITE8_HANDLER( ins8154_0_porta_w );
47WRITE8_HANDLER( ins8154_0_portb_w );
48WRITE8_HANDLER( ins8154_1_porta_w );
49WRITE8_HANDLER( ins8154_1_portb_w );
40READ8_DEVICE_HANDLER( ins8154_porta_r );
41READ8_DEVICE_HANDLER( ins8154_portb_r );
42WRITE8_DEVICE_HANDLER( ins8154_porta_w );
43WRITE8_DEVICE_HANDLER( ins8154_portb_w );
5044
5145
52#endif /*INS8154_H_*/
46#endif /* INS8154_H_ */
src/mess/drivers/acrnsys1.c
r1984r1985
2222static UINT8 key_digit;
2323
2424
25static READ8_HANDLER( ins8154_b1_port_a_r )
25static READ8_DEVICE_HANDLER( ins8154_b1_port_a_r )
2626{
2727   char port[11];
2828   UINT8 data;
r1984r1985
3232   return data;
3333}
3434
35static WRITE8_HANDLER( ins8154_b1_port_a_w )
35static WRITE8_DEVICE_HANDLER( ins8154_b1_port_a_w )
3636{
37   ttl74145_0_w(machine, 0, data & 0x07);
37   ttl74145_0_w(device->machine, 0, data & 0x07);
3838}
3939
40static WRITE8_HANDLER( acrnsys1_led_segment_w )
40static WRITE8_DEVICE_HANDLER( acrnsys1_led_segment_w )
4141{
4242   logerror("led %d segment data: %02x\n", key_digit, data);
4343   
r1984r1985
7878
7979static DRIVER_INIT( acrnsys1 )
8080{
81   ins8154_config(machine, 0, &ins8154_b1);
8281   ttl74145_config(0, &ic8_7445);
8382}
8483
8584static MACHINE_RESET( acrnsys1 )
8685{
87   ins8154_reset(0);
8886   ttl74145_reset(0);
8987}
9088
r1984r1985
9694
9795static ADDRESS_MAP_START( acrnsys1_map, ADDRESS_SPACE_PROGRAM, 8 )
9896   AM_RANGE(0x0000, 0x03ff) AM_RAM
99   AM_RANGE(0x0e00, 0x0e7f) AM_MIRROR(0x100) AM_READWRITE(ins8154_0_r, ins8154_0_w)
97   AM_RANGE(0x0e00, 0x0e7f) AM_MIRROR(0x100) AM_DEVREADWRITE(INS8154, "b1", ins8154_r, ins8154_w)
10098   AM_RANGE(0x0e80, 0x0eff) AM_MIRROR(0x100) AM_RAM
10199   AM_RANGE(0xfe00, 0xffff) AM_MIRROR(0x600) AM_ROM
102100ADDRESS_MAP_END
r1984r1985
186184
187185   MDRV_MACHINE_RESET(acrnsys1)
188186   
187   MDRV_DEVICE_ADD("b1", INS8154)
188   MDRV_DEVICE_CONFIG(ins8154_b1)
189   
189190   MDRV_DEFAULT_LAYOUT(layout_acrnsys1)
190191MACHINE_DRIVER_END
191192

Previous 15994 Revisions Next


© 1998-2018 The MESS Team