trunk/src/emu/machine/mos6530.c
| r26914 | r26915 | |
| 17 | 17 | |
| 18 | 18 | #include "emu.h" |
| 19 | 19 | #include "mos6530.h" |
| 20 | | #include "devlegcy.h" |
| 21 | 20 | |
| 22 | 21 | |
| 23 | 22 | /*************************************************************************** |
| r26914 | r26915 | |
| 33 | 32 | |
| 34 | 33 | #define TIMER_FLAG 0x80 |
| 35 | 34 | |
| 36 | | |
| 37 | | |
| 38 | 35 | /*************************************************************************** |
| 39 | | TYPE DEFINITIONS |
| 36 | DEVICE INTERFACE |
| 40 | 37 | ***************************************************************************/ |
| 41 | 38 | |
| 42 | | struct mos6530_port |
| 39 | const device_type MOS6530 = &device_creator<mos6530_device>; |
| 40 | |
| 41 | mos6530_device::mos6530_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 42 | : device_t(mconfig, MOS6530, "MOS6530", tag, owner, clock, "mos6530", __FILE__) |
| 43 | 43 | { |
| 44 | | devcb_resolved_read8 in_port_func; |
| 45 | | devcb_resolved_write8 out_port_func; |
| 44 | } |
| 46 | 45 | |
| 47 | | UINT8 in; |
| 48 | | UINT8 out; |
| 49 | | UINT8 ddr; |
| 50 | | }; |
| 46 | //------------------------------------------------- |
| 47 | // device_config_complete - perform any |
| 48 | // operations now that the configuration is |
| 49 | // complete |
| 50 | //------------------------------------------------- |
| 51 | 51 | |
| 52 | | |
| 53 | | struct mos6530_state |
| 52 | void mos6530_device::device_config_complete() |
| 54 | 53 | { |
| 55 | | devcb_resolved_write_line out_irq_func; |
| 54 | // inherit a copy of the static data |
| 55 | const mos6530_interface *intf = reinterpret_cast<const mos6530_interface *>(static_config()); |
| 56 | if (intf != NULL) |
| 57 | *static_cast<mos6530_interface *>(this) = *intf; |
| 56 | 58 | |
| 57 | | mos6530_port port[2]; |
| 59 | // or initialize to defaults if none provided |
| 60 | else |
| 61 | { |
| 62 | memset(&m_in_pa_cb, 0, sizeof(m_in_pa_cb)); |
| 63 | memset(&m_out_pa_cb, 0, sizeof(m_out_pa_cb)); |
| 64 | memset(&m_in_pb_cb, 0, sizeof(m_in_pb_cb)); |
| 65 | memset(&m_out_pb_cb, 0, sizeof(m_out_pb_cb)); |
| 66 | } |
| 67 | } |
| 58 | 68 | |
| 59 | | UINT8 irqstate; |
| 60 | | UINT8 irqenable; |
| 69 | //------------------------------------------------- |
| 70 | // device_start - device-specific startup |
| 71 | //------------------------------------------------- |
| 61 | 72 | |
| 62 | | UINT8 timershift; |
| 63 | | UINT8 timerstate; |
| 64 | | emu_timer * timer; |
| 73 | void mos6530_device::device_start() |
| 74 | { |
| 75 | /* set static values */ |
| 76 | m_clock = clock(); |
| 65 | 77 | |
| 66 | | UINT32 clock; |
| 67 | | }; |
| 78 | /* resolve callbacks */ |
| 79 | m_port[0].in_port_func.resolve(m_in_pa_cb, *this); |
| 80 | m_port[1].in_port_func.resolve(m_in_pb_cb, *this); |
| 81 | m_port[0].out_port_func.resolve(m_out_pa_cb, *this); |
| 82 | m_port[1].out_port_func.resolve(m_out_pb_cb, *this); |
| 68 | 83 | |
| 84 | /* allocate timers */ |
| 85 | m_timer = timer_alloc(TIMER_END_CALLBACK); |
| 69 | 86 | |
| 87 | /* register for save states */ |
| 88 | save_item(NAME(m_port[0].in)); |
| 89 | save_item(NAME(m_port[0].out)); |
| 90 | save_item(NAME(m_port[0].ddr)); |
| 91 | save_item(NAME(m_port[1].in)); |
| 92 | save_item(NAME(m_port[1].out)); |
| 93 | save_item(NAME(m_port[1].ddr)); |
| 70 | 94 | |
| 71 | | /*************************************************************************** |
| 72 | | INLINE FUNCTIONS |
| 73 | | ***************************************************************************/ |
| 95 | save_item(NAME(m_irqstate)); |
| 96 | save_item(NAME(m_irqenable)); |
| 74 | 97 | |
| 75 | | /*------------------------------------------------- |
| 76 | | get_safe_token - convert a device's token |
| 77 | | into a mos6530_state |
| 78 | | -------------------------------------------------*/ |
| 98 | save_item(NAME(m_timershift)); |
| 99 | save_item(NAME(m_timerstate)); |
| 100 | } |
| 79 | 101 | |
| 80 | | INLINE mos6530_state *get_safe_token(device_t *device) |
| 102 | //------------------------------------------------- |
| 103 | // device_reset - device-specific reset |
| 104 | //------------------------------------------------- |
| 105 | |
| 106 | void mos6530_device::device_reset() |
| 81 | 107 | { |
| 82 | | assert(device != NULL); |
| 83 | | assert(device->type() == MOS6530); |
| 84 | | return (mos6530_state *)downcast<mos6530_device *>(device)->token(); |
| 108 | /* reset I/O states */ |
| 109 | m_port[0].out = 0; |
| 110 | m_port[0].ddr = 0; |
| 111 | m_port[1].out = 0; |
| 112 | m_port[1].ddr = 0; |
| 113 | |
| 114 | /* reset IRQ states */ |
| 115 | m_irqenable = 0; |
| 116 | m_irqstate = TIMER_FLAG; |
| 117 | update_irqstate(); |
| 118 | |
| 119 | /* reset timer states */ |
| 120 | m_timershift = 0; |
| 121 | m_timerstate = TIMER_IDLE; |
| 122 | m_timer->adjust(attotime::never); |
| 85 | 123 | } |
| 86 | 124 | |
| 87 | 125 | |
| 126 | /*************************************************************************** |
| 127 | TYPE DEFINITIONS |
| 128 | ***************************************************************************/ |
| 129 | |
| 130 | |
| 88 | 131 | /*------------------------------------------------- |
| 89 | 132 | update_irqstate - update the IRQ state |
| 90 | 133 | based on interrupt enables |
| 91 | 134 | -------------------------------------------------*/ |
| 92 | 135 | |
| 93 | | INLINE void update_irqstate(device_t *device) |
| 136 | void mos6530_device::update_irqstate() |
| 94 | 137 | { |
| 95 | | mos6530_state *miot = get_safe_token(device); |
| 96 | | UINT8 out = miot->port[1].out; |
| 138 | UINT8 out = m_port[1].out; |
| 97 | 139 | |
| 98 | | if ( miot->irqenable ) |
| 99 | | out = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F ); |
| 140 | if ( m_irqenable ) |
| 141 | out = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F ); |
| 100 | 142 | |
| 101 | | if (!miot->port[1].out_port_func.isnull()) |
| 102 | | miot->port[1].out_port_func(0, out); |
| 143 | if (!m_port[1].out_port_func.isnull()) |
| 144 | m_port[1].out_port_func(0, out); |
| 103 | 145 | else |
| 104 | | logerror("6530MIOT chip %s: Port B is being written to but has no handler.\n", device->tag()); |
| 146 | logerror("6530MIOT chip %s: Port B is being written to but has no handler.\n", tag()); |
| 105 | 147 | } |
| 106 | 148 | |
| 107 | 149 | |
| r26914 | r26915 | |
| 109 | 151 | get_timer - return the current timer value |
| 110 | 152 | -------------------------------------------------*/ |
| 111 | 153 | |
| 112 | | INLINE UINT8 get_timer(mos6530_state *miot) |
| 154 | UINT8 mos6530_device::get_timer() |
| 113 | 155 | { |
| 114 | 156 | /* if idle, return 0 */ |
| 115 | | if (miot->timerstate == TIMER_IDLE) |
| 157 | if (m_timerstate == TIMER_IDLE) |
| 116 | 158 | return 0; |
| 117 | 159 | |
| 118 | 160 | /* if counting, return the number of ticks remaining */ |
| 119 | | else if (miot->timerstate == TIMER_COUNTING) |
| 120 | | return miot->timer->remaining().as_ticks(miot->clock) >> miot->timershift; |
| 161 | else if (m_timerstate == TIMER_COUNTING) |
| 162 | return m_timer->remaining().as_ticks(m_clock) >> m_timershift; |
| 121 | 163 | |
| 122 | 164 | /* if finishing, return the number of ticks without the shift */ |
| 123 | 165 | else |
| 124 | | return miot->timer->remaining().as_ticks(miot->clock); |
| 166 | return m_timer->remaining().as_ticks(m_clock); |
| 125 | 167 | } |
| 126 | 168 | |
| 127 | 169 | |
| r26914 | r26915 | |
| 134 | 176 | timer |
| 135 | 177 | -------------------------------------------------*/ |
| 136 | 178 | |
| 137 | | static TIMER_CALLBACK( timer_end_callback ) |
| 179 | void mos6530_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 138 | 180 | { |
| 139 | | device_t *device = (device_t *)ptr; |
| 140 | | mos6530_state *miot = get_safe_token(device); |
| 181 | switch (id) |
| 182 | { |
| 183 | // deferred reset |
| 184 | case TIMER_END_CALLBACK: |
| 185 | assert(m_timerstate != TIMER_IDLE); |
| 141 | 186 | |
| 142 | | assert(miot->timerstate != TIMER_IDLE); |
| 187 | /* if we finished counting, switch to the finishing state */ |
| 188 | if (m_timerstate == TIMER_COUNTING) |
| 189 | { |
| 190 | m_timerstate = TIMER_FINISHING; |
| 191 | m_timer->adjust(attotime::from_ticks(256, m_clock)); |
| 143 | 192 | |
| 144 | | /* if we finished counting, switch to the finishing state */ |
| 145 | | if (miot->timerstate == TIMER_COUNTING) |
| 146 | | { |
| 147 | | miot->timerstate = TIMER_FINISHING; |
| 148 | | miot->timer->adjust(attotime::from_ticks(256, miot->clock)); |
| 193 | /* signal timer IRQ as well */ |
| 194 | m_irqstate |= TIMER_FLAG; |
| 195 | update_irqstate(); |
| 196 | } |
| 149 | 197 | |
| 150 | | /* signal timer IRQ as well */ |
| 151 | | miot->irqstate |= TIMER_FLAG; |
| 152 | | update_irqstate(device); |
| 198 | /* if we finished finishing, switch to the idle state */ |
| 199 | else if (m_timerstate == TIMER_FINISHING) |
| 200 | { |
| 201 | m_timerstate = TIMER_IDLE; |
| 202 | m_timer->adjust(attotime::never); |
| 203 | } |
| 204 | break; |
| 153 | 205 | } |
| 154 | | |
| 155 | | /* if we finished finishing, switch to the idle state */ |
| 156 | | else if (miot->timerstate == TIMER_FINISHING) |
| 157 | | { |
| 158 | | miot->timerstate = TIMER_IDLE; |
| 159 | | miot->timer->adjust(attotime::never); |
| 160 | | } |
| 161 | 206 | } |
| 162 | 207 | |
| 163 | | |
| 164 | | |
| 165 | 208 | /*************************************************************************** |
| 166 | 209 | I/O ACCESS |
| 167 | 210 | ***************************************************************************/ |
| r26914 | r26915 | |
| 170 | 213 | mos6530_w - master I/O write access |
| 171 | 214 | -------------------------------------------------*/ |
| 172 | 215 | |
| 173 | | WRITE8_DEVICE_HANDLER( mos6530_w ) |
| 216 | WRITE8_MEMBER( mos6530_device::write ) |
| 174 | 217 | { |
| 175 | | mos6530_state *miot = get_safe_token(device); |
| 176 | | |
| 177 | 218 | /* if A2 == 1, we are writing to the timer */ |
| 178 | 219 | if (offset & 0x04) |
| 179 | 220 | { |
| r26914 | r26915 | |
| 182 | 223 | INT64 target; |
| 183 | 224 | |
| 184 | 225 | /* A0-A1 contain the timer divisor */ |
| 185 | | miot->timershift = timershift[offset & 3]; |
| 226 | m_timershift = timershift[offset & 3]; |
| 186 | 227 | |
| 187 | 228 | /* A3 contains the timer IRQ enable */ |
| 188 | 229 | if (offset & 8) |
| 189 | | miot->irqenable |= TIMER_FLAG; |
| 230 | m_irqenable |= TIMER_FLAG; |
| 190 | 231 | else |
| 191 | | miot->irqenable &= ~TIMER_FLAG; |
| 232 | m_irqenable &= ~TIMER_FLAG; |
| 192 | 233 | |
| 193 | 234 | /* writes here clear the timer flag */ |
| 194 | | if (miot->timerstate != TIMER_FINISHING || get_timer(miot) != 0xff) |
| 195 | | miot->irqstate &= ~TIMER_FLAG; |
| 196 | | update_irqstate(device); |
| 235 | if (m_timerstate != TIMER_FINISHING || get_timer() != 0xff) |
| 236 | m_irqstate &= ~TIMER_FLAG; |
| 237 | update_irqstate(); |
| 197 | 238 | |
| 198 | 239 | /* update the timer */ |
| 199 | | miot->timerstate = TIMER_COUNTING; |
| 200 | | target = curtime.as_ticks(miot->clock) + 1 + (data << miot->timershift); |
| 201 | | miot->timer->adjust(attotime::from_ticks(target, miot->clock) - curtime); |
| 240 | m_timerstate = TIMER_COUNTING; |
| 241 | target = curtime.as_ticks(m_clock) + 1 + (data << m_timershift); |
| 242 | m_timer->adjust(attotime::from_ticks(target, m_clock) - curtime); |
| 202 | 243 | } |
| 203 | 244 | |
| 204 | 245 | /* if A2 == 0, we are writing to the I/O section */ |
| 205 | 246 | else |
| 206 | 247 | { |
| 207 | 248 | /* A1 selects the port */ |
| 208 | | mos6530_port *port = &miot->port[(offset >> 1) & 1]; |
| 249 | mos6530_port *port = &m_port[(offset >> 1) & 1]; |
| 209 | 250 | |
| 210 | 251 | /* if A0 == 1, we are writing to the port's DDR */ |
| 211 | 252 | if (offset & 1) |
| r26914 | r26915 | |
| 217 | 258 | UINT8 olddata = port->out; |
| 218 | 259 | port->out = data; |
| 219 | 260 | |
| 220 | | if ( ( offset & 2 ) && miot->irqenable ) |
| 261 | if ( ( offset & 2 ) && m_irqenable ) |
| 221 | 262 | { |
| 222 | | olddata = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( olddata & 0x7F ); |
| 223 | | data = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( data & 0x7F ); |
| 263 | olddata = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( olddata & 0x7F ); |
| 264 | data = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( data & 0x7F ); |
| 224 | 265 | } |
| 225 | 266 | |
| 226 | 267 | if (!port->out_port_func.isnull()) |
| 227 | 268 | port->out_port_func(0, data); |
| 228 | 269 | else |
| 229 | | logerror("6530MIOT chip %s: Port %c is being written to but has no handler. PC: %08X - %02X\n", device->tag(), 'A' + (offset & 1), space.machine().firstcpu->pc(), data); |
| 270 | logerror("6530MIOT chip %s: Port %c is being written to but has no handler. PC: %08X - %02X\n", tag(), 'A' + (offset & 1), space.machine().firstcpu->pc(), data); |
| 230 | 271 | } |
| 231 | 272 | } |
| 232 | 273 | } |
| r26914 | r26915 | |
| 236 | 277 | mos6530_r - master I/O read access |
| 237 | 278 | -------------------------------------------------*/ |
| 238 | 279 | |
| 239 | | READ8_DEVICE_HANDLER( mos6530_r ) |
| 280 | READ8_MEMBER( mos6530_device::read ) |
| 240 | 281 | { |
| 241 | | mos6530_state *miot = get_safe_token(device); |
| 242 | 282 | UINT8 val = 0; |
| 243 | 283 | |
| 244 | 284 | /* if A2 == 1 and A0 == 1, we are reading interrupt flags */ |
| 245 | 285 | if ((offset & 0x05) == 0x05) |
| 246 | 286 | { |
| 247 | | val = miot->irqstate; |
| 287 | val = m_irqstate; |
| 248 | 288 | } |
| 249 | 289 | |
| 250 | 290 | /* if A2 == 1 and A0 == 0, we are reading the timer */ |
| 251 | 291 | else if ((offset & 0x05) == 0x04) |
| 252 | 292 | { |
| 253 | | val = get_timer(miot); |
| 293 | val = get_timer(); |
| 254 | 294 | |
| 255 | 295 | /* A3 contains the timer IRQ enable */ |
| 256 | 296 | if (offset & 8) |
| 257 | | miot->irqenable |= TIMER_FLAG; |
| 297 | m_irqenable |= TIMER_FLAG; |
| 258 | 298 | else |
| 259 | | miot->irqenable &= ~TIMER_FLAG; |
| 299 | m_irqenable &= ~TIMER_FLAG; |
| 260 | 300 | |
| 261 | 301 | /* implicitly clears the timer flag */ |
| 262 | | if (miot->timerstate != TIMER_FINISHING || val != 0xff) |
| 263 | | miot->irqstate &= ~TIMER_FLAG; |
| 264 | | update_irqstate(device); |
| 302 | if (m_timerstate != TIMER_FINISHING || val != 0xff) |
| 303 | m_irqstate &= ~TIMER_FLAG; |
| 304 | update_irqstate(); |
| 265 | 305 | } |
| 266 | 306 | |
| 267 | 307 | /* if A2 == 0 and A0 == anything, we are reading from ports */ |
| 268 | 308 | else |
| 269 | 309 | { |
| 270 | 310 | /* A1 selects the port */ |
| 271 | | mos6530_port *port = &miot->port[(offset >> 1) & 1]; |
| 311 | mos6530_port *port = &m_port[(offset >> 1) & 1]; |
| 272 | 312 | |
| 273 | 313 | /* if A0 == 1, we are reading the port's DDR */ |
| 274 | 314 | if (offset & 1) |
| r26914 | r26915 | |
| 279 | 319 | { |
| 280 | 320 | UINT8 out = port->out; |
| 281 | 321 | |
| 282 | | if ( ( offset & 2 ) && miot->irqenable ) |
| 283 | | out = ( ( miot->irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F ); |
| 322 | if ( ( offset & 2 ) && m_irqenable ) |
| 323 | out = ( ( m_irqstate & TIMER_FLAG ) ? 0x00 : 0x80 ) | ( out & 0x7F ); |
| 284 | 324 | |
| 285 | 325 | /* call the input callback if it exists */ |
| 286 | 326 | if (!port->in_port_func.isnull()) |
| r26914 | r26915 | |
| 288 | 328 | port->in = port->in_port_func(0); |
| 289 | 329 | } |
| 290 | 330 | else |
| 291 | | logerror("6530MIOT chip %s: Port %c is being read but has no handler. PC: %08X\n", device->tag(), 'A' + (offset & 1), space.machine().firstcpu->pc()); |
| 331 | logerror("6530MIOT chip %s: Port %c is being read but has no handler. PC: %08X\n", tag(), 'A' + (offset & 1), space.machine().firstcpu->pc()); |
| 292 | 332 | |
| 293 | 333 | /* apply the DDR to the result */ |
| 294 | 334 | val = (out & port->ddr) | (port->in & ~port->ddr); |
| r26914 | r26915 | |
| 303 | 343 | value |
| 304 | 344 | -------------------------------------------------*/ |
| 305 | 345 | |
| 306 | | void mos6530_porta_in_set(device_t *device, UINT8 data, UINT8 mask) |
| 346 | void mos6530_device::porta_in_set(UINT8 data, UINT8 mask) |
| 307 | 347 | { |
| 308 | | mos6530_state *miot = get_safe_token(device); |
| 309 | | miot->port[0].in = (miot->port[0].in & ~mask) | (data & mask); |
| 348 | m_port[0].in = (m_port[0].in & ~mask) | (data & mask); |
| 310 | 349 | } |
| 311 | 350 | |
| 312 | 351 | |
| r26914 | r26915 | |
| 315 | 354 | value |
| 316 | 355 | -------------------------------------------------*/ |
| 317 | 356 | |
| 318 | | void mos6530_portb_in_set(device_t *device, UINT8 data, UINT8 mask) |
| 357 | void mos6530_device::portb_in_set(UINT8 data, UINT8 mask) |
| 319 | 358 | { |
| 320 | | mos6530_state *miot = get_safe_token(device); |
| 321 | | miot->port[1].in = (miot->port[1].in & ~mask) | (data & mask); |
| 359 | m_port[1].in = (m_port[1].in & ~mask) | (data & mask); |
| 322 | 360 | } |
| 323 | 361 | |
| 324 | 362 | |
| r26914 | r26915 | |
| 327 | 365 | value |
| 328 | 366 | -------------------------------------------------*/ |
| 329 | 367 | |
| 330 | | UINT8 mos6530_porta_in_get(device_t *device) |
| 368 | UINT8 mos6530_device::porta_in_get() |
| 331 | 369 | { |
| 332 | | mos6530_state *miot = get_safe_token(device); |
| 333 | | return miot->port[0].in; |
| 370 | return m_port[0].in; |
| 334 | 371 | } |
| 335 | 372 | |
| 336 | 373 | |
| r26914 | r26915 | |
| 339 | 376 | value |
| 340 | 377 | -------------------------------------------------*/ |
| 341 | 378 | |
| 342 | | UINT8 mos6530_portb_in_get(device_t *device) |
| 379 | UINT8 mos6530_device::portb_in_get() |
| 343 | 380 | { |
| 344 | | mos6530_state *miot = get_safe_token(device); |
| 345 | | return miot->port[1].in; |
| 381 | return m_port[1].in; |
| 346 | 382 | } |
| 347 | 383 | |
| 348 | 384 | |
| r26914 | r26915 | |
| 351 | 387 | value |
| 352 | 388 | -------------------------------------------------*/ |
| 353 | 389 | |
| 354 | | UINT8 mos6530_porta_out_get(device_t *device) |
| 390 | UINT8 mos6530_device::porta_out_get() |
| 355 | 391 | { |
| 356 | | mos6530_state *miot = get_safe_token(device); |
| 357 | | return miot->port[0].out; |
| 392 | return m_port[0].out; |
| 358 | 393 | } |
| 359 | 394 | |
| 360 | 395 | |
| r26914 | r26915 | |
| 363 | 398 | value |
| 364 | 399 | -------------------------------------------------*/ |
| 365 | 400 | |
| 366 | | UINT8 mos6530_portb_out_get(device_t *device) |
| 401 | UINT8 mos6530_device::portb_out_get() |
| 367 | 402 | { |
| 368 | | mos6530_state *miot = get_safe_token(device); |
| 369 | | return miot->port[1].out; |
| 403 | return m_port[1].out; |
| 370 | 404 | } |
| 371 | | |
| 372 | | |
| 373 | | /*************************************************************************** |
| 374 | | DEVICE INTERFACE |
| 375 | | ***************************************************************************/ |
| 376 | | |
| 377 | | static DEVICE_START( mos6530 ) |
| 378 | | { |
| 379 | | mos6530_state *miot = get_safe_token(device); |
| 380 | | const mos6530_interface *intf = (const mos6530_interface*)device->static_config(); |
| 381 | | |
| 382 | | /* validate arguments */ |
| 383 | | assert(device != NULL); |
| 384 | | assert(device->tag() != NULL); |
| 385 | | |
| 386 | | /* set static values */ |
| 387 | | miot->clock = device->clock(); |
| 388 | | |
| 389 | | /* resolve callbacks */ |
| 390 | | miot->port[0].in_port_func.resolve(intf->in_pa_func, *device); |
| 391 | | miot->port[1].in_port_func.resolve(intf->in_pb_func, *device); |
| 392 | | miot->port[0].out_port_func.resolve(intf->out_pa_func, *device); |
| 393 | | miot->port[1].out_port_func.resolve(intf->out_pb_func, *device); |
| 394 | | |
| 395 | | /* allocate timers */ |
| 396 | | miot->timer = device->machine().scheduler().timer_alloc(FUNC(timer_end_callback), (void *)device); |
| 397 | | |
| 398 | | /* register for save states */ |
| 399 | | device->save_item(NAME(miot->port[0].in)); |
| 400 | | device->save_item(NAME(miot->port[0].out)); |
| 401 | | device->save_item(NAME(miot->port[0].ddr)); |
| 402 | | device->save_item(NAME(miot->port[1].in)); |
| 403 | | device->save_item(NAME(miot->port[1].out)); |
| 404 | | device->save_item(NAME(miot->port[1].ddr)); |
| 405 | | |
| 406 | | device->save_item(NAME(miot->irqstate)); |
| 407 | | device->save_item(NAME(miot->irqenable)); |
| 408 | | |
| 409 | | device->save_item(NAME(miot->timershift)); |
| 410 | | device->save_item(NAME(miot->timerstate)); |
| 411 | | } |
| 412 | | |
| 413 | | |
| 414 | | static DEVICE_RESET( mos6530 ) |
| 415 | | { |
| 416 | | mos6530_state *miot = get_safe_token(device); |
| 417 | | |
| 418 | | /* reset I/O states */ |
| 419 | | miot->port[0].out = 0; |
| 420 | | miot->port[0].ddr = 0; |
| 421 | | miot->port[1].out = 0; |
| 422 | | miot->port[1].ddr = 0; |
| 423 | | |
| 424 | | /* reset IRQ states */ |
| 425 | | miot->irqenable = 0; |
| 426 | | miot->irqstate = TIMER_FLAG; |
| 427 | | update_irqstate(device); |
| 428 | | |
| 429 | | /* reset timer states */ |
| 430 | | miot->timershift = 0; |
| 431 | | miot->timerstate = TIMER_IDLE; |
| 432 | | miot->timer->adjust(attotime::never); |
| 433 | | } |
| 434 | | |
| 435 | | |
| 436 | | const device_type MOS6530 = &device_creator<mos6530_device>; |
| 437 | | |
| 438 | | mos6530_device::mos6530_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 439 | | : device_t(mconfig, MOS6530, "MOS6530", tag, owner, clock, "mos6530", __FILE__) |
| 440 | | { |
| 441 | | m_token = global_alloc_clear(mos6530_state); |
| 442 | | } |
| 443 | | |
| 444 | | //------------------------------------------------- |
| 445 | | // device_config_complete - perform any |
| 446 | | // operations now that the configuration is |
| 447 | | // complete |
| 448 | | //------------------------------------------------- |
| 449 | | |
| 450 | | void mos6530_device::device_config_complete() |
| 451 | | { |
| 452 | | } |
| 453 | | |
| 454 | | //------------------------------------------------- |
| 455 | | // device_start - device-specific startup |
| 456 | | //------------------------------------------------- |
| 457 | | |
| 458 | | void mos6530_device::device_start() |
| 459 | | { |
| 460 | | DEVICE_START_NAME( mos6530 )(this); |
| 461 | | } |
| 462 | | |
| 463 | | //------------------------------------------------- |
| 464 | | // device_reset - device-specific reset |
| 465 | | //------------------------------------------------- |
| 466 | | |
| 467 | | void mos6530_device::device_reset() |
| 468 | | { |
| 469 | | DEVICE_RESET_NAME( mos6530 )(this); |
| 470 | | } |