summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/ds2401.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/ds2401.cpp')
-rw-r--r--src/devices/machine/ds2401.cpp133
1 files changed, 66 insertions, 67 deletions
diff --git a/src/devices/machine/ds2401.cpp b/src/devices/machine/ds2401.cpp
index a5fea5b189b..758d4405013 100644
--- a/src/devices/machine/ds2401.cpp
+++ b/src/devices/machine/ds2401.cpp
@@ -9,7 +9,9 @@
*/
#include "emu.h"
-#include "machine/ds2401.h"
+#include "ds2401.h"
+
+#include <cstdarg>
#define VERBOSE_LEVEL 0
@@ -60,8 +62,8 @@ void ds2401_device::device_start()
save_item(NAME(m_rx));
save_item(NAME(m_tx));
- m_timer_main = timer_alloc(TIMER_MAIN);
- m_timer_reset = timer_alloc(TIMER_RESET);
+ m_timer_main = timer_alloc(FUNC(ds2401_device::main_tick), this);
+ m_timer_reset = timer_alloc(FUNC(ds2401_device::reset_tick), this);
}
void ds2401_device::device_reset()
@@ -92,85 +94,82 @@ void ds2401_device::device_reset()
memset(m_data, 0, SIZE_DATA);
}
-void ds2401_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
+TIMER_CALLBACK_MEMBER(ds2401_device::reset_tick)
{
- switch(id)
+ verboselog(1, "timer_reset\n");
+ m_state = STATE_RESET;
+ m_timer_reset->adjust(attotime::never);
+}
+
+TIMER_CALLBACK_MEMBER(ds2401_device::main_tick)
+{
+ switch(m_state)
{
- case TIMER_RESET:
- verboselog(1, "timer_reset\n");
- m_state = STATE_RESET;
- m_timer_reset->adjust(attotime::never);
+ case STATE_RESET1:
+ verboselog(2, "timer_main state_reset1 %d\n", m_rx);
+ m_tx = false;
+ m_state = STATE_RESET2;
+ m_timer_main->adjust(t_pdl);
break;
- case TIMER_MAIN:
- switch(m_state)
- {
- case STATE_RESET1:
- verboselog(2, "timer_main state_reset1 %d\n", m_rx);
- m_tx = false;
- m_state = STATE_RESET2;
- m_timer_main->adjust(t_pdl);
- break;
+ case STATE_RESET2:
+ verboselog(2, "timer_main state_reset2 %d\n", m_rx);
+ m_tx = true;
+ m_bit = 0;
+ m_shift = 0;
+ m_state = STATE_COMMAND;
+ break;
- case STATE_RESET2:
- verboselog(2, "timer_main state_reset2 %d\n", m_rx);
- m_tx = true;
- m_bit = 0;
- m_shift = 0;
- m_state = STATE_COMMAND;
- break;
+ case STATE_COMMAND:
+ verboselog(2, "timer_main state_command %d\n", m_rx);
- case STATE_COMMAND:
- verboselog(2, "timer_main state_command %d\n", m_rx);
+ m_shift >>= 1;
+ if(m_rx)
+ {
+ m_shift |= 0x80;
+ }
- m_shift >>= 1;
- if(m_rx)
+ m_bit++;
+ if(m_bit == 8)
+ {
+ switch(m_shift)
{
- m_shift |= 0x80;
- }
+ case COMMAND_READROM:
+ case COMMAND_READROM_COMPAT:
+ verboselog(1, "timer_main readrom\n");
+ m_bit = 0;
+ m_byte = 0;
+ m_state = STATE_READROM;
+ break;
- m_bit++;
- if(m_bit == 8)
- {
- switch(m_shift)
- {
- case COMMAND_READROM:
- case COMMAND_READROM_COMPAT:
- verboselog(1, "timer_main readrom\n");
- m_bit = 0;
- m_byte = 0;
- m_state = STATE_READROM;
- break;
-
- default:
- verboselog(0, "timer_main command not handled %02x\n", m_shift);
- m_state = STATE_IDLE;
- break;
- }
+ default:
+ verboselog(0, "timer_main command not handled %02x\n", m_shift);
+ m_state = STATE_IDLE;
+ break;
}
- break;
+ }
+ break;
- case STATE_READROM:
- m_tx = true;
+ case STATE_READROM:
+ m_tx = true;
- if( m_byte == SIZE_DATA )
- {
- verboselog(1, "timer_main readrom finished\n");
- m_state = STATE_IDLE;
- }
- else
- {
- verboselog(2, "timer_main readrom window closed\n");
- }
- break;
- default:
- verboselog(0, "timer_main state not handled: %d\n", m_state);
- break;
+ if( m_byte == SIZE_DATA )
+ {
+ verboselog(1, "timer_main readrom finished\n");
+ m_state = STATE_IDLE;
}
+ else
+ {
+ verboselog(2, "timer_main readrom window closed\n");
+ }
+ break;
+ default:
+ verboselog(0, "timer_main state not handled: %d\n", m_state);
+ break;
}
}
-WRITE_LINE_MEMBER( ds2401_device::write )
+void ds2401_device::write(int state)
{
verboselog(1, "write(%d)\n", state);
@@ -230,7 +229,7 @@ WRITE_LINE_MEMBER( ds2401_device::write )
m_rx = state;
}
-READ_LINE_MEMBER( ds2401_device::read )
+int ds2401_device::read()
{
verboselog(2, "read %d\n", m_tx && m_rx);
return m_tx && m_rx;