diff options
author | 2018-04-30 12:14:27 +0200 | |
---|---|---|
committer | 2018-04-30 12:14:27 +0200 | |
commit | 1e82f36a94b1b56118ae461ae7c410a39f942d42 (patch) | |
tree | 4b175632f1fac54bb4048bb093285ecef5f13c33 | |
parent | 507399697b94fb3a7a206f98a3d3903413e8a604 (diff) |
-adc0808: Reduced CPU overhead by smarter timer usage. [Ryan Holtz]
-rw-r--r-- | src/devices/machine/adc0808.cpp | 58 | ||||
-rw-r--r-- | src/devices/machine/adc0808.h | 3 |
2 files changed, 26 insertions, 35 deletions
diff --git a/src/devices/machine/adc0808.cpp b/src/devices/machine/adc0808.cpp index b74939b83c5..b2bb8876703 100644 --- a/src/devices/machine/adc0808.cpp +++ b/src/devices/machine/adc0808.cpp @@ -45,7 +45,7 @@ adc0808_device::adc0808_device(const machine_config &mconfig, device_type type, m_in_cb{ {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this} }, m_state(STATE_IDLE), m_cycle_timer(nullptr), - m_start(0), m_cycle(0), m_step(0), m_address(0), m_sar(0xff), m_eoc(true), m_eoc_pending(false) + m_start(0), m_address(0), m_sar(0xff), m_eoc(1) { } @@ -92,12 +92,9 @@ void adc0808_device::device_start() // register for save states save_item(NAME(m_state)); save_item(NAME(m_start)); - save_item(NAME(m_cycle)); - save_item(NAME(m_step)); save_item(NAME(m_address)); save_item(NAME(m_sar)); save_item(NAME(m_eoc)); - save_item(NAME(m_eoc_pending)); } //------------------------------------------------- @@ -106,37 +103,34 @@ void adc0808_device::device_start() void adc0808_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { - // eoc is delayed one cycle - if (m_eoc_pending) + switch (m_state) { - m_eoc = true; - m_eoc_cb(1); - m_eoc_ff_cb(1); - m_eoc_pending = false; - } - - // start of conversion cycle - if (m_cycle == 0 && m_state == STATE_CONVERSION_START) - m_state = STATE_CONVERSION_RUNNING; - - // end of conversion cycle - if (m_cycle == 7 && m_state == STATE_CONVERSION_RUNNING) - { - // the conversion takes 8 steps every 8 cycles - if (m_step++ == 7) - { - m_step = 0; + case STATE_IDLE: + m_cycle_timer->adjust(attotime::never); + m_eoc = 1; + m_eoc_cb(m_eoc); + m_eoc_ff_cb(1); + return; + + // start of conversion cycle + case STATE_CONVERSION_START: + m_state = STATE_CONVERSION_RUNNING; + // the conversion takes 8 steps every 8 cycles + m_cycle_timer->adjust(attotime::from_hz(clock()) * 63); + return; + + // end of conversion cycle + case STATE_CONVERSION_RUNNING: m_sar = m_in_cb[m_address](0); - m_eoc_pending = true; m_state = STATE_IDLE; if (VERBOSE) logerror("Conversion finished, result %02x\n", m_sar); - } - } - // next cycle - m_cycle = (m_cycle + 1) & 7; + // eoc is delayed by one cycle + m_cycle_timer->adjust(attotime::from_hz(clock())); + break; + } } @@ -168,13 +162,13 @@ WRITE_LINE_MEMBER( adc0808_device::start_w ) if (m_start == 1 && state == 0) { m_state = STATE_CONVERSION_START; + m_cycle_timer->adjust(attotime::zero); } else if (m_start == 0 && state == 1) { m_sar = 0; - m_eoc = false; - m_eoc_cb(0); - m_eoc_pending = false; + m_eoc = 0; + m_eoc_cb(m_eoc); } m_start = state; @@ -182,7 +176,7 @@ WRITE_LINE_MEMBER( adc0808_device::start_w ) READ_LINE_MEMBER( adc0808_device::eoc_r ) { - return m_eoc ? 1 : 0; + return m_eoc; } WRITE8_MEMBER( adc0808_device::address_offset_start_w ) diff --git a/src/devices/machine/adc0808.h b/src/devices/machine/adc0808.h index 74a0b42cd57..5b9c97dc69f 100644 --- a/src/devices/machine/adc0808.h +++ b/src/devices/machine/adc0808.h @@ -127,12 +127,9 @@ private: // state int m_start; - int m_cycle; - int m_step; int m_address; uint8_t m_sar; bool m_eoc; - bool m_eoc_pending; }; class adc0809_device : public adc0808_device |