Previous 199869 Revisions Next

r23542 Saturday 8th June, 2013 at 16:15:23 UTC by Andrew Gardner
Modernize adc1038 and adc12138 devices. [Osso]
[src/emu/machine]adc1038.c adc1038.h adc1213x.c adc1213x.h
[src/mame/drivers]gticlub.c hornet.c nwk-tr.c
[src/mame/includes]flower.h
[src/mame/machine]nmk112.h

trunk/src/emu/machine/adc1213x.c
r23541r23542
2020    TYPE DEFINITIONS
2121***************************************************************************/
2222
23struct adc12138_state
24{
25   adc1213x_input_convert_func input_callback_r;
26
27   int cycle;
28   int data_out;
29   int data_in;
30   int conv_mode;
31   int auto_cal;
32   int auto_zero;
33   int acq_time;
34   int data_out_sign;
35   int mode;
36   int input_shift_reg;
37   int output_shift_reg;
38   int end_conv;
39};
40
41
4223#define ADC1213X_CONV_MODE_12_MSB_FIRST         0
4324#define ADC1213X_CONV_MODE_16_MSB_FIRST         1
4425#define ADC1213X_CONV_MODE_12_LSB_FIRST         2
r23541r23542
4930#define ADC1213X_ACQUISITION_TIME_18_CCLK       2
5031#define ADC1213X_ACQUISITION_TIME_34_CCLK       3
5132
52/***************************************************************************
53    INLINE FUNCTIONS
54***************************************************************************/
5533
56INLINE adc12138_state *get_safe_token(device_t *device)
34
35const device_type ADC12130 = &device_creator<adc12130_device>;
36
37adc12130_device::adc12130_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
38   : adc12138_device(mconfig, ADC12130, "A/D Converter 12130", tag, owner, clock)
5739{
58   assert(device != NULL);
59   assert((device->type() == ADC12130) || (device->type() == ADC12132) || (device->type() == ADC12138));
60   return (adc12138_state *)downcast<adc12138_device *>(device)->token();
6140}
6241
63INLINE const adc12138_interface *get_interface(device_t *device)
42
43const device_type ADC12132 = &device_creator<adc12132_device>;
44
45adc12132_device::adc12132_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
46   : adc12138_device(mconfig, ADC12132, "A/D Converter 12132", tag, owner, clock)
6447{
65   assert(device != NULL);
66   assert((device->type() == ADC12130) || (device->type() == ADC12132) || (device->type() == ADC12138));
67   return (const adc12138_interface *) device->static_config();
6848}
6949
7050
51const device_type ADC12138 = &device_creator<adc12138_device>;
52
53adc12138_device::adc12138_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
54   : device_t(mconfig, ADC12138, "A/D Converter 12138", tag, owner, clock)
55{
56}
57adc12138_device::adc12138_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
58   : device_t(mconfig, type, name, tag, owner, clock)
59{
60}
61
62//-------------------------------------------------
63//  device_config_complete - perform any
64//  operations now that the configuration is
65//  complete
66//-------------------------------------------------
67
68void adc12138_device::device_config_complete()
69{
70   // inherit a copy of the static data
71   const adc12138_interface *intf = reinterpret_cast<const adc12138_interface *>(static_config());
72   if (intf != NULL)
73      *static_cast<adc12138_interface *>(this) = *intf;
74
75   // or initialize to defaults if none provided
76   else
77   {
78      input_callback_r = NULL;
79   }
80}
81
82//-------------------------------------------------
83//  device_start - device-specific startup
84//-------------------------------------------------
85
86void adc12138_device::device_start()
87{
88   /* resolve callbacks */
89   m_input_callback_r_func = input_callback_r;
90
91   /* register for state saving */
92   save_item(NAME(m_cycle));
93   save_item(NAME(m_data_out));
94   save_item(NAME(m_data_in));
95   save_item(NAME(m_conv_mode));
96   save_item(NAME(m_auto_cal));
97   save_item(NAME(m_auto_zero));
98   save_item(NAME(m_acq_time));
99   save_item(NAME(m_data_out_sign));
100   save_item(NAME(m_mode));
101   save_item(NAME(m_input_shift_reg));
102   save_item(NAME(m_output_shift_reg));
103   save_item(NAME(m_end_conv));
104}
105
106//-------------------------------------------------
107//  device_reset - device-specific reset
108//-------------------------------------------------
109
110void adc12138_device::device_reset()
111{
112   m_conv_mode = ADC1213X_CONV_MODE_12_MSB_FIRST;
113   m_data_out_sign = 1;
114   m_auto_cal = 0;
115   m_auto_zero = 0;
116   m_acq_time = ADC1213X_ACQUISITION_TIME_10_CCLK;
117}
118
71119/***************************************************************************
72120    IMPLEMENTATION
73121***************************************************************************/
74122
75123/*-------------------------------------------------
76    adc1213x_di_w
124    di_w
77125-------------------------------------------------*/
78126
79WRITE8_DEVICE_HANDLER( adc1213x_di_w )
127WRITE8_MEMBER( adc12138_device::di_w )
80128{
81   adc12138_state *adc1213x = get_safe_token(device);
82   adc1213x->data_in = data & 1;
129   m_data_in = data & 1;
83130}
84131
85132/*-------------------------------------------------
86    adc1213x_convert
133    convert
87134-------------------------------------------------*/
88135
89static void adc1213x_convert(device_t *device, int channel, int bits16, int lsbfirst)
136void adc12138_device::convert(int channel, int bits16, int lsbfirst)
90137{
91   adc12138_state *adc1213x = get_safe_token(device);
92138   int i;
93139   int bits;
94140   int input_value;
r23541r23542
104150   {
105151      case 0x8:       // H L L L - CH0 (single-ended)
106152      {
107         input = adc1213x->input_callback_r(device, 0);
153         input = m_input_callback_r_func(this, 0);
108154         break;
109155      }
110156      case 0xc:       // H H L L - CH1 (single-ended)
111157      {
112         input = adc1213x->input_callback_r(device, 1);
158         input = m_input_callback_r_func(this, 1);
113159         break;
114160      }
115161      case 0x9:       // H L L H - CH2 (single-ended)
116162      {
117         input = adc1213x->input_callback_r(device, 2);
163         input = m_input_callback_r_func(this, 2);
118164         break;
119165      }
120166      case 0xd:       // H H L H - CH3 (single-ended)
121167      {
122         input = adc1213x->input_callback_r(device, 3);
168         input = m_input_callback_r_func(this, 3);
123169         break;
124170      }
125171      case 0xa:       // H L H L - CH4 (single-ended)
126172      {
127         input = adc1213x->input_callback_r(device, 4);
173         input = m_input_callback_r_func(this, 4);
128174         break;
129175      }
130176      case 0xe:       // H H H L - CH5 (single-ended)
131177      {
132         input = adc1213x->input_callback_r(device, 5);
178         input = m_input_callback_r_func(this, 5);
133179         break;
134180      }
135181      case 0xb:       // H L H H - CH6 (single-ended)
136182      {
137         input = adc1213x->input_callback_r(device, 6);
183         input = m_input_callback_r_func(this, 6);
138184         break;
139185      }
140186      case 0xf:       // H H H H - CH7 (single-ended)
141187      {
142         input = adc1213x->input_callback_r(device, 7);
188         input = m_input_callback_r_func(this, 7);
143189         break;
144190      }
145191      default:
r23541r23542
153199   bits = 12;
154200
155201   // sign-extend if needed
156   if (adc1213x->data_out_sign)
202   if (m_data_out_sign)
157203   {
158204      input_value = input_value | ((input_value & 0x800) << 1);
159205      bits++;
160206   }
161207
162   adc1213x->output_shift_reg = 0;
208   m_output_shift_reg = 0;
163209
164210   for (i=0; i < bits; i++)
165211   {
166212      if (input_value & (1 << ((bits-1) - i)))
167213      {
168         adc1213x->output_shift_reg |= (1 << i);
214         m_output_shift_reg |= (1 << i);
169215      }
170216   }
171217
172   adc1213x->data_out = adc1213x->output_shift_reg & 1;
173   adc1213x->output_shift_reg >>= 1;
218   m_data_out = m_output_shift_reg & 1;
219   m_output_shift_reg >>= 1;
174220}
175221
176222/*-------------------------------------------------
177    adc1213x_cs_w
223    cs_w
178224-------------------------------------------------*/
179225
180WRITE8_DEVICE_HANDLER( adc1213x_cs_w )
226WRITE8_MEMBER( adc12138_device::cs_w )
181227{
182   adc12138_state *adc1213x = get_safe_token(device);
183
184228   if (data)
185229   {
186230      //printf("ADC: CS\n");
187231
188      if (adc1213x->cycle >= 7)
232      if (m_cycle >= 7)
189233      {
190         int mode = adc1213x->input_shift_reg >> (adc1213x->cycle - 8);
234         int mode = m_input_shift_reg >> (m_cycle - 8);
191235
192236         switch (mode & 0xf)
193237         {
194238            case 0x0:       // X X X X L L L L - 12 or 13 Bit MSB First conversion
195239            {
196               adc1213x_convert(device, (mode >> 4) & 0xf, 0, 0);
240               convert((mode >> 4) & 0xf, 0, 0);
197241               break;
198242            }
199243            case 0x1:       // X X X X L L L H - 16 or 17 Bit MSB First conversion
200244            {
201               adc1213x_convert(device, (mode >> 4) & 0xf, 1, 0);
245               convert((mode >> 4) & 0xf, 1, 0);
202246               break;
203247            }
204248            case 0x4:       // X X X X L H L L - 12 or 13 Bit LSB First conversion
205249            {
206               adc1213x_convert(device, (mode >> 4) & 0xf, 0, 1);
250               convert((mode >> 4) & 0xf, 0, 1);
207251               break;
208252            }
209253            case 0x5:       // X X X X L H L H - 16 or 17 Bit LSB First conversion
210254            {
211               adc1213x_convert(device, (mode >> 4) & 0xf, 1, 1);
255               convert((mode >> 4) & 0xf, 1, 1);
212256               break;
213257            }
214258
r23541r23542
218262               {
219263                  case 0x08:      // L L L L H L L L - Auto cal
220264                  {
221                     adc1213x->auto_cal = 1;
265                     m_auto_cal = 1;
222266                     break;
223267                  }
224268
225269                  case 0x0e:      // L L L L H H H L - Acquisition time 6 CCLK cycles
226270                  {
227                     adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK;
271                     m_acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK;
228272                     break;
229273                  }
230274
231275                  case 0x8d:      // H L L L H H L H - Data out with sign
232276                  {
233                     adc1213x->data_out_sign = 1;
277                     m_data_out_sign = 1;
234278                     break;
235279                  }
236280
r23541r23542
249293         }
250294      }
251295
252      adc1213x->cycle = 0;
253      adc1213x->input_shift_reg = 0;
296      m_cycle = 0;
297      m_input_shift_reg = 0;
254298
255      adc1213x->end_conv = 0;
299      m_end_conv = 0;
256300   }
257301}
258302
259303/*-------------------------------------------------
260    adc1213x_sclk_w
304    sclk_w
261305-------------------------------------------------*/
262306
263WRITE8_DEVICE_HANDLER( adc1213x_sclk_w )
307WRITE8_MEMBER( adc12138_device::sclk_w )
264308{
265   adc12138_state *adc1213x = get_safe_token(device);
266
267309   if (data)
268310   {
269311      //printf("ADC: cycle %d, DI = %d\n", adc1213x->cycle, adc1213x->data_in);
270312
271      adc1213x->input_shift_reg <<= 1;
272      adc1213x->input_shift_reg |= adc1213x->data_in;
313      m_input_shift_reg <<= 1;
314      m_input_shift_reg |= m_data_in;
273315
274      adc1213x->data_out = adc1213x->output_shift_reg & 1;
275      adc1213x->output_shift_reg >>= 1;
316      m_data_out = m_output_shift_reg & 1;
317      m_output_shift_reg >>= 1;
276318
277      adc1213x->cycle++;
319      m_cycle++;
278320   }
279321}
280322
281323/*-------------------------------------------------
282    adc1213x_conv_w
324    conv_w
283325-------------------------------------------------*/
284326
285WRITE8_DEVICE_HANDLER( adc1213x_conv_w )
327WRITE8_MEMBER( adc12138_device::conv_w )
286328{
287   adc12138_state *adc1213x = get_safe_token(device);
288   adc1213x->end_conv = 1;
329   m_end_conv = 1;
289330}
290331
291332/*-------------------------------------------------
292    adc1213x_do_r
333    do_r
293334-------------------------------------------------*/
294335
295READ8_DEVICE_HANDLER( adc1213x_do_r )
336READ8_MEMBER( adc12138_device::do_r )
296337{
297   adc12138_state *adc1213x = get_safe_token(device);
298
299338   //printf("ADC: DO\n");
300   return adc1213x->data_out;
339   return m_data_out;
301340}
302341
303342/*-------------------------------------------------
304    adc1213x_eoc_r
343    eoc_r
305344-------------------------------------------------*/
306345
307READ8_DEVICE_HANDLER( adc1213x_eoc_r )
346READ8_MEMBER( adc12138_device::eoc_r )
308347{
309   adc12138_state *adc1213x = get_safe_token(device);
310   return adc1213x->end_conv;
348   return m_end_conv;
311349}
312
313/*-------------------------------------------------
314    DEVICE_START( adc1213x )
315-------------------------------------------------*/
316
317static DEVICE_START( adc12138 )
318{
319   adc12138_state *adc1213x = get_safe_token(device);
320   const adc12138_interface *intf = get_interface(device);
321
322   /* resolve callbacks */
323   adc1213x->input_callback_r = intf->input_callback_r;
324
325   /* register for state saving */
326   device->save_item(NAME(adc1213x->cycle));
327   device->save_item(NAME(adc1213x->data_out));
328   device->save_item(NAME(adc1213x->data_in));
329   device->save_item(NAME(adc1213x->conv_mode));
330   device->save_item(NAME(adc1213x->auto_cal));
331   device->save_item(NAME(adc1213x->auto_zero));
332   device->save_item(NAME(adc1213x->acq_time));
333   device->save_item(NAME(adc1213x->data_out_sign));
334   device->save_item(NAME(adc1213x->mode));
335   device->save_item(NAME(adc1213x->input_shift_reg));
336   device->save_item(NAME(adc1213x->output_shift_reg));
337   device->save_item(NAME(adc1213x->end_conv));
338}
339
340
341/*-------------------------------------------------
342    DEVICE_RESET( adc1213x )
343-------------------------------------------------*/
344
345static DEVICE_RESET( adc12138 )
346{
347   adc12138_state *adc1213x = get_safe_token(device);
348
349   adc1213x->conv_mode = ADC1213X_CONV_MODE_12_MSB_FIRST;
350   adc1213x->data_out_sign = 1;
351   adc1213x->auto_cal = 0;
352   adc1213x->auto_zero = 0;
353   adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_10_CCLK;
354}
355
356const device_type ADC12130 = &device_creator<adc12130_device>;
357
358adc12130_device::adc12130_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
359   : adc12138_device(mconfig, ADC12130, "A/D Converter 12130", tag, owner, clock)
360{
361}
362
363
364const device_type ADC12132 = &device_creator<adc12132_device>;
365
366adc12132_device::adc12132_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
367   : adc12138_device(mconfig, ADC12132, "A/D Converter 12132", tag, owner, clock)
368{
369}
370
371
372const device_type ADC12138 = &device_creator<adc12138_device>;
373
374adc12138_device::adc12138_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
375   : device_t(mconfig, ADC12138, "A/D Converter 12138", tag, owner, clock)
376{
377   m_token = global_alloc_clear(adc12138_state);
378}
379adc12138_device::adc12138_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
380   : device_t(mconfig, type, name, tag, owner, clock)
381{
382   m_token = global_alloc_clear(adc12138_state);
383}
384
385//-------------------------------------------------
386//  device_config_complete - perform any
387//  operations now that the configuration is
388//  complete
389//-------------------------------------------------
390
391void adc12138_device::device_config_complete()
392{
393}
394
395//-------------------------------------------------
396//  device_start - device-specific startup
397//-------------------------------------------------
398
399void adc12138_device::device_start()
400{
401   DEVICE_START_NAME( adc12138 )(this);
402}
403
404//-------------------------------------------------
405//  device_reset - device-specific reset
406//-------------------------------------------------
407
408void adc12138_device::device_reset()
409{
410   DEVICE_RESET_NAME( adc12138 )(this);
411}
trunk/src/emu/machine/adc1213x.h
r23541r23542
1010#ifndef __ADC1213X_H__
1111#define __ADC1213X_H__
1212
13#include "devlegcy.h"
1413
14/***************************************************************************
15    TYPE DEFINITIONS
16***************************************************************************/
1517
18typedef double (*adc1213x_input_convert_func)(device_t *device, UINT8 input);
19
20struct adc12138_interface
21{
22   adc1213x_input_convert_func input_callback_r;
23};
24
1625/***************************************************************************
1726    MACROS / CONSTANTS
1827***************************************************************************/
1928
20class adc12138_device : public device_t
29class adc12138_device : public device_t,
30                              public adc12138_interface
2131{
2232public:
2333   adc12138_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
2434   adc12138_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
25   ~adc12138_device() { global_free(m_token); }
35   ~adc12138_device() {}
2636
27   // access to legacy token
28   void *token() const { assert(m_token != NULL); return m_token; }
37   DECLARE_WRITE8_MEMBER( di_w );
38   DECLARE_WRITE8_MEMBER( cs_w );
39   DECLARE_WRITE8_MEMBER( sclk_w );
40   DECLARE_WRITE8_MEMBER( conv_w );
41   DECLARE_READ8_MEMBER( do_r );
42   DECLARE_READ8_MEMBER( eoc_r );
43   
2944protected:
3045   // device-level overrides
3146   virtual void device_config_complete();
3247   virtual void device_start();
3348   virtual void device_reset();
34private:
49   
50   void convert(int channel, int bits16, int lsbfirst);
51
52   adc1213x_input_convert_func m_input_callback_r_func;
53   
54   private:
3555   // internal state
36   void *m_token;
56   int m_cycle;
57   int m_data_out;
58   int m_data_in;
59   int m_conv_mode;
60   int m_auto_cal;
61   int m_auto_zero;
62   int m_acq_time;
63   int m_data_out_sign;
64   int m_mode;
65   int m_input_shift_reg;
66   int m_output_shift_reg;
67   int m_end_conv;
3768};
3869
3970extern const device_type ADC12138;
r23541r23542
6798   MCFG_DEVICE_CONFIG(_config)
6899
69100
70/***************************************************************************
71    TYPE DEFINITIONS
72***************************************************************************/
73
74typedef double (*adc1213x_input_convert_func)(device_t *device, UINT8 input);
75
76struct adc12138_interface
77{
78   adc1213x_input_convert_func input_callback_r;
79};
80
81/***************************************************************************
82    PROTOTYPES
83***************************************************************************/
84
85extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_di_w );
86extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_cs_w );
87extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_sclk_w );
88extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_conv_w );
89extern DECLARE_READ8_DEVICE_HANDLER( adc1213x_do_r );
90extern DECLARE_READ8_DEVICE_HANDLER( adc1213x_eoc_r );
91
92101#endif  /* __ADC1213X_H__ */
trunk/src/emu/machine/adc1038.c
r23541r23542
1010#include "emu.h"
1111#include "adc1038.h"
1212
13/***************************************************************************
14    TYPE DEFINITIONS
15***************************************************************************/
1613
17struct adc1038_state
14const device_type ADC1038 = &device_creator<adc1038_device>;
15
16adc1038_device::adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
17   : device_t(mconfig, ADC1038, "A/D Converters 1038", tag, owner, clock)
1818{
19   int cycle;
20   int clk;
21   int adr;
22   int data_in;
23   int data_out;
24   int adc_data;
25   int sars;
26   adc1038_input_read_func input_callback_r;
19}
2720
28   int gticlub_hack;
29};
21//-------------------------------------------------
22//  device_config_complete - perform any
23//  operations now that the configuration is
24//  complete
25//-------------------------------------------------
3026
31/*****************************************************************************
32    INLINE FUNCTIONS
33*****************************************************************************/
27void adc1038_device::device_config_complete()
28{
29   // inherit a copy of the static data
30   const adc1038_interface *intf = reinterpret_cast<const adc1038_interface *>(static_config());
31   if (intf != NULL)
32      *static_cast<adc1038_interface *>(this) = *intf;
3433
35INLINE adc1038_state *adc1038_get_safe_token( device_t *device )
34   // or initialize to defaults if none provided
35   else
36   {
37      input_callback_r = NULL;
38   }
39}
40
41//-------------------------------------------------
42//  device_start - device-specific startup
43//-------------------------------------------------
44
45void adc1038_device::device_start()
3646{
37   assert(device != NULL);
38   assert(device->type() == ADC1038);
47   m_input_callback_r_func = input_callback_r;
3948
40   return (adc1038_state *)downcast<adc1038_device *>(device)->token();
49   save_item(NAME(m_cycle));
50   save_item(NAME(m_clk));
51   save_item(NAME(m_adr));
52   save_item(NAME(m_data_in));
53   save_item(NAME(m_data_out));
54   save_item(NAME(m_adc_data));
55   save_item(NAME(m_sars));
4156}
4257
43INLINE const adc1038_interface *adc1038_get_interface( device_t *device )
58//-------------------------------------------------
59//  device_reset - device-specific reset
60//-------------------------------------------------
61
62void adc1038_device::device_reset()
4463{
45   assert(device != NULL);
46   assert((device->type() == ADC1038));
47   return (const adc1038_interface *) device->static_config();
64   m_cycle = 0;
65   m_clk = 0;
66   m_adr = 0;
67   m_data_in = 0;
68   m_data_out = 0;
69   m_adc_data = 0;
70   m_sars = 1;
4871}
4972
5073/*****************************************************************************
5174    DEVICE HANDLERS
5275*****************************************************************************/
5376
54READ_LINE_DEVICE_HANDLER( adc1038_do_read )
77READ_LINE_MEMBER( adc1038_device::do_read )
5578{
56   adc1038_state *adc1038 = adc1038_get_safe_token(device);
79   m_data_out = (m_adc_data & 0x200) ? 1 : 0;
80   m_adc_data <<= 1;
5781
58   adc1038->data_out = (adc1038->adc_data & 0x200) ? 1 : 0;
59   adc1038->adc_data <<= 1;
60
6182   //printf("ADC DO\n");
62   return adc1038->data_out;
83   return m_data_out;
6384}
6485
65WRITE_LINE_DEVICE_HANDLER( adc1038_di_write )
86WRITE_LINE_MEMBER( adc1038_device::di_write )
6687{
67   adc1038_state *adc1038 = adc1038_get_safe_token(device);
68
69   adc1038->data_in = state;
88   m_data_in = state;
7089}
7190
72WRITE_LINE_DEVICE_HANDLER( adc1038_clk_write )
91WRITE_LINE_MEMBER( adc1038_device::clk_write )
7392{
74   adc1038_state *adc1038 = adc1038_get_safe_token(device);
75
7693   // GTI Club doesn't sync on SARS
77   if (adc1038->gticlub_hack)
94   if (m_gticlub_hack)
7895   {
79      if (adc1038->clk == 0 && state == 0)
96      if (m_clk == 0 && state == 0)
8097      {
81         adc1038->cycle = 0;
98         m_cycle = 0;
8299
83         /* notice that adc1038->adr is always < 7! */
84         adc1038->adc_data = adc1038->input_callback_r(device, adc1038->adr);
100         /* notice that m_adr is always < 7! */
101         m_adc_data = m_input_callback_r_func(this, m_adr);
85102      }
86103   }
87104
88105   if (state == 1)
89106   {
90      //printf("ADC CLK, DI = %d, cycle = %d\n", adc1038->data_in, adc1038->cycle);
107      //printf("ADC CLK, DI = %d, cycle = %d\n", m_data_in, m_cycle);
91108
92      if (adc1038->cycle == 0)            // A2
109      if (m_cycle == 0)            // A2
93110      {
94         adc1038->adr = 0;
95         adc1038->adr |= (adc1038->data_in << 2);
111         m_adr = 0;
112         m_adr |= (m_data_in << 2);
96113      }
97      else if (adc1038->cycle == 1)   // A1
114      else if (m_cycle == 1)   // A1
98115      {
99         adc1038->adr |= (adc1038->data_in << 1);
116         m_adr |= (m_data_in << 1);
100117      }
101      else if (adc1038->cycle == 2)   // A0
118      else if (m_cycle == 2)   // A0
102119      {
103         adc1038->adr |= (adc1038->data_in << 0);
120         m_adr |= (m_data_in << 0);
104121      }
105122
106      adc1038->cycle++;
123      m_cycle++;
107124   }
108125
109   adc1038->clk = state;
126   m_clk = state;
110127}
111128
112READ_LINE_DEVICE_HANDLER( adc1038_sars_read )
129READ_LINE_MEMBER( adc1038_device::sars_read )
113130{
114   adc1038_state *adc1038 = adc1038_get_safe_token(device);
131   m_cycle = 0;
115132
116   adc1038->cycle = 0;
133   /* notice that m_adr is always < 7! */
134   m_adc_data = m_input_callback_r_func(this, m_adr);
117135
118   /* notice that adc1038->adr is always < 7! */
119   adc1038->adc_data = adc1038->input_callback_r(device, adc1038->adr);
120
121   adc1038->sars ^= 1;
122   return adc1038->sars;
136   m_sars ^= 1;
137   return m_sars;
123138}
124
125
126/*****************************************************************************
127    DEVICE INTERFACE
128*****************************************************************************/
129
130static DEVICE_START( adc1038 )
131{
132   adc1038_state *adc1038 = adc1038_get_safe_token(device);
133   const adc1038_interface *intf = adc1038_get_interface(device);
134
135   adc1038->gticlub_hack = intf->gticlub_hack;
136   adc1038->input_callback_r = intf->input_callback_r;
137
138   device->save_item(NAME(adc1038->cycle));
139   device->save_item(NAME(adc1038->clk));
140   device->save_item(NAME(adc1038->adr));
141   device->save_item(NAME(adc1038->data_in));
142   device->save_item(NAME(adc1038->data_out));
143   device->save_item(NAME(adc1038->adc_data));
144   device->save_item(NAME(adc1038->sars));
145}
146
147static DEVICE_RESET( adc1038 )
148{
149   adc1038_state *adc1038 = adc1038_get_safe_token(device);
150
151   adc1038->cycle = 0;
152   adc1038->clk = 0;
153   adc1038->adr = 0;
154   adc1038->data_in = 0;
155   adc1038->data_out = 0;
156   adc1038->adc_data = 0;
157   adc1038->sars = 1;
158}
159
160const device_type ADC1038 = &device_creator<adc1038_device>;
161
162adc1038_device::adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
163   : device_t(mconfig, ADC1038, "A/D Converters 1038", tag, owner, clock)
164{
165   m_token = global_alloc_clear(adc1038_state);
166}
167
168//-------------------------------------------------
169//  device_config_complete - perform any
170//  operations now that the configuration is
171//  complete
172//-------------------------------------------------
173
174void adc1038_device::device_config_complete()
175{
176}
177
178//-------------------------------------------------
179//  device_start - device-specific startup
180//-------------------------------------------------
181
182void adc1038_device::device_start()
183{
184   DEVICE_START_NAME( adc1038 )(this);
185}
186
187//-------------------------------------------------
188//  device_reset - device-specific reset
189//-------------------------------------------------
190
191void adc1038_device::device_reset()
192{
193   DEVICE_RESET_NAME( adc1038 )(this);
194}
trunk/src/emu/machine/adc1038.h
r23541r23542
2121
2222struct adc1038_interface
2323{
24   int gticlub_hack;
24   int m_gticlub_hack;
2525   adc1038_input_read_func input_callback_r;
2626};
2727
r23541r23542
3030    MACROS / CONSTANTS
3131***************************************************************************/
3232
33class adc1038_device : public device_t
33class adc1038_device : public device_t,
34                              public adc1038_interface
3435{
3536public:
3637   adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
37   ~adc1038_device() { global_free(m_token); }
38   ~adc1038_device() {}
3839
39   // access to legacy token
40   void *token() const { assert(m_token != NULL); return m_token; }
40   DECLARE_READ_LINE_MEMBER( do_read );
41   DECLARE_READ_LINE_MEMBER( sars_read );
42   DECLARE_WRITE_LINE_MEMBER( di_write );
43   DECLARE_WRITE_LINE_MEMBER( clk_write );
44
4145protected:
4246   // device-level overrides
4347   virtual void device_config_complete();
4448   virtual void device_start();
4549   virtual void device_reset();
46private:
50   
51   adc1038_input_read_func           m_input_callback_r_func;
52
53   private:
4754   // internal state
48   void *m_token;
55   int m_cycle;
56   int m_clk;
57   int m_adr;
58   int m_data_in;
59   int m_data_out;
60   int m_adc_data;
61   int m_sars;
4962};
5063
5164extern const device_type ADC1038;
r23541r23542
5669   MCFG_DEVICE_CONFIG(_config)
5770
5871
59/***************************************************************************
60    DEVICE I/O FUNCTIONS
61***************************************************************************/
62
63extern READ_LINE_DEVICE_HANDLER( adc1038_do_read );
64extern READ_LINE_DEVICE_HANDLER( adc1038_sars_read );
65extern WRITE_LINE_DEVICE_HANDLER( adc1038_di_write );
66extern WRITE_LINE_DEVICE_HANDLER( adc1038_clk_write );
67
6872#endif  /* __ADC1038_H__ */
trunk/src/mame/machine/nmk112.h
r23541r23542
77#ifndef __NMK112_H__
88#define __NMK112_H__
99
10#include "devlegcy.h"
11
1210/***************************************************************************
1311    TYPE DEFINITIONS
1412***************************************************************************/
trunk/src/mame/includes/flower.h
r23541r23542
4949};
5050
5151
52// ======================> gomoku_sound_device
52// ======================> flower_sound_device
5353
5454
5555/* this structure defines the parameters for a channel */
trunk/src/mame/drivers/nwk-tr.c
r23541r23542
235235      m_maincpu(*this, "maincpu"),
236236      m_audiocpu(*this, "audiocpu"),
237237      m_dsp(*this, "dsp"),
238      m_k001604(*this, "k001604")  { }
238      m_k001604(*this, "k001604"),
239      m_adc12138(*this, "adc12138") { }
239240
240241   UINT8 m_led_reg0;
241242   UINT8 m_led_reg1;
242243   required_shared_ptr<UINT32> m_work_ram;
244   required_device<cpu_device> m_maincpu;
245   required_device<cpu_device> m_audiocpu;
246   required_device<cpu_device> m_dsp;
247   required_device<k001604_device> m_k001604;
248   required_device<adc12138_device> m_adc12138;
243249   emu_timer *m_sound_irq_timer;
244250   int m_fpga_uploaded;
245251   int m_lanc2_ram_r;
r23541r23542
262268   UINT32 screen_update_nwktr(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
263269   TIMER_CALLBACK_MEMBER(irq_off);
264270   void lanc2_init();
265   required_device<cpu_device> m_maincpu;
266   required_device<cpu_device> m_audiocpu;
267   required_device<cpu_device> m_dsp;
268   required_device<k001604_device> m_k001604;
269271};
270272
271273
r23541r23542
307309
308310READ32_MEMBER(nwktr_state::sysreg_r)
309311{
310   device_t *adc12138 = machine().device("adc12138");
311312   UINT32 r = 0;
312313   if (offset == 0)
313314   {
r23541r23542
325326      }
326327      if (ACCESSING_BITS_0_7)
327328      {
328         r |= adc1213x_do_r(adc12138, space, 0) | (adc1213x_eoc_r(adc12138, space, 0) << 2);
329         r |= m_adc12138->do_r(space, 0) | (m_adc12138->eoc_r(space, 0) << 2);
329330      }
330331   }
331332   else if (offset == 1)
r23541r23542
340341
341342WRITE32_MEMBER(nwktr_state::sysreg_w)
342343{
343   device_t *adc12138 = machine().device("adc12138");
344344   if( offset == 0 )
345345   {
346346      if (ACCESSING_BITS_24_31)
r23541r23542
362362         int di = (data >> 25) & 0x1;
363363         int sclk = (data >> 24) & 0x1;
364364
365         adc1213x_cs_w(adc12138, space, 0, cs);
366         adc1213x_conv_w(adc12138, space, 0, conv);
367         adc1213x_di_w(adc12138, space, 0, di);
368         adc1213x_sclk_w(adc12138, space, 0, sclk);
365         m_adc12138->cs_w(space, 0, cs);
366         m_adc12138->conv_w(space, 0, conv);
367         m_adc12138->di_w(space, 0, di);
368         m_adc12138->sclk_w(space, 0, sclk);
369369      }
370370      if (ACCESSING_BITS_0_7)
371371      {
trunk/src/mame/drivers/hornet.c
r23541r23542
339339      m_dsp2(*this, "dsp2"),
340340      m_eeprom(*this, "eeprom"),
341341      m_k037122_1(*this, "k037122_1"),
342      m_k037122_2(*this, "k037122_2" ) { }
342      m_k037122_2(*this, "k037122_2" ),
343      m_adc12138(*this, "adc12138") { }
343344
344345   UINT8 m_led_reg0;
345346   UINT8 m_led_reg1;
346347   required_shared_ptr<UINT32> m_workram;
347348   required_shared_ptr<UINT32> m_sharc_dataram0;
348349   optional_shared_ptr<UINT32> m_sharc_dataram1;
350   required_device<cpu_device> m_maincpu;
351   required_device<cpu_device> m_audiocpu;
352   optional_device<cpu_device> m_gn680;
353   required_device<cpu_device> m_dsp;
354   optional_device<cpu_device> m_dsp2;
355   required_device<eeprom_device> m_eeprom;
356   optional_device<k037122_device> m_k037122_1;
357   optional_device<k037122_device> m_k037122_2;
358   required_device<adc12138_device> m_adc12138;
349359   UINT8 *m_jvs_sdata;
350360   UINT32 m_jvs_sdata_ptr;
351361   emu_timer *m_sound_irq_timer;
r23541r23542
385395   int jvs_encode_data(UINT8 *in, int length);
386396   int jvs_decode_data(UINT8 *in, UINT8 *out, int length);
387397   void jamma_jvs_cmd_exec();
388   required_device<cpu_device> m_maincpu;
389   required_device<cpu_device> m_audiocpu;
390   optional_device<cpu_device> m_gn680;
391   required_device<cpu_device> m_dsp;
392   optional_device<cpu_device> m_dsp2;
393   required_device<eeprom_device> m_eeprom;
394   optional_device<k037122_device> m_k037122_1;
395   optional_device<k037122_device> m_k037122_2;
396398};
397399
398400
r23541r23542
487489{
488490   UINT8 r = 0;
489491   static const char *const portnames[] = { "IN0", "IN1", "IN2" };
490   device_t *adc12138 = machine().device("adc12138");
491492   switch (offset)
492493   {
493494      case 0: /* I/O port 0 */
r23541r23542
507508             0x01 = ADDO (ADC DO)
508509         */
509510         r = 0xf0 | (m_eeprom->read_bit() << 3);
510         r |= adc1213x_do_r(adc12138, space, 0) | (adc1213x_eoc_r(adc12138, space, 0) << 2);
511         r |= m_adc12138->do_r(space, 0) | (m_adc12138->eoc_r(space, 0) << 2);
511512         break;
512513
513514      case 4: /* I/O port 4 - DIP switches */
r23541r23542
519520
520521WRITE8_MEMBER(hornet_state::sysreg_w)
521522{
522   device_t *adc12138 = machine().device("adc12138");
523
524523   switch (offset)
525524   {
526525      case 0: /* LED Register 0 */
r23541r23542
561560             0x02 = ADDI (ADC DI)
562561             0x01 = ADDSCLK (ADC SCLK)
563562         */
564         adc1213x_cs_w(adc12138, space, 0, (data >> 3) & 0x1);
565         adc1213x_conv_w(adc12138, space, 0, (data >> 2) & 0x1);
566         adc1213x_di_w(adc12138, space, 0, (data >> 1) & 0x1);
567         adc1213x_sclk_w(adc12138, space, 0, data & 0x1);
563         m_adc12138->cs_w(space, 0, (data >> 3) & 0x1);
564         m_adc12138->conv_w(space, 0, (data >> 2) & 0x1);
565         m_adc12138->di_w(space, 0, (data >> 1) & 0x1);
566         m_adc12138->sclk_w(space, 0, data & 0x1);
568567
569568         m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
570569         mame_printf_debug("System register 1 = %02X\n", data);
trunk/src/mame/drivers/gticlub.c
r23541r23542
250250      m_audiocpu(*this, "audiocpu"),
251251      m_dsp(*this, "dsp"),
252252      m_dsp2(*this, "dsp2"),
253      m_adc1038(*this, "adc1038"),
253254      m_eeprom(*this, "eeprom")  { }
254255
255256   required_shared_ptr<UINT32> m_work_ram;
257   required_device<cpu_device> m_maincpu;
258   required_device<cpu_device> m_audiocpu;
259   required_device<cpu_device> m_dsp;
260   optional_device<cpu_device> m_dsp2;
261   required_device<adc1038_device> m_adc1038;
262   required_device<eeprom_device> m_eeprom;
256263   UINT32 *m_sharc_dataram_0;
257264   UINT32 *m_sharc_dataram_1;
258265   DECLARE_WRITE32_MEMBER(paletteram32_w);
r23541r23542
278285   DECLARE_MACHINE_RESET(gticlub);
279286   DECLARE_MACHINE_RESET(hangplt);
280287   INTERRUPT_GEN_MEMBER(gticlub_vblank);
281   required_device<cpu_device> m_maincpu;
282   required_device<cpu_device> m_audiocpu;
283   required_device<cpu_device> m_dsp;
284   optional_device<cpu_device> m_dsp2;
285   required_device<eeprom_device> m_eeprom;
286288
287289protected:
288290   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
r23541r23542
363365READ8_MEMBER(gticlub_state::sysreg_r)
364366{
365367   static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3" };
366   device_t *adc1038 = machine().device("adc1038");
367368   switch (offset)
368369   {
369370      case 0:
r23541r23542
372373         return ioport(portnames[offset])->read();
373374
374375      case 2:
375         return adc1038_sars_read(adc1038) << 7;
376         return m_adc1038->sars_read() << 7;
376377
377378      case 4:
378379      {
r23541r23542
383384         // e = EEPROM data out
384385
385386         UINT32 eeprom_bit = (m_eeprom->read_bit() << 1);
386         UINT32 adc_bit = (adc1038_do_read(adc1038) << 2);
387         UINT32 adc_bit = (m_adc1038->do_read() << 2);
387388         return (eeprom_bit | adc_bit);
388389      }
389390
r23541r23542
396397
397398WRITE8_MEMBER(gticlub_state::sysreg_w)
398399{
399   device_t *adc1038 = machine().device("adc1038");
400400   switch (offset)
401401   {
402402      case 0:
r23541r23542
417417         if (data & 0x40)    /* CG Board 0 IRQ Ack */
418418            m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
419419
420         adc1038_di_write(adc1038, (data >> 0) & 1);
421         adc1038_clk_write(adc1038, (data >> 1) & 1);
420         m_adc1038->di_write((data >> 0) & 1);
421         m_adc1038->clk_write((data >> 1) & 1);
422422
423423         set_cgboard_id((data >> 4) & 0x3);
424424         break;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team