Previous 15994 Revisions Next

r11205 Saturday 16th April, 2011 at 17:56:48 UTC by Curt Coder
Synced with MAME.
[src/emu/machine]cdp1852.c cdp1852.h

src/emu/machine/cdp1852.c
r11204r11205
11/**********************************************************************
22
33    RCA CDP1852 Byte-Wide Input/Output Port emulation
4
4   
55    Copyright Nicola Salmoria and the MAME Team.
66    Visit http://mamedev.org for licensing and usage restrictions.
77
88**********************************************************************/
99
10#include "emu.h"
1110#include "cdp1852.h"
11#include "machine/devhelpr.h"
1212
13/***************************************************************************
14    TYPE DEFINITIONS
15***************************************************************************/
1613
17typedef struct _cdp1852_t cdp1852_t;
18struct _cdp1852_t
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19enum
1920{
20   devcb_resolved_write_line   out_sr_func;
21   devcb_resolved_read8      in_data_func;
22   devcb_resolved_write8      out_data_func;
21   MODE_INPUT = 0,
22   MODE_OUTPUT
23};
2324
24   cdp1852_mode mode;            /* operation mode */
25   int new_data;               /* new data written */
26   UINT8 data;                  /* data latch */
27   UINT8 next_data;            /* next data*/
2825
29   int sr;                     /* service request flag */
30   int next_sr;               /* next value of service request flag */
3126
32   /* timers */
33   emu_timer *scan_timer;         /* scan timer */
34};
27//**************************************************************************
28//  DEVICE DEFINITIONS
29//**************************************************************************
3530
36/***************************************************************************
37    INLINE FUNCTIONS
38***************************************************************************/
31const device_type CDP1852 = cdp1852_device_config::static_alloc_device_config;
3932
40INLINE cdp1852_t *get_safe_token(device_t *device)
41{
42   assert(device != NULL);
43   return (cdp1852_t *)downcast<legacy_device_base *>(device)->token();
44}
4533
46INLINE const cdp1852_interface *get_interface(device_t *device)
47{
48   assert(device != NULL);
49   assert((device->type() == CDP1852));
50   return (const cdp1852_interface *) device->baseconfig().static_config();
51}
5234
53/***************************************************************************
54    IMPLEMENTATION
55***************************************************************************/
35//**************************************************************************
36//  DEVICE CONFIGURATION
37//**************************************************************************
5638
57/*-------------------------------------------------
58    set_sr_line - service request out
59-------------------------------------------------*/
39GENERIC_DEVICE_CONFIG_SETUP(cdp1852, "CDP1852")
6040
61static void set_sr_line(cdp1852_t *cdp1852, int level)
41
42//-------------------------------------------------
43//  device_config_complete - perform any
44//  operations now that the configuration is
45//  complete
46//-------------------------------------------------
47
48void cdp1852_device_config::device_config_complete()
6249{
63   if (cdp1852->sr != level)
50   // inherit a copy of the static data
51   const cdp1852_interface *intf = reinterpret_cast<const cdp1852_interface *>(static_config());
52   if (intf != NULL)
53      *static_cast<cdp1852_interface *>(this) = *intf;
54
55   // or initialize to defaults if none provided
56   else
6457   {
65      cdp1852->sr = level;
66
67      devcb_call_write_line(&cdp1852->out_sr_func, cdp1852->sr);
58      memset(&m_in_mode_func, 0, sizeof(m_in_mode_func));
59      memset(&m_out_sr_func, 0, sizeof(m_out_sr_func));
60      memset(&m_in_data_func, 0, sizeof(m_in_data_func));
61      memset(&m_out_data_func, 0, sizeof(m_out_data_func));
6862   }
6963}
7064
71/*-------------------------------------------------
72    TIMER_CALLBACK( cdp1852_scan_tick )
73-------------------------------------------------*/
7465
75static TIMER_CALLBACK( cdp1852_scan_tick )
76{
77   device_t *device = (device_t *)ptr;
78   cdp1852_t *cdp1852 = get_safe_token(device);
7966
80   switch (cdp1852->mode)
81   {
82   case CDP1852_MODE_INPUT:
83      /* input data into register */
84      cdp1852->data = devcb_call_read8(&cdp1852->in_data_func, 0);
67//**************************************************************************
68//  INLINE HELPERS
69//**************************************************************************
8570
86      /* signal processor */
87      set_sr_line(cdp1852, 0);
88      break;
71//-------------------------------------------------
72//  get_mode -
73//-------------------------------------------------
8974
90   case CDP1852_MODE_OUTPUT:
91      if (cdp1852->new_data)
92      {
93         cdp1852->new_data = 0;
75int cdp1852_device::get_mode()
76{
77   return devcb_call_read_line(&m_in_mode_func);
78}
9479
95         /* latch data into register */
96         cdp1852->data = cdp1852->next_data;
9780
98         /* output data */
99         devcb_call_write8(&cdp1852->out_data_func, 0, cdp1852->data);
81//-------------------------------------------------
82//  set_sr_line -
83//-------------------------------------------------
10084
101         /* signal peripheral device */
102         set_sr_line(cdp1852, 1);
85void cdp1852_device::set_sr_line(int state)
86{
87   if (m_sr != state)
88   {
89      m_sr = state;
10390
104         cdp1852->next_sr = 0;
105      }
106      else
107      {
108         set_sr_line(cdp1852, cdp1852->next_sr);
109      }
110      break;
91      devcb_call_write_line(&m_out_sr_func, m_sr);
11192   }
11293}
11394
114/*-------------------------------------------------
115    cdp1852_data_r - data register read
116-------------------------------------------------*/
11795
118READ8_DEVICE_HANDLER( cdp1852_data_r )
119{
120   cdp1852_t *cdp1852 = get_safe_token(device);
12196
122   if (cdp1852->mode == CDP1852_MODE_INPUT && device->clock() == 0)
123   {
124      // input data into register
125      cdp1852->data = devcb_call_read8(&cdp1852->in_data_func, 0);
126   }
97//**************************************************************************
98//  LIVE DEVICE
99//**************************************************************************
127100
128   set_sr_line(cdp1852, 1);
101//-------------------------------------------------
102//  cdp1852_device - constructor
103//-------------------------------------------------
129104
130   return cdp1852->data;
105cdp1852_device::cdp1852_device(running_machine &_machine, const cdp1852_device_config &config)
106    : device_t(_machine, config),
107      m_config(config)
108{
131109}
132110
133/*-------------------------------------------------
134    cdp1852_data_r - data register write
135-------------------------------------------------*/
136111
137WRITE8_DEVICE_HANDLER( cdp1852_data_w )
112//-------------------------------------------------
113//  device_start - device-specific startup
114//-------------------------------------------------
115
116void cdp1852_device::device_start()
138117{
139   cdp1852_t *cdp1852 = get_safe_token(device);
118   // resolve callbacks
119   devcb_resolve_read_line(&m_in_mode_func, &m_config.m_in_mode_func, this);
120   devcb_resolve_write_line(&m_out_sr_func, &m_config.m_out_sr_func, this);
121   devcb_resolve_read8(&m_in_data_func, &m_config.m_in_data_func, this);
122   devcb_resolve_write8(&m_out_data_func, &m_config.m_out_data_func, this);
140123
141   if (cdp1852->mode == CDP1852_MODE_OUTPUT)
124   // allocate timers
125   if (clock() > 0)
142126   {
143      cdp1852->next_data = data;
144      cdp1852->new_data = 1;
127      m_scan_timer = timer_alloc();
128      m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock()));
145129   }
130
131   // register for state saving
132   save_item(NAME(m_new_data));
133   save_item(NAME(m_data));
134   save_item(NAME(m_next_data));
135   save_item(NAME(m_sr));
136   save_item(NAME(m_next_sr));
146137}
147138
148/*-------------------------------------------------
149    DEVICE_START( cdp1852 )
150-------------------------------------------------*/
151139
152static DEVICE_START( cdp1852 )
140//-------------------------------------------------
141//  device_reset - device-specific reset
142//-------------------------------------------------
143
144void cdp1852_device::device_reset()
153145{
154   cdp1852_t *cdp1852 = get_safe_token(device);
155   const cdp1852_interface *intf = get_interface(device);
146   // reset data register
147   m_data = 0;
156148
157   /* resolve callbacks */
158   devcb_resolve_read8(&cdp1852->in_data_func, &intf->in_data_func, device);
159   devcb_resolve_write8(&cdp1852->out_data_func, &intf->out_data_func, device);
160   devcb_resolve_write_line(&cdp1852->out_sr_func, &intf->out_sr_func, device);
161
162   /* set initial values */
163   cdp1852->mode = (cdp1852_mode)intf->mode;
164
165   if (device->clock() > 0)
149   if (get_mode() == MODE_INPUT)
166150   {
167      /* create the scan timer */
168      cdp1852->scan_timer = device->machine().scheduler().timer_alloc(FUNC(cdp1852_scan_tick), (void *)device);
169      cdp1852->scan_timer->adjust(attotime::zero, 0, attotime::from_hz(device->clock()));
151      // reset service request flip-flop
152      set_sr_line(1);
170153   }
154   else
155   {
156      // output data
157      devcb_call_write8(&m_out_data_func, 0, m_data);
171158
172   /* register for state saving */
173   device->save_item(NAME(cdp1852->new_data));
174   device->save_item(NAME(cdp1852->data));
175   device->save_item(NAME(cdp1852->next_data));
176   device->save_item(NAME(cdp1852->sr));
177   device->save_item(NAME(cdp1852->next_sr));
159      // reset service request flip-flop
160      set_sr_line(0);
161   }
178162}
179163
180/*-------------------------------------------------
181    DEVICE_RESET( cdp1852 )
182-------------------------------------------------*/
183164
184static DEVICE_RESET( cdp1852 )
165//-------------------------------------------------
166//  device_timer - handler timer events
167//-------------------------------------------------
168
169void cdp1852_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
185170{
186   cdp1852_t *cdp1852 = get_safe_token(device);
171   switch (get_mode())
172   {
173   case MODE_INPUT:
174      // input data into register
175      m_data = devcb_call_read8(&m_in_data_func, 0);
187176
188   /* reset data register */
189   cdp1852->data = 0;
177      // signal processor
178      set_sr_line(0);
179      break;
190180
191   if (cdp1852->mode == CDP1852_MODE_INPUT)
192   {
193      /* reset service request flip-flop */
194      set_sr_line(cdp1852, 1);
195   }
196   else
197   {
198      /* output data */
199      devcb_call_write8(&cdp1852->out_data_func, 0, cdp1852->data);
181   case MODE_OUTPUT:
182      if (m_new_data)
183      {
184         m_new_data = 0;
200185
201      /* reset service request flip-flop */
202      set_sr_line(cdp1852, 0);
186         // latch data into register
187         m_data = m_next_data;
188
189         // output data
190         devcb_call_write8(&m_out_data_func, 0, m_data);
191
192         // signal peripheral device
193         set_sr_line(1);
194
195         m_next_sr = 0;
196      }
197      else
198      {
199         set_sr_line(m_next_sr);
200      }
201      break;
203202   }
204203}
205204
206/*-------------------------------------------------
207    DEVICE_GET_INFO( cdp1852 )
208-------------------------------------------------*/
209205
210DEVICE_GET_INFO( cdp1852 )
206//-------------------------------------------------
207//  read - data read
208//-------------------------------------------------
209
210READ8_MEMBER( cdp1852_device::read )
211211{
212   switch (state)
212   if ((get_mode() == MODE_INPUT) && (clock() == 0))
213213   {
214      /* --- the following bits of info are returned as 64-bit signed integers --- */
215      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(cdp1852_t);            break;
216      case DEVINFO_INT_INLINE_CONFIG_BYTES:         info->i = 0;                        break;
214      // input data into register
215      m_data = devcb_call_read8(&m_in_data_func, 0);
216   }
217217
218      /* --- the following bits of info are returned as pointers to data or functions --- */
219      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(cdp1852);   break;
220      case DEVINFO_FCT_STOP:                     /* Nothing */                        break;
221      case DEVINFO_FCT_RESET:                     info->reset = DEVICE_RESET_NAME(cdp1852);   break;
218   set_sr_line(1);
222219
223      /* --- the following bits of info are returned as NULL-terminated strings --- */
224      case DEVINFO_STR_NAME:                     strcpy(info->s, "RCA CDP1852");            break;
225      case DEVINFO_STR_FAMILY:                  strcpy(info->s, "RCA CDP1800");            break;
226      case DEVINFO_STR_VERSION:                  strcpy(info->s, "1.0");                  break;
227      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);               break;
228      case DEVINFO_STR_CREDITS:                  strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break;
229   }
220   return m_data;
230221}
231222
232223
233DEFINE_LEGACY_DEVICE(CDP1852, cdp1852);
224//-------------------------------------------------
225//  write - data write
226//-------------------------------------------------
227
228WRITE8_MEMBER( cdp1852_device::write )
229{
230   if (get_mode() == MODE_OUTPUT)
231   {
232      m_next_data = data;
233      m_new_data = 1;
234   }
235}
src/emu/machine/cdp1852.h
r11204r11205
2222
2323**********************************************************************/
2424
25#pragma once
26
2527#ifndef __CDP1852__
2628#define __CDP1852__
2729
28#include "devlegcy.h"
30#include "emu.h"
2931
3032
31/***************************************************************************
32    MACROS / CONSTANTS
33***************************************************************************/
3433
34//**************************************************************************
35//  MACROS / CONSTANTS
36//**************************************************************************
37
3538#define CDP1852_CLOCK_HIGH   0
3639
37DECLARE_LEGACY_DEVICE(CDP1852, cdp1852);
40#define CDP1852_MODE_INPUT \
41   DEVCB_LINE_GND
3842
43#define CDP1852_MODE_OUTPUT \
44   DEVCB_LINE_VCC
45
46
47
48//**************************************************************************
49//  INTERFACE CONFIGURATION MACROS
50//**************************************************************************
51
3952#define MCFG_CDP1852_ADD(_tag, _clock, _config) \
4053   MCFG_DEVICE_ADD(_tag, CDP1852, _clock) \
4154   MCFG_DEVICE_CONFIG(_config)
4255
43#define CDP1852_INTERFACE(_name) \
44   const cdp1852_interface (_name)=
4556
46/***************************************************************************
47    TYPE DEFINITIONS
48***************************************************************************/
57#define CDP1852_INTERFACE(name) \
58   const cdp1852_interface (name)=
4959
50enum _cdp1852_mode {
51   CDP1852_MODE_INPUT = 0,
52   CDP1852_MODE_OUTPUT
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> cdp1852_interface
67
68struct cdp1852_interface
69{
70   devcb_read_line         m_in_mode_func;
71
72   devcb_read8            m_in_data_func;
73   devcb_write8         m_out_data_func;
74
75   devcb_write_line      m_out_sr_func;
5376};
54typedef enum _cdp1852_mode cdp1852_mode;
5577
56typedef struct _cdp1852_interface cdp1852_interface;
57struct _cdp1852_interface
78
79// ======================> cdp1852_device_config
80
81class cdp1852_device_config :   public device_config,
82                                public cdp1852_interface
5883{
59   int mode;            /* operation mode */
84   friend class cdp1852_device;
6085
61   /* this gets called for every external data read */
62   devcb_read8            in_data_func;
86    // construction/destruction
87    cdp1852_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
6388
64   /* this gets called for every external data write */
65   devcb_write8         out_data_func;
89public:
90    // allocators
91    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
92    virtual device_t *alloc_device(running_machine &machine) const;
6693
67   /* this gets called for every change of the SR pin (pin 23) */
68   devcb_write_line      out_sr_func;
94protected:
95    // device_config overrides
96    virtual void device_config_complete();
6997};
7098
71/***************************************************************************
72    PROTOTYPES
73***************************************************************************/
7499
75/* data access */
76READ8_DEVICE_HANDLER( cdp1852_data_r );
77WRITE8_DEVICE_HANDLER( cdp1852_data_w );
100// ======================> cdp1852_device
78101
102class cdp1852_device :  public device_t
103{
104    friend class cdp1852_device_config;
105
106    // construction/destruction
107    cdp1852_device(running_machine &_machine, const cdp1852_device_config &_config);
108
109public:
110    DECLARE_READ8_MEMBER( read );
111    DECLARE_WRITE8_MEMBER( write );
112
113protected:
114    // device-level overrides
115    virtual void device_start();
116    virtual void device_reset();
117   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
118
119private:
120   int get_mode();
121   inline void set_sr_line(int state);
122
123   devcb_resolved_read_line   m_in_mode_func;
124   devcb_resolved_write_line   m_out_sr_func;
125   devcb_resolved_read8      m_in_data_func;
126   devcb_resolved_write8      m_out_data_func;
127
128   int m_new_data;            // new data written
129   UINT8 m_data;            // data latch
130   UINT8 m_next_data;         // next data
131
132   int m_sr;               // service request flag
133   int m_next_sr;            // next value of service request flag
134
135   // timers
136   emu_timer *m_scan_timer;
137
138   const cdp1852_device_config &m_config;
139};
140
141
142// device type definition
143extern const device_type CDP1852;
144
145
146
79147#endif

Previous 15994 Revisions Next


© 1998-2018 The MESS Team