Previous 15994 Revisions Next

r9420 Wednesday 20th October, 2010 at 11:49:55 UTC by Curt Coder
Refactored the Intel 8155, 8355, 8212 and RCA CDP1871 into C++ devices.
[src/mess/drivers]comx35.c exp85.c kyocera.c mikromik.c
[src/mess/includes]comx35.h mikromik.h
[src/mess/machine]cdp1871.c cdp1871.h i8155.c i8155.h i8212.c i8212.h i8355.c i8355.h

src/mess/machine/cdp1871.c
r9419r9420
99
1010#include "emu.h"
1111#include "cdp1871.h"
12#include "cpu/mcs48/mcs48.h"
13#include "machine/devhelpr.h"
1214
13/***************************************************************************
14    PARAMETERS
15***************************************************************************/
1615
16
17//**************************************************************************
18//   MACROS / CONSTANTS
19//**************************************************************************
20
1721static const UINT8 CDP1871_KEY_CODES[4][11][8] =
1822{
1923   // normal
r9419r9420
7781   }
7882};
7983
80/***************************************************************************
81    TYPE DEFINITIONS
82***************************************************************************/
8384
84typedef struct _cdp1871_t cdp1871_t;
85struct _cdp1871_t
85
86//**************************************************************************
87//  DEVICE DEFINITIONS
88//**************************************************************************
89
90const device_type CDP1871 = cdp1871_device_config::static_alloc_device_config;
91
92
93
94//**************************************************************************
95//  DEVICE CONFIGURATION
96//**************************************************************************
97
98GENERIC_DEVICE_CONFIG_SETUP(cdp1871, "RCA CDP1871")
99
100
101//-------------------------------------------------
102//  device_config_complete - perform any
103//  operations now that the configuration is
104//  complete
105//-------------------------------------------------
106
107void cdp1871_device_config::device_config_complete()
86108{
87   devcb_resolved_write_line   out_da_func;
88   devcb_resolved_write_line   out_rpt_func;
89   devcb_resolved_read8      in_d1_func;
90   devcb_resolved_read8      in_d2_func;
91   devcb_resolved_read8      in_d3_func;
92   devcb_resolved_read8      in_d4_func;
93   devcb_resolved_read8      in_d5_func;
94   devcb_resolved_read8      in_d6_func;
95   devcb_resolved_read8      in_d7_func;
96   devcb_resolved_read8      in_d8_func;
97   devcb_resolved_read8      in_d9_func;
98   devcb_resolved_read8      in_d10_func;
99   devcb_resolved_read8      in_d11_func;
100   devcb_resolved_read_line   in_shift_func;
101   devcb_resolved_read_line   in_control_func;
102   devcb_resolved_read_line   in_alpha_func;
109   // inherit a copy of the static data
110   const cdp1871_interface *intf = reinterpret_cast<const cdp1871_interface *>(static_config());
111   if (intf != NULL)
112      *static_cast<cdp1871_interface *>(this) = *intf;
103113
104   int inhibit;               /* scan counter clock inhibit */
105   int sense;                  /* sense input scan counter */
106   int drive;                  /* modifier inputs */
114   // or initialize to defaults if none provided
115   else
116   {
117      memset(&out_da_func, 0, sizeof(out_da_func));
118      memset(&out_rpt_func, 0, sizeof(out_rpt_func));
119      // m_in_d_func[]
120      memset(&in_shift_func, 0, sizeof(in_shift_func));
121      memset(&in_control_func, 0, sizeof(in_control_func));
122      memset(&in_alpha_func, 0, sizeof(in_alpha_func));
123   }
124}
107125
108   int shift;                  /* latched shift modifier */
109   int control;               /* latched control modifier */
110126
111   int da;                     /* data available flag */
112   int next_da;               /* next value of data available flag */
113   int rpt;                  /* repeat flag */
114   int next_rpt;               /* next value of repeat flag */
115127
116   /* timers */
117   emu_timer *scan_timer;         /* keyboard scan timer */
118};
128//**************************************************************************
129//  LIVE DEVICE
130//**************************************************************************
119131
120/***************************************************************************
121    INLINE FUNCTIONS
122***************************************************************************/
132//-------------------------------------------------
133//  cdp1871_device - constructor
134//-------------------------------------------------
123135
124INLINE cdp1871_t *get_safe_token(running_device *device)
136cdp1871_device::cdp1871_device(running_machine &_machine, const cdp1871_device_config &config)
137    : device_t(_machine, config),
138     m_inhibit(false),
139     m_sense(0),
140     m_drive(0),
141     m_next_da(CLEAR_LINE),
142     m_next_rpt(CLEAR_LINE),
143      m_config(config)
125144{
126   assert(device != NULL);
127145
128   return (cdp1871_t *)downcast<legacy_device_base *>(device)->token();
129146}
130147
131INLINE const cdp1871_interface *get_interface(running_device *device)
148
149//-------------------------------------------------
150//  device_start - device-specific startup
151//-------------------------------------------------
152
153void cdp1871_device::device_start()
132154{
133   assert(device != NULL);
134   assert((device->type() == CDP1871));
135   return (const cdp1871_interface *) device->baseconfig().static_config();
155   // resolve callbacks
156   devcb_resolve_write_line(&m_out_da_func, &m_config.out_da_func, this);
157   devcb_resolve_write_line(&m_out_rpt_func, &m_config.out_rpt_func, this);
158   devcb_resolve_read8(&m_in_d_func[0], &m_config.in_d1_func, this);
159   devcb_resolve_read8(&m_in_d_func[1], &m_config.in_d2_func, this);
160   devcb_resolve_read8(&m_in_d_func[2], &m_config.in_d3_func, this);
161   devcb_resolve_read8(&m_in_d_func[3], &m_config.in_d4_func, this);
162   devcb_resolve_read8(&m_in_d_func[4], &m_config.in_d5_func, this);
163   devcb_resolve_read8(&m_in_d_func[5], &m_config.in_d6_func, this);
164   devcb_resolve_read8(&m_in_d_func[6], &m_config.in_d7_func, this);
165   devcb_resolve_read8(&m_in_d_func[7], &m_config.in_d8_func, this);
166   devcb_resolve_read8(&m_in_d_func[8], &m_config.in_d9_func, this);
167   devcb_resolve_read8(&m_in_d_func[9], &m_config.in_d10_func, this);
168   devcb_resolve_read8(&m_in_d_func[10], &m_config.in_d11_func, this);
169   devcb_resolve_read_line(&m_in_shift_func, &m_config.in_shift_func, this);
170   devcb_resolve_read_line(&m_in_control_func, &m_config.in_control_func, this);
171   devcb_resolve_read_line(&m_in_alpha_func, &m_config.in_alpha_func, this);
172
173   // set initial values
174   change_output_lines();
175
176   // allocate timers
177   m_scan_timer = device_timer_alloc(*this);
178   timer_adjust_periodic(m_scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(clock()));
179
180   // register for state saving
181   state_save_register_device_item(this, 0, m_inhibit);
182   state_save_register_device_item(this, 0, m_sense);
183   state_save_register_device_item(this, 0, m_drive);
184   state_save_register_device_item(this, 0, m_shift);
185   state_save_register_device_item(this, 0, m_control);
186   state_save_register_device_item(this, 0, m_da);
187   state_save_register_device_item(this, 0, m_next_da);
188   state_save_register_device_item(this, 0, m_rpt);
189   state_save_register_device_item(this, 0, m_next_rpt);
136190}
137191
138/***************************************************************************
139    IMPLEMENTATION
140***************************************************************************/
141192
142/*-------------------------------------------------
143    change_output_lines - change output line
144    state
145-------------------------------------------------*/
193//-------------------------------------------------
194//  device_timer - handler timer events
195//-------------------------------------------------
146196
147static void change_output_lines(running_device *device)
197void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
148198{
149   cdp1871_t *cdp1871 = get_safe_token(device);
199   change_output_lines();
200   clock_scan_counters();
201   detect_keypress();
202}
150203
151   if (cdp1871->next_da != cdp1871->da)
204
205//-------------------------------------------------
206//  change_output_lines - change output lines
207//-------------------------------------------------
208
209void cdp1871_device::change_output_lines()
210{
211   if (m_next_da != m_da)
152212   {
153      cdp1871->da = cdp1871->next_da;
213      m_da = m_next_da;
154214
155      devcb_call_write_line(&cdp1871->out_da_func, cdp1871->da);
215      devcb_call_write_line(&m_out_da_func, m_da);
156216   }
157217
158   if (cdp1871->next_rpt != cdp1871->rpt)
218   if (m_next_rpt != m_rpt)
159219   {
160      cdp1871->rpt = cdp1871->next_rpt;
220      m_rpt = m_next_rpt;
161221
162      devcb_call_write_line(&cdp1871->out_rpt_func, cdp1871->rpt);
222      devcb_call_write_line(&m_out_rpt_func, m_rpt);
163223   }
164224}
165225
166/*-------------------------------------------------
167    clock_scan_counters - clock the keyboard
168    scan counters
169-------------------------------------------------*/
170226
171static void clock_scan_counters(running_device *device)
172{
173   cdp1871_t *cdp1871 = get_safe_token(device);
227//-------------------------------------------------
228//  clock_scan_counters - clock the keyboard
229//   scan counters
230//-------------------------------------------------
174231
175   if (!cdp1871->inhibit)
232void cdp1871_device::clock_scan_counters()
233{
234   if (!m_inhibit)
176235   {
177      cdp1871->sense++;
236      m_sense++;
178237
179      if (cdp1871->sense == 8)
238      if (m_sense == 8)
180239      {
181         cdp1871->sense = 0;
182         cdp1871->drive++;
240         m_sense = 0;
241         m_drive++;
183242
184         if (cdp1871->drive == 11)
243         if (m_drive == 11)
185244         {
186            cdp1871->drive = 0;
245            m_drive = 0;
187246         }
188247      }
189248   }
190249}
191250
192/*-------------------------------------------------
193    detect_keypress - detect key press
194-------------------------------------------------*/
195251
196static void detect_keypress(running_device *device)
197{
198   cdp1871_t *cdp1871 = get_safe_token(device);
252//-------------------------------------------------
253//  detect_keypress - detect key press
254//-------------------------------------------------
199255
256void cdp1871_device::detect_keypress()
257{
200258   UINT8 data = 0;
201259
202   switch (cdp1871->drive)
203   {
204   case 0:      data = devcb_call_read8(&cdp1871->in_d1_func, 0);   break;
205   case 1:      data = devcb_call_read8(&cdp1871->in_d2_func, 0);   break;
206   case 2:      data = devcb_call_read8(&cdp1871->in_d3_func, 0);   break;
207   case 3:      data = devcb_call_read8(&cdp1871->in_d4_func, 0);   break;
208   case 4:      data = devcb_call_read8(&cdp1871->in_d5_func, 0);   break;
209   case 5:      data = devcb_call_read8(&cdp1871->in_d6_func, 0);   break;
210   case 6:      data = devcb_call_read8(&cdp1871->in_d7_func, 0);   break;
211   case 7:      data = devcb_call_read8(&cdp1871->in_d8_func, 0);   break;
212   case 8:      data = devcb_call_read8(&cdp1871->in_d9_func, 0);   break;
213   case 9:      data = devcb_call_read8(&cdp1871->in_d10_func, 0);   break;
214   case 10:   data = devcb_call_read8(&cdp1871->in_d11_func, 0);   break;
215   }
260   data = devcb_call_read8(&m_in_d_func[m_drive], 0);
216261
217   if (data == (1 << cdp1871->sense))
262   if (data == (1 << m_sense))
218263   {
219      if (!cdp1871->inhibit)
264      if (!m_inhibit)
220265      {
221         cdp1871->shift = devcb_call_read_line(&cdp1871->in_shift_func);
222         cdp1871->control = devcb_call_read_line(&cdp1871->in_control_func);
223         cdp1871->inhibit = 1;
224         cdp1871->next_da = ASSERT_LINE;
266         m_shift = devcb_call_read_line(&m_in_shift_func);
267         m_control = devcb_call_read_line(&m_in_control_func);
268         m_inhibit = true;
269         m_next_da = ASSERT_LINE;
225270      }
226271      else
227272      {
228         cdp1871->next_rpt = ASSERT_LINE;
273         m_next_rpt = ASSERT_LINE;
229274      }
230275   }
231276   else
232277   {
233      cdp1871->inhibit = 0;
234      cdp1871->next_rpt = CLEAR_LINE;
278      m_inhibit = false;
279      m_next_rpt = CLEAR_LINE;
235280   }
236281}
237282
238/*-------------------------------------------------
239    TIMER_CALLBACK( cdp1871_scan_tick )
240-------------------------------------------------*/
241283
242static TIMER_CALLBACK( cdp1871_scan_tick )
243{
244   running_device *device = (running_device *)ptr;
284//-------------------------------------------------
285//  data_r - keyboard data read
286//-------------------------------------------------
245287
246   change_output_lines(device);
247   clock_scan_counters(device);
248   detect_keypress(device);
249}
250
251/*-------------------------------------------------
252    cdp1871_data_r - interface retrieving
253    keyboard data
254-------------------------------------------------*/
255
256READ8_DEVICE_HANDLER( cdp1871_data_r )
288READ8_MEMBER( cdp1871_device::data_r )
257289{
258   cdp1871_t *cdp1871 = get_safe_token(device);
259
260290   int table = 0;
261   int alpha = devcb_call_read_line(&cdp1871->in_alpha_func);
291   int alpha = devcb_call_read_line(&m_in_alpha_func);
262292
263   if (cdp1871->control) table = 3; else if (cdp1871->shift) table = 2; else if (alpha) table = 1;
293   if (m_control) table = 3; else if (m_shift) table = 2; else if (alpha) table = 1;
264294
265295   // reset DA on next TPB
296   m_next_da = CLEAR_LINE;
266297
267   cdp1871->next_da = CLEAR_LINE;
268
269   return CDP1871_KEY_CODES[table][cdp1871->drive][cdp1871->sense];
298   return CDP1871_KEY_CODES[table][m_drive][m_sense];
270299}
271300
272/*-------------------------------------------------
273    cdp1871_da_r - keyboard data available
274-------------------------------------------------*/
275301
276READ_LINE_DEVICE_HANDLER( cdp1871_da_r )
277{
278   cdp1871_t *cdp1871 = get_safe_token(device);
302//-------------------------------------------------
303//  da_r - data available
304//-------------------------------------------------
279305
280   return cdp1871->da;
281}
282
283/*-------------------------------------------------
284    cdp1871_rpt_r - keyboard repeat
285-------------------------------------------------*/
286
287READ_LINE_DEVICE_HANDLER( cdp1871_rpt_r )
306READ_LINE_MEMBER( cdp1871_device::da_r )
288307{
289   cdp1871_t *cdp1871 = get_safe_token(device);
290
291   return cdp1871->rpt;
308   return m_da;
292309}
293310
294/*-------------------------------------------------
295    DEVICE_START( cdp1871 )
296-------------------------------------------------*/
297311
298static DEVICE_START( cdp1871 )
299{
300   cdp1871_t *cdp1871 = get_safe_token(device);
301   const cdp1871_interface *intf = get_interface(device);
312//-------------------------------------------------
313//  rpt_r - keyboard repeat
314//-------------------------------------------------
302315
303   /* resolve callbacks */
304   devcb_resolve_write_line(&cdp1871->out_da_func, &intf->out_da_func, device);
305   devcb_resolve_write_line(&cdp1871->out_rpt_func, &intf->out_rpt_func, device);
306   devcb_resolve_read8(&cdp1871->in_d1_func, &intf->in_d1_func, device);
307   devcb_resolve_read8(&cdp1871->in_d2_func, &intf->in_d2_func, device);
308   devcb_resolve_read8(&cdp1871->in_d3_func, &intf->in_d3_func, device);
309   devcb_resolve_read8(&cdp1871->in_d4_func, &intf->in_d4_func, device);
310   devcb_resolve_read8(&cdp1871->in_d5_func, &intf->in_d5_func, device);
311   devcb_resolve_read8(&cdp1871->in_d6_func, &intf->in_d6_func, device);
312   devcb_resolve_read8(&cdp1871->in_d7_func, &intf->in_d7_func, device);
313   devcb_resolve_read8(&cdp1871->in_d8_func, &intf->in_d8_func, device);
314   devcb_resolve_read8(&cdp1871->in_d9_func, &intf->in_d9_func, device);
315   devcb_resolve_read8(&cdp1871->in_d10_func, &intf->in_d10_func, device);
316   devcb_resolve_read8(&cdp1871->in_d11_func, &intf->in_d11_func, device);
317   devcb_resolve_read_line(&cdp1871->in_shift_func, &intf->in_shift_func, device);
318   devcb_resolve_read_line(&cdp1871->in_control_func, &intf->in_control_func, device);
319   devcb_resolve_read_line(&cdp1871->in_alpha_func, &intf->in_alpha_func, device);
320
321   /* set initial values */
322   cdp1871->next_da = CLEAR_LINE;
323   cdp1871->next_rpt = CLEAR_LINE;
324   change_output_lines(device);
325
326   /* create the timers */
327   cdp1871->scan_timer = timer_alloc(device->machine, cdp1871_scan_tick, (void *)device);
328   timer_adjust_periodic(cdp1871->scan_timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock()));
329
330   /* register for state saving */
331   state_save_register_device_item(device, 0, cdp1871->inhibit);
332   state_save_register_device_item(device, 0, cdp1871->sense);
333   state_save_register_device_item(device, 0, cdp1871->drive);
334   state_save_register_device_item(device, 0, cdp1871->shift);
335   state_save_register_device_item(device, 0, cdp1871->control);
336   state_save_register_device_item(device, 0, cdp1871->da);
337   state_save_register_device_item(device, 0, cdp1871->next_da);
338   state_save_register_device_item(device, 0, cdp1871->rpt);
339   state_save_register_device_item(device, 0, cdp1871->next_rpt);
340}
341
342/*-------------------------------------------------
343    DEVICE_GET_INFO( cdp1871 )
344-------------------------------------------------*/
345
346DEVICE_GET_INFO( cdp1871 )
316READ_LINE_MEMBER( cdp1871_device::rpt_r )
347317{
348   switch (state)
349   {
350      /* --- the following bits of info are returned as 64-bit signed integers --- */
351      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(cdp1871_t);            break;
352      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
353
354      /* --- the following bits of info are returned as pointers to data or functions --- */
355      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(cdp1871);   break;
356      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
357      case DEVINFO_FCT_RESET:                     /* Nothing */                        break;
358
359      /* --- the following bits of info are returned as NULL-terminated strings --- */
360      case DEVINFO_STR_NAME:                     strcpy(info->s, "RCA CDP1871");            break;
361      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "RCA CDP1800");            break;
362      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
363      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
364      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
365   }
318   return m_rpt;
366319}
367
368DEFINE_LEGACY_DEVICE(CDP1871, cdp1871);
src/mess/machine/cdp1871.h
r9419r9420
3030
3131**********************************************************************/
3232
33#pragma once
34
3335#ifndef __CDP1871__
3436#define __CDP1871__
3537
36#include "devcb.h"
38#include "emu.h"
3739
38/***************************************************************************
39    MACROS / CONSTANTS
40***************************************************************************/
4140
42DECLARE_LEGACY_DEVICE(CDP1871, cdp1871);
4341
42//**************************************************************************
43//   MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
4453#define MDRV_CDP1871_ADD(_tag, _intrf, _clock) \
4554   MDRV_DEVICE_ADD(_tag, CDP1871, _clock) \
4655   MDRV_DEVICE_CONFIG(_intrf)
r9419r9420
4857#define CDP1871_INTERFACE(name) \
4958   const cdp1871_interface (name)=
5059
51/***************************************************************************
52    TYPE DEFINITIONS
53***************************************************************************/
5460
55typedef struct _cdp1871_interface cdp1871_interface;
56struct _cdp1871_interface
61
62//**************************************************************************
63//   TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> cdp1871_interface
67
68struct cdp1871_interface
5769{
5870   devcb_read8         in_d1_func;
5971   devcb_read8         in_d2_func;
r9419r9420
7183   devcb_read_line      in_control_func;
7284   devcb_read_line      in_alpha_func;
7385
74   /* this gets called for every change of the DA pin (pin 33) */
86   // this gets called for every change of the DA pin (pin 33)
7587   devcb_write_line   out_da_func;
7688
77   /* this gets called for every change of the RPT pin (pin 35) */
89   // this gets called for every change of the RPT pin (pin 35)
7890   devcb_write_line   out_rpt_func;
7991};
8092
81/***************************************************************************
82    PROTOTYPES
83***************************************************************************/
8493
85/* keyboard data */
86READ8_DEVICE_HANDLER( cdp1871_data_r );
94// ======================> cdp1871_device_config
8795
88/* keyboard status */
89READ_LINE_DEVICE_HANDLER( cdp1871_da_r );
90READ_LINE_DEVICE_HANDLER( cdp1871_rpt_r );
96class cdp1871_device_config :   public device_config,
97                                public cdp1871_interface
98{
99    friend class cdp1871_device;
91100
101    // construction/destruction
102    cdp1871_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
103
104public:
105    // allocators
106    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
107    virtual device_t *alloc_device(running_machine &machine) const;
108
109protected:
110    // device_config overrides
111    virtual void device_config_complete();
112};
113
114
115// ======================> cdp1871_device
116
117class cdp1871_device :  public device_t
118{
119    friend class cdp1871_device_config;
120
121    // construction/destruction
122    cdp1871_device(running_machine &_machine, const cdp1871_device_config &_config);
123
124public:
125    DECLARE_READ8_MEMBER( data_r );
126
127   DECLARE_READ_LINE_MEMBER( da_r );
128   DECLARE_READ_LINE_MEMBER( rpt_r );
129
130protected:
131    // device-level overrides
132    virtual void device_start();
133   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
134
135   void change_output_lines();
136   void clock_scan_counters();
137   void detect_keypress();
138
139private:
140   devcb_resolved_write_line      m_out_da_func;
141   devcb_resolved_write_line      m_out_rpt_func;
142   devcb_resolved_read8         m_in_d_func[11];
143   devcb_resolved_read_line      m_in_shift_func;
144   devcb_resolved_read_line      m_in_control_func;
145   devcb_resolved_read_line      m_in_alpha_func;
146
147   bool m_inhibit;               // scan counter clock inhibit
148   int m_sense;               // sense input scan counter
149   int m_drive;               // modifier inputs
150
151   int m_shift;               // latched shift modifier
152   int m_control;               // latched control modifier
153
154   int m_da;                  // data available flag
155   int m_next_da;               // next value of data available flag
156   int m_rpt;                  // repeat flag
157   int m_next_rpt;               // next value of repeat flag
158
159   // timers
160   emu_timer *m_scan_timer;      // keyboard scan timer
161
162   const cdp1871_device_config &m_config;
163};
164
165
166// device type definition
167extern const device_type CDP1871;
168
169
170
92171#endif
src/mess/machine/i8155.c
r9419r9420
1515
1616*/
1717
18#include "emu.h"
1819#include "i8155.h"
1920
20/***************************************************************************
21    PARAMETERS
22***************************************************************************/
2321
22
23//**************************************************************************
24//   MACROS / CONSTANTS
25//**************************************************************************
26
2427#define LOG 0
2528
2629enum
2730{
28   I8155_REGISTER_COMMAND = 0,
29   I8155_REGISTER_STATUS = 0,
30   I8155_REGISTER_PORT_A,
31   I8155_REGISTER_PORT_B,
32   I8155_REGISTER_PORT_C,
33   I8155_REGISTER_TIMER_LOW,
34   I8155_REGISTER_TIMER_HIGH
31   REGISTER_COMMAND = 0,
32   REGISTER_STATUS = 0,
33   REGISTER_PORT_A,
34   REGISTER_PORT_B,
35   REGISTER_PORT_C,
36   REGISTER_TIMER_LOW,
37   REGISTER_TIMER_HIGH
3538};
3639
3740enum
3841{
39   I8155_PORT_A = 0,
40   I8155_PORT_B,
41   I8155_PORT_C,
42   I8155_PORT_COUNT
42   PORT_A = 0,
43   PORT_B,
44   PORT_C,
45   PORT_COUNT
4346};
4447
4548enum
4649{
47   I8155_PORT_MODE_INPUT = 0,
48   I8155_PORT_MODE_OUTPUT,
49   I8155_PORT_MODE_STROBED_PORT_A,   /* not supported */
50   I8155_PORT_MODE_STROBED         /* not supported */
50   PORT_MODE_INPUT = 0,
51   PORT_MODE_OUTPUT,
52   PORT_MODE_STROBED_PORT_A,   // not supported
53   PORT_MODE_STROBED         // not supported
5154};
5255
53#define I8155_COMMAND_PA               0x01
54#define I8155_COMMAND_PB               0x02
55#define I8155_COMMAND_PC_MASK            0x0c
56#define I8155_COMMAND_PC_ALT_1            0x00
57#define I8155_COMMAND_PC_ALT_2            0x0c
58#define I8155_COMMAND_PC_ALT_3            0x04   /* not supported */
59#define I8155_COMMAND_PC_ALT_4            0x08   /* not supported */
60#define I8155_COMMAND_IEA               0x10   /* not supported */
61#define I8155_COMMAND_IEB               0x20   /* not supported */
62#define I8155_COMMAND_TM_MASK            0xc0
63#define I8155_COMMAND_TM_NOP            0x00
64#define I8155_COMMAND_TM_STOP            0x40
65#define I8155_COMMAND_TM_STOP_AFTER_TC      0x80
66#define I8155_COMMAND_TM_START            0xc0
56#define COMMAND_PA               0x01
57#define COMMAND_PB               0x02
58#define COMMAND_PC_MASK            0x0c
59#define COMMAND_PC_ALT_1         0x00
60#define COMMAND_PC_ALT_2         0x0c
61#define COMMAND_PC_ALT_3         0x04   // not supported
62#define COMMAND_PC_ALT_4         0x08   // not supported
63#define COMMAND_IEA               0x10   // not supported
64#define COMMAND_IEB               0x20   // not supported
65#define COMMAND_TM_MASK            0xc0
66#define COMMAND_TM_NOP            0x00
67#define COMMAND_TM_STOP            0x40
68#define COMMAND_TM_STOP_AFTER_TC   0x80
69#define COMMAND_TM_START         0xc0
6770
68#define I8155_STATUS_INTR_A               0x01   /* not supported */
69#define I8155_STATUS_A_BF               0x02   /* not supported */
70#define I8155_STATUS_INTE_A               0x04   /* not supported */
71#define I8155_STATUS_INTR_B               0x08   /* not supported */
72#define I8155_STATUS_B_BF               0x10   /* not supported */
73#define I8155_STATUS_INTE_B               0x20   /* not supported */
74#define I8155_STATUS_TIMER               0x40
71#define STATUS_INTR_A            0x01   // not supported
72#define STATUS_A_BF               0x02   // not supported
73#define STATUS_INTE_A            0x04   // not supported
74#define STATUS_INTR_B            0x08   // not supported
75#define STATUS_B_BF               0x10   // not supported
76#define STATUS_INTE_B            0x20   // not supported
77#define STATUS_TIMER            0x40
7578
76#define I8155_TIMER_MODE_MASK            0xc0
77#define I8155_TIMER_MODE_LOW            0x00
78#define I8155_TIMER_MODE_SQUARE_WAVE      0x40
79#define I8155_TIMER_MODE_SINGLE_PULSE      0x80
80#define I8155_TIMER_MODE_AUTOMATIC_RELOAD   0xc0
79#define TIMER_MODE_MASK            0xc0
80#define TIMER_MODE_LOW            0x00
81#define TIMER_MODE_SQUARE_WAVE      0x40
82#define TIMER_MODE_SINGLE_PULSE      0x80
83#define TIMER_MODE_AUTOMATIC_RELOAD   0xc0
8184
82/***************************************************************************
83    TYPE DEFINITIONS
84***************************************************************************/
8585
86typedef struct _i8155_t i8155_t;
87struct _i8155_t
86
87//**************************************************************************
88//  GLOBAL VARIABLES
89//**************************************************************************
90
91// devices
92const device_type I8155 = i8155_device_config::static_alloc_device_config;
93
94
95// default address map
96static ADDRESS_MAP_START( i8155, 0, 8 )
97   AM_RANGE(0x00, 0xff) AM_RAM
98ADDRESS_MAP_END
99
100
101
102//**************************************************************************
103//  DEVICE CONFIGURATION
104//**************************************************************************
105
106//-------------------------------------------------
107//  i8155_device_config - constructor
108//-------------------------------------------------
109
110i8155_device_config::i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
111   : device_config(mconfig, static_alloc_device_config, "Intel 8155", tag, owner, clock),
112     device_config_memory_interface(mconfig, *this),
113     m_space_config("ram", ENDIANNESS_LITTLE, 8, 8, 0, NULL, *ADDRESS_MAP_NAME(i8155))
88114{
89   devcb_resolved_read8      in_port_func[I8155_PORT_COUNT];
90   devcb_resolved_write8      out_port_func[I8155_PORT_COUNT];
91   devcb_resolved_write_line   out_to_func;
115}
92116
93   /* memory */
94   UINT8 ram[256];            /* RAM */
95117
96   /* registers */
97   UINT8 command;            /* command register */
98   UINT8 status;            /* status register */
99   UINT8 output[3];         /* output latches */
118//-------------------------------------------------
119//  static_alloc_device_config - allocate a new
120//  configuration object
121//-------------------------------------------------
100122
101   /* counter */
102   UINT16 count_length;      /* count length register */
103   UINT16 counter;            /* counter register */
104   int to;                  /* timer output */
123device_config *i8155_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
124{
125   return global_alloc(i8155_device_config(mconfig, tag, owner, clock));
126}
105127
106   /* timers */
107   emu_timer *timer;         /* counter timer */
108};
109128
110/***************************************************************************
111    INLINE FUNCTIONS
112***************************************************************************/
129//-------------------------------------------------
130//  alloc_device - allocate a new device object
131//-------------------------------------------------
113132
114INLINE i8155_t *get_safe_token(running_device *device)
133device_t *i8155_device_config::alloc_device(running_machine &machine) const
115134{
116   assert(device != NULL);
117   return (i8155_t *)downcast<legacy_device_base *>(device)->token();
135   return auto_alloc(&machine, i8155_device(machine, *this));
118136}
119137
120INLINE const i8155_interface *get_interface(running_device *device)
138
139//-------------------------------------------------
140//  memory_space_config - return a description of
141//  any address spaces owned by this device
142//-------------------------------------------------
143
144const address_space_config *i8155_device_config::memory_space_config(int spacenum) const
121145{
122   assert(device != NULL);
123   assert(device->type() == I8155);
124   return (const i8155_interface *) device->baseconfig().static_config();
146   return (spacenum == 0) ? &m_space_config : NULL;
125147}
126148
127INLINE UINT8 get_timer_mode(i8155_t *i8155)
149
150//-------------------------------------------------
151//  device_config_complete - perform any
152//  operations now that the configuration is
153//  complete
154//-------------------------------------------------
155
156void i8155_device_config::device_config_complete()
128157{
129   return (i8155->count_length >> 8) & I8155_TIMER_MODE_MASK;
158   // inherit a copy of the static data
159   const i8155_interface *intf = reinterpret_cast<const i8155_interface *>(static_config());
160   if (intf != NULL)
161      *static_cast<i8155_interface *>(this) = *intf;
162
163   // or initialize to defaults if none provided
164   else
165   {
166      memset(&in_pa_func, 0, sizeof(in_pa_func));
167      memset(&out_pa_func, 0, sizeof(out_pa_func));
168      memset(&in_pb_func, 0, sizeof(in_pb_func));
169      memset(&out_pb_func, 0, sizeof(out_pb_func));
170      memset(&in_pc_func, 0, sizeof(in_pc_func));
171      memset(&out_pc_func, 0, sizeof(out_pc_func));
172      memset(&out_to_func, 0, sizeof(out_to_func));
173   }
130174}
131175
132INLINE void timer_output(i8155_t *i8155)
176
177
178//**************************************************************************
179//  INLINE HELPERS
180//**************************************************************************
181
182inline UINT8 i8155_device::get_timer_mode()
133183{
134   devcb_call_write_line(&i8155->out_to_func, i8155->to);
184   return (m_count_length >> 8) & TIMER_MODE_MASK;
185}
135186
136   if (LOG) logerror("8155 Timer Output: %u\n", i8155->to);
187inline void i8155_device::timer_output()
188{
189   devcb_call_write_line(&m_out_to_func, m_to);
190
191   if (LOG) logerror("8155 '%s' Timer Output: %u\n", tag(), m_to);
137192}
138193
139INLINE void pulse_timer_output(i8155_t *i8155)
194inline void i8155_device::pulse_timer_output()
140195{
141   i8155->to = 0; timer_output(i8155);
142   i8155->to = 1; timer_output(i8155);
196   m_to = 0; timer_output();
197   m_to = 1; timer_output();
143198}
144199
145INLINE int get_port_mode(i8155_t *i8155, int port)
200inline int i8155_device::get_port_mode(int port)
146201{
147202   int mode = -1;
148203
149204   switch (port)
150205   {
151   case I8155_PORT_A:
152      mode = (i8155->command & I8155_COMMAND_PA) ? I8155_PORT_MODE_OUTPUT : I8155_PORT_MODE_INPUT;
206   case PORT_A:
207      mode = (m_command & COMMAND_PA) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT;
153208      break;
154209
155   case I8155_PORT_B:
156      mode = (i8155->command & I8155_COMMAND_PB) ? I8155_PORT_MODE_OUTPUT : I8155_PORT_MODE_INPUT;
210   case PORT_B:
211      mode = (m_command & COMMAND_PB) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT;
157212      break;
158213
159   case I8155_PORT_C:
160      switch (i8155->command & I8155_COMMAND_PC_MASK)
214   case PORT_C:
215      switch (m_command & COMMAND_PC_MASK)
161216      {
162      case I8155_COMMAND_PC_ALT_1: mode = I8155_PORT_MODE_INPUT;         break;
163      case I8155_COMMAND_PC_ALT_2: mode = I8155_PORT_MODE_OUTPUT;         break;
164      case I8155_COMMAND_PC_ALT_3: mode = I8155_PORT_MODE_STROBED_PORT_A; break;
165      case I8155_COMMAND_PC_ALT_4: mode = I8155_PORT_MODE_STROBED;      break;
217      case COMMAND_PC_ALT_1: mode = PORT_MODE_INPUT;         break;
218      case COMMAND_PC_ALT_2: mode = PORT_MODE_OUTPUT;         break;
219      case COMMAND_PC_ALT_3: mode = PORT_MODE_STROBED_PORT_A; break;
220      case COMMAND_PC_ALT_4: mode = PORT_MODE_STROBED;      break;
166221      }
167222      break;
168223   }
r9419r9420
170225   return mode;
171226}
172227
173INLINE UINT8 read_port(i8155_t *i8155, int port)
228inline UINT8 i8155_device::read_port(int port)
174229{
175230   UINT8 data = 0;
176231
177232   switch (port)
178233   {
179   case I8155_PORT_A:
180   case I8155_PORT_B:
181      switch (get_port_mode(i8155, port))
234   case PORT_A:
235   case PORT_B:
236      switch (get_port_mode(port))
182237      {
183      case I8155_PORT_MODE_INPUT:
184         data = devcb_call_read8(&i8155->in_port_func[port], 0);
238      case PORT_MODE_INPUT:
239         data = devcb_call_read8(&m_in_port_func[port], 0);
185240         break;
186241
187      case I8155_PORT_MODE_OUTPUT:
188         data = i8155->output[port];
242      case PORT_MODE_OUTPUT:
243         data = m_output[port];
189244         break;
190245      }
191246      break;
192247
193   case I8155_PORT_C:
194      switch (get_port_mode(i8155, I8155_PORT_C))
248   case PORT_C:
249      switch (get_port_mode(PORT_C))
195250      {
196      case I8155_PORT_MODE_INPUT:
197         data = devcb_call_read8(&i8155->in_port_func[port], 0) & 0x3f;
251      case PORT_MODE_INPUT:
252         data = devcb_call_read8(&m_in_port_func[port], 0) & 0x3f;
198253         break;
199254
200      case I8155_PORT_MODE_OUTPUT:
201         data = i8155->output[port] & 0x3f;
255      case PORT_MODE_OUTPUT:
256         data = m_output[port] & 0x3f;
202257         break;
203258
204259      default:
205         logerror("8155 Unsupported Port C mode!\n");
260         logerror("8155 '%s' Unsupported Port C mode!\n", tag());
206261      }
207262      break;
208263   }
r9419r9420
210265   return data;
211266}
212267
213INLINE void write_port(i8155_t *i8155, int port, UINT8 data)
268inline void i8155_device::write_port(int port, UINT8 data)
214269{
215   switch (get_port_mode(i8155, port))
270   switch (get_port_mode(port))
216271   {
217   case I8155_PORT_MODE_OUTPUT:
218      i8155->output[port] = data;
219      devcb_call_write8(&i8155->out_port_func[port], 0, i8155->output[port]);
272   case PORT_MODE_OUTPUT:
273      m_output[port] = data;
274      devcb_call_write8(&m_out_port_func[port], 0, m_output[port]);
220275      break;
221276   }
222277}
223278
224/***************************************************************************
225    IMPLEMENTATION
226***************************************************************************/
227279
228/*-------------------------------------------------
229    TIMER_CALLBACK( counter_tick )
230-------------------------------------------------*/
280//**************************************************************************
281//  LIVE DEVICE
282//**************************************************************************
231283
232static TIMER_CALLBACK( counter_tick )
284//-------------------------------------------------
285//  i8155_device - constructor
286//-------------------------------------------------
287
288i8155_device::i8155_device(running_machine &_machine, const i8155_device_config &config)
289    : device_t(_machine, config),
290     device_memory_interface(_machine, config, *this),
291      m_config(config)
233292{
234   running_device *device = (running_device *)ptr;
235   i8155_t *i8155 = get_safe_token(device);
236293
237   /* count down */
238   i8155->counter--;
294}
239295
240   if (get_timer_mode(i8155) == I8155_TIMER_MODE_LOW)
296
297//-------------------------------------------------
298//  device_start - device-specific startup
299//-------------------------------------------------
300
301void i8155_device::device_start()
302{
303   // resolve callbacks
304   devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this);
305   devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this);
306   devcb_resolve_read8(&m_in_port_func[2], &m_config.in_pc_func, this);
307   devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this);
308   devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this);
309   devcb_resolve_write8(&m_out_port_func[2], &m_config.out_pc_func, this);
310   devcb_resolve_write_line(&m_out_to_func, &m_config.out_to_func, this);
311
312   // allocate timers
313   m_timer = device_timer_alloc(*this);
314
315   // register for state saving
316   state_save_register_device_item(this, 0, m_command);
317   state_save_register_device_item(this, 0, m_status);
318   state_save_register_device_item_array(this, 0, m_output);
319   state_save_register_device_item(this, 0, m_count_length);
320   state_save_register_device_item(this, 0, m_counter);
321   state_save_register_device_item(this, 0, m_to);
322}
323
324
325//-------------------------------------------------
326//  device_reset - device-specific reset
327//-------------------------------------------------
328
329void i8155_device::device_reset()
330{
331   // clear output registers
332   m_output[PORT_A] = 0;
333   m_output[PORT_B] = 0;
334   m_output[PORT_C] = 0;
335
336   // set ports to input mode
337   register_w(REGISTER_COMMAND, m_command & ~(COMMAND_PA | COMMAND_PB | COMMAND_PC_MASK));
338
339   // clear timer flag
340   m_status &= ~STATUS_TIMER;
341
342   // stop counting
343   timer_enable(m_timer, 0);
344
345   // clear timer output
346   m_to = 1;
347   timer_output();
348}
349
350
351//-------------------------------------------------
352//  device_timer - handler timer events
353//-------------------------------------------------
354
355void i8155_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
356{
357   // count down
358   m_counter--;
359
360   if (get_timer_mode() == TIMER_MODE_LOW)
241361   {
242      /* pulse on every count */
243      pulse_timer_output(i8155);
362      // pulse on every count
363      pulse_timer_output();
244364   }
245365
246   if (i8155->counter == 0)
366   if (m_counter == 0)
247367   {
248      if (LOG) logerror("8155 Timer Count Reached\n");
368      if (LOG) logerror("8155 '%s' Timer Count Reached\n", tag());
249369
250      switch (i8155->command & I8155_COMMAND_TM_MASK)
370      switch (m_command & COMMAND_TM_MASK)
251371      {
252      case I8155_COMMAND_TM_STOP_AFTER_TC:
253         /* stop timer */
254         timer_enable(i8155->timer, 0);
372      case COMMAND_TM_STOP_AFTER_TC:
373         // stop timer
374         timer_enable(m_timer, 0);
255375
256         if (LOG) logerror("8155 Timer Stopped\n");
376         if (LOG) logerror("8155 '%s' Timer Stopped\n", tag());
257377         break;
258378      }
259379
260      switch (get_timer_mode(i8155))
380      switch (get_timer_mode())
261381      {
262      case I8155_TIMER_MODE_SQUARE_WAVE:
263         /* toggle timer output */
264         i8155->to = !i8155->to;
265         timer_output(i8155);
382      case TIMER_MODE_SQUARE_WAVE:
383         // toggle timer output
384         m_to = !m_to;
385         timer_output();
266386         break;
267387
268      case I8155_TIMER_MODE_SINGLE_PULSE:
269         /* single pulse upon TC being reached */
270         pulse_timer_output(i8155);
388      case TIMER_MODE_SINGLE_PULSE:
389         // single pulse upon TC being reached
390         pulse_timer_output();
271391
272         /* clear timer mode setting */
273         i8155->command &= ~I8155_COMMAND_TM_MASK;
392         // clear timer mode setting
393         m_command &= ~COMMAND_TM_MASK;
274394         break;
275395
276      case I8155_TIMER_MODE_AUTOMATIC_RELOAD:
277         /* automatic reload, i.e. single pulse every time TC is reached */
278         pulse_timer_output(i8155);
396      case TIMER_MODE_AUTOMATIC_RELOAD:
397         // automatic reload, i.e. single pulse every time TC is reached
398         pulse_timer_output();
279399         break;
280400      }
281401
282      /* set timer flag */
283      i8155->status |= I8155_STATUS_TIMER;
402      // set timer flag
403      m_status |= STATUS_TIMER;
284404
285      /* reload timer counter */
286      i8155->counter = i8155->count_length & 0x3fff;
405      // reload timer counter
406      m_counter = m_count_length & 0x3fff;
287407   }
288408}
289409
290/*-------------------------------------------------
291    i8155_register_r - register read
292-------------------------------------------------*/
293410
294READ8_DEVICE_HANDLER( i8155_r )
411//-------------------------------------------------
412//  io_r - register read
413//-------------------------------------------------
414
415READ8_MEMBER( i8155_device::io_r )
295416{
296   i8155_t *i8155 = get_safe_token(device);
297
298417   UINT8 data = 0;
299418
300419   switch (offset & 0x03)
301420   {
302   case I8155_REGISTER_STATUS:
303      data = i8155->status;
421   case REGISTER_STATUS:
422      data = m_status;
304423
305      /* clear timer flag */
306      i8155->status &= ~I8155_STATUS_TIMER;
424      // clear timer flag
425      m_status &= ~STATUS_TIMER;
307426      break;
308427
309   case I8155_REGISTER_PORT_A:
310      data = read_port(i8155, I8155_PORT_A);
428   case REGISTER_PORT_A:
429      data = read_port(PORT_A);
311430      break;
312431
313   case I8155_REGISTER_PORT_B:
314      data = read_port(i8155, I8155_PORT_B);
432   case REGISTER_PORT_B:
433      data = read_port(PORT_B);
315434      break;
316435
317   case I8155_REGISTER_PORT_C:
318      data = read_port(i8155, I8155_PORT_C);
436   case REGISTER_PORT_C:
437      data = read_port(PORT_C);
319438      break;
320439   }
321440
322441   return data;
323442}
324443
325/*-------------------------------------------------
326    i8155_register_w - register write
327-------------------------------------------------*/
328444
329WRITE8_DEVICE_HANDLER( i8155_w )
445//-------------------------------------------------
446//  register_w - register write
447//-------------------------------------------------
448
449void i8155_device::register_w(int offset, UINT8 data)
330450{
331   i8155_t *i8155 = get_safe_token(device);
332
333451   switch (offset & 0x07)
334452   {
335   case I8155_REGISTER_COMMAND:
336      i8155->command = data;
453   case REGISTER_COMMAND:
454      m_command = data;
337455
338      if (LOG) logerror("8155 Port A Mode: %s\n", (data & I8155_COMMAND_PA) ? "output" : "input");
339      if (LOG) logerror("8155 Port B Mode: %s\n", (data & I8155_COMMAND_PB) ? "output" : "input");
456      if (LOG) logerror("8155 '%s' Port A Mode: %s\n", tag(), (data & COMMAND_PA) ? "output" : "input");
457      if (LOG) logerror("8155 '%s' Port B Mode: %s\n", tag(), (data & COMMAND_PB) ? "output" : "input");
340458
341      if (LOG) logerror("8155 Port A Interrupt: %s\n", (data & I8155_COMMAND_IEA) ? "enabled" : "disabled");
342      if (LOG) logerror("8155 Port B Interrupt: %s\n", (data & I8155_COMMAND_IEB) ? "enabled" : "disabled");
459      if (LOG) logerror("8155 '%s' Port A Interrupt: %s\n", tag(), (data & COMMAND_IEA) ? "enabled" : "disabled");
460      if (LOG) logerror("8155 '%s' Port B Interrupt: %s\n", tag(), (data & COMMAND_IEB) ? "enabled" : "disabled");
343461
344      switch (data & I8155_COMMAND_PC_MASK)
462      switch (data & COMMAND_PC_MASK)
345463      {
346      case I8155_COMMAND_PC_ALT_1:
347         if (LOG) logerror("8155 Port C Mode: Alt 1\n");
464      case COMMAND_PC_ALT_1:
465         if (LOG) logerror("8155 '%s' Port C Mode: Alt 1\n", tag());
348466         break;
349467
350      case I8155_COMMAND_PC_ALT_2:
351         if (LOG) logerror("8155 Port C Mode: Alt 2\n");
468      case COMMAND_PC_ALT_2:
469         if (LOG) logerror("8155 '%s' Port C Mode: Alt 2\n", tag());
352470         break;
353471
354      case I8155_COMMAND_PC_ALT_3:
355         if (LOG) logerror("8155 Port C Mode: Alt 3\n");
472      case COMMAND_PC_ALT_3:
473         if (LOG) logerror("8155 '%s' Port C Mode: Alt 3\n", tag());
356474         break;
357475
358      case I8155_COMMAND_PC_ALT_4:
359         if (LOG) logerror("8155 Port C Mode: Alt 4\n");
476      case COMMAND_PC_ALT_4:
477         if (LOG) logerror("8155 '%s' Port C Mode: Alt 4\n", tag());
360478         break;
361479      }
362480
363      switch (data & I8155_COMMAND_TM_MASK)
481      switch (data & COMMAND_TM_MASK)
364482      {
365      case I8155_COMMAND_TM_NOP:
366         /* do not affect counter operation */
483      case COMMAND_TM_NOP:
484         // do not affect counter operation
367485         break;
368486
369      case I8155_COMMAND_TM_STOP:
370         /* NOP if timer has not started, stop counting if the timer is running */
371         if (LOG) logerror("8155 Timer Command: Stop\n");
372         timer_enable(i8155->timer, 0);
487      case COMMAND_TM_STOP:
488         // NOP if timer has not started, stop counting if the timer is running
489         if (LOG) logerror("8155 '%s' Timer Command: Stop\n", tag());
490         timer_enable(m_timer, 0);
373491         break;
374492
375      case I8155_COMMAND_TM_STOP_AFTER_TC:
376         /* stop immediately after present TC is reached (NOP if timer has not started) */
377         if (LOG) logerror("8155 Timer Command: Stop after TC\n");
493      case COMMAND_TM_STOP_AFTER_TC:
494         // stop immediately after present TC is reached (NOP if timer has not started)
495         if (LOG) logerror("8155 '%s' Timer Command: Stop after TC\n", tag());
378496         break;
379497
380      case I8155_COMMAND_TM_START:
381         if (LOG) logerror("8155 Timer Command: Start\n");
498      case COMMAND_TM_START:
499         if (LOG) logerror("8155 '%s' Timer Command: Start\n", tag());
382500
383         if (timer_enabled(i8155->timer))
501         if (timer_enabled(m_timer))
384502         {
385            /* if timer is running, start the new mode and CNT length immediately after present TC is reached */
503            // if timer is running, start the new mode and CNT length immediately after present TC is reached
386504         }
387505         else
388506         {
389            /* load mode and CNT length and start immediately after loading (if timer is not running) */
390            i8155->counter = i8155->count_length;
391            timer_adjust_periodic(i8155->timer, attotime_zero, 0, ATTOTIME_IN_HZ(device->clock()));
507            // load mode and CNT length and start immediately after loading (if timer is not running)
508            m_counter = m_count_length;
509            timer_adjust_periodic(m_timer, attotime_zero, 0, ATTOTIME_IN_HZ(clock()));
392510         }
393511         break;
394512      }
395513      break;
396514
397   case I8155_REGISTER_PORT_A:
398      write_port(i8155, I8155_PORT_A, data);
515   case REGISTER_PORT_A:
516      write_port(PORT_A, data);
399517      break;
400518
401   case I8155_REGISTER_PORT_B:
402      write_port(i8155, I8155_PORT_B, data);
519   case REGISTER_PORT_B:
520      write_port(PORT_B, data);
403521      break;
404522
405   case I8155_REGISTER_PORT_C:
406      write_port(i8155, I8155_PORT_C, data);
523   case REGISTER_PORT_C:
524      write_port(PORT_C, data);
407525      break;
408526
409   case I8155_REGISTER_TIMER_LOW:
410      i8155->count_length = (i8155->count_length & 0xff00) | data;
411      if (LOG) logerror("8155 Count Length Low: %04x\n", i8155->count_length);
527   case REGISTER_TIMER_LOW:
528      m_count_length = (m_count_length & 0xff00) | data;
529      if (LOG) logerror("8155 '%s' Count Length Low: %04x\n", tag(), m_count_length);
412530      break;
413531
414   case I8155_REGISTER_TIMER_HIGH:
415      i8155->count_length = (data << 8) | (i8155->count_length & 0xff);
416      if (LOG) logerror("8155 Count Length High: %04x\n", i8155->count_length);
532   case REGISTER_TIMER_HIGH:
533      m_count_length = (data << 8) | (m_count_length & 0xff);
534      if (LOG) logerror("8155 '%s' Count Length High: %04x\n", tag(), m_count_length);
417535
418      switch (data & I8155_TIMER_MODE_MASK)
536      switch (data & TIMER_MODE_MASK)
419537      {
420      case I8155_TIMER_MODE_LOW:
421         /* puts out LOW during second half of count */
422         if (LOG) logerror("8155 Timer Mode: LOW\n");
538      case TIMER_MODE_LOW:
539         // puts out LOW during second half of count
540         if (LOG) logerror("8155 '%s' Timer Mode: LOW\n", tag());
423541         break;
424542
425      case I8155_TIMER_MODE_SQUARE_WAVE:
426         /* square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count */
427         if (LOG) logerror("8155 Timer Mode: Square wave\n");
543      case TIMER_MODE_SQUARE_WAVE:
544         // square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count
545         if (LOG) logerror("8155 '%s' Timer Mode: Square wave\n", tag());
428546         break;
429547
430      case I8155_TIMER_MODE_SINGLE_PULSE:
431         /* single pulse upon TC being reached */
432         if (LOG) logerror("8155 Timer Mode: Single pulse\n");
548      case TIMER_MODE_SINGLE_PULSE:
549         // single pulse upon TC being reached
550         if (LOG) logerror("8155 '%s' Timer Mode: Single pulse\n", tag());
433551         break;
434552
435      case I8155_TIMER_MODE_AUTOMATIC_RELOAD:
436         /* automatic reload, i.e. single pulse every time TC is reached */
437         if (LOG) logerror("8155 Timer Mode: Automatic reload\n");
553      case TIMER_MODE_AUTOMATIC_RELOAD:
554         // automatic reload, i.e. single pulse every time TC is reached
555         if (LOG) logerror("8155 '%s' Timer Mode: Automatic reload\n", tag());
438556         break;
439557      }
440558      break;
441559   }
442560}
443561
444/*-------------------------------------------------
445    i8155_ram_r - memory read
446-------------------------------------------------*/
562//-------------------------------------------------
563//  io_w - register write
564//-------------------------------------------------
447565
448READ8_DEVICE_HANDLER( i8155_ram_r )
566WRITE8_MEMBER( i8155_device::io_w )
449567{
450   i8155_t *i8155 = get_safe_token(device);
451
452   return i8155->ram[offset & 0xff];
568   register_w(offset, data);
453569}
454570
455/*-------------------------------------------------
456    i8155_ram_w - memory write
457-------------------------------------------------*/
458571
459WRITE8_DEVICE_HANDLER( i8155_ram_w )
460{
461   i8155_t *i8155 = get_safe_token(device);
572//-------------------------------------------------
573//  memory_r - internal RAM read
574//-------------------------------------------------
462575
463   i8155->ram[offset & 0xff] = data;
464}
465
466/*-------------------------------------------------
467    DEVICE_START( i8155 )
468-------------------------------------------------*/
469
470static DEVICE_START( i8155 )
576READ8_MEMBER( i8155_device::memory_r )
471577{
472   i8155_t *i8155 = (i8155_t *)downcast<legacy_device_base *>(device)->token();
473   const i8155_interface *intf = get_interface(device);
474
475   /* resolve callbacks */
476   devcb_resolve_read8(&i8155->in_port_func[0], &intf->in_pa_func, device);
477   devcb_resolve_read8(&i8155->in_port_func[1], &intf->in_pb_func, device);
478   devcb_resolve_read8(&i8155->in_port_func[2], &intf->in_pc_func, device);
479   devcb_resolve_write8(&i8155->out_port_func[0], &intf->out_pa_func, device);
480   devcb_resolve_write8(&i8155->out_port_func[1], &intf->out_pb_func, device);
481   devcb_resolve_write8(&i8155->out_port_func[2], &intf->out_pc_func, device);
482   devcb_resolve_write_line(&i8155->out_to_func, &intf->out_to_func, device);
483
484   /* create the timers */
485   i8155->timer = timer_alloc(device->machine, counter_tick, (void *)device);
486
487   /* register for state saving */
488   state_save_register_device_item(device, 0, i8155->command);
489   state_save_register_device_item(device, 0, i8155->status);
490   state_save_register_device_item_array(device, 0, i8155->output);
491   state_save_register_device_item(device, 0, i8155->count_length);
492   state_save_register_device_item(device, 0, i8155->counter);
493   state_save_register_device_item_array(device, 0, i8155->ram);
494   state_save_register_device_item(device, 0, i8155->to);
578   return this->space()->read_byte(offset);
495579}
496580
497/*-------------------------------------------------
498    DEVICE_RESET( i8155 )
499-------------------------------------------------*/
500581
501static DEVICE_RESET( i8155 )
502{
503   i8155_t *i8155 = (i8155_t *)downcast<legacy_device_base *>(device)->token();
582//-------------------------------------------------
583//  memory_w - internal RAM write
584//-------------------------------------------------
504585
505   /* clear output registers */
506   i8155->output[I8155_PORT_A] = 0;
507   i8155->output[I8155_PORT_B] = 0;
508   i8155->output[I8155_PORT_C] = 0;
509
510   /* set ports to input mode */
511   i8155_w(device, I8155_REGISTER_COMMAND, i8155->command & ~(I8155_COMMAND_PA | I8155_COMMAND_PB | I8155_COMMAND_PC_MASK));
512
513   /* clear timer flag */
514   i8155->status &= ~I8155_STATUS_TIMER;
515
516   /* stop counting */
517   timer_enable(i8155->timer, 0);
518
519   /* clear timer output */
520   i8155->to = 1;
521   timer_output(i8155);
522}
523
524/*-------------------------------------------------
525    DEVICE_GET_INFO( i8155 )
526-------------------------------------------------*/
527
528DEVICE_GET_INFO( i8155 )
586WRITE8_MEMBER( i8155_device::memory_w )
529587{
530   switch (state)
531   {
532      /* --- the following bits of info are returned as 64-bit signed integers --- */
533      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
534      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(i8155_t);               break;
535
536      /* --- the following bits of info are returned as pointers to data or functions --- */
537      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(i8155);      break;
538      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
539      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(i8155);      break;
540
541      /* --- the following bits of info are returned as NULL-terminated strings --- */
542      case DEVINFO_STR_NAME:                     strcpy(info->s, "Intel 8155");            break;
543      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Intel MCS-85");         break;
544      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
545      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
546      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");   break;
547   }
588   this->space()->write_byte(offset, data);
548589}
549
550DEFINE_LEGACY_DEVICE(I8155, i8155);
src/mess/machine/i8155.h
r9419r9420
3030
3131**********************************************************************/
3232
33#pragma once
34
3335#ifndef __I8155__
3436#define __I8155__
3537
3638#include "emu.h"
37#include "devcb.h"
3839
39/***************************************************************************
40    MACROS / CONSTANTS
41***************************************************************************/
4240
43DECLARE_LEGACY_DEVICE(I8155, i8155);
4441
42//**************************************************************************
43//   MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
4553#define MDRV_I8155_ADD(_tag, _clock, _config) \
4654   MDRV_DEVICE_ADD((_tag), I8155, _clock)   \
4755   MDRV_DEVICE_CONFIG(_config)
r9419r9420
4957#define I8155_INTERFACE(name) \
5058   const i8155_interface (name) =
5159
52/***************************************************************************
53    TYPE DEFINITIONS
54***************************************************************************/
5560
56typedef struct _i8155_interface i8155_interface;
57struct _i8155_interface
61
62//**************************************************************************
63//   TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> i8155_interface
67
68struct i8155_interface
5869{
5970   devcb_read8            in_pa_func;
71   devcb_write8         out_pa_func;
72
6073   devcb_read8            in_pb_func;
74   devcb_write8         out_pb_func;
75
6176   devcb_read8            in_pc_func;
62
63   devcb_write8         out_pa_func;
64   devcb_write8         out_pb_func;
6577   devcb_write8         out_pc_func;
6678
67   /* this gets called for each change of the TIMER OUT pin (pin 6) */
79   // this gets called for each change of the TIMER OUT pin (pin 6)
6880   devcb_write_line      out_to_func;
6981};
7082
71/***************************************************************************
72    PROTOTYPES
73***************************************************************************/
74/* register access */
75READ8_DEVICE_HANDLER( i8155_r );
76WRITE8_DEVICE_HANDLER( i8155_w );
7783
78/* memory access */
79READ8_DEVICE_HANDLER( i8155_ram_r );
80WRITE8_DEVICE_HANDLER( i8155_ram_w );
8184
85// ======================> i8155_device_config
86
87class i8155_device_config :   public device_config,
88                        public device_config_memory_interface,
89                                public i8155_interface
90{
91    friend class i8155_device;
92
93    // construction/destruction
94    i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
95
96public:
97    // allocators
98    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
99    virtual device_t *alloc_device(running_machine &machine) const;
100
101protected:
102   // device_config overrides
103   virtual void device_config_complete();
104
105   // device_config_memory_interface overrides
106   virtual const address_space_config *memory_space_config(int spacenum = 0) const;
107
108    // address space configurations
109   const address_space_config      m_space_config;
110};
111
112
113
114// ======================> i8155_device
115
116class i8155_device :   public device_t,
117                  public device_memory_interface
118{
119    friend class i8155_device_config;
120
121    // construction/destruction
122    i8155_device(running_machine &_machine, const i8155_device_config &_config);
123
124public:
125    DECLARE_READ8_MEMBER( io_r );
126    DECLARE_WRITE8_MEMBER( io_w );
127
128    DECLARE_READ8_MEMBER( memory_r );
129    DECLARE_WRITE8_MEMBER( memory_w );
130
131protected:
132    // device-level overrides
133    virtual void device_start();
134    virtual void device_reset();
135   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
136
137   inline UINT8 get_timer_mode();
138   inline void timer_output();
139   inline void pulse_timer_output();
140   inline int get_port_mode(int port);
141   inline UINT8 read_port(int port);
142   inline void write_port(int port, UINT8 data);
143
144   void register_w(int offset, UINT8 data);
145
146private:
147   devcb_resolved_read8      m_in_port_func[3];
148   devcb_resolved_write8      m_out_port_func[3];
149   devcb_resolved_write_line   m_out_to_func;
150
151   // registers
152   UINT8 m_command;         // command register
153   UINT8 m_status;            // status register
154   UINT8 m_output[3];         // output latches
155
156   // counter
157   UINT16 m_count_length;      // count length register
158   UINT16 m_counter;         // counter register
159   int m_to;               // timer output
160
161   // timers
162   emu_timer *m_timer;         // counter timer
163
164   const i8155_device_config &m_config;
165};
166
167
168// device type definition
169extern const device_type I8155;
170
171
172
82173#endif
src/mess/machine/i8212.c
r9419r9420
88**********************************************************************/
99
1010#include "emu.h"
11#include "machine/devhelpr.h"
1112#include "i8212.h"
1213
13/***************************************************************************
14    PARAMETERS
15***************************************************************************/
1614
17#define LOG 1
1815
19/***************************************************************************
20    TYPE DEFINITIONS
21***************************************************************************/
16//**************************************************************************
17//   MACROS / CONSTANTS
18//**************************************************************************
2219
23typedef struct _i8212_t i8212_t;
24struct _i8212_t
25{
26   devcb_resolved_write_line   out_int_func;
27   devcb_resolved_read8      in_di_func;
28   devcb_resolved_write8      out_do_func;
20#define LOG 0
2921
30   int md;                  /* mode */
31   int stb;               /* strobe */
32   UINT8 data;               /* data latch */
33};
3422
35/***************************************************************************
36    INLINE FUNCTIONS
37***************************************************************************/
3823
39INLINE i8212_t *get_safe_token(running_device *device)
40{
41   assert(device != NULL);
42   return (i8212_t *)downcast<legacy_device_base *>(device)->token();
43}
24//**************************************************************************
25//  GLOBAL VARIABLES
26//**************************************************************************
4427
45INLINE const i8212_interface *get_interface(running_device *device)
46{
47   assert(device != NULL);
48   assert((device->type() == I8212));
49   return (const i8212_interface *) device->baseconfig().static_config();
50}
28// devices
29const device_type I8212 = i8212_device_config::static_alloc_device_config;
5130
52/***************************************************************************
53    IMPLEMENTATION
54***************************************************************************/
5531
56/*-------------------------------------------------
57    i8212_r - data output read
58-------------------------------------------------*/
5932
60READ8_DEVICE_HANDLER( i8212_r )
61{
62   i8212_t *i8212 = get_safe_token(device);
33//**************************************************************************
34//  DEVICE CONFIGURATION
35//**************************************************************************
6336
64   /* clear interrupt line */
65   devcb_call_write_line(&i8212->out_int_func, CLEAR_LINE);
37GENERIC_DEVICE_CONFIG_SETUP(i8212, "Intel 8212")
6638
67   if (LOG) logerror("I8212 '%s' INT: %u\n", device->tag(), CLEAR_LINE);
6839
69   return i8212->data;
70}
40//-------------------------------------------------
41//  device_config_complete - perform any
42//  operations now that the configuration is
43//  complete
44//-------------------------------------------------
7145
72/*-------------------------------------------------
73    i8212_w - data input write
74-------------------------------------------------*/
75
76WRITE8_DEVICE_HANDLER( i8212_w )
46void i8212_device_config::device_config_complete()
7747{
78   i8212_t *i8212 = get_safe_token(device);
48   // inherit a copy of the static data
49   const i8212_interface *intf = reinterpret_cast<const i8212_interface *>(static_config());
50   if (intf != NULL)
51      *static_cast<i8212_interface *>(this) = *intf;
7952
80   /* latch data */
81   i8212->data = data;
82
83   /* output data */
84   devcb_call_write8(&i8212->out_do_func, 0, i8212->data);
53   // or initialize to defaults if none provided
54   else
55   {
56      memset(&out_int_func, 0, sizeof(out_int_func));
57      memset(&in_di_func, 0, sizeof(in_di_func));
58      memset(&out_do_func, 0, sizeof(out_do_func));
59   }
8560}
8661
87/*-------------------------------------------------
88    i8212_md_w - mode write
89-------------------------------------------------*/
9062
91#ifdef UNUSED_FUNCTION
92WRITE_LINE_DEVICE_HANDLER( i8212_md_w )
93{
94   i8212_t *i8212 = get_safe_token(device);
9563
96   if (LOG) logerror("I8212 '%s' Mode: %s\n", device->tag(), state ? "output" : "input");
64//**************************************************************************
65//  LIVE DEVICE
66//**************************************************************************
9767
98   i8212->md = state;
68//-------------------------------------------------
69//  i8212_device - constructor
70//-------------------------------------------------
71
72i8212_device::i8212_device(running_machine &_machine, const i8212_device_config &config)
73    : device_t(_machine, config),
74     m_md(I8212_MODE_INPUT),
75     m_stb(0),
76      m_config(config)
77{
78
9979}
100#endif
10180
102/*-------------------------------------------------
103    i8212_stb_w - strobe write
104-------------------------------------------------*/
10581
106WRITE_LINE_DEVICE_HANDLER( i8212_stb_w )
82//-------------------------------------------------
83//  device_start - device-specific startup
84//-------------------------------------------------
85
86void i8212_device::device_start()
10787{
108   i8212_t *i8212 = get_safe_token(device);
88   // resolve callbacks
89   devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this);
90   devcb_resolve_read8(&m_in_di_func, &m_config.in_di_func, this);
91   devcb_resolve_write8(&m_out_do_func, &m_config.out_do_func, this);
10992
110   if (LOG) logerror("I8212 '%s' STB: %u\n", device->tag(), state);
93   // register for state saving
94   state_save_register_device_item(this, 0, m_md);
95   state_save_register_device_item(this, 0, m_stb);
96   state_save_register_device_item(this, 0, m_data);
97}
11198
112   if (i8212->md == I8212_MODE_INPUT)
113   {
114      if (i8212->stb && !state)
115      {
116         /* input data */
117         i8212->data = devcb_call_read8(&i8212->in_di_func, 0);
11899
119         /* assert interrupt line */
120         devcb_call_write_line(&i8212->out_int_func, ASSERT_LINE);
100//-------------------------------------------------
101//  device_reset - device-specific reset
102//-------------------------------------------------
121103
122         if (LOG) logerror("I8212 '%s' INT: %u\n", device->tag(), ASSERT_LINE);
123      }
124   }
104void i8212_device::device_reset()
105{
106   m_data = 0;
125107
126   i8212->stb = state;
108   if (m_md == I8212_MODE_OUTPUT)
109   {
110      // output data
111      devcb_call_write8(&m_out_do_func, 0, m_data);
112   }
127113}
128114
129/*-------------------------------------------------
130    DEVICE_START( i8212 )
131-------------------------------------------------*/
132115
133static DEVICE_START( i8212 )
116//-------------------------------------------------
117//  data_r - data latch read
118//-------------------------------------------------
119
120READ8_MEMBER( i8212_device::data_r )
134121{
135   i8212_t *i8212 = get_safe_token(device);
136   const i8212_interface *intf = get_interface(device);
122   // clear interrupt line
123   devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
137124
138   /* resolve callbacks */
139   devcb_resolve_write_line(&i8212->out_int_func, &intf->out_int_func, device);
140   devcb_resolve_read8(&i8212->in_di_func, &intf->in_di_func, device);
141   devcb_resolve_write8(&i8212->out_do_func, &intf->out_do_func, device);
125   if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), CLEAR_LINE);
142126
143   /* register for state saving */
144   state_save_register_device_item(device, 0, i8212->md);
145   state_save_register_device_item(device, 0, i8212->stb);
146   state_save_register_device_item(device, 0, i8212->data);
127   return m_data;
147128}
148129
149/*-------------------------------------------------
150    DEVICE_RESET( i8212 )
151-------------------------------------------------*/
152130
153static DEVICE_RESET( i8212 )
131//-------------------------------------------------
132//  data_w - data latch write
133//-------------------------------------------------
134
135WRITE8_MEMBER( i8212_device::data_w )
154136{
155   i8212_t *i8212 = get_safe_token(device);
137   // latch data
138   m_data = data;
156139
157   i8212->data = 0;
140   // output data
141   devcb_call_write8(&m_out_do_func, 0, m_data);
142}
158143
159   if (i8212->md == I8212_MODE_OUTPUT)
160   {
161      /* output data */
162      devcb_call_write8(&i8212->out_do_func, 0, i8212->data);
163   }
144
145//-------------------------------------------------
146//  md_w - mode write
147//-------------------------------------------------
148
149WRITE_LINE_MEMBER( i8212_device::md_w )
150{
151   if (LOG) logerror("I8212 '%s' Mode: %s\n", tag(), state ? "output" : "input");
152
153   m_md = state;
164154}
165155
166/*-------------------------------------------------
167    DEVICE_GET_INFO( i8212 )
168-------------------------------------------------*/
169156
170DEVICE_GET_INFO( i8212 )
157//-------------------------------------------------
158//  stb_w - data strobe write
159//-------------------------------------------------
160
161WRITE_LINE_MEMBER( i8212_device::stb_w )
171162{
172   switch (state)
163   if (LOG) logerror("I8212 '%s' STB: %u\n", tag(), state);
164
165   if (m_md == I8212_MODE_INPUT)
173166   {
174      /* --- the following bits of info are returned as 64-bit signed integers --- */
175      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(i8212_t);               break;
176      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
167      if (m_stb && !state)
168      {
169         // input data
170         m_data = devcb_call_read8(&m_in_di_func, 0);
177171
178      /* --- the following bits of info are returned as pointers to data or functions --- */
179      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(i8212);      break;
180      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
181      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(i8212);      break;
172         // assert interrupt line
173         devcb_call_write_line(&m_out_int_func, ASSERT_LINE);
182174
183      /* --- the following bits of info are returned as NULL-terminated strings --- */
184      case DEVINFO_STR_NAME:                     strcpy(info->s, "Intel 8212");            break;
185      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Intel MCS-80");         break;
186      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
187      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
188      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright MESS Team");      break;
175         if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), ASSERT_LINE);
176      }
189177   }
190}
191178
192DEFINE_LEGACY_DEVICE(I8212, i8212);
179   m_stb = state;
180}
src/mess/machine/i8212.h
r9419r9420
2222
2323**********************************************************************/
2424
25#pragma once
26
2527#ifndef __I8212__
2628#define __I8212__
2729
28#include "devcb.h"
30#include "emu.h"
2931
30/***************************************************************************
31    MACROS / CONSTANTS
32***************************************************************************/
3332
34DECLARE_LEGACY_DEVICE(I8212, i8212);
3533
36#define MDRV_I8212_ADD(_tag, _intrf) \
37   MDRV_DEVICE_ADD(_tag, I8212, 0) \
38   MDRV_DEVICE_CONFIG(_intrf)
34///*************************************************************************
35//   MACROS / CONSTANTS
36///*************************************************************************
3937
40#define I8212_INTERFACE(name) \
41   const i8212_interface (name)=
42
43/***************************************************************************
44    TYPE DEFINITIONS
45***************************************************************************/
46
4738enum
4839{
4940   I8212_MODE_INPUT = 0,
5041   I8212_MODE_OUTPUT
5142};
5243
53typedef struct _i8212_interface i8212_interface;
54struct _i8212_interface
44
45
46///*************************************************************************
47//  INTERFACE CONFIGURATION MACROS
48///*************************************************************************
49
50#define MDRV_I8212_ADD(_tag, _config) \
51   MDRV_DEVICE_ADD((_tag), I8212, 0)   \
52   MDRV_DEVICE_CONFIG(_config)
53
54#define I8212_INTERFACE(name) \
55   const i8212_interface (name) =
56
57
58
59///*************************************************************************
60//   TYPE DEFINITIONS
61///*************************************************************************
62
63// ======================> i8212_interface
64
65struct i8212_interface
5566{
5667   devcb_write_line   out_int_func;
5768
r9419r9420
5970   devcb_write8      out_do_func;
6071};
6172
62/***************************************************************************
63    PROTOTYPES
64***************************************************************************/
65/* data latch access */
66READ8_DEVICE_HANDLER( i8212_r );
67WRITE8_DEVICE_HANDLER( i8212_w );
6873
69/* strobe */
70WRITE_LINE_DEVICE_HANDLER( i8212_stb_w );
7174
75// ======================> i8212_device_config
76
77class i8212_device_config :   public device_config,
78                                public i8212_interface
79{
80    friend class i8212_device;
81
82    // construction/destruction
83    i8212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
84
85public:
86    // allocators
87    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
88    virtual device_t *alloc_device(running_machine &machine) const;
89
90protected:
91   // device_config overrides
92   virtual void device_config_complete();
93};
94
95
96
97// ======================> i8212_device
98
99class i8212_device :   public device_t
100{
101    friend class i8212_device_config;
102
103    // construction/destruction
104    i8212_device(running_machine &_machine, const i8212_device_config &_config);
105
106public:
107    DECLARE_READ8_MEMBER( data_r );
108    DECLARE_WRITE8_MEMBER( data_w );
109
110   DECLARE_WRITE_LINE_MEMBER( md_w );
111   DECLARE_WRITE_LINE_MEMBER( stb_w );
112
113protected:
114    // device-level overrides
115    virtual void device_start();
116    virtual void device_reset();
117
118private:
119   devcb_resolved_write_line   m_out_int_func;
120   devcb_resolved_read8      m_in_di_func;
121   devcb_resolved_write8      m_out_do_func;
122
123   int m_md;               // mode
124   int m_stb;               // strobe
125   UINT8 m_data;            // data latch
126
127   const i8212_device_config &m_config;
128};
129
130
131// device type definition
132extern const device_type I8212;
133
134
135
72136#endif
src/mess/machine/i8355.c
r9419r9420
77
88**********************************************************************/
99
10/*
10#include "emu.h"
11#include "i8355.h"
1112
12    TODO:
1313
14    - attempt to direct-map
1514
16*/
15//**************************************************************************
16//   MACROS / CONSTANTS
17//**************************************************************************
1718
18#include "i8355.h"
19
20/***************************************************************************
21    PARAMETERS
22***************************************************************************/
23
2419#define LOG 0
2520
2621enum
2722{
28   I8355_REGISTER_PORT_A = 0,
29   I8355_REGISTER_PORT_B,
30   I8355_REGISTER_PORT_A_DDR,
31   I8355_REGISTER_PORT_B_DDR
23   REGISTER_PORT_A = 0,
24   REGISTER_PORT_B,
25   REGISTER_PORT_A_DDR,
26   REGISTER_PORT_B_DDR
3227};
3328
3429enum
r9419r9420
3833   PORT_COUNT
3934};
4035
41/***************************************************************************
42    TYPE DEFINITIONS
43***************************************************************************/
4436
45typedef struct _i8355_t i8355_t;
46struct _i8355_t
47{
48   devcb_resolved_read8      in_rom_func;
49   devcb_resolved_read8      in_port_func[PORT_COUNT];
50   devcb_resolved_write8      out_port_func[PORT_COUNT];
5137
52   /* registers */
53   UINT8 output[PORT_COUNT];   /* output latches */
54   UINT8 ddr[PORT_COUNT];      /* DDR latches */
38//**************************************************************************
39//  GLOBAL VARIABLES
40//**************************************************************************
5541
56   /* ROM */
57   const UINT8 *rom;         /* ROM */
58};
42// devices
43const device_type I8355 = i8355_device_config::static_alloc_device_config;
5944
60/***************************************************************************
61    INLINE FUNCTIONS
62***************************************************************************/
6345
64INLINE i8355_t *get_safe_token(running_device *device)
46// default address map
47static ADDRESS_MAP_START( i8355, 0, 8 )
48   AM_RANGE(0x000, 0x7ff) AM_ROM
49ADDRESS_MAP_END
50
51
52
53//**************************************************************************
54//  DEVICE CONFIGURATION
55//**************************************************************************
56
57//-------------------------------------------------
58//  i8355_device_config - constructor
59//-------------------------------------------------
60
61i8355_device_config::i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
62   : device_config(mconfig, static_alloc_device_config, "Intel 8355", tag, owner, clock),
63     device_config_memory_interface(mconfig, *this),
64     m_space_config("ram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(i8355))
6565{
66   assert(device != NULL);
67   return (i8355_t *)downcast<legacy_device_base *>(device)->token();
6866}
6967
70INLINE const i8355_interface *get_interface(running_device *device)
68
69//-------------------------------------------------
70//  static_alloc_device_config - allocate a new
71//  configuration object
72//-------------------------------------------------
73
74device_config *i8355_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
7175{
72   assert(device != NULL);
73   assert(device->type() == I8355);
74   return (const i8355_interface *) device->baseconfig().static_config();
76   return global_alloc(i8355_device_config(mconfig, tag, owner, clock));
7577}
7678
77INLINE UINT8 read_port(i8355_t *i8355, int port)
79
80//-------------------------------------------------
81//  alloc_device - allocate a new device object
82//-------------------------------------------------
83
84device_t *i8355_device_config::alloc_device(running_machine &machine) const
7885{
79   UINT8 data = i8355->output[port] & i8355->ddr[port];
86   return auto_alloc(&machine, i8355_device(machine, *this));
87}
8088
81   if (i8355->ddr[port] != 0xff)
82   {
83      data |= devcb_call_read8(&i8355->in_port_func[port], 0) & ~i8355->ddr[port];
84   }
8589
86   return data;
90//-------------------------------------------------
91//  memory_space_config - return a description of
92//  any address spaces owned by this device
93//-------------------------------------------------
94
95const address_space_config *i8355_device_config::memory_space_config(int spacenum) const
96{
97   return (spacenum == 0) ? &m_space_config : NULL;
8798}
8899
89INLINE void write_port(i8355_t *i8355, int port, UINT8 data)
100
101//-------------------------------------------------
102//  device_config_complete - perform any
103//  operations now that the configuration is
104//  complete
105//-------------------------------------------------
106
107void i8355_device_config::device_config_complete()
90108{
91   i8355->output[port] = data;
109   // inherit a copy of the static data
110   const i8355_interface *intf = reinterpret_cast<const i8355_interface *>(static_config());
111   if (intf != NULL)
112      *static_cast<i8355_interface *>(this) = *intf;
92113
93   devcb_call_write8(&i8355->out_port_func[port], 0, i8355->output[port] & i8355->ddr[port]);
114   // or initialize to defaults if none provided
115   else
116   {
117      memset(&in_pa_func, 0, sizeof(in_pa_func));
118      memset(&out_pa_func, 0, sizeof(out_pa_func));
119      memset(&in_pb_func, 0, sizeof(in_pb_func));
120      memset(&out_pb_func, 0, sizeof(out_pb_func));
121   }
94122}
95123
96/***************************************************************************
97    IMPLEMENTATION
98***************************************************************************/
99124
100/*-------------------------------------------------
101    i8355_register_r - register read
102-------------------------------------------------*/
103125
104READ8_DEVICE_HANDLER( i8355_r )
126//**************************************************************************
127//  INLINE HELPERS
128//**************************************************************************
129
130//-------------------------------------------------
131//  read_port - read from input port
132//-------------------------------------------------
133
134inline UINT8 i8355_device::read_port(int port)
105135{
106   i8355_t *i8355 = get_safe_token(device);
107   int port = offset & 0x01;
136   UINT8 data = m_output[port] & m_ddr[port];
108137
109   UINT8 data = 0;
110
111   switch (offset & 0x03)
138   if (m_ddr[port] != 0xff)
112139   {
113   case I8355_REGISTER_PORT_A:
114   case I8355_REGISTER_PORT_B:
115      data = read_port(i8355, port);
116      break;
117
118   case I8355_REGISTER_PORT_A_DDR:
119   case I8355_REGISTER_PORT_B_DDR:
120      /* write only */
121      break;
140      data |= devcb_call_read8(&m_in_port_func[port], 0) & ~m_ddr[port];
122141   }
123142
124143   return data;
125144}
126145
127/*-------------------------------------------------
128    i8355_register_w - register write
129-------------------------------------------------*/
130146
131WRITE8_DEVICE_HANDLER( i8355_w )
147//-------------------------------------------------
148//  write_port - write to output port
149//-------------------------------------------------
150
151inline void i8355_device::write_port(int port, UINT8 data)
132152{
133   i8355_t *i8355 = get_safe_token(device);
134   int port = offset & 0x01;
153   m_output[port] = data;
135154
136   switch (offset & 0x03)
137   {
138   case I8355_REGISTER_PORT_A:
139   case I8355_REGISTER_PORT_B:
140      if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", device->tag(), 'A' + port, data);
141      write_port(i8355, port, data);
142      break;
143
144   case I8355_REGISTER_PORT_A_DDR:
145   case I8355_REGISTER_PORT_B_DDR:
146      if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", device->tag(), 'A' + port, data);
147      i8355->ddr[port] = data;
148      write_port(i8355, port, data);
149      break;
150   }
155   devcb_call_write8(&m_out_port_func[port], 0, m_output[port] & m_ddr[port]);
151156}
152157
153/*-------------------------------------------------
154    i8355_rom_r - memory read
155-------------------------------------------------*/
156158
157READ8_DEVICE_HANDLER( i8355_rom_r )
159
160//**************************************************************************
161//  LIVE DEVICE
162//**************************************************************************
163
164//-------------------------------------------------
165//  i8355_device - constructor
166//-------------------------------------------------
167
168i8355_device::i8355_device(running_machine &_machine, const i8355_device_config &config)
169    : device_t(_machine, config),
170     device_memory_interface(_machine, config, *this),
171      m_config(config)
158172{
159   i8355_t *i8355 = get_safe_token(device);
160173
161   return i8355->rom[offset & 0x7ff];
162174}
163175
164/*-------------------------------------------------
165    DEVICE_START( i8355 )
166-------------------------------------------------*/
167176
168static DEVICE_START( i8355 )
177//-------------------------------------------------
178//  device_start - device-specific startup
179//-------------------------------------------------
180
181void i8355_device::device_start()
169182{
170   i8355_t *i8355 = (i8355_t *)downcast<legacy_device_base *>(device)->token();
171   const i8355_interface *intf = get_interface(device);
183   // resolve callbacks
184   devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this);
185   devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this);
186   devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this);
187   devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this);
172188
173   /* resolve callbacks */
174   devcb_resolve_read8(&i8355->in_port_func[PORT_A], &intf->in_pa_func, device);
175   devcb_resolve_read8(&i8355->in_port_func[PORT_B], &intf->in_pb_func, device);
176   devcb_resolve_write8(&i8355->out_port_func[PORT_A], &intf->out_pa_func, device);
177   devcb_resolve_write8(&i8355->out_port_func[PORT_B], &intf->out_pb_func, device);
189   // register for state saving
190   state_save_register_device_item_array(this, 0, m_output);
191   state_save_register_device_item_array(this, 0, m_ddr);
192}
178193
179   /* find memory region */
180   i8355->rom = memory_region(device->machine, device->tag());
181   assert(i8355->rom != NULL);
182194
183   /* register for state saving */
184   state_save_register_device_item_array(device, 0, i8355->output);
185   state_save_register_device_item_array(device, 0, i8355->ddr);
195//-------------------------------------------------
196//  device_reset - device-specific reset
197//-------------------------------------------------
198
199void i8355_device::device_reset()
200{
201   // set ports to input mode
202   m_ddr[PORT_A] = 0;
203   m_ddr[PORT_B] = 0;
186204}
187205
188/*-------------------------------------------------
189    DEVICE_RESET( i8355 )
190-------------------------------------------------*/
191206
192static DEVICE_RESET( i8355 )
207//-------------------------------------------------
208//  io_r - register read
209//-------------------------------------------------
210
211READ8_MEMBER( i8355_device::io_r )
193212{
194   i8355_t *i8355 = (i8355_t *)downcast<legacy_device_base *>(device)->token();
213   int port = offset & 0x01;
195214
196   /* set ports to input mode */
197   i8355->ddr[PORT_A] = 0;
198   i8355->ddr[PORT_B] = 0;
215   UINT8 data = 0;
216
217   switch (offset & 0x03)
218   {
219   case REGISTER_PORT_A:
220   case REGISTER_PORT_B:
221      data = read_port(port);
222      break;
223
224   case REGISTER_PORT_A_DDR:
225   case REGISTER_PORT_B_DDR:
226      // write only
227      break;
228   }
229
230   return data;
199231}
200232
201/*-------------------------------------------------
202    DEVICE_GET_INFO( i8355 )
203-------------------------------------------------*/
204233
205DEVICE_GET_INFO( i8355 )
234//-------------------------------------------------
235//  io_w - register write
236//-------------------------------------------------
237
238WRITE8_MEMBER( i8355_device::io_w )
206239{
207   switch (state)
240   int port = offset & 0x01;
241
242   switch (offset & 0x03)
208243   {
209      /* --- the following bits of info are returned as 64-bit signed integers --- */
210      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
211      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(i8355_t);               break;
244   case REGISTER_PORT_A:
245   case REGISTER_PORT_B:
246      if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", tag(), 'A' + port, data);
247     
248      write_port(port, data);
249      break;
212250
213      /* --- the following bits of info are returned as pointers to data or functions --- */
214      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(i8355);      break;
215      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
216      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(i8355);      break;
217
218      /* --- the following bits of info are returned as NULL-terminated strings --- */
219      case DEVINFO_STR_NAME:                     strcpy(info->s, "Intel 8355");            break;
220      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "Intel MCS-85");         break;
221      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
222      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
223      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright the MESS Team");   break;
251   case REGISTER_PORT_A_DDR:
252   case REGISTER_PORT_B_DDR:
253      if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", tag(), 'A' + port, data);
254     
255      m_ddr[port] = data;
256      write_port(port, data);
257      break;
224258   }
225259}
226260
227DEFINE_LEGACY_DEVICE(I8355,  i8355);
261
262//-------------------------------------------------
263//  memory_r - internal ROM read
264//-------------------------------------------------
265
266READ8_MEMBER( i8355_device::memory_r )
267{
268   return this->space()->read_byte(offset);
269}
src/mess/machine/i8355.h
r9419r9420
3030
3131**********************************************************************/
3232
33#pragma once
34
3335#ifndef __I8355__
3436#define __I8355__
3537
3638#include "emu.h"
37#include "devcb.h"
3839
39/***************************************************************************
40    MACROS / CONSTANTS
41***************************************************************************/
4240
43DECLARE_LEGACY_DEVICE(I8355,  i8355);
4441
42///*************************************************************************
43//   MACROS / CONSTANTS
44///*************************************************************************
45
46
47
48
49///*************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51///*************************************************************************
52
4553#define MDRV_I8355_ADD(_tag, _clock, _config) \
4654   MDRV_DEVICE_ADD((_tag), I8355, _clock)   \
4755   MDRV_DEVICE_CONFIG(_config)
r9419r9420
4957#define I8355_INTERFACE(name) \
5058   const i8355_interface (name) =
5159
52/***************************************************************************
53    TYPE DEFINITIONS
54***************************************************************************/
5560
56typedef struct _i8355_interface i8355_interface;
57struct _i8355_interface
61
62///*************************************************************************
63//   TYPE DEFINITIONS
64///*************************************************************************
65
66// ======================> i8355_interface
67
68struct i8355_interface
5869{
5970   devcb_read8            in_pa_func;
71   devcb_write8         out_pa_func;
72
6073   devcb_read8            in_pb_func;
61
62   devcb_write8         out_pa_func;
6374   devcb_write8         out_pb_func;
6475};
6576
66/***************************************************************************
67    PROTOTYPES
68***************************************************************************/
69/* register access */
70READ8_DEVICE_HANDLER( i8355_r );
71WRITE8_DEVICE_HANDLER( i8355_w );
7277
73/* memory access */
74READ8_DEVICE_HANDLER( i8355_rom_r );
7578
79// ======================> i8355_device_config
80
81class i8355_device_config :   public device_config,
82                        public device_config_memory_interface,
83                                public i8355_interface
84{
85    friend class i8355_device;
86
87    // construction/destruction
88    i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89
90public:
91    // allocators
92    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
93    virtual device_t *alloc_device(running_machine &machine) const;
94
95protected:
96   // device_config overrides
97   virtual void device_config_complete();
98
99   // device_config_memory_interface overrides
100   virtual const address_space_config *memory_space_config(int spacenum = 0) const;
101
102    // address space configurations
103   const address_space_config      m_space_config;
104};
105
106
107
108// ======================> i8355_device
109
110class i8355_device :   public device_t,
111                  public device_memory_interface
112{
113    friend class i8355_device_config;
114
115    // construction/destruction
116    i8355_device(running_machine &_machine, const i8355_device_config &_config);
117
118public:
119    DECLARE_READ8_MEMBER( io_r );
120    DECLARE_WRITE8_MEMBER( io_w );
121
122    DECLARE_READ8_MEMBER( memory_r );
123    DECLARE_WRITE8_MEMBER( memory_w );
124
125protected:
126    // device-level overrides
127    virtual void device_start();
128    virtual void device_reset();
129
130   inline UINT8 read_port(int port);
131   inline void write_port(int port, UINT8 data);
132
133private:
134   devcb_resolved_read8      m_in_port_func[2];
135   devcb_resolved_write8      m_out_port_func[2];
136
137   // registers
138   UINT8 m_output[2];         // output latches
139   UINT8 m_ddr[2];            // DDR latches
140
141   const i8355_device_config &m_config;
142};
143
144
145// device type definition
146extern const device_type I8355;
147
148
149
76150#endif
src/mess/includes/mikromik.h
r9419r9420
4040   int tc;
4141
4242   /* devices */
43   running_device *i8212;
43   i8212_device *i8212;
4444   running_device *i8237;
4545   running_device *i8275;
4646   running_device *upd765;
src/mess/includes/comx35.h
r9419r9420
33
44#include "cpu/cosmac/cosmac.h"
55#include "sound/cdp1869.h"
6#include "machine/cdp1871.h"
67#include "devices/snapquik.h"
78#include "machine/wd17xx.h"
89
r9419r9420
5556   required_device<cdp1869_device> m_vis;
5657   required_device<running_device> m_crtc;
5758   required_device<running_device> m_fdc;
58   required_device<running_device> m_kbe;
59   required_device<cdp1871_device> m_kbe;
5960   required_device<running_device> m_cassette;
6061   required_device<running_device> m_ram;
6162
src/mess/drivers/mikromik.c
r9419r9420
11#include "emu.h"
2#include "includes/mikromik.h"
32#include "formats/basicdsk.h"
43#include "devices/flopdrv.h"
54#include "cpu/i8085/i8085.h"
r9419r9420
1211#include "video/upd7220.h"
1312#include "sound/speaker.h"
1413#include "devices/messram.h"
14#include "includes/mikromik.h"
1515
1616/*
1717
r9419r9420
138138//  AM_RANGE(0xff10, 0xff13) AM_MIRROR(0x8c) AM_DEVREADWRITE(UPD7201_TAG, upd7201_cd_ba_r, upd7201_cd_ba_w)
139139    AM_RANGE(0xff20, 0xff21) AM_MIRROR(0x8e) AM_DEVREADWRITE(I8275_TAG, i8275_r, i8275_w)
140140   AM_RANGE(0xff30, 0xff33) AM_MIRROR(0x8c) AM_DEVREADWRITE(I8253_TAG, pit8253_r, pit8253_w)
141   AM_RANGE(0xff40, 0xff40) AM_MIRROR(0x8f) AM_DEVREADWRITE(I8212_TAG, i8212_r, i8212_w)
141   AM_RANGE(0xff40, 0xff40) AM_MIRROR(0x8f) AM_DEVREADWRITE_MODERN(I8212_TAG, i8212_device, data_r, data_w)
142142   AM_RANGE(0xff50, 0xff50) AM_MIRROR(0x8e) AM_DEVREAD(UPD765_TAG, upd765_status_r)
143143   AM_RANGE(0xff51, 0xff51) AM_MIRROR(0x8e) AM_DEVREADWRITE(UPD765_TAG, upd765_data_r, upd765_data_w)
144144   AM_RANGE(0xff60, 0xff67) AM_MIRROR(0x88) AM_WRITE(ls259_w)
r9419r9420
621621      if (keydata != 0xff)
622622      {
623623         /* strobe in key data */
624         i8212_stb_w(state->i8212, 1);
625         i8212_stb_w(state->i8212, 0);
624         state->i8212->stb_w(1);
625         state->i8212->stb_w(0);
626626      }
627627   }
628628
r9419r9420
691691   address_space *program = cputag_get_address_space(machine, I8085A_TAG, ADDRESS_SPACE_PROGRAM);
692692
693693   /* look up devices */
694   state->i8212 = machine->device(I8212_TAG);
694   state->i8212 = machine->device<i8212_device>(I8212_TAG);
695695   state->i8237 = machine->device(I8237_TAG);
696696   state->i8275 = machine->device(I8275_TAG);
697697   state->upd765 = machine->device(UPD765_TAG);
src/mess/drivers/kyocera.c
r9419r9420
527527//  AM_RANGE(0x80, 0x80) AM_MIRROR(0x0f) optional I/O controller unit
528528//  AM_RANGE(0x90, 0x90) AM_MIRROR(0x0f) optional answering telephone unit
529529//  AM_RANGE(0xa0, 0xa0) AM_MIRROR(0x0f) optional modem
530   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE(I8155_TAG, i8155_r, i8155_w)
530   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE_MODERN(I8155_TAG, i8155_device, io_r, io_w)
531531//  AM_RANGE(0xc0, 0xc0) AM_MIRROR(0x0f) AM_DEVREADWRITE(IM6402_TAG, im6402_data_r, im6402_data_w)
532532   AM_RANGE(0xd0, 0xd0) AM_MIRROR(0x0f) AM_READWRITE(uart_status_r, uart_ctrl_w)
533533   AM_RANGE(0xe0, 0xe0) AM_MIRROR(0x0f) AM_READWRITE(keyboard_r, kc85_ctrl_w)
r9419r9420
540540//  AM_RANGE(0x80, 0x80) AM_MIRROR(0x0f) optional I/O controller unit
541541//  AM_RANGE(0x90, 0x90) AM_MIRROR(0x0f) optional answering telephone unit
542542   AM_RANGE(0xa0, 0xa0) AM_MIRROR(0x0f) AM_WRITE(modem_w)
543   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE(I8155_TAG, i8155_r, i8155_w)
543   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE_MODERN(I8155_TAG, i8155_device, io_r, io_w)
544544//  AM_RANGE(0xc0, 0xc0) AM_MIRROR(0x0f) AM_DEVREADWRITE(IM6402_TAG, im6402_data_r, im6402_data_w)
545545   AM_RANGE(0xd0, 0xd0) AM_MIRROR(0x0f) AM_READWRITE(uart_status_r, uart_ctrl_w)
546546   AM_RANGE(0xe0, 0xe0) AM_MIRROR(0x0f) AM_READWRITE(keyboard_r, kc85_ctrl_w)
r9419r9420
553553//  AM_RANGE(0x80, 0x80) AM_MIRROR(0x0f) optional 128K ROM cartridge
554554   AM_RANGE(0x90, 0x90) AM_MIRROR(0x0f) AM_WRITE(pc8201_ctrl_w)
555555   AM_RANGE(0xa0, 0xa0) AM_MIRROR(0x0f) AM_READWRITE(pc8201_bank_r, pc8201_bank_w)
556   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE(I8155_TAG, i8155_r, i8155_w )
556   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE_MODERN(I8155_TAG, i8155_device, io_r, io_w)
557557//  AM_RANGE(0xc0, 0xc0) AM_MIRROR(0x0f) AM_DEVREADWRITE(IM6402_TAG, im6402_data_r, im6402_data_w)
558558   AM_RANGE(0xd0, 0xd0) AM_MIRROR(0x0f) AM_READWRITE(pc8201_uart_status_r, uart_ctrl_w)
559559   AM_RANGE(0xe0, 0xe0) AM_MIRROR(0x0f) AM_READ(keyboard_r)
r9419r9420
564564   ADDRESS_MAP_UNMAP_HIGH
565565   AM_RANGE(0x90, 0x9f) AM_DEVREADWRITE(RP5C01A_TAG, rp5c01a_r, rp5c01a_w)
566566//  AM_RANGE(0xa0, 0xa0) AM_MIRROR(0x0f) AM_DEVWRITE(TCM5089_TAG, tcm5089_w)
567   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE(I8155_TAG, i8155_r, i8155_w)
567   AM_RANGE(0xb0, 0xb7) AM_MIRROR(0x08) AM_DEVREADWRITE_MODERN(I8155_TAG, i8155_device, io_r, io_w)
568568   AM_RANGE(0xc0, 0xc0) AM_MIRROR(0x0e) AM_DEVREADWRITE(MSM8251_TAG, msm8251_data_r, msm8251_data_w)
569569   AM_RANGE(0xc1, 0xc1) AM_MIRROR(0x0e) AM_DEVREADWRITE(MSM8251_TAG, msm8251_status_r, msm8251_control_w)
570570   AM_RANGE(0xd0, 0xd0) AM_MIRROR(0x0f) AM_READWRITE(tandy200_bank_r, tandy200_bank_w)
r9419r9420
948948static I8155_INTERFACE( kc85_8155_intf )
949949{
950950   DEVCB_NULL,                        /* port A read */
951   DEVCB_HANDLER(kc85_8155_port_a_w),      /* port A write */
951952   DEVCB_NULL,                        /* port B read */
953   DEVCB_HANDLER(kc85_8155_port_b_w),      /* port B write */
952954   DEVCB_HANDLER(kc85_8155_port_c_r),      /* port C read */
953   DEVCB_HANDLER(kc85_8155_port_a_w),      /* port A write */
954   DEVCB_HANDLER(kc85_8155_port_b_w),      /* port B write */
955955   DEVCB_NULL,                        /* port C write */
956956   DEVCB_LINE(kc85_8155_to_w)            /* timer output */
957957};
r9419r9420
10181018static I8155_INTERFACE( pc8201_8155_intf )
10191019{
10201020   DEVCB_NULL,                        /* port A read */
1021   DEVCB_HANDLER(kc85_8155_port_a_w),      /* port A write */
10211022   DEVCB_NULL,                        /* port B read */
1023   DEVCB_HANDLER(pc8201_8155_port_b_w),   /* port B write */
10221024   DEVCB_HANDLER(pc8201_8155_port_c_r),   /* port C read */
1023   DEVCB_HANDLER(kc85_8155_port_a_w),      /* port A write */
1024   DEVCB_HANDLER(pc8201_8155_port_b_w),   /* port B write */
10251025   DEVCB_NULL,                        /* port C write */
10261026   DEVCB_LINE(kc85_8155_to_w)            /* timer output */
10271027};
r9419r9420
11171117static I8155_INTERFACE( tandy200_8155_intf )
11181118{
11191119   DEVCB_NULL,                        /* port A read */
1120   DEVCB_HANDLER(tandy200_8155_port_a_w),   /* port A write */
11201121   DEVCB_NULL,                        /* port B read */
1122   DEVCB_HANDLER(tandy200_8155_port_b_w),   /* port B write */
11211123   DEVCB_HANDLER(tandy200_8155_port_c_r),   /* port C read */
1122   DEVCB_HANDLER(tandy200_8155_port_a_w),   /* port A write */
1123   DEVCB_HANDLER(tandy200_8155_port_b_w),   /* port B write */
11241124   DEVCB_NULL,                        /* port C write */
11251125   DEVCB_LINE(tandy200_8155_to_w)         /* timer output */
11261126};
src/mess/drivers/comx35.c
r9419r9420
4646   ADDRESS_MAP_UNMAP_HIGH
4747   AM_RANGE(0x01, 0x01) AM_WRITE(bank_select_w)
4848   AM_RANGE(0x02, 0x02) AM_READWRITE(io_r, io_w)
49   AM_RANGE(0x03, 0x03) AM_DEVREAD_LEGACY(CDP1871_TAG, cdp1871_data_r)
49   AM_RANGE(0x03, 0x03) AM_DEVREAD(CDP1871_TAG, cdp1871_device, data_r)
5050   AM_RANGE(0x03, 0x07) AM_WRITE(cdp1869_w)
5151ADDRESS_MAP_END
5252
r9419r9420
219219   else
220220   {
221221      // interrupts enabled: keyboard repeat
222      return cdp1871_rpt_r(state->m_kbe);
222      return state->m_kbe->rpt_r();
223223   }
224224}
225225
src/mess/drivers/exp85.c
r9419r9420
99/*
1010
1111    TODO:
12
12   
1313    - needs a terminal, or a dump of the hexadecimal keyboard monitor ROM
1414    - serial input/output at SID/SOD pins
1515    - disable ROM mirror after boot
r9419r9420
3838
3939static ADDRESS_MAP_START( exp85_io, ADDRESS_SPACE_IO, 8 )
4040   ADDRESS_MAP_UNMAP_HIGH
41   AM_RANGE(0xf0, 0xf3) AM_DEVREADWRITE(I8355_TAG, i8355_r, i8355_w)
42   AM_RANGE(0xf8, 0xfd) AM_DEVREADWRITE(I8155_TAG, i8155_r, i8155_w)
41   AM_RANGE(0xf0, 0xf3) AM_DEVREADWRITE_MODERN(I8355_TAG, i8355_device, io_r, io_w)
42   AM_RANGE(0xf8, 0xfd) AM_DEVREADWRITE_MODERN(I8155_TAG, i8155_device, io_r, io_w)
4343//  AM_RANGE(0xfe, 0xff) AM_DEVREADWRITE(I8279_TAG, i8279_r, i8279_w)
4444ADDRESS_MAP_END
4545
r9419r9420
7777static I8155_INTERFACE( i8155_intf )
7878{
7979   DEVCB_NULL,   /* port A read */
80   DEVCB_NULL,   /* port B read */
81   DEVCB_NULL,   /* port C read */
8280   DEVCB_NULL,   /* port A write */
81   DEVCB_NULL,   /* port B read */
8382   DEVCB_NULL,   /* port B write */
83   DEVCB_NULL,   /* port C read */
8484   DEVCB_NULL,   /* port C write */
8585   DEVCB_NULL   /* timer output */
8686};
r9419r9420
136136static I8355_INTERFACE( i8355_intf )
137137{
138138   DEVCB_HANDLER(i8355_a_r),   /* port A read */
139   DEVCB_NULL,               /* port B read */
140139   DEVCB_HANDLER(i8355_a_w),   /* port A write */
140   DEVCB_NULL,               /* port B read */
141141   DEVCB_NULL,               /* port B write */
142142};
143143
r9419r9420
202202};
203203
204204static MACHINE_CONFIG_START( exp85, exp85_state )
205
206205    /* basic machine hardware */
207206    MDRV_CPU_ADD(I8085A_TAG, I8085A, XTAL_6_144MHz)
208207    MDRV_CPU_PROGRAM_MAP(exp85_mem)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team