trunk/src/emu/machine/adc1213x.c
| r23541 | r23542 | |
| 20 | 20 | TYPE DEFINITIONS |
| 21 | 21 | ***************************************************************************/ |
| 22 | 22 | |
| 23 | | struct 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 | | |
| 42 | 23 | #define ADC1213X_CONV_MODE_12_MSB_FIRST 0 |
| 43 | 24 | #define ADC1213X_CONV_MODE_16_MSB_FIRST 1 |
| 44 | 25 | #define ADC1213X_CONV_MODE_12_LSB_FIRST 2 |
| r23541 | r23542 | |
| 49 | 30 | #define ADC1213X_ACQUISITION_TIME_18_CCLK 2 |
| 50 | 31 | #define ADC1213X_ACQUISITION_TIME_34_CCLK 3 |
| 51 | 32 | |
| 52 | | /*************************************************************************** |
| 53 | | INLINE FUNCTIONS |
| 54 | | ***************************************************************************/ |
| 55 | 33 | |
| 56 | | INLINE adc12138_state *get_safe_token(device_t *device) |
| 34 | |
| 35 | const device_type ADC12130 = &device_creator<adc12130_device>; |
| 36 | |
| 37 | adc12130_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) |
| 57 | 39 | { |
| 58 | | assert(device != NULL); |
| 59 | | assert((device->type() == ADC12130) || (device->type() == ADC12132) || (device->type() == ADC12138)); |
| 60 | | return (adc12138_state *)downcast<adc12138_device *>(device)->token(); |
| 61 | 40 | } |
| 62 | 41 | |
| 63 | | INLINE const adc12138_interface *get_interface(device_t *device) |
| 42 | |
| 43 | const device_type ADC12132 = &device_creator<adc12132_device>; |
| 44 | |
| 45 | adc12132_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) |
| 64 | 47 | { |
| 65 | | assert(device != NULL); |
| 66 | | assert((device->type() == ADC12130) || (device->type() == ADC12132) || (device->type() == ADC12138)); |
| 67 | | return (const adc12138_interface *) device->static_config(); |
| 68 | 48 | } |
| 69 | 49 | |
| 70 | 50 | |
| 51 | const device_type ADC12138 = &device_creator<adc12138_device>; |
| 52 | |
| 53 | adc12138_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 | } |
| 57 | adc12138_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 | |
| 68 | void 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 | |
| 86 | void 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 | |
| 110 | void 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 | |
| 71 | 119 | /*************************************************************************** |
| 72 | 120 | IMPLEMENTATION |
| 73 | 121 | ***************************************************************************/ |
| 74 | 122 | |
| 75 | 123 | /*------------------------------------------------- |
| 76 | | adc1213x_di_w |
| 124 | di_w |
| 77 | 125 | -------------------------------------------------*/ |
| 78 | 126 | |
| 79 | | WRITE8_DEVICE_HANDLER( adc1213x_di_w ) |
| 127 | WRITE8_MEMBER( adc12138_device::di_w ) |
| 80 | 128 | { |
| 81 | | adc12138_state *adc1213x = get_safe_token(device); |
| 82 | | adc1213x->data_in = data & 1; |
| 129 | m_data_in = data & 1; |
| 83 | 130 | } |
| 84 | 131 | |
| 85 | 132 | /*------------------------------------------------- |
| 86 | | adc1213x_convert |
| 133 | convert |
| 87 | 134 | -------------------------------------------------*/ |
| 88 | 135 | |
| 89 | | static void adc1213x_convert(device_t *device, int channel, int bits16, int lsbfirst) |
| 136 | void adc12138_device::convert(int channel, int bits16, int lsbfirst) |
| 90 | 137 | { |
| 91 | | adc12138_state *adc1213x = get_safe_token(device); |
| 92 | 138 | int i; |
| 93 | 139 | int bits; |
| 94 | 140 | int input_value; |
| r23541 | r23542 | |
| 104 | 150 | { |
| 105 | 151 | case 0x8: // H L L L - CH0 (single-ended) |
| 106 | 152 | { |
| 107 | | input = adc1213x->input_callback_r(device, 0); |
| 153 | input = m_input_callback_r_func(this, 0); |
| 108 | 154 | break; |
| 109 | 155 | } |
| 110 | 156 | case 0xc: // H H L L - CH1 (single-ended) |
| 111 | 157 | { |
| 112 | | input = adc1213x->input_callback_r(device, 1); |
| 158 | input = m_input_callback_r_func(this, 1); |
| 113 | 159 | break; |
| 114 | 160 | } |
| 115 | 161 | case 0x9: // H L L H - CH2 (single-ended) |
| 116 | 162 | { |
| 117 | | input = adc1213x->input_callback_r(device, 2); |
| 163 | input = m_input_callback_r_func(this, 2); |
| 118 | 164 | break; |
| 119 | 165 | } |
| 120 | 166 | case 0xd: // H H L H - CH3 (single-ended) |
| 121 | 167 | { |
| 122 | | input = adc1213x->input_callback_r(device, 3); |
| 168 | input = m_input_callback_r_func(this, 3); |
| 123 | 169 | break; |
| 124 | 170 | } |
| 125 | 171 | case 0xa: // H L H L - CH4 (single-ended) |
| 126 | 172 | { |
| 127 | | input = adc1213x->input_callback_r(device, 4); |
| 173 | input = m_input_callback_r_func(this, 4); |
| 128 | 174 | break; |
| 129 | 175 | } |
| 130 | 176 | case 0xe: // H H H L - CH5 (single-ended) |
| 131 | 177 | { |
| 132 | | input = adc1213x->input_callback_r(device, 5); |
| 178 | input = m_input_callback_r_func(this, 5); |
| 133 | 179 | break; |
| 134 | 180 | } |
| 135 | 181 | case 0xb: // H L H H - CH6 (single-ended) |
| 136 | 182 | { |
| 137 | | input = adc1213x->input_callback_r(device, 6); |
| 183 | input = m_input_callback_r_func(this, 6); |
| 138 | 184 | break; |
| 139 | 185 | } |
| 140 | 186 | case 0xf: // H H H H - CH7 (single-ended) |
| 141 | 187 | { |
| 142 | | input = adc1213x->input_callback_r(device, 7); |
| 188 | input = m_input_callback_r_func(this, 7); |
| 143 | 189 | break; |
| 144 | 190 | } |
| 145 | 191 | default: |
| r23541 | r23542 | |
| 153 | 199 | bits = 12; |
| 154 | 200 | |
| 155 | 201 | // sign-extend if needed |
| 156 | | if (adc1213x->data_out_sign) |
| 202 | if (m_data_out_sign) |
| 157 | 203 | { |
| 158 | 204 | input_value = input_value | ((input_value & 0x800) << 1); |
| 159 | 205 | bits++; |
| 160 | 206 | } |
| 161 | 207 | |
| 162 | | adc1213x->output_shift_reg = 0; |
| 208 | m_output_shift_reg = 0; |
| 163 | 209 | |
| 164 | 210 | for (i=0; i < bits; i++) |
| 165 | 211 | { |
| 166 | 212 | if (input_value & (1 << ((bits-1) - i))) |
| 167 | 213 | { |
| 168 | | adc1213x->output_shift_reg |= (1 << i); |
| 214 | m_output_shift_reg |= (1 << i); |
| 169 | 215 | } |
| 170 | 216 | } |
| 171 | 217 | |
| 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; |
| 174 | 220 | } |
| 175 | 221 | |
| 176 | 222 | /*------------------------------------------------- |
| 177 | | adc1213x_cs_w |
| 223 | cs_w |
| 178 | 224 | -------------------------------------------------*/ |
| 179 | 225 | |
| 180 | | WRITE8_DEVICE_HANDLER( adc1213x_cs_w ) |
| 226 | WRITE8_MEMBER( adc12138_device::cs_w ) |
| 181 | 227 | { |
| 182 | | adc12138_state *adc1213x = get_safe_token(device); |
| 183 | | |
| 184 | 228 | if (data) |
| 185 | 229 | { |
| 186 | 230 | //printf("ADC: CS\n"); |
| 187 | 231 | |
| 188 | | if (adc1213x->cycle >= 7) |
| 232 | if (m_cycle >= 7) |
| 189 | 233 | { |
| 190 | | int mode = adc1213x->input_shift_reg >> (adc1213x->cycle - 8); |
| 234 | int mode = m_input_shift_reg >> (m_cycle - 8); |
| 191 | 235 | |
| 192 | 236 | switch (mode & 0xf) |
| 193 | 237 | { |
| 194 | 238 | case 0x0: // X X X X L L L L - 12 or 13 Bit MSB First conversion |
| 195 | 239 | { |
| 196 | | adc1213x_convert(device, (mode >> 4) & 0xf, 0, 0); |
| 240 | convert((mode >> 4) & 0xf, 0, 0); |
| 197 | 241 | break; |
| 198 | 242 | } |
| 199 | 243 | case 0x1: // X X X X L L L H - 16 or 17 Bit MSB First conversion |
| 200 | 244 | { |
| 201 | | adc1213x_convert(device, (mode >> 4) & 0xf, 1, 0); |
| 245 | convert((mode >> 4) & 0xf, 1, 0); |
| 202 | 246 | break; |
| 203 | 247 | } |
| 204 | 248 | case 0x4: // X X X X L H L L - 12 or 13 Bit LSB First conversion |
| 205 | 249 | { |
| 206 | | adc1213x_convert(device, (mode >> 4) & 0xf, 0, 1); |
| 250 | convert((mode >> 4) & 0xf, 0, 1); |
| 207 | 251 | break; |
| 208 | 252 | } |
| 209 | 253 | case 0x5: // X X X X L H L H - 16 or 17 Bit LSB First conversion |
| 210 | 254 | { |
| 211 | | adc1213x_convert(device, (mode >> 4) & 0xf, 1, 1); |
| 255 | convert((mode >> 4) & 0xf, 1, 1); |
| 212 | 256 | break; |
| 213 | 257 | } |
| 214 | 258 | |
| r23541 | r23542 | |
| 218 | 262 | { |
| 219 | 263 | case 0x08: // L L L L H L L L - Auto cal |
| 220 | 264 | { |
| 221 | | adc1213x->auto_cal = 1; |
| 265 | m_auto_cal = 1; |
| 222 | 266 | break; |
| 223 | 267 | } |
| 224 | 268 | |
| 225 | 269 | case 0x0e: // L L L L H H H L - Acquisition time 6 CCLK cycles |
| 226 | 270 | { |
| 227 | | adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK; |
| 271 | m_acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK; |
| 228 | 272 | break; |
| 229 | 273 | } |
| 230 | 274 | |
| 231 | 275 | case 0x8d: // H L L L H H L H - Data out with sign |
| 232 | 276 | { |
| 233 | | adc1213x->data_out_sign = 1; |
| 277 | m_data_out_sign = 1; |
| 234 | 278 | break; |
| 235 | 279 | } |
| 236 | 280 | |
| r23541 | r23542 | |
| 249 | 293 | } |
| 250 | 294 | } |
| 251 | 295 | |
| 252 | | adc1213x->cycle = 0; |
| 253 | | adc1213x->input_shift_reg = 0; |
| 296 | m_cycle = 0; |
| 297 | m_input_shift_reg = 0; |
| 254 | 298 | |
| 255 | | adc1213x->end_conv = 0; |
| 299 | m_end_conv = 0; |
| 256 | 300 | } |
| 257 | 301 | } |
| 258 | 302 | |
| 259 | 303 | /*------------------------------------------------- |
| 260 | | adc1213x_sclk_w |
| 304 | sclk_w |
| 261 | 305 | -------------------------------------------------*/ |
| 262 | 306 | |
| 263 | | WRITE8_DEVICE_HANDLER( adc1213x_sclk_w ) |
| 307 | WRITE8_MEMBER( adc12138_device::sclk_w ) |
| 264 | 308 | { |
| 265 | | adc12138_state *adc1213x = get_safe_token(device); |
| 266 | | |
| 267 | 309 | if (data) |
| 268 | 310 | { |
| 269 | 311 | //printf("ADC: cycle %d, DI = %d\n", adc1213x->cycle, adc1213x->data_in); |
| 270 | 312 | |
| 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; |
| 273 | 315 | |
| 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; |
| 276 | 318 | |
| 277 | | adc1213x->cycle++; |
| 319 | m_cycle++; |
| 278 | 320 | } |
| 279 | 321 | } |
| 280 | 322 | |
| 281 | 323 | /*------------------------------------------------- |
| 282 | | adc1213x_conv_w |
| 324 | conv_w |
| 283 | 325 | -------------------------------------------------*/ |
| 284 | 326 | |
| 285 | | WRITE8_DEVICE_HANDLER( adc1213x_conv_w ) |
| 327 | WRITE8_MEMBER( adc12138_device::conv_w ) |
| 286 | 328 | { |
| 287 | | adc12138_state *adc1213x = get_safe_token(device); |
| 288 | | adc1213x->end_conv = 1; |
| 329 | m_end_conv = 1; |
| 289 | 330 | } |
| 290 | 331 | |
| 291 | 332 | /*------------------------------------------------- |
| 292 | | adc1213x_do_r |
| 333 | do_r |
| 293 | 334 | -------------------------------------------------*/ |
| 294 | 335 | |
| 295 | | READ8_DEVICE_HANDLER( adc1213x_do_r ) |
| 336 | READ8_MEMBER( adc12138_device::do_r ) |
| 296 | 337 | { |
| 297 | | adc12138_state *adc1213x = get_safe_token(device); |
| 298 | | |
| 299 | 338 | //printf("ADC: DO\n"); |
| 300 | | return adc1213x->data_out; |
| 339 | return m_data_out; |
| 301 | 340 | } |
| 302 | 341 | |
| 303 | 342 | /*------------------------------------------------- |
| 304 | | adc1213x_eoc_r |
| 343 | eoc_r |
| 305 | 344 | -------------------------------------------------*/ |
| 306 | 345 | |
| 307 | | READ8_DEVICE_HANDLER( adc1213x_eoc_r ) |
| 346 | READ8_MEMBER( adc12138_device::eoc_r ) |
| 308 | 347 | { |
| 309 | | adc12138_state *adc1213x = get_safe_token(device); |
| 310 | | return adc1213x->end_conv; |
| 348 | return m_end_conv; |
| 311 | 349 | } |
| 312 | | |
| 313 | | /*------------------------------------------------- |
| 314 | | DEVICE_START( adc1213x ) |
| 315 | | -------------------------------------------------*/ |
| 316 | | |
| 317 | | static 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 | | |
| 345 | | static 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 | | |
| 356 | | const device_type ADC12130 = &device_creator<adc12130_device>; |
| 357 | | |
| 358 | | adc12130_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 | | |
| 364 | | const device_type ADC12132 = &device_creator<adc12132_device>; |
| 365 | | |
| 366 | | adc12132_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 | | |
| 372 | | const device_type ADC12138 = &device_creator<adc12138_device>; |
| 373 | | |
| 374 | | adc12138_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 | | } |
| 379 | | adc12138_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 | | |
| 391 | | void adc12138_device::device_config_complete() |
| 392 | | { |
| 393 | | } |
| 394 | | |
| 395 | | //------------------------------------------------- |
| 396 | | // device_start - device-specific startup |
| 397 | | //------------------------------------------------- |
| 398 | | |
| 399 | | void adc12138_device::device_start() |
| 400 | | { |
| 401 | | DEVICE_START_NAME( adc12138 )(this); |
| 402 | | } |
| 403 | | |
| 404 | | //------------------------------------------------- |
| 405 | | // device_reset - device-specific reset |
| 406 | | //------------------------------------------------- |
| 407 | | |
| 408 | | void adc12138_device::device_reset() |
| 409 | | { |
| 410 | | DEVICE_RESET_NAME( adc12138 )(this); |
| 411 | | } |
trunk/src/emu/machine/adc1038.c
| r23541 | r23542 | |
| 10 | 10 | #include "emu.h" |
| 11 | 11 | #include "adc1038.h" |
| 12 | 12 | |
| 13 | | /*************************************************************************** |
| 14 | | TYPE DEFINITIONS |
| 15 | | ***************************************************************************/ |
| 16 | 13 | |
| 17 | | struct adc1038_state |
| 14 | const device_type ADC1038 = &device_creator<adc1038_device>; |
| 15 | |
| 16 | adc1038_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) |
| 18 | 18 | { |
| 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 | } |
| 27 | 20 | |
| 28 | | int gticlub_hack; |
| 29 | | }; |
| 21 | //------------------------------------------------- |
| 22 | // device_config_complete - perform any |
| 23 | // operations now that the configuration is |
| 24 | // complete |
| 25 | //------------------------------------------------- |
| 30 | 26 | |
| 31 | | /***************************************************************************** |
| 32 | | INLINE FUNCTIONS |
| 33 | | *****************************************************************************/ |
| 27 | void 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; |
| 34 | 33 | |
| 35 | | INLINE 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 | |
| 45 | void adc1038_device::device_start() |
| 36 | 46 | { |
| 37 | | assert(device != NULL); |
| 38 | | assert(device->type() == ADC1038); |
| 47 | m_input_callback_r_func = input_callback_r; |
| 39 | 48 | |
| 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)); |
| 41 | 56 | } |
| 42 | 57 | |
| 43 | | INLINE const adc1038_interface *adc1038_get_interface( device_t *device ) |
| 58 | //------------------------------------------------- |
| 59 | // device_reset - device-specific reset |
| 60 | //------------------------------------------------- |
| 61 | |
| 62 | void adc1038_device::device_reset() |
| 44 | 63 | { |
| 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; |
| 48 | 71 | } |
| 49 | 72 | |
| 50 | 73 | /***************************************************************************** |
| 51 | 74 | DEVICE HANDLERS |
| 52 | 75 | *****************************************************************************/ |
| 53 | 76 | |
| 54 | | READ_LINE_DEVICE_HANDLER( adc1038_do_read ) |
| 77 | READ_LINE_MEMBER( adc1038_device::do_read ) |
| 55 | 78 | { |
| 56 | | adc1038_state *adc1038 = adc1038_get_safe_token(device); |
| 79 | m_data_out = (m_adc_data & 0x200) ? 1 : 0; |
| 80 | m_adc_data <<= 1; |
| 57 | 81 | |
| 58 | | adc1038->data_out = (adc1038->adc_data & 0x200) ? 1 : 0; |
| 59 | | adc1038->adc_data <<= 1; |
| 60 | | |
| 61 | 82 | //printf("ADC DO\n"); |
| 62 | | return adc1038->data_out; |
| 83 | return m_data_out; |
| 63 | 84 | } |
| 64 | 85 | |
| 65 | | WRITE_LINE_DEVICE_HANDLER( adc1038_di_write ) |
| 86 | WRITE_LINE_MEMBER( adc1038_device::di_write ) |
| 66 | 87 | { |
| 67 | | adc1038_state *adc1038 = adc1038_get_safe_token(device); |
| 68 | | |
| 69 | | adc1038->data_in = state; |
| 88 | m_data_in = state; |
| 70 | 89 | } |
| 71 | 90 | |
| 72 | | WRITE_LINE_DEVICE_HANDLER( adc1038_clk_write ) |
| 91 | WRITE_LINE_MEMBER( adc1038_device::clk_write ) |
| 73 | 92 | { |
| 74 | | adc1038_state *adc1038 = adc1038_get_safe_token(device); |
| 75 | | |
| 76 | 93 | // GTI Club doesn't sync on SARS |
| 77 | | if (adc1038->gticlub_hack) |
| 94 | if (m_gticlub_hack) |
| 78 | 95 | { |
| 79 | | if (adc1038->clk == 0 && state == 0) |
| 96 | if (m_clk == 0 && state == 0) |
| 80 | 97 | { |
| 81 | | adc1038->cycle = 0; |
| 98 | m_cycle = 0; |
| 82 | 99 | |
| 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); |
| 85 | 102 | } |
| 86 | 103 | } |
| 87 | 104 | |
| 88 | 105 | if (state == 1) |
| 89 | 106 | { |
| 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); |
| 91 | 108 | |
| 92 | | if (adc1038->cycle == 0) // A2 |
| 109 | if (m_cycle == 0) // A2 |
| 93 | 110 | { |
| 94 | | adc1038->adr = 0; |
| 95 | | adc1038->adr |= (adc1038->data_in << 2); |
| 111 | m_adr = 0; |
| 112 | m_adr |= (m_data_in << 2); |
| 96 | 113 | } |
| 97 | | else if (adc1038->cycle == 1) // A1 |
| 114 | else if (m_cycle == 1) // A1 |
| 98 | 115 | { |
| 99 | | adc1038->adr |= (adc1038->data_in << 1); |
| 116 | m_adr |= (m_data_in << 1); |
| 100 | 117 | } |
| 101 | | else if (adc1038->cycle == 2) // A0 |
| 118 | else if (m_cycle == 2) // A0 |
| 102 | 119 | { |
| 103 | | adc1038->adr |= (adc1038->data_in << 0); |
| 120 | m_adr |= (m_data_in << 0); |
| 104 | 121 | } |
| 105 | 122 | |
| 106 | | adc1038->cycle++; |
| 123 | m_cycle++; |
| 107 | 124 | } |
| 108 | 125 | |
| 109 | | adc1038->clk = state; |
| 126 | m_clk = state; |
| 110 | 127 | } |
| 111 | 128 | |
| 112 | | READ_LINE_DEVICE_HANDLER( adc1038_sars_read ) |
| 129 | READ_LINE_MEMBER( adc1038_device::sars_read ) |
| 113 | 130 | { |
| 114 | | adc1038_state *adc1038 = adc1038_get_safe_token(device); |
| 131 | m_cycle = 0; |
| 115 | 132 | |
| 116 | | adc1038->cycle = 0; |
| 133 | /* notice that m_adr is always < 7! */ |
| 134 | m_adc_data = m_input_callback_r_func(this, m_adr); |
| 117 | 135 | |
| 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; |
| 123 | 138 | } |
| 124 | | |
| 125 | | |
| 126 | | /***************************************************************************** |
| 127 | | DEVICE INTERFACE |
| 128 | | *****************************************************************************/ |
| 129 | | |
| 130 | | static 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 | | |
| 147 | | static 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 | | |
| 160 | | const device_type ADC1038 = &device_creator<adc1038_device>; |
| 161 | | |
| 162 | | adc1038_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 | | |
| 174 | | void adc1038_device::device_config_complete() |
| 175 | | { |
| 176 | | } |
| 177 | | |
| 178 | | //------------------------------------------------- |
| 179 | | // device_start - device-specific startup |
| 180 | | //------------------------------------------------- |
| 181 | | |
| 182 | | void adc1038_device::device_start() |
| 183 | | { |
| 184 | | DEVICE_START_NAME( adc1038 )(this); |
| 185 | | } |
| 186 | | |
| 187 | | //------------------------------------------------- |
| 188 | | // device_reset - device-specific reset |
| 189 | | //------------------------------------------------- |
| 190 | | |
| 191 | | void adc1038_device::device_reset() |
| 192 | | { |
| 193 | | DEVICE_RESET_NAME( adc1038 )(this); |
| 194 | | } |
trunk/src/mame/drivers/hornet.c
| r23541 | r23542 | |
| 339 | 339 | m_dsp2(*this, "dsp2"), |
| 340 | 340 | m_eeprom(*this, "eeprom"), |
| 341 | 341 | 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") { } |
| 343 | 344 | |
| 344 | 345 | UINT8 m_led_reg0; |
| 345 | 346 | UINT8 m_led_reg1; |
| 346 | 347 | required_shared_ptr<UINT32> m_workram; |
| 347 | 348 | required_shared_ptr<UINT32> m_sharc_dataram0; |
| 348 | 349 | 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; |
| 349 | 359 | UINT8 *m_jvs_sdata; |
| 350 | 360 | UINT32 m_jvs_sdata_ptr; |
| 351 | 361 | emu_timer *m_sound_irq_timer; |
| r23541 | r23542 | |
| 385 | 395 | int jvs_encode_data(UINT8 *in, int length); |
| 386 | 396 | int jvs_decode_data(UINT8 *in, UINT8 *out, int length); |
| 387 | 397 | 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; |
| 396 | 398 | }; |
| 397 | 399 | |
| 398 | 400 | |
| r23541 | r23542 | |
| 487 | 489 | { |
| 488 | 490 | UINT8 r = 0; |
| 489 | 491 | static const char *const portnames[] = { "IN0", "IN1", "IN2" }; |
| 490 | | device_t *adc12138 = machine().device("adc12138"); |
| 491 | 492 | switch (offset) |
| 492 | 493 | { |
| 493 | 494 | case 0: /* I/O port 0 */ |
| r23541 | r23542 | |
| 507 | 508 | 0x01 = ADDO (ADC DO) |
| 508 | 509 | */ |
| 509 | 510 | 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); |
| 511 | 512 | break; |
| 512 | 513 | |
| 513 | 514 | case 4: /* I/O port 4 - DIP switches */ |
| r23541 | r23542 | |
| 519 | 520 | |
| 520 | 521 | WRITE8_MEMBER(hornet_state::sysreg_w) |
| 521 | 522 | { |
| 522 | | device_t *adc12138 = machine().device("adc12138"); |
| 523 | | |
| 524 | 523 | switch (offset) |
| 525 | 524 | { |
| 526 | 525 | case 0: /* LED Register 0 */ |
| r23541 | r23542 | |
| 561 | 560 | 0x02 = ADDI (ADC DI) |
| 562 | 561 | 0x01 = ADDSCLK (ADC SCLK) |
| 563 | 562 | */ |
| 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); |
| 568 | 567 | |
| 569 | 568 | m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x80) ? CLEAR_LINE : ASSERT_LINE); |
| 570 | 569 | mame_printf_debug("System register 1 = %02X\n", data); |