1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/***************************************************************************
National Semiconductor ADC1038
10-Bit Serial I/O A/D Converters with Analog Multiplexer and
Track/hold Function
***************************************************************************/
#include "emu.h"
#include "adc1038.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
struct adc1038_state
{
int cycle;
int clk;
int adr;
int data_in;
int data_out;
int adc_data;
int sars;
adc1038_input_read_func input_callback_r;
int gticlub_hack;
};
/*****************************************************************************
INLINE FUNCTIONS
*****************************************************************************/
INLINE adc1038_state *adc1038_get_safe_token( device_t *device )
{
assert(device != NULL);
assert(device->type() == ADC1038);
return (adc1038_state *)downcast<adc1038_device *>(device)->token();
}
INLINE const adc1038_interface *adc1038_get_interface( device_t *device )
{
assert(device != NULL);
assert((device->type() == ADC1038));
return (const adc1038_interface *) device->static_config();
}
/*****************************************************************************
DEVICE HANDLERS
*****************************************************************************/
READ_LINE_DEVICE_HANDLER( adc1038_do_read )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->data_out = (adc1038->adc_data & 0x200) ? 1 : 0;
adc1038->adc_data <<= 1;
//printf("ADC DO\n");
return adc1038->data_out;
}
WRITE_LINE_DEVICE_HANDLER( adc1038_di_write )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->data_in = state;
}
WRITE_LINE_DEVICE_HANDLER( adc1038_clk_write )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
// GTI Club doesn't sync on SARS
if (adc1038->gticlub_hack)
{
if (adc1038->clk == 0 && state == 0)
{
adc1038->cycle = 0;
/* notice that adc1038->adr is always < 7! */
adc1038->adc_data = adc1038->input_callback_r(device, adc1038->adr);
}
}
if (state == 1)
{
//printf("ADC CLK, DI = %d, cycle = %d\n", adc1038->data_in, adc1038->cycle);
if (adc1038->cycle == 0) // A2
{
adc1038->adr = 0;
adc1038->adr |= (adc1038->data_in << 2);
}
else if (adc1038->cycle == 1) // A1
{
adc1038->adr |= (adc1038->data_in << 1);
}
else if (adc1038->cycle == 2) // A0
{
adc1038->adr |= (adc1038->data_in << 0);
}
adc1038->cycle++;
}
adc1038->clk = state;
}
READ_LINE_DEVICE_HANDLER( adc1038_sars_read )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->cycle = 0;
/* notice that adc1038->adr is always < 7! */
adc1038->adc_data = adc1038->input_callback_r(device, adc1038->adr);
adc1038->sars ^= 1;
return adc1038->sars;
}
/*****************************************************************************
DEVICE INTERFACE
*****************************************************************************/
static DEVICE_START( adc1038 )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
const adc1038_interface *intf = adc1038_get_interface(device);
adc1038->gticlub_hack = intf->gticlub_hack;
adc1038->input_callback_r = intf->input_callback_r;
device->save_item(NAME(adc1038->cycle));
device->save_item(NAME(adc1038->clk));
device->save_item(NAME(adc1038->adr));
device->save_item(NAME(adc1038->data_in));
device->save_item(NAME(adc1038->data_out));
device->save_item(NAME(adc1038->adc_data));
device->save_item(NAME(adc1038->sars));
}
static DEVICE_RESET( adc1038 )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->cycle = 0;
adc1038->clk = 0;
adc1038->adr = 0;
adc1038->data_in = 0;
adc1038->data_out = 0;
adc1038->adc_data = 0;
adc1038->sars = 1;
}
const device_type ADC1038 = &device_creator<adc1038_device>;
adc1038_device::adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, ADC1038, "A/D Converters 1038", tag, owner, clock)
{
m_token = global_alloc_array_clear(UINT8, sizeof(adc1038_state));
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void adc1038_device::device_config_complete()
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void adc1038_device::device_start()
{
DEVICE_START_NAME( adc1038 )(this);
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void adc1038_device::device_reset()
{
DEVICE_RESET_NAME( adc1038 )(this);
}
|