src/emu/machine/6526cia.c
| r8892 | r8893 | |
| 41 | 41 | #define CIA_CRA_SPMODE 0x40 |
| 42 | 42 | #define CIA_CRA_TODIN 0x80 |
| 43 | 43 | |
| 44 | | /*************************************************************************** |
| 45 | | TYPE DEFINITIONS |
| 46 | | ***************************************************************************/ |
| 44 | //************************************************************************** |
| 45 | // DEVICE CONFIGURATION |
| 46 | //************************************************************************** |
| 47 | 47 | |
| 48 | | typedef struct _cia_timer cia_timer; |
| 49 | | typedef struct _cia_port cia_port; |
| 50 | | typedef struct _cia_state cia_state; |
| 48 | //------------------------------------------------- |
| 49 | // mos6526_device_config - constructor |
| 50 | //------------------------------------------------- |
| 51 | 51 | |
| 52 | | struct _cia_timer |
| 52 | mos6526_device_config::mos6526_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 53 | : device_config(mconfig, static_alloc_device_config, "MOS6526", tag, owner, clock) |
| 53 | 54 | { |
| 54 | | UINT16 latch; |
| 55 | | UINT16 count; |
| 56 | | UINT8 mode; |
| 57 | | UINT8 irq; |
| 58 | | emu_timer *timer; |
| 59 | | cia_state * cia; |
| 60 | | }; |
| 55 | } |
| 61 | 56 | |
| 62 | | struct _cia_port |
| 63 | | { |
| 64 | | UINT8 ddr; |
| 65 | | UINT8 latch; |
| 66 | | UINT8 in; |
| 67 | | UINT8 out; |
| 68 | | devcb_resolved_read8 read; |
| 69 | | devcb_resolved_write8 write; |
| 70 | | UINT8 mask_value; /* in READ operation the value can be forced by a extern electric circuit */ |
| 71 | | }; |
| 72 | 57 | |
| 73 | | struct _cia_state |
| 58 | //------------------------------------------------- |
| 59 | // static_alloc_device_config - allocate a new |
| 60 | // configuration object |
| 61 | //------------------------------------------------- |
| 62 | |
| 63 | device_config *mos6526_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 74 | 64 | { |
| 75 | | running_device *device; |
| 76 | | devcb_resolved_write_line out_irq_func; |
| 77 | | devcb_resolved_write_line out_pc_func; |
| 78 | | devcb_resolved_write_line out_cnt_func; |
| 79 | | devcb_resolved_write_line out_sp_func; |
| 65 | return global_alloc(mos6526_device_config(mconfig, tag, owner, clock)); |
| 66 | } |
| 80 | 67 | |
| 81 | | cia_port port[2]; |
| 82 | | cia_timer timer[2]; |
| 83 | 68 | |
| 84 | | /* Time Of the Day clock (TOD) */ |
| 85 | | UINT32 tod; |
| 86 | | UINT32 tod_latch; |
| 87 | | UINT8 tod_latched; |
| 88 | | UINT8 tod_running; |
| 89 | | UINT32 alarm; |
| 69 | //------------------------------------------------- |
| 70 | // alloc_device - allocate a new device object |
| 71 | //------------------------------------------------- |
| 90 | 72 | |
| 91 | | /* Interrupts */ |
| 92 | | UINT8 icr; |
| 93 | | UINT8 ics; |
| 94 | | UINT8 irq; |
| 95 | | int flag; |
| 73 | device_t *mos6526_device_config::alloc_device(running_machine &machine) const |
| 74 | { |
| 75 | return auto_alloc(&machine, mos6526_device(machine, *this)); |
| 76 | } |
| 96 | 77 | |
| 97 | | /* Serial */ |
| 98 | | UINT8 loaded; |
| 99 | | UINT8 sdr; |
| 100 | | UINT8 sp; |
| 101 | | UINT8 cnt; |
| 102 | | UINT8 shift; |
| 103 | | UINT8 serial; |
| 104 | | }; |
| 105 | 78 | |
| 106 | | /*************************************************************************** |
| 107 | | PROTOTYPES |
| 108 | | ***************************************************************************/ |
| 79 | //------------------------------------------------- |
| 80 | // device_config_complete - perform any |
| 81 | // operations now that the configuration is |
| 82 | // complete |
| 83 | //------------------------------------------------- |
| 109 | 84 | |
| 110 | | static TIMER_CALLBACK( cia_timer_proc ); |
| 111 | | static void cia_timer_underflow(running_device *device, int timer); |
| 112 | | static TIMER_CALLBACK( cia_clock_tod_callback ); |
| 113 | | |
| 114 | | /*************************************************************************** |
| 115 | | INLINE FUNCTIONS |
| 116 | | ***************************************************************************/ |
| 117 | | |
| 118 | | INLINE cia_state *get_token(running_device *device) |
| 85 | void mos6526_device_config::device_config_complete() |
| 119 | 86 | { |
| 120 | | assert(device != NULL); |
| 121 | | assert((device->type() == MOS6526R1) || (device->type() == MOS6526R2) || (device->type() == MOS8520)); |
| 122 | | return (cia_state *) downcast<legacy_device_base *>(device)->token(); |
| 123 | | } |
| 87 | // inherit a copy of the static data |
| 88 | const mos6526_interface *intf = reinterpret_cast<const mos6526_interface *>(static_config()); |
| 89 | if (intf != NULL) |
| 90 | *static_cast<mos6526_interface *>(this) = *intf; |
| 124 | 91 | |
| 125 | | INLINE const mos6526_interface *get_interface(running_device *device) |
| 126 | | { |
| 127 | | assert(device != NULL); |
| 128 | | assert((device->type() == MOS6526R1) || (device->type() == MOS6526R2) || (device->type() == MOS8520)); |
| 129 | | return (mos6526_interface *) device->baseconfig().static_config(); |
| 92 | // or initialize to defaults if none provided |
| 93 | else |
| 94 | { |
| 95 | m_tod_clock = 0; |
| 96 | memset(&m_out_irq_func, 0, sizeof(m_out_irq_func)); |
| 97 | memset(&m_out_pc_func, 0, sizeof(m_out_pc_func)); |
| 98 | memset(&m_out_cnt_func, 0, sizeof(m_out_cnt_func)); |
| 99 | memset(&m_out_sp_func, 0, sizeof(m_out_sp_func)); |
| 100 | memset(&m_in_pa_func, 0, sizeof(m_in_pa_func)); |
| 101 | memset(&m_out_pa_func, 0, sizeof(m_out_pa_func)); |
| 102 | memset(&m_in_pb_func, 0, sizeof(m_in_pb_func)); |
| 103 | memset(&m_out_pb_func, 0, sizeof(m_out_pb_func)); |
| 104 | } |
| 130 | 105 | } |
| 131 | 106 | |
| 132 | | /*************************************************************************** |
| 133 | | IMPLEMENTATION |
| 134 | | ***************************************************************************/ |
| 135 | 107 | |
| 136 | | /*------------------------------------------------- |
| 137 | | cia_set_port_mask_value |
| 138 | | -------------------------------------------------*/ |
| 139 | 108 | |
| 140 | | void cia_set_port_mask_value(running_device *device, int port, int data) |
| 109 | //************************************************************************** |
| 110 | // LIVE DEVICE |
| 111 | //************************************************************************** |
| 112 | |
| 113 | const device_type MOS6526R1 = mos6526_device_config::static_alloc_device_config; |
| 114 | const device_type MOS6526R2 = mos6526_device_config::static_alloc_device_config; |
| 115 | const device_type MOS8520 = mos6526_device_config::static_alloc_device_config; |
| 116 | |
| 117 | //------------------------------------------------- |
| 118 | // mos6526_device - constructor |
| 119 | //------------------------------------------------- |
| 120 | |
| 121 | mos6526_device::mos6526_device(running_machine &_machine, const mos6526_device_config &config) |
| 122 | : device_t(_machine, config), |
| 123 | m_config(config) |
| 141 | 124 | { |
| 142 | | cia_state *cia = get_token(device); |
| 143 | | cia->port[port].mask_value = data; |
| 125 | |
| 144 | 126 | } |
| 145 | 127 | |
| 146 | | /*------------------------------------------------- |
| 147 | | DEVICE_RESET( cia ) |
| 148 | | -------------------------------------------------*/ |
| 149 | 128 | |
| 150 | | static DEVICE_RESET( cia ) |
| 151 | | { |
| 152 | | int t; |
| 153 | | cia_state *cia = get_token(device); |
| 129 | //------------------------------------------------- |
| 130 | // device_reset - device-specific reset |
| 131 | //------------------------------------------------- |
| 154 | 132 | |
| 133 | void mos6526_device::device_reset() |
| 134 | { |
| 155 | 135 | /* clear things out */ |
| 156 | | cia->port[0].latch = 0x00; |
| 157 | | cia->port[0].in = 0x00; |
| 158 | | cia->port[0].out = 0x00; |
| 159 | | cia->port[0].mask_value = 0xff; |
| 160 | | cia->port[1].latch = 0x00; |
| 161 | | cia->port[1].in = 0x00; |
| 162 | | cia->port[1].out = 0x00; |
| 163 | | cia->port[1].mask_value = 0xff; |
| 164 | | cia->tod = 0; |
| 165 | | cia->tod_latch = 0; |
| 166 | | cia->alarm = 0; |
| 167 | | cia->icr = 0x00; |
| 168 | | cia->ics = 0x00; |
| 169 | | cia->irq = 0; |
| 170 | | cia->shift = 0; |
| 171 | | cia->loaded = 0; |
| 172 | | cia->cnt = 1; |
| 173 | | cia->sp = 0; |
| 136 | m_port[0].m_latch = 0x00; |
| 137 | m_port[0].m_in = 0x00; |
| 138 | m_port[0].m_out = 0x00; |
| 139 | m_port[0].m_mask_value = 0xff; |
| 140 | m_port[1].m_latch = 0x00; |
| 141 | m_port[1].m_in = 0x00; |
| 142 | m_port[1].m_out = 0x00; |
| 143 | m_port[1].m_mask_value = 0xff; |
| 144 | m_tod = 0; |
| 145 | m_tod_latch = 0; |
| 146 | m_alarm = 0; |
| 147 | m_icr = 0x00; |
| 148 | m_ics = 0x00; |
| 149 | m_irq = 0; |
| 150 | m_shift = 0; |
| 151 | m_loaded = 0; |
| 152 | m_cnt = 1; |
| 153 | m_sp = 0; |
| 174 | 154 | |
| 175 | 155 | /* initialize data direction registers */ |
| 176 | | cia->port[0].ddr = !strcmp(device->tag(), "cia_0") ? 0x03 : 0xff; |
| 177 | | cia->port[1].ddr = !strcmp(device->tag(), "cia_0") ? 0x00 : 0xff; |
| 156 | m_port[0].m_ddr = !strcmp(tag(), "cia_0") ? 0x03 : 0xff; |
| 157 | m_port[1].m_ddr = !strcmp(tag(), "cia_0") ? 0x00 : 0xff; |
| 178 | 158 | |
| 179 | 159 | /* TOD running by default */ |
| 180 | | cia->tod_running = TRUE; |
| 160 | m_tod_running = TRUE; |
| 181 | 161 | |
| 182 | 162 | /* initialize timers */ |
| 183 | | for (t = 0; t < 2; t++) |
| 163 | for(int t = 0; t < 2; t++) |
| 184 | 164 | { |
| 185 | | cia_timer *timer = &cia->timer[t]; |
| 186 | | |
| 187 | | timer->latch = 0xffff; |
| 188 | | timer->count = 0x0000; |
| 189 | | timer->mode = 0x00; |
| 165 | cia_timer *timer = &m_timer[t]; |
| 166 | timer->m_cia = this; |
| 167 | timer->m_clock = clock(); |
| 168 | timer->m_latch = 0xffff; |
| 169 | timer->m_count = 0x0000; |
| 170 | timer->m_mode = 0x00; |
| 190 | 171 | } |
| 191 | 172 | } |
| 192 | 173 | |
| 193 | | /*------------------------------------------------- |
| 194 | | DEVICE_VALIDITY_CHECK( cia ) |
| 195 | | -------------------------------------------------*/ |
| 196 | 174 | |
| 197 | | #if 0 |
| 198 | | static DEVICE_VALIDITY_CHECK( cia ) |
| 175 | //------------------------------------------------- |
| 176 | // device_start - device-specific startup |
| 177 | //------------------------------------------------- |
| 178 | |
| 179 | void mos6526_device::device_start() |
| 199 | 180 | { |
| 200 | | int error = FALSE; |
| 181 | /* clear out CIA structure, and copy the interface */ |
| 182 | devcb_resolve_write_line(&m_out_irq_func, &m_config.m_out_irq_func, this); |
| 183 | devcb_resolve_write_line(&m_out_pc_func, &m_config.m_out_pc_func, this); |
| 184 | devcb_resolve_write_line(&m_out_cnt_func, &m_config.m_out_cnt_func, this); |
| 185 | devcb_resolve_write_line(&m_out_sp_func, &m_config.m_out_sp_func, this); |
| 186 | m_flag = 1; |
| 201 | 187 | |
| 202 | | if (device->clock() <= 0) |
| 188 | /* setup ports */ |
| 189 | devcb_resolve_read8(&m_port[0].m_read, &m_config.m_in_pa_func, this); |
| 190 | devcb_resolve_write8(&m_port[0].m_write, &m_config.m_out_pa_func, this); |
| 191 | devcb_resolve_read8(&m_port[1].m_read, &m_config.m_in_pb_func, this); |
| 192 | devcb_resolve_write8(&m_port[1].m_write, &m_config.m_out_pb_func, this); |
| 193 | |
| 194 | for (int p = 0; p < (sizeof(m_port) / sizeof(m_port[0])); p++) |
| 203 | 195 | { |
| 204 | | mame_printf_error("%s: %s has a cia with an invalid clock\n", driver->source_file, driver->name); |
| 205 | | error = TRUE; |
| 196 | m_port[p].m_mask_value = 0xff; |
| 206 | 197 | } |
| 207 | 198 | |
| 208 | | return error; |
| 209 | | } |
| 210 | | #endif |
| 199 | /* setup timers */ |
| 200 | for (int t = 0; t < (sizeof(m_timer) / sizeof(m_timer[0])); t++) |
| 201 | { |
| 202 | cia_timer *timer = &m_timer[t]; |
| 203 | timer->m_timer = timer_alloc(&m_machine, timer_proc, (void*)this); |
| 204 | timer->m_cia = this; |
| 205 | timer->m_irq = 0x01 << t; |
| 206 | } |
| 211 | 207 | |
| 212 | | /*------------------------------------------------- |
| 213 | | cia_update_pc - pulse /pc output |
| 214 | | -------------------------------------------------*/ |
| 208 | /* setup TOD timer, if appropriate */ |
| 209 | if (m_config.m_tod_clock != 0) |
| 210 | { |
| 211 | timer_pulse(&m_machine, ATTOTIME_IN_HZ(m_config.m_tod_clock), (void *)this, 0, clock_tod_callback); |
| 212 | } |
| 215 | 213 | |
| 216 | | static void cia_update_pc(running_device *device) |
| 217 | | { |
| 218 | | cia_state *cia = get_token(device); |
| 219 | | |
| 220 | | /* this should really be one cycle long */ |
| 221 | | devcb_call_write_line(&cia->out_pc_func, 0); |
| 222 | | devcb_call_write_line(&cia->out_pc_func, 1); |
| 214 | /* state save support */ |
| 215 | state_save_register_device_item(this, 0, m_port[0].m_ddr); |
| 216 | state_save_register_device_item(this, 0, m_port[0].m_latch); |
| 217 | state_save_register_device_item(this, 0, m_port[0].m_in); |
| 218 | state_save_register_device_item(this, 0, m_port[0].m_out); |
| 219 | state_save_register_device_item(this, 0, m_port[0].m_mask_value); |
| 220 | state_save_register_device_item(this, 0, m_port[1].m_ddr); |
| 221 | state_save_register_device_item(this, 0, m_port[1].m_latch); |
| 222 | state_save_register_device_item(this, 0, m_port[1].m_in); |
| 223 | state_save_register_device_item(this, 0, m_port[1].m_out); |
| 224 | state_save_register_device_item(this, 0, m_port[1].m_mask_value); |
| 225 | state_save_register_device_item(this, 0, m_timer[0].m_latch); |
| 226 | state_save_register_device_item(this, 0, m_timer[0].m_count); |
| 227 | state_save_register_device_item(this, 0, m_timer[0].m_mode); |
| 228 | state_save_register_device_item(this, 0, m_timer[0].m_irq); |
| 229 | state_save_register_device_item(this, 0, m_timer[1].m_latch); |
| 230 | state_save_register_device_item(this, 0, m_timer[1].m_count); |
| 231 | state_save_register_device_item(this, 0, m_timer[1].m_mode); |
| 232 | state_save_register_device_item(this, 0, m_timer[1].m_irq); |
| 233 | state_save_register_device_item(this, 0, m_tod); |
| 234 | state_save_register_device_item(this, 0, m_tod_latch); |
| 235 | state_save_register_device_item(this, 0, m_tod_latched); |
| 236 | state_save_register_device_item(this, 0, m_tod_running); |
| 237 | state_save_register_device_item(this, 0, m_alarm); |
| 238 | state_save_register_device_item(this, 0, m_icr); |
| 239 | state_save_register_device_item(this, 0, m_ics); |
| 240 | state_save_register_device_item(this, 0, m_irq); |
| 241 | state_save_register_device_item(this, 0, m_flag); |
| 242 | state_save_register_device_item(this, 0, m_loaded); |
| 243 | state_save_register_device_item(this, 0, m_sdr); |
| 244 | state_save_register_device_item(this, 0, m_sp); |
| 245 | state_save_register_device_item(this, 0, m_cnt); |
| 246 | state_save_register_device_item(this, 0, m_shift); |
| 247 | state_save_register_device_item(this, 0, m_serial); |
| 223 | 248 | } |
| 224 | 249 | |
| 250 | |
| 225 | 251 | /*------------------------------------------------- |
| 226 | | cia_update_interrupts |
| 252 | set_port_mask_value |
| 227 | 253 | -------------------------------------------------*/ |
| 228 | 254 | |
| 229 | | static void cia_update_interrupts(running_device *device) |
| 255 | void mos6526_device::set_port_mask_value(int port, int data) |
| 230 | 256 | { |
| 231 | | UINT8 new_irq; |
| 232 | | cia_state *cia = get_token(device); |
| 233 | | |
| 234 | | /* always update the high bit of ICS */ |
| 235 | | if (cia->ics & 0x7f) |
| 236 | | cia->ics |= 0x80; |
| 237 | | else |
| 238 | | cia->ics &= ~0x80; |
| 239 | | |
| 240 | | /* based on what is enabled, set/clear the IRQ via the custom chip */ |
| 241 | | new_irq = (cia->ics & cia->icr) ? 1 : 0; |
| 242 | | if (cia->irq != new_irq) |
| 243 | | { |
| 244 | | cia->irq = new_irq; |
| 245 | | devcb_call_write_line(&cia->out_irq_func, cia->irq); |
| 246 | | } |
| 257 | m_port[port].m_mask_value = data; |
| 247 | 258 | } |
| 248 | 259 | |
| 249 | 260 | /*------------------------------------------------- |
| 250 | | is_timer_active |
| 261 | update_pc - pulse /pc output |
| 251 | 262 | -------------------------------------------------*/ |
| 252 | 263 | |
| 253 | | static int is_timer_active(emu_timer *timer) |
| 264 | void mos6526_device::update_pc() |
| 254 | 265 | { |
| 255 | | attotime t = timer_firetime(timer); |
| 256 | | return attotime_compare(t, attotime_never) != 0; |
| 266 | /* this should really be one cycle long */ |
| 267 | devcb_call_write_line(&m_out_pc_func, 0); |
| 268 | devcb_call_write_line(&m_out_pc_func, 1); |
| 257 | 269 | } |
| 258 | 270 | |
| 259 | 271 | /*------------------------------------------------- |
| 260 | | cia_timer_update - updates the count and |
| 261 | | emu_timer for a given CIA timer |
| 272 | update_interrupts |
| 262 | 273 | -------------------------------------------------*/ |
| 263 | 274 | |
| 264 | | static void cia_timer_update(cia_timer *timer, INT32 new_count) |
| 275 | void mos6526_device::update_interrupts() |
| 265 | 276 | { |
| 266 | | int which = timer - timer->cia->timer; |
| 277 | UINT8 new_irq; |
| 267 | 278 | |
| 268 | | /* sanity check arguments */ |
| 269 | | assert((new_count >= -1) && (new_count <= 0xffff)); |
| 270 | | |
| 271 | | /* update the timer count, if necessary */ |
| 272 | | if ((new_count == -1) && is_timer_active(timer->timer)) |
| 279 | /* always update the high bit of ICS */ |
| 280 | if (m_ics & 0x7f) |
| 273 | 281 | { |
| 274 | | UINT16 current_count = attotime_to_double(attotime_mul(timer_timeelapsed(timer->timer), timer->cia->device->clock())); |
| 275 | | timer->count = timer->count - MIN(timer->count, current_count); |
| 282 | m_ics |= 0x80; |
| 276 | 283 | } |
| 277 | | |
| 278 | | /* set the timer if we are instructed to */ |
| 279 | | if (new_count != -1) |
| 280 | | timer->count = new_count; |
| 281 | | |
| 282 | | /* now update the MAME timer */ |
| 283 | | if ((timer->mode & 0x01) && ((timer->mode & (which ? 0x60 : 0x20)) == 0x00)) |
| 284 | else |
| 284 | 285 | { |
| 285 | | /* timer is on and is connected to clock */ |
| 286 | | attotime period = attotime_mul(ATTOTIME_IN_HZ(timer->cia->device->clock()), (timer->count ? timer->count : 0x10000)); |
| 287 | | timer_adjust_oneshot(timer->timer, period, 0); |
| 286 | m_ics &= ~0x80; |
| 288 | 287 | } |
| 289 | | else |
| 288 | |
| 289 | /* based on what is enabled, set/clear the IRQ via the custom chip */ |
| 290 | new_irq = (m_ics & m_icr) ? 1 : 0; |
| 291 | if (m_irq != new_irq) |
| 290 | 292 | { |
| 291 | | /* timer is off or not connected to clock */ |
| 292 | | timer_adjust_oneshot(timer->timer, attotime_never, 0); |
| 293 | m_irq = new_irq; |
| 294 | devcb_call_write_line(&m_out_irq_func, m_irq); |
| 293 | 295 | } |
| 294 | 296 | } |
| 295 | 297 | |
| 298 | |
| 296 | 299 | /*------------------------------------------------- |
| 297 | | cia_get_timer - get the count |
| 298 | | for a given CIA timer |
| 300 | timer_bump |
| 299 | 301 | -------------------------------------------------*/ |
| 300 | 302 | |
| 301 | | static UINT16 cia_get_timer(cia_timer *timer) |
| 303 | void mos6526_device::timer_bump(int timer) |
| 302 | 304 | { |
| 303 | | UINT16 count; |
| 305 | m_timer[timer].update(timer, -1); |
| 304 | 306 | |
| 305 | | if (is_timer_active(timer->timer)) |
| 307 | if (m_timer[timer].m_count == 0x00) |
| 306 | 308 | { |
| 307 | | UINT16 current_count = attotime_to_double(attotime_mul(timer_timeelapsed(timer->timer), timer->cia->device->clock())); |
| 308 | | count = timer->count - MIN(timer->count, current_count); |
| 309 | timer_underflow(timer); |
| 309 | 310 | } |
| 310 | 311 | else |
| 311 | | count = timer->count; |
| 312 | | |
| 313 | | return count; |
| 312 | { |
| 313 | m_timer[timer].update(timer, m_timer[timer].m_count - 1); |
| 314 | } |
| 314 | 315 | } |
| 315 | 316 | |
| 316 | 317 | /*------------------------------------------------- |
| 317 | | cia_timer_bump |
| 318 | | -------------------------------------------------*/ |
| 319 | | |
| 320 | | static void cia_timer_bump(running_device *device, int timer) |
| 321 | | { |
| 322 | | cia_state *cia = get_token(device); |
| 323 | | |
| 324 | | cia_timer_update(&cia->timer[timer], -1); |
| 325 | | |
| 326 | | if (cia->timer[timer].count == 0x00) |
| 327 | | cia_timer_underflow(device, timer); |
| 328 | | else |
| 329 | | cia_timer_update(&cia->timer[timer], cia->timer[timer].count - 1); |
| 330 | | } |
| 331 | | |
| 332 | | /*------------------------------------------------- |
| 333 | 318 | cia_timer_underflow |
| 334 | 319 | -------------------------------------------------*/ |
| 335 | 320 | |
| 336 | | static void cia_timer_underflow(running_device *device, int timer) |
| 321 | void mos6526_device::timer_underflow(int timer) |
| 337 | 322 | { |
| 338 | | cia_state *cia = get_token(device); |
| 339 | | |
| 340 | 323 | assert((timer == 0) || (timer == 1)); |
| 341 | 324 | |
| 342 | 325 | /* set the status and update interrupts */ |
| 343 | | cia->ics |= cia->timer[timer].irq; |
| 344 | | cia_update_interrupts(device); |
| 326 | m_ics |= m_timer[timer].m_irq; |
| 327 | update_interrupts(); |
| 345 | 328 | |
| 346 | 329 | /* if one-shot mode, turn it off */ |
| 347 | | if (cia->timer[timer].mode & 0x08) |
| 348 | | cia->timer[timer].mode &= 0xfe; |
| 330 | if (m_timer[timer].m_mode & 0x08) |
| 331 | { |
| 332 | m_timer[timer].m_mode &= 0xfe; |
| 333 | } |
| 349 | 334 | |
| 350 | 335 | /* reload the timer */ |
| 351 | | cia_timer_update(&cia->timer[timer], cia->timer[timer].latch); |
| 336 | m_timer[timer].update(timer, m_timer[timer].m_latch); |
| 352 | 337 | |
| 353 | 338 | /* timer A has some interesting properties */ |
| 354 | 339 | if (timer == 0) |
| 355 | 340 | { |
| 356 | 341 | /* such as cascading to timer B */ |
| 357 | | if ((cia->timer[1].mode & 0x41) == 0x41) |
| 342 | if ((m_timer[1].m_mode & 0x41) == 0x41) |
| 358 | 343 | { |
| 359 | | if (cia->cnt || !(cia->timer[1].mode & 0x20)) |
| 360 | | cia_timer_bump(device, 1); |
| 344 | if (m_cnt || !(m_timer[1].m_mode & 0x20)) |
| 345 | { |
| 346 | timer_bump(1); |
| 347 | } |
| 361 | 348 | } |
| 362 | 349 | |
| 363 | 350 | /* also the serial line */ |
| 364 | | if ((cia->timer[timer].irq == 0x01) && (cia->timer[timer].mode & CIA_CRA_SPMODE)) |
| 351 | if ((m_timer[timer].m_irq == 0x01) && (m_timer[timer].m_mode & CIA_CRA_SPMODE)) |
| 365 | 352 | { |
| 366 | | if (cia->loaded || cia->shift) |
| 353 | if (m_loaded || m_shift) |
| 367 | 354 | { |
| 368 | 355 | /* falling edge */ |
| 369 | | if (cia->cnt) |
| 356 | if (m_cnt) |
| 370 | 357 | { |
| 371 | | if (cia->shift == 0) |
| 358 | if (m_shift == 0) |
| 372 | 359 | { |
| 373 | 360 | /* load shift register */ |
| 374 | | cia->loaded = 0; |
| 375 | | cia->serial = cia->sdr; |
| 361 | m_loaded = 0; |
| 362 | m_serial = m_sdr; |
| 376 | 363 | } |
| 377 | 364 | |
| 378 | 365 | /* transmit MSB */ |
| 379 | | cia->sp = BIT(cia->serial, 7); |
| 380 | | devcb_call_write_line(&cia->out_sp_func, cia->sp); |
| 366 | m_sp = BIT(m_serial, 7); |
| 367 | devcb_call_write_line(&m_out_sp_func, m_sp); |
| 381 | 368 | |
| 382 | 369 | /* toggle CNT */ |
| 383 | | cia->cnt = !cia->cnt; |
| 384 | | devcb_call_write_line(&cia->out_cnt_func, cia->cnt); |
| 370 | m_cnt = !m_cnt; |
| 371 | devcb_call_write_line(&m_out_cnt_func, m_cnt); |
| 385 | 372 | |
| 386 | 373 | /* shift data */ |
| 387 | | cia->serial <<= 1; |
| 388 | | cia->shift++; |
| 374 | m_serial <<= 1; |
| 375 | m_shift++; |
| 389 | 376 | |
| 390 | | if (cia->shift == 8) |
| 377 | if (m_shift == 8) |
| 391 | 378 | { |
| 392 | 379 | /* signal interrupt */ |
| 393 | | cia->ics |= 0x08; |
| 394 | | cia_update_interrupts(device); |
| 380 | m_ics |= 0x08; |
| 381 | update_interrupts(); |
| 395 | 382 | } |
| 396 | 383 | } |
| 397 | 384 | else |
| 398 | 385 | { |
| 399 | 386 | /* toggle CNT */ |
| 400 | | cia->cnt = !cia->cnt; |
| 401 | | devcb_call_write_line(&cia->out_cnt_func, cia->cnt); |
| 387 | m_cnt = !m_cnt; |
| 388 | devcb_call_write_line(&m_out_cnt_func, m_cnt); |
| 402 | 389 | |
| 403 | | if (cia->shift == 8) |
| 390 | if (m_shift == 8) |
| 404 | 391 | { |
| 405 | | cia->shift = 0; |
| 392 | m_shift = 0; |
| 406 | 393 | } |
| 407 | 394 | } |
| 408 | 395 | } |
| r8892 | r8893 | |
| 414 | 401 | TIMER_CALLBACK( cia_timer_proc ) |
| 415 | 402 | -------------------------------------------------*/ |
| 416 | 403 | |
| 417 | | static TIMER_CALLBACK( cia_timer_proc ) |
| 404 | TIMER_CALLBACK( mos6526_device::timer_proc ) |
| 418 | 405 | { |
| 419 | | cia_timer *timer = (cia_timer *)ptr; |
| 420 | | cia_state *cia = timer->cia; |
| 406 | mos6526_device *cia = reinterpret_cast<mos6526_device *>(ptr); |
| 421 | 407 | |
| 422 | | cia_timer_underflow(cia->device, timer - cia->timer); |
| 408 | cia->timer_underflow(param); |
| 423 | 409 | } |
| 424 | 410 | |
| 425 | 411 | /*------------------------------------------------- |
| r8892 | r8893 | |
| 438 | 424 | cia6526_increment |
| 439 | 425 | -------------------------------------------------*/ |
| 440 | 426 | |
| 441 | | static void cia6526_increment(cia_state *cia) |
| 427 | void mos6526_device::increment() |
| 442 | 428 | { |
| 443 | 429 | /* break down TOD value into components */ |
| 444 | | UINT8 subsecond = (UINT8) (cia->tod >> 0); |
| 445 | | UINT8 second = (UINT8) (cia->tod >> 8); |
| 446 | | UINT8 minute = (UINT8) (cia->tod >> 16); |
| 447 | | UINT8 hour = (UINT8) (cia->tod >> 24); |
| 430 | UINT8 subsecond = (UINT8) (m_tod >> 0); |
| 431 | UINT8 second = (UINT8) (m_tod >> 8); |
| 432 | UINT8 minute = (UINT8) (m_tod >> 16); |
| 433 | UINT8 hour = (UINT8) (m_tod >> 24); |
| 448 | 434 | |
| 449 | 435 | subsecond = bcd_increment(subsecond); |
| 450 | 436 | if (subsecond >= 0x10) |
| 451 | 437 | { |
| 452 | 438 | subsecond = 0x00; |
| 453 | 439 | second = bcd_increment(second); |
| 454 | | if (second >= ((cia->timer[0].mode & 0x80) ? 0x50 : 0x60)) |
| 440 | if (second >= ((m_timer[0].m_mode & 0x80) ? 0x50 : 0x60)) |
| 455 | 441 | { |
| 456 | 442 | second = 0x00; |
| 457 | 443 | minute = bcd_increment(minute); |
| r8892 | r8893 | |
| 473 | 459 | } |
| 474 | 460 | |
| 475 | 461 | /* update the TOD with new value */ |
| 476 | | cia->tod = (((UINT32) subsecond) << 0) |
| 477 | | | (((UINT32) second) << 8) |
| 478 | | | (((UINT32) minute) << 16) |
| 479 | | | (((UINT32) hour) << 24); |
| 462 | m_tod = (((UINT32) subsecond) << 0) |
| 463 | | (((UINT32) second) << 8) |
| 464 | | (((UINT32) minute) << 16) |
| 465 | | (((UINT32) hour) << 24); |
| 480 | 466 | } |
| 481 | 467 | |
| 482 | 468 | /*------------------------------------------------- |
| 483 | 469 | cia_clock_tod - Update TOD on CIA A |
| 484 | 470 | -------------------------------------------------*/ |
| 485 | 471 | |
| 486 | | static void cia_clock_tod(running_device *device) |
| 472 | void mos6526_device::clock_tod() |
| 487 | 473 | { |
| 488 | | cia_state *cia; |
| 489 | | |
| 490 | | cia = get_token(device); |
| 491 | | |
| 492 | | if (cia->tod_running) |
| 474 | if (m_tod_running) |
| 493 | 475 | { |
| 494 | | if ((device->type() == MOS6526R1) || (device->type() == MOS6526R2)) |
| 476 | if ((type() == MOS6526R1) || (type() == MOS6526R2)) |
| 495 | 477 | { |
| 496 | 478 | /* The 6526 split the value into hours, minutes, seconds and |
| 497 | 479 | * subseconds */ |
| 498 | | cia6526_increment(cia); |
| 480 | increment(); |
| 499 | 481 | } |
| 500 | | else if (device->type() == MOS8520) |
| 482 | else if (type() == MOS8520) |
| 501 | 483 | { |
| 502 | 484 | /* the 8520 has a straight 24-bit counter */ |
| 503 | | cia->tod++; |
| 504 | | cia->tod &= 0xffffff; |
| 485 | m_tod++; |
| 486 | m_tod &= 0xffffff; |
| 505 | 487 | } |
| 506 | 488 | |
| 507 | | if (cia->tod == cia->alarm) |
| 489 | if (m_tod == m_alarm) |
| 508 | 490 | { |
| 509 | | cia->ics |= 0x04; |
| 510 | | cia_update_interrupts(device); |
| 491 | m_ics |= 0x04; |
| 492 | update_interrupts(); |
| 511 | 493 | } |
| 512 | 494 | } |
| 513 | 495 | } |
| 514 | 496 | |
| 497 | |
| 515 | 498 | /*------------------------------------------------- |
| 516 | | cia_clock_tod_callback |
| 499 | clock_tod_callback |
| 517 | 500 | -------------------------------------------------*/ |
| 518 | 501 | |
| 519 | | static TIMER_CALLBACK( cia_clock_tod_callback ) |
| 502 | TIMER_CALLBACK( mos6526_device::clock_tod_callback ) |
| 520 | 503 | { |
| 521 | | running_device *device = (running_device *)ptr; |
| 522 | | cia_clock_tod(device); |
| 504 | mos6526_device *cia = reinterpret_cast<mos6526_device *>(ptr); |
| 505 | cia->clock_tod(); |
| 523 | 506 | } |
| 524 | 507 | |
| 525 | | READ8_DEVICE_HANDLER( mos6526_pa_r ) |
| 526 | | { |
| 527 | | return (get_token(device)->port[0].latch | ~get_token(device)->port[0].ddr); |
| 528 | | } |
| 529 | 508 | |
| 530 | | READ8_DEVICE_HANDLER( mos6526_pb_r ) |
| 531 | | { |
| 532 | | return (get_token(device)->port[1].latch | ~get_token(device)->port[1].ddr); |
| 533 | | } |
| 509 | /*------------------------------------------------- |
| 510 | cnt_w |
| 511 | -------------------------------------------------*/ |
| 534 | 512 | |
| 535 | | READ_LINE_DEVICE_HANDLER( mos6526_irq_r ) |
| 513 | void mos6526_device::cnt_w(UINT8 state) |
| 536 | 514 | { |
| 537 | | cia_state *cia = get_token(device); |
| 538 | | |
| 539 | | return cia->irq; |
| 540 | | } |
| 541 | | |
| 542 | | WRITE_LINE_DEVICE_HANDLER( mos6526_tod_w ) |
| 543 | | { |
| 544 | | if (state) cia_clock_tod(device); |
| 545 | | } |
| 546 | | |
| 547 | | READ_LINE_DEVICE_HANDLER( mos6526_cnt_r ) |
| 548 | | { |
| 549 | | cia_state *cia = get_token(device); |
| 550 | | |
| 551 | | return cia->cnt; |
| 552 | | } |
| 553 | | |
| 554 | | WRITE_LINE_DEVICE_HANDLER( mos6526_cnt_w ) |
| 555 | | { |
| 556 | | cia_state *cia = get_token(device); |
| 557 | | |
| 558 | 515 | /* is this a rising edge? */ |
| 559 | | if (!cia->cnt && state) |
| 516 | if (!m_cnt && state) |
| 560 | 517 | { |
| 561 | | if (cia->timer[0].mode & CIA_CRA_START) |
| 518 | if (m_timer[0].m_mode & CIA_CRA_START) |
| 562 | 519 | { |
| 563 | 520 | /* does timer #0 bump on CNT? */ |
| 564 | | if (cia->timer[0].mode & CIA_CRA_INMODE) |
| 565 | | cia_timer_bump(device, 0); |
| 521 | if (m_timer[0].m_mode & CIA_CRA_INMODE) |
| 522 | { |
| 523 | timer_bump(0); |
| 524 | } |
| 566 | 525 | } |
| 567 | 526 | |
| 568 | 527 | /* if the serial port is set to input, the CNT will shift the port */ |
| 569 | | if (!(cia->timer[0].mode & CIA_CRA_SPMODE)) |
| 528 | if (!(m_timer[0].m_mode & CIA_CRA_SPMODE)) |
| 570 | 529 | { |
| 571 | | cia->serial <<= 1; |
| 572 | | cia->shift++; |
| 530 | m_serial <<= 1; |
| 531 | m_shift++; |
| 573 | 532 | |
| 574 | | if (cia->sp) cia->serial |= 0x01; |
| 533 | if (m_sp) |
| 534 | { |
| 535 | m_serial |= 0x01; |
| 536 | } |
| 575 | 537 | |
| 576 | | if (cia->shift == 8) |
| 538 | if (m_shift == 8) |
| 577 | 539 | { |
| 578 | | cia->sdr = cia->serial; |
| 579 | | cia->serial = 0; |
| 580 | | cia->shift = 0; |
| 581 | | cia->ics |= 0x08; |
| 582 | | cia_update_interrupts(device); |
| 540 | m_sdr = m_serial; |
| 541 | m_serial = 0; |
| 542 | m_shift = 0; |
| 543 | m_ics |= 0x08; |
| 544 | update_interrupts(); |
| 583 | 545 | } |
| 584 | 546 | } |
| 585 | 547 | |
| 586 | 548 | /* does timer #1 bump on CNT? */ |
| 587 | | if ((cia->timer[1].mode & 0x61) == 0x21) |
| 588 | | cia_timer_bump(device, 1); |
| 549 | if ((m_timer[1].m_mode & 0x61) == 0x21) |
| 550 | { |
| 551 | timer_bump(1); |
| 552 | } |
| 589 | 553 | } |
| 590 | 554 | |
| 591 | | cia->cnt = state; |
| 555 | m_cnt = state; |
| 592 | 556 | } |
| 593 | 557 | |
| 594 | | READ_LINE_DEVICE_HANDLER( mos6526_sp_r ) |
| 558 | void mos6526_device::flag_w(UINT8 state) |
| 595 | 559 | { |
| 596 | | cia_state *cia = get_token(device); |
| 597 | | |
| 598 | | return cia->sp; |
| 599 | | } |
| 600 | | |
| 601 | | WRITE_LINE_DEVICE_HANDLER( mos6526_sp_w ) |
| 602 | | { |
| 603 | | cia_state *cia = get_token(device); |
| 604 | | |
| 605 | | cia->sp = state; |
| 606 | | } |
| 607 | | |
| 608 | | WRITE_LINE_DEVICE_HANDLER( mos6526_flag_w ) |
| 609 | | { |
| 610 | | cia_state *cia = get_token(device); |
| 611 | | |
| 612 | 560 | /* falling edge */ |
| 613 | | if (cia->flag && !state) |
| 561 | if (m_flag && !state) |
| 614 | 562 | { |
| 615 | | cia->ics |= 0x10; |
| 616 | | cia_update_interrupts(device); |
| 563 | m_ics |= 0x10; |
| 564 | update_interrupts(); |
| 617 | 565 | } |
| 618 | 566 | |
| 619 | | cia->flag = state; |
| 567 | m_flag = state; |
| 620 | 568 | } |
| 621 | 569 | |
| 622 | 570 | /*------------------------------------------------- |
| 623 | | mos6526_r |
| 571 | reg_r |
| 624 | 572 | -------------------------------------------------*/ |
| 625 | 573 | |
| 626 | | READ8_DEVICE_HANDLER( mos6526_r ) |
| 574 | UINT8 mos6526_device::reg_r(UINT8 offset) |
| 627 | 575 | { |
| 628 | 576 | cia_timer *timer; |
| 629 | | cia_state *cia; |
| 630 | 577 | cia_port *port; |
| 631 | 578 | UINT8 data = 0x00; |
| 632 | 579 | |
| 633 | | cia = get_token(device); |
| 634 | 580 | offset &= 0x0F; |
| 635 | 581 | |
| 636 | 582 | switch(offset) |
| r8892 | r8893 | |
| 638 | 584 | /* port A/B data */ |
| 639 | 585 | case CIA_PRA: |
| 640 | 586 | case CIA_PRB: |
| 641 | | port = &cia->port[offset & 1]; |
| 642 | | data = devcb_call_read8(&port->read, 0); |
| 643 | | data = ((data & ~port->ddr) | (port->latch & port->ddr)) & port->mask_value; |
| 587 | port = &m_port[offset & 1]; |
| 588 | data = devcb_call_read8(&port->m_read, 0); |
| 589 | data = ((data & ~port->m_ddr) | (port->m_latch & port->m_ddr)) & port->m_mask_value; |
| 644 | 590 | |
| 645 | | port->in = data; |
| 591 | port->m_in = data; |
| 646 | 592 | |
| 647 | 593 | if (offset == CIA_PRB) |
| 648 | 594 | { |
| 649 | 595 | /* timer #0 can change PB6 */ |
| 650 | | if (cia->timer[0].mode & 0x02) |
| 596 | if (m_timer[0].m_mode & 0x02) |
| 651 | 597 | { |
| 652 | | cia_timer_update(&cia->timer[0], -1); |
| 653 | | if (cia->timer[0].count != 0) |
| 598 | m_timer[0].update(0, -1); |
| 599 | if (m_timer[0].m_count != 0) |
| 600 | { |
| 654 | 601 | data |= 0x40; |
| 602 | } |
| 655 | 603 | else |
| 604 | { |
| 656 | 605 | data &= ~0x40; |
| 606 | } |
| 657 | 607 | } |
| 658 | 608 | |
| 659 | 609 | /* timer #1 can change PB7 */ |
| 660 | | if (cia->timer[1].mode & 0x02) |
| 610 | if (m_timer[1].m_mode & 0x02) |
| 661 | 611 | { |
| 662 | | cia_timer_update(&cia->timer[1], -1); |
| 663 | | if (cia->timer[1].count != 0) |
| 612 | m_timer[1].update(1, -1); |
| 613 | if (m_timer[1].m_count != 0) |
| 614 | { |
| 664 | 615 | data |= 0x80; |
| 616 | } |
| 665 | 617 | else |
| 618 | { |
| 666 | 619 | data &= ~0x80; |
| 620 | } |
| 667 | 621 | } |
| 668 | 622 | |
| 669 | 623 | /* pulse /PC following the read */ |
| 670 | | cia_update_pc(device); |
| 624 | update_pc(); |
| 671 | 625 | } |
| 672 | 626 | break; |
| 673 | 627 | |
| 674 | 628 | /* port A/B direction */ |
| 675 | 629 | case CIA_DDRA: |
| 676 | 630 | case CIA_DDRB: |
| 677 | | port = &cia->port[offset & 1]; |
| 678 | | data = port->ddr; |
| 631 | port = &m_port[offset & 1]; |
| 632 | data = port->m_ddr; |
| 679 | 633 | break; |
| 680 | 634 | |
| 681 | 635 | /* timer A/B low byte */ |
| 682 | 636 | case CIA_TALO: |
| 683 | 637 | case CIA_TBLO: |
| 684 | | timer = &cia->timer[(offset >> 1) & 1]; |
| 685 | | data = cia_get_timer(timer) >> 0; |
| 638 | timer = &m_timer[(offset >> 1) & 1]; |
| 639 | data = timer->get_count() >> 0; |
| 686 | 640 | break; |
| 687 | 641 | |
| 688 | 642 | /* timer A/B high byte */ |
| 689 | 643 | case CIA_TAHI: |
| 690 | 644 | case CIA_TBHI: |
| 691 | | timer = &cia->timer[(offset >> 1) & 1]; |
| 692 | | data = cia_get_timer(timer) >> 8; |
| 645 | timer = &m_timer[(offset >> 1) & 1]; |
| 646 | data = timer->get_count() >> 8; |
| 693 | 647 | break; |
| 694 | 648 | |
| 695 | 649 | /* TOD counter */ |
| r8892 | r8893 | |
| 697 | 651 | case CIA_TOD1: |
| 698 | 652 | case CIA_TOD2: |
| 699 | 653 | case CIA_TOD3: |
| 700 | | if (device->type() == MOS8520) |
| 654 | if (type() == MOS8520) |
| 701 | 655 | { |
| 702 | 656 | if (offset == CIA_TOD2) |
| 703 | 657 | { |
| 704 | | cia->tod_latch = cia->tod; |
| 705 | | cia->tod_latched = TRUE; |
| 658 | m_tod_latch = m_tod; |
| 659 | m_tod_latched = TRUE; |
| 706 | 660 | } |
| 707 | 661 | } |
| 708 | 662 | else |
| 709 | 663 | { |
| 710 | 664 | if (offset == CIA_TOD3) |
| 711 | 665 | { |
| 712 | | cia->tod_latch = cia->tod; |
| 713 | | cia->tod_latched = TRUE; |
| 666 | m_tod_latch = m_tod; |
| 667 | m_tod_latched = TRUE; |
| 714 | 668 | } |
| 715 | 669 | } |
| 716 | 670 | if (offset == CIA_TOD0) |
| 717 | | cia->tod_latched = FALSE; |
| 671 | { |
| 672 | m_tod_latched = FALSE; |
| 673 | } |
| 718 | 674 | |
| 719 | | if (cia->tod_latched) |
| 720 | | data = cia->tod_latch >> ((offset - CIA_TOD0) * 8); |
| 675 | if (m_tod_latched) |
| 676 | { |
| 677 | data = m_tod_latch >> ((offset - CIA_TOD0) * 8); |
| 678 | } |
| 721 | 679 | else |
| 722 | | data = cia->tod >> ((offset - CIA_TOD0) * 8); |
| 680 | { |
| 681 | data = m_tod >> ((offset - CIA_TOD0) * 8); |
| 682 | } |
| 723 | 683 | break; |
| 724 | 684 | |
| 725 | 685 | /* serial data ready */ |
| 726 | 686 | case CIA_SDR: |
| 727 | | data = cia->sdr; |
| 687 | data = m_sdr; |
| 728 | 688 | break; |
| 729 | 689 | |
| 730 | 690 | /* interrupt status/clear */ |
| 731 | 691 | case CIA_ICR: |
| 732 | | data = cia->ics; |
| 733 | | cia->ics = 0; /* clear on read */ |
| 734 | | cia_update_interrupts(device); |
| 692 | data = m_ics; |
| 693 | m_ics = 0; /* clear on read */ |
| 694 | update_interrupts(); |
| 735 | 695 | break; |
| 736 | 696 | |
| 737 | 697 | /* timer A/B mode */ |
| 738 | 698 | case CIA_CRA: |
| 739 | 699 | case CIA_CRB: |
| 740 | | timer = &cia->timer[offset & 1]; |
| 741 | | data = timer->mode; |
| 700 | timer = &m_timer[offset & 1]; |
| 701 | data = timer->m_mode; |
| 742 | 702 | break; |
| 743 | 703 | } |
| 744 | 704 | |
| r8892 | r8893 | |
| 746 | 706 | } |
| 747 | 707 | |
| 748 | 708 | /*------------------------------------------------- |
| 749 | | mos6526_w |
| 709 | reg_w |
| 750 | 710 | -------------------------------------------------*/ |
| 751 | 711 | |
| 752 | | WRITE8_DEVICE_HANDLER( mos6526_w ) |
| 712 | void mos6526_device::reg_w(UINT8 offset, UINT8 data) |
| 753 | 713 | { |
| 754 | 714 | cia_timer *timer; |
| 755 | | cia_state *cia; |
| 756 | 715 | cia_port *port; |
| 757 | 716 | int shift; |
| 758 | 717 | |
| 759 | | cia = get_token(device); |
| 760 | 718 | offset &= 0x0F; |
| 761 | 719 | |
| 762 | 720 | switch(offset) |
| r8892 | r8893 | |
| 764 | 722 | /* port A/B data */ |
| 765 | 723 | case CIA_PRA: |
| 766 | 724 | case CIA_PRB: |
| 767 | | port = &cia->port[offset & 1]; |
| 768 | | port->latch = data; |
| 769 | | port->out = (data & port->ddr) | (port->in & ~port->ddr); |
| 770 | | devcb_call_write8(&port->write, 0, port->out); |
| 725 | port = &m_port[offset & 1]; |
| 726 | port->m_latch = data; |
| 727 | port->m_out = (data & port->m_ddr) | (port->m_in & ~port->m_ddr); |
| 728 | devcb_call_write8(&port->m_write, 0, port->m_out); |
| 771 | 729 | |
| 772 | 730 | /* pulse /PC following the write */ |
| 773 | 731 | if (offset == CIA_PRB) |
| 774 | | cia_update_pc(device); |
| 732 | { |
| 733 | update_pc(); |
| 734 | } |
| 775 | 735 | |
| 776 | 736 | break; |
| 777 | 737 | |
| 778 | 738 | /* port A/B direction */ |
| 779 | 739 | case CIA_DDRA: |
| 780 | 740 | case CIA_DDRB: |
| 781 | | port = &cia->port[offset & 1]; |
| 782 | | port->ddr = data; |
| 741 | port = &m_port[offset & 1]; |
| 742 | port->m_ddr = data; |
| 783 | 743 | break; |
| 784 | 744 | |
| 785 | 745 | /* timer A/B latch low */ |
| 786 | 746 | case CIA_TALO: |
| 787 | 747 | case CIA_TBLO: |
| 788 | | timer = &cia->timer[(offset >> 1) & 1]; |
| 789 | | timer->latch = (timer->latch & 0xff00) | (data << 0); |
| 748 | timer = &m_timer[(offset >> 1) & 1]; |
| 749 | timer->m_latch = (timer->m_latch & 0xff00) | (data << 0); |
| 790 | 750 | break; |
| 791 | 751 | |
| 792 | 752 | /* timer A latch high */ |
| 793 | 753 | case CIA_TAHI: |
| 794 | 754 | case CIA_TBHI: |
| 795 | | timer = &cia->timer[(offset >> 1) & 1]; |
| 796 | | timer->latch = (timer->latch & 0x00ff) | (data << 8); |
| 755 | timer = &m_timer[(offset >> 1) & 1]; |
| 756 | timer->m_latch = (timer->m_latch & 0x00ff) | (data << 8); |
| 797 | 757 | |
| 798 | 758 | /* if the timer is one-shot, then force a start on it */ |
| 799 | | if (timer->mode & 0x08) |
| 759 | if (timer->m_mode & 0x08) |
| 800 | 760 | { |
| 801 | | timer->mode |= 1; |
| 802 | | cia_timer_update(timer, timer->latch); |
| 761 | timer->m_mode |= 1; |
| 762 | timer->update((offset >> 1) & 1, timer->m_latch); |
| 803 | 763 | } |
| 804 | 764 | else |
| 805 | 765 | { |
| 806 | 766 | /* if the timer is off, update the count */ |
| 807 | | if (!(timer->mode & 0x01)) |
| 808 | | cia_timer_update(timer, timer->latch); |
| 767 | if (!(timer->m_mode & 0x01)) |
| 768 | { |
| 769 | timer->update((offset >> 1) & 1, timer->m_latch); |
| 770 | } |
| 809 | 771 | } |
| 810 | 772 | break; |
| 811 | 773 | |
| r8892 | r8893 | |
| 817 | 779 | shift = 8 * ((offset - CIA_TOD0)); |
| 818 | 780 | |
| 819 | 781 | /* alarm setting mode? */ |
| 820 | | if (cia->timer[1].mode & 0x80) |
| 821 | | cia->alarm = (cia->alarm & ~(0xff << shift)) | (data << shift); |
| 782 | if (m_timer[1].m_mode & 0x80) |
| 783 | { |
| 784 | m_alarm = (m_alarm & ~(0xff << shift)) | (data << shift); |
| 785 | } |
| 822 | 786 | /* counter setting mode */ |
| 823 | 787 | else |
| 824 | | cia->tod = (cia->tod & ~(0xff << shift)) | (data << shift); |
| 788 | { |
| 789 | m_tod = (m_tod & ~(0xff << shift)) | (data << shift); |
| 790 | } |
| 825 | 791 | |
| 826 | | if (device->type() == MOS8520) |
| 792 | if (type() == MOS8520) |
| 827 | 793 | { |
| 828 | 794 | if (offset == CIA_TOD2) |
| 829 | | cia->tod_running = FALSE; |
| 795 | { |
| 796 | m_tod_running = FALSE; |
| 797 | } |
| 830 | 798 | } |
| 831 | 799 | else |
| 832 | 800 | { |
| 833 | 801 | if (offset == CIA_TOD3) |
| 834 | | cia->tod_running = FALSE; |
| 802 | { |
| 803 | m_tod_running = FALSE; |
| 804 | } |
| 835 | 805 | } |
| 836 | 806 | if (offset == CIA_TOD0) |
| 837 | | cia->tod_running = TRUE; |
| 807 | { |
| 808 | m_tod_running = TRUE; |
| 809 | } |
| 838 | 810 | break; |
| 839 | 811 | |
| 840 | 812 | /* serial data ready */ |
| 841 | 813 | case CIA_SDR: |
| 842 | | cia->sdr = data; |
| 843 | | if (cia->timer[0].mode & 0x40) |
| 844 | | cia->loaded = 1; |
| 814 | m_sdr = data; |
| 815 | if (m_timer[0].m_mode & 0x40) |
| 816 | { |
| 817 | m_loaded = 1; |
| 818 | } |
| 845 | 819 | break; |
| 846 | 820 | |
| 847 | 821 | /* interrupt control register */ |
| 848 | 822 | case CIA_ICR: |
| 849 | 823 | if (data & 0x80) |
| 850 | | cia->icr |= data & 0x7f; |
| 824 | { |
| 825 | m_icr |= data & 0x7f; |
| 826 | } |
| 851 | 827 | else |
| 852 | | cia->icr &= ~(data & 0x7f); |
| 853 | | cia_update_interrupts(device); |
| 828 | { |
| 829 | m_icr &= ~(data & 0x7f); |
| 830 | } |
| 831 | update_interrupts(); |
| 854 | 832 | break; |
| 855 | 833 | |
| 856 | 834 | /* timer A/B modes */ |
| 857 | 835 | case CIA_CRA: |
| 858 | 836 | case CIA_CRB: |
| 859 | | timer = &cia->timer[offset & 1]; |
| 860 | | timer->mode = data & 0xef; |
| 837 | timer = &m_timer[offset & 1]; |
| 838 | timer->m_mode = data & 0xef; |
| 861 | 839 | |
| 862 | 840 | /* force load? */ |
| 863 | 841 | if (data & 0x10) |
| 864 | | cia_timer_update(timer, timer->latch); |
| 842 | { |
| 843 | timer->update(offset & 1, timer->m_latch); |
| 844 | } |
| 865 | 845 | else |
| 866 | | cia_timer_update(timer, -1); |
| 846 | { |
| 847 | timer->update(offset & 1, -1); |
| 848 | } |
| 867 | 849 | break; |
| 868 | 850 | } |
| 869 | 851 | } |
| 870 | 852 | |
| 871 | 853 | /*------------------------------------------------- |
| 872 | | DEVICE_START( cia ) |
| 854 | is_timer_active |
| 873 | 855 | -------------------------------------------------*/ |
| 874 | 856 | |
| 875 | | static DEVICE_START( cia ) |
| 857 | static int is_timer_active(emu_timer *timer) |
| 876 | 858 | { |
| 877 | | int t, p; |
| 878 | | cia_state *cia = get_token(device); |
| 879 | | const mos6526_interface *intf = get_interface(device); |
| 859 | attotime t = timer_firetime(timer); |
| 860 | return attotime_compare(t, attotime_never) != 0; |
| 861 | } |
| 880 | 862 | |
| 881 | | /* clear out CIA structure, and copy the interface */ |
| 882 | | memset(cia, 0, sizeof(*cia)); |
| 883 | | cia->device = device; |
| 884 | | devcb_resolve_write_line(&cia->out_irq_func, &intf->out_irq_func, device); |
| 885 | | devcb_resolve_write_line(&cia->out_pc_func, &intf->out_pc_func, device); |
| 886 | | devcb_resolve_write_line(&cia->out_cnt_func, &intf->out_cnt_func, device); |
| 887 | | devcb_resolve_write_line(&cia->out_sp_func, &intf->out_sp_func, device); |
| 888 | | cia->flag = 1; |
| 863 | /*------------------------------------------------- |
| 864 | update - updates the count and emu_timer for |
| 865 | a given CIA timer |
| 866 | -------------------------------------------------*/ |
| 889 | 867 | |
| 890 | | /* setup ports */ |
| 891 | | devcb_resolve_read8(&cia->port[0].read, &intf->in_pa_func, device); |
| 892 | | devcb_resolve_write8(&cia->port[0].write, &intf->out_pa_func, device); |
| 893 | | devcb_resolve_read8(&cia->port[1].read, &intf->in_pb_func, device); |
| 894 | | devcb_resolve_write8(&cia->port[1].write, &intf->out_pb_func, device); |
| 868 | void mos6526_device::cia_timer::update(int which, INT32 new_count) |
| 869 | { |
| 870 | /* sanity check arguments */ |
| 871 | assert((new_count >= -1) && (new_count <= 0xffff)); |
| 895 | 872 | |
| 896 | | for (p = 0; p < (sizeof(cia->port) / sizeof(cia->port[0])); p++) |
| 873 | /* update the timer count, if necessary */ |
| 874 | if ((new_count == -1) && is_timer_active(m_timer)) |
| 897 | 875 | { |
| 898 | | cia->port[p].mask_value = 0xff; |
| 876 | UINT16 current_count = attotime_to_double(attotime_mul(timer_timeelapsed(m_timer), m_clock)); |
| 877 | m_count = m_count - MIN(m_count, current_count); |
| 899 | 878 | } |
| 900 | 879 | |
| 901 | | /* setup timers */ |
| 902 | | for (t = 0; t < (sizeof(cia->timer) / sizeof(cia->timer[0])); t++) |
| 880 | /* set the timer if we are instructed to */ |
| 881 | if (new_count != -1) |
| 903 | 882 | { |
| 904 | | cia_timer *timer = &cia->timer[t]; |
| 905 | | timer->timer = timer_alloc(device->machine, cia_timer_proc, timer); |
| 906 | | timer->cia = cia; |
| 907 | | timer->irq = 0x01 << t; |
| 883 | m_count = new_count; |
| 908 | 884 | } |
| 909 | 885 | |
| 910 | | /* setup TOD timer, if appropriate */ |
| 911 | | if (intf->tod_clock != 0) |
| 912 | | timer_pulse(device->machine, ATTOTIME_IN_HZ(intf->tod_clock), (void *) device, 0, cia_clock_tod_callback); |
| 913 | | |
| 914 | | /* state save support */ |
| 915 | | state_save_register_device_item(device, 0, cia->port[0].ddr); |
| 916 | | state_save_register_device_item(device, 0, cia->port[0].latch); |
| 917 | | state_save_register_device_item(device, 0, cia->port[0].in); |
| 918 | | state_save_register_device_item(device, 0, cia->port[0].out); |
| 919 | | state_save_register_device_item(device, 0, cia->port[0].mask_value); |
| 920 | | state_save_register_device_item(device, 0, cia->port[1].ddr); |
| 921 | | state_save_register_device_item(device, 0, cia->port[1].latch); |
| 922 | | state_save_register_device_item(device, 0, cia->port[1].in); |
| 923 | | state_save_register_device_item(device, 0, cia->port[1].out); |
| 924 | | state_save_register_device_item(device, 0, cia->port[1].mask_value); |
| 925 | | state_save_register_device_item(device, 0, cia->timer[0].latch); |
| 926 | | state_save_register_device_item(device, 0, cia->timer[0].count); |
| 927 | | state_save_register_device_item(device, 0, cia->timer[0].mode); |
| 928 | | state_save_register_device_item(device, 0, cia->timer[0].irq); |
| 929 | | state_save_register_device_item(device, 0, cia->timer[1].latch); |
| 930 | | state_save_register_device_item(device, 0, cia->timer[1].count); |
| 931 | | state_save_register_device_item(device, 0, cia->timer[1].mode); |
| 932 | | state_save_register_device_item(device, 0, cia->timer[1].irq); |
| 933 | | state_save_register_device_item(device, 0, cia->tod); |
| 934 | | state_save_register_device_item(device, 0, cia->tod_latch); |
| 935 | | state_save_register_device_item(device, 0, cia->tod_latched); |
| 936 | | state_save_register_device_item(device, 0, cia->tod_running); |
| 937 | | state_save_register_device_item(device, 0, cia->alarm); |
| 938 | | state_save_register_device_item(device, 0, cia->icr); |
| 939 | | state_save_register_device_item(device, 0, cia->ics); |
| 940 | | state_save_register_device_item(device, 0, cia->irq); |
| 941 | | state_save_register_device_item(device, 0, cia->flag); |
| 942 | | state_save_register_device_item(device, 0, cia->loaded); |
| 943 | | state_save_register_device_item(device, 0, cia->sdr); |
| 944 | | state_save_register_device_item(device, 0, cia->sp); |
| 945 | | state_save_register_device_item(device, 0, cia->cnt); |
| 946 | | state_save_register_device_item(device, 0, cia->shift); |
| 947 | | state_save_register_device_item(device, 0, cia->serial); |
| 948 | | } |
| 949 | | |
| 950 | | /*------------------------------------------------- |
| 951 | | DEVICE_GET_INFO( cia6526r1 ) |
| 952 | | -------------------------------------------------*/ |
| 953 | | |
| 954 | | DEVICE_GET_INFO(cia6526r1) |
| 955 | | { |
| 956 | | switch (state) |
| 886 | /* now update the MAME timer */ |
| 887 | if ((m_mode & 0x01) && ((m_mode & (which ? 0x60 : 0x20)) == 0x00)) |
| 957 | 888 | { |
| 958 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 959 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cia_state); break; |
| 960 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 961 | | |
| 962 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 963 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cia); break; |
| 964 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 965 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(cia); break; |
| 966 | | // case DEVINFO_FCT_VALIDITY_CHECK: info->validity_check = DEVICE_VALIDITY_CHECK_NAME(cia); break; |
| 967 | | |
| 968 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 969 | | case DEVINFO_STR_NAME: strcpy(info->s, "MOS6526 rev1"); break; |
| 970 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "MOS6526"); break; |
| 971 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 972 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 973 | | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 889 | /* timer is on and is connected to clock */ |
| 890 | attotime period = attotime_mul(ATTOTIME_IN_HZ(m_clock), (m_count ? m_count : 0x10000)); |
| 891 | timer_adjust_oneshot(m_timer, period, which); |
| 974 | 892 | } |
| 975 | | } |
| 976 | | |
| 977 | | /*------------------------------------------------- |
| 978 | | DEVICE_GET_INFO( cia8520 ) |
| 979 | | -------------------------------------------------*/ |
| 980 | | |
| 981 | | DEVICE_GET_INFO(cia6526r2) |
| 982 | | { |
| 983 | | switch (state) |
| 893 | else |
| 984 | 894 | { |
| 985 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 986 | | case DEVINFO_STR_NAME: strcpy(info->s, "MOS6526 rev2"); break; |
| 987 | | default: DEVICE_GET_INFO_CALL(cia6526r1); break; |
| 895 | /* timer is off or not connected to clock */ |
| 896 | timer_adjust_oneshot(m_timer, attotime_never, which); |
| 988 | 897 | } |
| 989 | 898 | } |
| 990 | 899 | |
| 991 | 900 | /*------------------------------------------------- |
| 992 | | DEVICE_GET_INFO( cia8520 ) |
| 901 | get_count - get the count for a given CIA |
| 902 | timer |
| 993 | 903 | -------------------------------------------------*/ |
| 994 | 904 | |
| 995 | | DEVICE_GET_INFO(cia8520) |
| 905 | UINT16 mos6526_device::cia_timer::get_count() |
| 996 | 906 | { |
| 997 | | switch (state) |
| 907 | UINT16 count; |
| 908 | |
| 909 | if (is_timer_active(m_timer)) |
| 998 | 910 | { |
| 999 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1000 | | case DEVINFO_STR_NAME: strcpy(info->s, "MOS8520"); break; |
| 1001 | | default: DEVICE_GET_INFO_CALL(cia6526r1); break; |
| 911 | UINT16 current_count = attotime_to_double(attotime_mul(timer_timeelapsed(m_timer), m_clock)); |
| 912 | count = m_count - MIN(m_count, current_count); |
| 1002 | 913 | } |
| 914 | else |
| 915 | { |
| 916 | count = m_count; |
| 917 | } |
| 918 | |
| 919 | return count; |
| 1003 | 920 | } |
| 1004 | 921 | |
| 1005 | | DEFINE_LEGACY_DEVICE(MOS6526R1, cia6526r1); |
| 1006 | | DEFINE_LEGACY_DEVICE(MOS6526R2, cia6526r2); |
| 1007 | | DEFINE_LEGACY_DEVICE(MOS8520, cia8520); |
| 922 | /*************************************************************************** |
| 923 | TRAMPOLINES |
| 924 | ***************************************************************************/ |
| 925 | |
| 926 | void cia_set_port_mask_value(running_device *device, int port, int data) { downcast<mos6526_device *>(device)->set_port_mask_value(port, data); } |
| 927 | |
| 928 | READ8_DEVICE_HANDLER( mos6526_r ) { return downcast<mos6526_device *>(device)->reg_r(offset); } |
| 929 | WRITE8_DEVICE_HANDLER( mos6526_w ) { downcast<mos6526_device *>(device)->reg_w(offset, data); } |
| 930 | |
| 931 | READ8_DEVICE_HANDLER( mos6526_pa_r ) { return downcast<mos6526_device *>(device)->pa_r(offset); } |
| 932 | READ8_DEVICE_HANDLER( mos6526_pb_r ) { return downcast<mos6526_device *>(device)->pb_r(offset); } |
| 933 | |
| 934 | READ_LINE_DEVICE_HANDLER( mos6526_irq_r ) { return downcast<mos6526_device *>(device)->irq_r(); } |
| 935 | |
| 936 | WRITE_LINE_DEVICE_HANDLER( mos6526_tod_w ) { downcast<mos6526_device *>(device)->tod_w(state); } |
| 937 | |
| 938 | READ_LINE_DEVICE_HANDLER( mos6526_cnt_r ) { return downcast<mos6526_device *>(device)->cnt_r(); } |
| 939 | WRITE_LINE_DEVICE_HANDLER( mos6526_cnt_w ) { downcast<mos6526_device *>(device)->cnt_w(state); } |
| 940 | |
| 941 | READ_LINE_DEVICE_HANDLER( mos6526_sp_r ) { return downcast<mos6526_device *>(device)->sp_r(); } |
| 942 | WRITE_LINE_DEVICE_HANDLER( mos6526_sp_w ) { downcast<mos6526_device *>(device)->sp_w(state); } |
| 943 | |
| 944 | WRITE_LINE_DEVICE_HANDLER( mos6526_flag_w ) { downcast<mos6526_device *>(device)->flag_w(state); } |
src/emu/machine/74123.c
| r8892 | r8893 | |
| 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
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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); |
| 85 | // inherit a copy of the static data |
| 86 | const pia6821_interface *intf = reinterpret_cast<const pia6821_interface *>(static_config()); |
| 87 | if (intf != NULL) |
| 88 | *static_cast<pia6821_interface *>(this) = *intf; |
| 138 | 89 | |
| 139 | | /* clear structure */ |
| 140 | | memset(p, 0, sizeof(*p)); |
| 90 | // or initialize to defaults if none provided |
| 91 | else |
| 92 | { |
| 93 | memset(&m_in_a_func, 0, sizeof(m_in_a_func)); |
| 94 | memset(&m_in_b_func, 0, sizeof(m_in_b_func)); |
| 95 | memset(&m_in_ca1_func, 0, sizeof(m_in_ca1_func)); |
| 96 | memset(&m_in_cb1_func, 0, sizeof(m_in_cb1_func)); |
| 97 | memset(&m_in_ca2_func, 0, sizeof(m_in_ca2_func)); |
| 98 | memset(&m_in_cb2_func, 0, sizeof(m_in_cb2_func)); |
| 99 | memset(&m_out_a_func, 0, sizeof(m_out_a_func)); |
| 100 | memset(&m_out_b_func, 0, sizeof(m_out_b_func)); |
| 101 | memset(&m_out_ca2_func, 0, sizeof(m_out_ca2_func)); |
| 102 | memset(&m_out_cb2_func, 0, sizeof(m_out_cb2_func)); |
| 103 | memset(&m_irq_a_func, 0, sizeof(m_irq_a_func)); |
| 104 | memset(&m_irq_b_func, 0, sizeof(m_irq_b_func)); |
| 105 | } |
| 106 | } |
| 141 | 107 | |
| 108 | |
| 109 | |
| 110 | //************************************************************************** |
| 111 | // LIVE DEVICE |
| 112 | //************************************************************************** |
| 113 | |
| 114 | const device_type PIA6821 = pia6821_device_config::static_alloc_device_config; |
| 115 | |
| 116 | //------------------------------------------------- |
| 117 | // pia6821_device - constructor |
| 118 | //------------------------------------------------- |
| 119 | |
| 120 | pia6821_device::pia6821_device(running_machine &_machine, const pia6821_device_config &config) |
| 121 | : device_t(_machine, config), |
| 122 | m_config(config) |
| 123 | { |
| 124 | |
| 125 | } |
| 126 | |
| 127 | //------------------------------------------------- |
| 128 | // device_start - device-specific startup |
| 129 | //------------------------------------------------- |
| 130 | |
| 131 | void pia6821_device::device_start() |
| 132 | { |
| 142 | 133 | /* 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); |
| 134 | devcb_resolve_read8(&m_in_a_func, &m_config.m_in_a_func, this); |
| 135 | devcb_resolve_read8(&m_in_b_func, &m_config.m_in_b_func, this); |
| 136 | devcb_resolve_read_line(&m_in_ca1_func, &m_config.m_in_ca1_func, this); |
| 137 | devcb_resolve_read_line(&m_in_cb1_func, &m_config.m_in_cb1_func, this); |
| 138 | devcb_resolve_read_line(&m_in_ca2_func, &m_config.m_in_ca2_func, this); |
| 139 | devcb_resolve_read_line(&m_in_cb2_func, &m_config.m_in_cb2_func, this); |
| 140 | devcb_resolve_write8(&m_out_a_func, &m_config.m_out_a_func, this); |
| 141 | devcb_resolve_write8(&m_out_b_func, &m_config.m_out_b_func, this); |
| 142 | devcb_resolve_write_line(&m_out_ca2_func, &m_config.m_out_ca2_func, this); |
| 143 | devcb_resolve_write_line(&m_out_cb2_func, &m_config.m_out_cb2_func, this); |
| 144 | devcb_resolve_write_line(&m_irq_a_func, &m_config.m_irq_a_func, this); |
| 145 | devcb_resolve_write_line(&m_irq_b_func, &m_config.m_irq_b_func, this); |
| 155 | 146 | |
| 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); |
| 147 | state_save_register_device_item(this, 0, m_in_a); |
| 148 | state_save_register_device_item(this, 0, m_in_ca1); |
| 149 | state_save_register_device_item(this, 0, m_in_ca2); |
| 150 | state_save_register_device_item(this, 0, m_out_a); |
| 151 | state_save_register_device_item(this, 0, m_out_ca2); |
| 152 | state_save_register_device_item(this, 0, m_port_a_z_mask); |
| 153 | state_save_register_device_item(this, 0, m_ddr_a); |
| 154 | state_save_register_device_item(this, 0, m_ctl_a); |
| 155 | state_save_register_device_item(this, 0, m_irq_a1); |
| 156 | state_save_register_device_item(this, 0, m_irq_a2); |
| 157 | state_save_register_device_item(this, 0, m_irq_a_state); |
| 158 | state_save_register_device_item(this, 0, m_in_b); |
| 159 | state_save_register_device_item(this, 0, m_in_cb1); |
| 160 | state_save_register_device_item(this, 0, m_in_cb2); |
| 161 | state_save_register_device_item(this, 0, m_out_b); |
| 162 | state_save_register_device_item(this, 0, m_out_cb2); |
| 163 | state_save_register_device_item(this, 0, m_last_out_cb2_z); |
| 164 | state_save_register_device_item(this, 0, m_ddr_b); |
| 165 | state_save_register_device_item(this, 0, m_ctl_b); |
| 166 | state_save_register_device_item(this, 0, m_irq_b1); |
| 167 | state_save_register_device_item(this, 0, m_irq_b2); |
| 168 | state_save_register_device_item(this, 0, m_irq_b_state); |
| 169 | state_save_register_device_item(this, 0, m_in_a_pushed); |
| 170 | state_save_register_device_item(this, 0, m_out_a_needs_pulled); |
| 171 | state_save_register_device_item(this, 0, m_in_ca1_pushed); |
| 172 | state_save_register_device_item(this, 0, m_in_ca2_pushed); |
| 173 | state_save_register_device_item(this, 0, m_out_ca2_needs_pulled); |
| 174 | state_save_register_device_item(this, 0, m_in_b_pushed); |
| 175 | state_save_register_device_item(this, 0, m_out_b_needs_pulled); |
| 176 | state_save_register_device_item(this, 0, m_in_cb1_pushed); |
| 177 | state_save_register_device_item(this, 0, m_in_cb2_pushed); |
| 178 | state_save_register_device_item(this, 0, m_out_cb2_needs_pulled); |
| 188 | 179 | } |
| 189 | 180 | |
| 190 | 181 | |
| 191 | | /*------------------------------------------------- |
| 192 | | DEVICE_RESET( pia6821 ) |
| 193 | | -------------------------------------------------*/ |
| 182 | //------------------------------------------------- |
| 183 | // device_reset - device-specific reset |
| 184 | //------------------------------------------------- |
| 194 | 185 | |
| 195 | | static DEVICE_RESET( pia6821 ) |
| 186 | void pia6821_device::device_reset() |
| 196 | 187 | { |
| 197 | | pia6821_state *p = get_token(device); |
| 198 | | |
| 199 | 188 | /* |
| 200 | 189 | * set default read values. |
| 201 | 190 | * |
| 202 | 191 | * ports A,CA1,CA2 default to 1 |
| 203 | 192 | * ports B,CB1,CB2 are three-state and undefined (set to 0) |
| 204 | 193 | */ |
| 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; |
| 194 | m_in_a = 0xff; |
| 195 | m_in_ca1 = TRUE; |
| 196 | m_in_ca2 = TRUE; |
| 197 | m_out_a = 0; |
| 198 | m_out_ca2 = 0; |
| 199 | m_port_a_z_mask = 0; |
| 200 | m_ddr_a = 0; |
| 201 | m_ctl_a = 0; |
| 202 | m_irq_a1 = 0; |
| 203 | m_irq_a2 = 0; |
| 204 | m_irq_a_state = 0; |
| 205 | m_in_b = 0; |
| 206 | m_in_cb1 = 0; |
| 207 | m_in_cb2 = 0; |
| 208 | m_out_b = 0; |
| 209 | m_out_cb2 = 0; |
| 210 | m_last_out_cb2_z = 0; |
| 211 | m_ddr_b = 0; |
| 212 | m_ctl_b = 0; |
| 213 | m_irq_b1 = 0; |
| 214 | m_irq_b2 = 0; |
| 215 | m_irq_b_state = 0; |
| 216 | m_in_a_pushed = 0; |
| 217 | m_out_a_needs_pulled = 0; |
| 218 | m_in_ca1_pushed = 0; |
| 219 | m_in_ca2_pushed = 0; |
| 220 | m_out_ca2_needs_pulled = 0; |
| 221 | m_in_b_pushed = 0; |
| 222 | m_out_b_needs_pulled = 0; |
| 223 | m_in_cb1_pushed = 0; |
| 224 | m_in_cb2_pushed = 0; |
| 225 | m_out_cb2_needs_pulled = 0; |
| 226 | m_logged_port_a_not_connected = 0; |
| 227 | m_logged_port_b_not_connected = 0; |
| 228 | m_logged_ca1_not_connected = 0; |
| 229 | m_logged_ca2_not_connected = 0; |
| 230 | m_logged_cb1_not_connected = 0; |
| 231 | m_logged_cb2_not_connected = 0; |
| 243 | 232 | |
| 244 | 233 | |
| 245 | 234 | /* clear the IRQs */ |
| 246 | | devcb_call_write_line(&p->irq_a_func, FALSE); |
| 247 | | devcb_call_write_line(&p->irq_b_func, FALSE); |
| 235 | devcb_call_write_line(&m_irq_a_func, FALSE); |
| 236 | devcb_call_write_line(&m_irq_b_func, FALSE); |
| 248 | 237 | } |
| 249 | 238 | |
| 250 | 239 | |
| r8892 | r8893 | |
| 252 | 241 | update_interrupts |
| 253 | 242 | -------------------------------------------------*/ |
| 254 | 243 | |
| 255 | | static void update_interrupts(running_device *device) |
| 244 | void pia6821_device::update_interrupts() |
| 256 | 245 | { |
| 257 | | pia6821_state *p = get_token(device); |
| 258 | | int new_state; |
| 246 | /* start with IRQ A */ |
| 247 | int new_state = (m_irq_a1 && IRQ1_ENABLED(m_ctl_a)) || (m_irq_a2 && IRQ2_ENABLED(m_ctl_a)); |
| 259 | 248 | |
| 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) |
| 249 | if (new_state != m_irq_a_state) |
| 264 | 250 | { |
| 265 | | p->irq_a_state = new_state; |
| 266 | | devcb_call_write_line(&p->irq_a_func, p->irq_a_state); |
| 251 | m_irq_a_state = new_state; |
| 252 | devcb_call_write_line(&m_irq_a_func, m_irq_a_state); |
| 267 | 253 | } |
| 268 | 254 | |
| 269 | 255 | /* then do IRQ B */ |
| 270 | | new_state = (p->irq_b1 && IRQ1_ENABLED(p->ctl_b)) || (p->irq_b2 && IRQ2_ENABLED(p->ctl_b)); |
| 256 | new_state = (m_irq_b1 && IRQ1_ENABLED(m_ctl_b)) || (m_irq_b2 && IRQ2_ENABLED(m_ctl_b)); |
| 271 | 257 | |
| 272 | | if (new_state != p->irq_b_state) |
| 258 | if (new_state != m_irq_b_state) |
| 273 | 259 | { |
| 274 | | p->irq_b_state = new_state; |
| 275 | | devcb_call_write_line(&p->irq_b_func, p->irq_b_state); |
| 260 | m_irq_b_state = new_state; |
| 261 | devcb_call_write_line(&m_irq_b_func, m_irq_b_state); |
| 276 | 262 | } |
| 277 | 263 | } |
| 278 | 264 | |
| r8892 | r8893 | |
| 281 | 267 | get_in_a_value |
| 282 | 268 | -------------------------------------------------*/ |
| 283 | 269 | |
| 284 | | static UINT8 get_in_a_value(running_device *device) |
| 270 | UINT8 pia6821_device::get_in_a_value() |
| 285 | 271 | { |
| 286 | | pia6821_state *p = get_token(device); |
| 287 | 272 | UINT8 port_a_data = 0; |
| 288 | 273 | UINT8 ret; |
| 289 | 274 | |
| 290 | 275 | /* update the input */ |
| 291 | | if (p->in_a_func.read != NULL) |
| 292 | | port_a_data = devcb_call_read8(&p->in_a_func, 0); |
| 276 | if (m_in_a_func.read != NULL) |
| 277 | { |
| 278 | port_a_data = devcb_call_read8(&m_in_a_func, 0); |
| 279 | } |
| 293 | 280 | else |
| 294 | 281 | { |
| 295 | | if (p->in_a_pushed) |
| 296 | | port_a_data = p->in_a; |
| 282 | if (m_in_a_pushed) |
| 283 | { |
| 284 | port_a_data = m_in_a; |
| 285 | } |
| 297 | 286 | else |
| 298 | 287 | { |
| 299 | 288 | /* mark all pins disconnected */ |
| 300 | | p->port_a_z_mask = 0xff; |
| 289 | m_port_a_z_mask = 0xff; |
| 301 | 290 | |
| 302 | | if (!p->logged_port_a_not_connected && (p->ddr_a != 0xff)) |
| 291 | if (!m_logged_port_a_not_connected && (m_ddr_a != 0xff)) |
| 303 | 292 | { |
| 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; |
| 293 | logerror("PIA #%s: Warning! No port A read handler. Assuming pins 0x%02X not connected\n", tag(), m_ddr_a ^ 0xff); |
| 294 | m_logged_port_a_not_connected = TRUE; |
| 306 | 295 | } |
| 307 | 296 | } |
| 308 | 297 | } |
| r8892 | r8893 | |
| 310 | 299 | /* - connected pins are always read |
| 311 | 300 | - disconnected pins read the output buffer in output mode |
| 312 | 301 | - 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); |
| 302 | ret = (~m_port_a_z_mask & port_a_data) | |
| 303 | ( m_port_a_z_mask & m_ddr_a & m_out_a) | |
| 304 | ( m_port_a_z_mask & ~m_ddr_a); |
| 316 | 305 | |
| 317 | 306 | return ret; |
| 318 | 307 | } |
| r8892 | r8893 | |
| 322 | 311 | get_in_b_value |
| 323 | 312 | -------------------------------------------------*/ |
| 324 | 313 | |
| 325 | | static UINT8 get_in_b_value(running_device *device) |
| 314 | UINT8 pia6821_device::get_in_b_value() |
| 326 | 315 | { |
| 327 | | pia6821_state *p = get_token(device); |
| 328 | 316 | UINT8 ret; |
| 329 | 317 | |
| 330 | | if (p->ddr_b == 0xff) |
| 318 | if (m_ddr_b == 0xff) |
| 319 | { |
| 331 | 320 | /* all output, just return buffer */ |
| 332 | | ret = p->out_b; |
| 321 | ret = m_out_b; |
| 322 | } |
| 333 | 323 | else |
| 334 | 324 | { |
| 335 | 325 | UINT8 port_b_data; |
| 336 | 326 | |
| 337 | 327 | /* update the input */ |
| 338 | | if (p->in_b_func.read != NULL) |
| 339 | | port_b_data = devcb_call_read8(&p->in_b_func, 0); |
| 328 | if (m_in_b_func.read != NULL) |
| 329 | { |
| 330 | port_b_data = devcb_call_read8(&m_in_b_func, 0); |
| 331 | } |
| 340 | 332 | else |
| 341 | 333 | { |
| 342 | | if (p->in_b_pushed) |
| 343 | | port_b_data = p->in_b; |
| 334 | if (m_in_b_pushed) |
| 335 | { |
| 336 | port_b_data = m_in_b; |
| 337 | } |
| 344 | 338 | else |
| 345 | 339 | { |
| 346 | | if (!p->logged_port_b_not_connected && (p->ddr_b != 0xff)) |
| 340 | if (!m_logged_port_b_not_connected && (m_ddr_b != 0xff)) |
| 347 | 341 | { |
| 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; |
| 342 | logerror("PIA #%s: Error! No port B read handler. Three-state pins 0x%02X are undefined\n", tag(), m_ddr_b ^ 0xff); |
| 343 | m_logged_port_b_not_connected = TRUE; |
| 350 | 344 | } |
| 351 | 345 | |
| 352 | 346 | /* undefined -- need to return something */ |
| r8892 | r8893 | |
| 355 | 349 | } |
| 356 | 350 | |
| 357 | 351 | /* 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); |
| 352 | ret = (m_out_b & m_ddr_b) | (port_b_data & ~m_ddr_b); |
| 359 | 353 | } |
| 360 | 354 | |
| 361 | 355 | return ret; |
| r8892 | r8893 | |
| 366 | 360 | get_out_a_value |
| 367 | 361 | -------------------------------------------------*/ |
| 368 | 362 | |
| 369 | | static UINT8 get_out_a_value(running_device *device) |
| 363 | UINT8 pia6821_device::get_out_a_value() |
| 370 | 364 | { |
| 371 | | pia6821_state *p = get_token(device); |
| 372 | 365 | UINT8 ret; |
| 373 | 366 | |
| 374 | | if (p->ddr_a == 0xff) |
| 367 | if (m_ddr_a == 0xff) |
| 368 | { |
| 375 | 369 | /* all output */ |
| 376 | | ret = p->out_a; |
| 370 | ret = m_out_a; |
| 371 | } |
| 377 | 372 | else |
| 373 | { |
| 378 | 374 | /* input pins don't change */ |
| 379 | | ret = (p->out_a & p->ddr_a) | (get_in_a_value(device) & ~p->ddr_a); |
| 375 | ret = (m_out_a & m_ddr_a) | (get_in_a_value() & ~m_ddr_a); |
| 376 | } |
| 380 | 377 | |
| 381 | 378 | return ret; |
| 382 | 379 | } |
| r8892 | r8893 | |
| 386 | 383 | get_out_b_value |
| 387 | 384 | -------------------------------------------------*/ |
| 388 | 385 | |
| 389 | | static UINT8 get_out_b_value(running_device *device) |
| 386 | UINT8 pia6821_device::get_out_b_value() |
| 390 | 387 | { |
| 391 | | pia6821_state *p = get_token(device); |
| 392 | | |
| 393 | 388 | /* input pins are high-impedance - we just send them as zeros for backwards compatibility */ |
| 394 | | return p->out_b & p->ddr_b; |
| 389 | return m_out_b & m_ddr_b; |
| 395 | 390 | } |
| 396 | 391 | |
| 397 | 392 | |
| r8892 | r8893 | |
| 399 | 394 | set_out_ca2 |
| 400 | 395 | -------------------------------------------------*/ |
| 401 | 396 | |
| 402 | | static void set_out_ca2(running_device *device, int data) |
| 397 | void pia6821_device::set_out_ca2(int data) |
| 403 | 398 | { |
| 404 | | pia6821_state *p = get_token(device); |
| 405 | | |
| 406 | | if (data != p->out_ca2) |
| 399 | if (data != m_out_ca2) |
| 407 | 400 | { |
| 408 | | p->out_ca2 = data; |
| 401 | m_out_ca2 = data; |
| 409 | 402 | |
| 410 | 403 | /* send to output function */ |
| 411 | | if (p->out_ca2_func.write) |
| 412 | | devcb_call_write_line(&p->out_ca2_func, p->out_ca2); |
| 404 | if (m_out_ca2_func.write) |
| 405 | { |
| 406 | devcb_call_write_line(&m_out_ca2_func, m_out_ca2); |
| 407 | } |
| 413 | 408 | else |
| 414 | 409 | { |
| 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()); |
| 410 | if (m_out_ca2_needs_pulled) |
| 411 | { |
| 412 | logerror("PIA #%s: Warning! No port CA2 write handler. Previous value has been lost!\n", tag()); |
| 413 | } |
| 417 | 414 | |
| 418 | | p->out_ca2_needs_pulled = TRUE; |
| 415 | m_out_ca2_needs_pulled = TRUE; |
| 419 | 416 | } |
| 420 | 417 | } |
| 421 | 418 | } |
| r8892 | r8893 | |
| 425 | 422 | set_out_cb2 |
| 426 | 423 | -------------------------------------------------*/ |
| 427 | 424 | |
| 428 | | static void set_out_cb2(running_device *device, int data) |
| 425 | void pia6821_device::set_out_cb2(int data) |
| 429 | 426 | { |
| 430 | | pia6821_state *p = get_token(device); |
| 427 | int z = pia6821_get_output_cb2_z(this); |
| 431 | 428 | |
| 432 | | int z = pia6821_get_output_cb2_z(device); |
| 433 | | |
| 434 | | if ((data != p->out_cb2) || (z != p->last_out_cb2_z)) |
| 429 | if ((data != m_out_cb2) || (z != m_last_out_cb2_z)) |
| 435 | 430 | { |
| 436 | | p->out_cb2 = data; |
| 437 | | p->last_out_cb2_z = z; |
| 431 | m_out_cb2 = data; |
| 432 | m_last_out_cb2_z = z; |
| 438 | 433 | |
| 439 | 434 | /* send to output function */ |
| 440 | | if (p->out_cb2_func.write) |
| 441 | | devcb_call_write_line(&p->out_cb2_func, p->out_cb2); |
| 435 | if (m_out_cb2_func.write) |
| 436 | { |
| 437 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 438 | } |
| 442 | 439 | else |
| 443 | 440 | { |
| 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()); |
| 441 | if (m_out_cb2_needs_pulled) |
| 442 | { |
| 443 | logerror("PIA #%s: Warning! No port CB2 write handler. Previous value has been lost!\n", tag()); |
| 444 | } |
| 446 | 445 | |
| 447 | | p->out_cb2_needs_pulled = TRUE; |
| 446 | m_out_cb2_needs_pulled = TRUE; |
| 448 | 447 | } |
| 449 | 448 | } |
| 450 | 449 | } |
| r8892 | r8893 | |
| 454 | 453 | port_a_r |
| 455 | 454 | -------------------------------------------------*/ |
| 456 | 455 | |
| 457 | | static UINT8 port_a_r(running_device *device) |
| 456 | UINT8 pia6821_device::port_a_r() |
| 458 | 457 | { |
| 459 | | pia6821_state *p = get_token(device); |
| 458 | UINT8 ret = get_in_a_value(); |
| 460 | 459 | |
| 461 | | UINT8 ret = get_in_a_value(device); |
| 462 | | |
| 463 | 460 | /* IRQ flags implicitly cleared by a read */ |
| 464 | | p->irq_a1 = FALSE; |
| 465 | | p->irq_a2 = FALSE; |
| 466 | | update_interrupts(device); |
| 461 | m_irq_a1 = FALSE; |
| 462 | m_irq_a2 = FALSE; |
| 463 | update_interrupts(); |
| 467 | 464 | |
| 468 | 465 | /* CA2 is configured as output and in read strobe mode */ |
| 469 | | if (C2_OUTPUT(p->ctl_a) && C2_STROBE_MODE(p->ctl_a)) |
| 466 | if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a)) |
| 470 | 467 | { |
| 471 | 468 | /* this will cause a transition low */ |
| 472 | | set_out_ca2(device, FALSE); |
| 469 | set_out_ca2(FALSE); |
| 473 | 470 | |
| 474 | 471 | /* 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); |
| 472 | if(STROBE_E_RESET(m_ctl_a)) |
| 473 | { |
| 474 | set_out_ca2(TRUE); |
| 475 | } |
| 477 | 476 | } |
| 478 | 477 | |
| 479 | | LOG(("PIA #%s: port A read = %02X\n", device->tag(), ret)); |
| 478 | LOG(("PIA #%s: port A read = %02X\n", tag(), ret)); |
| 480 | 479 | |
| 481 | 480 | return ret; |
| 482 | 481 | } |
| r8892 | r8893 | |
| 486 | 485 | ddr_a_r |
| 487 | 486 | -------------------------------------------------*/ |
| 488 | 487 | |
| 489 | | static UINT8 ddr_a_r(running_device *device) |
| 488 | UINT8 pia6821_device::ddr_a_r() |
| 490 | 489 | { |
| 491 | | pia6821_state *p = get_token(device); |
| 490 | UINT8 ret = m_ddr_a; |
| 492 | 491 | |
| 493 | | UINT8 ret = p->ddr_a; |
| 492 | LOG(("PIA #%s: DDR A read = %02X\n", tag(), ret)); |
| 494 | 493 | |
| 495 | | LOG(("PIA #%s: DDR A read = %02X\n", device->tag(), ret)); |
| 496 | | |
| 497 | 494 | return ret; |
| 498 | 495 | } |
| 499 | 496 | |
| r8892 | r8893 | |
| 502 | 499 | port_b_r |
| 503 | 500 | -------------------------------------------------*/ |
| 504 | 501 | |
| 505 | | static UINT8 port_b_r(running_device *device) |
| 502 | UINT8 pia6821_device::port_b_r() |
| 506 | 503 | { |
| 507 | | pia6821_state *p = get_token(device); |
| 504 | UINT8 ret = get_in_b_value(); |
| 508 | 505 | |
| 509 | | UINT8 ret = get_in_b_value(device); |
| 510 | | |
| 511 | 506 | /* This read will implicitly clear the IRQ B1 flag. If CB2 is in write-strobe |
| 512 | 507 | mode with CB1 restore, and a CB1 active transition set the flag, |
| 513 | 508 | clearing it will cause CB2 to go high again. Note that this is different |
| 514 | 509 | 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); |
| 510 | if(m_irq_b1 && C2_STROBE_MODE(m_ctl_b) && STROBE_C1_RESET(m_ctl_b)) |
| 511 | { |
| 512 | set_out_cb2(TRUE); |
| 513 | } |
| 517 | 514 | |
| 518 | 515 | /* IRQ flags implicitly cleared by a read */ |
| 519 | | p->irq_b1 = FALSE; |
| 520 | | p->irq_b2 = FALSE; |
| 521 | | update_interrupts(device); |
| 516 | m_irq_b1 = FALSE; |
| 517 | m_irq_b2 = FALSE; |
| 518 | update_interrupts(); |
| 522 | 519 | |
| 523 | | LOG(("PIA #%s: port B read = %02X\n", device->tag(), ret)); |
| 520 | LOG(("PIA #%s: port B read = %02X\n", tag(), ret)); |
| 524 | 521 | |
| 525 | 522 | return ret; |
| 526 | 523 | } |
| r8892 | r8893 | |
| 530 | 527 | ddr_b_r |
| 531 | 528 | -------------------------------------------------*/ |
| 532 | 529 | |
| 533 | | static UINT8 ddr_b_r(running_device *device) |
| 530 | UINT8 pia6821_device::ddr_b_r() |
| 534 | 531 | { |
| 535 | | pia6821_state *p = get_token(device); |
| 532 | UINT8 ret = m_ddr_b; |
| 536 | 533 | |
| 537 | | UINT8 ret = p->ddr_b; |
| 534 | LOG(("PIA #%s: DDR B read = %02X\n", tag(), ret)); |
| 538 | 535 | |
| 539 | | LOG(("PIA #%s: DDR B read = %02X\n", device->tag(), ret)); |
| 540 | | |
| 541 | 536 | return ret; |
| 542 | 537 | } |
| 543 | 538 | |
| r8892 | r8893 | |
| 546 | 541 | control_a_r |
| 547 | 542 | -------------------------------------------------*/ |
| 548 | 543 | |
| 549 | | static UINT8 control_a_r(running_device *device) |
| 544 | UINT8 pia6821_device::control_a_r() |
| 550 | 545 | { |
| 551 | | pia6821_state *p = get_token(device); |
| 552 | 546 | UINT8 ret; |
| 553 | 547 | |
| 554 | 548 | /* 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)) |
| 549 | if (m_in_ca1_func.read != NULL) |
| 550 | { |
| 551 | ca1_w(devcb_call_read_line(&m_in_ca1_func)); |
| 552 | } |
| 553 | else if(!m_logged_ca1_not_connected && (!m_in_ca1_pushed)) |
| 558 | 554 | { |
| 559 | | logerror("PIA #%s: Warning! No CA1 read handler. Assuming pin not connected\n", device->tag()); |
| 560 | | p->logged_ca1_not_connected = TRUE; |
| 555 | logerror("PIA #%s: Warning! No CA1 read handler. Assuming pin not connected\n", tag()); |
| 556 | m_logged_ca1_not_connected = TRUE; |
| 561 | 557 | } |
| 562 | 558 | |
| 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) |
| 559 | if (m_in_ca2_func.read != NULL) |
| 560 | { |
| 561 | ca2_w(devcb_call_read_line(&m_in_ca2_func)); |
| 562 | } |
| 563 | else if ( !m_logged_ca2_not_connected && C2_INPUT(m_ctl_a) && !m_in_ca2_pushed) |
| 566 | 564 | { |
| 567 | | logerror("PIA #%s: Warning! No CA2 read handler. Assuming pin not connected\n", device->tag()); |
| 568 | | p->logged_ca2_not_connected = TRUE; |
| 565 | logerror("PIA #%s: Warning! No CA2 read handler. Assuming pin not connected\n", tag()); |
| 566 | m_logged_ca2_not_connected = TRUE; |
| 569 | 567 | } |
| 570 | 568 | |
| 571 | 569 | /* read control register */ |
| 572 | | ret = p->ctl_a; |
| 570 | ret = m_ctl_a; |
| 573 | 571 | |
| 574 | 572 | /* set the IRQ flags if we have pending IRQs */ |
| 575 | | if (p->irq_a1) |
| 573 | if(m_irq_a1) |
| 574 | { |
| 576 | 575 | ret |= PIA_IRQ1; |
| 576 | } |
| 577 | 577 | |
| 578 | | if (p->irq_a2 && C2_INPUT(p->ctl_a)) |
| 578 | if(m_irq_a2 && C2_INPUT(m_ctl_a)) |
| 579 | { |
| 579 | 580 | ret |= PIA_IRQ2; |
| 581 | } |
| 580 | 582 | |
| 581 | | LOG(("PIA #%s: control A read = %02X\n", device->tag(), ret)); |
| 583 | LOG(("PIA #%s: control A read = %02X\n", tag(), ret)); |
| 582 | 584 | |
| 583 | 585 | return ret; |
| 584 | 586 | } |
| r8892 | r8893 | |
| 588 | 590 | control_b_r |
| 589 | 591 | -------------------------------------------------*/ |
| 590 | 592 | |
| 591 | | static UINT8 control_b_r(running_device *device) |
| 593 | UINT8 pia6821_device::control_b_r() |
| 592 | 594 | { |
| 593 | | pia6821_state *p = get_token(device); |
| 594 | 595 | UINT8 ret; |
| 595 | 596 | |
| 596 | 597 | /* 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) |
| 598 | if(m_in_cb1_func.read != NULL) |
| 599 | { |
| 600 | cb1_w(devcb_call_read_line(&m_in_cb1_func)); |
| 601 | } |
| 602 | else if(!m_logged_cb1_not_connected && !m_in_cb1_pushed) |
| 600 | 603 | { |
| 601 | | logerror("PIA #%s: Error! no CB1 read handler. Three-state pin is undefined\n", device->tag()); |
| 602 | | p->logged_cb1_not_connected = TRUE; |
| 604 | logerror("PIA #%s: Error! no CB1 read handler. Three-state pin is undefined\n", tag()); |
| 605 | m_logged_cb1_not_connected = TRUE; |
| 603 | 606 | } |
| 604 | 607 | |
| 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) |
| 608 | if(m_in_cb2_func.read != NULL) |
| 609 | { |
| 610 | cb2_w(devcb_call_read_line(&m_in_cb2_func)); |
| 611 | } |
| 612 | else if(!m_logged_cb2_not_connected && C2_INPUT(m_ctl_b) && !m_in_cb2_pushed) |
| 608 | 613 | { |
| 609 | | logerror("PIA #%s: Error! No CB2 read handler. Three-state pin is undefined\n", device->tag()); |
| 610 | | p->logged_cb2_not_connected = TRUE; |
| 614 | logerror("PIA #%s: Error! No CB2 read handler. Three-state pin is undefined\n", tag()); |
| 615 | m_logged_cb2_not_connected = TRUE; |
| 611 | 616 | } |
| 612 | 617 | |
| 613 | 618 | /* read control register */ |
| 614 | | ret = p->ctl_b; |
| 619 | ret = m_ctl_b; |
| 615 | 620 | |
| 616 | 621 | /* set the IRQ flags if we have pending IRQs */ |
| 617 | | if (p->irq_b1) |
| 622 | if(m_irq_b1) |
| 623 | { |
| 618 | 624 | ret |= PIA_IRQ1; |
| 625 | } |
| 619 | 626 | |
| 620 | | if (p->irq_b2 && C2_INPUT(p->ctl_b)) |
| 627 | if(m_irq_b2 && C2_INPUT(m_ctl_b)) |
| 628 | { |
| 621 | 629 | ret |= PIA_IRQ2; |
| 630 | } |
| 622 | 631 | |
| 623 | | LOG(("PIA #%s: control B read = %02X\n", device->tag(), ret)); |
| 632 | LOG(("PIA #%s: control B read = %02X\n", tag(), ret)); |
| 624 | 633 | |
| 625 | 634 | return ret; |
| 626 | 635 | } |
| r8892 | r8893 | |
| 632 | 641 | |
| 633 | 642 | READ8_DEVICE_HANDLER( pia6821_r ) |
| 634 | 643 | { |
| 635 | | pia6821_state *p = get_token(device); |
| 644 | return downcast<pia6821_device *>(device)->reg_r(offset); |
| 645 | } |
| 646 | |
| 647 | UINT8 pia6821_device::reg_r(UINT8 offset) |
| 648 | { |
| 636 | 649 | UINT8 ret; |
| 637 | 650 | |
| 638 | 651 | switch (offset & 0x03) |
| 639 | 652 | { |
| 640 | 653 | default: /* impossible */ |
| 641 | 654 | case 0x00: |
| 642 | | if (OUTPUT_SELECTED(p->ctl_a)) |
| 643 | | ret = port_a_r(device); |
| 655 | if (OUTPUT_SELECTED(m_ctl_a)) |
| 656 | { |
| 657 | ret = port_a_r(); |
| 658 | } |
| 644 | 659 | else |
| 645 | | ret = ddr_a_r(device); |
| 660 | { |
| 661 | ret = ddr_a_r(); |
| 662 | } |
| 646 | 663 | break; |
| 647 | 664 | |
| 648 | 665 | case 0x01: |
| 649 | | ret = control_a_r(device); |
| 666 | ret = control_a_r(); |
| 650 | 667 | break; |
| 651 | 668 | |
| 652 | 669 | case 0x02: |
| 653 | | if (OUTPUT_SELECTED(p->ctl_b)) |
| 654 | | ret = port_b_r(device); |
| 670 | if (OUTPUT_SELECTED(m_ctl_b)) |
| 671 | { |
| 672 | ret = port_b_r(); |
| 673 | } |
| 655 | 674 | else |
| 656 | | ret = ddr_b_r(device); |
| 675 | { |
| 676 | ret = ddr_b_r(); |
| 677 | } |
| 657 | 678 | break; |
| 658 | 679 | |
| 659 | 680 | case 0x03: |
| 660 | | ret = control_b_r(device); |
| 681 | ret = control_b_r(); |
| 661 | 682 | break; |
| 662 | 683 | } |
| 663 | 684 | |
| r8892 | r8893 | |
| 671 | 692 | |
| 672 | 693 | READ8_DEVICE_HANDLER( pia6821_alt_r ) |
| 673 | 694 | { |
| 674 | | return pia6821_r(device, ((offset << 1) & 0x02) | ((offset >> 1) & 0x01)); |
| 695 | return downcast<pia6821_device *>(device)->reg_r(((offset << 1) & 0x02) | ((offset >> 1) & 0x01)); |
| 675 | 696 | } |
| 676 | 697 | |
| 677 | 698 | |
| 699 | |
| 678 | 700 | /*------------------------------------------------- |
| 679 | 701 | pia6821_get_port_b_z_mask |
| 680 | 702 | -------------------------------------------------*/ |
| 681 | 703 | |
| 682 | 704 | UINT8 pia6821_get_port_b_z_mask(running_device *device) |
| 683 | 705 | { |
| 684 | | pia6821_state *p = get_token(device); |
| 685 | | return ~p->ddr_b; |
| 706 | return downcast<pia6821_device *>(device)->get_port_b_z_mask(); |
| 686 | 707 | } |
| 687 | 708 | |
| 709 | UINT8 pia6821_device::get_port_b_z_mask() |
| 710 | { |
| 711 | return ~m_ddr_b; |
| 712 | } |
| 688 | 713 | |
| 714 | |
| 689 | 715 | /*------------------------------------------------- |
| 690 | 716 | send_to_out_a_func |
| 691 | 717 | -------------------------------------------------*/ |
| 692 | 718 | |
| 693 | | static void send_to_out_a_func(running_device *device, const char* message) |
| 719 | void pia6821_device::send_to_out_a_func(const char* message) |
| 694 | 720 | { |
| 695 | | pia6821_state *p = get_token(device); |
| 696 | | |
| 697 | 721 | /* input pins are pulled high */ |
| 698 | | UINT8 data = get_out_a_value(device); |
| 722 | UINT8 data = get_out_a_value(); |
| 699 | 723 | |
| 700 | | LOG(("PIA #%s: %s = %02X\n", device->tag(), message, data)); |
| 724 | LOG(("PIA #%s: %s = %02X\n", tag(), message, data)); |
| 701 | 725 | |
| 702 | | if (p->out_a_func.write != NULL) |
| 703 | | devcb_call_write8(&p->out_a_func, 0, data); |
| 726 | if(m_out_a_func.write != NULL) |
| 727 | { |
| 728 | devcb_call_write8(&m_out_a_func, 0, data); |
| 729 | } |
| 704 | 730 | else |
| 705 | 731 | { |
| 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()); |
| 732 | if(m_out_a_needs_pulled) |
| 733 | { |
| 734 | logerror("PIA #%s: Warning! No port A write handler. Previous value has been lost!\n", tag()); |
| 735 | } |
| 708 | 736 | |
| 709 | | p->out_a_needs_pulled = TRUE; |
| 737 | m_out_a_needs_pulled = TRUE; |
| 710 | 738 | } |
| 711 | 739 | } |
| 712 | 740 | |
| r8892 | r8893 | |
| 715 | 743 | send_to_out_b_func |
| 716 | 744 | -------------------------------------------------*/ |
| 717 | 745 | |
| 718 | | static void send_to_out_b_func(running_device *device, const char* message) |
| 746 | void pia6821_device::send_to_out_b_func(const char* message) |
| 719 | 747 | { |
| 720 | | pia6821_state *p = get_token(device); |
| 721 | | |
| 722 | 748 | /* input pins are high-impedance - we just send them as zeros for backwards compatibility */ |
| 723 | | UINT8 data = get_out_b_value(device); |
| 749 | UINT8 data = get_out_b_value(); |
| 724 | 750 | |
| 725 | | LOG(("PIA #%s: %s = %02X\n", device->tag(), message, data)); |
| 751 | LOG(("PIA #%s: %s = %02X\n", tag(), message, data)); |
| 726 | 752 | |
| 727 | | if (p->out_b_func.write != NULL) |
| 728 | | devcb_call_write8(&p->out_b_func, 0, data); |
| 753 | if(m_out_b_func.write != NULL) |
| 754 | { |
| 755 | devcb_call_write8(&m_out_b_func, 0, data); |
| 756 | } |
| 729 | 757 | else |
| 730 | 758 | { |
| 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()); |
| 759 | if(m_out_b_needs_pulled) |
| 760 | { |
| 761 | logerror("PIA #%s: Warning! No port B write handler. Previous value has been lost!\n", tag()); |
| 762 | } |
| 733 | 763 | |
| 734 | | p->out_b_needs_pulled = TRUE; |
| 764 | m_out_b_needs_pulled = TRUE; |
| 735 | 765 | } |
| 736 | 766 | } |
| 737 | 767 | |
| r8892 | r8893 | |
| 740 | 770 | port_a_w |
| 741 | 771 | -------------------------------------------------*/ |
| 742 | 772 | |
| 743 | | static void port_a_w(running_device *device, UINT8 data) |
| 773 | void pia6821_device::port_a_w(UINT8 data) |
| 744 | 774 | { |
| 745 | | pia6821_state *p = get_token(device); |
| 746 | | |
| 747 | 775 | /* buffer the output value */ |
| 748 | | p->out_a = data; |
| 776 | m_out_a = data; |
| 749 | 777 | |
| 750 | | send_to_out_a_func(device, "port A write"); |
| 778 | send_to_out_a_func("port A write"); |
| 751 | 779 | } |
| 752 | 780 | |
| 753 | 781 | |
| r8892 | r8893 | |
| 755 | 783 | ddr_a_w |
| 756 | 784 | -------------------------------------------------*/ |
| 757 | 785 | |
| 758 | | static void ddr_a_w(running_device *device, UINT8 data) |
| 786 | void pia6821_device::ddr_a_w(UINT8 data) |
| 759 | 787 | { |
| 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)); |
| 788 | if(data == 0x00) |
| 789 | { |
| 790 | LOG(("PIA #%s: DDR A write = %02X (input mode)\n", tag(), data)); |
| 791 | } |
| 792 | else if(data == 0xff) |
| 793 | { |
| 794 | LOG(("PIA #%s: DDR A write = %02X (output mode)\n", tag(), data)); |
| 795 | } |
| 766 | 796 | else |
| 767 | | LOG(("PIA #%s: DDR A write = %02X (mixed mode)\n", device->tag(), data)); |
| 797 | { |
| 798 | LOG(("PIA #%s: DDR A write = %02X (mixed mode)\n", tag(), data)); |
| 799 | } |
| 768 | 800 | |
| 769 | | if (p->ddr_a != data) |
| 801 | if(m_ddr_a != data) |
| 770 | 802 | { |
| 771 | 803 | /* 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"); |
| 804 | m_ddr_a = data; |
| 805 | m_logged_port_a_not_connected = FALSE; |
| 806 | send_to_out_a_func("port A write due to DDR change"); |
| 775 | 807 | } |
| 776 | 808 | } |
| 777 | 809 | |
| r8892 | r8893 | |
| 780 | 812 | port_b_w |
| 781 | 813 | -------------------------------------------------*/ |
| 782 | 814 | |
| 783 | | static void port_b_w(running_device *device, UINT8 data) |
| 815 | void pia6821_device::port_b_w(UINT8 data) |
| 784 | 816 | { |
| 785 | | pia6821_state *p = get_token(device); |
| 786 | | |
| 787 | 817 | /* buffer the output value */ |
| 788 | | p->out_b = data; |
| 818 | m_out_b = data; |
| 789 | 819 | |
| 790 | | send_to_out_b_func(device, "port B write"); |
| 820 | send_to_out_b_func("port B write"); |
| 791 | 821 | |
| 792 | 822 | /* CB2 in write strobe mode */ |
| 793 | | if (C2_STROBE_MODE(p->ctl_b)) |
| 823 | if(C2_STROBE_MODE(m_ctl_b)) |
| 794 | 824 | { |
| 795 | 825 | /* this will cause a transition low */ |
| 796 | | set_out_cb2(device, FALSE); |
| 826 | set_out_cb2(FALSE); |
| 797 | 827 | |
| 798 | 828 | /* 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); |
| 829 | if(STROBE_E_RESET(m_ctl_b)) |
| 830 | { |
| 831 | set_out_cb2(TRUE); |
| 832 | } |
| 801 | 833 | } |
| 802 | 834 | } |
| 803 | 835 | |
| r8892 | r8893 | |
| 806 | 838 | ddr_b_w |
| 807 | 839 | -------------------------------------------------*/ |
| 808 | 840 | |
| 809 | | static void ddr_b_w(running_device *device, UINT8 data) |
| 841 | void pia6821_device::ddr_b_w(UINT8 data) |
| 810 | 842 | { |
| 811 | | pia6821_state *p = get_token(device); |
| 812 | | |
| 813 | 843 | if (data == 0x00) |
| 814 | | LOG(("PIA #%s: DDR B write = %02X (input mode)\n", device->tag(), data)); |
| 844 | { |
| 845 | LOG(("PIA #%s: DDR B write = %02X (input mode)\n", tag(), data)); |
| 846 | } |
| 815 | 847 | else if (data == 0xff) |
| 816 | | LOG(("PIA #%s: DDR B write = %02X (output mode)\n", device->tag(), data)); |
| 848 | { |
| 849 | LOG(("PIA #%s: DDR B write = %02X (output mode)\n", tag(), data)); |
| 850 | } |
| 817 | 851 | else |
| 818 | | LOG(("PIA #%s: DDR B write = %02X (mixed mode)\n", device->tag(), data)); |
| 852 | { |
| 853 | LOG(("PIA #%s: DDR B write = %02X (mixed mode)\n", tag(), data)); |
| 854 | } |
| 819 | 855 | |
| 820 | | if (p->ddr_b != data) |
| 856 | if(m_ddr_b != data) |
| 821 | 857 | { |
| 822 | 858 | /* 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"); |
| 859 | m_ddr_b = data; |
| 860 | m_logged_port_b_not_connected = FALSE; |
| 861 | send_to_out_b_func("port B write due to DDR change"); |
| 826 | 862 | } |
| 827 | 863 | } |
| 828 | 864 | |
| r8892 | r8893 | |
| 831 | 867 | control_a_w |
| 832 | 868 | -------------------------------------------------*/ |
| 833 | 869 | |
| 834 | | static void control_a_w(running_device *device, UINT8 data) |
| 870 | void pia6821_device::control_a_w(UINT8 data) |
| 835 | 871 | { |
| 836 | | pia6821_state *p = get_token(device); |
| 837 | | |
| 838 | 872 | /* bit 7 and 6 are read only */ |
| 839 | 873 | data &= 0x3f; |
| 840 | 874 | |
| 841 | | LOG(("PIA #%s: control A write = %02X\n", device->tag(), data)); |
| 875 | LOG(("PIA #%s: control A write = %02X\n", tag(), data)); |
| 842 | 876 | |
| 843 | 877 | /* update the control register */ |
| 844 | | p->ctl_a = data; |
| 878 | m_ctl_a = data; |
| 845 | 879 | |
| 846 | 880 | /* CA2 is configured as output */ |
| 847 | | if (C2_OUTPUT(p->ctl_a)) |
| 881 | if(C2_OUTPUT(m_ctl_a)) |
| 848 | 882 | { |
| 849 | 883 | int temp; |
| 850 | 884 | |
| 851 | | if (C2_SET_MODE(p->ctl_a)) |
| 885 | if(C2_SET_MODE(m_ctl_a)) |
| 886 | { |
| 852 | 887 | /* set/reset mode - bit value determines the new output */ |
| 853 | | temp = C2_SET(p->ctl_a); |
| 888 | temp = C2_SET(m_ctl_a); |
| 889 | } |
| 854 | 890 | else |
| 891 | { |
| 855 | 892 | /* strobe mode - output is always high unless strobed */ |
| 856 | 893 | temp = TRUE; |
| 894 | } |
| 857 | 895 | |
| 858 | | set_out_ca2(device, temp); |
| 896 | set_out_ca2(temp); |
| 859 | 897 | } |
| 860 | 898 | |
| 861 | 899 | /* update externals */ |
| 862 | | update_interrupts(device); |
| 900 | update_interrupts(); |
| 863 | 901 | } |
| 864 | 902 | |
| 865 | 903 | |
| r8892 | r8893 | |
| 867 | 905 | control_b_w |
| 868 | 906 | -------------------------------------------------*/ |
| 869 | 907 | |
| 870 | | static void control_b_w(running_device *device, UINT8 data) |
| 908 | void pia6821_device::control_b_w(UINT8 data) |
| 871 | 909 | { |
| 872 | | pia6821_state *p = get_token(device); |
| 873 | 910 | int temp; |
| 874 | 911 | |
| 875 | 912 | /* bit 7 and 6 are read only */ |
| 876 | 913 | data &= 0x3f; |
| 877 | 914 | |
| 878 | | LOG(("PIA #%s: control B write = %02X\n", device->tag(), data)); |
| 915 | LOG(("PIA #%s: control B write = %02X\n", tag(), data)); |
| 879 | 916 | |
| 880 | 917 | /* update the control register */ |
| 881 | | p->ctl_b = data; |
| 918 | m_ctl_b = data; |
| 882 | 919 | |
| 883 | | if (C2_SET_MODE(p->ctl_b)) |
| 920 | if (C2_SET_MODE(m_ctl_b)) |
| 921 | { |
| 884 | 922 | /* set/reset mode - bit value determines the new output */ |
| 885 | | temp = C2_SET(p->ctl_b); |
| 923 | temp = C2_SET(m_ctl_b); |
| 924 | } |
| 886 | 925 | else |
| 926 | { |
| 887 | 927 | /* strobe mode - output is always high unless strobed */ |
| 888 | 928 | temp = TRUE; |
| 929 | } |
| 889 | 930 | |
| 890 | | set_out_cb2(device, temp); |
| 931 | set_out_cb2(temp); |
| 891 | 932 | |
| 892 | 933 | /* update externals */ |
| 893 | | update_interrupts(device); |
| 934 | update_interrupts(); |
| 894 | 935 | } |
| 895 | 936 | |
| 896 | 937 | |
| r8892 | r8893 | |
| 900 | 941 | |
| 901 | 942 | WRITE8_DEVICE_HANDLER( pia6821_w ) |
| 902 | 943 | { |
| 903 | | pia6821_state *p = get_token(device); |
| 944 | downcast<pia6821_device *>(device)->reg_w(offset, data); |
| 945 | } |
| 904 | 946 | |
| 947 | void pia6821_device::reg_w(UINT8 offset, UINT8 data) |
| 948 | { |
| 905 | 949 | switch (offset & 0x03) |
| 906 | 950 | { |
| 907 | 951 | default: /* impossible */ |
| 908 | 952 | case 0x00: |
| 909 | | if (OUTPUT_SELECTED(p->ctl_a)) |
| 910 | | port_a_w(device, data); |
| 953 | if (OUTPUT_SELECTED(m_ctl_a)) |
| 954 | { |
| 955 | port_a_w(data); |
| 956 | } |
| 911 | 957 | else |
| 912 | | ddr_a_w(device, data); |
| 958 | { |
| 959 | ddr_a_w(data); |
| 960 | } |
| 913 | 961 | break; |
| 914 | 962 | |
| 915 | 963 | case 0x01: |
| 916 | | control_a_w(device, data); |
| 964 | control_a_w( data); |
| 917 | 965 | break; |
| 918 | 966 | |
| 919 | 967 | case 0x02: |
| 920 | | if (OUTPUT_SELECTED(p->ctl_b)) |
| 921 | | port_b_w(device, data); |
| 968 | if(OUTPUT_SELECTED(m_ctl_b)) |
| 969 | { |
| 970 | port_b_w(data); |
| 971 | } |
| 922 | 972 | else |
| 923 | | ddr_b_w(device, data); |
| 973 | { |
| 974 | ddr_b_w(data); |
| 975 | } |
| 924 | 976 | break; |
| 925 | 977 | |
| 926 | 978 | case 0x03: |
| 927 | | control_b_w(device, data); |
| 979 | control_b_w(data); |
| 928 | 980 | break; |
| 929 | 981 | } |
| 930 | 982 | } |
| r8892 | r8893 | |
| 936 | 988 | |
| 937 | 989 | WRITE8_DEVICE_HANDLER( pia6821_alt_w ) |
| 938 | 990 | { |
| 939 | | pia6821_w(device, ((offset << 1) & 0x02) | ((offset >> 1) & 0x01), data); |
| 991 | downcast<pia6821_device *>(device)->reg_w(((offset << 1) & 0x02) | ((offset >> 1) & 0x01), data); |
| 940 | 992 | } |
| 941 | 993 | |
| 942 | 994 | |
| r8892 | r8893 | |
| 946 | 998 | |
| 947 | 999 | void pia6821_set_port_a_z_mask(running_device *device, UINT8 data) |
| 948 | 1000 | { |
| 949 | | pia6821_state *p = get_token(device); |
| 1001 | downcast<pia6821_device *>(device)->set_port_a_z_mask(data); |
| 1002 | } |
| 950 | 1003 | |
| 951 | | p->port_a_z_mask = data; |
| 1004 | void pia6821_device::set_port_a_z_mask(UINT8 data) |
| 1005 | { |
| 1006 | m_port_a_z_mask = data; |
| 952 | 1007 | } |
| 953 | 1008 | |
| 954 | 1009 | |
| r8892 | r8893 | |
| 958 | 1013 | |
| 959 | 1014 | READ8_DEVICE_HANDLER( pia6821_porta_r ) |
| 960 | 1015 | { |
| 961 | | pia6821_state *p = get_token(device); |
| 1016 | return downcast<pia6821_device *>(device)->porta_r(); |
| 1017 | } |
| 962 | 1018 | |
| 963 | | return p->in_a; |
| 1019 | UINT8 pia6821_device::porta_r() |
| 1020 | { |
| 1021 | return m_in_a; |
| 964 | 1022 | } |
| 965 | 1023 | |
| 966 | 1024 | |
| r8892 | r8893 | |
| 970 | 1028 | |
| 971 | 1029 | void pia6821_set_input_a(running_device *device, UINT8 data, UINT8 z_mask) |
| 972 | 1030 | { |
| 973 | | pia6821_state *p = get_token(device); |
| 1031 | downcast<pia6821_device *>(device)->set_input_a(data, z_mask); |
| 1032 | } |
| 974 | 1033 | |
| 975 | | assert_always(p->in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented"); |
| 1034 | void pia6821_device::set_input_a(UINT8 data, UINT8 z_mask) |
| 1035 | { |
| 1036 | assert_always(m_in_a_func.read == NULL, "pia6821_porta_w() called when in_a_func implemented"); |
| 976 | 1037 | |
| 977 | | LOG(("PIA #%s: set input port A = %02X\n", device->tag(), data)); |
| 1038 | LOG(("PIA #%s: set input port A = %02X\n", tag(), data)); |
| 978 | 1039 | |
| 979 | | p->in_a = data; |
| 980 | | p->port_a_z_mask = z_mask; |
| 981 | | p->in_a_pushed = TRUE; |
| 1040 | m_in_a = data; |
| 1041 | m_port_a_z_mask = z_mask; |
| 1042 | m_in_a_pushed = TRUE; |
| 982 | 1043 | } |
| 983 | 1044 | |
| 984 | 1045 | |
| r8892 | r8893 | |
| 988 | 1049 | |
| 989 | 1050 | WRITE8_DEVICE_HANDLER( pia6821_porta_w ) |
| 990 | 1051 | { |
| 991 | | pia6821_set_input_a(device, data, 0); |
| 1052 | downcast<pia6821_device *>(device)->porta_w(data); |
| 992 | 1053 | } |
| 993 | 1054 | |
| 1055 | void pia6821_device::porta_w(UINT8 data) |
| 1056 | { |
| 1057 | pia6821_set_input_a(this, data, 0); |
| 1058 | } |
| 994 | 1059 | |
| 1060 | |
| 995 | 1061 | /*------------------------------------------------- |
| 996 | 1062 | pia6821_get_output_a |
| 997 | 1063 | -------------------------------------------------*/ |
| 998 | 1064 | |
| 999 | 1065 | UINT8 pia6821_get_output_a(running_device *device) |
| 1000 | 1066 | { |
| 1001 | | pia6821_state *p = get_token(device); |
| 1067 | return downcast<pia6821_device *>(device)->get_output_a(); |
| 1068 | } |
| 1002 | 1069 | |
| 1003 | | p->out_a_needs_pulled = FALSE; |
| 1070 | UINT8 pia6821_device::get_output_a() |
| 1071 | { |
| 1072 | m_out_a_needs_pulled = FALSE; |
| 1004 | 1073 | |
| 1005 | | return get_out_a_value(device); |
| 1074 | return get_out_a_value(); |
| 1006 | 1075 | } |
| 1007 | 1076 | |
| 1008 | 1077 | |
| r8892 | r8893 | |
| 1012 | 1081 | |
| 1013 | 1082 | READ_LINE_DEVICE_HANDLER( pia6821_ca1_r ) |
| 1014 | 1083 | { |
| 1015 | | pia6821_state *p = get_token(device); |
| 1084 | return downcast<pia6821_device *>(device)->ca1_r(); |
| 1085 | } |
| 1016 | 1086 | |
| 1017 | | return p->in_ca1; |
| 1087 | UINT8 pia6821_device::ca1_r() |
| 1088 | { |
| 1089 | return m_in_ca1; |
| 1018 | 1090 | } |
| 1019 | 1091 | |
| 1020 | 1092 | |
| r8892 | r8893 | |
| 1024 | 1096 | |
| 1025 | 1097 | WRITE_LINE_DEVICE_HANDLER( pia6821_ca1_w ) |
| 1026 | 1098 | { |
| 1027 | | pia6821_state *p = get_token(device); |
| 1099 | downcast<pia6821_device *>(device)->ca1_w(state); |
| 1100 | } |
| 1028 | 1101 | |
| 1029 | | LOG(("PIA #%s: set input CA1 = %d\n", device->tag(), state)); |
| 1102 | void pia6821_device::ca1_w(UINT8 state) |
| 1103 | { |
| 1104 | LOG(("PIA #%s: set input CA1 = %d\n", tag(), state)); |
| 1030 | 1105 | |
| 1031 | 1106 | /* 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)))) |
| 1107 | if((m_in_ca1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_a)) || (!state && C1_HIGH_TO_LOW(m_ctl_a)))) |
| 1034 | 1108 | { |
| 1035 | | LOG(("PIA #%s: CA1 triggering\n", device->tag())); |
| 1109 | LOG(("PIA #%s: CA1 triggering\n", tag())); |
| 1036 | 1110 | |
| 1037 | 1111 | /* mark the IRQ */ |
| 1038 | | p->irq_a1 = TRUE; |
| 1112 | m_irq_a1 = TRUE; |
| 1039 | 1113 | |
| 1040 | 1114 | /* update externals */ |
| 1041 | | update_interrupts(device); |
| 1115 | update_interrupts(); |
| 1042 | 1116 | |
| 1043 | 1117 | /* 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); |
| 1118 | if(C2_OUTPUT(m_ctl_a) && C2_STROBE_MODE(m_ctl_a) && STROBE_C1_RESET(m_ctl_a)) |
| 1119 | { |
| 1120 | set_out_ca2(TRUE); |
| 1121 | } |
| 1046 | 1122 | } |
| 1047 | 1123 | |
| 1048 | 1124 | /* set the new value for CA1 */ |
| 1049 | | p->in_ca1 = state; |
| 1050 | | p->in_ca1_pushed = TRUE; |
| 1125 | m_in_ca1 = state; |
| 1126 | m_in_ca1_pushed = TRUE; |
| 1051 | 1127 | } |
| 1052 | 1128 | |
| 1053 | 1129 | |
| r8892 | r8893 | |
| 1057 | 1133 | |
| 1058 | 1134 | READ_LINE_DEVICE_HANDLER( pia6821_ca2_r ) |
| 1059 | 1135 | { |
| 1060 | | pia6821_state *p = get_token(device); |
| 1136 | return downcast<pia6821_device *>(device)->ca2_r(); |
| 1137 | } |
| 1061 | 1138 | |
| 1062 | | return p->in_ca2; |
| 1139 | UINT8 pia6821_device::ca2_r() |
| 1140 | { |
| 1141 | return m_in_ca2; |
| 1063 | 1142 | } |
| 1064 | 1143 | |
| 1065 | 1144 | |
| r8892 | r8893 | |
| 1069 | 1148 | |
| 1070 | 1149 | WRITE_LINE_DEVICE_HANDLER( pia6821_ca2_w ) |
| 1071 | 1150 | { |
| 1072 | | pia6821_state *p = get_token(device); |
| 1151 | downcast<pia6821_device *>(device)->ca2_w(state); |
| 1152 | } |
| 1073 | 1153 | |
| 1074 | | LOG(("PIA #%s: set input CA2 = %d\n", device->tag(), state)); |
| 1154 | void pia6821_device::ca2_w(UINT8 state) |
| 1155 | { |
| 1156 | LOG(("PIA #%s: set input CA2 = %d\n", tag(), state)); |
| 1075 | 1157 | |
| 1076 | 1158 | /* 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)))) |
| 1159 | 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 | 1160 | { |
| 1081 | | LOG(("PIA #%s: CA2 triggering\n", device->tag())); |
| 1161 | LOG(("PIA #%s: CA2 triggering\n", tag())); |
| 1082 | 1162 | |
| 1083 | 1163 | /* mark the IRQ */ |
| 1084 | | p->irq_a2 = TRUE; |
| 1164 | m_irq_a2 = TRUE; |
| 1085 | 1165 | |
| 1086 | 1166 | /* update externals */ |
| 1087 | | update_interrupts(device); |
| 1167 | update_interrupts(); |
| 1088 | 1168 | } |
| 1089 | 1169 | |
| 1090 | 1170 | /* set the new value for CA2 */ |
| 1091 | | p->in_ca2 = state; |
| 1092 | | p->in_ca2_pushed = TRUE; |
| 1171 | m_in_ca2 = state; |
| 1172 | m_in_ca2_pushed = TRUE; |
| 1093 | 1173 | } |
| 1094 | 1174 | |
| 1095 | 1175 | |
| r8892 | r8893 | |
| 1099 | 1179 | |
| 1100 | 1180 | int pia6821_get_output_ca2(running_device *device) |
| 1101 | 1181 | { |
| 1102 | | pia6821_state *p = get_token(device); |
| 1182 | return downcast<pia6821_device *>(device)->get_output_ca2(); |
| 1183 | } |
| 1103 | 1184 | |
| 1104 | | p->out_ca2_needs_pulled = FALSE; |
| 1185 | int pia6821_device::get_output_ca2() |
| 1186 | { |
| 1187 | m_out_ca2_needs_pulled = FALSE; |
| 1105 | 1188 | |
| 1106 | | return p->out_ca2; |
| 1189 | return m_out_ca2; |
| 1107 | 1190 | } |
| 1108 | 1191 | |
| 1109 | 1192 | |
| r8892 | r8893 | |
| 1115 | 1198 | |
| 1116 | 1199 | int pia6821_get_output_ca2_z(running_device *device) |
| 1117 | 1200 | { |
| 1118 | | pia6821_state *p = get_token(device); |
| 1201 | return downcast<pia6821_device *>(device)->get_output_ca2_z(); |
| 1202 | } |
| 1119 | 1203 | |
| 1120 | | p->out_ca2_needs_pulled = FALSE; |
| 1204 | int pia6821_device::get_output_ca2_z() |
| 1205 | { |
| 1206 | m_out_ca2_needs_pulled = FALSE; |
| 1121 | 1207 | |
| 1122 | 1208 | // If it's an output, output the bit, if it's an input, it's |
| 1123 | 1209 | // pulled up |
| 1124 | | return p->out_ca2 | |
| 1125 | | C2_INPUT(p->ctl_a); |
| 1210 | return m_out_ca2 | C2_INPUT(m_ctl_a); |
| 1126 | 1211 | } |
| 1127 | 1212 | |
| 1128 | 1213 | |
| r8892 | r8893 | |
| 1132 | 1217 | |
| 1133 | 1218 | READ8_DEVICE_HANDLER( pia6821_portb_r ) |
| 1134 | 1219 | { |
| 1135 | | pia6821_state *p = get_token(device); |
| 1220 | return downcast<pia6821_device *>(device)->portb_r(); |
| 1221 | } |
| 1136 | 1222 | |
| 1137 | | return p->in_b; |
| 1223 | UINT8 pia6821_device::portb_r() |
| 1224 | { |
| 1225 | return m_in_b; |
| 1138 | 1226 | } |
| 1139 | 1227 | |
| 1140 | 1228 | |
| r8892 | r8893 | |
| 1144 | 1232 | |
| 1145 | 1233 | WRITE8_DEVICE_HANDLER( pia6821_portb_w ) |
| 1146 | 1234 | { |
| 1147 | | pia6821_state *p = get_token(device); |
| 1235 | downcast<pia6821_device *>(device)->portb_w(data); |
| 1236 | } |
| 1148 | 1237 | |
| 1149 | | assert_always(p->in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented"); |
| 1238 | void pia6821_device::portb_w(UINT8 data) |
| 1239 | { |
| 1240 | assert_always(m_in_b_func.read == NULL, "pia_set_input_b() called when in_b_func implemented"); |
| 1150 | 1241 | |
| 1151 | | LOG(("PIA #%s: set input port B = %02X\n", device->tag(), data)); |
| 1242 | LOG(("PIA #%s: set input port B = %02X\n", tag(), data)); |
| 1152 | 1243 | |
| 1153 | | p->in_b = data; |
| 1154 | | p->in_b_pushed = TRUE; |
| 1244 | m_in_b = data; |
| 1245 | m_in_b_pushed = TRUE; |
| 1155 | 1246 | } |
| 1156 | 1247 | |
| 1157 | 1248 | |
| r8892 | r8893 | |
| 1161 | 1252 | |
| 1162 | 1253 | UINT8 pia6821_get_output_b(running_device *device) |
| 1163 | 1254 | { |
| 1164 | | pia6821_state *p = get_token(device); |
| 1255 | return downcast<pia6821_device *>(device)->get_output_b(); |
| 1256 | } |
| 1165 | 1257 | |
| 1166 | | p->out_b_needs_pulled = FALSE; |
| 1258 | UINT8 pia6821_device::get_output_b() |
| 1259 | { |
| 1260 | m_out_b_needs_pulled = FALSE; |
| 1167 | 1261 | |
| 1168 | | return get_out_b_value(device); |
| 1262 | return get_out_b_value(); |
| 1169 | 1263 | } |
| 1170 | 1264 | |
| 1171 | 1265 | |
| r8892 | r8893 | |
| 1175 | 1269 | |
| 1176 | 1270 | READ_LINE_DEVICE_HANDLER( pia6821_cb1_r ) |
| 1177 | 1271 | { |
| 1178 | | pia6821_state *p = get_token(device); |
| 1272 | return downcast<pia6821_device *>(device)->cb1_r(); |
| 1273 | } |
| 1179 | 1274 | |
| 1180 | | return p->in_cb1; |
| 1275 | UINT8 pia6821_device::cb1_r() |
| 1276 | { |
| 1277 | return m_in_cb1; |
| 1181 | 1278 | } |
| 1182 | 1279 | |
| 1183 | 1280 | |
| r8892 | r8893 | |
| 1187 | 1284 | |
| 1188 | 1285 | WRITE_LINE_DEVICE_HANDLER( pia6821_cb1_w ) |
| 1189 | 1286 | { |
| 1190 | | pia6821_state *p = get_token(device); |
| 1287 | downcast<pia6821_device *>(device)->cb1_w(state); |
| 1288 | } |
| 1191 | 1289 | |
| 1192 | | LOG(("PIA #%s: set input CB1 = %d\n", device->tag(), state)); |
| 1290 | void pia6821_device::cb1_w(UINT8 state) |
| 1291 | { |
| 1292 | LOG(("PIA #%s: set input CB1 = %d\n", tag(), state)); |
| 1193 | 1293 | |
| 1194 | 1294 | /* 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)))) |
| 1295 | if((m_in_cb1 != state) && ((state && C1_LOW_TO_HIGH(m_ctl_b)) || (!state && C1_HIGH_TO_LOW(m_ctl_b)))) |
| 1197 | 1296 | { |
| 1198 | | LOG(("PIA #%s: CB1 triggering\n", device->tag())); |
| 1297 | LOG(("PIA #%s: CB1 triggering\n", tag())); |
| 1199 | 1298 | |
| 1200 | 1299 | /* mark the IRQ */ |
| 1201 | | p->irq_b1 = 1; |
| 1300 | m_irq_b1 = 1; |
| 1202 | 1301 | |
| 1203 | 1302 | /* update externals */ |
| 1204 | | update_interrupts(device); |
| 1303 | update_interrupts(); |
| 1205 | 1304 | |
| 1206 | 1305 | /* If CB2 is configured as a write-strobe output which is reset by a CB1 |
| 1207 | 1306 | transition, this reset will only happen when a read from port B implicitly |
| r8892 | r8893 | |
| 1210 | 1309 | } |
| 1211 | 1310 | |
| 1212 | 1311 | /* set the new value for CB1 */ |
| 1213 | | p->in_cb1 = state; |
| 1214 | | p->in_cb1_pushed = TRUE; |
| 1312 | m_in_cb1 = state; |
| 1313 | m_in_cb1_pushed = TRUE; |
| 1215 | 1314 | } |
| 1216 | 1315 | |
| 1217 | 1316 | |
| r8892 | r8893 | |
| 1221 | 1320 | |
| 1222 | 1321 | READ_LINE_DEVICE_HANDLER( pia6821_cb2_r ) |
| 1223 | 1322 | { |
| 1224 | | pia6821_state *p = get_token(device); |
| 1323 | return downcast<pia6821_device *>(device)->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 | |
| r8892 | r8893 | |
| 1233 | 1335 | |
| 1234 | 1336 | WRITE_LINE_DEVICE_HANDLER( pia6821_cb2_w ) |
| 1235 | 1337 | { |
| 1236 | | pia6821_state *p = get_token(device); |
| 1338 | downcast<pia6821_device *>(device)->cb2_w(state); |
| 1339 | } |
| 1237 | 1340 | |
| 1238 | | LOG(("PIA #%s: set input CB2 = %d\n", device->tag(), state)); |
| 1341 | void pia6821_device::cb2_w(UINT8 state) |
| 1342 | { |
| 1343 | LOG(("PIA #%s: set input CB2 = %d\n", tag(), state)); |
| 1239 | 1344 | |
| 1240 | 1345 | /* 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)))) |
| 1346 | if (C2_INPUT(m_ctl_b) && |
| 1347 | (m_in_cb2 != state) && |
| 1348 | ((state && C2_LOW_TO_HIGH(m_ctl_b)) || (!state && C2_HIGH_TO_LOW(m_ctl_b)))) |
| 1244 | 1349 | { |
| 1245 | | LOG(("PIA #%s: CB2 triggering\n", device->tag())); |
| 1350 | LOG(("PIA #%s: CB2 triggering\n", tag())); |
| 1246 | 1351 | |
| 1247 | 1352 | /* mark the IRQ */ |
| 1248 | | p->irq_b2 = 1; |
| 1353 | m_irq_b2 = 1; |
| 1249 | 1354 | |
| 1250 | 1355 | /* update externals */ |
| 1251 | | update_interrupts(device); |
| 1356 | update_interrupts(); |
| 1252 | 1357 | } |
| 1253 | 1358 | |
| 1254 | 1359 | /* set the new value for CA2 */ |
| 1255 | | p->in_cb2 = state; |
| 1256 | | p->in_cb2_pushed = TRUE; |
| 1360 | m_in_cb2 = state; |
| 1361 | m_in_cb2_pushed = TRUE; |
| 1257 | 1362 | } |
| 1258 | 1363 | |
| 1259 | 1364 | |
| r8892 | r8893 | |
| 1263 | 1368 | |
| 1264 | 1369 | int pia6821_get_output_cb2(running_device *device) |
| 1265 | 1370 | { |
| 1266 | | pia6821_state *p = get_token(device); |
| 1371 | return downcast<pia6821_device *>(device)->get_output_cb2(); |
| 1372 | } |
| 1267 | 1373 | |
| 1268 | | p->out_cb2_needs_pulled = FALSE; |
| 1374 | int pia6821_device::get_output_cb2() |
| 1375 | { |
| 1376 | m_out_cb2_needs_pulled = FALSE; |
| 1269 | 1377 | |
| 1270 | | return p->out_cb2; |
| 1378 | return m_out_cb2; |
| 1271 | 1379 | } |
| 1272 | 1380 | |
| 1273 | 1381 | |
| r8892 | r8893 | |
| 1277 | 1385 | |
| 1278 | 1386 | int pia6821_get_output_cb2_z(running_device *device) |
| 1279 | 1387 | { |
| 1280 | | pia6821_state *p = get_token(device); |
| 1388 | return downcast<pia6821_device *>(device)->get_output_cb2_z(); |
| 1389 | } |
| 1281 | 1390 | |
| 1282 | | return !C2_OUTPUT(p->ctl_b); |
| 1391 | int pia6821_device::get_output_cb2_z() |
| 1392 | { |
| 1393 | return !C2_OUTPUT(m_ctl_b); |
| 1283 | 1394 | } |
| 1284 | 1395 | |
| 1285 | 1396 | |
| r8892 | r8893 | |
| 1289 | 1400 | |
| 1290 | 1401 | int pia6821_get_irq_a(running_device *device) |
| 1291 | 1402 | { |
| 1292 | | pia6821_state *p = get_token(device); |
| 1403 | return downcast<pia6821_device *>(device)->get_irq_a(); |
| 1404 | } |
| 1293 | 1405 | |
| 1294 | | return p->irq_a_state; |
| 1406 | int pia6821_device::get_irq_a() |
| 1407 | { |
| 1408 | return m_irq_a_state; |
| 1295 | 1409 | } |
| 1296 | 1410 | |
| 1297 | 1411 | |
| r8892 | r8893 | |
| 1301 | 1415 | |
| 1302 | 1416 | int pia6821_get_irq_b(running_device *device) |
| 1303 | 1417 | { |
| 1304 | | pia6821_state *p = get_token(device); |
| 1418 | return downcast<pia6821_device *>(device)->get_irq_b(); |
| 1419 | } |
| 1305 | 1420 | |
| 1306 | | return p->irq_b_state; |
| 1421 | int pia6821_device::get_irq_b() |
| 1422 | { |
| 1423 | return m_irq_b_state; |
| 1307 | 1424 | } |
| 1308 | | |
| 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); |
src/emu/machine/6532riot.c
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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 */ |
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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); |
| r8892 | r8893 | |
| 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
| r8892 | r8893 | |
| 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 | |
| r8892 | r8893 | |
| 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 | // inherit a copy of the static data |
| 152 | const via6522_interface *intf = reinterpret_cast<const via6522_interface *>(static_config()); |
| 153 | if (intf != NULL) |
| 154 | *static_cast<via6522_interface *>(this) = *intf; |
| 155 | |
| 156 | // or initialize to defaults if none provided |
| 157 | else |
| 158 | { |
| 159 | memset(&m_in_a_func, 0, sizeof(m_in_a_func)); |
| 160 | memset(&m_in_b_func, 0, sizeof(m_in_b_func)); |
| 161 | memset(&m_in_ca1_func, 0, sizeof(m_in_ca1_func)); |
| 162 | memset(&m_in_cb1_func, 0, sizeof(m_in_cb1_func)); |
| 163 | memset(&m_in_ca2_func, 0, sizeof(m_in_ca2_func)); |
| 164 | memset(&m_in_cb2_func, 0, sizeof(m_in_cb2_func)); |
| 165 | memset(&m_out_a_func, 0, sizeof(m_out_a_func)); |
| 166 | memset(&m_out_b_func, 0, sizeof(m_out_b_func)); |
| 167 | memset(&m_out_ca2_func, 0, sizeof(m_out_ca2_func)); |
| 168 | memset(&m_out_cb2_func, 0, sizeof(m_out_cb2_func)); |
| 169 | memset(&m_irq_func, 0, sizeof(m_irq_func)); |
| 170 | } |
| 208 | 171 | } |
| 209 | 172 | |
| 210 | 173 | |
| 211 | | INLINE UINT16 v_get_counter1_value(running_device *device) |
| 174 | |
| 175 | /*************************************************************************** |
| 176 | INLINE FUNCTIONS |
| 177 | ***************************************************************************/ |
| 178 | |
| 179 | attotime via6522_device::cycles_to_time(int c) |
| 212 | 180 | { |
| 213 | | via6522_t *v = get_token(device); |
| 181 | return attotime_mul(ATTOTIME_IN_HZ(clock()), c); |
| 182 | } |
| 183 | |
| 184 | |
| 185 | UINT32 via6522_device::time_to_cycles(attotime t) |
| 186 | { |
| 187 | return attotime_to_double(attotime_mul(t, clock())); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | UINT16 via6522_device::get_counter1_value() |
| 192 | { |
| 214 | 193 | UINT16 val; |
| 215 | 194 | |
| 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)); |
| 195 | if(m_t1_active) |
| 196 | { |
| 197 | val = time_to_cycles(timer_timeleft(m_t1)) - IFR_DELAY; |
| 220 | 198 | } |
| 199 | else |
| 200 | { |
| 201 | val = 0xffff - time_to_cycles(attotime_sub(timer_get_time(&m_machine), m_time1)); |
| 202 | } |
| 203 | |
| 221 | 204 | return val; |
| 222 | 205 | } |
| 223 | 206 | |
| 224 | 207 | |
| 225 | | /*************************************************************************** |
| 226 | | IMPLEMENTATION |
| 227 | | ***************************************************************************/ |
| 208 | //************************************************************************** |
| 209 | // LIVE DEVICE |
| 210 | //************************************************************************** |
| 228 | 211 | |
| 229 | | /*------------------------------------------------- |
| 230 | | DEVICE_START( via6522 ) |
| 231 | | -------------------------------------------------*/ |
| 212 | const device_type VIA6522 = via6522_device_config::static_alloc_device_config; |
| 232 | 213 | |
| 233 | | static DEVICE_START( via6522 ) |
| 214 | //------------------------------------------------- |
| 215 | // via6522_device - constructor |
| 216 | //------------------------------------------------- |
| 217 | |
| 218 | via6522_device::via6522_device(running_machine &_machine, const via6522_device_config &config) |
| 219 | : device_t(_machine, config), |
| 220 | m_config(config) |
| 234 | 221 | { |
| 235 | | via6522_t *v = get_token(device); |
| 236 | | const via6522_interface *intf = get_interface(device); |
| 237 | 222 | |
| 238 | | memset(v, 0, sizeof(*v)); |
| 223 | } |
| 239 | 224 | |
| 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); |
| 225 | //------------------------------------------------- |
| 226 | // device_start - device-specific startup |
| 227 | //------------------------------------------------- |
| 253 | 228 | |
| 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); |
| 229 | void via6522_device::device_start() |
| 230 | { |
| 231 | devcb_resolve_read8(&m_in_a_func, &m_config.m_in_a_func, this); |
| 232 | devcb_resolve_read8(&m_in_b_func, &m_config.m_in_b_func, this); |
| 233 | devcb_resolve_read_line(&m_in_ca1_func, &m_config.m_in_ca1_func, this); |
| 234 | devcb_resolve_read_line(&m_in_cb1_func, &m_config.m_in_cb1_func, this); |
| 235 | devcb_resolve_read_line(&m_in_ca2_func, &m_config.m_in_ca2_func, this); |
| 236 | devcb_resolve_read_line(&m_in_cb2_func, &m_config.m_in_cb2_func, this); |
| 237 | devcb_resolve_write8(&m_out_a_func, &m_config.m_out_a_func, this); |
| 238 | devcb_resolve_write8(&m_out_b_func, &m_config.m_out_b_func, this); |
| 239 | devcb_resolve_write_line(&m_out_ca1_func, &m_config.m_out_ca1_func, this); |
| 240 | devcb_resolve_write_line(&m_out_cb1_func, &m_config.m_out_cb1_func, this); |
| 241 | devcb_resolve_write_line(&m_out_ca2_func, &m_config.m_out_ca2_func, this); |
| 242 | devcb_resolve_write_line(&m_out_cb2_func, &m_config.m_out_cb2_func, this); |
| 243 | devcb_resolve_write_line(&m_irq_func, &m_config.m_irq_func, this); |
| 262 | 244 | |
| 245 | m_t1ll = 0xf3; /* via at 0x9110 in vic20 show these values */ |
| 246 | m_t1lh = 0xb5; /* ports are not written by kernel! */ |
| 247 | m_t2ll = 0xff; /* taken from vice */ |
| 248 | m_t2lh = 0xff; |
| 249 | m_time2 = m_time1 = timer_get_time(&m_machine); |
| 250 | m_t1 = timer_alloc(&m_machine, t1_timeout_callback, (void *)this); |
| 251 | m_t2 = timer_alloc(&m_machine, t2_timeout_callback, (void *)this); |
| 252 | m_shift_timer = timer_alloc(&m_machine, shift_callback, (void *)this); |
| 253 | |
| 263 | 254 | /* Default clock is from CPU1 */ |
| 264 | | if (device->clock() == 0) |
| 265 | | device->set_unscaled_clock(device->machine->firstcpu->clock()); |
| 255 | if (clock() == 0) |
| 256 | { |
| 257 | set_unscaled_clock(m_machine.firstcpu->clock()); |
| 258 | } |
| 266 | 259 | |
| 267 | 260 | /* 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); |
| 261 | state_save_register_device_item(this, 0, m_in_a); |
| 262 | state_save_register_device_item(this, 0, m_in_ca1); |
| 263 | state_save_register_device_item(this, 0, m_in_ca2); |
| 264 | state_save_register_device_item(this, 0, m_out_a); |
| 265 | state_save_register_device_item(this, 0, m_out_ca2); |
| 266 | state_save_register_device_item(this, 0, m_ddr_a); |
| 267 | state_save_register_device_item(this, 0, m_in_b); |
| 268 | state_save_register_device_item(this, 0, m_in_cb1); |
| 269 | state_save_register_device_item(this, 0, m_in_cb2); |
| 270 | state_save_register_device_item(this, 0, m_out_b); |
| 271 | state_save_register_device_item(this, 0, m_out_cb2); |
| 272 | state_save_register_device_item(this, 0, m_ddr_b); |
| 273 | state_save_register_device_item(this, 0, m_t1cl); |
| 274 | state_save_register_device_item(this, 0, m_t1ch); |
| 275 | state_save_register_device_item(this, 0, m_t1ll); |
| 276 | state_save_register_device_item(this, 0, m_t1lh); |
| 277 | state_save_register_device_item(this, 0, m_t2cl); |
| 278 | state_save_register_device_item(this, 0, m_t2ch); |
| 279 | state_save_register_device_item(this, 0, m_t2ll); |
| 280 | state_save_register_device_item(this, 0, m_t2lh); |
| 281 | state_save_register_device_item(this, 0, m_sr); |
| 282 | state_save_register_device_item(this, 0, m_pcr); |
| 283 | state_save_register_device_item(this, 0, m_acr); |
| 284 | state_save_register_device_item(this, 0, m_ier); |
| 285 | state_save_register_device_item(this, 0, m_ifr); |
| 286 | state_save_register_device_item(this, 0, m_t1_active); |
| 287 | state_save_register_device_item(this, 0, m_t2_active); |
| 288 | state_save_register_device_item(this, 0, m_shift_counter); |
| 296 | 289 | } |
| 297 | 290 | |
| 298 | 291 | |
| 292 | //------------------------------------------------- |
| 293 | // device_reset - device-specific reset |
| 294 | //------------------------------------------------- |
| 295 | |
| 296 | void via6522_device::device_reset() |
| 297 | { |
| 298 | m_in_a = 0; |
| 299 | m_in_ca1 = 0; |
| 300 | m_in_ca2 = 0; |
| 301 | m_out_a = 0; |
| 302 | m_out_ca2 = 0; |
| 303 | m_ddr_a = 0; |
| 304 | m_in_b = 0; |
| 305 | m_in_cb1 = 0; |
| 306 | m_in_cb2 = 0; |
| 307 | m_out_b = 0; |
| 308 | m_out_cb2 = 0; |
| 309 | m_ddr_b = 0; |
| 310 | |
| 311 | m_t1cl = 0; |
| 312 | m_t1ch = 0; |
| 313 | m_t2cl = 0; |
| 314 | m_t2ch = 0; |
| 315 | |
| 316 | m_sr = 0; |
| 317 | m_pcr = 0; |
| 318 | m_acr = 0; |
| 319 | m_ier = 0; |
| 320 | m_ifr = 0; |
| 321 | m_t1_active = 0; |
| 322 | m_t2_active = 0; |
| 323 | m_shift_counter = 0; |
| 324 | } |
| 325 | |
| 326 | |
| 299 | 327 | /*------------------------------------------------- |
| 300 | 328 | via_set_int - external interrupt check |
| 301 | 329 | -------------------------------------------------*/ |
| 302 | 330 | |
| 303 | | static void via_set_int (running_device *device, int data) |
| 331 | void via6522_device::set_int(int data) |
| 304 | 332 | { |
| 305 | | via6522_t *v = get_token(device); |
| 306 | | |
| 307 | | v->ifr |= data; |
| 333 | m_ifr |= data; |
| 308 | 334 | if (TRACE_VIA) |
| 309 | | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(device->machine), device->tag(), v->ifr); |
| 335 | { |
| 336 | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(&m_machine), tag(), m_ifr); |
| 337 | } |
| 310 | 338 | |
| 311 | | if (v->ier & v->ifr) |
| 339 | if (m_ier & m_ifr) |
| 312 | 340 | { |
| 313 | | v->ifr |= INT_ANY; |
| 314 | | devcb_call_write_line(&v->irq_func, ASSERT_LINE); |
| 341 | m_ifr |= INT_ANY; |
| 342 | devcb_call_write_line(&m_irq_func, ASSERT_LINE); |
| 315 | 343 | } |
| 316 | 344 | } |
| 317 | 345 | |
| r8892 | r8893 | |
| 320 | 348 | via_clear_int - external interrupt check |
| 321 | 349 | -------------------------------------------------*/ |
| 322 | 350 | |
| 323 | | static void via_clear_int (running_device *device, int data) |
| 351 | void via6522_device::clear_int(int data) |
| 324 | 352 | { |
| 325 | | via6522_t *v = get_token(device); |
| 353 | m_ifr = (m_ifr & ~data) & 0x7f; |
| 326 | 354 | |
| 327 | | v->ifr = (v->ifr & ~data) & 0x7f; |
| 328 | | |
| 329 | 355 | if (TRACE_VIA) |
| 330 | | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(device->machine), device->tag(), v->ifr); |
| 356 | { |
| 357 | logerror("%s:6522VIA chip %s: IFR = %02X\n", cpuexec_describe_context(&m_machine), tag(), m_ifr); |
| 358 | } |
| 331 | 359 | |
| 332 | | if (v->ifr & v->ier) |
| 333 | | v->ifr |= INT_ANY; |
| 360 | if (m_ifr & m_ier) |
| 361 | { |
| 362 | m_ifr |= INT_ANY; |
| 363 | } |
| 334 | 364 | else |
| 335 | 365 | { |
| 336 | | devcb_call_write_line(&v->irq_func, CLEAR_LINE); |
| 366 | devcb_call_write_line(&m_irq_func, CLEAR_LINE); |
| 337 | 367 | } |
| 338 | 368 | } |
| 339 | 369 | |
| r8892 | r8893 | |
| 342 | 372 | via_shift |
| 343 | 373 | -------------------------------------------------*/ |
| 344 | 374 | |
| 345 | | static void via_shift(running_device *device) |
| 375 | void via6522_device::shift() |
| 346 | 376 | { |
| 347 | | via6522_t *v = get_token(device); |
| 348 | | |
| 349 | | if (SO_O2_CONTROL(v->acr)) |
| 377 | if (SO_O2_CONTROL(m_acr)) |
| 350 | 378 | { |
| 351 | | v->out_cb2 = (v->sr >> 7) & 1; |
| 352 | | v->sr = (v->sr << 1) | v->out_cb2; |
| 379 | m_out_cb2 = (m_sr >> 7) & 1; |
| 380 | m_sr = (m_sr << 1) | m_out_cb2; |
| 353 | 381 | |
| 354 | | devcb_call_write_line(&v->out_cb2_func, v->out_cb2); |
| 382 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 355 | 383 | |
| 356 | | v->in_cb1=1; |
| 384 | m_in_cb1=1; |
| 357 | 385 | |
| 358 | 386 | /* 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); |
| 387 | devcb_call_write_line(&m_out_cb1_func, 0); |
| 388 | devcb_call_write_line(&m_out_cb1_func, 1); |
| 361 | 389 | |
| 362 | | v->shift_counter = (v->shift_counter + 1) % 8; |
| 390 | m_shift_counter = (m_shift_counter + 1) % 8; |
| 363 | 391 | |
| 364 | | if (v->shift_counter) |
| 365 | | timer_adjust_oneshot(v->shift_timer, v_cycles_to_time(device, 2), 0); |
| 392 | if (m_shift_counter) |
| 393 | { |
| 394 | timer_adjust_oneshot(m_shift_timer, cycles_to_time(2), 0); |
| 395 | } |
| 366 | 396 | else |
| 367 | 397 | { |
| 368 | | if (!(v->ifr & INT_SR)) |
| 369 | | via_set_int(device, INT_SR); |
| 398 | if (!(m_ifr & INT_SR)) |
| 399 | { |
| 400 | set_int(INT_SR); |
| 401 | } |
| 370 | 402 | } |
| 371 | 403 | } |
| 372 | | if (SO_EXT_CONTROL(v->acr)) |
| 404 | if (SO_EXT_CONTROL(m_acr)) |
| 373 | 405 | { |
| 374 | | v->out_cb2 = (v->sr >> 7) & 1; |
| 375 | | v->sr = (v->sr << 1) | v->out_cb2; |
| 406 | m_out_cb2 = (m_sr >> 7) & 1; |
| 407 | m_sr = (m_sr << 1) | m_out_cb2; |
| 376 | 408 | |
| 377 | | devcb_call_write_line(&v->out_cb2_func, v->out_cb2); |
| 409 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 378 | 410 | |
| 379 | | v->shift_counter = (v->shift_counter + 1) % 8; |
| 411 | m_shift_counter = (m_shift_counter + 1) % 8; |
| 380 | 412 | |
| 381 | | if (v->shift_counter == 0) |
| 413 | if (m_shift_counter == 0) |
| 382 | 414 | { |
| 383 | | if (!(v->ifr & INT_SR)) |
| 384 | | via_set_int(device, INT_SR); |
| 415 | if (!(m_ifr & INT_SR)) |
| 416 | { |
| 417 | set_int(INT_SR); |
| 418 | } |
| 385 | 419 | } |
| 386 | 420 | } |
| 387 | | if (SI_EXT_CONTROL(v->acr)) |
| 421 | if (SI_EXT_CONTROL(m_acr)) |
| 388 | 422 | { |
| 389 | | if (v->in_cb2_func.read != NULL) |
| 390 | | v->in_cb2 = devcb_call_read_line(&v->in_cb2_func); |
| 423 | if (m_in_cb2_func.read != NULL) |
| 424 | { |
| 425 | m_in_cb2 = devcb_call_read_line(&m_in_cb2_func); |
| 426 | } |
| 391 | 427 | |
| 392 | | v->sr = (v->sr << 1) | (v->in_cb2 & 1); |
| 428 | m_sr = (m_sr << 1) | (m_in_cb2 & 1); |
| 393 | 429 | |
| 394 | | v->shift_counter = (v->shift_counter + 1) % 8; |
| 430 | m_shift_counter = (m_shift_counter + 1) % 8; |
| 395 | 431 | |
| 396 | | if (v->shift_counter == 0) |
| 432 | if (m_shift_counter == 0) |
| 397 | 433 | { |
| 398 | | if (!(v->ifr & INT_SR)) |
| 434 | if (!(m_ifr & INT_SR)) |
| 399 | 435 | { |
| 400 | | via_set_int(device, INT_SR); |
| 436 | set_int(INT_SR); |
| 401 | 437 | } |
| 402 | 438 | } |
| 403 | 439 | } |
| r8892 | r8893 | |
| 408 | 444 | TIMER_CALLBACK( via_shift_callback ) |
| 409 | 445 | -------------------------------------------------*/ |
| 410 | 446 | |
| 411 | | static TIMER_CALLBACK( via_shift_callback ) |
| 447 | TIMER_CALLBACK( via6522_device::shift_callback ) |
| 412 | 448 | { |
| 413 | | running_device *device = (running_device *)ptr; |
| 414 | | via_shift(device); |
| 449 | via6522_device *via = reinterpret_cast<via6522_device *>(ptr); |
| 450 | via->shift(); |
| 415 | 451 | } |
| 416 | 452 | |
| 417 | 453 | |
| r8892 | r8893 | |
| 419 | 455 | TIMER_CALLBACK( via_t1_timeout ) |
| 420 | 456 | -------------------------------------------------*/ |
| 421 | 457 | |
| 422 | | static TIMER_CALLBACK( via_t1_timeout ) |
| 458 | TIMER_CALLBACK( via6522_device::t1_timeout_callback ) |
| 423 | 459 | { |
| 424 | | running_device *device = (running_device *)ptr; |
| 425 | | via6522_t *v = get_token(device); |
| 460 | via6522_device *via = reinterpret_cast<via6522_device *>(ptr); |
| 461 | via->t1_timeout(); |
| 462 | } |
| 426 | 463 | |
| 427 | | if (T1_CONTINUOUS (v->acr)) |
| 464 | void via6522_device::t1_timeout() |
| 465 | { |
| 466 | if (T1_CONTINUOUS (m_acr)) |
| 428 | 467 | { |
| 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); |
| 468 | if (T1_SET_PB7(m_acr)) |
| 469 | { |
| 470 | m_out_b ^= 0x80; |
| 471 | } |
| 472 | timer_adjust_oneshot(m_t1, cycles_to_time(TIMER1_VALUE + IFR_DELAY), 0); |
| 432 | 473 | } |
| 433 | 474 | else |
| 434 | 475 | { |
| 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); |
| 476 | if (T1_SET_PB7(m_acr)) |
| 477 | { |
| 478 | m_out_b |= 0x80; |
| 479 | } |
| 480 | m_t1_active = 0; |
| 481 | m_time1 = timer_get_time(&m_machine); |
| 439 | 482 | } |
| 440 | | if (v->ddr_b) |
| 483 | if (m_ddr_b) |
| 441 | 484 | { |
| 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); |
| 485 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 486 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 444 | 487 | } |
| 445 | 488 | |
| 446 | | if (!(v->ifr & INT_T1)) |
| 447 | | via_set_int (device, INT_T1); |
| 489 | if (!(m_ifr & INT_T1)) |
| 490 | { |
| 491 | set_int(INT_T1); |
| 492 | } |
| 448 | 493 | } |
| 449 | 494 | |
| 450 | 495 | |
| r8892 | r8893 | |
| 452 | 497 | TIMER_CALLBACK( via_t2_timeout ) |
| 453 | 498 | -------------------------------------------------*/ |
| 454 | 499 | |
| 455 | | static TIMER_CALLBACK( via_t2_timeout ) |
| 500 | TIMER_CALLBACK( via6522_device::t2_timeout_callback ) |
| 456 | 501 | { |
| 457 | | running_device *device = (running_device *)ptr; |
| 458 | | via6522_t *v = get_token(device); |
| 459 | | |
| 460 | | v->t2_active = 0; |
| 461 | | v->time2 = timer_get_time(device->machine); |
| 462 | | |
| 463 | | if (!(v->ifr & INT_T2)) |
| 464 | | via_set_int (device, INT_T2); |
| 502 | via6522_device *via = reinterpret_cast<via6522_device *>(ptr); |
| 503 | via->t2_timeout(); |
| 465 | 504 | } |
| 466 | 505 | |
| 467 | | |
| 468 | | /*------------------------------------------------- |
| 469 | | DEVICE_RESET( via6522 ) |
| 470 | | -------------------------------------------------*/ |
| 471 | | |
| 472 | | static DEVICE_RESET( via6522 ) |
| 506 | void via6522_device::t2_timeout() |
| 473 | 507 | { |
| 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; |
| 508 | m_t2_active = 0; |
| 509 | m_time2 = timer_get_time(&m_machine); |
| 487 | 510 | |
| 488 | | v->t1cl = 0; |
| 489 | | v->t1ch = 0; |
| 490 | | v->t2cl = 0; |
| 491 | | v->t2ch = 0; |
| 492 | | |
| 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; |
| 511 | if (!(m_ifr & INT_T2)) |
| 512 | { |
| 513 | set_int(INT_T2); |
| 514 | } |
| 501 | 515 | } |
| 502 | 516 | |
| 503 | 517 | |
| r8892 | r8893 | |
| 505 | 519 | via_r - CPU interface for VIA read |
| 506 | 520 | -------------------------------------------------*/ |
| 507 | 521 | |
| 508 | | READ8_DEVICE_HANDLER(via_r) |
| 522 | UINT8 via6522_device::reg_r(UINT8 offset) |
| 509 | 523 | { |
| 510 | | via6522_t *v = get_token(device); |
| 511 | 524 | int val = 0; |
| 512 | 525 | |
| 513 | 526 | offset &= 0xf; |
| r8892 | r8893 | |
| 516 | 529 | { |
| 517 | 530 | case VIA_PB: |
| 518 | 531 | /* update the input */ |
| 519 | | if (PB_LATCH_ENABLE(v->acr) == 0) |
| 532 | if (PB_LATCH_ENABLE(m_acr) == 0) |
| 520 | 533 | { |
| 521 | | if (v->ddr_b != 0xff) |
| 534 | if (m_ddr_b != 0xff) |
| 522 | 535 | { |
| 523 | | if (v->in_b_func.read != NULL) |
| 524 | | v->in_b = devcb_call_read8(&v->in_b_func, 0); |
| 536 | if (m_in_b_func.read != NULL) |
| 537 | { |
| 538 | m_in_b = devcb_call_read8(&m_in_b_func, 0); |
| 539 | } |
| 525 | 540 | else |
| 526 | | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 541 | { |
| 542 | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 543 | } |
| 527 | 544 | } |
| 528 | 545 | } |
| 529 | 546 | |
| 530 | | CLR_PB_INT(device); |
| 547 | CLR_PB_INT(); |
| 531 | 548 | |
| 532 | 549 | /* 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)); |
| 550 | if (T1_SET_PB7(m_acr)) |
| 551 | { |
| 552 | val = (m_out_b & (m_ddr_b | 0x80)) | (m_in_b & ~(m_ddr_b | 0x80)); |
| 553 | } |
| 535 | 554 | else |
| 536 | | val = (v->out_b & v->ddr_b) + (v->in_b & ~v->ddr_b); |
| 555 | { |
| 556 | val = (m_out_b & m_ddr_b) + (m_in_b & ~m_ddr_b); |
| 557 | } |
| 537 | 558 | break; |
| 538 | 559 | |
| 539 | 560 | case VIA_PA: |
| 540 | 561 | /* update the input */ |
| 541 | | if (PA_LATCH_ENABLE(v->acr) == 0) |
| 562 | if (PA_LATCH_ENABLE(m_acr) == 0) |
| 542 | 563 | { |
| 543 | | if (v->ddr_a != 0xff) |
| 564 | if (m_ddr_a != 0xff) |
| 544 | 565 | { |
| 545 | | if (v->in_a_func.read != NULL) |
| 546 | | v->in_a = devcb_call_read8(&v->in_a_func, 0); |
| 566 | if (m_in_a_func.read != NULL) |
| 567 | { |
| 568 | m_in_a = devcb_call_read8(&m_in_a_func, 0); |
| 569 | } |
| 547 | 570 | else |
| 548 | | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 571 | { |
| 572 | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 573 | } |
| 549 | 574 | } |
| 550 | 575 | } |
| 551 | 576 | |
| 552 | 577 | /* combine input and output values */ |
| 553 | | val = (v->out_a & v->ddr_a) + (v->in_a & ~v->ddr_a); |
| 578 | val = (m_out_a & m_ddr_a) + (m_in_a & ~m_ddr_a); |
| 554 | 579 | |
| 555 | | CLR_PA_INT(device); |
| 580 | CLR_PA_INT(); |
| 556 | 581 | |
| 557 | 582 | /* If CA2 is configured as output and in pulse or handshake mode, |
| 558 | 583 | CA2 is set now */ |
| 559 | | if (CA2_AUTO_HS(v->pcr)) |
| 584 | if (CA2_AUTO_HS(m_pcr)) |
| 560 | 585 | { |
| 561 | | if (v->out_ca2) |
| 586 | if (m_out_ca2) |
| 562 | 587 | { |
| 563 | 588 | /* set CA2 */ |
| 564 | | v->out_ca2 = 0; |
| 589 | m_out_ca2 = 0; |
| 565 | 590 | |
| 566 | 591 | /* call the CA2 output function */ |
| 567 | | devcb_call_write_line(&v->out_ca2_func, 0); |
| 592 | devcb_call_write_line(&m_out_ca2_func, 0); |
| 568 | 593 | } |
| 569 | 594 | } |
| 570 | 595 | |
| r8892 | r8893 | |
| 572 | 597 | |
| 573 | 598 | case VIA_PANH: |
| 574 | 599 | /* update the input */ |
| 575 | | if (PA_LATCH_ENABLE(v->acr) == 0) |
| 600 | if (PA_LATCH_ENABLE(m_acr) == 0) |
| 576 | 601 | { |
| 577 | | if (v->in_a_func.read != NULL) |
| 578 | | v->in_a = devcb_call_read8(&v->in_a_func, 0); |
| 602 | if (m_in_a_func.read != NULL) |
| 603 | { |
| 604 | m_in_a = devcb_call_read8(&m_in_a_func, 0); |
| 605 | } |
| 579 | 606 | else |
| 580 | | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 607 | { |
| 608 | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 609 | } |
| 581 | 610 | } |
| 582 | 611 | |
| 583 | 612 | /* combine input and output values */ |
| 584 | | val = (v->out_a & v->ddr_a) + (v->in_a & ~v->ddr_a); |
| 613 | val = (m_out_a & m_ddr_a) + (m_in_a & ~m_ddr_a); |
| 585 | 614 | break; |
| 586 | 615 | |
| 587 | 616 | case VIA_DDRB: |
| 588 | | val = v->ddr_b; |
| 617 | val = m_ddr_b; |
| 589 | 618 | break; |
| 590 | 619 | |
| 591 | 620 | case VIA_DDRA: |
| 592 | | val = v->ddr_a; |
| 621 | val = m_ddr_a; |
| 593 | 622 | break; |
| 594 | 623 | |
| 595 | 624 | case VIA_T1CL: |
| 596 | | via_clear_int (device, INT_T1); |
| 597 | | val = v_get_counter1_value(device) & 0xFF; |
| 625 | clear_int(INT_T1); |
| 626 | val = get_counter1_value() & 0xFF; |
| 598 | 627 | break; |
| 599 | 628 | |
| 600 | 629 | case VIA_T1CH: |
| 601 | | val = v_get_counter1_value(device) >> 8; |
| 630 | val = get_counter1_value() >> 8; |
| 602 | 631 | break; |
| 603 | 632 | |
| 604 | 633 | case VIA_T1LL: |
| 605 | | val = v->t1ll; |
| 634 | val = m_t1ll; |
| 606 | 635 | break; |
| 607 | 636 | |
| 608 | 637 | case VIA_T1LH: |
| 609 | | val = v->t1lh; |
| 638 | val = m_t1lh; |
| 610 | 639 | break; |
| 611 | 640 | |
| 612 | 641 | 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; |
| 642 | clear_int(INT_T2); |
| 643 | if (m_t2_active) |
| 644 | { |
| 645 | val = time_to_cycles(timer_timeleft(m_t2)) & 0xff; |
| 646 | } |
| 616 | 647 | else |
| 617 | 648 | { |
| 618 | | if (T2_COUNT_PB6(v->acr)) |
| 619 | | val = v->t2cl; |
| 649 | if (T2_COUNT_PB6(m_acr)) |
| 650 | { |
| 651 | val = m_t2cl; |
| 652 | } |
| 620 | 653 | else |
| 621 | | val = (0x10000- (v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time2)) & 0xffff) - 1) & 0xff; |
| 654 | { |
| 655 | val = (0x10000 - (time_to_cycles(attotime_sub(timer_get_time(&m_machine), m_time2)) & 0xffff) - 1) & 0xff; |
| 656 | } |
| 622 | 657 | } |
| 623 | 658 | break; |
| 624 | 659 | |
| 625 | 660 | case VIA_T2CH: |
| 626 | | if (v->t2_active) |
| 627 | | val = v_time_to_cycles(device, timer_timeleft(v->t2)) >> 8; |
| 661 | if (m_t2_active) |
| 662 | { |
| 663 | val = time_to_cycles(timer_timeleft(m_t2)) >> 8; |
| 664 | } |
| 628 | 665 | else |
| 629 | 666 | { |
| 630 | | if (T2_COUNT_PB6(v->acr)) |
| 631 | | val = v->t2ch; |
| 667 | if (T2_COUNT_PB6(m_acr)) |
| 668 | { |
| 669 | val = m_t2ch; |
| 670 | } |
| 632 | 671 | else |
| 633 | | val = (0x10000- (v_time_to_cycles(device, attotime_sub(timer_get_time(device->machine), v->time2)) & 0xffff) - 1) >> 8; |
| 672 | { |
| 673 | val = (0x10000 - (time_to_cycles(attotime_sub(timer_get_time(&m_machine), m_time2)) & 0xffff) - 1) >> 8; |
| 674 | } |
| 634 | 675 | } |
| 635 | 676 | break; |
| 636 | 677 | |
| 637 | 678 | case VIA_SR: |
| 638 | | val = v->sr; |
| 639 | | via_clear_int(device, INT_SR); |
| 640 | | if (SO_O2_CONTROL(v->acr)) |
| 679 | val = m_sr; |
| 680 | clear_int(INT_SR); |
| 681 | if (SO_O2_CONTROL(m_acr)) |
| 641 | 682 | { |
| 642 | | v->shift_counter=0; |
| 643 | | timer_adjust_oneshot(v->shift_timer, v_cycles_to_time(device, 2), 0); |
| 683 | m_shift_counter=0; |
| 684 | timer_adjust_oneshot(m_shift_timer, cycles_to_time(2), 0); |
| 644 | 685 | } |
| 645 | 686 | break; |
| 646 | 687 | |
| 647 | 688 | case VIA_PCR: |
| 648 | | val = v->pcr; |
| 689 | val = m_pcr; |
| 649 | 690 | break; |
| 650 | 691 | |
| 651 | 692 | case VIA_ACR: |
| 652 | | val = v->acr; |
| 693 | val = m_acr; |
| 653 | 694 | break; |
| 654 | 695 | |
| 655 | 696 | case VIA_IER: |
| 656 | | val = v->ier | 0x80; |
| 697 | val = m_ier | 0x80; |
| 657 | 698 | break; |
| 658 | 699 | |
| 659 | 700 | case VIA_IFR: |
| 660 | | val = v->ifr; |
| 701 | val = m_ifr; |
| 661 | 702 | break; |
| 662 | 703 | } |
| 663 | 704 | return val; |
| r8892 | r8893 | |
| 668 | 709 | via_w - CPU interface for VIA write |
| 669 | 710 | -------------------------------------------------*/ |
| 670 | 711 | |
| 671 | | WRITE8_DEVICE_HANDLER(via_w) |
| 712 | void via6522_device::reg_w(UINT8 offset, UINT8 data) |
| 672 | 713 | { |
| 673 | | via6522_t *v = get_token(device); |
| 674 | | |
| 675 | 714 | offset &=0x0f; |
| 676 | 715 | |
| 677 | 716 | switch (offset) |
| 678 | 717 | { |
| 679 | 718 | case VIA_PB: |
| 680 | | if (T1_SET_PB7(v->acr)) |
| 681 | | v->out_b = (v->out_b & 0x80) | (data & 0x7f); |
| 719 | if (T1_SET_PB7(m_acr)) |
| 720 | m_out_b = (m_out_b & 0x80) | (data & 0x7f); |
| 682 | 721 | else |
| 683 | | v->out_b = data; |
| 722 | m_out_b = data; |
| 684 | 723 | |
| 685 | | if (v->ddr_b) |
| 724 | if (m_ddr_b) |
| 686 | 725 | { |
| 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); |
| 726 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 727 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 689 | 728 | } |
| 690 | 729 | |
| 691 | | CLR_PB_INT(device); |
| 730 | CLR_PB_INT(); |
| 692 | 731 | |
| 693 | 732 | /* If CB2 is configured as output and in pulse or handshake mode, |
| 694 | 733 | CB2 is set now */ |
| 695 | | if (CB2_AUTO_HS(v->pcr)) |
| 734 | if (CB2_AUTO_HS(m_pcr)) |
| 696 | 735 | { |
| 697 | | if (v->out_cb2) |
| 736 | if (m_out_cb2) |
| 698 | 737 | { |
| 699 | 738 | /* set CB2 */ |
| 700 | | v->out_cb2 = 0; |
| 739 | m_out_cb2 = 0; |
| 701 | 740 | |
| 702 | 741 | /* call the CB2 output function */ |
| 703 | | devcb_call_write_line(&v->out_cb2_func, 0); |
| 742 | devcb_call_write_line(&m_out_cb2_func, 0); |
| 704 | 743 | } |
| 705 | 744 | } |
| 706 | 745 | break; |
| 707 | 746 | |
| 708 | 747 | case VIA_PA: |
| 709 | | v->out_a = data; |
| 748 | m_out_a = data; |
| 710 | 749 | |
| 711 | | if (v->ddr_a) |
| 750 | if (m_ddr_a) |
| 712 | 751 | { |
| 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); |
| 752 | UINT8 write_data = (m_out_a & m_ddr_a) | (m_ddr_a ^ 0xff); |
| 753 | devcb_call_write8(&m_out_a_func, 0, write_data); |
| 715 | 754 | } |
| 716 | 755 | |
| 717 | | CLR_PA_INT(device); |
| 756 | CLR_PA_INT(); |
| 718 | 757 | |
| 719 | 758 | /* If CA2 is configured as output and in pulse or handshake mode, |
| 720 | 759 | CA2 is set now */ |
| 721 | | if (CA2_PULSE_OUTPUT(v->pcr)) |
| 760 | if (CA2_PULSE_OUTPUT(m_pcr)) |
| 722 | 761 | { |
| 723 | 762 | /* 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); |
| 763 | devcb_call_write_line(&m_out_ca2_func, 0); |
| 764 | devcb_call_write_line(&m_out_ca2_func, 1); |
| 726 | 765 | |
| 727 | 766 | /* set CA2 (shouldn't be needed) */ |
| 728 | | v->out_ca2 = 1; |
| 767 | m_out_ca2 = 1; |
| 729 | 768 | } |
| 730 | | else if (CA2_AUTO_HS(v->pcr)) |
| 769 | else if (CA2_AUTO_HS(m_pcr)) |
| 731 | 770 | { |
| 732 | | if (v->out_ca2) |
| 771 | if (m_out_ca2) |
| 733 | 772 | { |
| 734 | 773 | /* set CA2 */ |
| 735 | | v->out_ca2 = 0; |
| 774 | m_out_ca2 = 0; |
| 736 | 775 | |
| 737 | 776 | /* call the CA2 output function */ |
| 738 | | devcb_call_write_line(&v->out_ca2_func, 0); |
| 777 | devcb_call_write_line(&m_out_ca2_func, 0); |
| 739 | 778 | } |
| 740 | 779 | } |
| 741 | 780 | |
| 742 | 781 | break; |
| 743 | 782 | |
| 744 | 783 | case VIA_PANH: |
| 745 | | v->out_a = data; |
| 784 | m_out_a = data; |
| 746 | 785 | |
| 747 | | if (v->ddr_a) |
| 786 | if (m_ddr_a) |
| 748 | 787 | { |
| 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); |
| 788 | UINT8 write_data = (m_out_a & m_ddr_a) | (m_ddr_a ^ 0xff); |
| 789 | devcb_call_write8(&m_out_a_func, 0, write_data); |
| 751 | 790 | } |
| 752 | 791 | |
| 753 | 792 | break; |
| 754 | 793 | |
| 755 | 794 | case VIA_DDRB: |
| 756 | 795 | /* EHC 03/04/2000 - If data direction changed, present output on the lines */ |
| 757 | | if ( data != v->ddr_b ) |
| 796 | if ( data != m_ddr_b ) |
| 758 | 797 | { |
| 759 | | v->ddr_b = data; |
| 798 | m_ddr_b = data; |
| 760 | 799 | |
| 761 | | //if (v->ddr_b) |
| 800 | //if (m_ddr_b) |
| 762 | 801 | { |
| 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); |
| 802 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 803 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 765 | 804 | } |
| 766 | 805 | } |
| 767 | 806 | break; |
| 768 | 807 | |
| 769 | 808 | case VIA_DDRA: |
| 770 | 809 | /* EHC 03/04/2000 - If data direction changed, present output on the lines */ |
| 771 | | if ( data != v->ddr_a ) |
| 810 | if ( data != m_ddr_a ) |
| 772 | 811 | { |
| 773 | | v->ddr_a = data; |
| 812 | m_ddr_a = data; |
| 774 | 813 | |
| 775 | | //if (v->ddr_a) |
| 814 | //if (m_ddr_a) |
| 776 | 815 | { |
| 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); |
| 816 | UINT8 write_data = (m_out_a & m_ddr_a) | (m_ddr_a ^ 0xff); |
| 817 | devcb_call_write8(&m_out_a_func, 0, write_data); |
| 779 | 818 | } |
| 780 | 819 | } |
| 781 | 820 | break; |
| 782 | 821 | |
| 783 | 822 | case VIA_T1CL: |
| 784 | 823 | case VIA_T1LL: |
| 785 | | v->t1ll = data; |
| 824 | m_t1ll = data; |
| 786 | 825 | break; |
| 787 | 826 | |
| 788 | 827 | case VIA_T1LH: |
| 789 | | v->t1lh = data; |
| 790 | | via_clear_int (device, INT_T1); |
| 828 | m_t1lh = data; |
| 829 | clear_int(INT_T1); |
| 791 | 830 | break; |
| 792 | 831 | |
| 793 | 832 | case VIA_T1CH: |
| 794 | | v->t1ch = v->t1lh = data; |
| 795 | | v->t1cl = v->t1ll; |
| 833 | m_t1ch = m_t1lh = data; |
| 834 | m_t1cl = m_t1ll; |
| 796 | 835 | |
| 797 | | via_clear_int (device, INT_T1); |
| 836 | clear_int(INT_T1); |
| 798 | 837 | |
| 799 | | if (T1_SET_PB7(v->acr)) |
| 838 | if (T1_SET_PB7(m_acr)) |
| 800 | 839 | { |
| 801 | | v->out_b &= 0x7f; |
| 840 | m_out_b &= 0x7f; |
| 802 | 841 | |
| 803 | | //if (v->ddr_b) |
| 842 | //if (m_ddr_b) |
| 804 | 843 | { |
| 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); |
| 844 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 845 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 807 | 846 | } |
| 808 | 847 | } |
| 809 | | timer_adjust_oneshot(v->t1, v_cycles_to_time(device, TIMER1_VALUE(v) + IFR_DELAY), 0); |
| 810 | | v->t1_active = 1; |
| 848 | timer_adjust_oneshot(m_t1, cycles_to_time(TIMER1_VALUE + IFR_DELAY), 0); |
| 849 | m_t1_active = 1; |
| 811 | 850 | break; |
| 812 | 851 | |
| 813 | 852 | case VIA_T2CL: |
| 814 | | v->t2ll = data; |
| 853 | m_t2ll = data; |
| 815 | 854 | break; |
| 816 | 855 | |
| 817 | 856 | case VIA_T2CH: |
| 818 | | v->t2ch = v->t2lh = data; |
| 819 | | v->t2cl = v->t2ll; |
| 857 | m_t2ch = m_t2lh = data; |
| 858 | m_t2cl = m_t2ll; |
| 820 | 859 | |
| 821 | | via_clear_int (device, INT_T2); |
| 860 | clear_int(INT_T2); |
| 822 | 861 | |
| 823 | | if (!T2_COUNT_PB6(v->acr)) |
| 862 | if (!T2_COUNT_PB6(m_acr)) |
| 824 | 863 | { |
| 825 | | timer_adjust_oneshot(v->t2, v_cycles_to_time(device, TIMER2_VALUE(v) + IFR_DELAY), 0); |
| 826 | | v->t2_active = 1; |
| 864 | timer_adjust_oneshot(m_t2, cycles_to_time(TIMER2_VALUE + IFR_DELAY), 0); |
| 865 | m_t2_active = 1; |
| 827 | 866 | } |
| 828 | 867 | else |
| 829 | 868 | { |
| 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); |
| 869 | timer_adjust_oneshot(m_t2, cycles_to_time(TIMER2_VALUE), 0); |
| 870 | m_t2_active = 1; |
| 871 | m_time2 = timer_get_time(&m_machine); |
| 833 | 872 | } |
| 834 | 873 | break; |
| 835 | 874 | |
| 836 | 875 | 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)) |
| 876 | m_sr = data; |
| 877 | m_shift_counter=0; |
| 878 | clear_int(INT_SR); |
| 879 | if (SO_O2_CONTROL(m_acr)) |
| 841 | 880 | { |
| 842 | | timer_set(device->machine, v_cycles_to_time(device, 2), (void *) device, 0, via_shift_callback); |
| 881 | timer_set(&m_machine, cycles_to_time(2), (void *)this, 0, shift_callback); |
| 843 | 882 | } |
| 844 | 883 | break; |
| 845 | 884 | |
| 846 | 885 | case VIA_PCR: |
| 847 | | v->pcr = data; |
| 886 | m_pcr = data; |
| 848 | 887 | |
| 849 | 888 | if (TRACE_VIA) |
| 850 | | logerror("%s:6522VIA chip %s: PCR = %02X\n", cpuexec_describe_context(device->machine), device->tag(), data); |
| 889 | { |
| 890 | logerror("%s:6522VIA chip %s: PCR = %02X\n", cpuexec_describe_context(&m_machine), tag(), data); |
| 891 | } |
| 851 | 892 | |
| 852 | | if (CA2_FIX_OUTPUT(data) && CA2_OUTPUT_LEVEL(data) ^ v->out_ca2) |
| 893 | if (CA2_FIX_OUTPUT(data) && CA2_OUTPUT_LEVEL(data) ^ m_out_ca2) |
| 853 | 894 | { |
| 854 | | v->out_ca2 = CA2_OUTPUT_LEVEL(data); |
| 855 | | devcb_call_write_line(&v->out_ca2_func, v->out_ca2); |
| 895 | m_out_ca2 = CA2_OUTPUT_LEVEL(data); |
| 896 | devcb_call_write_line(&m_out_ca2_func, m_out_ca2); |
| 856 | 897 | } |
| 857 | 898 | |
| 858 | | if (CB2_FIX_OUTPUT(data) && CB2_OUTPUT_LEVEL(data) ^ v->out_cb2) |
| 899 | if (CB2_FIX_OUTPUT(data) && CB2_OUTPUT_LEVEL(data) ^ m_out_cb2) |
| 859 | 900 | { |
| 860 | | v->out_cb2 = CB2_OUTPUT_LEVEL(data); |
| 861 | | devcb_call_write_line(&v->out_cb2_func, v->out_cb2); |
| 901 | m_out_cb2 = CB2_OUTPUT_LEVEL(data); |
| 902 | devcb_call_write_line(&m_out_cb2_func, m_out_cb2); |
| 862 | 903 | } |
| 863 | 904 | break; |
| 864 | 905 | |
| 865 | 906 | case VIA_ACR: |
| 866 | 907 | { |
| 867 | | UINT16 counter1 = v_get_counter1_value(device); |
| 868 | | v->acr = data; |
| 869 | | if (T1_SET_PB7(v->acr)) |
| 908 | UINT16 counter1 = get_counter1_value(); |
| 909 | m_acr = data; |
| 910 | if (T1_SET_PB7(m_acr)) |
| 870 | 911 | { |
| 871 | | if (v->t1_active) |
| 872 | | v->out_b &= ~0x80; |
| 912 | if (m_t1_active) |
| 913 | { |
| 914 | m_out_b &= ~0x80; |
| 915 | } |
| 873 | 916 | else |
| 874 | | v->out_b |= 0x80; |
| 917 | { |
| 918 | m_out_b |= 0x80; |
| 919 | } |
| 875 | 920 | |
| 876 | | //if (v->ddr_b) |
| 921 | //if (m_ddr_b) |
| 877 | 922 | { |
| 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); |
| 923 | UINT8 write_data = (m_out_b & m_ddr_b) | (m_ddr_b ^ 0xff); |
| 924 | devcb_call_write8(&m_out_b_func, 0, write_data); |
| 880 | 925 | } |
| 881 | 926 | } |
| 882 | 927 | if (T1_CONTINUOUS(data)) |
| 883 | 928 | { |
| 884 | | timer_adjust_oneshot(v->t1, v_cycles_to_time(device, counter1 + IFR_DELAY), 0); |
| 885 | | v->t1_active = 1; |
| 929 | timer_adjust_oneshot(m_t1, cycles_to_time(counter1 + IFR_DELAY), 0); |
| 930 | m_t1_active = 1; |
| 886 | 931 | } |
| 887 | 932 | } |
| 888 | 933 | break; |
| 889 | 934 | |
| 890 | 935 | case VIA_IER: |
| 891 | 936 | if (data & 0x80) |
| 892 | | v->ier |= data & 0x7f; |
| 937 | { |
| 938 | m_ier |= data & 0x7f; |
| 939 | } |
| 893 | 940 | else |
| 894 | | v->ier &= ~(data & 0x7f); |
| 941 | { |
| 942 | m_ier &= ~(data & 0x7f); |
| 943 | } |
| 895 | 944 | |
| 896 | | if (v->ifr & INT_ANY) |
| 945 | if (m_ifr & INT_ANY) |
| 897 | 946 | { |
| 898 | | if (((v->ifr & v->ier) & 0x7f) == 0) |
| 947 | if (((m_ifr & m_ier) & 0x7f) == 0) |
| 899 | 948 | { |
| 900 | | v->ifr &= ~INT_ANY; |
| 901 | | devcb_call_write_line(&v->irq_func, CLEAR_LINE); |
| 949 | m_ifr &= ~INT_ANY; |
| 950 | devcb_call_write_line(&m_irq_func, CLEAR_LINE); |
| 902 | 951 | } |
| 903 | 952 | } |
| 904 | 953 | else |
| 905 | 954 | { |
| 906 | | if ((v->ier & v->ifr) & 0x7f) |
| 955 | if ((m_ier & m_ifr) & 0x7f) |
| 907 | 956 | { |
| 908 | | v->ifr |= INT_ANY; |
| 909 | | devcb_call_write_line(&v->irq_func, ASSERT_LINE); |
| 957 | m_ifr |= INT_ANY; |
| 958 | devcb_call_write_line(&m_irq_func, ASSERT_LINE); |
| 910 | 959 | } |
| 911 | 960 | } |
| 912 | 961 | break; |
| 913 | 962 | |
| 914 | 963 | case VIA_IFR: |
| 915 | 964 | if (data & INT_ANY) |
| 965 | { |
| 916 | 966 | data = 0x7f; |
| 917 | | via_clear_int (device, data); |
| 967 | } |
| 968 | clear_int(data); |
| 918 | 969 | break; |
| 919 | 970 | } |
| 920 | 971 | } |
| 921 | 972 | |
| 922 | 973 | |
| 923 | 974 | /*------------------------------------------------- |
| 924 | | via_porta_w - interface setting VIA port |
| 925 | | A input |
| 975 | ca1_w - interface setting VIA port CA1 input |
| 926 | 976 | -------------------------------------------------*/ |
| 927 | 977 | |
| 928 | | WRITE8_DEVICE_HANDLER(via_porta_w) |
| 978 | void via6522_device::ca1_w(UINT8 state) |
| 929 | 979 | { |
| 930 | | via6522_t *v = get_token(device); |
| 931 | | |
| 932 | | /* set the input, what could be easier? */ |
| 933 | | v->in_a = data; |
| 934 | | } |
| 935 | | |
| 936 | | |
| 937 | | /*------------------------------------------------- |
| 938 | | via_ca1_r - interface retrieving VIA port |
| 939 | | CA1 input |
| 940 | | -------------------------------------------------*/ |
| 941 | | |
| 942 | | READ_LINE_DEVICE_HANDLER(via_ca1_r) |
| 943 | | { |
| 944 | | via6522_t *v = get_token(device); |
| 945 | | return v->in_ca1; |
| 946 | | } |
| 947 | | |
| 948 | | |
| 949 | | /*------------------------------------------------- |
| 950 | | via_ca1_w - interface setting VIA port |
| 951 | | CA1 input |
| 952 | | -------------------------------------------------*/ |
| 953 | | |
| 954 | | WRITE_LINE_DEVICE_HANDLER(via_ca1_w) |
| 955 | | { |
| 956 | | via6522_t *v = get_token(device); |
| 957 | | |
| 958 | 980 | /* handle the active transition */ |
| 959 | | if (state != v->in_ca1) |
| 981 | if (state != m_in_ca1) |
| 960 | 982 | { |
| 961 | 983 | if (TRACE_VIA) |
| 962 | | logerror("%s:6522VIA chip %s: CA1 = %02X\n", cpuexec_describe_context(device->machine), device->tag(), state); |
| 984 | logerror("%s:6522VIA chip %s: CA1 = %02X\n", cpuexec_describe_context(&m_machine), tag(), state); |
| 963 | 985 | |
| 964 | | if ((CA1_LOW_TO_HIGH(v->pcr) && state) || (CA1_HIGH_TO_LOW(v->pcr) && !state)) |
| 986 | if ((CA1_LOW_TO_HIGH(m_pcr) && state) || (CA1_HIGH_TO_LOW(m_pcr) && !state)) |
| 965 | 987 | { |
| 966 | | if (PA_LATCH_ENABLE(v->acr)) |
| 988 | if (PA_LATCH_ENABLE(m_acr)) |
| 967 | 989 | { |
| 968 | | if (v->in_a_func.read != NULL) |
| 969 | | v->in_a = devcb_call_read8(&v->in_a_func, 0); |
| 990 | if (m_in_a_func.read != NULL) |
| 991 | { |
| 992 | m_in_a = devcb_call_read8(&m_in_a_func, 0); |
| 993 | } |
| 970 | 994 | else |
| 971 | | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 995 | { |
| 996 | logerror("%s:6522VIA chip %s: Port A is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 997 | } |
| 972 | 998 | } |
| 973 | 999 | |
| 974 | | via_set_int (device, INT_CA1); |
| 1000 | set_int(INT_CA1); |
| 975 | 1001 | |
| 976 | 1002 | /* CA2 is configured as output and in pulse or handshake mode, |
| 977 | 1003 | CA2 is cleared now */ |
| 978 | | if (CA2_AUTO_HS(v->pcr)) |
| 1004 | if (CA2_AUTO_HS(m_pcr)) |
| 979 | 1005 | { |
| 980 | | if (!v->out_ca2) |
| 1006 | if (!m_out_ca2) |
| 981 | 1007 | { |
| 982 | 1008 | /* clear CA2 */ |
| 983 | | v->out_ca2 = 1; |
| 1009 | m_out_ca2 = 1; |
| 984 | 1010 | |
| 985 | 1011 | /* call the CA2 output function */ |
| 986 | | devcb_call_write_line(&v->out_ca2_func, 1); |
| 1012 | devcb_call_write_line(&m_out_ca2_func, 1); |
| 987 | 1013 | } |
| 988 | 1014 | } |
| 989 | 1015 | } |
| 990 | 1016 | |
| 991 | | v->in_ca1 = state; |
| 1017 | m_in_ca1 = state; |
| 992 | 1018 | } |
| 993 | 1019 | } |
| 994 | 1020 | |
| 995 | 1021 | |
| 996 | 1022 | /*------------------------------------------------- |
| 997 | | via_ca2_r - interface retrieving VIA port |
| 998 | | CA2 input |
| 1023 | ca2_w - interface setting VIA port CA2 input |
| 999 | 1024 | -------------------------------------------------*/ |
| 1000 | 1025 | |
| 1001 | | READ_LINE_DEVICE_HANDLER(via_ca2_r) |
| 1026 | void via6522_device::ca2_w(UINT8 state) |
| 1002 | 1027 | { |
| 1003 | | via6522_t *v = get_token(device); |
| 1004 | | return v->in_ca2; |
| 1005 | | } |
| 1006 | | |
| 1007 | | |
| 1008 | | /*------------------------------------------------- |
| 1009 | | via_ca2_w - interface setting VIA port |
| 1010 | | CA2 input |
| 1011 | | -------------------------------------------------*/ |
| 1012 | | |
| 1013 | | WRITE_LINE_DEVICE_HANDLER(via_ca2_w) |
| 1014 | | { |
| 1015 | | via6522_t *v = get_token(device); |
| 1016 | | |
| 1017 | 1028 | /* CA2 is in input mode */ |
| 1018 | | if (CA2_INPUT(v->pcr)) |
| 1029 | if (CA2_INPUT(m_pcr)) |
| 1019 | 1030 | { |
| 1020 | 1031 | /* the new state has caused a transition */ |
| 1021 | | if (v->in_ca2 != state) |
| 1032 | if (m_in_ca2 != state) |
| 1022 | 1033 | { |
| 1023 | 1034 | /* handle the active transition */ |
| 1024 | | if ((state && CA2_LOW_TO_HIGH(v->pcr)) || (!state && CA2_HIGH_TO_LOW(v->pcr))) |
| 1035 | if ((state && CA2_LOW_TO_HIGH(m_pcr)) || (!state && CA2_HIGH_TO_LOW(m_pcr))) |
| 1025 | 1036 | { |
| 1026 | 1037 | /* mark the IRQ */ |
| 1027 | | via_set_int (device, INT_CA2); |
| 1038 | set_int(INT_CA2); |
| 1028 | 1039 | } |
| 1029 | 1040 | /* set the new value for CA2 */ |
| 1030 | | v->in_ca2 = state; |
| 1041 | m_in_ca2 = state; |
| 1031 | 1042 | } |
| 1032 | 1043 | } |
| 1033 | | |
| 1034 | | |
| 1035 | 1044 | } |
| 1036 | 1045 | |
| 1037 | 1046 | |
| 1038 | 1047 | /*------------------------------------------------- |
| 1039 | | via_portb_r - interface retrieving VIA port |
| 1040 | | B input |
| 1048 | cb1_w - interface setting VIA port CB1 input |
| 1041 | 1049 | -------------------------------------------------*/ |
| 1042 | 1050 | |
| 1043 | | READ8_DEVICE_HANDLER(via_portb_r) |
| 1051 | void via6522_device::cb1_w(UINT8 state) |
| 1044 | 1052 | { |
| 1045 | | via6522_t *v = get_token(device); |
| 1046 | | return v->in_b; |
| 1047 | | } |
| 1048 | | |
| 1049 | | |
| 1050 | | /*------------------------------------------------- |
| 1051 | | via_portb_w - interface setting VIA port |
| 1052 | | B input |
| 1053 | | -------------------------------------------------*/ |
| 1054 | | |
| 1055 | | WRITE8_DEVICE_HANDLER(via_portb_w) |
| 1056 | | { |
| 1057 | | via6522_t *v = get_token(device); |
| 1058 | | |
| 1059 | | /* set the input, what could be easier? */ |
| 1060 | | v->in_b = data; |
| 1061 | | } |
| 1062 | | |
| 1063 | | |
| 1064 | | /*------------------------------------------------- |
| 1065 | | via_cb1_r - interface retrieving VIA port |
| 1066 | | CB1 input |
| 1067 | | -------------------------------------------------*/ |
| 1068 | | |
| 1069 | | READ_LINE_DEVICE_HANDLER(via_cb1_r) |
| 1070 | | { |
| 1071 | | via6522_t *v = get_token(device); |
| 1072 | | return v->in_cb1; |
| 1073 | | } |
| 1074 | | |
| 1075 | | |
| 1076 | | /*------------------------------------------------- |
| 1077 | | via_cb1_w - interface setting VIA port |
| 1078 | | CB1 input |
| 1079 | | -------------------------------------------------*/ |
| 1080 | | |
| 1081 | | WRITE_LINE_DEVICE_HANDLER(via_cb1_w) |
| 1082 | | { |
| 1083 | | via6522_t *v = get_token(device); |
| 1084 | | |
| 1085 | 1053 | /* handle the active transition */ |
| 1086 | | if (state != v->in_cb1) |
| 1054 | if (state != m_in_cb1) |
| 1087 | 1055 | { |
| 1088 | | if ((CB1_LOW_TO_HIGH(v->pcr) && state) || (CB1_HIGH_TO_LOW(v->pcr) && !state)) |
| 1056 | if ((CB1_LOW_TO_HIGH(m_pcr) && state) || (CB1_HIGH_TO_LOW(m_pcr) && !state)) |
| 1089 | 1057 | { |
| 1090 | | if (PB_LATCH_ENABLE(v->acr)) |
| 1058 | if (PB_LATCH_ENABLE(m_acr)) |
| 1091 | 1059 | { |
| 1092 | | if (v->in_b_func.read != NULL) |
| 1093 | | v->in_b = devcb_call_read8(&v->in_b_func, 0); |
| 1060 | if (m_in_b_func.read != NULL) |
| 1061 | { |
| 1062 | m_in_b = devcb_call_read8(&m_in_b_func, 0); |
| 1063 | } |
| 1094 | 1064 | else |
| 1095 | | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag()); |
| 1065 | { |
| 1066 | logerror("%s:6522VIA chip %s: Port B is being read but has no handler\n", cpuexec_describe_context(&m_machine), tag()); |
| 1067 | } |
| 1096 | 1068 | } |
| 1097 | | if (SO_EXT_CONTROL(v->acr) || SI_EXT_CONTROL(v->acr)) |
| 1098 | | via_shift (device); |
| 1069 | if (SO_EXT_CONTROL(m_acr) || SI_EXT_CONTROL(m_acr)) |
| 1070 | { |
| 1071 | shift(); |
| 1072 | } |
| 1099 | 1073 | |
| 1100 | | via_set_int (device, INT_CB1); |
| 1074 | set_int(INT_CB1); |
| 1101 | 1075 | |
| 1102 | 1076 | /* CB2 is configured as output and in pulse or handshake mode, |
| 1103 | 1077 | CB2 is cleared now */ |
| 1104 | | if (CB2_AUTO_HS(v->pcr)) |
| 1078 | if (CB2_AUTO_HS(m_pcr)) |
| 1105 | 1079 | { |
| 1106 | | if (!v->out_cb2) |
| 1080 | if (!m_out_cb2) |
| 1107 | 1081 | { |
| 1108 | 1082 | /* clear CB2 */ |
| 1109 | | v->out_cb2 = 1; |
| 1083 | m_out_cb2 = 1; |
| 1110 | 1084 | |
| 1111 | 1085 | /* call the CB2 output function */ |
| 1112 | | devcb_call_write_line(&v->out_cb2_func, 1); |
| 1086 | devcb_call_write_line(&m_out_cb2_func, 1); |
| 1113 | 1087 | } |
| 1114 | 1088 | } |
| 1115 | 1089 | } |
| 1116 | | v->in_cb1 = state; |
| 1090 | m_in_cb1 = state; |
| 1117 | 1091 | } |
| 1118 | 1092 | } |
| 1119 | 1093 | |
| 1120 | 1094 | |
| 1121 | 1095 | /*------------------------------------------------- |
| 1122 | | via_cb2_r - interface retrieving VIA port |
| 1123 | | CB2 input |
| 1096 | cb2_w - interface setting VIA port CB2 input |
| 1124 | 1097 | -------------------------------------------------*/ |
| 1125 | 1098 | |
| 1126 | | READ_LINE_DEVICE_HANDLER(via_cb2_r) |
| 1099 | void via6522_device::cb2_w(UINT8 state) |
| 1127 | 1100 | { |
| 1128 | | via6522_t *v = get_token(device); |
| 1129 | | return v->in_cb2; |
| 1130 | | } |
| 1131 | | |
| 1132 | | |
| 1133 | | /*------------------------------------------------- |
| 1134 | | via_cb2_w - interface setting VIA port |
| 1135 | | CB2 input |
| 1136 | | -------------------------------------------------*/ |
| 1137 | | |
| 1138 | | WRITE_LINE_DEVICE_HANDLER(via_cb2_w) |
| 1139 | | { |
| 1140 | | via6522_t *v = get_token(device); |
| 1141 | | |
| 1142 | 1101 | /* CB2 is in input mode */ |
| 1143 | | if (CB2_INPUT(v->pcr)) |
| 1102 | if (CB2_INPUT(m_pcr)) |
| 1144 | 1103 | { |
| 1145 | 1104 | /* the new state has caused a transition */ |
| 1146 | | if (v->in_cb2 != state) |
| 1105 | if (m_in_cb2 != state) |
| 1147 | 1106 | { |
| 1148 | 1107 | /* handle the active transition */ |
| 1149 | | if ((state && CB2_LOW_TO_HIGH(v->pcr)) || (!state && CB2_HIGH_TO_LOW(v->pcr))) |
| 1108 | if ((state && CB2_LOW_TO_HIGH(m_pcr)) || (!state && CB2_HIGH_TO_LOW(m_pcr))) |
| 1150 | 1109 | { |
| 1151 | 1110 | /* mark the IRQ */ |
| 1152 | | via_set_int (device, INT_CB2); |
| 1111 | set_int(INT_CB2); |
| 1153 | 1112 | } |
| 1154 | 1113 | /* set the new value for CB2 */ |
| 1155 | | v->in_cb2 = state; |
| 1114 | m_in_cb2 = state; |
| 1156 | 1115 | } |
| 1157 | 1116 | } |
| 1158 | 1117 | } |
| 1159 | 1118 | |
| 1160 | 1119 | |
| 1161 | | /*------------------------------------------------- |
| 1162 | | DEVICE_GET_INFO( via6522 ) |
| 1163 | | -------------------------------------------------*/ |
| 1164 | 1120 | |
| 1165 | | DEVICE_GET_INFO(via6522) |
| 1166 | | { |
| 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; |
| 1121 | /*************************************************************************** |
| 1122 | TRAMPOLINES |
| 1123 | ***************************************************************************/ |
| 1172 | 1124 | |
| 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; |
| 1125 | READ8_DEVICE_HANDLER(via_r) { return downcast<via6522_device *>(device)->reg_r(offset); } |
| 1126 | WRITE8_DEVICE_HANDLER(via_w) { downcast<via6522_device *>(device)->reg_w(offset, data); } |
| 1177 | 1127 | |
| 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 | | } |
| 1185 | | } |
| 1128 | READ_LINE_DEVICE_HANDLER(via_ca1_r) { return downcast<via6522_device *>(device)->ca1_r(); } |
| 1129 | WRITE_LINE_DEVICE_HANDLER(via_ca1_w) { downcast<via6522_device *>(device)->ca1_w(state); } |
| 1186 | 1130 | |
| 1131 | READ_LINE_DEVICE_HANDLER(via_ca2_r) { return downcast<via6522_device *>(device)->ca2_r(); } |
| 1132 | WRITE_LINE_DEVICE_HANDLER(via_ca2_w) { downcast<via6522_device *>(device)->ca2_w(state); } |
| 1187 | 1133 | |
| 1188 | | DEFINE_LEGACY_DEVICE(VIA6522, via6522); |
| 1134 | READ_LINE_DEVICE_HANDLER(via_cb1_r) { return downcast<via6522_device *>(device)->cb1_r(); } |
| 1135 | WRITE_LINE_DEVICE_HANDLER(via_cb1_w) { downcast<via6522_device *>(device)->cb1_w(state); } |
| 1136 | |
| 1137 | READ_LINE_DEVICE_HANDLER(via_cb2_r) { return downcast<via6522_device *>(device)->cb2_r(); } |
| 1138 | WRITE_LINE_DEVICE_HANDLER(via_cb2_w) { downcast<via6522_device *>(device)->cb2_w(state); } |
| 1139 | |
| 1140 | WRITE8_DEVICE_HANDLER(via_porta_w) { downcast<via6522_device *>(device)->porta_w(data); } |
| 1141 | |
| 1142 | READ8_DEVICE_HANDLER(via_portb_r) { return downcast<via6522_device *>(device)->portb_r(); } |
| 1143 | WRITE8_DEVICE_HANDLER(via_portb_w) { downcast<via6522_device *>(device)->portb_w(data); } |
src/emu/machine/7474.c
| r8892 | r8893 | |
| 40 | 40 | #include "emu.h" |
| 41 | 41 | #include "7474.h" |
| 42 | 42 | |
| 43 | //************************************************************************** |
| 44 | // DEVICE CONFIGURATION |
| 45 | //************************************************************************** |
| 43 | 46 | |
| 44 | | typedef struct _ttl7474_state ttl7474_state; |
| 45 | | struct _ttl7474_state |
| 47 | //------------------------------------------------- |
| 48 | // ttl7474_device_config - constructor |
| 49 | //------------------------------------------------- |
| 50 | |
| 51 | ttl7474_device_config::ttl7474_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 52 | : device_config(mconfig, static_alloc_device_config, "TTL7474", tag, owner, clock) |
| 46 | 53 | { |
| 47 | | /* callbacks */ |
| 48 | | devcb_resolved_write_line output_cb; |
| 49 | | devcb_resolved_write_line comp_output_cb; |
| 54 | } |
| 50 | 55 | |
| 51 | | /* inputs */ |
| 52 | | UINT8 clear; /* pin 1/13 */ |
| 53 | | UINT8 preset; /* pin 4/10 */ |
| 54 | | UINT8 clock; /* pin 3/11 */ |
| 55 | | UINT8 d; /* pin 2/12 */ |
| 56 | 56 | |
| 57 | | /* outputs */ |
| 58 | | UINT8 output; /* pin 5/9 */ |
| 59 | | UINT8 output_comp; /* pin 6/8 */ |
| 57 | //------------------------------------------------- |
| 58 | // static_alloc_device_config - allocate a new |
| 59 | // configuration object |
| 60 | //------------------------------------------------- |
| 60 | 61 | |
| 61 | | /* internal */ |
| 62 | | UINT8 last_clock; |
| 63 | | UINT8 last_output; |
| 64 | | UINT8 last_output_comp; |
| 62 | device_config *ttl7474_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) |
| 63 | { |
| 64 | return global_alloc(ttl7474_device_config(mconfig, tag, owner, clock)); |
| 65 | } |
| 65 | 66 | |
| 66 | | running_device *device; |
| 67 | | }; |
| 68 | 67 | |
| 69 | | INLINE ttl7474_state *get_safe_token(running_device *device) |
| 68 | //------------------------------------------------- |
| 69 | // alloc_device - allocate a new device object |
| 70 | //------------------------------------------------- |
| 71 | |
| 72 | device_t *ttl7474_device_config::alloc_device(running_machine &machine) const |
| 70 | 73 | { |
| 71 | | assert(device != NULL); |
| 72 | | assert(device->type() == TTL7474); |
| 74 | return auto_alloc(&machine, ttl7474_device(machine, *this)); |
| 75 | } |
| 73 | 76 | |
| 74 | | return (ttl7474_state *)downcast<legacy_device_base *>(device)->token(); |
| 77 | |
| 78 | |
| 79 | //------------------------------------------------- |
| 80 | // device_config_complete - perform any |
| 81 | // operations now that the configuration is |
| 82 | // complete |
| 83 | //------------------------------------------------- |
| 84 | |
| 85 | void ttl7474_device_config::device_config_complete() |
| 86 | { |
| 87 | m_target_tag = reinterpret_cast<const char *>(m_inline_data[INLINE_TARGET_TAG]); |
| 88 | m_base_output_cb = reinterpret_cast<void (*)(device_t *device, INT32)>(m_inline_data[INLINE_OUTPUT_CB]); |
| 89 | m_base_comp_output_cb = reinterpret_cast<void (*)(device_t *device, INT32)>(m_inline_data[INLINE_COMP_OUTPUT_CB]); |
| 90 | |
| 91 | m_output_cb.type = DEVCB_TYPE_DEVICE; |
| 92 | m_output_cb.tag = m_target_tag; |
| 93 | m_output_cb.writeline = m_base_output_cb; |
| 94 | |
| 95 | m_comp_output_cb.type = DEVCB_TYPE_DEVICE; |
| 96 | m_comp_output_cb.tag = m_target_tag; |
| 97 | m_comp_output_cb.writeline = m_base_comp_output_cb; |
| 75 | 98 | } |
| 76 | 99 | |
| 77 | 100 | |
| 78 | | static void ttl7474_update(ttl7474_state *state) |
| 101 | |
| 102 | //************************************************************************** |
| 103 | // LIVE DEVICE |
| 104 | //************************************************************************** |
| 105 | |
| 106 | //------------------------------------------------- |
| 107 | // ttl7474_device - constructor |
| 108 | //------------------------------------------------- |
| 109 | |
| 110 | ttl7474_device::ttl7474_device(running_machine &_machine, const ttl7474_device_config &config) |
| 111 | : device_t(_machine, config), |
| 112 | m_config(config) |
| 79 | 113 | { |
| 80 | | if (!state->preset && state->clear) /* line 1 in truth table */ |
| 114 | init(); |
| 115 | } |
| 116 | |
| 117 | //------------------------------------------------- |
| 118 | // device_start - device-specific startup |
| 119 | //------------------------------------------------- |
| 120 | |
| 121 | void ttl7474_device::device_start() |
| 122 | { |
| 123 | state_save_register_device_item(this, 0, m_clear); |
| 124 | state_save_register_device_item(this, 0, m_preset); |
| 125 | state_save_register_device_item(this, 0, m_clk); |
| 126 | state_save_register_device_item(this, 0, m_d); |
| 127 | state_save_register_device_item(this, 0, m_output); |
| 128 | state_save_register_device_item(this, 0, m_output_comp); |
| 129 | state_save_register_device_item(this, 0, m_last_clock); |
| 130 | state_save_register_device_item(this, 0, m_last_output); |
| 131 | state_save_register_device_item(this, 0, m_last_output_comp); |
| 132 | |
| 133 | devcb_resolve_write_line(&m_output_cb, &m_config.m_output_cb, this); |
| 134 | devcb_resolve_write_line(&m_comp_output_cb, &m_config.m_comp_output_cb, this); |
| 135 | } |
| 136 | |
| 137 | //------------------------------------------------- |
| 138 | // device_reset - device-specific reset |
| 139 | //------------------------------------------------- |
| 140 | |
| 141 | void ttl7474_device::device_reset() |
| 142 | { |
| 143 | init(); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | //------------------------------------------------- |
| 148 | // update - update internal state |
| 149 | //------------------------------------------------- |
| 150 | |
| 151 | void ttl7474_device::update() |
| 152 | { |
| 153 | if (!m_preset && m_clear) /* line 1 in truth table */ |
| 81 | 154 | { |
| 82 | | state->output = 1; |
| 83 | | state->output_comp = 0; |
| 155 | m_output = 1; |
| 156 | m_output_comp = 0; |
| 84 | 157 | } |
| 85 | | else if (state->preset && !state->clear) /* line 2 in truth table */ |
| 158 | else if (m_preset && !m_clear) /* line 2 in truth table */ |
| 86 | 159 | { |
| 87 | | state->output = 0; |
| 88 | | state->output_comp = 1; |
| 160 | m_output = 0; |
| 161 | m_output_comp = 1; |
| 89 | 162 | } |
| 90 | | else if (!state->preset && !state->clear) /* line 3 in truth table */ |
| 163 | else if (!m_preset && !m_clear) /* line 3 in truth table */ |
| 91 | 164 | { |
| 92 | | state->output = 1; |
| 93 | | state->output_comp = 1; |
| 165 | m_output = 1; |
| 166 | m_output_comp = 1; |
| 94 | 167 | } |
| 95 | | else if (!state->last_clock && state->clock) /* line 4 in truth table */ |
| 168 | else if (!m_last_clock && m_clk) /* line 4 in truth table */ |
| 96 | 169 | { |
| 97 | | state->output = state->d; |
| 98 | | state->output_comp = !state->d; |
| 170 | m_output = m_d; |
| 171 | m_output_comp = !m_d; |
| 99 | 172 | } |
| 100 | 173 | |
| 101 | | state->last_clock = state->clock; |
| 174 | m_last_clock = m_clk; |
| 102 | 175 | |
| 103 | 176 | |
| 104 | 177 | /* call callback if any of the outputs changed */ |
| 105 | | if (state->output != state->last_output) |
| 178 | if (m_output != m_last_output) |
| 106 | 179 | { |
| 107 | | state->last_output = state->output; |
| 108 | | if (state->output_cb.write != NULL) |
| 109 | | devcb_call_write_line(&state->output_cb, state->output); |
| 180 | m_last_output = m_output; |
| 181 | devcb_call_write_line(&m_output_cb, m_output); |
| 110 | 182 | } |
| 111 | 183 | /* call callback if any of the outputs changed */ |
| 112 | | if (state->output_comp != state->last_output_comp) |
| 184 | if (m_output_comp != m_last_output_comp) |
| 113 | 185 | { |
| 114 | | state->last_output_comp = state->output_comp; |
| 115 | | if (state->comp_output_cb.write != NULL) |
| 116 | | devcb_call_write_line(&state->comp_output_cb, state->output_comp); |
| 186 | m_last_output_comp = m_output_comp; |
| 187 | devcb_call_write_line(&m_comp_output_cb, m_output_comp); |
| 117 | 188 | } |
| 118 | 189 | } |
| 119 | 190 | |
| 120 | 191 | |
| 192 | //------------------------------------------------- |
| 193 | // clear_w - set the clear line state |
| 194 | //------------------------------------------------- |
| 195 | |
| 121 | 196 | WRITE_LINE_DEVICE_HANDLER( ttl7474_clear_w ) |
| 122 | 197 | { |
| 123 | | ttl7474_state *dev_state = get_safe_token(device); |
| 124 | | dev_state->clear = state & 1; |
| 125 | | ttl7474_update(dev_state); |
| 198 | downcast<ttl7474_device *>(device)->clear_w(state); |
| 126 | 199 | } |
| 127 | 200 | |
| 128 | | WRITE_LINE_DEVICE_HANDLER( ttl7474_preset_w ) |
| 201 | void ttl7474_device::clear_w(UINT8 state) |
| 129 | 202 | { |
| 130 | | ttl7474_state *dev_state = get_safe_token(device); |
| 131 | | dev_state->preset = state & 1; |
| 132 | | ttl7474_update(dev_state); |
| 203 | m_clear = state & 1; |
| 204 | update(); |
| 133 | 205 | } |
| 134 | 206 | |
| 135 | | WRITE_LINE_DEVICE_HANDLER( ttl7474_clock_w ) |
| 207 | |
| 208 | //------------------------------------------------- |
| 209 | // clear_w - set the clear line state |
| 210 | //------------------------------------------------- |
| 211 | |
| 212 | WRITE_LINE_DEVICE_HANDLER( ttl7474_preset_w ) |
| 136 | 213 | { |
| 137 | | ttl7474_state *dev_state = get_safe_token(device); |
| 138 | | dev_state->clock = state & 1; |
| 139 | | ttl7474_update(dev_state); |
| 214 | downcast<ttl7474_device *>(device)->preset_w(state); |
| 140 | 215 | } |
| 141 | 216 | |
| 142 | | WRITE_LINE_DEVICE_HANDLER( ttl7474_d_w ) |
| 217 | void ttl7474_device::preset_w(UINT8 state) |
| 143 | 218 | { |
| 144 | | ttl7474_state *dev_state = get_safe_token(device); |
| 145 | | dev_state->d = state & 1; |
| 146 | | ttl7474_update(dev_state); |
| 219 | m_preset = state & 1; |
| 220 | update(); |
| 147 | 221 | } |
| 148 | 222 | |
| 149 | 223 | |
| 150 | | READ_LINE_DEVICE_HANDLER( ttl7474_output_r ) |
| 224 | //------------------------------------------------- |
| 225 | // clock_w - set the clock line state |
| 226 | //------------------------------------------------- |
| 227 | |
| 228 | WRITE_LINE_DEVICE_HANDLER( ttl7474_clock_w ) |
| 151 | 229 | { |
| 152 | | ttl7474_state *dev_state = get_safe_token(device); |
| 153 | | return dev_state->output; |
| 230 | downcast<ttl7474_device *>(device)->clock_w(state); |
| 154 | 231 | } |
| 155 | 232 | |
| 156 | | READ_LINE_DEVICE_HANDLER( ttl7474_output_comp_r ) |
| 233 | void ttl7474_device::clock_w(UINT8 state) |
| 157 | 234 | { |
| 158 | | ttl7474_state *dev_state = get_safe_token(device); |
| 159 | | return dev_state->output_comp; |
| 235 | m_clk = state & 1; |
| 236 | update(); |
| 160 | 237 | } |
| 161 | 238 | |
| 162 | 239 | |
| 163 | | static DEVICE_START( ttl7474 ) |
| 240 | //------------------------------------------------- |
| 241 | // d_w - set the d line state |
| 242 | //------------------------------------------------- |
| 243 | |
| 244 | WRITE_LINE_DEVICE_HANDLER( ttl7474_d_w ) |
| 164 | 245 | { |
| 165 | | ttl7474_config *config = (ttl7474_config *)downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config(); |
| 166 | | ttl7474_state *state = get_safe_token(device); |
| 246 | downcast<ttl7474_device *>(device)->d_w(state); |
| 247 | } |
| 167 | 248 | |
| 168 | | devcb_resolve_write_line(&state->output_cb, &config->output_cb, device); |
| 169 | | devcb_resolve_write_line(&state->comp_output_cb, &config->comp_output_cb, device); |
| 249 | void ttl7474_device::d_w(UINT8 state) |
| 250 | { |
| 251 | m_d = state & 1; |
| 252 | update(); |
| 253 | } |
| 170 | 254 | |
| 171 | | state->device = device; |
| 172 | 255 | |
| 173 | | state_save_register_device_item(device, 0, state->clear); |
| 174 | | state_save_register_device_item(device, 0, state->preset); |
| 175 | | state_save_register_device_item(device, 0, state->clock); |
| 176 | | state_save_register_device_item(device, 0, state->d); |
| 177 | | state_save_register_device_item(device, 0, state->output); |
| 178 | | state_save_register_device_item(device, 0, state->output_comp); |
| 179 | | state_save_register_device_item(device, 0, state->last_clock); |
| 180 | | state_save_register_device_item(device, 0, state->last_output); |
| 181 | | state_save_register_device_item(device, 0, state->last_output_comp); |
| 256 | //------------------------------------------------- |
| 257 | // output_r - get the output line state |
| 258 | //------------------------------------------------- |
| 259 | |
| 260 | READ_LINE_DEVICE_HANDLER( ttl7474_output_r ) |
| 261 | { |
| 262 | return downcast<ttl7474_device *>(device)->output_r(); |
| 182 | 263 | } |
| 183 | 264 | |
| 184 | | |
| 185 | | static DEVICE_RESET( ttl7474 ) |
| 265 | UINT8 ttl7474_device::output_r() |
| 186 | 266 | { |
| 187 | | ttl7474_state *state = get_safe_token(device); |
| 267 | return m_output; |
| 268 | } |
| 188 | 269 | |
| 189 | | /* all inputs are open first */ |
| 190 | | state->clear = 1; |
| 191 | | state->preset = 1; |
| 192 | | state->clock = 1; |
| 193 | | state->d = 1; |
| 194 | 270 | |
| 195 | | state->output = -1; |
| 196 | | state->last_clock = 1; |
| 197 | | state->last_output = -1; |
| 198 | | state->last_output_comp = -1; |
| 271 | //----------------------------------------------------- |
| 272 | // output_comp_r - get the output-compare line state |
| 273 | //----------------------------------------------------- |
| 274 | |
| 275 | READ_LINE_DEVICE_HANDLER( ttl7474_output_comp_r ) |
| 276 | { |
| 277 | return downcast<ttl7474_device *>(device)->output_comp_r(); |
| 199 | 278 | } |
| 200 | 279 | |
| 280 | UINT8 ttl7474_device::output_comp_r() |
| 281 | { |
| 282 | return m_output_comp; |
| 283 | } |
| 201 | 284 | |
| 202 | | static const char DEVTEMPLATE_SOURCE[] = __FILE__; |
| 285 | void ttl7474_device::init() |
| 286 | { |
| 287 | m_clear = 1; |
| 288 | m_preset = 1; |
| 289 | m_clk = 1; |
| 290 | m_d = 1; |
| 203 | 291 | |
| 204 | | #define DEVTEMPLATE_ID(p,s) p##ttl7474##s |
| 205 | | #define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET | DT_HAS_INLINE_CONFIG |
| 206 | | #define DEVTEMPLATE_NAME "7474" |
| 207 | | #define DEVTEMPLATE_FAMILY "TTL" |
| 208 | | #include "devtempl.h" |
| 292 | m_output = -1; |
| 293 | m_last_clock = 1; |
| 294 | m_last_output = -1; |
| 295 | } |
| 209 | 296 | |
| 210 | | DEFINE_LEGACY_DEVICE(TTL7474, ttl7474); |
| 297 | const device_type MACHINE_TTL7474 = ttl7474_device_config::static_alloc_device_config; |