diff options
Diffstat (limited to 'src/devices/machine/msm58321.cpp')
-rw-r--r-- | src/devices/machine/msm58321.cpp | 124 |
1 files changed, 63 insertions, 61 deletions
diff --git a/src/devices/machine/msm58321.cpp b/src/devices/machine/msm58321.cpp index 2dc268d8bc1..aa0c30987f6 100644 --- a/src/devices/machine/msm58321.cpp +++ b/src/devices/machine/msm58321.cpp @@ -189,7 +189,8 @@ msm58321_device::msm58321_device(const machine_config &mconfig, const char *tag, m_test(0), m_cs1(0), m_address(0xf), - m_reg{} + m_reg{}, + m_khz_ctr(0) { } @@ -200,23 +201,16 @@ msm58321_device::msm58321_device(const machine_config &mconfig, const char *tag, void msm58321_device::device_start() { - // resolve callbacks - m_d0_handler.resolve_safe(); - m_d1_handler.resolve_safe(); - m_d2_handler.resolve_safe(); - m_d3_handler.resolve_safe(); - m_busy_handler.resolve_safe(); - // allocate timers - m_clock_timer = timer_alloc(TIMER_CLOCK); + m_clock_timer = timer_alloc(FUNC(msm58321_device::clock_tick), this); m_clock_timer->adjust(clocks_to_attotime(32768/1024), 0, clocks_to_attotime(32768/1024)); // busy signal active period is approximately 427 µs - m_busy_timer = timer_alloc(TIMER_BUSY); + m_busy_timer = timer_alloc(FUNC(msm58321_device::release_busy), this); m_busy_timer->adjust(clocks_to_attotime(32768 - 14), 0, clocks_to_attotime(32768)); // standard signal active period is approximately 122 µs - m_standard_timer = timer_alloc(TIMER_STANDARD); + m_standard_timer = timer_alloc(FUNC(msm58321_device::assert_standard), this); m_standard_timer->adjust(clocks_to_attotime(32768-4), 0, clocks_to_attotime(32768)); // state saving @@ -238,60 +232,64 @@ void msm58321_device::device_start() save_item(NAME(m_cs1)); save_item(NAME(m_address)); save_item(NAME(m_reg)); + save_item(NAME(m_khz_ctr)); } //------------------------------------------------- -// device_timer - handler timer events +// clock_tick - advance the RTC //------------------------------------------------- -void msm58321_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +TIMER_CALLBACK_MEMBER(msm58321_device::clock_tick) { - switch (id) + if (m_khz_ctr & 1) + { + m_reg[REGISTER_REF0] |= 1; + m_reg[REGISTER_REF1] |= 1; + } + else { - case TIMER_CLOCK: + m_reg[REGISTER_REF0] &= ~1; + m_reg[REGISTER_REF1] &= ~1; + } - if (m_khz_ctr & 1) + if (++m_khz_ctr >= 1024) + { + m_khz_ctr = 0; + if (!m_stop) { - m_reg[REGISTER_REF0] |= 1; - m_reg[REGISTER_REF1] |= 1; + advance_seconds(); } - else + + if (!m_busy) { - m_reg[REGISTER_REF0] &= ~1; - m_reg[REGISTER_REF1] &= ~1; + m_busy = 1; + m_busy_handler(m_busy); } + } +} - if (++m_khz_ctr >= 1024) - { - m_khz_ctr = 0; - if (!m_stop) - { - advance_seconds(); - } - if (!m_busy) - { - m_busy = 1; - m_busy_handler(m_busy); - } - } - break; +//------------------------------------------------- +// release_busy - release the 'busy' line after +// an appropriate amount of time +//------------------------------------------------- - case TIMER_BUSY: - if (!m_cs1 || !m_cs2 || !m_write || m_address != REGISTER_RESET) - { - m_busy = 0; - m_busy_handler(m_busy); - } - break; - case TIMER_STANDARD: - m_reg[REGISTER_REF0] = 0x0e; - m_reg[REGISTER_REF1] = 0x0e; - break; +TIMER_CALLBACK_MEMBER(msm58321_device::release_busy) +{ + if (!m_cs1 || !m_cs2 || !m_write || m_address != REGISTER_RESET) + { + m_busy = 0; + m_busy_handler(m_busy); } } +TIMER_CALLBACK_MEMBER(msm58321_device::assert_standard) +{ + m_reg[REGISTER_REF0] = 0x0e; + m_reg[REGISTER_REF1] = 0x0e; +} + void msm58321_device::update_standard() { uint8_t reg = 0; @@ -348,11 +346,14 @@ void msm58321_device::nvram_default() // .nv file //------------------------------------------------- -void msm58321_device::nvram_read(emu_file &file) +bool msm58321_device::nvram_read(util::read_stream &file) { - file.read(m_reg.data(), m_reg.size()); + auto const [err, actual] = read(file, m_reg.data(), m_reg.size()); + if (err || (actual != m_reg.size())) + return false; clock_updated(); + return true; } @@ -361,9 +362,10 @@ void msm58321_device::nvram_read(emu_file &file) // .nv file //------------------------------------------------- -void msm58321_device::nvram_write(emu_file &file) +bool msm58321_device::nvram_write(util::write_stream &file) { - file.write(m_reg.data(), m_reg.size()); + auto const [err, actual] = write(file, m_reg.data(), m_reg.size()); + return !err; } //------------------------------------------------- @@ -506,7 +508,7 @@ void msm58321_device::update_input() // cs2_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::cs2_w ) +void msm58321_device::cs2_w(int state) { if (m_cs2 != state) { @@ -523,7 +525,7 @@ WRITE_LINE_MEMBER( msm58321_device::cs2_w ) // write_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::write_w ) +void msm58321_device::write_w(int state) { if (m_write != state) { @@ -540,7 +542,7 @@ WRITE_LINE_MEMBER( msm58321_device::write_w ) // read_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::read_w ) +void msm58321_device::read_w(int state) { if (m_read != state) { @@ -558,7 +560,7 @@ WRITE_LINE_MEMBER( msm58321_device::read_w ) // d0_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::d0_w ) +void msm58321_device::d0_w(int state) { if (m_d0_in != state) { @@ -573,7 +575,7 @@ WRITE_LINE_MEMBER( msm58321_device::d0_w ) // d1_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::d1_w ) +void msm58321_device::d1_w(int state) { if (m_d1_in != state) { @@ -588,7 +590,7 @@ WRITE_LINE_MEMBER( msm58321_device::d1_w ) // d2_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::d2_w ) +void msm58321_device::d2_w(int state) { if (m_d2_in != state) { @@ -603,7 +605,7 @@ WRITE_LINE_MEMBER( msm58321_device::d2_w ) // d3_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::d3_w ) +void msm58321_device::d3_w(int state) { if (m_d3_in != state) { @@ -618,7 +620,7 @@ WRITE_LINE_MEMBER( msm58321_device::d3_w ) // address_write_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::address_write_w ) +void msm58321_device::address_write_w(int state) { if (m_address_write != state) { @@ -635,7 +637,7 @@ WRITE_LINE_MEMBER( msm58321_device::address_write_w ) // stop_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::stop_w ) +void msm58321_device::stop_w(int state) { if (m_stop != state) { @@ -650,7 +652,7 @@ WRITE_LINE_MEMBER( msm58321_device::stop_w ) // test_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::test_w ) +void msm58321_device::test_w(int state) { if (m_test != state) { @@ -666,7 +668,7 @@ WRITE_LINE_MEMBER( msm58321_device::test_w ) // cs1_w - //------------------------------------------------- -WRITE_LINE_MEMBER( msm58321_device::cs1_w ) +void msm58321_device::cs1_w(int state) { if (m_cs1 != state) { |