src/emu/machine/74123.c
| r8885 | r8886 | |
| 14 | 14 | #define LOG (0) |
| 15 | 15 | |
| 16 | 16 | |
| 17 | | typedef struct _ttl74123_t ttl74123_t; |
| 17 | //************************************************************************** |
| 18 | // DEVICE CONFIGURATION |
| 19 | //************************************************************************** |
| 18 | 20 | |
| 19 | | struct _ttl74123_t |
| 21 | //------------------------------------------------- |
| 22 | // ttl74123_device_config - constructor |
| 23 | //------------------------------------------------- |
| 24 | |
| 25 | ttl74123_device_config::ttl74123_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 26 | : device_config(mconfig, static_alloc_device_config, "TTL74123", tag, owner, clock) |
| 20 | 27 | { |
| 21 | | const ttl74123_config *intf; |
| 28 | } |
| 22 | 29 | |
| 23 | | UINT8 a; /* pin 1/9 */ |
| 24 | | UINT8 b; /* pin 2/10 */ |
| 25 | | UINT8 clear; /* pin 3/11 */ |
| 26 | | emu_timer *timer; |
| 27 | | }; |
| 28 | 30 | |
| 29 | | /* ----------------------------------------------------------------------- */ |
| 31 | //------------------------------------------------- |
| 32 | // static_alloc_device_config - allocate a new |
| 33 | // configuration object |
| 34 | //------------------------------------------------- |
| 30 | 35 | |
| 31 | | INLINE ttl74123_t *get_safe_token(running_device *device) { |
| 32 | | assert( device != NULL ); |
| 33 | | assert( device->type() == TTL74123 ); |
| 34 | | return ( ttl74123_t * ) downcast<legacy_device_base *>(device)->token(); |
| 36 | device_config *ttl74123_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 37 | { |
| 38 | return global_alloc(ttl74123_device_config(mconfig, tag, owner, clock)); |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | 41 | |
| 38 | | static attotime compute_duration(ttl74123_t *chip) |
| 42 | //------------------------------------------------- |
| 43 | // alloc_device - allocate a new device object |
| 44 | //------------------------------------------------- |
| 45 | |
| 46 | device_t *ttl74123_device_config::alloc_device(running_machine &machine) const |
| 39 | 47 | { |
| 40 | | double duration; |
| 48 | return auto_alloc(&machine, ttl74123_device(machine, *this)); |
| 49 | } |
| 41 | 50 | |
| 42 | | switch (chip->intf->connection_type) |
| 43 | | { |
| 44 | | case TTL74123_NOT_GROUNDED_NO_DIODE: |
| 45 | | duration = 0.28 * chip->intf->res * chip->intf->cap * (1.0 + (700.0 / chip->intf->res)); |
| 46 | | break; |
| 47 | 51 | |
| 48 | | case TTL74123_NOT_GROUNDED_DIODE: |
| 49 | | duration = 0.25 * chip->intf->res * chip->intf->cap * (1.0 + (700.0 / chip->intf->res)); |
| 50 | | break; |
| 52 | //------------------------------------------------- |
| 53 | // device_config_complete - perform any |
| 54 | // operations now that the configuration is |
| 55 | // complete |
| 56 | //------------------------------------------------- |
| 51 | 57 | |
| 52 | | case TTL74123_GROUNDED: |
| 53 | | default: |
| 54 | | if (chip->intf->cap < CAP_U(0.1)) |
| 55 | | /* this is really a curve - a very flat one in the 0.1uF-.01uF range */ |
| 56 | | duration = 0.32 * chip->intf->res * chip->intf->cap; |
| 57 | | else |
| 58 | | duration = 0.33 * chip->intf->res * chip->intf->cap; |
| 59 | | break; |
| 60 | | } |
| 58 | void ttl74123_device_config::device_config_complete() |
| 59 | { |
| 61 | 60 | |
| 62 | | return double_to_attotime(duration); |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | |
| 66 | | static int timer_running(ttl74123_t *chip) |
| 67 | | { |
| 68 | | return (attotime_compare(timer_timeleft(chip->timer), attotime_zero) > 0) && |
| 69 | | (attotime_compare(timer_timeleft(chip->timer), attotime_never) != 0); |
| 70 | | } |
| 71 | 64 | |
| 65 | //************************************************************************** |
| 66 | // LIVE DEVICE |
| 67 | //************************************************************************** |
| 72 | 68 | |
| 73 | | static TIMER_CALLBACK( output_callback ) |
| 69 | //------------------------------------------------- |
| 70 | // ttl74123_device - constructor |
| 71 | //------------------------------------------------- |
| 72 | |
| 73 | ttl74123_device::ttl74123_device(running_machine &_machine, const ttl74123_device_config &config) |
| 74 | : device_t(_machine, config), |
| 75 | m_config(config) |
| 74 | 76 | { |
| 75 | | running_device *device = (running_device *)ptr; |
| 76 | | ttl74123_t *chip = get_safe_token(device); |
| 77 | 77 | |
| 78 | | chip->intf->output_changed_cb(device, 0, param); |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | |
| 82 | | static void set_output(running_device *device) |
| 81 | //------------------------------------------------- |
| 82 | // device_start - device-specific startup |
| 83 | //------------------------------------------------- |
| 84 | |
| 85 | void ttl74123_device::device_start() |
| 83 | 86 | { |
| 84 | | ttl74123_t *chip = get_safe_token(device); |
| 85 | | int output = timer_running(chip); |
| 87 | m_timer = timer_alloc(&m_machine, clear_callback, (void *)this); |
| 86 | 88 | |
| 87 | | timer_set( device->machine, attotime_zero, (void *) device, output, output_callback ); |
| 89 | /* start with the defaults */ |
| 90 | m_a = m_config.m_a; |
| 91 | m_b = m_config.m_b; |
| 92 | m_clear = m_config.m_clear; |
| 88 | 93 | |
| 89 | | if (LOG) logerror("74123 %s: Output: %d\n", device->tag(), output); |
| 94 | /* register for state saving */ |
| 95 | state_save_register_device_item(this, 0, m_a); |
| 96 | state_save_register_device_item(this, 0, m_b); |
| 97 | state_save_register_device_item(this, 0, m_clear); |
| 90 | 98 | } |
| 91 | 99 | |
| 92 | 100 | |
| 93 | | static TIMER_CALLBACK( clear_callback ) |
| 101 | //------------------------------------------------- |
| 102 | // device_reset - device-specific reset |
| 103 | //------------------------------------------------- |
| 104 | |
| 105 | void ttl74123_device::device_reset() |
| 94 | 106 | { |
| 95 | | running_device *device = (running_device *)ptr; |
| 96 | | ttl74123_t *chip = get_safe_token(device); |
| 97 | | int output = timer_running(chip); |
| 98 | | |
| 99 | | chip->intf->output_changed_cb(device, 0, output); |
| 107 | set_output(); |
| 100 | 108 | } |
| 101 | 109 | |
| 102 | 110 | |
| 103 | 111 | |
| 112 | /*------------------------------------------------- |
| 113 | compute_duration |
| 114 | -------------------------------------------------*/ |
| 104 | 115 | |
| 105 | | static void start_pulse(running_device *device) |
| 116 | attotime ttl74123_device::compute_duration() |
| 106 | 117 | { |
| 107 | | ttl74123_t *chip = get_safe_token(device); |
| 118 | double duration; |
| 108 | 119 | |
| 109 | | attotime duration = compute_duration(chip); |
| 120 | switch (m_config.m_connection_type) |
| 121 | { |
| 122 | case TTL74123_NOT_GROUNDED_NO_DIODE: |
| 123 | duration = 0.28 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res)); |
| 124 | break; |
| 110 | 125 | |
| 111 | | if (timer_running(chip)) |
| 112 | | { |
| 113 | | /* retriggering, but not if we are called to quickly */ |
| 114 | | attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * chip->intf->cap * 220); |
| 126 | case TTL74123_NOT_GROUNDED_DIODE: |
| 127 | duration = 0.25 * m_config.m_res * m_config.m_cap * (1.0 + (700.0 / m_config.m_res)); |
| 128 | break; |
| 115 | 129 | |
| 116 | | if (attotime_compare(timer_timeelapsed(chip->timer), delay_time) >= 0) |
| 117 | | { |
| 118 | | timer_adjust_oneshot(chip->timer, duration, 0); |
| 130 | case TTL74123_GROUNDED: |
| 131 | default: |
| 132 | if (m_config.m_cap < CAP_U(0.1)) |
| 133 | { |
| 134 | /* this is really a curve - a very flat one in the 0.1uF-.01uF range */ |
| 135 | duration = 0.32 * m_config.m_res * m_config.m_cap; |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | duration = 0.33 * m_config.m_res * m_config.m_cap; |
| 140 | } |
| 141 | break; |
| 142 | } |
| 119 | 143 | |
| 120 | | if (LOG) logerror("74123 %s: Retriggering pulse. Duration: %f\n", device->tag(), attotime_to_double(duration)); |
| 121 | | } |
| 122 | | else |
| 123 | | { |
| 124 | | if (LOG) logerror("74123 %s: Retriggering failed.\n", device->tag()); |
| 125 | | } |
| 126 | | } |
| 127 | | else |
| 128 | | { |
| 129 | | /* starting */ |
| 130 | | timer_adjust_oneshot(chip->timer, duration, 0); |
| 144 | return double_to_attotime(duration); |
| 145 | } |
| 131 | 146 | |
| 132 | | set_output(device); |
| 133 | 147 | |
| 134 | | if (LOG) logerror("74123 %s: Starting pulse. Duration: %f\n", device->tag(), attotime_to_double(duration)); |
| 135 | | } |
| 148 | /*------------------------------------------------- |
| 149 | timer_running |
| 150 | -------------------------------------------------*/ |
| 151 | |
| 152 | int ttl74123_device::timer_running() |
| 153 | { |
| 154 | return (attotime_compare(timer_timeleft(m_timer), attotime_zero) > 0) && |
| 155 | (attotime_compare(timer_timeleft(m_timer), attotime_never) != 0); |
| 136 | 156 | } |
| 137 | 157 | |
| 138 | 158 | |
| 139 | | WRITE8_DEVICE_HANDLER( ttl74123_a_w ) |
| 159 | /*------------------------------------------------- |
| 160 | TIMER_CALLBACK( output_callback ) |
| 161 | -------------------------------------------------*/ |
| 162 | |
| 163 | TIMER_CALLBACK( ttl74123_device::output_callback ) |
| 140 | 164 | { |
| 141 | | ttl74123_t *chip = get_safe_token(device); |
| 165 | ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr); |
| 166 | dev->output(param); |
| 167 | } |
| 142 | 168 | |
| 143 | | /* start/regtrigger pulse if B=HI and falling edge on A (while clear is HI) */ |
| 144 | | if (!data && chip->a && chip->b && chip->clear) |
| 145 | | start_pulse(device); |
| 146 | | |
| 147 | | chip->a = data; |
| 169 | void ttl74123_device::output(INT32 param) |
| 170 | { |
| 171 | m_config.m_output_changed_cb(this, 0, param); |
| 148 | 172 | } |
| 149 | 173 | |
| 150 | 174 | |
| 151 | | WRITE8_DEVICE_HANDLER( ttl74123_b_w ) |
| 175 | void ttl74123_device::set_output() |
| 152 | 176 | { |
| 153 | | ttl74123_t *chip = get_safe_token(device); |
| 177 | int output = timer_running(); |
| 154 | 178 | |
| 155 | | /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */ |
| 156 | | if (data && !chip->b && !chip->a && chip->clear) |
| 157 | | start_pulse(device); |
| 179 | timer_set( &m_machine, attotime_zero, (void *)this, output, output_callback ); |
| 158 | 180 | |
| 159 | | chip->b = data; |
| 181 | if (LOG) logerror("74123 %s: Output: %d\n", tag(), output); |
| 160 | 182 | } |
| 161 | 183 | |
| 162 | 184 | |
| 163 | | WRITE8_DEVICE_HANDLER( ttl74123_clear_w ) |
| 185 | TIMER_CALLBACK( ttl74123_device::clear_callback ) |
| 164 | 186 | { |
| 165 | | ttl74123_t *chip = get_safe_token(device); |
| 187 | ttl74123_device *dev = reinterpret_cast<ttl74123_device*>(ptr); |
| 188 | dev->clear(); |
| 189 | } |
| 166 | 190 | |
| 167 | | /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */ |
| 168 | | if (data && !chip->a && chip->b && !chip->clear) |
| 169 | | start_pulse(device); |
| 170 | | else if (!data) /* clear the output */ |
| 171 | | { |
| 172 | | timer_adjust_oneshot(chip->timer, attotime_zero, 0); |
| 191 | void ttl74123_device::clear() |
| 192 | { |
| 193 | int output = timer_running(); |
| 173 | 194 | |
| 174 | | if (LOG) logerror("74123 #%s: Cleared\n", device->tag() ); |
| 175 | | } |
| 176 | | chip->clear = data; |
| 195 | m_config.m_output_changed_cb(this, 0, output); |
| 177 | 196 | } |
| 178 | 197 | |
| 179 | | WRITE8_DEVICE_HANDLER( ttl74123_reset_w ) |
| 198 | |
| 199 | void ttl74123_device::start_pulse() |
| 180 | 200 | { |
| 181 | | set_output(device); |
| 201 | attotime duration = compute_duration(); |
| 202 | |
| 203 | if(timer_running()) |
| 204 | { |
| 205 | /* retriggering, but not if we are called to quickly */ |
| 206 | attotime delay_time = attotime_make(0, ATTOSECONDS_PER_SECOND * m_config.m_cap * 220); |
| 207 | |
| 208 | if(attotime_compare(timer_timeelapsed(m_timer), delay_time) >= 0) |
| 209 | { |
| 210 | timer_adjust_oneshot(m_timer, duration, 0); |
| 211 | |
| 212 | if (LOG) logerror("74123 %s: Retriggering pulse. Duration: %f\n", tag(), attotime_to_double(duration)); |
| 213 | } |
| 214 | else |
| 215 | { |
| 216 | if (LOG) logerror("74123 %s: Retriggering failed.\n", tag()); |
| 217 | } |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | /* starting */ |
| 222 | timer_adjust_oneshot(m_timer, duration, 0); |
| 223 | |
| 224 | set_output(); |
| 225 | |
| 226 | if (LOG) logerror("74123 %s: Starting pulse. Duration: %f\n", tag(), attotime_to_double(duration)); |
| 227 | } |
| 182 | 228 | } |
| 183 | 229 | |
| 184 | | /* ----------------------------------------------------------------------- */ |
| 185 | 230 | |
| 186 | | /* device interface */ |
| 231 | WRITE8_DEVICE_HANDLER( ttl74123_a_w ) |
| 232 | { |
| 233 | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 234 | dev->a_w(data); |
| 235 | } |
| 187 | 236 | |
| 188 | | static DEVICE_START( ttl74123 ) |
| 237 | void ttl74123_device::a_w(UINT8 data) |
| 189 | 238 | { |
| 190 | | ttl74123_t *chip = get_safe_token(device); |
| 239 | /* start/regtrigger pulse if B=HI and falling edge on A (while clear is HI) */ |
| 240 | if (!data && m_a && m_b && m_clear) |
| 241 | { |
| 242 | start_pulse(); |
| 243 | } |
| 191 | 244 | |
| 192 | | /* validate arguments */ |
| 193 | | chip->intf = (ttl74123_config *)device->baseconfig().static_config(); |
| 245 | m_a = data; |
| 246 | } |
| 194 | 247 | |
| 195 | | assert_always(chip->intf, "No interface specified"); |
| 196 | | assert_always((chip->intf->connection_type != TTL74123_GROUNDED) || (chip->intf->cap >= CAP_U(0.01)), "Only capacitors >= 0.01uF supported for GROUNDED type"); |
| 197 | | assert_always(chip->intf->cap >= CAP_P(1000), "Only capacitors >= 1000pF supported "); |
| 198 | 248 | |
| 199 | | chip->timer = timer_alloc(device->machine, clear_callback, (void *) device); |
| 249 | WRITE8_DEVICE_HANDLER( ttl74123_b_w ) |
| 250 | { |
| 251 | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 252 | dev->b_w(data); |
| 253 | } |
| 200 | 254 | |
| 201 | | /* start with the defaults */ |
| 202 | | chip->a = chip->intf->a; |
| 203 | | chip->b = chip->intf->b; |
| 204 | | chip->clear = chip->intf->clear; |
| 255 | void ttl74123_device::b_w(UINT8 data) |
| 256 | { |
| 257 | /* start/regtrigger pulse if A=LO and rising edge on B (while clear is HI) */ |
| 258 | if (data && !m_b && !m_a && m_clear) |
| 259 | { |
| 260 | start_pulse(); |
| 261 | } |
| 205 | 262 | |
| 206 | | /* register for state saving */ |
| 207 | | state_save_register_device_item(device, 0, chip->a); |
| 208 | | state_save_register_device_item(device, 0, chip->b); |
| 209 | | state_save_register_device_item(device, 0, chip->clear); |
| 263 | m_b = data; |
| 210 | 264 | } |
| 211 | 265 | |
| 212 | 266 | |
| 213 | | static DEVICE_RESET( ttl74123 ) |
| 267 | WRITE8_DEVICE_HANDLER( ttl74123_clear_w ) |
| 214 | 268 | { |
| 215 | | set_output(device); |
| 269 | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 270 | dev->clear_w(data); |
| 216 | 271 | } |
| 217 | 272 | |
| 218 | | |
| 219 | | DEVICE_GET_INFO( ttl74123 ) |
| 273 | void ttl74123_device::clear_w(UINT8 data) |
| 220 | 274 | { |
| 221 | | switch (state) |
| 222 | | { |
| 223 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 224 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ttl74123_t); break; |
| 225 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 275 | /* start/regtrigger pulse if B=HI and A=LO and rising edge on clear */ |
| 276 | if (data && !m_a && m_b && !m_clear) |
| 277 | { |
| 278 | start_pulse(); |
| 279 | } |
| 280 | else if (!data) /* clear the output */ |
| 281 | { |
| 282 | timer_adjust_oneshot(m_timer, attotime_zero, 0); |
| 226 | 283 | |
| 227 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 228 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ttl74123); break; |
| 229 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 230 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(ttl74123); break; |
| 284 | if (LOG) logerror("74123 #%s: Cleared\n", tag() ); |
| 285 | } |
| 286 | m_clear = data; |
| 287 | } |
| 231 | 288 | |
| 232 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 233 | | case DEVINFO_STR_NAME: strcpy(info->s, "74123"); break; |
| 234 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "TTL"); break; |
| 235 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 236 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 237 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 238 | | } |
| 289 | WRITE8_DEVICE_HANDLER( ttl74123_reset_w ) |
| 290 | { |
| 291 | ttl74123_device *dev = reinterpret_cast<ttl74123_device *>(device); |
| 292 | dev->reset_w(); |
| 239 | 293 | } |
| 240 | 294 | |
| 241 | | DEFINE_LEGACY_DEVICE(TTL74123, ttl74123); |
| 295 | void ttl74123_device::reset_w() |
| 296 | { |
| 297 | set_output(); |
| 298 | } |
| 299 | |
| 300 | const device_type TTL74123 = ttl74123_device_config::static_alloc_device_config; |
src/emu/machine/6821pia.c
| r8885 | r8886 | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | /*************************************************************************** |
| 12 | | TYPE DEFINITIONS |
| 13 | | ***************************************************************************/ |
| 14 | | |
| 15 | | typedef struct _pia6821_state pia6821_state; |
| 16 | | struct _pia6821_state |
| 17 | | { |
| 18 | | devcb_resolved_read8 in_a_func; |
| 19 | | devcb_resolved_read8 in_b_func; |
| 20 | | devcb_resolved_read_line in_ca1_func; |
| 21 | | devcb_resolved_read_line in_cb1_func; |
| 22 | | devcb_resolved_read_line in_ca2_func; |
| 23 | | devcb_resolved_read_line in_cb2_func; |
| 24 | | devcb_resolved_write8 out_a_func; |
| 25 | | devcb_resolved_write8 out_b_func; |
| 26 | | devcb_resolved_write_line out_ca2_func; |
| 27 | | devcb_resolved_write_line out_cb2_func; |
| 28 | | devcb_resolved_write_line irq_a_func; |
| 29 | | devcb_resolved_write_line irq_b_func; |
| 30 | | |
| 31 | | UINT8 in_a; |
| 32 | | UINT8 in_ca1; |
| 33 | | UINT8 in_ca2; |
| 34 | | UINT8 out_a; |
| 35 | | UINT8 out_ca2; |
| 36 | | UINT8 port_a_z_mask; |
| 37 | | UINT8 ddr_a; |
| 38 | | UINT8 ctl_a; |
| 39 | | UINT8 irq_a1; |
| 40 | | UINT8 irq_a2; |
| 41 | | UINT8 irq_a_state; |
| 42 | | |
| 43 | | UINT8 in_b; |
| 44 | | UINT8 in_cb1; |
| 45 | | UINT8 in_cb2; |
| 46 | | UINT8 out_b; |
| 47 | | UINT8 out_cb2; |
| 48 | | UINT8 last_out_cb2_z; |
| 49 | | UINT8 ddr_b; |
| 50 | | UINT8 ctl_b; |
| 51 | | UINT8 irq_b1; |
| 52 | | UINT8 irq_b2; |
| 53 | | UINT8 irq_b_state; |
| 54 | | |
| 55 | | /* variables that indicate if access a line externally - |
| 56 | | used to for logging purposes ONLY */ |
| 57 | | UINT8 in_a_pushed; |
| 58 | | UINT8 out_a_needs_pulled; |
| 59 | | UINT8 in_ca1_pushed; |
| 60 | | UINT8 in_ca2_pushed; |
| 61 | | UINT8 out_ca2_needs_pulled; |
| 62 | | UINT8 in_b_pushed; |
| 63 | | UINT8 out_b_needs_pulled; |
| 64 | | UINT8 in_cb1_pushed; |
| 65 | | UINT8 in_cb2_pushed; |
| 66 | | UINT8 out_cb2_needs_pulled; |
| 67 | | UINT8 logged_port_a_not_connected; |
| 68 | | UINT8 logged_port_b_not_connected; |
| 69 | | UINT8 logged_ca1_not_connected; |
| 70 | | UINT8 logged_ca2_not_connected; |
| 71 | | UINT8 logged_cb1_not_connected; |
| 72 | | UINT8 logged_cb2_not_connected; |
| 73 | | }; |
| 74 | | |
| 75 | | |
| 76 | | /*************************************************************************** |
| 77 | 12 | MACROS |
| 78 | 13 | ***************************************************************************/ |
| 79 | 14 | |
| r8885 | r8886 | |
| 101 | 36 | |
| 102 | 37 | |
| 103 | 38 | /*************************************************************************** |
| 104 | | PROTOTYPES |
| 39 | IMPLEMENTATION |
| 105 | 40 | ***************************************************************************/ |
| 106 | | /*************************************************************************** |
| 107 | | INLINE FUNCTIONS |
| 108 | | ***************************************************************************/ |
| 109 | 41 | |
| 110 | | INLINE pia6821_state *get_token(running_device *device) |
| 42 | //************************************************************************** |
| 43 | // DEVICE CONFIGURATION |
| 44 | //************************************************************************** |
| 45 | |
| 46 | //------------------------------------------------- |
| 47 | // pia6821_device_config - constructor |
| 48 | //------------------------------------------------- |
| 49 | |
| 50 | pia6821_device_config::pia6821_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 51 | : device_config(mconfig, static_alloc_device_config, "PIA6821", tag, owner, clock) |
| 111 | 52 | { |
| 112 | | assert(device != NULL); |
| 113 | | assert((device->type() == PIA6821) || (device->type() == PIA6822)); |
| 114 | | return (pia6821_state *) downcast<legacy_device_base *>(device)->token(); |
| 115 | 53 | } |
| 116 | 54 | |
| 117 | 55 | |
| 118 | | INLINE const pia6821_interface *get_interface(running_device *device) |
| 56 | //------------------------------------------------- |
| 57 | // static_alloc_device_config - allocate a new |
| 58 | // configuration object |
| 59 | //------------------------------------------------- |
| 60 | |
| 61 | device_config *pia6821_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 119 | 62 | { |
| 120 | | assert(device != NULL); |
| 121 | | assert((device->type() == PIA6821) || (device->type() == PIA6822)); |
| 122 | | return (const pia6821_interface *) device->baseconfig().static_config(); |
| 63 | return global_alloc(pia6821_device_config(mconfig, tag, owner, clock)); |
| 123 | 64 | } |
| 124 | 65 | |
| 125 | 66 | |
| 126 | | /*************************************************************************** |
| 127 | | IMPLEMENTATION |
| 128 | | ***************************************************************************/ |
| 67 | //------------------------------------------------- |
| 68 | // alloc_device - allocate a new device object |
| 69 | //------------------------------------------------- |
| 129 | 70 | |
| 130 | | /*------------------------------------------------- |
| 131 | | DEVICE_START( pia6821 ) |
| 132 | | -------------------------------------------------*/ |
| 71 | device_t *pia6821_device_config::alloc_device(running_machine &machine) const |
| 72 | { |
| 73 | return auto_alloc(&machine, pia6821_device(machine, *this)); |
| 74 | } |
| 133 | 75 | |
| 134 | | static DEVICE_START( pia6821 ) |
| 76 | |
| 77 | //------------------------------------------------- |
| 78 | // device_config_complete - perform any |
| 79 | // operations now that the configuration is |
| 80 | // complete |
| 81 | //------------------------------------------------- |
| 82 | |
| 83 | void pia6821_device_config::device_config_complete() |
| 135 | 84 | { |
| 136 | | pia6821_state *p = get_token(device); |
| 137 | | const pia6821_interface *intf = get_interface(device); |
| 138 | 85 | |
| 139 | | /* clear structure */ |
| 140 | | memset(p, 0, sizeof(*p)); |
| 86 | } |
| 141 | 87 | |
| 88 | |
| 89 | |
| 90 | //************************************************************************** |
| 91 | // LIVE DEVICE |
| 92 | //************************************************************************** |
| 93 | |
| 94 | //------------------------------------------------- |
| 95 | // pia6821_device - constructor |
| 96 | //------------------------------------------------- |
| 97 | |
| 98 | pia6821_device::pia6821_device(running_machine &_machine, const pia6821_device_config &config) |
| 99 | : device_t(_machine, config), |
| 100 | m_config(config) |
| 101 | { |
| 102 | |
| 103 | } |
| 104 | |
| 105 | //------------------------------------------------- |
| 106 | // device_start - device-specific startup |
| 107 | //------------------------------------------------- |
| 108 | |
| 109 | void pia6821_device::device_start() |
| 110 | { |
| 142 | 111 | /* resolve callbacks */ |
| 143 | | devcb_resolve_read8(&p->in_a_func, &intf->in_a_func, device); |
| 144 | | devcb_resolve_read8(&p->in_b_func, &intf->in_b_func, device); |
| 145 | | devcb_resolve_read_line(&p->in_ca1_func, &intf->in_ca1_func, device); |
| 146 | | devcb_resolve_read_line(&p->in_cb1_func, &intf->in_cb1_func, device); |
| 147 | | devcb_resolve_read_line(&p->in_ca2_func, &intf->in_ca2_func, device); |
| 148 | | devcb_resolve_read_line(&p->in_cb2_func, &intf->in_cb2_func, device); |
| 149 | | devcb_resolve_write8(&p->out_a_func, &intf->out_a_func, device); |
| 150 | | devcb_resolve_write8(&p->out_b_func, &intf->out_b_func, device); |
| 151 | | devcb_resolve_write_line(&p->out_ca2_func, &intf->out_ca2_func, device); |
| 152 | | devcb_resolve_write_line(&p->out_cb2_func, &intf->out_cb2_func, device); |
| 153 | | devcb_resolve_write_line(&p->irq_a_func, &intf->irq_a_func, device); |
| 154 | | devcb_resolve_write_line(&p->irq_b_func, &intf->irq_b_func, device); |
| 112 | devcb_resolve_read8(&m_in_a_func, &m_config.m_in_a_func, this); |
| 113 | devcb_resolve_read8(&m_in_b_func, &m_config.m_in_b_func, this); |
| 114 | devcb_resolve_read_line(&m_in_ca1_func, &m_config.m_in_ca1_func, this); |
| 115 | devcb_resolve_read_line(&m_in_cb1_func, &m_config.m_in_cb1_func, this); |
| 116 | devcb_resolve_read_line(&m_in_ca2_func, &m_config.m_in_ca2_func, this); |
| 117 | devcb_resolve_read_line(&m_in_cb2_func, &m_config.m_in_cb2_func, this); |
| 118 | devcb_resolve_write8(&m_out_a_func, &m_config.m_out_a_func, this); |
| 119 | devcb_resolve_write8(&m_out_b_func, &m_config.m_out_b_func, this); |
| 120 | devcb_resolve_write_line(&m_out_ca2_func, &m_config.m_out_ca2_func, this); |
| 121 | devcb_resolve_write_line(&m_out_cb2_func, &m_config.m_out_cb2_func, this); |
| 122 | devcb_resolve_write_line(&m_irq_a_func, &m_config.m_irq_a_func, this); |
| 123 | devcb_resolve_write_line(&m_irq_b_func, &m_config.m_irq_b_func, this); |
| 155 | 124 | |
| 156 | | state_save_register_device_item(device, 0, p->in_a); |
| 157 | | state_save_register_device_item(device, 0, p->in_ca1); |
| 158 | | state_save_register_device_item(device, 0, p->in_ca2); |
| 159 | | state_save_register_device_item(device, 0, p->out_a); |
| 160 | | state_save_register_device_item(device, 0, p->out_ca2); |
| 161 | | state_save_register_device_item(device, 0, p->port_a_z_mask); |
| 162 | | state_save_register_device_item(device, 0, p->ddr_a); |
| 163 | | state_save_register_device_item(device, 0, p->ctl_a); |
| 164 | | state_save_register_device_item(device, 0, p->irq_a1); |
| 165 | | state_save_register_device_item(device, 0, p->irq_a2); |
| 166 | | state_save_register_device_item(device, 0, p->irq_a_state); |
| 167 | | state_save_register_device_item(device, 0, p->in_b); |
| 168 | | state_save_register_device_item(device, 0, p->in_cb1); |
| 169 | | state_save_register_device_item(device, 0, p->in_cb2); |
| 170 | | state_save_register_device_item(device, 0, p->out_b); |
| 171 | | state_save_register_device_item(device, 0, p->out_cb2); |
| 172 | | state_save_register_device_item(device, 0, p->last_out_cb2_z); |
| 173 | | state_save_register_device_item(device, 0, p->ddr_b); |
| 174 | | state_save_register_device_item(device, 0, p->ctl_b); |
| 175 | | state_save_register_device_item(device, 0, p->irq_b1); |
| 176 | | state_save_register_device_item(device, 0, p->irq_b2); |
| 177 | | state_save_register_device_item(device, 0, p->irq_b_state); |
| 178 | | state_save_register_device_item(device, 0, p->in_a_pushed); |
| 179 | | state_save_register_device_item(device, 0, p->out_a_needs_pulled); |
| 180 | | state_save_register_device_item(device, 0, p->in_ca1_pushed); |
| 181 | | state_save_register_device_item(device, 0, p->in_ca2_pushed); |
| 182 | | state_save_register_device_item(device, 0, p->out_ca2_needs_pulled); |
| 183 | | state_save_register_device_item(device, 0, p->in_b_pushed); |
| 184 | | state_save_register_device_item(device, 0, p->out_b_needs_pulled); |
| 185 | | state_save_register_device_item(device, 0, p->in_cb1_pushed); |
| 186 | | state_save_register_device_item(device, 0, p->in_cb2_pushed); |
| 187 | | state_save_register_device_item(device, 0, p->out_cb2_needs_pulled); |
| 125 | state_save_register_device_item(this, 0, m_in_a); |
| 126 | state_save_register_device_item(this, 0, m_in_ca1); |
| 127 | state_save_register_device_item(this, 0, m_in_ca2); |
| 128 | state_save_register_device_item(this, 0, m_out_a); |
| 129 | state_save_register_device_item(this, 0, m_out_ca2); |
| 130 | state_save_register_device_item(this, 0, m_port_a_z_mask); |
| 131 | state_save_register_device_item(this, 0, m_ddr_a); |
| 132 | state_save_register_device_item(this, 0, m_ctl_a); |
| 133 | state_save_register_device_item(this, 0, m_irq_a1); |
| 134 | state_save_register_device_item(this, 0, m_irq_a2); |
| 135 | state_save_register_device_item(this, 0, m_irq_a_state); |
| 136 | state_save_register_device_item(this, 0, m_in_b); |
| 137 | state_save_register_device_item(this, 0, m_in_cb1); |
| 138 | state_save_register_device_item(this, 0, m_in_cb2); |
| 139 | state_save_register_device_item(this, 0, m_out_b); |
| 140 | state_save_register_device_item(this, 0, m_out_cb2); |
| 141 | state_save_register_device_item(this, 0, m_last_out_cb2_z); |
| 142 | state_save_register_device_item(this, 0, m_ddr_b); |
| 143 | state_save_register_device_item(this, 0, m_ctl_b); |
| 144 | state_save_register_device_item(this, 0, m_irq_b1); |
| 145 | state_save_register_device_item(this, 0, m_irq_b2); |
| 146 | state_save_register_device_item(this, 0, m_irq_b_state); |
| 147 | state_save_register_device_item(this, 0, m_in_a_pushed); |
| 148 | state_save_register_device_item(this, 0, m_out_a_needs_pulled); |
| 149 | state_save_register_device_item(this, 0, m_in_ca1_pushed); |
| 150 | state_save_register_device_item(this, 0, m_in_ca2_pushed); |
| 151 | state_save_register_device_item(this, 0, m_out_ca2_needs_pulled); |
| 152 | state_save_register_device_item(this, 0, m_in_b_pushed); |
| 153 | state_save_register_device_item(this, 0, m_out_b_needs_pulled); |
| 154 | state_save_register_device_item(this, 0, m_in_cb1_pushed); |
| 155 | state_save_register_device_item(this, 0, m_in_cb2_pushed); |
| 156 | state_save_register_device_item(this, 0, m_out_cb2_needs_pulled); |
| 188 | 157 | } |
| 189 | 158 | |
| 190 | 159 | |
| 191 | | /*------------------------------------------------- |
| 192 | | DEVICE_RESET( pia6821 ) |
| 193 | | -------------------------------------------------*/ |
| 160 | //------------------------------------------------- |
| 161 | // device_reset - device-specific reset |
| 162 | //------------------------------------------------- |
| 194 | 163 | |
| 195 | | static DEVICE_RESET( pia6821 ) |
| 164 | void pia6821_device::device_reset() |
| 196 | 165 | { |
| 197 | | pia6821_state *p = get_token(device); |
| 198 | | |
| 199 | 166 | /* |
| 200 | 167 | * set default read values. |
| 201 | 168 | * |
| 202 | 169 | * ports A,CA1,CA2 default to 1 |
| 203 | 170 | * ports B,CB1,CB2 are three-state and undefined (set to 0) |
| 204 | 171 | */ |
| 205 | | p->in_a = 0xff; |
| 206 | | p->in_ca1 = TRUE; |
| 207 | | p->in_ca2 = TRUE; |
| 208 | | p->out_a = 0; |
| 209 | | p->out_ca2 = 0; |
| 210 | | p->port_a_z_mask = 0; |
| 211 | | p->ddr_a = 0; |
| 212 | | p->ctl_a = 0; |
| 213 | | p->irq_a1 = 0; |
| 214 | | p->irq_a2 = 0; |
| 215 | | p->irq_a_state = 0; |
| 216 | | p->in_b = 0; |
| 217 | | p->in_cb1 = 0; |
| 218 | | p->in_cb2 = 0; |
| 219 | | p->out_b = 0; |
| 220 | | p->out_cb2 = 0; |
| 221 | | p->last_out_cb2_z = 0; |
| 222 | | p->ddr_b = 0; |
| 223 | | p->ctl_b = 0; |
| 224 | | p->irq_b1 = 0; |
| 225 | | p->irq_b2 = 0; |
| 226 | | p->irq_b_state = 0; |
| 227 | | p->in_a_pushed = 0; |
| 228 | | p->out_a_needs_pulled = 0; |
| 229 | | p->in_ca1_pushed = 0; |
| 230 | | p->in_ca2_pushed = 0; |
| 231 | | p->out_ca2_needs_pulled = 0; |
| 232 | | p->in_b_pushed = 0; |
| 233 | | p->out_b_needs_pulled = 0; |
| 234 | | p->in_cb1_pushed = 0; |
| 235 | | p->in_cb2_pushed = 0; |
| 236 | | p->out_cb2_needs_pulled = 0; |
| 237 | | p->logged_port_a_not_connected = 0; |
| 238 | | p->logged_port_b_not_connected = 0; |
| 239 | | p->logged_ca1_not_connected = 0; |
| 240 | | p->logged_ca2_not_connected = 0; |
| 241 | | p->logged_cb1_not_connected = 0; |
| 242 | | p->logged_cb2_not_connected = 0; |
| 172 | m_in_a = 0xff; |
| 173 | m_in_ca1 = TRUE; |
| 174 | m_in_ca2 = TRUE; |
| 175 | m_out_a = 0; |
| 176 | m_out_ca2 = 0; |
| 177 | m_port_a_z_mask = 0; |
| 178 | m_ddr_a = 0; |
| 179 | m_ctl_a = 0; |
| 180 | m_irq_a1 = 0; |
| 181 | m_irq_a2 = 0; |
| 182 | m_irq_a_state = 0; |
| 183 | m_in_b = 0; |
| 184 | m_in_cb1 = 0; |
| 185 | m_in_cb2 = 0; |
| 186 | m_out_b = 0; |
| 187 | m_out_cb2 = 0; |
| 188 | m_last_out_cb2_z = 0; |
| 189 | m_ddr_b = 0; |
| 190 | m_ctl_b = 0; |
| 191 | m_irq_b1 = 0; |
| 192 | m_irq_b2 = 0; |
| 193 | m_irq_b_state = 0; |
| 194 | m_in_a_pushed = 0; |
| 195 | m_out_a_needs_pulled = 0; |
| 196 | m_in_ca1_pushed = 0; |
| 197 | m_in_ca2_pushed = 0; |
| 198 | m_out_ca2_needs_pulled = 0; |
| 199 | m_in_b_pushed = 0; |
| 200 | m_out_b_needs_pulled = 0; |
| 201 | m_in_cb1_pushed = 0; |
| 202 | m_in_cb2_pushed = 0; |
| 203 | m_out_cb2_needs_pulled = 0; |
| 204 | m_logged_port_a_not_connected = 0; |
| 205 | m_logged_port_b_not_connected = 0; |
| 206 | m_logged_ca1_not_connected = 0; |
| 207 | m_logged_ca2_not_connected = 0; |
| 208 | m_logged_cb1_not_connected = 0; |
| 209 | m_logged_cb2_not_connected = 0; |
| 243 | 210 | |
| 244 | 211 | |
| 245 | 212 | /* clear the IRQs */ |
| 246 | | devcb_call_write_line(&p->irq_a_func, FALSE); |
| 247 | | devcb_call_write_line(&p->irq_b_func, FALSE); |
| 213 | devcb_call_write_line(&m_irq_a_func, FALSE); |
| 214 | devcb_call_write_line(&m_irq_b_func, FALSE); |
| 248 | 215 | } |
| 249 | 216 | |
| 250 | 217 | |
| r8885 | r8886 | |
| 252 | 219 | update_interrupts |
| 253 | 220 | -------------------------------------------------*/ |
| 254 | 221 | |
| 255 | | static void update_interrupts(running_device *device) |
| 222 | void pia6821_device::update_interrupts() |
| 256 | 223 | { |
| 257 | | pia6821_state *p = get_token(device); |
| 258 | | int new_state; |
| 224 | /* start with IRQ A */ |
| 225 | int new_state = (m_irq_a1 && IRQ1_ENABLED(m_ctl_a)) || (m_irq_a2 && IRQ2_ENABLED(m_ctl_a)); |
| 259 | 226 | |
| 260 | | /* start with IRQ A */ |
| 261 | | new_state = (p->irq_a1 && IRQ1_ENABLED(p->ctl_a)) || (p->irq_a2 && IRQ2_ENABLED(p->ctl_a)); |
| 262 | | |
| 263 | | if (new_state != p->irq_a_state) |
| 227 | if (new_state != m_irq_a_state) |
| 264 | 228 | { |
| 265 | | p->irq_a_state = new_state; |
| 266 | | devcb_call_write_line(&p->irq_a_func, p->irq_a_state); |
| 229 | m_irq_a_state = new_state; |
| 230 | devcb_call_write_line(&m_irq_a_func, m_irq_a_state); |
| 267 | 231 | } |
| 268 | 232 | |
| 269 | 233 | /* then do IRQ B */ |
| 270 | | new_state = (p->irq_b1 && IRQ1_ENABLED(p->ctl_b)) || (p->irq_b2 && IRQ2_ENABLED(p->ctl_b)); |
| 234 | new_state = (m_irq_b1 && IRQ1_ENABLED(m_ctl_b)) || (m_irq_b2 && IRQ2_ENABLED(m_ctl_b)); |
| 271 | 235 | |
| 272 | | if (new_state != p->irq_b_state) |
| 236 | if (new_state != m_irq_b_state) |
| 273 | 237 | { |
| 274 | | p->irq_b_state = new_state; |
| 275 | | devcb_call_write_line(&p->irq_b_func, p->irq_b_state); |
| 238 | m_irq_b_state = new_state; |
| 239 | devcb_call_write_line(&m_irq_b_func, m_irq_b_state); |
| 276 | 240 | } |
| 277 | 241 | } |
| 278 | 242 | |
| r8885 | r8886 | |
| 281 | 245 | get_in_a_value |
| 282 | 246 | -------------------------------------------------*/ |
| 283 | 247 | |
| 284 | | static UINT8 get_in_a_value(running_device *device) |
| 248 | UINT8 pia6821_device::get_in_a_value() |
| 285 | 249 | { |
| 286 | | pia6821_state *p = get_token(device); |
| 287 | 250 | UINT8 port_a_data = 0; |
| 288 | 251 | UINT8 ret; |
| 289 | 252 | |
| 290 | 253 | /* update the input */ |
| 291 | | if (p->in_a_func.read != NULL) |
| 292 | | port_a_data = devcb_call_read8(&p->in_a_func, 0); |
| 254 | if (m_in_a_func.read != NULL) |
| 255 | { |
| 256 | port_a_data = devcb_call_read8(&m_in_a_func, 0); |
| 257 | } |
| 293 | 258 | else |
| 294 | 259 | { |
| 295 | | if (p->in_a_pushed) |
| 296 | | port_a_data = p->in_a; |
| 260 | if (m_in_a_pushed) |
| 261 | { |
| 262 | port_a_data = m_in_a; |
| 263 | } |
| 297 | 264 | else |
| 298 | 265 | { |
| 299 | 266 | /* mark all pins disconnected */ |
| 300 | | p->port_a_z_mask = 0xff; |
| 267 | m_port_a_z_mask = 0xff; |
| 301 | 268 | |
| 302 | | if (!p->logged_port_a_not_connected && (p->ddr_a != 0xff)) |
| 269 | if (!m_logged_port_a_not_connected && (m_ddr_a != 0xff)) |
| 303 | 270 | { |
| 304 | | logerror("PIA #%s: Warning! No port A read handler. Assuming pins 0x%02X not connected\n", device->tag(), p->ddr_a ^ 0xff); |
| 305 | | p->logged_port_a_not_connected = TRUE; |
| 271 | logerror("PIA #%s: Warning! No port A read handler. Assuming pins 0x%02X not connected\n", tag(), m_ddr_a ^ 0xff); |
| 272 | m_logged_port_a_not_connected = TRUE; |
| 306 | 273 | } |
| 307 | 274 | } |
| 308 | 275 | } |
| r8885 | r8886 | |
| 310 | 277 | /* - connected pins are always read |
| 311 | 278 | - disconnected pins read the output buffer in output mode |
| 312 | 279 | - disconnected pins are HI in input mode */ |
| 313 | | ret = (~p->port_a_z_mask & port_a_data) | |
| 314 | | ( p->port_a_z_mask & p->ddr_a & p->out_a) | |
| 315 | | ( p->port_a_z_mask & ~p->ddr_a); |
| 280 | ret = (~m_port_a_z_mask & port_a_data) | |
| 281 | ( m_port_a_z_mask & m_ddr_a & m_out_a) | |
| 282 | ( m_port_a_z_mask & ~m_ddr_a); |
| 316 | 283 | |
| 317 | 284 | return ret; |
| 318 | 285 | } |
| r8885 | r8886 | |
| 322 | 289 | get_in_b_value |
| 323 | 290 | -------------------------------------------------*/ |
| 324 | 291 | |
| 325 | | static UINT8 get_in_b_value(running_device *device) |
| 292 | UINT8 pia6821_device::get_in_b_value() |
| 326 | 293 | { |
| 327 | | pia6821_state *p = get_token(device); |
| 328 | 294 | UINT8 ret; |
| 329 | 295 | |
| 330 | | if (p->ddr_b == 0xff) |
| 296 | if (m_ddr_b == 0xff) |
| 297 | { |
| 331 | 298 | /* all output, just return buffer */ |
| 332 | | ret = p->out_b; |
| 299 | ret = m_out_b; |
| 300 | } |
| 333 | 301 | else |
| 334 | 302 | { |
| 335 | 303 | UINT8 port_b_data; |
| 336 | 304 | |
| 337 | 305 | /* update the input */ |
| 338 | | if (p->in_b_func.read != NULL) |
| 339 | | port_b_data = devcb_call_read8(&p->in_b_func, 0); |
| 306 | if (m_in_b_func.read != NULL) |
| 307 | { |
| 308 | port_b_data = devcb_call_read8(&m_in_b_func, 0); |
| 309 | } |
| 340 | 310 | else |
| 341 | 311 | { |
| 342 | | if (p->in_b_pushed) |
| 343 | | port_b_data = p->in_b; |
| 312 | if (m_in_b_pushed) |
| 313 | { |
| 314 | port_b_data = m_in_b; |
| 315 | } |
| 344 | 316 | else |
| 345 | 317 | { |
| 346 | | if (!p->logged_port_b_not_connected && (p->ddr_b != 0xff)) |
| 318 | if (!m_logged_port_b_not_connected && (m_ddr_b != 0xff)) |
| 347 | 319 | { |
| 348 | | logerror("PIA #%s: Error! No port B read handler. Three-state pins 0x%02X are undefined\n", device->tag(), p->ddr_b ^ 0xff); |
| 349 | | p->logged_port_b_not_connected = TRUE; |
| 320 | logerror("PIA #%s: Error! No port B read handler. Three-state pins 0x%02X are undefined\n", tag(), m_ddr_b ^ 0xff); |
| 321 | m_logged_port_b_not_connected = TRUE; |
| 350 | 322 | } |
| 351 | 323 | |
| 352 | 324 | /* undefined -- need to return something */ |
| r8885 | r8886 | |
| 355 | 327 | } |
| 356 | 328 | |
| 357 | 329 | /* the DDR determines if the pin or the output buffer is read */ |
| 358 | | ret = (p->out_b & p->ddr_b) | (port_b_data & ~p->ddr_b); |
| 330 | ret = (m_out_b & m_ddr_b) | (port_b_data & ~m_ddr_b); |
| 359 | 331 | } |
| 360 | 332 | |
| 361 | 333 | return ret; |
| r8885 | r8886 | |
| 366 | 338 | get_out_a_value |
| 367 | 339 | -------------------------------------------------*/ |
| 368 | 340 | |
| 369 | | static UINT8 get_out_a_value(running_device *device) |
| 341 | UINT8 pia6821_device::get_out_a_value() |
| 370 | 342 | { |
| 371 | | pia6821_state *p = get_token(device); |
| 372 | 343 | UINT8 ret; |
| 373 | 344 | |
| 374 | | if (p->ddr_a == 0xff) |
| 345 | if (m_ddr_a == 0xff) |
| 346 | { |
| 375 | 347 | /* all output */ |
| 376 | | ret = p->out_a; |
| 348 | ret = m_out_a; |
| 349 | } |
| 377 | 350 | else |
| 351 | { |
| 378 | 352 | /* input pins don't change */ |
| 379 | | ret = (p->out_a & p->ddr_a) | (get_in_a_value(device) & ~p->ddr_a); |
| 353 | ret = (m_out_a & m_ddr_a) | (get_in_a_value() & ~m_ddr_a); |
| 354 | } |
| 380 | 355 | |
| 381 | 356 | return ret; |
| 382 | 357 | } |
| r8885 | r8886 | |
| 386 | 361 | get_out_b_value |
| 387 | 362 | -------------------------------------------------*/ |
| 388 | 363 | |
| 389 | | static UINT8 get_out_b_value(running_device *device) |
| 364 | UINT8 pia6821_device::get_out_b_value() |
| 390 | 365 | { |
| 391 | | pia6821_state *p = get_token(device); |
| 392 | | |
| 393 | 366 | /* input pins are high-impedance - we just send them as zeros for backwards compatibility */ |
| 394 | | return p->out_b & p->ddr_b; |
| 367 | return m_out_b & m_ddr_b; |
| 395 | 368 | } |
| 396 | 369 | |
| 397 | 370 | |
| r8885 | r8886 | |
| 399 | 372 | set_out_ca2 |
| 400 | 373 | -------------------------------------------------*/ |
| 401 | 374 | |
| 402 | | static void set_out_ca2(running_device *device, int data) |
| 375 | void pia6821_device::set_out_ca2(int data) |
| 403 | 376 | { |
| 404 | | pia6821_state *p = get_token(device); |
| 405 | | |
| 406 | | if (data != p->out_ca2) |
| 377 | if (data != m_out_ca2) |
| 407 | 378 | { |
| 408 | | p->out_ca2 = data; |
| 379 | m_out_ca2 = data; |
| 409 | 380 | |
| 410 | 381 | /* send to output function */ |
| 411 | | if (p->out_ca2_func.write) |
| 412 | | devcb_call_write_line(&p->out_ca2_func, p->out_ca2); |
| 382 | if (m_out_ca2_func.write) |
| 383 | { |
| 384 | devcb_call_write_line(&m_out_ca2_func, m_out_ca2); |
| 385 | } |
| 413 | 386 | else |
| 414 | 387 | { |
| 415 | | if (p->out_ca2_needs_pulled) |
| 416 | | logerror("PIA #%s: Warning! No port CA2 write handler. Previous value has been lost!\n", device->tag()); |
| 388 | if (m_out_ca2_needs_pulled) |
| 389 | { |
| 390 | logerror("PIA #%s: Warning! No port CA2 write handler. Previous value has been lost!\n", tag()); |
| 391 | } |
| 417 | 392 | |
| 418 | | p->out_ca2_needs_pulled = TRUE; |
| 393 | m_out_ca2_needs_pulled = TRUE; |
| 419 | 394 | } |
| 420 | 395 | } |
| 421 | 396 | } |
| r8885 | r8886 | |
| 425 | 400 | set_out_cb2 |
| 426 | 401 | -------------------------------------------------*/ |
| 427 | 402 | |
| 428 | | static void set_out_cb2(running_device *device, int data) |
| 403 | void pia6821_device::set_out_cb2(int data) |
| 429 | 404 | { |
| 430 | | pia6821_state *p = get_token(device); |
| 405 | int z = pia6821_get_output_cb2_z(this); |
| 431 | 406 | |
| 432 | | int z = pia6821_get_output_cb2_z(device); |
| 433 | | |
| 434 | | if ((data != p->out_cb2) || (z != p->last_out_cb2_z)) |
| 407 | if ((data != m_out_cb2) || (z != m_last_out_cb2_z)) |
| 435 | 408 | { |
| 436 | | p->out_cb2 = data; |
| 437 | | p->last_out_cb2_z = z; |
| 409 | m_out_cb2 = data; |
| 410 | m_last_out_cb2_z = z; |
| 438 | 411 | |
| 439 | 412 | /* send to output function */ |
| 440 | | if (p->out_cb2_func.write) |
| 441 | | devcb_call_write_line(&p->out_cb2_func, p->out_cb2); |
| 413 | if (m_out_cb2_func.write) |
| 414 | { |
| 415 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 416 | } |
| 442 | 417 | else |
| 443 | 418 | { |
| 444 | | if (p->out_cb2_needs_pulled) |
| 445 | | logerror("PIA #%s: Warning! No port CB2 write handler. Previous value has been lost!\n", device->tag()); |
| 419 | if (m_out_cb2_needs_pulled) |
| 420 | { |
| 421 | logerror("PIA #%s: Warning! No port CB2 write handler. Previous value has been lost!\n", tag()); |
| 422 | } |
| 446 | 423 | |
| 447 | | p->out_cb2_needs_pulled = TRUE; |
| 424 | m_out_cb2_needs_pulled = TRUE; |
| 448 | 425 | } |
| 449 | 426 | } |
| 450 | 427 | } |
| r8885 | r8886 | |
| 454 | 431 | port_a_r |
| 455 | 432 | -------------------------------------------------*/ |
| 456 | 433 | |
| 457 | | static UINT8 port_a_r(running_device *device) |
| 434 | UINT8 pia6821_device::port_a_r() |
| 458 | 435 | { |
| 459 | | pia6821_state *p = get_token(device); |
| 436 | UINT8 ret = get_in_a_value(); |
| 460 | 437 | |
| 461 | | UINT8 ret = get_in_a_value(device); |
| 462 | | |
| 463 | 438 | /* IRQ flags implicitly cleared by a read */ |
| 464 | | p->irq_a1 = FALSE; |
| 465 | | p->irq_a2 = FALSE; |
| 466 | | update_interrupts(device); |
| 439 | m_irq_a1 = FALSE; |
| 440 | m_irq_a2 = FALSE; |
| 441 | update_interrupts(); |
| 467 | 442 | |
| 468 | 443 | /* CA2 is configured as output and in read strobe mode */ |
| 469 | | if (C2_OUTPUT(p->ctl_a) && C2_STROBE_MODE(p->ctl_a)) |
| 444 | if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a)) |
| 470 | 445 | { |
| 471 | 446 | /* this will cause a transition low */ |
| 472 | | set_out_ca2(device, FALSE); |
| 447 | set_out_ca2(FALSE); |
| 473 | 448 | |
| 474 | 449 | /* if the CA2 strobe is cleared by the E, reset it right away */ |
| 475 | | if (STROBE_E_RESET(p->ctl_a)) |
| 476 | | set_out_ca2(device, TRUE); |
| 450 | if(STROBE_E_RESET(m_ctl_a)) |
| 451 | { |
| 452 | set_out_ca2(TRUE); |
| 453 | } |
| 477 | 454 | } |
| 478 | 455 | |
| 479 | | LOG(("PIA #%s: port A read = %02X\n", device->tag(), ret)); |
| 456 | LOG(("PIA #%s: port A read = %02X\n", tag(), ret)); |
| 480 | 457 | |
| 481 | 458 | return ret; |
| 482 | 459 | } |
| r8885 | r8886 | |
| 486 | 463 | ddr_a_r |
| 487 | 464 | -------------------------------------------------*/ |
| 488 | 465 | |
| 489 | | static UINT8 ddr_a_r(running_device *device) |
| 466 | UINT8 pia6821_device::ddr_a_r() |
| 490 | 467 | { |
| 491 | | pia6821_state *p = get_token(device); |
| 468 | UINT8 ret = m_ddr_a; |
| 492 | 469 | |
| 493 | | UINT8 ret = p->ddr_a; |
| 470 | LOG(("PIA #%s: DDR A read = %02X\n", tag(), ret)); |
| 494 | 471 | |
| 495 | | LOG(("PIA #%s: DDR A read = %02X\n", device->tag(), ret)); |
| 496 | | |
| 497 | 472 | return ret; |
| 498 | 473 | } |
| 499 | 474 | |
| r8885 | r8886 | |
| 502 | 477 | port_b_r |
| 503 | 478 | -------------------------------------------------*/ |
| 504 | 479 | |
| 505 | | static UINT8 port_b_r(running_device *device) |
| 480 | UINT8 pia6821_device::port_b_r() |
| 506 | 481 | { |
| 507 | | pia6821_state *p = get_token(device); |
| 482 | UINT8 ret = get_in_b_value(); |
| 508 | 483 | |
| 509 | | UINT8 ret = get_in_b_value(device); |
| 510 | | |
| 511 | 484 | /* This read will implicitly clear the IRQ B1 flag. If CB2 is in write-strobe |
| 512 | 485 | mode with CB1 restore, and a CB1 active transition set the flag, |
| 513 | 486 | clearing it will cause CB2 to go high again. Note that this is different |
| 514 | 487 | from what happens with port A. */ |
| 515 | | if (p->irq_b1 && C2_STROBE_MODE(p->ctl_b) && STROBE_C1_RESET(p->ctl_b)) |
| 516 | | set_out_cb2(device, TRUE); |
| 488 | if(m_irq_b1 && C2_STROBE_MODE(m_ctl_b) && STROBE_C1_RESET(m_ctl_b)) |
| 489 | { |
| 490 | set_out_cb2(TRUE); |
| 491 | } |
| 517 | 492 | |
| 518 | 493 | /* IRQ flags implicitly cleared by a read */ |
| 519 | | p->irq_b1 = FALSE; |
| 520 | | p->irq_b2 = FALSE; |
| 521 | | update_interrupts(device); |
| 494 | m_irq_b1 = FALSE; |
| 495 | m_irq_b2 = FALSE; |
| 496 | update_interrupts(); |
| 522 | 497 | |
| 523 | | LOG(("PIA #%s: port B read = %02X\n", device->tag(), ret)); |
| 498 | LOG(("PIA #%s: port B read = %02X\n", tag(), ret)); |
| 524 | 499 | |
| 525 | 500 | return ret; |
| 526 | 501 | } |
| r8885 | r8886 | |
| 530 | 505 | ddr_b_r |
| 531 | 506 | -------------------------------------------------*/ |
| 532 | 507 | |
| 533 | | static UINT8 ddr_b_r(running_device *device) |
| 508 | UINT8 pia6821_device::ddr_b_r() |
| 534 | 509 | { |
| 535 | | pia6821_state *p = get_token(device); |
| 510 | UINT8 ret = m_ddr_b; |
| 536 | 511 | |
| 537 | | UINT8 ret = p->ddr_b; |
| 512 | LOG(("PIA #%s: DDR B read = %02X\n", tag(), ret)); |
| 538 | 513 | |
| 539 | | LOG(("PIA #%s: DDR B read = %02X\n", device->tag(), ret)); |
| 540 | | |
| 541 | 514 | return ret; |
| 542 | 515 | } |
| 543 | 516 | |
| r8885 | r8886 | |
| 546 | 519 | control_a_r |
| 547 | 520 | -------------------------------------------------*/ |
| 548 | 521 | |
| 549 | | static UINT8 control_a_r(running_device *device) |
| 522 | UINT8 pia6821_device::control_a_r() |
| 550 | 523 | { |
| 551 | | pia6821_state *p = get_token(device); |
| 552 | 524 | UINT8 ret; |
| 553 | 525 | |
| 554 | 526 | /* update CA1 & CA2 if callback exists, these in turn may update IRQ's */ |
| 555 | | if (p->in_ca1_func.read != NULL) |
| 556 | | pia6821_ca1_w(device, devcb_call_read_line(&p->in_ca1_func)); |
| 557 | | else if (!p->logged_ca1_not_connected && (!p->in_ca1_pushed)) |
| 527 | if (m_in_ca1_func.read != NULL) |
| 528 | { |
| 529 | ca1_w(devcb_call_read_line(&m_in_ca1_func)); |
| 530 | } |
| 531 | else if(!m_logged_ca1_not_connected && (!m_in_ca1_pushed)) |
| 558 | 532 | { |
| 559 | | logerror("PIA #%s: Warning! No CA1 read handler. Assuming pin not connected\n", device->tag()); |
| 560 | | p->logged_ca1_not_connected = TRUE; |
| 533 | logerror("PIA #%s: Warning! No CA1 read handler. Assuming pin not connected\n", tag()); |
| 534 | m_logged_ca1_not_connected = TRUE; |
| 561 | 535 | } |
| 562 | 536 | |
| 563 | | if (p->in_ca2_func.read != NULL) |
| 564 | | pia6821_ca2_w(device, devcb_call_read_line(&p->in_ca2_func)); |
| 565 | | else if ( !p->logged_ca2_not_connected && C2_INPUT(p->ctl_a) && !p->in_ca2_pushed) |
| 537 | if (m_in_ca2_func.read != NULL) |
| 538 | { |
| 539 | ca2_w(devcb_call_read_line(&m_in_ca2_func)); |
| 540 | } |
| 541 | else if ( !m_logged_ca2_not_connected && C2_INPUT(m_ctl_a) && !m_in_ca2_pushed) |
| 566 | 542 | { |
| 567 | | logerror("PIA #%s: Warning! No CA2 read handler. Assuming pin not connected\n", device->tag()); |
| 568 | | p->logged_ca2_not_connected = TRUE; |
| 543 | logerror("PIA #%s: Warning! No CA2 read handler. Assuming pin not connected\n", tag()); |
| 544 | m_logged_ca2_not_connected = TRUE; |
| 569 | 545 | } |
| 570 | 546 | |
| 571 | 547 | /* read control register */ |
| 572 | | ret = p->ctl_a; |
| 548 | ret = m_ctl_a; |
| 573 | 549 | |
| 574 | 550 | /* set the IRQ flags if we have pending IRQs */ |
| 575 | | if (p->irq_a1) |
| 551 | if(m_irq_a1) |
| 552 | { |
| 576 | 553 | ret |= PIA_IRQ1; |
| 554 | } |
| 577 | 555 | |
| 578 | | if (p->irq_a2 && C2_INPUT(p->ctl_a)) |
| 556 | if(m_irq_a2 && C2_INPUT(m_ctl_a)) |
| 557 | { |
| 579 | 558 | ret |= PIA_IRQ2; |
| 559 | } |
| 580 | 560 | |
| 581 | | LOG(("PIA #%s: control A read = %02X\n", device->tag(), ret)); |
| 561 | LOG(("PIA #%s: control A read = %02X\n", tag(), ret)); |
| 582 | 562 | |
| 583 | 563 | return ret; |
| 584 | 564 | } |
| r8885 | r8886 | |
| 588 | 568 | control_b_r |
| 589 | 569 | -------------------------------------------------*/ |
| 590 | 570 | |
| 591 | | static UINT8 control_b_r(running_device *device) |
| 571 | UINT8 pia6821_device::control_b_r() |
| 592 | 572 | { |
| 593 | | pia6821_state *p = get_token(device); |
| 594 | 573 | UINT8 ret; |
| 595 | 574 | |
| 596 | 575 | /* update CB1 & CB2 if callback exists, these in turn may update IRQ's */ |
| 597 | | if (p->in_cb1_func.read != NULL) |
| 598 | | pia6821_cb1_w(device, devcb_call_read_line(&p->in_cb1_func)); |
| 599 | | else if (!p->logged_cb1_not_connected && !p->in_cb1_pushed) |
| 576 | if(m_in_cb1_func.read != NULL) |
| 577 | { |
| 578 | cb1_w(devcb_call_read_line(&m_in_cb1_func)); |
| 579 | } |
| 580 | else if(!m_logged_cb1_not_connected && !m_in_cb1_pushed) |
| 600 | 581 | { |
| 601 | | logerror("PIA #%s: Error! no CB1 read handler. Three-state pin is undefined\n", device->tag()); |
| 602 | | p->logged_cb1_not_connected = TRUE; |
| 582 | logerror("PIA #%s: Error! no CB1 read handler. Three-state pin is undefined\n", tag()); |
| 583 | m_logged_cb1_not_connected = TRUE; |
| 603 | 584 | } |
| 604 | 585 | |
| 605 | | if (p->in_cb2_func.read != NULL) |
| 606 | | pia6821_cb2_w(device, devcb_call_read_line(&p->in_cb2_func)); |
| 607 | | else if (!p->logged_cb2_not_connected && C2_INPUT(p->ctl_b) && !p->in_cb2_pushed) |
| 586 | if(m_in_cb2_func.read != NULL) |
| 587 | { |
| 588 | cb2_w(devcb_call_read_line(&m_in_cb2_func)); |
| 589 | } |
| 590 | else if(!m_logged_cb2_not_connected && C2_INPUT(m_ctl_b) && !m_in_cb2_pushed) |
| 608 | 591 | { |
| 609 | | logerror("PIA #%s: Error! No CB2 read handler. Three-state pin is undefined\n", device->tag()); |
| 610 | | p->logged_cb2_not_connected = TRUE; |
| 592 | logerror("PIA #%s: Error! No CB2 read handler. Three-state pin is undefined\n", tag()); |
| 593 | m_logged_cb2_not_connected = TRUE; |
| 611 | 594 | } |
| 612 | 595 | |
| 613 | 596 | /* read control register */ |
| 614 | | ret = p->ctl_b; |
| 597 | ret = m_ctl_b; |
| 615 | 598 | |
| 616 | 599 | /* set the IRQ flags if we have pending IRQs */ |
| 617 | | if (p->irq_b1) |
| 600 | if(m_irq_b1) |
| 601 | { |
| 618 | 602 | ret |= PIA_IRQ1; |
| 603 | } |
| 619 | 604 | |
| 620 | | if (p->irq_b2 && C2_INPUT(p->ctl_b)) |
| 605 | if(m_irq_b2 && C2_INPUT(m_ctl_b)) |
| 606 | { |
| 621 | 607 | ret |= PIA_IRQ2; |
| 608 | } |
| 622 | 609 | |
| 623 | | LOG(("PIA #%s: control B read = %02X\n", device->tag(), ret)); |
| 610 | LOG(("PIA #%s: control B read = %02X\n", tag(), ret)); |
| 624 | 611 | |
| 625 | 612 | return ret; |
| 626 | 613 | } |
| r8885 | r8886 | |
| 632 | 619 | |
| 633 | 620 | READ8_DEVICE_HANDLER( pia6821_r ) |
| 634 | 621 | { |
| 635 | | pia6821_state *p = get_token(device); |
| 622 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 623 | return dev->reg_r(offset); |
| 624 | } |
| 625 | |
| 626 | UINT8 pia6821_device::reg_r(UINT8 offset) |
| 627 | { |
| 636 | 628 | UINT8 ret; |
| 637 | 629 | |
| 638 | 630 | switch (offset & 0x03) |
| 639 | 631 | { |
| 640 | 632 | default: /* impossible */ |
| 641 | 633 | case 0x00: |
| 642 | | if (OUTPUT_SELECTED(p->ctl_a)) |
| 643 | | ret = port_a_r(device); |
| 634 | if (OUTPUT_SELECTED(m_ctl_a)) |
| 635 | { |
| 636 | ret = port_a_r(); |
| 637 | } |
| 644 | 638 | else |
| 645 | | ret = ddr_a_r(device); |
| 639 | { |
| 640 | ret = ddr_a_r(); |
| 641 | } |
| 646 | 642 | break; |
| 647 | 643 | |
| 648 | 644 | case 0x01: |
| 649 | | ret = control_a_r(device); |
| 645 | ret = control_a_r(); |
| 650 | 646 | break; |
| 651 | 647 | |
| 652 | 648 | case 0x02: |
| 653 | | if (OUTPUT_SELECTED(p->ctl_b)) |
| 654 | | ret = port_b_r(device); |
| 649 | if (OUTPUT_SELECTED(m_ctl_b)) |
| 650 | { |
| 651 | ret = port_b_r(); |
| 652 | } |
| 655 | 653 | else |
| 656 | | ret = ddr_b_r(device); |
| 654 | { |
| 655 | ret = ddr_b_r(); |
| 656 | } |
| 657 | 657 | break; |
| 658 | 658 | |
| 659 | 659 | case 0x03: |
| 660 | | ret = control_b_r(device); |
| 660 | ret = control_b_r(); |
| 661 | 661 | break; |
| 662 | 662 | } |
| 663 | 663 | |
| r8885 | r8886 | |
| 671 | 671 | |
| 672 | 672 | READ8_DEVICE_HANDLER( pia6821_alt_r ) |
| 673 | 673 | { |
| 674 | | return pia6821_r(device, ((offset << 1) & 0x02) | ((offset >> 1) & 0x01)); |
| 674 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 675 | return dev->reg_r(((offset << 1) & 0x02) | ((offset >> 1) & 0x01)); |
| 675 | 676 | } |
| 676 | 677 | |
| 677 | 678 | |
| 679 | |
| 678 | 680 | /*------------------------------------------------- |
| 679 | 681 | pia6821_get_port_b_z_mask |
| 680 | 682 | -------------------------------------------------*/ |
| 681 | 683 | |
| 682 | 684 | UINT8 pia6821_get_port_b_z_mask(running_device *device) |
| 683 | 685 | { |
| 684 | | pia6821_state *p = get_token(device); |
| 685 | | return ~p->ddr_b; |
| 686 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 687 | return dev->get_port_b_z_mask(); |
| 686 | 688 | } |
| 687 | 689 | |
| 690 | UINT8 pia6821_device::get_port_b_z_mask() |
| 691 | { |
| 692 | return ~m_ddr_b; |
| 693 | } |
| 688 | 694 | |
| 695 | |
| 689 | 696 | /*------------------------------------------------- |
| 690 | 697 | send_to_out_a_func |
| 691 | 698 | -------------------------------------------------*/ |
| 692 | 699 | |
| 693 | | static void send_to_out_a_func(running_device *device, const char* message) |
| 700 | void pia6821_device::send_to_out_a_func(const char* message) |
| 694 | 701 | { |
| 695 | | pia6821_state *p = get_token(device); |
| 696 | | |
| 697 | 702 | /* input pins are pulled high */ |
| 698 | | UINT8 data = get_out_a_value(device); |
| 703 | UINT8 data = get_out_a_value(); |
| 699 | 704 | |
| 700 | | LOG(("PIA #%s: %s = %02X\n", device->tag(), message, data)); |
| 705 | LOG(("PIA #%s: %s = %02X\n", tag(), message, data)); |
| 701 | 706 | |
| 702 | | if (p->out_a_func.write != NULL) |
| 703 | | devcb_call_write8(&p->out_a_func, 0, data); |
| 707 | if(m_out_a_func.write != NULL) |
| 708 | { |
| 709 | devcb_call_write8(&m_out_a_func, 0, data); |
| 710 | } |
| 704 | 711 | else |
| 705 | 712 | { |
| 706 | | if (p->out_a_needs_pulled) |
| 707 | | logerror("PIA #%s: Warning! No port A write handler. Previous value has been lost!\n", device->tag()); |
| 713 | if(m_out_a_needs_pulled) |
| 714 | { |
| 715 | logerror("PIA #%s: Warning! No port A write handler. Previous value has been lost!\n", tag()); |
| 716 | } |
| 708 | 717 | |
| 709 | | p->out_a_needs_pulled = TRUE; |
| 718 | m_out_a_needs_pulled = TRUE; |
| 710 | 719 | } |
| 711 | 720 | } |
| 712 | 721 | |
| r8885 | r8886 | |
| 715 | 724 | send_to_out_b_func |
| 716 | 725 | -------------------------------------------------*/ |
| 717 | 726 | |
| 718 | | static void send_to_out_b_func(running_device *device, const char* message) |
| 727 | void pia6821_device::send_to_out_b_func(const char* message) |
| 719 | 728 | { |
| 720 | | pia6821_state *p = get_token(device); |
| 721 | | |
| 722 | 729 | /* input pins are high-impedance - we just send them as zeros for backwards compatibility */ |
| 723 | | UINT8 data = get_out_b_value(device); |
| 730 | UINT8 data = get_out_b_value(); |
| 724 | 731 | |
| 725 | | LOG(("PIA #%s: %s = %02X\n", device->tag(), message, data)); |
| 732 | LOG(("PIA #%s: %s = %02X\n", tag(), message, data)); |
| 726 | 733 | |
| 727 | | if (p->out_b_func.write != NULL) |
| 728 | | devcb_call_write8(&p->out_b_func, 0, data); |
| 734 | if(m_out_b_func.write != NULL) |
| 735 | { |
| 736 | devcb_call_write8(&m_out_b_func, 0, data); |
| 737 | } |
| 729 | 738 | else |
| 730 | 739 | { |
| 731 | | if (p->out_b_needs_pulled) |
| 732 | | logerror("PIA #%s: Warning! No port B write handler. Previous value has been lost!\n", device->tag()); |
| 740 | if(m_out_b_needs_pulled) |
| 741 | { |
| 742 | logerror("PIA #%s: Warning! No port B write handler. Previous value has been lost!\n", tag()); |
| 743 | } |
| 733 | 744 | |
| 734 | | p->out_b_needs_pulled = TRUE; |
| 745 | m_out_b_needs_pulled = TRUE; |
| 735 | 746 | } |
| 736 | 747 | } |
| 737 | 748 | |
| r8885 | r8886 | |
| 740 | 751 | port_a_w |
| 741 | 752 | -------------------------------------------------*/ |
| 742 | 753 | |
| 743 | | static void port_a_w(running_device *device, UINT8 data) |
| 754 | void pia6821_device::port_a_w(UINT8 data) |
| 744 | 755 | { |
| 745 | | pia6821_state *p = get_token(device); |
| 746 | | |
| 747 | 756 | /* buffer the output value */ |
| 748 | | p->out_a = data; |
| 757 | m_out_a = data; |
| 749 | 758 | |
| 750 | | send_to_out_a_func(device, "port A write"); |
| 759 | send_to_out_a_func("port A write"); |
| 751 | 760 | } |
| 752 | 761 | |
| 753 | 762 | |
| r8885 | r8886 | |
| 755 | 764 | ddr_a_w |
| 756 | 765 | -------------------------------------------------*/ |
| 757 | 766 | |
| 758 | | static void ddr_a_w(running_device *device, UINT8 data) |
| 767 | void pia6821_device::ddr_a_w(UINT8 data) |
| 759 | 768 | { |
| 760 | | pia6821_state *p = get_token(device); |
| 761 | | |
| 762 | | if (data == 0x00) |
| 763 | | LOG(("PIA #%s: DDR A write = %02X (input mode)\n", device->tag(), data)); |
| 764 | | else if (data == 0xff) |
| 765 | | LOG(("PIA #%s: DDR A write = %02X (output mode)\n", device->tag(), data)); |
| 769 | if(data == 0x00) |
| 770 | { |
| 771 | LOG(("PIA #%s: DDR A write = %02X (input mode)\n", tag(), data)); |
| 772 | } |
| 773 | else if(data == 0xff) |
| 774 | { |
| 775 | LOG(("PIA #%s: DDR A write = %02X (output mode)\n", tag(), data)); |
| 776 | } |
| 766 | 777 | else |
| 767 | | LOG(("PIA #%s: DDR A write = %02X (mixed mode)\n", device->tag(), data)); |
| 778 | { |
| 779 | LOG(("PIA #%s: DDR A write = %02X (mixed mode)\n", tag(), data)); |
| 780 | } |
| 768 | 781 | |
| 769 | | if (p->ddr_a != data) |
| 782 | if(m_ddr_a != data) |
| 770 | 783 | { |
| 771 | 784 | /* DDR changed, call the callback again */ |
| 772 | | p->ddr_a = data; |
| 773 | | p->logged_port_a_not_connected = FALSE; |
| 774 | | send_to_out_a_func(device, "port A write due to DDR change"); |
| 785 | m_ddr_a = data; |
| 786 | m_logged_port_a_not_connected = FALSE; |
| 787 | send_to_out_a_func("port A write due to DDR change"); |
| 775 | 788 | } |
| 776 | 789 | } |
| 777 | 790 | |
| r8885 | r8886 | |
| 780 | 793 | port_b_w |
| 781 | 794 | -------------------------------------------------*/ |
| 782 | 795 | |
| 783 | | static void port_b_w(running_device *device, UINT8 data) |
| 796 | void pia6821_device::port_b_w(UINT8 data) |
| 784 | 797 | { |
| 785 | | pia6821_state *p = get_token(device); |
| 786 | | |
| 787 | 798 | /* buffer the output value */ |
| 788 | | p->out_b = data; |
| 799 | m_out_b = data; |
| 789 | 800 | |
| 790 | | send_to_out_b_func(device, "port B write"); |
| 801 | send_to_out_b_func("port B write"); |
| 791 | 802 | |
| 792 | 803 | /* CB2 in write strobe mode */ |
| 793 | | if (C2_STROBE_MODE(p->ctl_b)) |
| 804 | if(C2_STROBE_MODE(m_ctl_b)) |
| 794 | 805 | { |
| 795 | 806 | /* this will cause a transition low */ |
| 796 | | set_out_cb2(device, FALSE); |
| 807 | set_out_cb2(FALSE); |
| 797 | 808 | |
| 798 | 809 | /* if the CB2 strobe is cleared by the E, reset it right away */ |
| 799 | | if (STROBE_E_RESET(p->ctl_b)) |
| 800 | | set_out_cb2(device, TRUE); |
| 810 | if(STROBE_E_RESET(m_ctl_b)) |
| 811 | { |
| 812 | set_out_cb2(TRUE); |
| 813 | } |
| 801 | 814 | } |
| 802 | 815 | } |
| 803 | 816 | |
| r8885 | r8886 | |
| 806 | 819 | ddr_b_w |
| 807 | 820 | -------------------------------------------------*/ |
| 808 | 821 | |
| 809 | | static void ddr_b_w(running_device *device, UINT8 data) |
| 822 | void pia6821_device::ddr_b_w(UINT8 data) |
| 810 | 823 | { |
| 811 | | pia6821_state *p = get_token(device); |
| 812 | | |
| 813 | 824 | if (data == 0x00) |
| 814 | | LOG(("PIA #%s: DDR B write = %02X (input mode)\n", device->tag(), data)); |
| 825 | { |
| 826 | LOG(("PIA #%s: DDR B write = %02X (input mode)\n", tag(), data)); |
| 827 | } |
| 815 | 828 | else if (data == 0xff) |
| 816 | | LOG(("PIA #%s: DDR B write = %02X (output mode)\n", device->tag(), data)); |
| 829 | { |
| 830 | LOG(("PIA #%s: DDR B write = %02X (output mode)\n", tag(), data)); |
| 831 | } |
| 817 | 832 | else |
| 818 | | LOG(("PIA #%s: DDR B write = %02X (mixed mode)\n", device->tag(), data)); |
| 833 | { |
| 834 | LOG(("PIA #%s: DDR B write = %02X (mixed mode)\n", tag(), data)); |
| 835 | } |
| 819 | 836 | |
| 820 | | if (p->ddr_b != data) |
| 837 | if(m_ddr_b != data) |
| 821 | 838 | { |
| 822 | 839 | /* DDR changed, call the callback again */ |
| 823 | | p->ddr_b = data; |
| 824 | | p->logged_port_b_not_connected = FALSE; |
| 825 | | send_to_out_b_func(device, "port B write due to DDR change"); |
| 840 | m_ddr_b = data; |
| 841 | m_logged_port_b_not_connected = FALSE; |
| 842 | send_to_out_b_func("port B write due to DDR change"); |
| 826 | 843 | } |
| 827 | 844 | } |
| 828 | 845 | |
| r8885 | r8886 | |
| 831 | 848 | control_a_w |
| 832 | 849 | -------------------------------------------------*/ |
| 833 | 850 | |
| 834 | | static void control_a_w(running_device *device, UINT8 data) |
| 851 | void pia6821_device::control_a_w(UINT8 data) |
| 835 | 852 | { |
| 836 | | pia6821_state *p = get_token(device); |
| 837 | | |
| 838 | 853 | /* bit 7 and 6 are read only */ |
| 839 | 854 | data &= 0x3f; |
| 840 | 855 | |
| 841 | | LOG(("PIA #%s: control A write = %02X\n", device->tag(), data)); |
| 856 | LOG(("PIA #%s: control A write = %02X\n", tag(), data)); |
| 842 | 857 | |
| 843 | 858 | /* update the control register */ |
| 844 | | p->ctl_a = data; |
| 859 | m_ctl_a = data; |
| 845 | 860 | |
| 846 | 861 | /* CA2 is configured as output */ |
| 847 | | if (C2_OUTPUT(p->ctl_a)) |
| 862 | if(C2_OUTPUT(m_ctl_a)) |
| 848 | 863 | { |
| 849 | 864 | int temp; |
| 850 | 865 | |
| 851 | | if (C2_SET_MODE(p->ctl_a)) |
| 866 | if(C2_SET_MODE(m_ctl_a)) |
| 867 | { |
| 852 | 868 | /* set/reset mode - bit value determines the new output */ |
| 853 | | temp = C2_SET(p->ctl_a); |
| 869 | temp = C2_SET(m_ctl_a); |
| 870 | } |
| 854 | 871 | else |
| 872 | { |
| 855 | 873 | /* strobe mode - output is always high unless strobed */ |
| 856 | 874 | temp = TRUE; |
| 875 | } |
| 857 | 876 | |
| 858 | | set_out_ca2(device, temp); |
| 877 | set_out_ca2(temp); |
| 859 | 878 | } |
| 860 | 879 | |
| 861 | 880 | /* update externals */ |
| 862 | | update_interrupts(device); |
| 881 | update_interrupts(); |
| 863 | 882 | } |
| 864 | 883 | |
| 865 | 884 | |
| r8885 | r8886 | |
| 867 | 886 | control_b_w |
| 868 | 887 | -------------------------------------------------*/ |
| 869 | 888 | |
| 870 | | static void control_b_w(running_device *device, UINT8 data) |
| 889 | void pia6821_device::control_b_w(UINT8 data) |
| 871 | 890 | { |
| 872 | | pia6821_state *p = get_token(device); |
| 873 | 891 | int temp; |
| 874 | 892 | |
| 875 | 893 | /* bit 7 and 6 are read only */ |
| 876 | 894 | data &= 0x3f; |
| 877 | 895 | |
| 878 | | LOG(("PIA #%s: control B write = %02X\n", device->tag(), data)); |
| 896 | LOG(("PIA #%s: control B write = %02X\n", tag(), data)); |
| 879 | 897 | |
| 880 | 898 | /* update the control register */ |
| 881 | | p->ctl_b = data; |
| 899 | m_ctl_b = data; |
| 882 | 900 | |
| 883 | | if (C2_SET_MODE(p->ctl_b)) |
| 901 | if (C2_SET_MODE(m_ctl_b)) |
| 902 | { |
| 884 | 903 | /* set/reset mode - bit value determines the new output */ |
| 885 | | temp = C2_SET(p->ctl_b); |
| 904 | temp = C2_SET(m_ctl_b); |
| 905 | } |
| 886 | 906 | else |
| 907 | { |
| 887 | 908 | /* strobe mode - output is always high unless strobed */ |
| 888 | 909 | temp = TRUE; |
| 910 | } |
| 889 | 911 | |
| 890 | | set_out_cb2(device, temp); |
| 912 | set_out_cb2(temp); |
| 891 | 913 | |
| 892 | 914 | /* update externals */ |
| 893 | | update_interrupts(device); |
| 915 | update_interrupts(); |
| 894 | 916 | } |
| 895 | 917 | |
| 896 | 918 | |
| r8885 | r8886 | |
| 900 | 922 | |
| 901 | 923 | WRITE8_DEVICE_HANDLER( pia6821_w ) |
| 902 | 924 | { |
| 903 | | pia6821_state *p = get_token(device); |
| 925 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 926 | dev->reg_w(offset, data); |
| 927 | } |
| 904 | 928 | |
| 929 | void pia6821_device::reg_w(UINT8 offset, UINT8 data) |
| 930 | { |
| 905 | 931 | switch (offset & 0x03) |
| 906 | 932 | { |
| 907 | 933 | default: /* impossible */ |
| 908 | 934 | case 0x00: |
| 909 | | if (OUTPUT_SELECTED(p->ctl_a)) |
| 910 | | port_a_w(device, data); |
| 935 | if (OUTPUT_SELECTED(m_ctl_a)) |
| 936 | { |
| 937 | port_a_w(data); |
| 938 | } |
| 911 | 939 | else |
| 912 | | ddr_a_w(device, data); |
| 940 | { |
| 941 | ddr_a_w(data); |
| 942 | } |
| 913 | 943 | break; |
| 914 | 944 | |
| 915 | 945 | case 0x01: |
| 916 | | control_a_w(device, data); |
| 946 | control_a_w( data); |
| 917 | 947 | break; |
| 918 | 948 | |
| 919 | 949 | case 0x02: |
| 920 | | if (OUTPUT_SELECTED(p->ctl_b)) |
| 921 | | port_b_w(device, data); |
| 950 | if(OUTPUT_SELECTED(m_ctl_b)) |
| 951 | { |
| 952 | port_b_w(data); |
| 953 | } |
| 922 | 954 | else |
| 923 | | ddr_b_w(device, data); |
| 955 | { |
| 956 | ddr_b_w(data); |
| 957 | } |
| 924 | 958 | break; |
| 925 | 959 | |
| 926 | 960 | case 0x03: |
| 927 | | control_b_w(device, data); |
| 961 | control_b_w(data); |
| 928 | 962 | break; |
| 929 | 963 | } |
| 930 | 964 | } |
| r8885 | r8886 | |
| 936 | 970 | |
| 937 | 971 | WRITE8_DEVICE_HANDLER( pia6821_alt_w ) |
| 938 | 972 | { |
| 939 | | pia6821_w(device, ((offset << 1) & 0x02) | ((offset >> 1) & 0x01), data); |
| 973 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 974 | dev->reg_w(((offset << 1) & 0x02) | ((offset >> 1) & 0x01), data); |
| 940 | 975 | } |
| 941 | 976 | |
| 942 | 977 | |
| r8885 | r8886 | |
| 946 | 981 | |
| 947 | 982 | void pia6821_set_port_a_z_mask(running_device *device, UINT8 data) |
| 948 | 983 | { |
| 949 | | pia6821_state *p = get_token(device); |
| 984 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 985 | dev->set_port_a_z_mask(data); |
| 986 | } |
| 950 | 987 | |
| 951 | | p->port_a_z_mask = data; |
| 988 | void pia6821_device::set_port_a_z_mask(UINT8 data) |
| 989 | { |
| 990 | m_port_a_z_mask = data; |
| 952 | 991 | } |
| 953 | 992 | |
| 954 | 993 | |
| r8885 | r8886 | |
| 958 | 997 | |
| 959 | 998 | READ8_DEVICE_HANDLER( pia6821_porta_r ) |
| 960 | 999 | { |
| 961 | | pia6821_state *p = get_token(device); |
| 1000 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1001 | return dev->porta_r(); |
| 1002 | } |
| 962 | 1003 | |
| 963 | | return p->in_a; |
| 1004 | UINT8 pia6821_device::porta_r() |
| 1005 | { |
| 1006 | return m_in_a; |
| 964 | 1007 | } |
| 965 | 1008 | |
| 966 | 1009 | |
| r8885 | r8886 | |
| 970 | 1013 | |
| 971 | 1014 | void pia6821_set_input_a(running_device *device, UINT8 data, UINT8 z_mask) |
| 972 | 1015 | { |
| 973 | | pia6821_state *p = get_token(device); |
| 1016 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1017 | dev->set_input_a(data, z_mask); |
| 1018 | } |
| 974 | 1019 | |
| 975 | | assert_always(p->in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented"); |
| 1020 | void pia6821_device::set_input_a(UINT8 data, UINT8 z_mask) |
| 1021 | { |
| 1022 | assert_always(m_in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented"); |
| 976 | 1023 | |
| 977 | | LOG(("PIA #%s: set input port A = %02X\n", device->tag(), data)); |
| 1024 | LOG(("PIA #%s: set input port A = %02X\n", tag(), data)); |
| 978 | 1025 | |
| 979 | | p->in_a = data; |
| 980 | | p->port_a_z_mask = z_mask; |
| 981 | | p->in_a_pushed = TRUE; |
| 1026 | m_in_a = data; |
| 1027 | m_port_a_z_mask = z_mask; |
| 1028 | m_in_a_pushed = TRUE; |
| 982 | 1029 | } |
| 983 | 1030 | |
| 984 | 1031 | |
| r8885 | r8886 | |
| 988 | 1035 | |
| 989 | 1036 | WRITE8_DEVICE_HANDLER( pia6821_porta_w ) |
| 990 | 1037 | { |
| 991 | | pia6821_set_input_a(device, data, 0); |
| 1038 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1039 | dev->porta_w(data); |
| 992 | 1040 | } |
| 993 | 1041 | |
| 1042 | void pia6821_device::porta_w(UINT8 data) |
| 1043 | { |
| 1044 | pia6821_set_input_a(this, data, 0); |
| 1045 | } |
| 994 | 1046 | |
| 1047 | |
| 995 | 1048 | /*------------------------------------------------- |
| 996 | 1049 | pia6821_get_output_a |
| 997 | 1050 | -------------------------------------------------*/ |
| 998 | 1051 | |
| 999 | 1052 | UINT8 pia6821_get_output_a(running_device *device) |
| 1000 | 1053 | { |
| 1001 | | pia6821_state *p = get_token(device); |
| 1054 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1055 | return dev->get_output_a(); |
| 1056 | } |
| 1002 | 1057 | |
| 1003 | | p->out_a_needs_pulled = FALSE; |
| 1058 | UINT8 pia6821_device::get_output_a() |
| 1059 | { |
| 1060 | m_out_a_needs_pulled = FALSE; |
| 1004 | 1061 | |
| 1005 | | return get_out_a_value(device); |
| 1062 | return get_out_a_value(); |
| 1006 | 1063 | } |
| 1007 | 1064 | |
| 1008 | 1065 | |
| r8885 | r8886 | |
| 1012 | 1069 | |
| 1013 | 1070 | READ_LINE_DEVICE_HANDLER( pia6821_ca1_r ) |
| 1014 | 1071 | { |
| 1015 | | pia6821_state *p = get_token(device); |
| 1072 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1073 | return dev->ca1_r(); |
| 1074 | } |
| 1016 | 1075 | |
| 1017 | | return p->in_ca1; |
| 1076 | UINT8 pia6821_device::ca1_r() |
| 1077 | { |
| 1078 | return m_in_ca1; |
| 1018 | 1079 | } |
| 1019 | 1080 | |
| 1020 | 1081 | |
| r8885 | r8886 | |
| 1024 | 1085 | |
| 1025 | 1086 | WRITE_LINE_DEVICE_HANDLER( pia6821_ca1_w ) |
| 1026 | 1087 | { |
| 1027 | | pia6821_state *p = get_token(device); |
| 1088 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1089 | dev->ca1_w(state); |
| 1090 | } |
| 1028 | 1091 | |
| 1029 | | LOG(("PIA #%s: set input CA1 = %d\n", device->tag(), state)); |
| 1092 | void pia6821_device::ca1_w(UINT8 state) |
| 1093 | { |
| 1094 | LOG(("PIA #%s: set input CA1 = %d\n", tag(), state)); |
| 1030 | 1095 | |
| 1031 | 1096 | /* the new state has caused a transition */ |
| 1032 | | if ((p->in_ca1 != state) && |
| 1033 | | ((state && C1_LOW_TO_HIGH(p->ctl_a)) || (!state && C1_HIGH_TO_LOW(p->ctl_a)))) |
| 1097 | if((m_in_ca1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_a)) || (!state && C1_HIGH_TO_LOW(m_ctl_a)))) |
| 1034 | 1098 | { |
| 1035 | | LOG(("PIA #%s: CA1 triggering\n", device->tag())); |
| 1099 | LOG(("PIA #%s: CA1 triggering\n", tag())); |
| 1036 | 1100 | |
| 1037 | 1101 | /* mark the IRQ */ |
| 1038 | | p->irq_a1 = TRUE; |
| 1102 | m_irq_a1 = TRUE; |
| 1039 | 1103 | |
| 1040 | 1104 | /* update externals */ |
| 1041 | | update_interrupts(device); |
| 1105 | update_interrupts(); |
| 1042 | 1106 | |
| 1043 | 1107 | /* CA2 is configured as output and in read strobe mode and cleared by a CA1 transition */ |
| 1044 | | if (C2_OUTPUT(p->ctl_a) && C2_STROBE_MODE(p->ctl_a) && STROBE_C1_RESET(p->ctl_a)) |
| 1045 | | set_out_ca2(device, TRUE); |
| 1108 | if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a) && STROBE_C1_RESET(m_ctl_a)) |
| 1109 | { |
| 1110 | set_out_ca2(TRUE); |
| 1111 | } |
| 1046 | 1112 | } |
| 1047 | 1113 | |
| 1048 | 1114 | /* set the new value for CA1 */ |
| 1049 | | p->in_ca1 = state; |
| 1050 | | p->in_ca1_pushed = TRUE; |
| 1115 | m_in_ca1 = state; |
| 1116 | m_in_ca1_pushed = TRUE; |
| 1051 | 1117 | } |
| 1052 | 1118 | |
| 1053 | 1119 | |
| r8885 | r8886 | |
| 1057 | 1123 | |
| 1058 | 1124 | READ_LINE_DEVICE_HANDLER( pia6821_ca2_r ) |
| 1059 | 1125 | { |
| 1060 | | pia6821_state *p = get_token(device); |
| 1126 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1127 | return dev->ca2_r(); |
| 1128 | } |
| 1061 | 1129 | |
| 1062 | | return p->in_ca2; |
| 1130 | UINT8 pia6821_device::ca2_r() |
| 1131 | { |
| 1132 | return m_in_ca2; |
| 1063 | 1133 | } |
| 1064 | 1134 | |
| 1065 | 1135 | |
| r8885 | r8886 | |
| 1069 | 1139 | |
| 1070 | 1140 | WRITE_LINE_DEVICE_HANDLER( pia6821_ca2_w ) |
| 1071 | 1141 | { |
| 1072 | | pia6821_state *p = get_token(device); |
| 1142 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1143 | dev->ca2_w(state); |
| 1144 | } |
| 1073 | 1145 | |
| 1074 | | LOG(("PIA #%s: set input CA2 = %d\n", device->tag(), state)); |
| 1146 | void pia6821_device::ca2_w(UINT8 state) |
| 1147 | { |
| 1148 | LOG(("PIA #%s: set input CA2 = %d\n", tag(), state)); |
| 1075 | 1149 | |
| 1076 | 1150 | /* if input mode and the new state has caused a transition */ |
| 1077 | | if (C2_INPUT(p->ctl_a) && |
| 1078 | | (p->in_ca2 != state) && |
| 1079 | | ((state && C2_LOW_TO_HIGH(p->ctl_a)) || (!state && C2_HIGH_TO_LOW(p->ctl_a)))) |
| 1151 | if(C2_INPUT(m_ctl_a) && (m_in_ca2 != state) && ((state && C2_LOW_TO_HIGH(m_ctl_a)) || (!state && C2_HIGH_TO_LOW(m_ctl_a)))) |
| 1080 | 1152 | { |
| 1081 | | LOG(("PIA #%s: CA2 triggering\n", device->tag())); |
| 1153 | LOG(("PIA #%s: CA2 triggering\n", tag())); |
| 1082 | 1154 | |
| 1083 | 1155 | /* mark the IRQ */ |
| 1084 | | p->irq_a2 = TRUE; |
| 1156 | m_irq_a2 = TRUE; |
| 1085 | 1157 | |
| 1086 | 1158 | /* update externals */ |
| 1087 | | update_interrupts(device); |
| 1159 | update_interrupts(); |
| 1088 | 1160 | } |
| 1089 | 1161 | |
| 1090 | 1162 | /* set the new value for CA2 */ |
| 1091 | | p->in_ca2 = state; |
| 1092 | | p->in_ca2_pushed = TRUE; |
| 1163 | m_in_ca2 = state; |
| 1164 | m_in_ca2_pushed = TRUE; |
| 1093 | 1165 | } |
| 1094 | 1166 | |
| 1095 | 1167 | |
| r8885 | r8886 | |
| 1099 | 1171 | |
| 1100 | 1172 | int pia6821_get_output_ca2(running_device *device) |
| 1101 | 1173 | { |
| 1102 | | pia6821_state *p = get_token(device); |
| 1174 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1175 | return dev->get_output_ca2(); |
| 1176 | } |
| 1103 | 1177 | |
| 1104 | | p->out_ca2_needs_pulled = FALSE; |
| 1178 | int pia6821_device::get_output_ca2() |
| 1179 | { |
| 1180 | m_out_ca2_needs_pulled = FALSE; |
| 1105 | 1181 | |
| 1106 | | return p->out_ca2; |
| 1182 | return m_out_ca2; |
| 1107 | 1183 | } |
| 1108 | 1184 | |
| 1109 | 1185 | |
| r8885 | r8886 | |
| 1115 | 1191 | |
| 1116 | 1192 | int pia6821_get_output_ca2_z(running_device *device) |
| 1117 | 1193 | { |
| 1118 | | pia6821_state *p = get_token(device); |
| 1194 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1195 | return dev->get_output_ca2_z(); |
| 1196 | } |
| 1119 | 1197 | |
| 1120 | | p->out_ca2_needs_pulled = FALSE; |
| 1198 | int pia6821_device::get_output_ca2_z() |
| 1199 | { |
| 1200 | m_out_ca2_needs_pulled = FALSE; |
| 1121 | 1201 | |
| 1122 | 1202 | // If it's an output, output the bit, if it's an input, it's |
| 1123 | 1203 | // pulled up |
| 1124 | | return p->out_ca2 | |
| 1125 | | C2_INPUT(p->ctl_a); |
| 1204 | return m_out_ca2 | C2_INPUT(m_ctl_a); |
| 1126 | 1205 | } |
| 1127 | 1206 | |
| 1128 | 1207 | |
| r8885 | r8886 | |
| 1132 | 1211 | |
| 1133 | 1212 | READ8_DEVICE_HANDLER( pia6821_portb_r ) |
| 1134 | 1213 | { |
| 1135 | | pia6821_state *p = get_token(device); |
| 1214 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1215 | return dev->portb_r(); |
| 1216 | } |
| 1136 | 1217 | |
| 1137 | | return p->in_b; |
| 1218 | UINT8 pia6821_device::portb_r() |
| 1219 | { |
| 1220 | return m_in_b; |
| 1138 | 1221 | } |
| 1139 | 1222 | |
| 1140 | 1223 | |
| r8885 | r8886 | |
| 1144 | 1227 | |
| 1145 | 1228 | WRITE8_DEVICE_HANDLER( pia6821_portb_w ) |
| 1146 | 1229 | { |
| 1147 | | pia6821_state *p = get_token(device); |
| 1230 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1231 | dev->portb_w(data); |
| 1232 | } |
| 1148 | 1233 | |
| 1149 | | assert_always(p->in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented"); |
| 1234 | void pia6821_device::portb_w(UINT8 data) |
| 1235 | { |
| 1236 | assert_always(m_in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented"); |
| 1150 | 1237 | |
| 1151 | | LOG(("PIA #%s: set input port B = %02X\n", device->tag(), data)); |
| 1238 | LOG(("PIA #%s: set input port B = %02X\n", tag(), data)); |
| 1152 | 1239 | |
| 1153 | | p->in_b = data; |
| 1154 | | p->in_b_pushed = TRUE; |
| 1240 | m_in_b = data; |
| 1241 | m_in_b_pushed = TRUE; |
| 1155 | 1242 | } |
| 1156 | 1243 | |
| 1157 | 1244 | |
| r8885 | r8886 | |
| 1161 | 1248 | |
| 1162 | 1249 | UINT8 pia6821_get_output_b(running_device *device) |
| 1163 | 1250 | { |
| 1164 | | pia6821_state *p = get_token(device); |
| 1251 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1252 | return dev->get_output_b(); |
| 1253 | } |
| 1165 | 1254 | |
| 1166 | | p->out_b_needs_pulled = FALSE; |
| 1255 | UINT8 pia6821_device::get_output_b() |
| 1256 | { |
| 1257 | m_out_b_needs_pulled = FALSE; |
| 1167 | 1258 | |
| 1168 | | return get_out_b_value(device); |
| 1259 | return get_out_b_value(); |
| 1169 | 1260 | } |
| 1170 | 1261 | |
| 1171 | 1262 | |
| r8885 | r8886 | |
| 1175 | 1266 | |
| 1176 | 1267 | READ_LINE_DEVICE_HANDLER( pia6821_cb1_r ) |
| 1177 | 1268 | { |
| 1178 | | pia6821_state *p = get_token(device); |
| 1269 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1270 | return dev->cb1_r(); |
| 1271 | } |
| 1179 | 1272 | |
| 1180 | | return p->in_cb1; |
| 1273 | UINT8 pia6821_device::cb1_r() |
| 1274 | { |
| 1275 | return m_in_cb1; |
| 1181 | 1276 | } |
| 1182 | 1277 | |
| 1183 | 1278 | |
| r8885 | r8886 | |
| 1187 | 1282 | |
| 1188 | 1283 | WRITE_LINE_DEVICE_HANDLER( pia6821_cb1_w ) |
| 1189 | 1284 | { |
| 1190 | | pia6821_state *p = get_token(device); |
| 1285 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1286 | dev->cb1_w(state); |
| 1287 | } |
| 1191 | 1288 | |
| 1192 | | LOG(("PIA #%s: set input CB1 = %d\n", device->tag(), state)); |
| 1289 | void pia6821_device::cb1_w(UINT8 state) |
| 1290 | { |
| 1291 | LOG(("PIA #%s: set input CB1 = %d\n", tag(), state)); |
| 1193 | 1292 | |
| 1194 | 1293 | /* the new state has caused a transition */ |
| 1195 | | if ((p->in_cb1 != state) && |
| 1196 | | ((state && C1_LOW_TO_HIGH(p->ctl_b)) || (!state && C1_HIGH_TO_LOW(p->ctl_b)))) |
| 1294 | if((m_in_cb1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_b)) || (!state && C1_HIGH_TO_LOW(m_ctl_b)))) |
| 1197 | 1295 | { |
| 1198 | | LOG(("PIA #%s: CB1 triggering\n", device->tag())); |
| 1296 | LOG(("PIA #%s: CB1 triggering\n", tag())); |
| 1199 | 1297 | |
| 1200 | 1298 | /* mark the IRQ */ |
| 1201 | | p->irq_b1 = 1; |
| 1299 | m_irq_b1 = 1; |
| 1202 | 1300 | |
| 1203 | 1301 | /* update externals */ |
| 1204 | | update_interrupts(device); |
| 1302 | update_interrupts(); |
| 1205 | 1303 | |
| 1206 | 1304 | /* If CB2 is configured as a write-strobe output which is reset by a CB1 |
| 1207 | 1305 | transition, this reset will only happen when a read from port B implicitly |
| r8885 | r8886 | |
| 1210 | 1308 | } |
| 1211 | 1309 | |
| 1212 | 1310 | /* set the new value for CB1 */ |
| 1213 | | p->in_cb1 = state; |
| 1214 | | p->in_cb1_pushed = TRUE; |
| 1311 | m_in_cb1 = state; |
| 1312 | m_in_cb1_pushed = TRUE; |
| 1215 | 1313 | } |
| 1216 | 1314 | |
| 1217 | 1315 | |
| r8885 | r8886 | |
| 1221 | 1319 | |
| 1222 | 1320 | READ_LINE_DEVICE_HANDLER( pia6821_cb2_r ) |
| 1223 | 1321 | { |
| 1224 | | pia6821_state *p = get_token(device); |
| 1322 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1323 | return dev->cb2_r(); |
| 1324 | } |
| 1225 | 1325 | |
| 1226 | | return p->in_cb2; |
| 1326 | UINT8 pia6821_device::cb2_r() |
| 1327 | { |
| 1328 | return m_in_cb2; |
| 1227 | 1329 | } |
| 1228 | 1330 | |
| 1229 | 1331 | |
| r8885 | r8886 | |
| 1233 | 1335 | |
| 1234 | 1336 | WRITE_LINE_DEVICE_HANDLER( pia6821_cb2_w ) |
| 1235 | 1337 | { |
| 1236 | | pia6821_state *p = get_token(device); |
| 1338 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1339 | dev->cb2_w(state); |
| 1340 | } |
| 1237 | 1341 | |
| 1238 | | LOG(("PIA #%s: set input CB2 = %d\n", device->tag(), state)); |
| 1342 | void pia6821_device::cb2_w(UINT8 state) |
| 1343 | { |
| 1344 | LOG(("PIA #%s: set input CB2 = %d\n", tag(), state)); |
| 1239 | 1345 | |
| 1240 | 1346 | /* if input mode and the new state has caused a transition */ |
| 1241 | | if (C2_INPUT(p->ctl_b) && |
| 1242 | | (p->in_cb2 != state) && |
| 1243 | | ((state && C2_LOW_TO_HIGH(p->ctl_b)) || (!state && C2_HIGH_TO_LOW(p->ctl_b)))) |
| 1347 | if (C2_INPUT(m_ctl_b) && |
| 1348 | (m_in_cb2 != state) && |
| 1349 | ((state && C2_LOW_TO_HIGH(m_ctl_b)) || (!state && C2_HIGH_TO_LOW(m_ctl_b)))) |
| 1244 | 1350 | { |
| 1245 | | LOG(("PIA #%s: CB2 triggering\n", device->tag())); |
| 1351 | LOG(("PIA #%s: CB2 triggering\n", tag())); |
| 1246 | 1352 | |
| 1247 | 1353 | /* mark the IRQ */ |
| 1248 | | p->irq_b2 = 1; |
| 1354 | m_irq_b2 = 1; |
| 1249 | 1355 | |
| 1250 | 1356 | /* update externals */ |
| 1251 | | update_interrupts(device); |
| 1357 | update_interrupts(); |
| 1252 | 1358 | } |
| 1253 | 1359 | |
| 1254 | 1360 | /* set the new value for CA2 */ |
| 1255 | | p->in_cb2 = state; |
| 1256 | | p->in_cb2_pushed = TRUE; |
| 1361 | m_in_cb2 = state; |
| 1362 | m_in_cb2_pushed = TRUE; |
| 1257 | 1363 | } |
| 1258 | 1364 | |
| 1259 | 1365 | |
| r8885 | r8886 | |
| 1263 | 1369 | |
| 1264 | 1370 | int pia6821_get_output_cb2(running_device *device) |
| 1265 | 1371 | { |
| 1266 | | pia6821_state *p = get_token(device); |
| 1372 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1373 | return dev->get_output_cb2(); |
| 1374 | } |
| 1267 | 1375 | |
| 1268 | | p->out_cb2_needs_pulled = FALSE; |
| 1376 | int pia6821_device::get_output_cb2() |
| 1377 | { |
| 1378 | m_out_cb2_needs_pulled = FALSE; |
| 1269 | 1379 | |
| 1270 | | return p->out_cb2; |
| 1380 | return m_out_cb2; |
| 1271 | 1381 | } |
| 1272 | 1382 | |
| 1273 | 1383 | |
| r8885 | r8886 | |
| 1277 | 1387 | |
| 1278 | 1388 | int pia6821_get_output_cb2_z(running_device *device) |
| 1279 | 1389 | { |
| 1280 | | pia6821_state *p = get_token(device); |
| 1390 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1391 | return dev->get_output_cb2_z(); |
| 1392 | } |
| 1281 | 1393 | |
| 1282 | | return !C2_OUTPUT(p->ctl_b); |
| 1394 | int pia6821_device::get_output_cb2_z() |
| 1395 | { |
| 1396 | return !C2_OUTPUT(m_ctl_b); |
| 1283 | 1397 | } |
| 1284 | 1398 | |
| 1285 | 1399 | |
| r8885 | r8886 | |
| 1289 | 1403 | |
| 1290 | 1404 | int pia6821_get_irq_a(running_device *device) |
| 1291 | 1405 | { |
| 1292 | | pia6821_state *p = get_token(device); |
| 1406 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1407 | return dev->get_irq_a(); |
| 1408 | } |
| 1293 | 1409 | |
| 1294 | | return p->irq_a_state; |
| 1410 | int pia6821_device::get_irq_a() |
| 1411 | { |
| 1412 | return m_irq_a_state; |
| 1295 | 1413 | } |
| 1296 | 1414 | |
| 1297 | 1415 | |
| r8885 | r8886 | |
| 1301 | 1419 | |
| 1302 | 1420 | int pia6821_get_irq_b(running_device *device) |
| 1303 | 1421 | { |
| 1304 | | pia6821_state *p = get_token(device); |
| 1422 | pia6821_device *dev = reinterpret_cast<pia6821_device *>(device); |
| 1423 | return dev->get_irq_b(); |
| 1424 | } |
| 1305 | 1425 | |
| 1306 | | return p->irq_b_state; |
| 1426 | int pia6821_device::get_irq_b() |
| 1427 | { |
| 1428 | return m_irq_b_state; |
| 1307 | 1429 | } |
| 1308 | 1430 | |
| 1309 | | |
| 1310 | | /*------------------------------------------------- |
| 1311 | | device definition |
| 1312 | | -------------------------------------------------*/ |
| 1313 | | |
| 1314 | | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |
| 1315 | | |
| 1316 | | #define DEVTEMPLATE_ID(p,s) p##pia6821##s |
| 1317 | | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET |
| 1318 | | #define DEVTEMPLATE_NAME "6821 PIA" |
| 1319 | | #define DEVTEMPLATE_FAMILY "6821 PIA" |
| 1320 | | #include "devtempl.h" |
| 1321 | | |
| 1322 | | #define DEVTEMPLATE_DERIVED_ID(p,s) p##pia6822##s |
| 1323 | | #define DEVTEMPLATE_DERIVED_FEATURES 0 |
| 1324 | | #define DEVTEMPLATE_DERIVED_NAME "6822 PIA" |
| 1325 | | #include "devtempl.h" |
| 1326 | | |
| 1327 | | DEFINE_LEGACY_DEVICE(PIA6821, pia6821); |
| 1328 | | DEFINE_LEGACY_DEVICE(PIA6822, pia6822); |
| 1431 | const device_type PIA6821 = pia6821_device_config::static_alloc_device_config; |
src/emu/machine/6532riot.c
| r8885 | r8886 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | | /*************************************************************************** |
| 35 | | TYPE DEFINITIONS |
| 36 | | ***************************************************************************/ |
| 34 | //************************************************************************** |
| 35 | // DEVICE CONFIGURATION |
| 36 | //************************************************************************** |
| 37 | 37 | |
| 38 | | typedef struct _riot6532_port riot6532_port; |
| 39 | | struct _riot6532_port |
| 38 | //------------------------------------------------- |
| 39 | // riot6532_device_config - constructor |
| 40 | //------------------------------------------------- |
| 41 | |
| 42 | riot6532_device_config::riot6532_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 43 | : device_config(mconfig, static_alloc_device_config, "RIOT6532", tag, owner, clock) |
| 40 | 44 | { |
| 41 | | UINT8 in; |
| 42 | | UINT8 out; |
| 43 | | UINT8 ddr; |
| 44 | | devcb_resolved_read8 in_func; |
| 45 | | devcb_resolved_write8 out_func; |
| 46 | | }; |
| 45 | } |
| 47 | 46 | |
| 48 | 47 | |
| 49 | | typedef struct _riot6532_state riot6532_state; |
| 50 | | struct _riot6532_state |
| 48 | //------------------------------------------------- |
| 49 | // static_alloc_device_config - allocate a new |
| 50 | // configuration object |
| 51 | //------------------------------------------------- |
| 52 | |
| 53 | device_config *riot6532_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 51 | 54 | { |
| 52 | | running_device *device; |
| 53 | | const riot6532_interface *intf; |
| 54 | | int index; |
| 55 | return global_alloc(riot6532_device_config(mconfig, tag, owner, clock)); |
| 56 | } |
| 55 | 57 | |
| 56 | | riot6532_port port[2]; |
| 57 | 58 | |
| 58 | | devcb_resolved_write_line irq_func; |
| 59 | //------------------------------------------------- |
| 60 | // alloc_device - allocate a new device object |
| 61 | //------------------------------------------------- |
| 59 | 62 | |
| 60 | | UINT8 irqstate; |
| 61 | | UINT8 irqenable; |
| 63 | device_t *riot6532_device_config::alloc_device(running_machine &machine) const |
| 64 | { |
| 65 | return auto_alloc(&machine, riot6532_device(machine, *this)); |
| 66 | } |
| 62 | 67 | |
| 63 | | UINT8 pa7dir; /* 0x80 = high-to-low, 0x00 = low-to-high */ |
| 64 | | UINT8 pa7prev; |
| 65 | 68 | |
| 66 | | UINT8 timershift; |
| 67 | | UINT8 timerstate; |
| 68 | | emu_timer * timer; |
| 69 | | }; |
| 69 | //------------------------------------------------- |
| 70 | // device_config_complete - perform any |
| 71 | // operations now that the configuration is |
| 72 | // complete |
| 73 | //------------------------------------------------- |
| 70 | 74 | |
| 75 | void riot6532_device_config::device_config_complete() |
| 76 | { |
| 77 | // inherit a copy of the static data |
| 78 | const riot6532_interface *intf = reinterpret_cast<const riot6532_interface *>(static_config()); |
| 79 | if (intf != NULL) |
| 80 | { |
| 81 | *static_cast<riot6532_interface *>(this) = *intf; |
| 82 | } |
| 71 | 83 | |
| 84 | // or initialize to defaults if none provided |
| 85 | else |
| 86 | { |
| 87 | memset(&m_in_a_func, 0, sizeof(m_in_a_func)); |
| 88 | memset(&m_in_b_func, 0, sizeof(m_in_b_func)); |
| 89 | memset(&m_out_a_func, 0, sizeof(m_out_a_func)); |
| 90 | memset(&m_out_b_func, 0, sizeof(m_out_b_func)); |
| 91 | memset(&m_irq_func, 0, sizeof(m_irq_func)); |
| 92 | } |
| 93 | } |
| 72 | 94 | |
| 95 | |
| 96 | |
| 73 | 97 | /*************************************************************************** |
| 74 | | INLINE FUNCTIONS |
| 98 | INTERNAL FUNCTIONS |
| 75 | 99 | ***************************************************************************/ |
| 76 | 100 | |
| 77 | 101 | /*------------------------------------------------- |
| 78 | | get_safe_token - convert a device's token |
| 79 | | into a riot6532_state |
| 80 | | -------------------------------------------------*/ |
| 81 | | |
| 82 | | INLINE riot6532_state *get_safe_token(running_device *device) |
| 83 | | { |
| 84 | | assert(device != NULL); |
| 85 | | assert(device->type() == RIOT6532); |
| 86 | | return (riot6532_state *)downcast<legacy_device_base *>(device)->token(); |
| 87 | | } |
| 88 | | |
| 89 | | |
| 90 | | /*------------------------------------------------- |
| 91 | 102 | update_irqstate - update the IRQ state |
| 92 | 103 | based on interrupt enables |
| 93 | 104 | -------------------------------------------------*/ |
| 94 | 105 | |
| 95 | | INLINE void update_irqstate(running_device *device) |
| 106 | void riot6532_device::update_irqstate() |
| 96 | 107 | { |
| 97 | | riot6532_state *riot = get_safe_token(device); |
| 98 | | int state = (riot->irqstate & riot->irqenable); |
| 108 | int state = (m_irqstate & m_irqenable); |
| 99 | 109 | |
| 100 | | if (riot->irq_func.write != NULL) |
| 101 | | devcb_call_write_line(&riot->irq_func, (state != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 110 | if (m_irq_func.write != NULL) |
| 111 | { |
| 112 | devcb_call_write_line(&m_irq_func, (state != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 113 | } |
| 102 | 114 | else |
| 103 | | logerror("%s:6532RIOT chip #%d: no irq callback function\n", cpuexec_describe_context(device->machine), riot->index); |
| 115 | { |
| 116 | logerror("%s:6532RIOT chip #%d: no irq callback function\n", cpuexec_describe_context(&m_machine), m_index); |
| 117 | } |
| 104 | 118 | } |
| 105 | 119 | |
| 106 | 120 | |
| r8885 | r8886 | |
| 109 | 123 | according to the DDR |
| 110 | 124 | -------------------------------------------------*/ |
| 111 | 125 | |
| 112 | | INLINE UINT8 apply_ddr(const riot6532_port *port) |
| 126 | UINT8 riot6532_device::apply_ddr(const riot6532_port *port) |
| 113 | 127 | { |
| 114 | | return (port->out & port->ddr) | (port->in & ~port->ddr); |
| 128 | return (port->m_out & port->m_ddr) | (port->m_in & ~port->m_ddr); |
| 115 | 129 | } |
| 116 | 130 | |
| 117 | 131 | |
| r8885 | r8886 | |
| 120 | 134 | and signal appropriately |
| 121 | 135 | -------------------------------------------------*/ |
| 122 | 136 | |
| 123 | | INLINE void update_pa7_state(running_device *device) |
| 137 | void riot6532_device::update_pa7_state() |
| 124 | 138 | { |
| 125 | | riot6532_state *riot = get_safe_token(device); |
| 126 | | UINT8 data = apply_ddr(&riot->port[0]) & 0x80; |
| 139 | UINT8 data = apply_ddr(&m_port[0]) & 0x80; |
| 127 | 140 | |
| 128 | 141 | /* if the state changed in the correct direction, set the PA7 flag and update IRQs */ |
| 129 | | if ((riot->pa7prev ^ data) && (riot->pa7dir ^ data) == 0) |
| 142 | if ((m_pa7prev ^ data) && (m_pa7dir ^ data) == 0) |
| 130 | 143 | { |
| 131 | | riot->irqstate |= PA7_FLAG; |
| 132 | | update_irqstate(device); |
| 144 | m_irqstate |= PA7_FLAG; |
| 145 | update_irqstate(); |
| 133 | 146 | } |
| 134 | | riot->pa7prev = data; |
| 147 | m_pa7prev = data; |
| 135 | 148 | } |
| 136 | 149 | |
| 137 | 150 | |
| r8885 | r8886 | |
| 139 | 152 | get_timer - return the current timer value |
| 140 | 153 | -------------------------------------------------*/ |
| 141 | 154 | |
| 142 | | INLINE UINT8 get_timer(riot6532_state *riot) |
| 155 | UINT8 riot6532_device::get_timer() |
| 143 | 156 | { |
| 144 | 157 | /* if idle, return 0 */ |
| 145 | | if (riot->timerstate == TIMER_IDLE) |
| 158 | if (m_timerstate == TIMER_IDLE) |
| 159 | { |
| 146 | 160 | return 0; |
| 161 | } |
| 147 | 162 | |
| 148 | 163 | /* if counting, return the number of ticks remaining */ |
| 149 | | else if (riot->timerstate == TIMER_COUNTING) |
| 150 | | return attotime_to_ticks(timer_timeleft(riot->timer), riot->device->clock()) >> riot->timershift; |
| 164 | else if (m_timerstate == TIMER_COUNTING) |
| 165 | { |
| 166 | return attotime_to_ticks(timer_timeleft(m_timer), clock()) >> m_timershift; |
| 167 | } |
| 151 | 168 | |
| 152 | 169 | /* if finishing, return the number of ticks without the shift */ |
| 153 | 170 | else |
| 154 | | return attotime_to_ticks(timer_timeleft(riot->timer), riot->device->clock()); |
| 171 | { |
| 172 | return attotime_to_ticks(timer_timeleft(m_timer), clock()); |
| 173 | } |
| 155 | 174 | } |
| 156 | 175 | |
| 157 | 176 | |
| 158 | 177 | |
| 159 | | /*************************************************************************** |
| 160 | | INTERNAL FUNCTIONS |
| 161 | | ***************************************************************************/ |
| 162 | | |
| 163 | 178 | /*------------------------------------------------- |
| 164 | 179 | timer_end_callback - callback to process the |
| 165 | 180 | timer |
| 166 | 181 | -------------------------------------------------*/ |
| 167 | 182 | |
| 168 | | static TIMER_CALLBACK( timer_end_callback ) |
| 183 | TIMER_CALLBACK( riot6532_device::timer_end_callback ) |
| 169 | 184 | { |
| 170 | | running_device *device = (running_device *)ptr; |
| 171 | | riot6532_state *riot = get_safe_token(device); |
| 185 | riot6532_device *via = reinterpret_cast<riot6532_device *>(ptr); |
| 186 | via->timer_end(); |
| 187 | } |
| 172 | 188 | |
| 173 | | assert(riot->timerstate != TIMER_IDLE); |
| 189 | void riot6532_device::timer_end() |
| 190 | { |
| 191 | assert(m_timerstate != TIMER_IDLE); |
| 174 | 192 | |
| 175 | 193 | /* if we finished counting, switch to the finishing state */ |
| 176 | | if (riot->timerstate == TIMER_COUNTING) |
| 194 | if(m_timerstate == TIMER_COUNTING) |
| 177 | 195 | { |
| 178 | | riot->timerstate = TIMER_FINISHING; |
| 179 | | timer_adjust_oneshot(riot->timer, ticks_to_attotime(256, device->clock()), 0); |
| 196 | m_timerstate = TIMER_FINISHING; |
| 197 | timer_adjust_oneshot(m_timer, ticks_to_attotime(256, clock()), 0); |
| 180 | 198 | |
| 181 | 199 | /* signal timer IRQ as well */ |
| 182 | | riot->irqstate |= TIMER_FLAG; |
| 183 | | update_irqstate(device); |
| 200 | m_irqstate |= TIMER_FLAG; |
| 201 | update_irqstate(); |
| 184 | 202 | } |
| 185 | 203 | |
| 186 | 204 | /* if we finished finishing, keep spinning */ |
| 187 | | else if (riot->timerstate == TIMER_FINISHING) |
| 205 | else if (m_timerstate == TIMER_FINISHING) |
| 188 | 206 | { |
| 189 | | timer_adjust_oneshot(riot->timer, ticks_to_attotime(256, device->clock()), 0); |
| 207 | timer_adjust_oneshot(m_timer, ticks_to_attotime(256, clock()), 0); |
| 190 | 208 | } |
| 191 | 209 | } |
| 192 | 210 | |
| r8885 | r8886 | |
| 202 | 220 | |
| 203 | 221 | WRITE8_DEVICE_HANDLER( riot6532_w ) |
| 204 | 222 | { |
| 205 | | riot6532_state *riot = get_safe_token(device); |
| 223 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 224 | via->reg_w(offset, data); |
| 225 | } |
| 206 | 226 | |
| 227 | void riot6532_device::reg_w(UINT8 offset, UINT8 data) |
| 228 | { |
| 207 | 229 | /* if A4 == 1 and A2 == 1, we are writing to the timer */ |
| 208 | 230 | if ((offset & 0x14) == 0x14) |
| 209 | 231 | { |
| 210 | 232 | static const UINT8 timershift[4] = { 0, 3, 6, 10 }; |
| 211 | | attotime curtime = timer_get_time(device->machine); |
| 233 | attotime curtime = timer_get_time(&m_machine); |
| 212 | 234 | INT64 target; |
| 213 | 235 | |
| 214 | 236 | /* A0-A1 contain the timer divisor */ |
| 215 | | riot->timershift = timershift[offset & 3]; |
| 237 | m_timershift = timershift[offset & 3]; |
| 216 | 238 | |
| 217 | 239 | /* A3 contains the timer IRQ enable */ |
| 218 | 240 | if (offset & 8) |
| 219 | | riot->irqenable |= TIMER_FLAG; |
| 241 | m_irqenable |= TIMER_FLAG; |
| 220 | 242 | else |
| 221 | | riot->irqenable &= ~TIMER_FLAG; |
| 243 | m_irqenable &= ~TIMER_FLAG; |
| 222 | 244 | |
| 223 | 245 | /* writes here clear the timer flag */ |
| 224 | | if (riot->timerstate != TIMER_FINISHING || get_timer(riot) != 0xff) |
| 225 | | riot->irqstate &= ~TIMER_FLAG; |
| 226 | | update_irqstate(device); |
| 246 | if (m_timerstate != TIMER_FINISHING || get_timer() != 0xff) |
| 247 | { |
| 248 | m_irqstate &= ~TIMER_FLAG; |
| 249 | } |
| 250 | update_irqstate(); |
| 227 | 251 | |
| 228 | 252 | /* update the timer */ |
| 229 | | riot->timerstate = TIMER_COUNTING; |
| 230 | | target = attotime_to_ticks(curtime, device->clock()) + 1 + (data << riot->timershift); |
| 231 | | timer_adjust_oneshot(riot->timer, attotime_sub(ticks_to_attotime(target, device->clock()), curtime), 0); |
| 253 | m_timerstate = TIMER_COUNTING; |
| 254 | target = attotime_to_ticks(curtime, clock()) + 1 + (data << m_timershift); |
| 255 | timer_adjust_oneshot(m_timer, attotime_sub(ticks_to_attotime(target, clock()), curtime), 0); |
| 232 | 256 | } |
| 233 | 257 | |
| 234 | 258 | /* if A4 == 0 and A2 == 1, we are writing to the edge detect control */ |
| r8885 | r8886 | |
| 236 | 260 | { |
| 237 | 261 | /* A1 contains the A7 IRQ enable */ |
| 238 | 262 | if (offset & 2) |
| 239 | | riot->irqenable |= PA7_FLAG; |
| 263 | { |
| 264 | m_irqenable |= PA7_FLAG; |
| 265 | } |
| 240 | 266 | else |
| 241 | | riot->irqenable &= ~PA7_FLAG; |
| 267 | { |
| 268 | m_irqenable &= ~PA7_FLAG; |
| 269 | } |
| 242 | 270 | |
| 243 | 271 | /* A0 specifies the edge detect direction: 0=negative, 1=positive */ |
| 244 | | riot->pa7dir = (offset & 1) << 7; |
| 272 | m_pa7dir = (offset & 1) << 7; |
| 245 | 273 | } |
| 246 | 274 | |
| 247 | 275 | /* if A4 == anything and A2 == 0, we are writing to the I/O section */ |
| 248 | 276 | else |
| 249 | 277 | { |
| 250 | 278 | /* A1 selects the port */ |
| 251 | | riot6532_port *port = &riot->port[(offset >> 1) & 1]; |
| 279 | riot6532_port *port = &m_port[(offset >> 1) & 1]; |
| 252 | 280 | |
| 253 | 281 | /* if A0 == 1, we are writing to the port's DDR */ |
| 254 | 282 | if (offset & 1) |
| 255 | | port->ddr = data; |
| 283 | { |
| 284 | port->m_ddr = data; |
| 285 | } |
| 256 | 286 | |
| 257 | 287 | /* if A0 == 0, we are writing to the port's output */ |
| 258 | 288 | else |
| 259 | 289 | { |
| 260 | | port->out = data; |
| 261 | | if (port->out_func.write != NULL) |
| 262 | | devcb_call_write8(&port->out_func, 0, data); |
| 290 | port->m_out = data; |
| 291 | if (port->m_out_func.write != NULL) |
| 292 | { |
| 293 | devcb_call_write8(&port->m_out_func, 0, data); |
| 294 | } |
| 263 | 295 | else |
| 264 | | logerror("%s:6532RIOT chip %s: Port %c is being written to but has no handler. %02X\n", cpuexec_describe_context(device->machine), device->tag(), 'A' + (offset & 1), data); |
| 296 | { |
| 297 | logerror("%s:6532RIOT chip %s: Port %c is being written to but has no handler. %02X\n", cpuexec_describe_context(&m_machine), tag(), 'A' + (offset & 1), data); |
| 298 | } |
| 265 | 299 | } |
| 266 | 300 | |
| 267 | 301 | /* writes to port A need to update the PA7 state */ |
| 268 | | if (port == &riot->port[0]) |
| 269 | | update_pa7_state(device); |
| 302 | if (port == &m_port[0]) |
| 303 | { |
| 304 | update_pa7_state(); |
| 305 | } |
| 270 | 306 | } |
| 271 | 307 | } |
| 272 | 308 | |
| r8885 | r8886 | |
| 277 | 313 | |
| 278 | 314 | READ8_DEVICE_HANDLER( riot6532_r ) |
| 279 | 315 | { |
| 280 | | riot6532_state *riot = get_safe_token(device); |
| 316 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 317 | return via->reg_r(offset); |
| 318 | } |
| 319 | |
| 320 | UINT8 riot6532_device::reg_r(UINT8 offset) |
| 321 | { |
| 281 | 322 | UINT8 val = 0; |
| 282 | 323 | |
| 283 | 324 | /* if A2 == 1 and A0 == 1, we are reading interrupt flags */ |
| 284 | 325 | if ((offset & 0x05) == 0x05) |
| 285 | 326 | { |
| 286 | | val = riot->irqstate; |
| 327 | val = m_irqstate; |
| 287 | 328 | |
| 288 | 329 | /* implicitly clears the PA7 flag */ |
| 289 | | riot->irqstate &= ~PA7_FLAG; |
| 290 | | update_irqstate(device); |
| 330 | m_irqstate &= ~PA7_FLAG; |
| 331 | update_irqstate(); |
| 291 | 332 | } |
| 292 | 333 | |
| 293 | 334 | /* if A2 == 1 and A0 == 0, we are reading the timer */ |
| 294 | 335 | else if ((offset & 0x05) == 0x04) |
| 295 | 336 | { |
| 296 | | val = get_timer(riot); |
| 337 | val = get_timer(); |
| 297 | 338 | |
| 298 | 339 | /* A3 contains the timer IRQ enable */ |
| 299 | 340 | if (offset & 8) |
| 300 | | riot->irqenable |= TIMER_FLAG; |
| 341 | { |
| 342 | m_irqenable |= TIMER_FLAG; |
| 343 | } |
| 301 | 344 | else |
| 302 | | riot->irqenable &= ~TIMER_FLAG; |
| 345 | { |
| 346 | m_irqenable &= ~TIMER_FLAG; |
| 347 | } |
| 303 | 348 | |
| 304 | 349 | /* implicitly clears the timer flag */ |
| 305 | | if (riot->timerstate != TIMER_FINISHING || val != 0xff) |
| 306 | | riot->irqstate &= ~TIMER_FLAG; |
| 307 | | update_irqstate(device); |
| 350 | if (m_timerstate != TIMER_FINISHING || val != 0xff) |
| 351 | { |
| 352 | m_irqstate &= ~TIMER_FLAG; |
| 353 | } |
| 354 | update_irqstate(); |
| 308 | 355 | } |
| 309 | 356 | |
| 310 | 357 | /* if A2 == 0 and A0 == anything, we are reading from ports */ |
| 311 | 358 | else |
| 312 | 359 | { |
| 313 | 360 | /* A1 selects the port */ |
| 314 | | riot6532_port *port = &riot->port[(offset >> 1) & 1]; |
| 361 | riot6532_port *port = &m_port[(offset >> 1) & 1]; |
| 315 | 362 | |
| 316 | 363 | /* if A0 == 1, we are reading the port's DDR */ |
| 317 | 364 | if (offset & 1) |
| 318 | | val = port->ddr; |
| 365 | { |
| 366 | val = port->m_ddr; |
| 367 | } |
| 319 | 368 | |
| 320 | 369 | /* if A0 == 0, we are reading the port as an input */ |
| 321 | 370 | else |
| 322 | 371 | { |
| 323 | 372 | /* call the input callback if it exists */ |
| 324 | | if (port->in_func.read != NULL) |
| 373 | if (port->m_in_func.read != NULL) |
| 325 | 374 | { |
| 326 | | port->in = devcb_call_read8(&port->in_func, 0); |
| 375 | port->m_in = devcb_call_read8(&port->m_in_func, 0); |
| 327 | 376 | |
| 328 | 377 | /* changes to port A need to update the PA7 state */ |
| 329 | | if (port == &riot->port[0]) |
| 330 | | update_pa7_state(device); |
| 378 | if (port == &m_port[0]) |
| 379 | { |
| 380 | update_pa7_state(); |
| 381 | } |
| 331 | 382 | } |
| 332 | 383 | else |
| 333 | | logerror("%s:6532RIOT chip %s: Port %c is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag(), 'A' + (offset & 1)); |
| 384 | { |
| 385 | logerror("%s:6532RIOT chip %s: Port %c is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag(), 'A' + (offset & 1)); |
| 386 | } |
| 334 | 387 | |
| 335 | 388 | /* apply the DDR to the result */ |
| 336 | 389 | val = apply_ddr(port); |
| r8885 | r8886 | |
| 341 | 394 | |
| 342 | 395 | |
| 343 | 396 | /*------------------------------------------------- |
| 344 | | riot6532_porta_in_set - set port A input |
| 345 | | value |
| 397 | porta_in_set - set port A input value |
| 346 | 398 | -------------------------------------------------*/ |
| 347 | 399 | |
| 348 | 400 | void riot6532_porta_in_set(running_device *device, UINT8 data, UINT8 mask) |
| 349 | 401 | { |
| 350 | | riot6532_state *riot = get_safe_token(device); |
| 351 | | riot->port[0].in = (riot->port[0].in & ~mask) | (data & mask); |
| 352 | | update_pa7_state(device); |
| 402 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 403 | via->porta_in_set(data, mask); |
| 353 | 404 | } |
| 354 | 405 | |
| 406 | void riot6532_device::porta_in_set(UINT8 data, UINT8 mask) |
| 407 | { |
| 408 | m_port[0].m_in = (m_port[0].m_in & ~mask) | (data & mask); |
| 409 | update_pa7_state(); |
| 410 | } |
| 355 | 411 | |
| 412 | |
| 356 | 413 | /*------------------------------------------------- |
| 357 | | riot6532_portb_in_set - set port B input |
| 358 | | value |
| 414 | portb_in_set - set port B input value |
| 359 | 415 | -------------------------------------------------*/ |
| 360 | 416 | |
| 361 | 417 | void riot6532_portb_in_set(running_device *device, UINT8 data, UINT8 mask) |
| 362 | 418 | { |
| 363 | | riot6532_state *riot = get_safe_token(device); |
| 364 | | riot->port[1].in = (riot->port[1].in & ~mask) | (data & mask); |
| 419 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 420 | via->portb_in_set(data, mask); |
| 365 | 421 | } |
| 366 | 422 | |
| 423 | void riot6532_device::portb_in_set(UINT8 data, UINT8 mask) |
| 424 | { |
| 425 | m_port[1].m_in = (m_port[1].m_in & ~mask) | (data & mask); |
| 426 | } |
| 367 | 427 | |
| 428 | |
| 368 | 429 | /*------------------------------------------------- |
| 369 | | riot6532_porta_in_get - return port A input |
| 370 | | value |
| 430 | porta_in_get - return port A input value |
| 371 | 431 | -------------------------------------------------*/ |
| 372 | 432 | |
| 373 | 433 | UINT8 riot6532_porta_in_get(running_device *device) |
| 374 | 434 | { |
| 375 | | riot6532_state *riot = get_safe_token(device); |
| 376 | | return riot->port[0].in; |
| 435 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 436 | return via->porta_in_get(); |
| 377 | 437 | } |
| 378 | 438 | |
| 439 | UINT8 riot6532_device::porta_in_get() |
| 440 | { |
| 441 | return m_port[0].m_in; |
| 442 | } |
| 379 | 443 | |
| 444 | |
| 380 | 445 | /*------------------------------------------------- |
| 381 | | riot6532_portb_in_get - return port B input |
| 382 | | value |
| 446 | portb_in_get - return port B input value |
| 383 | 447 | -------------------------------------------------*/ |
| 384 | 448 | |
| 385 | 449 | UINT8 riot6532_portb_in_get(running_device *device) |
| 386 | 450 | { |
| 387 | | riot6532_state *riot = get_safe_token(device); |
| 388 | | return riot->port[1].in; |
| 451 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 452 | return via->portb_in_get(); |
| 389 | 453 | } |
| 390 | 454 | |
| 455 | UINT8 riot6532_device::portb_in_get() |
| 456 | { |
| 457 | return m_port[1].m_in; |
| 458 | } |
| 391 | 459 | |
| 460 | |
| 392 | 461 | /*------------------------------------------------- |
| 393 | | riot6532_porta_in_get - return port A output |
| 394 | | value |
| 462 | porta_in_get - return port A output value |
| 395 | 463 | -------------------------------------------------*/ |
| 396 | 464 | |
| 397 | 465 | UINT8 riot6532_porta_out_get(running_device *device) |
| 398 | 466 | { |
| 399 | | riot6532_state *riot = get_safe_token(device); |
| 400 | | return riot->port[0].out; |
| 467 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 468 | return via->porta_out_get(); |
| 401 | 469 | } |
| 402 | 470 | |
| 471 | UINT8 riot6532_device::porta_out_get() |
| 472 | { |
| 473 | return m_port[0].m_out; |
| 474 | } |
| 403 | 475 | |
| 476 | |
| 404 | 477 | /*------------------------------------------------- |
| 405 | | riot6532_portb_in_get - return port B output |
| 406 | | value |
| 478 | portb_in_get - return port B output value |
| 407 | 479 | -------------------------------------------------*/ |
| 408 | 480 | |
| 409 | 481 | UINT8 riot6532_portb_out_get(running_device *device) |
| 410 | 482 | { |
| 411 | | riot6532_state *riot = get_safe_token(device); |
| 412 | | return riot->port[1].out; |
| 483 | riot6532_device *via = reinterpret_cast<riot6532_device *>(device); |
| 484 | return via->portb_out_get(); |
| 413 | 485 | } |
| 414 | 486 | |
| 487 | UINT8 riot6532_device::portb_out_get() |
| 488 | { |
| 489 | return m_port[1].m_out; |
| 490 | } |
| 415 | 491 | |
| 416 | | /*************************************************************************** |
| 417 | | DEVICE INTERFACE |
| 418 | | ***************************************************************************/ |
| 419 | 492 | |
| 493 | //************************************************************************** |
| 494 | // LIVE DEVICE |
| 495 | //************************************************************************** |
| 496 | |
| 497 | //------------------------------------------------- |
| 498 | // riot6532_device - constructor |
| 499 | //------------------------------------------------- |
| 500 | |
| 501 | riot6532_device::riot6532_device(running_machine &_machine, const riot6532_device_config &config) |
| 502 | : device_t(_machine, config), |
| 503 | m_config(config) |
| 504 | { |
| 505 | } |
| 506 | |
| 420 | 507 | /*------------------------------------------------- |
| 421 | | riot6532_portb_r - return port B output |
| 422 | | value |
| 508 | device_start - device-specific startup |
| 423 | 509 | -------------------------------------------------*/ |
| 424 | 510 | |
| 425 | | static DEVICE_START( riot6532 ) |
| 511 | void riot6532_device::device_start() |
| 426 | 512 | { |
| 427 | | riot6532_state *riot = get_safe_token(device); |
| 428 | | |
| 429 | 513 | /* validate arguments */ |
| 430 | | assert(device != NULL); |
| 514 | assert(this != NULL); |
| 431 | 515 | |
| 432 | 516 | /* set static values */ |
| 433 | | riot->device = device; |
| 434 | | riot->intf = (riot6532_interface *)device->baseconfig().static_config(); |
| 435 | | riot->index = device->machine->m_devicelist.index(RIOT6532, device->tag()); |
| 517 | m_index = m_machine.m_devicelist.index(RIOT6532, tag()); |
| 436 | 518 | |
| 437 | 519 | /* configure the ports */ |
| 438 | | devcb_resolve_read8(&riot->port[0].in_func, &riot->intf->in_a_func, device); |
| 439 | | devcb_resolve_write8(&riot->port[0].out_func, &riot->intf->out_a_func, device); |
| 440 | | devcb_resolve_read8(&riot->port[1].in_func, &riot->intf->in_b_func, device); |
| 441 | | devcb_resolve_write8(&riot->port[1].out_func, &riot->intf->out_b_func, device); |
| 520 | devcb_resolve_read8(&m_port[0].m_in_func, &m_config.m_in_a_func, this); |
| 521 | devcb_resolve_write8(&m_port[0].m_out_func, &m_config.m_out_a_func, this); |
| 522 | devcb_resolve_read8(&m_port[1].m_in_func, &m_config.m_in_b_func, this); |
| 523 | devcb_resolve_write8(&m_port[1].m_out_func, &m_config.m_out_b_func, this); |
| 442 | 524 | |
| 443 | 525 | /* resolve irq func */ |
| 444 | | devcb_resolve_write_line(&riot->irq_func, &riot->intf->irq_func, device); |
| 526 | devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this); |
| 445 | 527 | |
| 446 | 528 | /* allocate timers */ |
| 447 | | riot->timer = timer_alloc(device->machine, timer_end_callback, (void *)device); |
| 529 | m_timer = timer_alloc(&m_machine, timer_end_callback, (void *)this); |
| 448 | 530 | |
| 449 | 531 | /* register for save states */ |
| 450 | | state_save_register_device_item(device, 0, riot->port[0].in); |
| 451 | | state_save_register_device_item(device, 0, riot->port[0].out); |
| 452 | | state_save_register_device_item(device, 0, riot->port[0].ddr); |
| 453 | | state_save_register_device_item(device, 0, riot->port[1].in); |
| 454 | | state_save_register_device_item(device, 0, riot->port[1].out); |
| 455 | | state_save_register_device_item(device, 0, riot->port[1].ddr); |
| 532 | state_save_register_device_item(this, 0, m_port[0].m_in); |
| 533 | state_save_register_device_item(this, 0, m_port[0].m_out); |
| 534 | state_save_register_device_item(this, 0, m_port[0].m_ddr); |
| 535 | state_save_register_device_item(this, 0, m_port[1].m_in); |
| 536 | state_save_register_device_item(this, 0, m_port[1].m_out); |
| 537 | state_save_register_device_item(this, 0, m_port[1].m_ddr); |
| 456 | 538 | |
| 457 | | state_save_register_device_item(device, 0, riot->irqstate); |
| 458 | | state_save_register_device_item(device, 0, riot->irqenable); |
| 539 | state_save_register_device_item(this, 0, m_irqstate); |
| 540 | state_save_register_device_item(this, 0, m_irqenable); |
| 459 | 541 | |
| 460 | | state_save_register_device_item(device, 0, riot->pa7dir); |
| 461 | | state_save_register_device_item(device, 0, riot->pa7prev); |
| 542 | state_save_register_device_item(this, 0, m_pa7dir); |
| 543 | state_save_register_device_item(this, 0, m_pa7prev); |
| 462 | 544 | |
| 463 | | state_save_register_device_item(device, 0, riot->timershift); |
| 464 | | state_save_register_device_item(device, 0, riot->timerstate); |
| 545 | state_save_register_device_item(this, 0, m_timershift); |
| 546 | state_save_register_device_item(this, 0, m_timerstate); |
| 465 | 547 | } |
| 466 | 548 | |
| 467 | 549 | |
| 468 | | static DEVICE_RESET( riot6532 ) |
| 550 | |
| 551 | /*------------------------------------------------- |
| 552 | device_reset - device-specific reset |
| 553 | -------------------------------------------------*/ |
| 554 | |
| 555 | void riot6532_device::device_reset() |
| 469 | 556 | { |
| 470 | | riot6532_state *riot = get_safe_token(device); |
| 471 | | |
| 472 | 557 | /* reset I/O states */ |
| 473 | | riot->port[0].out = 0; |
| 474 | | riot->port[0].ddr = 0; |
| 475 | | riot->port[1].out = 0; |
| 476 | | riot->port[1].ddr = 0; |
| 558 | m_port[0].m_out = 0; |
| 559 | m_port[0].m_ddr = 0; |
| 560 | m_port[1].m_out = 0; |
| 561 | m_port[1].m_ddr = 0; |
| 477 | 562 | |
| 478 | 563 | /* reset IRQ states */ |
| 479 | | riot->irqenable = 0; |
| 480 | | riot->irqstate = 0; |
| 481 | | update_irqstate(device); |
| 564 | m_irqenable = 0; |
| 565 | m_irqstate = 0; |
| 566 | update_irqstate(); |
| 482 | 567 | |
| 483 | 568 | /* reset PA7 states */ |
| 484 | | riot->pa7dir = 0; |
| 485 | | riot->pa7prev = 0; |
| 569 | m_pa7dir = 0; |
| 570 | m_pa7prev = 0; |
| 486 | 571 | |
| 487 | 572 | /* reset timer states */ |
| 488 | | riot->timershift = 0; |
| 489 | | riot->timerstate = TIMER_IDLE; |
| 490 | | timer_adjust_oneshot(riot->timer, attotime_never, 0); |
| 573 | m_timershift = 0; |
| 574 | m_timerstate = TIMER_IDLE; |
| 575 | timer_adjust_oneshot(m_timer, attotime_never, 0); |
| 491 | 576 | } |
| 492 | 577 | |
| 493 | | |
| 494 | | DEVICE_GET_INFO( riot6532 ) |
| 495 | | { |
| 496 | | switch (state) |
| 497 | | { |
| 498 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 499 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(riot6532_state); break; |
| 500 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 501 | | |
| 502 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 503 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(riot6532);break; |
| 504 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 505 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(riot6532);break; |
| 506 | | |
| 507 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 508 | | case DEVINFO_STR_NAME: strcpy(info->s, "6532 (RIOT)"); break; |
| 509 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "I/O devices"); break; |
| 510 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 511 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 512 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 513 | | } |
| 514 | | } |
| 515 | | |
| 516 | | |
| 517 | | DEFINE_LEGACY_DEVICE(RIOT6532, riot6532); |
| 578 | const device_type RIOT6532 = riot6532_device_config::static_alloc_device_config; |
src/emu/machine/6522via.c
| r8885 | r8886 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | /*************************************************************************** |
| 37 | | TYPE DEFINITIONS |
| 38 | | ***************************************************************************/ |
| 39 | | |
| 40 | | /******************* internal VIA data structure *******************/ |
| 41 | | |
| 42 | | typedef struct _via6522_t via6522_t; |
| 43 | | struct _via6522_t |
| 44 | | { |
| 45 | | devcb_resolved_read8 in_a_func; |
| 46 | | devcb_resolved_read8 in_b_func; |
| 47 | | devcb_resolved_read_line in_ca1_func; |
| 48 | | devcb_resolved_read_line in_cb1_func; |
| 49 | | devcb_resolved_read_line in_ca2_func; |
| 50 | | devcb_resolved_read_line in_cb2_func; |
| 51 | | devcb_resolved_write8 out_a_func; |
| 52 | | devcb_resolved_write8 out_b_func; |
| 53 | | devcb_resolved_write_line out_ca1_func; |
| 54 | | devcb_resolved_write_line out_cb1_func; |
| 55 | | devcb_resolved_write_line out_ca2_func; |
| 56 | | devcb_resolved_write_line out_cb2_func; |
| 57 | | devcb_resolved_write_line irq_func; |
| 58 | | |
| 59 | | UINT8 in_a; |
| 60 | | UINT8 in_ca1; |
| 61 | | UINT8 in_ca2; |
| 62 | | UINT8 out_a; |
| 63 | | UINT8 out_ca2; |
| 64 | | UINT8 ddr_a; |
| 65 | | |
| 66 | | UINT8 in_b; |
| 67 | | UINT8 in_cb1; |
| 68 | | UINT8 in_cb2; |
| 69 | | UINT8 out_b; |
| 70 | | UINT8 out_cb2; |
| 71 | | UINT8 ddr_b; |
| 72 | | |
| 73 | | UINT8 t1cl; |
| 74 | | UINT8 t1ch; |
| 75 | | UINT8 t1ll; |
| 76 | | UINT8 t1lh; |
| 77 | | UINT8 t2cl; |
| 78 | | UINT8 t2ch; |
| 79 | | UINT8 t2ll; |
| 80 | | UINT8 t2lh; |
| 81 | | |
| 82 | | UINT8 sr; |
| 83 | | UINT8 pcr; |
| 84 | | UINT8 acr; |
| 85 | | UINT8 ier; |
| 86 | | UINT8 ifr; |
| 87 | | |
| 88 | | emu_timer *t1; |
| 89 | | attotime time1; |
| 90 | | UINT8 t1_active; |
| 91 | | emu_timer *t2; |
| 92 | | attotime time2; |
| 93 | | UINT8 t2_active; |
| 94 | | |
| 95 | | emu_timer *shift_timer; |
| 96 | | UINT8 shift_counter; |
| 97 | | }; |
| 98 | | |
| 99 | | |
| 100 | | /*************************************************************************** |
| 101 | 37 | MACROS |
| 102 | 38 | ***************************************************************************/ |
| 103 | 39 | |
| r8885 | r8886 | |
| 159 | 95 | #define INT_T1 0x40 |
| 160 | 96 | #define INT_ANY 0x80 |
| 161 | 97 | |
| 162 | | #define CLR_PA_INT(device) via_clear_int (device, INT_CA1 | ((!CA2_IND_IRQ(get_token(device)->pcr)) ? INT_CA2: 0)) |
| 163 | | #define CLR_PB_INT(device) via_clear_int (device, INT_CB1 | ((!CB2_IND_IRQ(get_token(device)->pcr)) ? INT_CB2: 0)) |
| 98 | #define CLR_PA_INT() clear_int(INT_CA1 | ((!CA2_IND_IRQ(m_pcr)) ? INT_CA2: 0)) |
| 99 | #define CLR_PB_INT() clear_int(INT_CB1 | ((!CB2_IND_IRQ(m_pcr)) ? INT_CB2: 0)) |
| 164 | 100 | |
| 165 | 101 | #define IFR_DELAY 3 |
| 166 | 102 | |
| 167 | | #define TIMER1_VALUE(v) (v->t1ll+(v->t1lh<<8)) |
| 168 | | #define TIMER2_VALUE(v) (v->t2ll+(v->t2lh<<8)) |
| 103 | #define TIMER1_VALUE (m_t1ll+(m_t1lh<<8)) |
| 104 | #define TIMER2_VALUE (m_t2ll+(m_t2lh<<8)) |
| 169 | 105 | |
| 170 | | /*************************************************************************** |
| 171 | | PROTOTYPES |
| 172 | | ***************************************************************************/ |
| 173 | 106 | |
| 174 | | static TIMER_CALLBACK( via_shift_callback ); |
| 175 | | static TIMER_CALLBACK( via_t1_timeout ); |
| 176 | | static TIMER_CALLBACK( via_t2_timeout ); |
| 177 | 107 | |
| 108 | //************************************************************************** |
| 109 | // DEVICE CONFIGURATION |
| 110 | //************************************************************************** |
| 178 | 111 | |
| 179 | | /*************************************************************************** |
| 180 | | INLINE FUNCTIONS |
| 181 | | ***************************************************************************/ |
| 112 | //------------------------------------------------- |
| 113 | // via6522_device_config - constructor |
| 114 | //------------------------------------------------- |
| 182 | 115 | |
| 183 | | INLINE via6522_t *get_token(running_device *device) |
| 116 | via6522_device_config::via6522_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 117 | : device_config(mconfig, static_alloc_device_config, "VIA6522", tag, owner, clock) |
| 184 | 118 | { |
| 185 | | assert(device != NULL); |
| 186 | | assert((device->type() == VIA6522)); |
| 187 | | return (via6522_t *) downcast<legacy_device_base *>(device)->token(); |
| 188 | 119 | } |
| 189 | 120 | |
| 190 | 121 | |
| 191 | | INLINE const via6522_interface *get_interface(running_device *device) |
| 122 | //------------------------------------------------- |
| 123 | // static_alloc_device_config - allocate a new |
| 124 | // configuration object |
| 125 | //------------------------------------------------- |
| 126 | |
| 127 | device_config *via6522_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 192 | 128 | { |
| 193 | | assert(device != NULL); |
| 194 | | assert((device->type() == VIA6522)); |
| 195 | | return (const via6522_interface *) device->baseconfig().static_config(); |
| 129 | return global_alloc(via6522_device_config(mconfig, tag, owner, clock)); |
| 196 | 130 | } |
| 197 | 131 | |
| 198 | 132 | |
| 199 | | INLINE attotime v_cycles_to_time(running_device *device, int c) |
| 133 | //------------------------------------------------- |
| 134 | // alloc_device - allocate a new device object |
| 135 | //------------------------------------------------- |
| 136 | |
| 137 | device_t *via6522_device_config::alloc_device(running_machine &machine) const |
| 200 | 138 | { |
| 201 | | return attotime_mul(ATTOTIME_IN_HZ(device->clock()), c); |
| 139 | return auto_alloc(&machine, via6522_device(machine, *this)); |
| 202 | 140 | } |
| 203 | 141 | |
| 204 | 142 | |
| 205 | | INLINE UINT32 v_time_to_cycles(running_device *device, attotime t) |
| 143 | //------------------------------------------------- |
| 144 | // device_config_complete - perform any |
| 145 | // operations now that the configuration is |
| 146 | // complete |
| 147 | //------------------------------------------------- |
| 148 | |
| 149 | void via6522_device_config::device_config_complete() |
| 206 | 150 | { |
| 207 | | return attotime_to_double(attotime_mul(t, device->clock())); |
| 151 | |
| 208 | 152 | } |
| 209 | 153 | |
| 210 | 154 | |
| 211 | | INLINE UINT16 v_get_counter1_value(running_device *device) |
| 155 | |
| 156 | /*************************************************************************** |
| 157 | INLINE FUNCTIONS |
| 158 | ***************************************************************************/ |
| 159 | |
| 160 | attotime via6522_device::cycles_to_time(int c) |
| 212 | 161 | { |
| 213 | | via6522_t *v = get_token(device); |
| 162 | return attotime_mul(ATTOTIME_IN_HZ(clock()), c); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | UINT32 via6522_device::time_to_cycles(attotime t) |
| 167 | { |
| 168 | return attotime_to_double(attotime_mul(t, clock())); |
| 169 | } |
| 170 | |
| 171 | |
| 172 | UINT16 via6522_device::get_counter1_value() |
| 173 | { |
| 214 | 174 | UINT16 val; |
| 215 | 175 | |
| 216 | | if (v->t1_active) { |
| 217 | | val = v_time_to_cycles(device, timer_timeleft(v->t1)) - IFR_DELAY; |
| 218 | | } else { |
| 219 | | val = 0xFFFF - v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time1)); |
| 176 | if(m_t1_active) |
| 177 | { |
| 178 | val = time_to_cycles(timer_timeleft(m_t1)) - IFR_DELAY; |
| 220 | 179 | } |
| 180 | else |
| 181 | { |
| 182 | val = 0xffff - time_to_cycles(attotime_sub(timer_get_time(&m_machine), m_time1)); |
| 183 | } |
| 184 | |
| 221 | 185 | return val; |
| 222 | 186 | } |
| 223 | 187 | |
| 224 | 188 | |
| 225 | | /*************************************************************************** |
| 226 | | IMPLEMENTATION |
| 227 | | ***************************************************************************/ |
| 189 | //************************************************************************** |
| 190 | // LIVE DEVICE |
| 191 | //************************************************************************** |
| 228 | 192 | |
| 229 | | /*------------------------------------------------- |
| 230 | | DEVICE_START( via6522 ) |
| 231 | | -------------------------------------------------*/ |
| 193 | //------------------------------------------------- |
| 194 | // via6522_device - constructor |
| 195 | //------------------------------------------------- |
| 232 | 196 | |
| 233 | | static DEVICE_START( via6522 ) |
| 197 | via6522_device::via6522_device(running_machine &_machine, const via6522_device_config &config) |
| 198 | : device_t(_machine, config), |
| 199 | m_config(config) |
| 234 | 200 | { |
| 235 | | via6522_t *v = get_token(device); |
| 236 | | const via6522_interface *intf = get_interface(device); |
| 237 | 201 | |
| 238 | | memset(v, 0, sizeof(*v)); |
| 202 | } |
| 239 | 203 | |
| 240 | | devcb_resolve_read8(&v->in_a_func, &intf->in_a_func, device); |
| 241 | | devcb_resolve_read8(&v->in_b_func, &intf->in_b_func, device); |
| 242 | | devcb_resolve_read_line(&v->in_ca1_func, &intf->in_ca1_func, device); |
| 243 | | devcb_resolve_read_line(&v->in_cb1_func, &intf->in_cb1_func, device); |
| 244 | | devcb_resolve_read_line(&v->in_ca2_func, &intf->in_ca2_func, device); |
| 245 | | devcb_resolve_read_line(&v->in_cb2_func, &intf->in_cb2_func, device); |
| 246 | | devcb_resolve_write8(&v->out_a_func, &intf->out_a_func, device); |
| 247 | | devcb_resolve_write8(&v->out_b_func, &intf->out_b_func, device); |
| 248 | | devcb_resolve_write_line(&v->out_ca1_func, &intf->out_ca1_func, device); |
| 249 | | devcb_resolve_write_line(&v->out_cb1_func, &intf->out_cb1_func, device); |
| 250 | | devcb_resolve_write_line(&v->out_ca2_func, &intf->out_ca2_func, device); |
| 251 | | devcb_resolve_write_line(&v->out_cb2_func, &intf->out_cb2_func, device); |
| 252 | | devcb_resolve_write_line(&v->irq_func, &intf->irq_func, device); |
| 204 | //------------------------------------------------- |
| 205 | // device_start - device-specific startup |
| 206 | //------------------------------------------------- |
| 253 | 207 | |
| 254 | | v->t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */ |
| 255 | | v->t1lh = 0xb5; /* ports are not written by kernel! */ |
| 256 | | v->t2ll = 0xff; /* taken from vice */ |
| 257 | | v->t2lh = 0xff; |
| 258 | | v->time2 = v->time1 = timer_get_time(device->machine); |
| 259 | | v->t1 = timer_alloc(device->machine, via_t1_timeout, (void *) device); |
| 260 | | v->t2 = timer_alloc(device->machine, via_t2_timeout, (void *) device); |
| 261 | | v->shift_timer = timer_alloc(device->machine, via_shift_callback, (void *) device); |
| 208 | void via6522_device::device_start() |
| 209 | { |
| 210 | devcb_resolve_read8(&m_in_a_func, &m_config.m_in_a_func, this); |
| 211 | devcb_resolve_read8(&m_in_b_func, &m_config.m_in_b_func, this); |
| 212 | devcb_resolve_read_line(&m_in_ca1_func, &m_config.m_in_ca1_func, this); |
| 213 | devcb_resolve_read_line(&m_in_cb1_func, &m_config.m_in_cb1_func, this); |
| 214 | devcb_resolve_read_line(&m_in_ca2_func, &m_config.m_in_ca2_func, this); |
| 215 | devcb_resolve_read_line(&m_in_cb2_func, &m_config.m_in_cb2_func, this); |
| 216 | devcb_resolve_write8(&m_out_a_func, &m_config.m_out_a_func, this); |
| 217 | devcb_resolve_write8(&m_out_b_func, &m_config.m_out_b_func, this); |
| 218 | devcb_resolve_write_line(&m_out_ca1_func, &m_config.m_out_ca1_func, this); |
| 219 | devcb_resolve_write_line(&m_out_cb1_func, &m_config.m_out_cb1_func, this); |
| 220 | devcb_resolve_write_line(&m_out_ca2_func, &m_config.m_out_ca2_func, this); |
| 221 | devcb_resolve_write_line(&m_out_cb2_func, &m_config.m_out_cb2_func, this); |
| 222 | devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this); |
| 262 | 223 | |
| 224 | m_t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */ |
| 225 | m_t1lh = 0xb5; /* ports are not written by kernel! */ |
| 226 | m_t2ll = 0xff; /* taken from vice */ |
| 227 | m_t2lh = 0xff; |
| 228 | m_time2 = m_time1 = timer_get_time(&m_machine); |
| 229 | m_t1 = timer_alloc(&m_machine, t1_timeout_callback, 0); |
| 230 | m_t2 = timer_alloc(&m_machine, t2_timeout_callback, 0); |
| 231 | m_shift_timer = timer_alloc(&m_machine, shift_callback, 0); |
| 232 | |
| 263 | 233 | /* Default clock is from CPU1 */ |
| 264 | | if (device->clock() == 0) |
| 265 | | device->set_unscaled_clock(device->machine->firstcpu->clock()); |
| 234 | if (clock() == 0) |
| 235 | { |
| 236 | set_unscaled_clock(m_machine.firstcpu->clock()); |
| 237 | } |
| 266 | 238 | |
| 267 | 239 | /* save state register */ |
| 268 | | state_save_register_device_item(device, 0, v->in_a); |
| 269 | | state_save_register_device_item(device, 0, v->in_ca1); |
| 270 | | state_save_register_device_item(device, 0, v->in_ca2); |
| 271 | | state_save_register_device_item(device, 0, v->out_a); |
| 272 | | state_save_register_device_item(device, 0, v->out_ca2); |
| 273 | | state_save_register_device_item(device, 0, v->ddr_a); |
| 274 | | state_save_register_device_item(device, 0, v->in_b); |
| 275 | | state_save_register_device_item(device, 0, v->in_cb1); |
| 276 | | state_save_register_device_item(device, 0, v->in_cb2); |
| 277 | | state_save_register_device_item(device, 0, v->out_b); |
| 278 | | state_save_register_device_item(device, 0, v->out_cb2); |
| 279 | | state_save_register_device_item(device, 0, v->ddr_b); |
| 280 | | state_save_register_device_item(device, 0, v->t1cl); |
| 281 | | state_save_register_device_item(device, 0, v->t1ch); |
| 282 | | state_save_register_device_item(device, 0, v->t1ll); |
| 283 | | state_save_register_device_item(device, 0, v->t1lh); |
| 284 | | state_save_register_device_item(device, 0, v->t2cl); |
| 285 | | state_save_register_device_item(device, 0, v->t2ch); |
| 286 | | state_save_register_device_item(device, 0, v->t2ll); |
| 287 | | state_save_register_device_item(device, 0, v->t2lh); |
| 288 | | state_save_register_device_item(device, 0, v->sr); |
| 289 | | state_save_register_device_item(device, 0, v->pcr); |
| 290 | | state_save_register_device_item(device, 0, v->acr); |
| 291 | | state_save_register_device_item(device, 0, v->ier); |
| 292 | | state_save_register_device_item(device, 0, v->ifr); |
| 293 | | state_save_register_device_item(device, 0, v->t1_active); |
| 294 | | state_save_register_device_item(device, 0, v->t2_active); |
| 295 | | state_save_register_device_item(device, 0, v->shift_counter); |
| 240 | state_save_register_device_item(this, 0, m_in_a); |
| 241 | state_save_register_device_item(this, 0, m_in_ca1); |
| 242 | state_save_register_device_item(this, 0, m_in_ca2); |
| 243 | state_save_register_device_item(this, 0, m_out_a); |
| 244 | state_save_register_device_item(this, 0, m_out_ca2); |
| 245 | state_save_register_device_item(this, 0, m_ddr_a); |
| 246 | state_save_register_device_item(this, 0, m_in_b); |
| 247 | state_save_register_device_item(this, 0, m_in_cb1); |
| 248 | state_save_register_device_item(this, 0, m_in_cb2); |
| 249 | state_save_register_device_item(this, 0, m_out_b); |
| 250 | state_save_register_device_item(this, 0, m_out_cb2); |
| 251 | state_save_register_device_item(this, 0, m_ddr_b); |
| 252 | state_save_register_device_item(this, 0, m_t1cl); |
| 253 | state_save_register_device_item(this, 0, m_t1ch); |
| 254 | state_save_register_device_item(this, 0, m_t1ll); |
| 255 | state_save_register_device_item(this, 0, m_t1lh); |
| 256 | state_save_register_device_item(this, 0, m_t2cl); |
| 257 | state_save_register_device_item(this, 0, m_t2ch); |
| 258 | state_save_register_device_item(this, 0, m_t2ll); |
| 259 | state_save_register_device_item(this, 0, m_t2lh); |
| 260 | state_save_register_device_item(this, 0, m_sr); |
| 261 | state_save_register_device_item(this, 0, m_pcr); |
| 262 | state_save_register_device_item(this, 0, m_acr); |
| 263 | state_save_register_device_item(this, 0, m_ier); |
| 264 | state_save_register_device_item(this, 0, m_ifr); |
| 265 | state_save_register_device_item(this, 0, m_t1_active); |
| 266 | state_save_register_device_item(this, 0, m_t2_active); |
| 267 | state_save_register_device_item(this, 0, m_shift_counter); |
| 296 | 268 | } |
| 297 | 269 | |
| 298 | 270 | |
| r8885 | r8886 | |
| 300 | 272 | via_set_int - external interrupt check |
| 301 | 273 | -------------------------------------------------*/ |
| 302 | 274 | |
| 303 | | static void via_set_int (running_device *device, int data) |
| 275 | void via6522_device::set_int(int data) |
| 304 | 276 | { |
| 305 | | via6522_t *v = get_token(device); |
| 306 | | |
| 307 | | v->ifr |= data; |
| 277 | m_ifr |= data; |
| 308 | 278 | if (TRACE_VIA) |
| 309 | | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(device->machine), device->tag(), v->ifr); |
| 279 | { |
| 280 | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(&m_machine), tag(), m_ifr); |
| 281 | } |
| 310 | 282 | |
| 311 | | if (v->ier & v->ifr) |
| 283 | if (m_ier & m_ifr) |
| 312 | 284 | { |
| 313 | | v->ifr |= INT_ANY; |
| 314 | | devcb_call_write_line(&v->irq_func, ASSERT_LINE); |
| 285 | m_ifr |= INT_ANY; |
| 286 | devcb_call_write_line(&m_irq_func, ASSERT_LINE); |
| 315 | 287 | } |
| 316 | 288 | } |
| 317 | 289 | |
| r8885 | r8886 | |
| 320 | 292 | via_clear_int - external interrupt check |
| 321 | 293 | -------------------------------------------------*/ |
| 322 | 294 | |
| 323 | | static void via_clear_int (running_device *device, int data) |
| 295 | void via6522_device::clear_int(int data) |
| 324 | 296 | { |
| 325 | | via6522_t *v = get_token(device); |
| 297 | m_ifr = (m_ifr & ~data) & 0x7f; |
| 326 | 298 | |
| 327 | | v->ifr = (v->ifr & ~data) & 0x7f; |
| 328 | | |
| 329 | 299 | if (TRACE_VIA) |
| 330 | | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(device->machine), device->tag(), v->ifr); |
| 300 | { |
| 301 | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(&m_machine), tag(), m_ifr); |
| 302 | } |
| 331 | 303 | |
| 332 | | if (v->ifr & v->ier) |
| 333 | | v->ifr |= INT_ANY; |
| 304 | if (m_ifr & m_ier) |
| 305 | { |
| 306 | m_ifr |= INT_ANY; |
| 307 | } |
| 334 | 308 | else |
| 335 | 309 | { |
| 336 | | devcb_call_write_line(&v->irq_func, CLEAR_LINE); |
| 310 | devcb_call_write_line(&m_irq_func, CLEAR_LINE); |
| 337 | 311 | } |
| 338 | 312 | } |
| 339 | 313 | |
| r8885 | r8886 | |
| 342 | 316 | via_shift |
| 343 | 317 | -------------------------------------------------*/ |
| 344 | 318 | |
| 345 | | static void via_shift(running_device *device) |
| 319 | void via6522_device::shift() |
| 346 | 320 | { |
| 347 | | via6522_t *v = get_token(device); |
| 348 | | |
| 349 | | if (SO_O2_CONTROL(v->acr)) |
| 321 | if (SO_O2_CONTROL(m_acr)) |
| 350 | 322 | { |
| 351 | | v->out_cb2 = (v->sr >> 7) & 1; |
| 352 | | v->sr = (v->sr << 1) | v->out_cb2; |
| 323 | m_out_cb2 = (m_sr >> 7) & 1; |
| 324 | m_sr = (m_sr << 1) | m_out_cb2; |
| 353 | 325 | |
| 354 | | devcb_call_write_line(&v->out_cb2_func, v->out_cb2); |
| 326 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 355 | 327 | |
| 356 | | v->in_cb1=1; |
| 328 | m_in_cb1=1; |
| 357 | 329 | |
| 358 | 330 | /* this should be one cycle wide */ |
| 359 | | devcb_call_write_line(&v->out_cb1_func, 0); |
| 360 | | devcb_call_write_line(&v->out_cb1_func, 1); |
| 331 | devcb_call_write_line(&m_out_cb1_func, 0); |
| 332 | devcb_call_write_line(&m_out_cb1_func, 1); |
| 361 | 333 | |
| 362 | | v->shift_counter = (v->shift_counter + 1) % 8; |
| 334 | m_shift_counter = (m_shift_counter + 1) % 8; |
| 363 | 335 | |
| 364 | | if (v->shift_counter) |
| 365 | | timer_adjust_oneshot(v->shift_timer, v_cycles_to_time(device, 2), 0); |
| 336 | if (m_shift_counter) |
| 337 | { |
| 338 | timer_adjust_oneshot(m_shift_timer, cycles_to_time(2), 0); |
| 339 | } |
| 366 | 340 | else |
| 367 | 341 | { |
| 368 | | if (!(v->ifr & INT_SR)) |
| 369 | | via_set_int(device, INT_SR); |
| 342 | if (!(m_ifr & INT_SR)) |
| 343 | { |
| 344 | set_int(INT_SR); |
| 345 | } |
| 370 | 346 | } |
| 371 | 347 | } |
| 372 | | if (SO_EXT_CONTROL(v->acr)) |
| 348 | if (SO_EXT_CONTROL(m_acr)) |
| 373 | 349 | { |
| 374 | | v->out_cb2 = (v->sr >> 7) & 1; |
| 375 | | v->sr = (v->sr << 1) | v->out_cb2; |
| 350 | m_out_cb2 = (m_sr >> 7) & 1; |
| 351 | m_sr = (m_sr << 1) | m_out_cb2; |
| 376 | 352 | |
| 377 | | devcb_call_write_line(&v->out_cb2_func, v->out_cb2); |
| 353 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 378 | 354 | |
| 379 | | v->shift_counter = (v->shift_counter + 1) % 8; |
| 355 | m_shift_counter = (m_shift_counter + 1) % 8; |
| 380 | 356 | |
| 381 | | if (v->shift_counter == 0) |
| 357 | if (m_shift_counter == 0) |
| 382 | 358 | { |
| 383 | | if (!(v->ifr & INT_SR)) |
| 384 | | via_set_int(device, INT_SR); |
| 359 | if (!(m_ifr & INT_SR)) |
| 360 | { |
| 361 | set_int(INT_SR); |
| 362 | } |
| 385 | 363 | } |
| 386 | 364 | } |
| 387 | | if (SI_EXT_CONTROL(v->acr)) |
| 365 | if (SI_EXT_CONTROL(m_acr)) |
| 388 | 366 | { |
| 389 | | if (v->in_cb2_func.read != NULL) |
| 390 | | v->in_cb2 = devcb_call_read_line(&v->in_cb2_func); |
| 367 | if (m_in_cb2_func.read != NULL) |
| 368 | { |
| 369 | m_in_cb2 = devcb_call_read_line(&m_in_cb2_func); |
| 370 | } |
| 391 | 371 | |
| 392 | | v->sr = (v->sr << 1) | (v->in_cb2 & 1); |
| 372 | m_sr = (m_sr << 1) | (m_in_cb2 & 1); |
| 393 | 373 | |
| 394 | | v->shift_counter = (v->shift_counter + 1) % 8; |
| 374 | m_shift_counter = (m_shift_counter + 1) % 8; |
| 395 | 375 | |
| 396 | | if (v->shift_counter == 0) |
| 376 | if (m_shift_counter == 0) |
| 397 | 377 | { |
| 398 | | if (!(v->ifr & INT_SR)) |
| 378 | if (!(m_ifr & INT_SR)) |
| 399 | 379 | { |
| 400 | | via_set_int(device, INT_SR); |
| 380 | set_int(INT_SR); |
| 401 | 381 | } |
| 402 | 382 | } |
| 403 | 383 | } |
| r8885 | r8886 | |
| 408 | 388 | TIMER_CALLBACK( via_shift_callback ) |
| 409 | 389 | -------------------------------------------------*/ |
| 410 | 390 | |
| 411 | | static TIMER_CALLBACK( via_shift_callback ) |
| 391 | TIMER_CALLBACK( via6522_device::shift_callback ) |
| 412 | 392 | { |
| 413 | | running_device *device = (running_device *)ptr; |
| 414 | | via_shift(device); |
| 393 | via6522_device *via = reinterpret_cast<via6522_device *>(ptr); |
| 394 | via->shift(); |
| 415 | 395 | } |
| 416 | 396 | |
| 417 | 397 | |
| r8885 | r8886 | |
| 419 | 399 | TIMER_CALLBACK( via_t1_timeout ) |
| 420 | 400 | -------------------------------------------------*/ |
| 421 | 401 | |
| 422 | | static TIMER_CALLBACK( via_t1_timeout ) |
| 402 | TIMER_CALLBACK( via6522_device::t1_timeout_callback ) |
| 423 | 403 | { |
| 424 | | running_device *device = (running_device *)ptr; |
| 425 | | via6522_t *v = get_token(device); |
| 404 | via6522_device *via = reinterpret_cast<via6522_device *>(ptr); |
| 405 | via->t1_timeout(); |
| 406 | } |
| 426 | 407 | |
| 427 | | if (T1_CONTINUOUS (v->acr)) |
| 408 | void via6522_device::t1_timeout() |
| 409 | { |
| 410 | if (T1_CONTINUOUS (m_acr)) |
| 428 | 411 | { |
| 429 | | if (T1_SET_PB7(v->acr)) |
| 430 | | v->out_b ^= 0x80; |
| 431 | | timer_adjust_oneshot(v->t1, v_cycles_to_time(device, TIMER1_VALUE(v) + IFR_DELAY), 0); |
| 412 | if (T1_SET_PB7(m_acr)) |
| 413 | { |
| 414 | m_out_b ^= 0x80; |
| 415 | } |
| 416 | timer_adjust_oneshot(m_t1, cycles_to_time(TIMER1_VALUE + IFR_DELAY), 0); |
| 432 | 417 | } |
| 433 | 418 | else |
| 434 | 419 | { |
| 435 | | if (T1_SET_PB7(v->acr)) |
| 436 | | v->out_b |= 0x80; |
| 437 | | v->t1_active = 0; |
| 438 | | v->time1 = timer_get_time(device->machine); |
| 420 | if (T1_SET_PB7(m_acr)) |
| 421 | { |
| 422 | m_out_b |= 0x80; |
| 423 | } |
| 424 | m_t1_active = 0; |
| 425 | m_time1 = timer_get_time(&m_machine); |
| 439 | 426 | } |
| 440 | | if (v->ddr_b) |
| 427 | if (m_ddr_b) |
| 441 | 428 | { |
| 442 | | UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); |
| 443 | | devcb_call_write8(&v->out_b_func, 0, write_data); |
| 429 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 430 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 444 | 431 | } |
| 445 | 432 | |
| 446 | | if (!(v->ifr & INT_T1)) |
| 447 | | via_set_int (device, INT_T1); |
| 433 | if (!(m_ifr & INT_T1)) |
| 434 | { |
| 435 | set_int(INT_T1); |
| 436 | } |
| 448 | 437 | } |
| 449 | 438 | |
| 450 | 439 | |
| r8885 | r8886 | |
| 452 | 441 | TIMER_CALLBACK( via_t2_timeout ) |
| 453 | 442 | -------------------------------------------------*/ |
| 454 | 443 | |
| 455 | | static TIMER_CALLBACK( via_t2_timeout ) |
| 444 | TIMER_CALLBACK( via6522_device::t2_timeout_callback ) |
| 456 | 445 | { |
| 457 | | running_device *device = (running_device *)ptr; |
| 458 | | via6522_t *v = get_token(device); |
| 446 | via6522_device *via = reinterpret_cast<via6522_device *>(ptr); |
| 447 | via->t2_timeout(); |
| 448 | } |
| 459 | 449 | |
| 460 | | v->t2_active = 0; |
| 461 | | v->time2 = timer_get_time(device->machine); |
| 450 | void via6522_device::t2_timeout() |
| 451 | { |
| 452 | m_t2_active = 0; |
| 453 | m_time2 = timer_get_time(&m_machine); |
| 462 | 454 | |
| 463 | | if (!(v->ifr & INT_T2)) |
| 464 | | via_set_int (device, INT_T2); |
| 455 | if (!(m_ifr & INT_T2)) |
| 456 | { |
| 457 | set_int(INT_T2); |
| 458 | } |
| 465 | 459 | } |
| 466 | 460 | |
| 467 | 461 | |
| 468 | | /*------------------------------------------------- |
| 469 | | DEVICE_RESET( via6522 ) |
| 470 | | -------------------------------------------------*/ |
| 462 | //------------------------------------------------- |
| 463 | // device_reset - device-specific reset |
| 464 | //------------------------------------------------- |
| 471 | 465 | |
| 472 | | static DEVICE_RESET( via6522 ) |
| 466 | void via6522_device::device_reset() |
| 473 | 467 | { |
| 474 | | via6522_t *v = get_token(device); |
| 475 | | v->in_a = 0; |
| 476 | | v->in_ca1 = 0; |
| 477 | | v->in_ca2 = 0; |
| 478 | | v->out_a = 0; |
| 479 | | v->out_ca2 = 0; |
| 480 | | v->ddr_a = 0; |
| 481 | | v->in_b = 0; |
| 482 | | v->in_cb1 = 0; |
| 483 | | v->in_cb2 = 0; |
| 484 | | v->out_b = 0; |
| 485 | | v->out_cb2 = 0; |
| 486 | | v->ddr_b = 0; |
| 468 | m_in_a = 0; |
| 469 | m_in_ca1 = 0; |
| 470 | m_in_ca2 = 0; |
| 471 | m_out_a = 0; |
| 472 | m_out_ca2 = 0; |
| 473 | m_ddr_a = 0; |
| 474 | m_in_b = 0; |
| 475 | m_in_cb1 = 0; |
| 476 | m_in_cb2 = 0; |
| 477 | m_out_b = 0; |
| 478 | m_out_cb2 = 0; |
| 479 | m_ddr_b = 0; |
| 487 | 480 | |
| 488 | | v->t1cl = 0; |
| 489 | | v->t1ch = 0; |
| 490 | | v->t2cl = 0; |
| 491 | | v->t2ch = 0; |
| 481 | m_t1cl = 0; |
| 482 | m_t1ch = 0; |
| 483 | m_t2cl = 0; |
| 484 | m_t2ch = 0; |
| 492 | 485 | |
| 493 | | v->sr = 0; |
| 494 | | v->pcr = 0; |
| 495 | | v->acr = 0; |
| 496 | | v->ier = 0; |
| 497 | | v->ifr = 0; |
| 498 | | v->t1_active = 0; |
| 499 | | v->t2_active = 0; |
| 500 | | v->shift_counter = 0; |
| 486 | m_sr = 0; |
| 487 | m_pcr = 0; |
| 488 | m_acr = 0; |
| 489 | m_ier = 0; |
| 490 | m_ifr = 0; |
| 491 | m_t1_active = 0; |
| 492 | m_t2_active = 0; |
| 493 | m_shift_counter = 0; |
| 501 | 494 | } |
| 502 | 495 | |
| 503 | 496 | |
| r8885 | r8886 | |
| 507 | 500 | |
| 508 | 501 | READ8_DEVICE_HANDLER(via_r) |
| 509 | 502 | { |
| 510 | | via6522_t *v = get_token(device); |
| 503 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 504 | return via->reg_r(offset); |
| 505 | } |
| 506 | |
| 507 | UINT8 via6522_device::reg_r(UINT8 offset) |
| 508 | { |
| 511 | 509 | int val = 0; |
| 512 | 510 | |
| 513 | 511 | offset &= 0xf; |
| r8885 | r8886 | |
| 516 | 514 | { |
| 517 | 515 | case VIA_PB: |
| 518 | 516 | /* update the input */ |
| 519 | | if (PB_LATCH_ENABLE(v->acr) == 0) |
| 517 | if (PB_LATCH_ENABLE(m_acr) == 0) |
| 520 | 518 | { |
| 521 | | if (v->ddr_b != 0xff) |
| 519 | if (m_ddr_b != 0xff) |
| 522 | 520 | { |
| 523 | | if (v->in_b_func.read != NULL) |
| 524 | | v->in_b = devcb_call_read8(&v->in_b_func, 0); |
| 521 | if (m_in_b_func.read != NULL) |
| 522 | { |
| 523 | m_in_b = devcb_call_read8(&m_in_b_func, 0); |
| 524 | } |
| 525 | 525 | else |
| 526 | | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 526 | { |
| 527 | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 528 | } |
| 527 | 529 | } |
| 528 | 530 | } |
| 529 | 531 | |
| 530 | | CLR_PB_INT(device); |
| 532 | CLR_PB_INT(); |
| 531 | 533 | |
| 532 | 534 | /* combine input and output values, hold DDRB bit 7 high if T1_SET_PB7 */ |
| 533 | | if (T1_SET_PB7(v->acr)) |
| 534 | | val = (v->out_b & (v->ddr_b | 0x80)) | (v->in_b & ~(v->ddr_b | 0x80)); |
| 535 | if (T1_SET_PB7(m_acr)) |
| 536 | { |
| 537 | val = (m_out_b & (m_ddr_b | 0x80)) | (m_in_b & ~(m_ddr_b | 0x80)); |
| 538 | } |
| 535 | 539 | else |
| 536 | | val = (v->out_b & v->ddr_b) + (v->in_b & ~v->ddr_b); |
| 540 | { |
| 541 | val = (m_out_b & m_ddr_b) + (m_in_b & ~m_ddr_b); |
| 542 | } |
| 537 | 543 | break; |
| 538 | 544 | |
| 539 | 545 | case VIA_PA: |
| 540 | 546 | /* update the input */ |
| 541 | | if (PA_LATCH_ENABLE(v->acr) == 0) |
| 547 | if (PA_LATCH_ENABLE(m_acr) == 0) |
| 542 | 548 | { |
| 543 | | if (v->ddr_a != 0xff) |
| 549 | if (m_ddr_a != 0xff) |
| 544 | 550 | { |
| 545 | | if (v->in_a_func.read != NULL) |
| 546 | | v->in_a = devcb_call_read8(&v->in_a_func, 0); |
| 551 | if (m_in_a_func.read != NULL) |
| 552 | { |
| 553 | m_in_a = devcb_call_read8(&m_in_a_func, 0); |
| 554 | } |
| 547 | 555 | else |
| 548 | | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 556 | { |
| 557 | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 558 | } |
| 549 | 559 | } |
| 550 | 560 | } |
| 551 | 561 | |
| 552 | 562 | /* combine input and output values */ |
| 553 | | val = (v->out_a & v->ddr_a) + (v->in_a & ~v->ddr_a); |
| 563 | val = (m_out_a & m_ddr_a) + (m_in_a & ~m_ddr_a); |
| 554 | 564 | |
| 555 | | CLR_PA_INT(device); |
| 565 | CLR_PA_INT(); |
| 556 | 566 | |
| 557 | 567 | /* If CA2 is configured as output and in pulse or handshake mode, |
| 558 | 568 | CA2 is set now */ |
| 559 | | if (CA2_AUTO_HS(v->pcr)) |
| 569 | if (CA2_AUTO_HS(m_pcr)) |
| 560 | 570 | { |
| 561 | | if (v->out_ca2) |
| 571 | if (m_out_ca2) |
| 562 | 572 | { |
| 563 | 573 | /* set CA2 */ |
| 564 | | v->out_ca2 = 0; |
| 574 | m_out_ca2 = 0; |
| 565 | 575 | |
| 566 | 576 | /* call the CA2 output function */ |
| 567 | | devcb_call_write_line(&v->out_ca2_func, 0); |
| 577 | devcb_call_write_line(&m_out_ca2_func, 0); |
| 568 | 578 | } |
| 569 | 579 | } |
| 570 | 580 | |
| r8885 | r8886 | |
| 572 | 582 | |
| 573 | 583 | case VIA_PANH: |
| 574 | 584 | /* update the input */ |
| 575 | | if (PA_LATCH_ENABLE(v->acr) == 0) |
| 585 | if (PA_LATCH_ENABLE(m_acr) == 0) |
| 576 | 586 | { |
| 577 | | if (v->in_a_func.read != NULL) |
| 578 | | v->in_a = devcb_call_read8(&v->in_a_func, 0); |
| 587 | if (m_in_a_func.read != NULL) |
| 588 | { |
| 589 | m_in_a = devcb_call_read8(&m_in_a_func, 0); |
| 590 | } |
| 579 | 591 | else |
| 580 | | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 592 | { |
| 593 | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 594 | } |
| 581 | 595 | } |
| 582 | 596 | |
| 583 | 597 | /* combine input and output values */ |
| 584 | | val = (v->out_a & v->ddr_a) + (v->in_a & ~v->ddr_a); |
| 598 | val = (m_out_a & m_ddr_a) + (m_in_a & ~m_ddr_a); |
| 585 | 599 | break; |
| 586 | 600 | |
| 587 | 601 | case VIA_DDRB: |
| 588 | | val = v->ddr_b; |
| 602 | val = m_ddr_b; |
| 589 | 603 | break; |
| 590 | 604 | |
| 591 | 605 | case VIA_DDRA: |
| 592 | | val = v->ddr_a; |
| 606 | val = m_ddr_a; |
| 593 | 607 | break; |
| 594 | 608 | |
| 595 | 609 | case VIA_T1CL: |
| 596 | | via_clear_int (device, INT_T1); |
| 597 | | val = v_get_counter1_value(device) & 0xFF; |
| 610 | clear_int(INT_T1); |
| 611 | val = get_counter1_value() & 0xFF; |
| 598 | 612 | break; |
| 599 | 613 | |
| 600 | 614 | case VIA_T1CH: |
| 601 | | val = v_get_counter1_value(device) >> 8; |
| 615 | val = get_counter1_value() >> 8; |
| 602 | 616 | break; |
| 603 | 617 | |
| 604 | 618 | case VIA_T1LL: |
| 605 | | val = v->t1ll; |
| 619 | val = m_t1ll; |
| 606 | 620 | break; |
| 607 | 621 | |
| 608 | 622 | case VIA_T1LH: |
| 609 | | val = v->t1lh; |
| 623 | val = m_t1lh; |
| 610 | 624 | break; |
| 611 | 625 | |
| 612 | 626 | case VIA_T2CL: |
| 613 | | via_clear_int (device, INT_T2); |
| 614 | | if (v->t2_active) |
| 615 | | val = v_time_to_cycles(device, timer_timeleft(v->t2)) & 0xff; |
| 627 | clear_int(INT_T2); |
| 628 | if (m_t2_active) |
| 629 | { |
| 630 | val = time_to_cycles(timer_timeleft(m_t2)) & 0xff; |
| 631 | } |
| 616 | 632 | else |
| 617 | 633 | { |
| 618 | | if (T2_COUNT_PB6(v->acr)) |
| 619 | | val = v->t2cl; |
| 634 | if (T2_COUNT_PB6(m_acr)) |
| 635 | { |
| 636 | val = m_t2cl; |
| 637 | } |
| 620 | 638 | else |
| 621 | | val = (0x10000- (v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time2)) & 0xffff) - 1) & 0xff; |
| 639 | { |
| 640 | val = (0x10000 - (time_to_cycles(attotime_sub(timer_get_time(&m_machine), m_time2)) & 0xffff) - 1) & 0xff; |
| 641 | } |
| 622 | 642 | } |
| 623 | 643 | break; |
| 624 | 644 | |
| 625 | 645 | case VIA_T2CH: |
| 626 | | if (v->t2_active) |
| 627 | | val = v_time_to_cycles(device, timer_timeleft(v->t2)) >> 8; |
| 646 | if (m_t2_active) |
| 647 | { |
| 648 | val = time_to_cycles(timer_timeleft(m_t2)) >> 8; |
| 649 | } |
| 628 | 650 | else |
| 629 | 651 | { |
| 630 | | if (T2_COUNT_PB6(v->acr)) |
| 631 | | val = v->t2ch; |
| 652 | if (T2_COUNT_PB6(m_acr)) |
| 653 | { |
| 654 | val = m_t2ch; |
| 655 | } |
| 632 | 656 | else |
| 633 | | val = (0x10000- (v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time2)) & 0xffff) - 1) >> 8; |
| 657 | { |
| 658 | val = (0x10000 - (time_to_cycles(attotime_sub(timer_get_time(&m_machine), m_time2)) & 0xffff) - 1) >> 8; |
| 659 | } |
| 634 | 660 | } |
| 635 | 661 | break; |
| 636 | 662 | |
| 637 | 663 | case VIA_SR: |
| 638 | | val = v->sr; |
| 639 | | via_clear_int(device, INT_SR); |
| 640 | | if (SO_O2_CONTROL(v->acr)) |
| 664 | val = m_sr; |
| 665 | clear_int(INT_SR); |
| 666 | if (SO_O2_CONTROL(m_acr)) |
| 641 | 667 | { |
| 642 | | v->shift_counter=0; |
| 643 | | timer_adjust_oneshot(v->shift_timer, v_cycles_to_time(device, 2), 0); |
| 668 | m_shift_counter=0; |
| 669 | timer_adjust_oneshot(m_shift_timer, cycles_to_time(2), 0); |
| 644 | 670 | } |
| 645 | 671 | break; |
| 646 | 672 | |
| 647 | 673 | case VIA_PCR: |
| 648 | | val = v->pcr; |
| 674 | val = m_pcr; |
| 649 | 675 | break; |
| 650 | 676 | |
| 651 | 677 | case VIA_ACR: |
| 652 | | val = v->acr; |
| 678 | val = m_acr; |
| 653 | 679 | break; |
| 654 | 680 | |
| 655 | 681 | case VIA_IER: |
| 656 | | val = v->ier | 0x80; |
| 682 | val = m_ier | 0x80; |
| 657 | 683 | break; |
| 658 | 684 | |
| 659 | 685 | case VIA_IFR: |
| 660 | | val = v->ifr; |
| 686 | val = m_ifr; |
| 661 | 687 | break; |
| 662 | 688 | } |
| 663 | 689 | return val; |
| r8885 | r8886 | |
| 670 | 696 | |
| 671 | 697 | WRITE8_DEVICE_HANDLER(via_w) |
| 672 | 698 | { |
| 673 | | via6522_t *v = get_token(device); |
| 699 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 700 | via->reg_w(offset, data); |
| 701 | } |
| 674 | 702 | |
| 703 | void via6522_device::reg_w(UINT8 offset, UINT8 data) |
| 704 | { |
| 675 | 705 | offset &=0x0f; |
| 676 | 706 | |
| 677 | 707 | switch (offset) |
| 678 | 708 | { |
| 679 | 709 | case VIA_PB: |
| 680 | | if (T1_SET_PB7(v->acr)) |
| 681 | | v->out_b = (v->out_b & 0x80) | (data & 0x7f); |
| 710 | if (T1_SET_PB7(m_acr)) |
| 711 | m_out_b = (m_out_b & 0x80) | (data & 0x7f); |
| 682 | 712 | else |
| 683 | | v->out_b = data; |
| 713 | m_out_b = data; |
| 684 | 714 | |
| 685 | | if (v->ddr_b) |
| 715 | if (m_ddr_b) |
| 686 | 716 | { |
| 687 | | UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); |
| 688 | | devcb_call_write8(&v->out_b_func, 0, write_data); |
| 717 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 718 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 689 | 719 | } |
| 690 | 720 | |
| 691 | | CLR_PB_INT(device); |
| 721 | CLR_PB_INT(); |
| 692 | 722 | |
| 693 | 723 | /* If CB2 is configured as output and in pulse or handshake mode, |
| 694 | 724 | CB2 is set now */ |
| 695 | | if (CB2_AUTO_HS(v->pcr)) |
| 725 | if (CB2_AUTO_HS(m_pcr)) |
| 696 | 726 | { |
| 697 | | if (v->out_cb2) |
| 727 | if (m_out_cb2) |
| 698 | 728 | { |
| 699 | 729 | /* set CB2 */ |
| 700 | | v->out_cb2 = 0; |
| 730 | m_out_cb2 = 0; |
| 701 | 731 | |
| 702 | 732 | /* call the CB2 output function */ |
| 703 | | devcb_call_write_line(&v->out_cb2_func, 0); |
| 733 | devcb_call_write_line(&m_out_cb2_func, 0); |
| 704 | 734 | } |
| 705 | 735 | } |
| 706 | 736 | break; |
| 707 | 737 | |
| 708 | 738 | case VIA_PA: |
| 709 | | v->out_a = data; |
| 739 | m_out_a = data; |
| 710 | 740 | |
| 711 | | if (v->ddr_a) |
| 741 | if (m_ddr_a) |
| 712 | 742 | { |
| 713 | | UINT8 write_data = (v->out_a & v->ddr_a) | (v->ddr_a ^ 0xff); |
| 714 | | devcb_call_write8(&v->out_a_func, 0, write_data); |
| 743 | UINT8 write_data = (m_out_a & m_ddr_a) | (m_ddr_a ^ 0xff); |
| 744 | devcb_call_write8(&m_out_a_func, 0, write_data); |
| 715 | 745 | } |
| 716 | 746 | |
| 717 | | CLR_PA_INT(device); |
| 747 | CLR_PA_INT(); |
| 718 | 748 | |
| 719 | 749 | /* If CA2 is configured as output and in pulse or handshake mode, |
| 720 | 750 | CA2 is set now */ |
| 721 | | if (CA2_PULSE_OUTPUT(v->pcr)) |
| 751 | if (CA2_PULSE_OUTPUT(m_pcr)) |
| 722 | 752 | { |
| 723 | 753 | /* call the CA2 output function */ |
| 724 | | devcb_call_write_line(&v->out_ca2_func, 0); |
| 725 | | devcb_call_write_line(&v->out_ca2_func, 1); |
| 754 | devcb_call_write_line(&m_out_ca2_func, 0); |
| 755 | devcb_call_write_line(&m_out_ca2_func, 1); |
| 726 | 756 | |
| 727 | 757 | /* set CA2 (shouldn't be needed) */ |
| 728 | | v->out_ca2 = 1; |
| 758 | m_out_ca2 = 1; |
| 729 | 759 | } |
| 730 | | else if (CA2_AUTO_HS(v->pcr)) |
| 760 | else if (CA2_AUTO_HS(m_pcr)) |
| 731 | 761 | { |
| 732 | | if (v->out_ca2) |
| 762 | if (m_out_ca2) |
| 733 | 763 | { |
| 734 | 764 | /* set CA2 */ |
| 735 | | v->out_ca2 = 0; |
| 765 | m_out_ca2 = 0; |
| 736 | 766 | |
| 737 | 767 | /* call the CA2 output function */ |
| 738 | | devcb_call_write_line(&v->out_ca2_func, 0); |
| 768 | devcb_call_write_line(&m_out_ca2_func, 0); |
| 739 | 769 | } |
| 740 | 770 | } |
| 741 | 771 | |
| 742 | 772 | break; |
| 743 | 773 | |
| 744 | 774 | case VIA_PANH: |
| 745 | | v->out_a = data; |
| 775 | m_out_a = data; |
| 746 | 776 | |
| 747 | | if (v->ddr_a) |
| 777 | if (m_ddr_a) |
| 748 | 778 | { |
| 749 | | UINT8 write_data = (v->out_a & v->ddr_a) | (v->ddr_a ^ 0xff); |
| 750 | | devcb_call_write8(&v->out_a_func, 0, write_data); |
| 779 | UINT8 write_data = (m_out_a & m_ddr_a) | (m_ddr_a ^ 0xff); |
| 780 | devcb_call_write8(&m_out_a_func, 0, write_data); |
| 751 | 781 | } |
| 752 | 782 | |
| 753 | 783 | break; |
| 754 | 784 | |
| 755 | 785 | case VIA_DDRB: |
| 756 | 786 | /* EHC 03/04/2000 - If data direction changed, present output on the lines */ |
| 757 | | if ( data != v->ddr_b ) |
| 787 | if ( data != m_ddr_b ) |
| 758 | 788 | { |
| 759 | | v->ddr_b = data; |
| 789 | m_ddr_b = data; |
| 760 | 790 | |
| 761 | | //if (v->ddr_b) |
| 791 | //if (m_ddr_b) |
| 762 | 792 | { |
| 763 | | UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); |
| 764 | | devcb_call_write8(&v->out_b_func, 0, write_data); |
| 793 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 794 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 765 | 795 | } |
| 766 | 796 | } |
| 767 | 797 | break; |
| 768 | 798 | |
| 769 | 799 | case VIA_DDRA: |
| 770 | 800 | /* EHC 03/04/2000 - If data direction changed, present output on the lines */ |
| 771 | | if ( data != v->ddr_a ) |
| 801 | if ( data != m_ddr_a ) |
| 772 | 802 | { |
| 773 | | v->ddr_a = data; |
| 803 | m_ddr_a = data; |
| 774 | 804 | |
| 775 | | //if (v->ddr_a) |
| 805 | //if (m_ddr_a) |
| 776 | 806 | { |
| 777 | | UINT8 write_data = (v->out_a & v->ddr_a) | (v->ddr_a ^ 0xff); |
| 778 | | devcb_call_write8(&v->out_a_func, 0, write_data); |
| 807 | UINT8 write_data = (m_out_a & m_ddr_a) | (m_ddr_a ^ 0xff); |
| 808 | devcb_call_write8(&m_out_a_func, 0, write_data); |
| 779 | 809 | } |
| 780 | 810 | } |
| 781 | 811 | break; |
| 782 | 812 | |
| 783 | 813 | case VIA_T1CL: |
| 784 | 814 | case VIA_T1LL: |
| 785 | | v->t1ll = data; |
| 815 | m_t1ll = data; |
| 786 | 816 | break; |
| 787 | 817 | |
| 788 | 818 | case VIA_T1LH: |
| 789 | | v->t1lh = data; |
| 790 | | via_clear_int (device, INT_T1); |
| 819 | m_t1lh = data; |
| 820 | clear_int(INT_T1); |
| 791 | 821 | break; |
| 792 | 822 | |
| 793 | 823 | case VIA_T1CH: |
| 794 | | v->t1ch = v->t1lh = data; |
| 795 | | v->t1cl = v->t1ll; |
| 824 | m_t1ch = m_t1lh = data; |
| 825 | m_t1cl = m_t1ll; |
| 796 | 826 | |
| 797 | | via_clear_int (device, INT_T1); |
| 827 | clear_int(INT_T1); |
| 798 | 828 | |
| 799 | | if (T1_SET_PB7(v->acr)) |
| 829 | if (T1_SET_PB7(m_acr)) |
| 800 | 830 | { |
| 801 | | v->out_b &= 0x7f; |
| 831 | m_out_b &= 0x7f; |
| 802 | 832 | |
| 803 | | //if (v->ddr_b) |
| 833 | //if (m_ddr_b) |
| 804 | 834 | { |
| 805 | | UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); |
| 806 | | devcb_call_write8(&v->out_b_func, 0, write_data); |
| 835 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 836 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 807 | 837 | } |
| 808 | 838 | } |
| 809 | | timer_adjust_oneshot(v->t1, v_cycles_to_time(device, TIMER1_VALUE(v) + IFR_DELAY), 0); |
| 810 | | v->t1_active = 1; |
| 839 | timer_adjust_oneshot(m_t1, cycles_to_time(TIMER1_VALUE + IFR_DELAY), 0); |
| 840 | m_t1_active = 1; |
| 811 | 841 | break; |
| 812 | 842 | |
| 813 | 843 | case VIA_T2CL: |
| 814 | | v->t2ll = data; |
| 844 | m_t2ll = data; |
| 815 | 845 | break; |
| 816 | 846 | |
| 817 | 847 | case VIA_T2CH: |
| 818 | | v->t2ch = v->t2lh = data; |
| 819 | | v->t2cl = v->t2ll; |
| 848 | m_t2ch = m_t2lh = data; |
| 849 | m_t2cl = m_t2ll; |
| 820 | 850 | |
| 821 | | via_clear_int (device, INT_T2); |
| 851 | clear_int(INT_T2); |
| 822 | 852 | |
| 823 | | if (!T2_COUNT_PB6(v->acr)) |
| 853 | if (!T2_COUNT_PB6(m_acr)) |
| 824 | 854 | { |
| 825 | | timer_adjust_oneshot(v->t2, v_cycles_to_time(device, TIMER2_VALUE(v) + IFR_DELAY), 0); |
| 826 | | v->t2_active = 1; |
| 855 | timer_adjust_oneshot(m_t2, cycles_to_time(TIMER2_VALUE + IFR_DELAY), 0); |
| 856 | m_t2_active = 1; |
| 827 | 857 | } |
| 828 | 858 | else |
| 829 | 859 | { |
| 830 | | timer_adjust_oneshot(v->t2, v_cycles_to_time(device, TIMER2_VALUE(v)), 0); |
| 831 | | v->t2_active = 1; |
| 832 | | v->time2 = timer_get_time(device->machine); |
| 860 | timer_adjust_oneshot(m_t2, cycles_to_time(TIMER2_VALUE), 0); |
| 861 | m_t2_active = 1; |
| 862 | m_time2 = timer_get_time(&m_machine); |
| 833 | 863 | } |
| 834 | 864 | break; |
| 835 | 865 | |
| 836 | 866 | case VIA_SR: |
| 837 | | v->sr = data; |
| 838 | | v->shift_counter=0; |
| 839 | | via_clear_int(device, INT_SR); |
| 840 | | if (SO_O2_CONTROL(v->acr)) |
| 867 | m_sr = data; |
| 868 | m_shift_counter=0; |
| 869 | clear_int(INT_SR); |
| 870 | if (SO_O2_CONTROL(m_acr)) |
| 841 | 871 | { |
| 842 | | timer_set(device->machine, v_cycles_to_time(device, 2), (void *) device, 0, via_shift_callback); |
| 872 | timer_set(&m_machine, cycles_to_time(2), (void *)this, 0, shift_callback); |
| 843 | 873 | } |
| 844 | 874 | break; |
| 845 | 875 | |
| 846 | 876 | case VIA_PCR: |
| 847 | | v->pcr = data; |
| 877 | m_pcr = data; |
| 848 | 878 | |
| 849 | 879 | if (TRACE_VIA) |
| 850 | | logerror("%s:6522VIA chip %s: PCR = %02X\n", cpuexec_describe_context(device->machine), device->tag(), data); |
| 880 | { |
| 881 | logerror("%s:6522VIA chip %s: PCR = %02X\n", cpuexec_describe_context(&m_machine), tag(), data); |
| 882 | } |
| 851 | 883 | |
| 852 | | if (CA2_FIX_OUTPUT(data) && CA2_OUTPUT_LEVEL(data) ^ v->out_ca2) |
| 884 | if (CA2_FIX_OUTPUT(data) && CA2_OUTPUT_LEVEL(data) ^ m_out_ca2) |
| 853 | 885 | { |
| 854 | | v->out_ca2 = CA2_OUTPUT_LEVEL(data); |
| 855 | | devcb_call_write_line(&v->out_ca2_func, v->out_ca2); |
| 886 | m_out_ca2 = CA2_OUTPUT_LEVEL(data); |
| 887 | devcb_call_write_line(&m_out_ca2_func, m_out_ca2); |
| 856 | 888 | } |
| 857 | 889 | |
| 858 | | if (CB2_FIX_OUTPUT(data) && CB2_OUTPUT_LEVEL(data) ^ v->out_cb2) |
| 890 | if (CB2_FIX_OUTPUT(data) && CB2_OUTPUT_LEVEL(data) ^ m_out_cb2) |
| 859 | 891 | { |
| 860 | | v->out_cb2 = CB2_OUTPUT_LEVEL(data); |
| 861 | | devcb_call_write_line(&v->out_cb2_func, v->out_cb2); |
| 892 | m_out_cb2 = CB2_OUTPUT_LEVEL(data); |
| 893 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 862 | 894 | } |
| 863 | 895 | break; |
| 864 | 896 | |
| 865 | 897 | case VIA_ACR: |
| 866 | 898 | { |
| 867 | | UINT16 counter1 = v_get_counter1_value(device); |
| 868 | | v->acr = data; |
| 869 | | if (T1_SET_PB7(v->acr)) |
| 899 | UINT16 counter1 = get_counter1_value(); |
| 900 | m_acr = data; |
| 901 | if (T1_SET_PB7(m_acr)) |
| 870 | 902 | { |
| 871 | | if (v->t1_active) |
| 872 | | v->out_b &= ~0x80; |
| 903 | if (m_t1_active) |
| 904 | { |
| 905 | m_out_b &= ~0x80; |
| 906 | } |
| 873 | 907 | else |
| 874 | | v->out_b |= 0x80; |
| 908 | { |
| 909 | m_out_b |= 0x80; |
| 910 | } |
| 875 | 911 | |
| 876 | | //if (v->ddr_b) |
| 912 | //if (m_ddr_b) |
| 877 | 913 | { |
| 878 | | UINT8 write_data = (v->out_b & v->ddr_b) | (v->ddr_b ^ 0xff); |
| 879 | | devcb_call_write8(&v->out_b_func, 0, write_data); |
| 914 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 915 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 880 | 916 | } |
| 881 | 917 | } |
| 882 | 918 | if (T1_CONTINUOUS(data)) |
| 883 | 919 | { |
| 884 | | timer_adjust_oneshot(v->t1, v_cycles_to_time(device, counter1 + IFR_DELAY), 0); |
| 885 | | v->t1_active = 1; |
| 920 | timer_adjust_oneshot(m_t1, cycles_to_time(counter1 + IFR_DELAY), 0); |
| 921 | m_t1_active = 1; |
| 886 | 922 | } |
| 887 | 923 | } |
| 888 | 924 | break; |
| 889 | 925 | |
| 890 | 926 | case VIA_IER: |
| 891 | 927 | if (data & 0x80) |
| 892 | | v->ier |= data & 0x7f; |
| 928 | { |
| 929 | m_ier |= data & 0x7f; |
| 930 | } |
| 893 | 931 | else |
| 894 | | v->ier &= ~(data & 0x7f); |
| 932 | { |
| 933 | m_ier &= ~(data & 0x7f); |
| 934 | } |
| 895 | 935 | |
| 896 | | if (v->ifr & INT_ANY) |
| 936 | if (m_ifr & INT_ANY) |
| 897 | 937 | { |
| 898 | | if (((v->ifr & v->ier) & 0x7f) == 0) |
| 938 | if (((m_ifr & m_ier) & 0x7f) == 0) |
| 899 | 939 | { |
| 900 | | v->ifr &= ~INT_ANY; |
| 901 | | devcb_call_write_line(&v->irq_func, CLEAR_LINE); |
| 940 | m_ifr &= ~INT_ANY; |
| 941 | devcb_call_write_line(&m_irq_func, CLEAR_LINE); |
| 902 | 942 | } |
| 903 | 943 | } |
| 904 | 944 | else |
| 905 | 945 | { |
| 906 | | if ((v->ier & v->ifr) & 0x7f) |
| 946 | if ((m_ier & m_ifr) & 0x7f) |
| 907 | 947 | { |
| 908 | | v->ifr |= INT_ANY; |
| 909 | | devcb_call_write_line(&v->irq_func, ASSERT_LINE); |
| 948 | m_ifr |= INT_ANY; |
| 949 | devcb_call_write_line(&m_irq_func, ASSERT_LINE); |
| 910 | 950 | } |
| 911 | 951 | } |
| 912 | 952 | break; |
| 913 | 953 | |
| 914 | 954 | case VIA_IFR: |
| 915 | 955 | if (data & INT_ANY) |
| 956 | { |
| 916 | 957 | data = 0x7f; |
| 917 | | via_clear_int (device, data); |
| 958 | } |
| 959 | clear_int(data); |
| 918 | 960 | break; |
| 919 | 961 | } |
| 920 | 962 | } |
| 921 | 963 | |
| 922 | | |
| 923 | 964 | /*------------------------------------------------- |
| 924 | | via_porta_w - interface setting VIA port |
| 925 | | A input |
| 965 | via_ca1_r - interface returning VIA port |
| 966 | CA1 input |
| 926 | 967 | -------------------------------------------------*/ |
| 927 | 968 | |
| 928 | | WRITE8_DEVICE_HANDLER(via_porta_w) |
| 969 | READ_LINE_DEVICE_HANDLER(via_ca1_r) |
| 929 | 970 | { |
| 930 | | via6522_t *v = get_token(device); |
| 931 | | |
| 932 | | /* set the input, what could be easier? */ |
| 933 | | v->in_a = data; |
| 971 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 972 | return via->ca1_r(); |
| 934 | 973 | } |
| 935 | 974 | |
| 936 | 975 | |
| 976 | |
| 937 | 977 | /*------------------------------------------------- |
| 938 | | via_ca1_r - interface retrieving VIA port |
| 939 | | CA1 input |
| 978 | via_ca2_r - interface returning VIA port |
| 979 | CA2 input |
| 940 | 980 | -------------------------------------------------*/ |
| 941 | 981 | |
| 942 | | READ_LINE_DEVICE_HANDLER(via_ca1_r) |
| 982 | READ_LINE_DEVICE_HANDLER(via_ca2_r) |
| 943 | 983 | { |
| 944 | | via6522_t *v = get_token(device); |
| 945 | | return v->in_ca1; |
| 984 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 985 | return via->ca2_r(); |
| 946 | 986 | } |
| 947 | 987 | |
| 948 | 988 | |
| 989 | |
| 949 | 990 | /*------------------------------------------------- |
| 950 | 991 | via_ca1_w - interface setting VIA port |
| 951 | 992 | CA1 input |
| r8885 | r8886 | |
| 953 | 994 | |
| 954 | 995 | WRITE_LINE_DEVICE_HANDLER(via_ca1_w) |
| 955 | 996 | { |
| 956 | | via6522_t *v = get_token(device); |
| 997 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 998 | via->ca1_w(state); |
| 999 | } |
| 957 | 1000 | |
| 1001 | void via6522_device::ca1_w(UINT8 state) |
| 1002 | { |
| 958 | 1003 | /* handle the active transition */ |
| 959 | | if (state != v->in_ca1) |
| 1004 | if (state != m_in_ca1) |
| 960 | 1005 | { |
| 961 | 1006 | if (TRACE_VIA) |
| 962 | | logerror("%s:6522VIA chip %s: CA1 = %02X\n", cpuexec_describe_context(device->machine), device->tag(), state); |
| 1007 | logerror("%s:6522VIA chip %s: CA1 = %02X\n", cpuexec_describe_context(&m_machine), tag(), state); |
| 963 | 1008 | |
| 964 | | if ((CA1_LOW_TO_HIGH(v->pcr) && state) || (CA1_HIGH_TO_LOW(v->pcr) && !state)) |
| 1009 | if ((CA1_LOW_TO_HIGH(m_pcr) && state) || (CA1_HIGH_TO_LOW(m_pcr) && !state)) |
| 965 | 1010 | { |
| 966 | | if (PA_LATCH_ENABLE(v->acr)) |
| 1011 | if (PA_LATCH_ENABLE(m_acr)) |
| 967 | 1012 | { |
| 968 | | if (v->in_a_func.read != NULL) |
| 969 | | v->in_a = devcb_call_read8(&v->in_a_func, 0); |
| 1013 | if (m_in_a_func.read != NULL) |
| 1014 | { |
| 1015 | m_in_a = devcb_call_read8(&m_in_a_func, 0); |
| 1016 | } |
| 970 | 1017 | else |
| 971 | | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 1018 | { |
| 1019 | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 1020 | } |
| 972 | 1021 | } |
| 973 | 1022 | |
| 974 | | via_set_int (device, INT_CA1); |
| 1023 | set_int(INT_CA1); |
| 975 | 1024 | |
| 976 | 1025 | /* CA2 is configured as output and in pulse or handshake mode, |
| 977 | 1026 | CA2 is cleared now */ |
| 978 | | if (CA2_AUTO_HS(v->pcr)) |
| 1027 | if (CA2_AUTO_HS(m_pcr)) |
| 979 | 1028 | { |
| 980 | | if (!v->out_ca2) |
| 1029 | if (!m_out_ca2) |
| 981 | 1030 | { |
| 982 | 1031 | /* clear CA2 */ |
| 983 | | v->out_ca2 = 1; |
| 1032 | m_out_ca2 = 1; |
| 984 | 1033 | |
| 985 | 1034 | /* call the CA2 output function */ |
| 986 | | devcb_call_write_line(&v->out_ca2_func, 1); |
| 1035 | devcb_call_write_line(&m_out_ca2_func, 1); |
| 987 | 1036 | } |
| 988 | 1037 | } |
| 989 | 1038 | } |
| 990 | 1039 | |
| 991 | | v->in_ca1 = state; |
| 1040 | m_in_ca1 = state; |
| 992 | 1041 | } |
| 993 | 1042 | } |
| 994 | 1043 | |
| 995 | 1044 | |
| 996 | | /*------------------------------------------------- |
| 997 | | via_ca2_r - interface retrieving VIA port |
| 998 | | CA2 input |
| 999 | | -------------------------------------------------*/ |
| 1000 | 1045 | |
| 1001 | | READ_LINE_DEVICE_HANDLER(via_ca2_r) |
| 1002 | | { |
| 1003 | | via6522_t *v = get_token(device); |
| 1004 | | return v->in_ca2; |
| 1005 | | } |
| 1006 | | |
| 1007 | | |
| 1008 | 1046 | /*------------------------------------------------- |
| 1009 | 1047 | via_ca2_w - interface setting VIA port |
| 1010 | 1048 | CA2 input |
| r8885 | r8886 | |
| 1012 | 1050 | |
| 1013 | 1051 | WRITE_LINE_DEVICE_HANDLER(via_ca2_w) |
| 1014 | 1052 | { |
| 1015 | | via6522_t *v = get_token(device); |
| 1053 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1054 | via->ca2_w(state); |
| 1055 | } |
| 1016 | 1056 | |
| 1057 | void via6522_device::ca2_w(UINT8 state) |
| 1058 | { |
| 1017 | 1059 | /* CA2 is in input mode */ |
| 1018 | | if (CA2_INPUT(v->pcr)) |
| 1060 | if (CA2_INPUT(m_pcr)) |
| 1019 | 1061 | { |
| 1020 | 1062 | /* the new state has caused a transition */ |
| 1021 | | if (v->in_ca2 != state) |
| 1063 | if (m_in_ca2 != state) |
| 1022 | 1064 | { |
| 1023 | 1065 | /* handle the active transition */ |
| 1024 | | if ((state && CA2_LOW_TO_HIGH(v->pcr)) || (!state && CA2_HIGH_TO_LOW(v->pcr))) |
| 1066 | if ((state && CA2_LOW_TO_HIGH(m_pcr)) || (!state && CA2_HIGH_TO_LOW(m_pcr))) |
| 1025 | 1067 | { |
| 1026 | 1068 | /* mark the IRQ */ |
| 1027 | | via_set_int (device, INT_CA2); |
| 1069 | set_int(INT_CA2); |
| 1028 | 1070 | } |
| 1029 | 1071 | /* set the new value for CA2 */ |
| 1030 | | v->in_ca2 = state; |
| 1072 | m_in_ca2 = state; |
| 1031 | 1073 | } |
| 1032 | 1074 | } |
| 1075 | } |
| 1033 | 1076 | |
| 1034 | 1077 | |
| 1035 | | } |
| 1036 | 1078 | |
| 1037 | | |
| 1038 | 1079 | /*------------------------------------------------- |
| 1039 | | via_portb_r - interface retrieving VIA port |
| 1040 | | B input |
| 1080 | via_cb1_r - interface returning VIA port |
| 1081 | CB1 input |
| 1041 | 1082 | -------------------------------------------------*/ |
| 1042 | 1083 | |
| 1043 | | READ8_DEVICE_HANDLER(via_portb_r) |
| 1084 | READ_LINE_DEVICE_HANDLER(via_cb1_r) |
| 1044 | 1085 | { |
| 1045 | | via6522_t *v = get_token(device); |
| 1046 | | return v->in_b; |
| 1086 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1087 | return via->cb1_r(); |
| 1047 | 1088 | } |
| 1048 | 1089 | |
| 1049 | 1090 | |
| 1091 | |
| 1050 | 1092 | /*------------------------------------------------- |
| 1051 | | via_portb_w - interface setting VIA port |
| 1052 | | B input |
| 1093 | via_cb2_r - interface returning VIA port |
| 1094 | CB2 input |
| 1053 | 1095 | -------------------------------------------------*/ |
| 1054 | 1096 | |
| 1055 | | WRITE8_DEVICE_HANDLER(via_portb_w) |
| 1097 | READ_LINE_DEVICE_HANDLER(via_cb2_r) |
| 1056 | 1098 | { |
| 1057 | | via6522_t *v = get_token(device); |
| 1058 | | |
| 1059 | | /* set the input, what could be easier? */ |
| 1060 | | v->in_b = data; |
| 1099 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1100 | return via->cb2_r(); |
| 1061 | 1101 | } |
| 1062 | 1102 | |
| 1063 | 1103 | |
| 1104 | |
| 1064 | 1105 | /*------------------------------------------------- |
| 1065 | | via_cb1_r - interface retrieving VIA port |
| 1106 | via_cb1_w - interface setting VIA port |
| 1066 | 1107 | CB1 input |
| 1067 | 1108 | -------------------------------------------------*/ |
| 1068 | 1109 | |
| 1069 | | READ_LINE_DEVICE_HANDLER(via_cb1_r) |
| 1110 | WRITE_LINE_DEVICE_HANDLER( via_cb1_w ) |
| 1070 | 1111 | { |
| 1071 | | via6522_t *v = get_token(device); |
| 1072 | | return v->in_cb1; |
| 1112 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1113 | via->cb1_w(state); |
| 1073 | 1114 | } |
| 1074 | 1115 | |
| 1075 | | |
| 1076 | | /*------------------------------------------------- |
| 1077 | | via_cb1_w - interface setting VIA port |
| 1078 | | CB1 input |
| 1079 | | -------------------------------------------------*/ |
| 1080 | | |
| 1081 | | WRITE_LINE_DEVICE_HANDLER(via_cb1_w) |
| 1116 | void via6522_device::cb1_w(UINT8 state) |
| 1082 | 1117 | { |
| 1083 | | via6522_t *v = get_token(device); |
| 1084 | | |
| 1085 | 1118 | /* handle the active transition */ |
| 1086 | | if (state != v->in_cb1) |
| 1119 | if (state != m_in_cb1) |
| 1087 | 1120 | { |
| 1088 | | if ((CB1_LOW_TO_HIGH(v->pcr) && state) || (CB1_HIGH_TO_LOW(v->pcr) && !state)) |
| 1121 | if ((CB1_LOW_TO_HIGH(m_pcr) && state) || (CB1_HIGH_TO_LOW(m_pcr) && !state)) |
| 1089 | 1122 | { |
| 1090 | | if (PB_LATCH_ENABLE(v->acr)) |
| 1123 | if (PB_LATCH_ENABLE(m_acr)) |
| 1091 | 1124 | { |
| 1092 | | if (v->in_b_func.read != NULL) |
| 1093 | | v->in_b = devcb_call_read8(&v->in_b_func, 0); |
| 1125 | if (m_in_b_func.read != NULL) |
| 1126 | { |
| 1127 | m_in_b = devcb_call_read8(&m_in_b_func, 0); |
| 1128 | } |
| 1094 | 1129 | else |
| 1095 | | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 1130 | { |
| 1131 | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 1132 | } |
| 1096 | 1133 | } |
| 1097 | | if (SO_EXT_CONTROL(v->acr) || SI_EXT_CONTROL(v->acr)) |
| 1098 | | via_shift (device); |
| 1134 | if (SO_EXT_CONTROL(m_acr) || SI_EXT_CONTROL(m_acr)) |
| 1135 | { |
| 1136 | shift(); |
| 1137 | } |
| 1099 | 1138 | |
| 1100 | | via_set_int (device, INT_CB1); |
| 1139 | set_int(INT_CB1); |
| 1101 | 1140 | |
| 1102 | 1141 | /* CB2 is configured as output and in pulse or handshake mode, |
| 1103 | 1142 | CB2 is cleared now */ |
| 1104 | | if (CB2_AUTO_HS(v->pcr)) |
| 1143 | if (CB2_AUTO_HS(m_pcr)) |
| 1105 | 1144 | { |
| 1106 | | if (!v->out_cb2) |
| 1145 | if (!m_out_cb2) |
| 1107 | 1146 | { |
| 1108 | 1147 | /* clear CB2 */ |
| 1109 | | v->out_cb2 = 1; |
| 1148 | m_out_cb2 = 1; |
| 1110 | 1149 | |
| 1111 | 1150 | /* call the CB2 output function */ |
| 1112 | | devcb_call_write_line(&v->out_cb2_func, 1); |
| 1151 | devcb_call_write_line(&m_out_cb2_func, 1); |
| 1113 | 1152 | } |
| 1114 | 1153 | } |
| 1115 | 1154 | } |
| 1116 | | v->in_cb1 = state; |
| 1155 | m_in_cb1 = state; |
| 1117 | 1156 | } |
| 1118 | 1157 | } |
| 1119 | 1158 | |
| 1120 | 1159 | |
| 1121 | 1160 | /*------------------------------------------------- |
| 1122 | | via_cb2_r - interface retrieving VIA port |
| 1161 | via_cb2_w - interface setting VIA port |
| 1123 | 1162 | CB2 input |
| 1124 | 1163 | -------------------------------------------------*/ |
| 1125 | 1164 | |
| 1126 | | READ_LINE_DEVICE_HANDLER(via_cb2_r) |
| 1165 | WRITE_LINE_DEVICE_HANDLER(via_cb2_w) |
| 1127 | 1166 | { |
| 1128 | | via6522_t *v = get_token(device); |
| 1129 | | return v->in_cb2; |
| 1167 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1168 | via->cb2_w(state); |
| 1130 | 1169 | } |
| 1131 | 1170 | |
| 1132 | | |
| 1133 | | /*------------------------------------------------- |
| 1134 | | via_cb2_w - interface setting VIA port |
| 1135 | | CB2 input |
| 1136 | | -------------------------------------------------*/ |
| 1137 | | |
| 1138 | | WRITE_LINE_DEVICE_HANDLER(via_cb2_w) |
| 1171 | void via6522_device::cb2_w(UINT8 state) |
| 1139 | 1172 | { |
| 1140 | | via6522_t *v = get_token(device); |
| 1141 | | |
| 1142 | 1173 | /* CB2 is in input mode */ |
| 1143 | | if (CB2_INPUT(v->pcr)) |
| 1174 | if (CB2_INPUT(m_pcr)) |
| 1144 | 1175 | { |
| 1145 | 1176 | /* the new state has caused a transition */ |
| 1146 | | if (v->in_cb2 != state) |
| 1177 | if (m_in_cb2 != state) |
| 1147 | 1178 | { |
| 1148 | 1179 | /* handle the active transition */ |
| 1149 | | if ((state && CB2_LOW_TO_HIGH(v->pcr)) || (!state && CB2_HIGH_TO_LOW(v->pcr))) |
| 1180 | if ((state && CB2_LOW_TO_HIGH(m_pcr)) || (!state && CB2_HIGH_TO_LOW(m_pcr))) |
| 1150 | 1181 | { |
| 1151 | 1182 | /* mark the IRQ */ |
| 1152 | | via_set_int (device, INT_CB2); |
| 1183 | set_int(INT_CB2); |
| 1153 | 1184 | } |
| 1154 | 1185 | /* set the new value for CB2 */ |
| 1155 | | v->in_cb2 = state; |
| 1186 | m_in_cb2 = state; |
| 1156 | 1187 | } |
| 1157 | 1188 | } |
| 1158 | 1189 | } |
| 1159 | 1190 | |
| 1191 | /*------------------------------------------------- |
| 1192 | via_porta_w - interface writing VIA port A |
| 1193 | -------------------------------------------------*/ |
| 1160 | 1194 | |
| 1195 | WRITE8_DEVICE_HANDLER(via_porta_w) |
| 1196 | { |
| 1197 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1198 | via->porta_w(data); |
| 1199 | } |
| 1200 | |
| 1161 | 1201 | /*------------------------------------------------- |
| 1162 | | DEVICE_GET_INFO( via6522 ) |
| 1202 | via_portb_w - interface writing VIA port B |
| 1163 | 1203 | -------------------------------------------------*/ |
| 1164 | 1204 | |
| 1165 | | DEVICE_GET_INFO(via6522) |
| 1205 | WRITE8_DEVICE_HANDLER(via_portb_w) |
| 1166 | 1206 | { |
| 1167 | | switch (state) |
| 1168 | | { |
| 1169 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1170 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(via6522_t); break; |
| 1171 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 1207 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1208 | via->portb_w(data); |
| 1209 | } |
| 1172 | 1210 | |
| 1173 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1174 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(via6522); break; |
| 1175 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1176 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(via6522); break; |
| 1211 | /*------------------------------------------------- |
| 1212 | via_portb_r - interface reading VIA port B |
| 1213 | -------------------------------------------------*/ |
| 1177 | 1214 | |
| 1178 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1179 | | case DEVINFO_STR_NAME: strcpy(info->s, "6522 VIA"); break; |
| 1180 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "6522 VIA"); break; |
| 1181 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1182 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1183 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 1184 | | } |
| 1215 | READ8_DEVICE_HANDLER(via_portb_w) |
| 1216 | { |
| 1217 | via6522_device *via = reinterpret_cast<via6522_device *>(device); |
| 1218 | return via->portb_r(); |
| 1185 | 1219 | } |
| 1186 | 1220 | |
| 1187 | | |
| 1188 | | DEFINE_LEGACY_DEVICE(VIA6522, via6522); |
| 1221 | const device_type VIA6522 = via6522_device_config::static_alloc_device_config; |