diff options
author | 2011-05-03 06:55:11 +0000 | |
---|---|---|
committer | 2011-05-03 06:55:11 +0000 | |
commit | 1c7b9ec528ab1369e8b6dc143c1695c89b8873cf (patch) | |
tree | 66412eec94779dcb2e97b34939c4117fb368c99c /src/emu/machine/6840ptm.c | |
parent | a5a153d11468b7ae5b8cf866d3a0cdbe47aa8781 (diff) |
Cleaned up 6840 device modernization, removing legacy trampolines
and using device timers.
Diffstat (limited to 'src/emu/machine/6840ptm.c')
-rw-r--r-- | src/emu/machine/6840ptm.c | 303 |
1 files changed, 120 insertions, 183 deletions
diff --git a/src/emu/machine/6840ptm.c b/src/emu/machine/6840ptm.c index dcc32e99f22..f9d65da927b 100644 --- a/src/emu/machine/6840ptm.c +++ b/src/emu/machine/6840ptm.c @@ -111,7 +111,7 @@ void ptm6840_device::device_config_complete() void ptm6840_device::device_start() { m_internal_clock = m_internal_clock; - /* resolve callbacks */ + // resolve callbacks for (int i = 0; i < 3; i++) { m_out_func[i].resolve(m_out_cb[i], *this); @@ -130,9 +130,9 @@ void ptm6840_device::device_start() } - m_timer[0] = machine().scheduler().timer_alloc(FUNC(ptm6840_timer1_cb), (void *)this); - m_timer[1] = machine().scheduler().timer_alloc(FUNC(ptm6840_timer2_cb), (void *)this); - m_timer[2] = machine().scheduler().timer_alloc(FUNC(ptm6840_timer3_cb), (void *)this); + m_timer[0] = timer_alloc(0); + m_timer[1] = timer_alloc(1); + m_timer[2] = timer_alloc(2); for (int i = 0; i < 3; i++) { @@ -141,7 +141,7 @@ void ptm6840_device::device_start() m_irq_func.resolve(m_irq_cb, *this); - /* register for state saving */ + // register for state saving save_item(NAME(m_lsb_buffer)); save_item(NAME(m_msb_buffer)); save_item(NAME(m_status_read_since_int)); @@ -187,48 +187,47 @@ void ptm6840_device::device_reset() } +//------------------------------------------------- +// device_timer - handle timer callbacks +//------------------------------------------------- -/*------------------------------------------------- - ptm6840_get_status - Get enabled status --------------------------------------------------*/ - -int ptm6840_get_status( device_t *device, int clock ) +void ptm6840_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { - return downcast<ptm6840_device*>(device)->ptm6840_get_status(clock); + timeout(id); } -int ptm6840_device::ptm6840_get_status( int clock ) + +//------------------------------------------------- +// status - Get enabled status +//------------------------------------------------- + +int ptm6840_device::status( int clock ) const { return m_enabled[clock - 1]; } -/*------------------------------------------------- - ptm6840_get_irq - Get IRQ state --------------------------------------------------*/ - -int ptm6840_get_irq( device_t *device ) -{ - return downcast<ptm6840_device*>(device)->ptm6840_get_irq(); -} +//------------------------------------------------- +// irq - Get IRQ state +//------------------------------------------------- -int ptm6840_device::ptm6840_get_irq() +int ptm6840_device::irq_state() const { return m_IRQ; } -/*------------------------------------------------- - subtract_from_counter - Subtract from Counter --------------------------------------------------*/ +//------------------------------------------------- +// subtract_from_counter - Subtract from Counter +//------------------------------------------------- void ptm6840_device::subtract_from_counter(int counter, int count) { double clock; - /* Determine the clock frequency for this timer */ + // Determine the clock frequency for this timer if (m_control_reg[counter] & 0x02) { clock = m_internal_clock; @@ -238,53 +237,53 @@ void ptm6840_device::subtract_from_counter(int counter, int count) clock = m_external_clock[counter]; } - /* Dual-byte mode */ + // Dual-byte mode if (m_control_reg[counter] & 0x04) { int lsb = m_counter[counter] & 0xff; int msb = m_counter[counter] >> 8; - /* Count the clocks */ + // Count the clocks lsb -= count; - /* Loop while we're less than zero */ + // Loop while we're less than zero while (lsb < 0) { - /* Borrow from the MSB */ + // Borrow from the MSB lsb += (m_latch[counter] & 0xff) + 1; msb--; - /* If MSB goes less than zero, we've expired */ + // If MSB goes less than zero, we've expired if (msb < 0) { - ptm6840_timeout(counter); + timeout(counter); msb = (m_latch[counter] >> 8) + 1; } } - /* Store the result */ + // Store the result m_counter[counter] = (msb << 8) | lsb; } - /* Word mode */ + // Word mode else { int word = m_counter[counter]; - /* Count the clocks */ + // Count the clocks word -= count; - /* loop while we're less than zero */ + // loop while we're less than zero while (word < 0) { - /* Borrow from the MSB */ + // Borrow from the MSB word += m_latch[counter] + 1; - /* We've expired */ - ptm6840_timeout(counter); + // We've expired + timeout(counter); } - /* Store the result */ + // Store the result m_counter[counter] = word; } @@ -303,11 +302,11 @@ void ptm6840_device::subtract_from_counter(int counter, int count) -/*------------------------------------------------- - ptm_tick --------------------------------------------------*/ +//------------------------------------------------- +// tick +//------------------------------------------------- -void ptm6840_device::ptm_tick(int counter, int count) +void ptm6840_device::tick(int counter, int count) { if (counter == 2) { @@ -327,14 +326,9 @@ void ptm6840_device::ptm_tick(int counter, int count) -/*------------------------------------------------- - update_interrupts - Update Internal Interrupts --------------------------------------------------*/ - -void update_interrupts( device_t *device ) -{ - downcast<ptm6840_device*>(device)->update_interrupts(); -} +//------------------------------------------------- +// update_interrupts - Update Internal Interrupts +//------------------------------------------------- void ptm6840_device::update_interrupts() { @@ -361,22 +355,22 @@ void ptm6840_device::update_interrupts() -/*------------------------------------------------- - compute_counter - Compute Counter --------------------------------------------------*/ +//------------------------------------------------- +// compute_counter - Compute Counter +//------------------------------------------------- -UINT16 ptm6840_device::compute_counter( int counter ) +UINT16 ptm6840_device::compute_counter( int counter ) const { double clock; - /* If there's no timer, return the count */ + // If there's no timer, return the count if (!m_enabled[counter]) { PLOG(("MC6840 #%s: read counter(%d): %d\n", tag(), counter, m_counter[counter])); return m_counter[counter]; } - /* determine the clock frequency for this timer */ + // determine the clock frequency for this timer if (m_control_reg[counter] & 0x02) { clock = m_internal_clock; @@ -387,10 +381,10 @@ UINT16 ptm6840_device::compute_counter( int counter ) clock = m_external_clock[counter]; PLOG(("MC6840 #%s: %d external clock freq %f \n", tag(), counter, clock)); } - /* See how many are left */ + // See how many are left int remaining = (m_timer[counter]->remaining() * clock).as_double(); - /* Adjust the count for dual byte mode */ + // Adjust the count for dual byte mode if (m_control_reg[counter] & 0x04) { int divisor = (m_counter[counter] & 0xff) + 1; @@ -404,18 +398,18 @@ UINT16 ptm6840_device::compute_counter( int counter ) -/*------------------------------------------------- - reload_count - Reload Counter --------------------------------------------------*/ +//------------------------------------------------- +// reload_count - Reload Counter +//------------------------------------------------- void ptm6840_device::reload_count(int idx) { double clock; - /* Copy the latched value in */ + // Copy the latched value in m_counter[idx] = m_latch[idx]; - /* Determine the clock frequency for this timer */ + // Determine the clock frequency for this timer if (m_control_reg[idx] & 0x02) { clock = m_internal_clock; @@ -427,7 +421,7 @@ void ptm6840_device::reload_count(int idx) PLOG(("MC6840 #%s: %d external clock freq %f \n", tag(), idx, clock)); } - /* Determine the number of clock periods before we expire */ + // Determine the number of clock periods before we expire int count = m_counter[idx]; if (m_control_reg[idx] & 0x04) { @@ -449,7 +443,7 @@ void ptm6840_device::reload_count(int idx) } } - /* Set the timer */ + // Set the timer PLOG(("MC6840 #%s: reload_count(%d): clock = %f count = %d\n", tag(), idx, clock, count)); attotime duration = attotime::from_hz(clock) * count; @@ -480,11 +474,16 @@ void ptm6840_device::reload_count(int idx) -/*------------------------------------------------- - ptm6840_read - Read Timer --------------------------------------------------*/ +//------------------------------------------------- +// read - Read Timer +//------------------------------------------------- -READ8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_read) +READ8_MEMBER( ptm6840_device::read ) +{ + return read(offset); +} + +UINT8 ptm6840_device::read(offs_t offset) { int val; @@ -511,7 +510,7 @@ READ8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_read) int idx = (offset - 2) / 2; int result = compute_counter(idx); - /* Clear the interrupt if the status has been read */ + // Clear the interrupt if the status has been read if (m_status_read_since_int & (1 << idx)) { m_status_reg &= ~(1 << idx); @@ -544,11 +543,16 @@ READ8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_read) } -/*------------------------------------------------- - ptm6840_write - Write Timer --------------------------------------------------*/ +//------------------------------------------------- +// write - Write Timer +//------------------------------------------------- + +WRITE8_MEMBER( ptm6840_device::write ) +{ + write(offset, data); +} -WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) +void ptm6840_device::write(offs_t offset, UINT8 data) { switch ( offset ) { @@ -568,13 +572,13 @@ WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) if (!(m_control_reg[idx] & 0x80 )) { - /* Output cleared */ + // Output cleared m_out_func[idx](0, 0); } - /* Reset? */ + // Reset? if (idx == 0 && (diffs & 0x01)) { - /* Holding reset down */ + // Holding reset down if (data & 0x01) { PLOG(("MC6840 #%s : Timer reset\n", tag())); @@ -584,7 +588,7 @@ WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) m_enabled[i] = 0; } } - /* Releasing reset */ + // Releasing reset else { for (int i = 0; i < 3; i++) @@ -596,7 +600,7 @@ WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) m_status_reg = 0; update_interrupts(); - /* Changing the clock source? (e.g. Zwackery) */ + // Changing the clock source? (e.g. Zwackery) if (diffs & 0x02) { reload_count(idx); @@ -621,11 +625,11 @@ WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) int idx = (offset - 3) / 2; m_latch[idx] = (m_msb_buffer << 8) | (data & 0xff); - /* Clear the interrupt */ + // Clear the interrupt m_status_reg &= ~(1 << idx); update_interrupts(); - /* Reload the count if in an appropriate mode */ + // Reload the count if in an appropriate mode if (!(m_control_reg[idx] & 0x10)) { reload_count(idx); @@ -638,15 +642,15 @@ WRITE8_DEVICE_HANDLER_TRAMPOLINE(ptm6840, ptm6840_write) } -/*------------------------------------------------- - ptm6840_timeout - Called if timer is mature --------------------------------------------------*/ +//------------------------------------------------- +// timeout - Called if timer is mature +//------------------------------------------------- -void ptm6840_device::ptm6840_timeout(int idx) +void ptm6840_device::timeout(int idx) { PLOG(("**ptm6840 %s t%d timeout**\n", tag(), idx + 1)); - /* Set the interrupt flag */ + // Set the interrupt flag m_status_reg |= (1 << idx); m_status_read_since_int &= ~(1 << idx); update_interrupts(); @@ -669,7 +673,7 @@ void ptm6840_device::ptm6840_timeout(int idx) m_out_func[idx](0, m_output[idx]); - /* No changes in output until reinit */ + // No changes in output until reinit m_fired[idx] = 1; m_status_reg |= (1 << idx); @@ -683,31 +687,11 @@ void ptm6840_device::ptm6840_timeout(int idx) } -/*------------------------------------------------- - TIMER_CALLBACKs for Timer 1, 2 & 3 --------------------------------------------------*/ - -TIMER_CALLBACK( ptm6840_device::ptm6840_timer1_cb ) -{ - reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(0); -} - -TIMER_CALLBACK( ptm6840_device::ptm6840_timer2_cb ) -{ - reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(1); -} - -TIMER_CALLBACK( ptm6840_device::ptm6840_timer3_cb ) -{ - reinterpret_cast<ptm6840_device *>(ptr)->ptm6840_timeout(2); -} - - -/*------------------------------------------------- - ptm6840_set_gate - set gate status (0 or 1) --------------------------------------------------*/ +//------------------------------------------------- +// set_gate - set gate status (0 or 1) +//------------------------------------------------- -void ptm6840_device::ptm6840_set_gate(int state, int idx) +void ptm6840_device::set_gate(int idx, int state) { if ( (m_mode[idx] == 0) || (m_mode[idx] == 2) || (m_mode[0] == 4) || (m_mode[idx] == 6) ) { @@ -719,32 +703,16 @@ void ptm6840_device::ptm6840_set_gate(int state, int idx) m_gate[idx] = state; } - -/*------------------------------------------------- - WRITE8_DEVICE_HANDLERs for Gate 1, 2 & 3 --------------------------------------------------*/ - -WRITE8_DEVICE_HANDLER( ptm6840_set_g1 ) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 0); -} - -WRITE8_DEVICE_HANDLER( ptm6840_set_g2 ) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 1); -} - -WRITE8_DEVICE_HANDLER( ptm6840_set_g3 ) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_gate(data, 2); -} +WRITE_LINE_MEMBER( ptm6840_device::set_g1 ) { set_gate(0, state); } +WRITE_LINE_MEMBER( ptm6840_device::set_g2 ) { set_gate(1, state); } +WRITE_LINE_MEMBER( ptm6840_device::set_g3 ) { set_gate(2, state); } -/*------------------------------------------------- - ptm6840_set_clock - set clock status (0 or 1) --------------------------------------------------*/ +//------------------------------------------------- +// set_clock - set clock status (0 or 1) +//------------------------------------------------- -void ptm6840_device::ptm6840_set_clock(int state, int idx) +void ptm6840_device::set_clock(int idx, int state) { m_clk[idx] = state; @@ -752,57 +720,31 @@ void ptm6840_device::ptm6840_set_clock(int state, int idx) { if (state) { - ptm_tick(idx, 1); + tick(idx, 1); } } } +WRITE_LINE_MEMBER( ptm6840_device::set_c1 ) { set_clock(0, state); } +WRITE_LINE_MEMBER( ptm6840_device::set_c2 ) { set_clock(1, state); } +WRITE_LINE_MEMBER( ptm6840_device::set_c3 ) { set_clock(2, state); } -/*------------------------------------------------- - WRITE8_DEVICE_HANDLERs for Clock 1, 2 & 3 --------------------------------------------------*/ -WRITE8_DEVICE_HANDLER( ptm6840_set_c1 ) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 0); -} - -WRITE8_DEVICE_HANDLER( ptm6840_set_c2 ) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 1); -} - -WRITE8_DEVICE_HANDLER( ptm6840_set_c3 ) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_clock(data, 2); -} - - -/*------------------------------------------------- - ptm6840_get_count - get count value --------------------------------------------------*/ - -UINT16 ptm6840_get_count(device_t *device, int counter) -{ - return downcast<ptm6840_device*>(device)->ptm6840_get_count(counter); -} +//------------------------------------------------- +// count - get count value +//------------------------------------------------- -UINT16 ptm6840_device::ptm6840_get_count(int counter) +UINT16 ptm6840_device::count(int counter) const { return compute_counter(counter); } -/*------------------------------------------------------------ - ptm6840_set_ext_clock - set external clock frequency -------------------------------------------------------------*/ - -void ptm6840_set_ext_clock(device_t *device, int counter, double clock) -{ - downcast<ptm6840_device*>(device)->ptm6840_set_ext_clock(counter, clock); -} +//------------------------------------------------- +// set_ext_clock - set external clock frequency +//------------------------------------------------- -void ptm6840_device::ptm6840_set_ext_clock(int counter, double clock) +void ptm6840_device::set_ext_clock(int counter, double clock) { m_external_clock[counter] = clock; @@ -819,7 +761,7 @@ void ptm6840_device::ptm6840_set_ext_clock(int counter, double clock) int count; attotime duration; - /* Determine the number of clock periods before we expire */ + // Determine the number of clock periods before we expire count = m_counter[counter]; if (m_control_reg[counter] & 0x04) @@ -845,16 +787,11 @@ void ptm6840_device::ptm6840_set_ext_clock(int counter, double clock) } -/*------------------------------------------------------------ - ptm6840_get_ext_clock - get external clock frequency -------------------------------------------------------------*/ - -int ptm6840_get_ext_clock( device_t *device, int counter ) -{ - return downcast<ptm6840_device*>(device)->ptm6840_get_ext_clock(counter); -} +//------------------------------------------------- +// ext_clock - get external clock frequency +//------------------------------------------------- -int ptm6840_device::ptm6840_get_ext_clock(int counter) +int ptm6840_device::ext_clock(int counter) const { return m_external_clock[counter]; } |