diff options
Diffstat (limited to 'src/devices/machine/msm6242.cpp')
-rw-r--r-- | src/devices/machine/msm6242.cpp | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/src/devices/machine/msm6242.cpp b/src/devices/machine/msm6242.cpp index 62cb24b641f..59abd5313bc 100644 --- a/src/devices/machine/msm6242.cpp +++ b/src/devices/machine/msm6242.cpp @@ -14,9 +14,8 @@ ***************************************************************************/ #include "emu.h" -#include "machine/msm6242.h" +#include "msm6242.h" -#define LOG_GENERAL (1U << 0) #define LOG_UNMAPPED (1U << 1) #define LOG_IRQ (1U << 2) #define LOG_IRQ_ENABLE (1U << 3) @@ -53,7 +52,6 @@ enum MSM6242_REG_CF }; -#define TIMER_RTC_CALLBACK 1 @@ -77,12 +75,12 @@ DEFINE_DEVICE_TYPE(RTC72423, rtc72423_device, "rtc72423", "Epson RTC-72423 RTC") // msm6242_device - constructor //------------------------------------------------- -msm6242_device::msm6242_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +msm6242_device::msm6242_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : msm6242_device(mconfig, MSM6242, tag, owner, clock) { } -msm6242_device::msm6242_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) +msm6242_device::msm6242_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, type, tag, owner, clock) , device_rtc_interface(mconfig, *this) , m_out_int_handler(*this) @@ -97,11 +95,11 @@ msm6242_device::msm6242_device(const machine_config &mconfig, device_type type, void msm6242_device::device_start() { - m_out_int_handler.resolve(); - // let's call the timer callback every tick - m_timer = timer_alloc(TIMER_RTC_CALLBACK); + m_timer = timer_alloc(FUNC(msm6242_device::rtc_timer_callback), this); m_timer->adjust(attotime::zero); + m_timer_irq_clear = timer_alloc(FUNC(msm6242_device::rtc_irq_pulse_timer_callback), this); + m_timer_irq_clear->adjust(attotime::zero); // set up registers m_tick = 0; @@ -164,22 +162,6 @@ void msm6242_device::device_post_load() //------------------------------------------------- -// device_timer - called whenever a device timer -// fires -//------------------------------------------------- - -void msm6242_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) -{ - switch(id) - { - case TIMER_RTC_CALLBACK: - rtc_timer_callback(); - break; - } -} - - -//------------------------------------------------- // set_irq - set the IRQ flag and output //------------------------------------------------- @@ -190,8 +172,16 @@ void msm6242_device::set_irq(bool active) else m_reg[0] &= 0x0b; - if (!m_out_int_handler.isnull()) + if (!m_out_int_handler.isunset()) m_out_int_handler(active ? ASSERT_LINE : CLEAR_LINE); + + if (active) + { + if (!BIT(m_reg[1], 1)) // irq is pulsed + { + m_timer_irq_clear->adjust(attotime::from_nsec(7812500)); + } + } } @@ -199,7 +189,7 @@ void msm6242_device::set_irq(bool active) // irq //------------------------------------------------- -void msm6242_device::irq(uint8_t irq_type) +void msm6242_device::irq(u8 irq_type) { // are we actually raising this particular IRQ? if (m_irq_flag == 1 && m_irq_type == irq_type) @@ -218,28 +208,28 @@ void msm6242_device::irq(uint8_t irq_type) // bump //------------------------------------------------- -uint64_t msm6242_device::bump(int rtc_register, uint64_t delta, uint64_t register_min, uint64_t register_range) +u64 msm6242_device::bump(int rtc_register, u64 delta, u64 register_min, u64 register_range) { - uint64_t carry = 0; + u64 carry = 0; if (delta > 0) { // get the register value - uint64_t register_value = (rtc_register == RTC_TICKS) + u64 register_value = (rtc_register == RTC_TICKS) ? m_tick : get_clock_register(rtc_register); // increment the value - uint64_t new_register_value = ((register_value - register_min + delta) % register_range) + register_min; + u64 new_register_value = ((register_value - register_min + delta) % register_range) + register_min; // calculate the cary carry = ((register_value - register_min) + delta) / register_range; // store the new register value if (rtc_register == RTC_TICKS) - m_tick = (uint16_t) new_register_value; + m_tick = u16(new_register_value); else - set_clock_register(rtc_register, (int) new_register_value); + set_clock_register(rtc_register, int(new_register_value)); } return carry; @@ -251,7 +241,7 @@ uint64_t msm6242_device::bump(int rtc_register, uint64_t delta, uint64_t registe // current_time //------------------------------------------------- -uint64_t msm6242_device::current_time() +u64 msm6242_device::current_time() { return machine().time().as_ticks(clock()); } @@ -265,10 +255,10 @@ uint64_t msm6242_device::current_time() void msm6242_device::update_rtc_registers() { // get the absolute current time, in ticks - uint64_t curtime = current_time(); + u64 curtime = current_time(); // how long as it been since we last updated? - uint64_t delta = curtime - m_last_update_time; + u64 delta = curtime - m_last_update_time; // set current time m_last_update_time = curtime; @@ -278,7 +268,7 @@ void msm6242_device::update_rtc_registers() return; // ticks - if ((m_tick % 200) != (int)((delta + m_tick) % 0x200)) + if ((m_tick / 0x200) != int((delta + m_tick) / 0x200)) irq(IRQ_64THSECOND); delta = bump(RTC_TICKS, delta, 0, 0x8000); if (delta == 0) @@ -315,21 +305,21 @@ void msm6242_device::update_rtc_registers() void msm6242_device::update_timer() { - uint64_t callback_ticks = 0; + u64 callback_ticks = 0; attotime callback_time = attotime::never; // we only need to call back if the IRQ flag is on, and we have a handler - if (!m_out_int_handler.isnull() && m_irq_flag == 1) + if (!m_out_int_handler.isunset() && m_irq_flag == 1) { switch(m_irq_type) { case IRQ_HOUR: callback_ticks += (59 - get_clock_register(RTC_MINUTE)) * (0x8000 * 60); - // fall through + [[fallthrough]]; case IRQ_MINUTE: callback_ticks += (59 - get_clock_register(RTC_SECOND)) * 0x8000; - // fall through + [[fallthrough]]; case IRQ_SECOND: callback_ticks += 0x8000 - m_tick; @@ -345,10 +335,10 @@ void msm6242_device::update_timer() if (callback_ticks > 0) { // get the current time - uint64_t curtime = current_time(); + u64 curtime = current_time(); // we need the absolute callback time, in ticks - uint64_t absolute_callback_ticks = curtime + callback_ticks; + u64 absolute_callback_ticks = curtime + callback_ticks; // convert that to an attotime attotime absolute_callback_time = attotime::from_ticks(absolute_callback_ticks, clock()); @@ -377,7 +367,7 @@ void msm6242_device::rtc_clock_updated(int year, int month, int day, int day_of_ // rtc_timer_callback //------------------------------------------------- -void msm6242_device::rtc_timer_callback() +TIMER_CALLBACK_MEMBER(msm6242_device::rtc_timer_callback) { update_rtc_registers(); update_timer(); @@ -386,14 +376,25 @@ void msm6242_device::rtc_timer_callback() //------------------------------------------------- +// rtc_irq_pulse_timer_callback +//------------------------------------------------- + +TIMER_CALLBACK_MEMBER(msm6242_device::rtc_irq_pulse_timer_callback) +{ + set_irq(false); +} + + + +//------------------------------------------------- // get_clock_nibble //------------------------------------------------- -uint8_t msm6242_device::get_clock_nibble(int rtc_register, bool high) +u8 msm6242_device::get_clock_nibble(int rtc_register, bool high) { int value = get_clock_register(rtc_register); value /= high ? 10 : 1; - return (uint8_t) ((value % 10) & 0x0F); + return u8((value % 10) & 0x0F); } @@ -402,7 +403,7 @@ uint8_t msm6242_device::get_clock_nibble(int rtc_register, bool high) // get_clock_nibble //------------------------------------------------- -const char *msm6242_device::irq_type_string(uint8_t irq_type) +const char *msm6242_device::irq_type_string(u8 irq_type) { switch(irq_type) { @@ -424,10 +425,10 @@ const char *msm6242_device::irq_type_string(uint8_t irq_type) // read //------------------------------------------------- -READ8_MEMBER( msm6242_device::read ) +u8 msm6242_device::read(offs_t offset) { int hour, pm; - uint8_t result; + u8 result; // update the registers; they may have changed update_rtc_registers(); @@ -498,7 +499,7 @@ READ8_MEMBER( msm6242_device::read ) break; case MSM6242_REG_W: - result = (uint8_t) (get_clock_register(RTC_DAY_OF_WEEK) - 1); + result = u8(get_clock_register(RTC_DAY_OF_WEEK) - 1); break; case MSM6242_REG_CD: @@ -522,7 +523,7 @@ READ8_MEMBER( msm6242_device::read ) // write //------------------------------------------------- -WRITE8_MEMBER( msm6242_device::write ) +void msm6242_device::write(offs_t offset, u8 data) { switch(offset) { @@ -535,6 +536,7 @@ WRITE8_MEMBER( msm6242_device::write ) { LOGIRQENABLE("%s: MSM6242 acknowledging irq\n", machine().describe_context()); set_irq(false); + m_timer_irq_clear->adjust(attotime::zero); } m_reg[0] = (data & 0x09) | (m_reg[0] & 0x06); break; @@ -544,7 +546,7 @@ WRITE8_MEMBER( msm6242_device::write ) // --x- STD // ---x MASK m_reg[1] = data & 0x0f; - if((data & 3) == 0) // MASK & STD = 0 + if((data & 1) == 0) // MASK = 0 { m_irq_flag = 1; m_irq_type = (data & 0xc) >> 2; @@ -587,7 +589,7 @@ WRITE8_MEMBER( msm6242_device::write ) // rtc62421_device - constructor //------------------------------------------------- -rtc62421_device::rtc62421_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +rtc62421_device::rtc62421_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : msm6242_device(mconfig, RTC62421, tag, owner, clock) { } @@ -597,7 +599,7 @@ rtc62421_device::rtc62421_device(const machine_config &mconfig, const char *tag, // rtc62423_device - constructor //------------------------------------------------- -rtc62423_device::rtc62423_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +rtc62423_device::rtc62423_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : msm6242_device(mconfig, RTC62423, tag, owner, clock) { } @@ -607,7 +609,7 @@ rtc62423_device::rtc62423_device(const machine_config &mconfig, const char *tag, // rtc72421_device - constructor //------------------------------------------------- -rtc72421_device::rtc72421_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +rtc72421_device::rtc72421_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : msm6242_device(mconfig, RTC72421, tag, owner, clock) { } @@ -617,7 +619,7 @@ rtc72421_device::rtc72421_device(const machine_config &mconfig, const char *tag, // rtc72423_device - constructor //------------------------------------------------- -rtc72423_device::rtc72423_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +rtc72423_device::rtc72423_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : msm6242_device(mconfig, RTC72423, tag, owner, clock) { } |