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.cpp53
1 files changed, 20 insertions, 33 deletions
diff --git a/src/devices/machine/upd7002.cpp b/src/devices/machine/upd7002.cpp
index 2d4d2ad4bc6..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
******************************************************************************/
@@ -36,8 +32,9 @@ upd7002_device::upd7002_device(const machine_config &mconfig, const char *tag, d
void upd7002_device::device_start()
{
+ m_conversion_timer = timer_alloc(FUNC(upd7002_device::conversion_complete), this);
m_get_analogue_cb.resolve();
- m_eoc_cb.resolve();
+ m_eoc_cb.resolve_safe();
// register for state saving
save_item(NAME(m_status));
@@ -66,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;
}
}
@@ -145,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 */
@@ -159,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;