summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/upd7002.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/upd7002.cpp')
-rw-r--r--src/devices/machine/upd7002.cpp64
1 files changed, 29 insertions, 35 deletions
diff --git a/src/devices/machine/upd7002.cpp b/src/devices/machine/upd7002.cpp
index 7dd57725147..ab97f46b4b3 100644
--- a/src/devices/machine/upd7002.cpp
+++ b/src/devices/machine/upd7002.cpp
@@ -1,12 +1,8 @@
// license:BSD-3-Clause
// copyright-holders:Gordon Jefferyes
/******************************************************************************
- uPD7002 Analogue to Digital Converter
-
- MESS Driver By:
- Gordon Jefferyes
- mess_bbc@gjeffery.dircon.co.uk
+ uPD7002 Analogue to Digital Converter
******************************************************************************/
@@ -19,7 +15,14 @@
DEFINE_DEVICE_TYPE(UPD7002, upd7002_device, "upd7002", "uPD7002 ADC")
upd7002_device::upd7002_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
- : device_t(mconfig, UPD7002, tag, owner, clock), m_status(0), m_data1(0), m_data0(0), m_digitalvalue(0), m_conversion_counter(0)
+ : device_t(mconfig, UPD7002, tag, owner, clock)
+ , m_status(0)
+ , m_data1(0)
+ , m_data0(0)
+ , m_digitalvalue(0)
+ , m_conversion_counter(0)
+ , m_get_analogue_cb(*this)
+ , m_eoc_cb(*this)
{
}
@@ -29,8 +32,9 @@ upd7002_device::upd7002_device(const machine_config &mconfig, const char *tag, d
void upd7002_device::device_start()
{
- m_get_analogue_cb.bind_relative_to(*owner());
- m_eoc_cb.bind_relative_to(*owner());
+ m_conversion_timer = timer_alloc(FUNC(upd7002_device::conversion_complete), this);
+ m_get_analogue_cb.resolve();
+ m_eoc_cb.resolve_safe();
// register for state saving
save_item(NAME(m_status));
@@ -59,37 +63,27 @@ void upd7002_device::device_reset()
*****************************************************************************/
-READ_LINE_MEMBER( upd7002_device::eoc_r )
+int upd7002_device::eoc_r()
{
return BIT(m_status, 7);
}
-void upd7002_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+TIMER_CALLBACK_MEMBER(upd7002_device::conversion_complete)
{
- switch (id)
+ if (param == m_conversion_counter)
{
- case TIMER_CONVERSION_COMPLETE:
- {
- int counter_value = param;
- if (counter_value == m_conversion_counter)
- {
- // this really always does a 12 bit conversion
- m_data1 = m_digitalvalue >> 8;
- m_data0 = m_digitalvalue & 0xf0;
-
- // set the status register with top 2 MSB, not busy and conversion complete
- m_status = (m_status & 0x0f) | ((m_data1 & 0xc0) >> 2) | 0x40;
-
- // call the EOC function with EOC from status
- // eoc_r(0) this has just been set to 0
- if (!m_eoc_cb.isnull()) m_eoc_cb(0);
- m_conversion_counter=0;
- }
- }
- break;
- default:
- throw emu_fatalerror("Unknown id in upd7002_device::device_timer");
+ // this really always does a 12 bit conversion
+ m_data1 = m_digitalvalue >> 8;
+ m_data0 = m_digitalvalue & 0xf0;
+
+ // set the status register with top 2 MSB, not busy and conversion complete
+ m_status = (m_status & 0x0f) | ((m_data1 & 0xc0) >> 2) | 0x40;
+
+ // call the EOC function with EOC from status
+ // eoc_r(0) this has just been set to 0
+ m_eoc_cb(0);
+ m_conversion_counter = 0;
}
}
@@ -138,7 +132,7 @@ void upd7002_device::write(offs_t offset, uint8_t data)
// call the EOC function with EOC from status
// eoc_r(0) this has just been set to 1
- if (!m_eoc_cb.isnull()) m_eoc_cb(1);
+ m_eoc_cb(1);
/* the uPD7002 works by sampling the analogue value at the start of the conversion
so it is read hear and stored until the end of the A to D conversion */
@@ -152,12 +146,12 @@ void upd7002_device::write(offs_t offset, uint8_t data)
if (m_status & 0x08)
{
// 12 bit conversion takes 10ms
- timer_set(attotime::from_msec(10), TIMER_CONVERSION_COMPLETE, m_conversion_counter);
+ m_conversion_timer->adjust(attotime::from_msec(10), m_conversion_counter);
}
else
{
// 8 bit conversion takes 4ms
- timer_set(attotime::from_msec(4), TIMER_CONVERSION_COMPLETE, m_conversion_counter);
+ m_conversion_timer->adjust(attotime::from_msec(4), m_conversion_counter);
}
break;