src/emu/machine/adc0808.c
| r0 | r11199 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | National Semiconductor ADC0808/ADC0809 8-Bit A/D Converter emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | #include "emu.h" |
| 11 | #include "adc0808.h" |
| 12 | #include "machine/devhelpr.h" |
| 13 | |
| 14 | |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // MACROS / CONSTANTS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | |
| 21 | |
| 22 | //************************************************************************** |
| 23 | // DEVICE DEFINITIONS |
| 24 | //************************************************************************** |
| 25 | |
| 26 | const device_type ADC0808 = adc0808_device_config::static_alloc_device_config; |
| 27 | |
| 28 | |
| 29 | |
| 30 | //************************************************************************** |
| 31 | // DEVICE CONFIGURATION |
| 32 | //************************************************************************** |
| 33 | |
| 34 | GENERIC_DEVICE_CONFIG_SETUP(adc0808, "ADC0808") |
| 35 | |
| 36 | |
| 37 | //------------------------------------------------- |
| 38 | // device_config_complete - perform any |
| 39 | // operations now that the configuration is |
| 40 | // complete |
| 41 | //------------------------------------------------- |
| 42 | |
| 43 | void adc0808_device_config::device_config_complete() |
| 44 | { |
| 45 | // inherit a copy of the static data |
| 46 | const adc0808_interface *intf = reinterpret_cast<const adc0808_interface *>(static_config()); |
| 47 | if (intf != NULL) |
| 48 | *static_cast<adc0808_interface *>(this) = *intf; |
| 49 | |
| 50 | // or initialize to defaults if none provided |
| 51 | else |
| 52 | { |
| 53 | memset(&m_out_eoc_func, 0, sizeof(m_out_eoc_func)); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | |
| 58 | |
| 59 | //************************************************************************** |
| 60 | // LIVE DEVICE |
| 61 | //************************************************************************** |
| 62 | |
| 63 | //------------------------------------------------- |
| 64 | // adc0808_device - constructor |
| 65 | //------------------------------------------------- |
| 66 | |
| 67 | adc0808_device::adc0808_device(running_machine &_machine, const adc0808_device_config &config) |
| 68 | : device_t(_machine, config), |
| 69 | m_address(0), |
| 70 | m_start(0), |
| 71 | m_next_eoc(0), |
| 72 | m_cycle(0), |
| 73 | m_config(config) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | |
| 78 | //------------------------------------------------- |
| 79 | // device_start - device-specific startup |
| 80 | //------------------------------------------------- |
| 81 | |
| 82 | void adc0808_device::device_start() |
| 83 | { |
| 84 | // resolve callbacks |
| 85 | devcb_resolve_write_line(&m_out_eoc_func, &m_config.m_out_eoc_func, this); |
| 86 | |
| 87 | // allocate timers |
| 88 | m_cycle_timer = timer_alloc(); |
| 89 | m_cycle_timer->adjust(attotime::zero, 0, attotime::from_hz(clock())); |
| 90 | |
| 91 | // register for state saving |
| 92 | save_item(NAME(m_address)); |
| 93 | save_item(NAME(m_start)); |
| 94 | save_item(NAME(m_eoc)); |
| 95 | save_item(NAME(m_next_eoc)); |
| 96 | save_item(NAME(m_sar)); |
| 97 | save_item(NAME(m_cycle)); |
| 98 | save_item(NAME(m_bit)); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | //------------------------------------------------- |
| 103 | // device_timer - handler timer events |
| 104 | //------------------------------------------------- |
| 105 | |
| 106 | void adc0808_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 107 | { |
| 108 | if (!m_start) |
| 109 | { |
| 110 | if (m_cycle == 7) |
| 111 | { |
| 112 | m_bit++; |
| 113 | |
| 114 | if (m_bit == 8) |
| 115 | { |
| 116 | /* sample input */ |
| 117 | double vref_pos = m_config.m_in_vref_pos_func(this); |
| 118 | double vref_neg = m_config.m_in_vref_neg_func(this); |
| 119 | |
| 120 | double input = m_config.m_in_in_func[m_address](this); |
| 121 | |
| 122 | m_sar = (255 * (input - vref_neg)) / (vref_pos - vref_neg); |
| 123 | |
| 124 | /* trigger end of conversion */ |
| 125 | m_next_eoc = 1; |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (m_cycle == 0) |
| 131 | { |
| 132 | /* set end of conversion pin */ |
| 133 | if (m_next_eoc != m_eoc) |
| 134 | { |
| 135 | devcb_call_write_line(&m_out_eoc_func, m_next_eoc); |
| 136 | m_eoc = m_next_eoc; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | m_cycle++; |
| 141 | |
| 142 | if (m_cycle == 8) |
| 143 | { |
| 144 | m_cycle = 0; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | |
| 149 | //------------------------------------------------- |
| 150 | // data_r - data read |
| 151 | //------------------------------------------------- |
| 152 | |
| 153 | READ8_MEMBER( adc0808_device::data_r ) |
| 154 | { |
| 155 | return m_sar; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | //------------------------------------------------- |
| 160 | // ale_w - address write |
| 161 | //------------------------------------------------- |
| 162 | |
| 163 | WRITE8_MEMBER( adc0808_device::ale_w ) |
| 164 | { |
| 165 | m_address = data; |
| 166 | } |
| 167 | |
| 168 | |
| 169 | //------------------------------------------------- |
| 170 | // start_w - start conversion |
| 171 | //------------------------------------------------- |
| 172 | |
| 173 | WRITE_LINE_MEMBER( adc0808_device::start_w ) |
| 174 | { |
| 175 | if (!m_start && state) // rising edge |
| 176 | { |
| 177 | // reset registers |
| 178 | |
| 179 | m_sar = 0; |
| 180 | m_bit = 0; |
| 181 | } |
| 182 | else if (m_start && !state) // falling edge |
| 183 | { |
| 184 | // start conversion |
| 185 | |
| 186 | m_next_eoc = 0; |
| 187 | } |
| 188 | |
| 189 | m_start = state; |
| 190 | } |
src/emu/machine/adc0808.h
| r0 | r11199 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | National Semiconductor ADC0808/ADC0809 8-Bit A/D Converter emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | ********************************************************************** |
| 9 | _____ _____ |
| 10 | IN3 1 |* \_/ | 28 IN2 |
| 11 | IN4 2 | | 27 IN1 |
| 12 | IN5 3 | | 26 IN0 |
| 13 | IN6 4 | | 25 ADD A |
| 14 | IN7 5 | | 24 ADD B |
| 15 | START 6 | | 23 ADD C |
| 16 | EOC 7 | ADC0808 | 22 ALE |
| 17 | 2-5 8 | ADC0809 | 21 2-1 MSB |
| 18 | OUTPUT ENABLE 9 | | 20 2-2 |
| 19 | CLOCK 10 | | 19 2-3 |
| 20 | Vcc 11 | | 18 2-4 |
| 21 | Vref+ 12 | | 17 2-8 LSB |
| 22 | GND 13 | | 16 Vref- |
| 23 | 2-7 14 |_____________| 15 2-6 |
| 24 | |
| 25 | **********************************************************************/ |
| 26 | |
| 27 | #pragma once |
| 28 | |
| 29 | #ifndef __ADC0808__ |
| 30 | #define __ADC0808__ |
| 31 | |
| 32 | #include "emu.h" |
| 33 | |
| 34 | |
| 35 | |
| 36 | //************************************************************************** |
| 37 | // INTERFACE CONFIGURATION MACROS |
| 38 | //************************************************************************** |
| 39 | |
| 40 | #define MCFG_ADC0808_ADD(_tag, _clock, _config) \ |
| 41 | MCFG_DEVICE_ADD(_tag, ADC0808, _clock) \ |
| 42 | MCFG_DEVICE_CONFIG(_config) |
| 43 | |
| 44 | |
| 45 | #define ADC0808_INTERFACE(name) \ |
| 46 | const adc0808_interface (name) = |
| 47 | |
| 48 | |
| 49 | |
| 50 | //************************************************************************** |
| 51 | // TYPE DEFINITIONS |
| 52 | //************************************************************************** |
| 53 | |
| 54 | // ======================> adc0808_analog_read |
| 55 | |
| 56 | typedef double (*adc0808_analog_read) (device_t *device); |
| 57 | #define ADC0808_ANALOG_READ(name) double name(device_t *device) |
| 58 | |
| 59 | |
| 60 | // ======================> adc0808_interface |
| 61 | |
| 62 | struct adc0808_interface |
| 63 | { |
| 64 | devcb_write_line m_out_eoc_func; |
| 65 | |
| 66 | adc0808_analog_read m_in_vref_pos_func; |
| 67 | adc0808_analog_read m_in_vref_neg_func; |
| 68 | |
| 69 | adc0808_analog_read m_in_in_func[8]; |
| 70 | }; |
| 71 | |
| 72 | |
| 73 | // ======================> adc0808_device_config |
| 74 | |
| 75 | class adc0808_device_config : public device_config, |
| 76 | public adc0808_interface |
| 77 | { |
| 78 | friend class adc0808_device; |
| 79 | |
| 80 | // construction/destruction |
| 81 | adc0808_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 82 | |
| 83 | public: |
| 84 | // allocators |
| 85 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 86 | virtual device_t *alloc_device(running_machine &machine) const; |
| 87 | |
| 88 | protected: |
| 89 | // device_config overrides |
| 90 | virtual void device_config_complete(); |
| 91 | }; |
| 92 | |
| 93 | |
| 94 | // ======================> adc0808_device |
| 95 | |
| 96 | class adc0808_device : public device_t |
| 97 | { |
| 98 | friend class adc0808_device_config; |
| 99 | |
| 100 | // construction/destruction |
| 101 | adc0808_device(running_machine &_machine, const adc0808_device_config &_config); |
| 102 | |
| 103 | public: |
| 104 | DECLARE_READ8_MEMBER( data_r ); |
| 105 | DECLARE_WRITE8_MEMBER( ale_w ); |
| 106 | |
| 107 | DECLARE_WRITE_LINE_MEMBER( start_w ); |
| 108 | |
| 109 | protected: |
| 110 | // device-level overrides |
| 111 | virtual void device_start(); |
| 112 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 113 | |
| 114 | private: |
| 115 | devcb_resolved_write_line m_out_eoc_func; |
| 116 | |
| 117 | int m_address; // analog channel address |
| 118 | int m_start; // start conversion pin |
| 119 | int m_eoc; // end of conversion pin |
| 120 | int m_next_eoc; // next value end of conversion pin |
| 121 | |
| 122 | UINT8 m_sar; // successive approximation register |
| 123 | |
| 124 | int m_cycle; // clock cycle counter |
| 125 | int m_bit; // bit counter |
| 126 | |
| 127 | // timers |
| 128 | emu_timer *m_cycle_timer; |
| 129 | |
| 130 | const adc0808_device_config &m_config; |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | // device type definition |
| 135 | extern const device_type ADC0808; |
| 136 | |
| 137 | |
| 138 | |
| 139 | #endif |
src/mess/machine/adc080x.c
| r11198 | r11199 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | ADC0808/ADC0809 8-Bit A/D Converter emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | **********************************************************************/ |
| 9 | | |
| 10 | | #include "emu.h" |
| 11 | | #include "adc080x.h" |
| 12 | | |
| 13 | | typedef struct _adc080x_t adc080x_t; |
| 14 | | struct _adc080x_t |
| 15 | | { |
| 16 | | const adc080x_interface *intf; /* interface */ |
| 17 | | |
| 18 | | int address; /* analog channel address */ |
| 19 | | int ale; /* address latch enable pin */ |
| 20 | | int start; /* start conversion pin */ |
| 21 | | int eoc; /* end of conversion pin */ |
| 22 | | int next_eoc; /* next value end of conversion pin */ |
| 23 | | |
| 24 | | UINT8 sar; /* successive approximation register */ |
| 25 | | |
| 26 | | int cycle; /* clock cycle counter */ |
| 27 | | int bit; /* bit counter */ |
| 28 | | |
| 29 | | /* timers */ |
| 30 | | emu_timer *cycle_timer; /* cycle timer */ |
| 31 | | }; |
| 32 | | |
| 33 | | INLINE adc080x_t *get_safe_token(device_t *device) |
| 34 | | { |
| 35 | | assert(device != NULL); |
| 36 | | assert(device->type() == ADC0808 || device->type() == ADC0809); |
| 37 | | |
| 38 | | return (adc080x_t *)downcast<legacy_device_base *>(device)->token(); |
| 39 | | } |
| 40 | | |
| 41 | | /* Approximation Cycle */ |
| 42 | | |
| 43 | | static TIMER_CALLBACK( cycle_tick ) |
| 44 | | { |
| 45 | | device_t *device = (device_t *)ptr; |
| 46 | | adc080x_t *adc080x = get_safe_token(device); |
| 47 | | |
| 48 | | if (!adc080x->start) |
| 49 | | { |
| 50 | | if (adc080x->cycle == 7) |
| 51 | | { |
| 52 | | adc080x->bit++; |
| 53 | | |
| 54 | | if (adc080x->bit == 8) |
| 55 | | { |
| 56 | | /* sample input */ |
| 57 | | double vref_pos = adc080x->intf->vref_pos_r(device); |
| 58 | | double vref_neg = adc080x->intf->vref_neg_r(device); |
| 59 | | double input = adc080x->intf->input_r(device, adc080x->address); |
| 60 | | |
| 61 | | adc080x->sar = (255 * (input - vref_neg)) / (vref_pos - vref_neg); |
| 62 | | |
| 63 | | /* trigger end of conversion */ |
| 64 | | adc080x->next_eoc = 1; |
| 65 | | } |
| 66 | | } |
| 67 | | } |
| 68 | | |
| 69 | | if (adc080x->cycle == 0) |
| 70 | | { |
| 71 | | /* set end of conversion pin */ |
| 72 | | if (adc080x->next_eoc != adc080x->eoc) |
| 73 | | { |
| 74 | | adc080x->intf->on_eoc_changed(device, adc080x->next_eoc); |
| 75 | | adc080x->eoc = adc080x->next_eoc; |
| 76 | | } |
| 77 | | } |
| 78 | | |
| 79 | | adc080x->cycle++; |
| 80 | | |
| 81 | | if (adc080x->cycle == 8) |
| 82 | | { |
| 83 | | adc080x->cycle = 0; |
| 84 | | } |
| 85 | | } |
| 86 | | |
| 87 | | /* Address Latch Enable */ |
| 88 | | |
| 89 | | void adc080x_ale_w(device_t *device, int level, int address) |
| 90 | | { |
| 91 | | adc080x_t *adc080x = get_safe_token(device); |
| 92 | | |
| 93 | | if (adc080x->ale && !level) // falling edge |
| 94 | | { |
| 95 | | adc080x->address = address; |
| 96 | | } |
| 97 | | |
| 98 | | adc080x->ale = level; |
| 99 | | } |
| 100 | | |
| 101 | | /* Start Conversion */ |
| 102 | | |
| 103 | | void adc080x_start_w(device_t *device, int level) |
| 104 | | { |
| 105 | | adc080x_t *adc080x = get_safe_token(device); |
| 106 | | |
| 107 | | if (!adc080x->start && level) // rising edge |
| 108 | | { |
| 109 | | // reset registers |
| 110 | | |
| 111 | | adc080x->sar = 0; |
| 112 | | adc080x->bit = 0; |
| 113 | | } |
| 114 | | else if (adc080x->start && !level) // falling edge |
| 115 | | { |
| 116 | | // start conversion |
| 117 | | |
| 118 | | adc080x->next_eoc = 0; |
| 119 | | } |
| 120 | | |
| 121 | | adc080x->start = level; |
| 122 | | } |
| 123 | | |
| 124 | | /* Conversion Data */ |
| 125 | | |
| 126 | | READ8_DEVICE_HANDLER( adc080x_data_r ) |
| 127 | | { |
| 128 | | adc080x_t *adc080x = get_safe_token(device); |
| 129 | | |
| 130 | | return adc080x->sar; |
| 131 | | } |
| 132 | | |
| 133 | | /* Device Interface */ |
| 134 | | |
| 135 | | static DEVICE_START( adc080x ) |
| 136 | | { |
| 137 | | adc080x_t *adc080x = get_safe_token(device); |
| 138 | | |
| 139 | | /* validate arguments */ |
| 140 | | assert(device != NULL); |
| 141 | | assert(device->tag() != NULL); |
| 142 | | |
| 143 | | adc080x->intf = (const adc080x_interface*)device->baseconfig().static_config(); |
| 144 | | |
| 145 | | assert(adc080x->intf != NULL); |
| 146 | | assert(device->clock() > 0); |
| 147 | | |
| 148 | | /* set initial values */ |
| 149 | | adc080x->eoc = 1; |
| 150 | | |
| 151 | | /* allocate cycle timer */ |
| 152 | | adc080x->cycle_timer = device->machine().scheduler().timer_alloc(FUNC(cycle_tick), (void *)device); |
| 153 | | adc080x->cycle_timer->adjust(attotime::zero, 0, attotime::from_hz(device->clock())); |
| 154 | | |
| 155 | | /* register for state saving */ |
| 156 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->address); |
| 157 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->ale); |
| 158 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->start); |
| 159 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->eoc); |
| 160 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->next_eoc); |
| 161 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->sar); |
| 162 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->cycle); |
| 163 | | state_save_register_item(device->machine(), "adc080x", device->tag(), 0, adc080x->bit); |
| 164 | | } |
| 165 | | |
| 166 | | DEVICE_GET_INFO( adc0808 ) |
| 167 | | { |
| 168 | | switch (state) |
| 169 | | { |
| 170 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 171 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(adc080x_t); break; |
| 172 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 173 | | |
| 174 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 175 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(adc080x); break; |
| 176 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 177 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 178 | | |
| 179 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 180 | | case DEVINFO_STR_NAME: strcpy(info->s, "National Semiconductor ADC0808"); break; |
| 181 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "National Semiconductor ADC080"); break; |
| 182 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 183 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 184 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 185 | | } |
| 186 | | } |
| 187 | | |
| 188 | | DEVICE_GET_INFO( adc0809 ) |
| 189 | | { |
| 190 | | switch (state) |
| 191 | | { |
| 192 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 193 | | case DEVINFO_STR_NAME: strcpy(info->s, "National Semiconductor ADC0809"); break; |
| 194 | | |
| 195 | | default: DEVICE_GET_INFO_CALL(adc0808); break; |
| 196 | | } |
| 197 | | } |
| 198 | | |
| 199 | | DEFINE_LEGACY_DEVICE(ADC0808, adc0808); |
| 200 | | DEFINE_LEGACY_DEVICE(ADC0809, adc0809); |
src/mess/machine/adc080x.h
| r11198 | r11199 | |
| 1 | | /********************************************************************** |
| 2 | | |
| 3 | | ADC0808/ADC0809 8-Bit A/D Converter emulation |
| 4 | | |
| 5 | | Copyright MESS Team. |
| 6 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | | |
| 8 | | ********************************************************************** |
| 9 | | _____ _____ |
| 10 | | IN3 1 |* \_/ | 28 IN2 |
| 11 | | IN4 2 | | 27 IN1 |
| 12 | | IN5 3 | | 26 IN0 |
| 13 | | IN6 4 | | 25 ADD A |
| 14 | | IN7 5 | | 24 ADD B |
| 15 | | START 6 | | 23 ADD C |
| 16 | | EOC 7 | ADC0808 | 22 ALE |
| 17 | | 2-5 8 | ADC0809 | 21 2-1 MSB |
| 18 | | OUTPUT ENABLE 9 | | 20 2-2 |
| 19 | | CLOCK 10 | | 19 2-3 |
| 20 | | Vcc 11 | | 18 2-4 |
| 21 | | Vref+ 12 | | 17 2-8 LSB |
| 22 | | GND 13 | | 16 Vref- |
| 23 | | 2-7 14 |_____________| 15 2-6 |
| 24 | | |
| 25 | | **********************************************************************/ |
| 26 | | |
| 27 | | #ifndef __ADC080X__ |
| 28 | | #define __ADC080X__ |
| 29 | | |
| 30 | | typedef void (*adc080x_on_eoc_changed_func) (device_t *device, int level); |
| 31 | | #define ADC080X_ON_EOC_CHANGED(name) void name(device_t *device, int level) |
| 32 | | |
| 33 | | typedef double (*adc080x_vref_pos_read) (device_t *device); |
| 34 | | #define ADC080X_VREF_POSITIVE_READ(name) double name(device_t *device) |
| 35 | | |
| 36 | | typedef double (*adc080x_vref_neg_read) (device_t *device); |
| 37 | | #define ADC080X_VREF_NEGATIVE_READ(name) double name(device_t *device) |
| 38 | | |
| 39 | | typedef double (*adc080x_input_read) (device_t *device, int channel); |
| 40 | | #define ADC080X_INPUT_READ(name) double name(device_t *device, int channel) |
| 41 | | |
| 42 | | DECLARE_LEGACY_DEVICE(ADC0808, adc0808); |
| 43 | | DECLARE_LEGACY_DEVICE(ADC0809, adc0809); |
| 44 | | |
| 45 | | #define MCFG_ADC0808_ADD(_tag, _clock, _intrf) \ |
| 46 | | MCFG_DEVICE_ADD(_tag, ADC0808, _clock) \ |
| 47 | | MCFG_DEVICE_CONFIG(_intrf) |
| 48 | | |
| 49 | | #define MCFG_ADC0809_ADD(_tag, _clock, _intrf) \ |
| 50 | | MCFG_DEVICE_ADD(_tag, ADC0809, _clock) \ |
| 51 | | MCFG_DEVICE_CONFIG(_intrf) |
| 52 | | |
| 53 | | |
| 54 | | /* interface */ |
| 55 | | typedef struct _adc080x_interface adc080x_interface; |
| 56 | | struct _adc080x_interface |
| 57 | | { |
| 58 | | /* this gets called for every change of the EOC pin (pin 7) */ |
| 59 | | adc080x_on_eoc_changed_func on_eoc_changed; |
| 60 | | |
| 61 | | /* this gets called for every sampling of the positive reference voltage (pin 12) */ |
| 62 | | adc080x_vref_pos_read vref_pos_r; |
| 63 | | |
| 64 | | /* this gets called for every sampling of the negative reference voltage (pin 16) */ |
| 65 | | adc080x_vref_neg_read vref_neg_r; |
| 66 | | |
| 67 | | /* this gets called for every sampling of the input pins IN0-IN7 */ |
| 68 | | adc080x_input_read input_r; |
| 69 | | }; |
| 70 | | #define ADC080X_INTERFACE(name) const adc080x_interface (name)= |
| 71 | | |
| 72 | | /* address latching */ |
| 73 | | void adc080x_ale_w(device_t *device, int level, int address); |
| 74 | | |
| 75 | | /* start conversion */ |
| 76 | | void adc080x_start_w(device_t *device, int level); |
| 77 | | |
| 78 | | /* conversion data */ |
| 79 | | READ8_DEVICE_HANDLER( adc080x_data_r ); |
| 80 | | |
| 81 | | #endif |
src/mess/drivers/newbrain.c
| r11198 | r11199 | |
| 953 | 953 | |
| 954 | 954 | /* A/D Converter */ |
| 955 | 955 | |
| 956 | | static ADC080X_ON_EOC_CHANGED( newbrain_adc_on_eoc_changed ) |
| 956 | WRITE_LINE_MEMBER( newbrain_eim_state::adc_eoc_w ) |
| 957 | 957 | { |
| 958 | | newbrain_state *state = device->machine().driver_data<newbrain_state>(); |
| 959 | | |
| 960 | | state->m_anint = level; |
| 958 | m_anint = state; |
| 961 | 959 | } |
| 962 | 960 | |
| 963 | | static ADC080X_VREF_POSITIVE_READ( newbrain_adc_vref_pos_r ) |
| 961 | static ADC0808_ANALOG_READ( newbrain_adc_vref_pos_r ) |
| 964 | 962 | { |
| 965 | 963 | return 5.0; |
| 966 | 964 | } |
| 967 | 965 | |
| 968 | | static ADC080X_VREF_NEGATIVE_READ( newbrain_adc_vref_neg_r ) |
| 966 | static ADC0808_ANALOG_READ( newbrain_adc_vref_neg_r ) |
| 969 | 967 | { |
| 970 | 968 | return 0.0; |
| 971 | 969 | } |
| 972 | 970 | |
| 973 | | static ADC080X_INPUT_READ( newbrain_adc_input_r ) |
| 971 | static ADC0808_ANALOG_READ( newbrain_adc_input_r ) |
| 974 | 972 | { |
| 975 | 973 | return 0.0; |
| 976 | 974 | } |
| 977 | 975 | |
| 978 | | static ADC080X_INTERFACE( newbrain_adc0809_intf ) |
| 976 | static ADC0808_INTERFACE( adc_intf ) |
| 979 | 977 | { |
| 980 | | newbrain_adc_on_eoc_changed, |
| 978 | DEVCB_DRIVER_LINE_MEMBER(newbrain_eim_state, adc_eoc_w), |
| 981 | 979 | newbrain_adc_vref_pos_r, |
| 982 | 980 | newbrain_adc_vref_neg_r, |
| 983 | | newbrain_adc_input_r |
| 981 | { newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r, |
| 982 | newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r } |
| 984 | 983 | }; |
| 985 | 984 | |
| 986 | 985 | /* Memory Maps */ |
| r11198 | r11199 | |
| 1174 | 1173 | m_aciaint = state; |
| 1175 | 1174 | } |
| 1176 | 1175 | |
| 1177 | | static ACIA6850_INTERFACE( newbrain_acia_intf ) |
| 1176 | static ACIA6850_INTERFACE( acia_intf ) |
| 1178 | 1177 | { |
| 1179 | 1178 | 0, |
| 1180 | 1179 | 0, |
| r11198 | r11199 | |
| 1191 | 1190 | m_fdc_int = state; |
| 1192 | 1191 | } |
| 1193 | 1192 | |
| 1194 | | static const upd765_interface newbrain_upd765_interface = |
| 1193 | static const upd765_interface fdc_intf = |
| 1195 | 1194 | { |
| 1196 | 1195 | DEVCB_DRIVER_LINE_MEMBER(newbrain_eim_state, fdc_interrupt), |
| 1197 | 1196 | DEVCB_NULL, |
| r11198 | r11199 | |
| 1433 | 1432 | // devices |
| 1434 | 1433 | MCFG_Z80CTC_ADD(Z80CTC_TAG, XTAL_16MHz/8, newbrain_ctc_intf) |
| 1435 | 1434 | MCFG_TIMER_ADD_PERIODIC("z80ctc_c2", ctc_c2_tick, attotime::from_hz(XTAL_16MHz/4/13)) |
| 1436 | | MCFG_ADC0809_ADD(ADC0809_TAG, 500000, newbrain_adc0809_intf) |
| 1437 | | MCFG_ACIA6850_ADD(MC6850_TAG, newbrain_acia_intf) |
| 1438 | | MCFG_UPD765A_ADD(UPD765_TAG, newbrain_upd765_interface) |
| 1435 | MCFG_ADC0808_ADD(ADC0809_TAG, 500000, adc_intf) |
| 1436 | MCFG_ACIA6850_ADD(MC6850_TAG, acia_intf) |
| 1437 | MCFG_UPD765A_ADD(UPD765_TAG, fdc_intf) |
| 1439 | 1438 | MCFG_FLOPPY_2_DRIVES_ADD(newbrain_floppy_config) |
| 1440 | 1439 | |
| 1441 | 1440 | // internal ram |