diff options
Diffstat (limited to 'src/devices/machine/vrc5074.cpp')
-rw-r--r-- | src/devices/machine/vrc5074.cpp | 66 |
1 files changed, 16 insertions, 50 deletions
diff --git a/src/devices/machine/vrc5074.cpp b/src/devices/machine/vrc5074.cpp index ade82af624e..33620edb4f2 100644 --- a/src/devices/machine/vrc5074.cpp +++ b/src/devices/machine/vrc5074.cpp @@ -241,6 +241,7 @@ void vrc5074_device::device_start() save_item(NAME(m_nile_irq_state)); save_item(NAME(m_sdram_addr)); save_item(NAME(m_uart_irq)); + save_item(NAME(m_timer_period)); machine().save().register_postload(save_prepost_delegate(FUNC(vrc5074_device::postload), this)); } @@ -745,16 +746,7 @@ TIMER_CALLBACK_MEMBER(vrc5074_device::nile_timer_callback) /* adjust the timer to fire again */ { - uint32_t scale = regs[0]; - if (regs[1] & 2) { - uint32_t scaleSrc = (regs[1] >> 2) & 0x3; - uint32_t *scaleReg = &m_cpu_regs[NREG_T0CTRL + scaleSrc * 4]; - scale *= scaleReg[0]; - //logerror("Unexpected value: timer %d is prescaled\n", which); - logerror("Timer Scaling value: timer %d is prescaled from %08X to %08X\n", which, regs[0], scale); - } - if (scale != 0) - m_timer[which]->adjust(TIMER_PERIOD * scale, which); + m_timer[which]->adjust(attotime::from_double(m_timer_period[which]), which); } /* trigger the interrupt */ @@ -837,15 +829,8 @@ READ32_MEMBER(vrc5074_device::cpu_reg_r) which = (offset - NREG_T0CNTR) / 4; if (m_cpu_regs[offset - 1] & 1) { - //if (m_cpu_regs[offset - 1] & 2) - // logerror("Unexpected value: timer %d is prescaled\n", which); - uint32_t scale = 1; - if (m_cpu_regs[offset - 1] & 2) { - uint32_t scaleSrc = (m_cpu_regs[offset - 1] >> 2) & 0x3; - scale = m_cpu_regs[NREG_T0CTRL + scaleSrc * 4]; - logerror("Timer value: timer %d is prescaled by \n", which, scale); - } - result = m_cpu_regs[offset + 1] = m_timer[which]->remaining().as_double() * (double)SYSTEM_CLOCK / scale; + // Should check for cascaded timer + result = m_cpu_regs[offset] = m_timer[which]->remaining().as_double() * SYSTEM_CLOCK; } if (LOG_TIMERS) logerror("%08X:NILE READ: timer %d counter(%03X) = %08X\n", m_cpu_space->device().safe_pc(), which, offset * 4, result); @@ -961,37 +946,26 @@ WRITE32_MEMBER(vrc5074_device::cpu_reg_w) case NREG_T2CTRL + 1: /* general purpose timer control (control bits) */ case NREG_T3CTRL + 1: /* watchdog timer control (control bits) */ which = (offset - NREG_T0CTRL) / 4; - if (LOG_NILE) logerror("%08X:NILE WRITE: timer %d control(%03X) = %08X & %08X\n", m_cpu_space->device().safe_pc(), which, offset * 4, data, mem_mask); + if (LOG_NILE | LOG_TIMERS) logerror("%08X:NILE WRITE: timer %d control(%03X) = %08X & %08X\n", m_cpu_space->device().safe_pc(), which, offset * 4, data, mem_mask); logit = 0; - + m_timer_period[which] = (uint64_t(m_cpu_regs[NREG_T0CTRL + which * 4]) + 1) * attotime::from_hz(SYSTEM_CLOCK).as_double(); + if (m_cpu_regs[offset] & 2) { + // Cascade timer + uint32_t scaleSrc = (m_cpu_regs[offset] >> 2) & 0x3; + m_timer_period[which] += (uint64_t(m_cpu_regs[NREG_T0CTRL + scaleSrc * 4]) + 1) * attotime::from_hz(SYSTEM_CLOCK).as_double(); + logerror("Timer scale: timer %d is scaled by %08X\n", which, m_cpu_regs[NREG_T0CTRL + which * 4]); + } /* timer just enabled? */ if (!(olddata & 1) && (m_cpu_regs[offset] & 1)) { - uint32_t scale = m_cpu_regs[offset - 1]; - //if (m_cpu_regs[offset] & 2) - // logerror("Unexpected value: timer %d is prescaled\n", which); - if (m_cpu_regs[offset] & 2) { - uint32_t scaleSrc = (m_cpu_regs[offset] >> 2) & 0x3; - scale *= m_cpu_regs[NREG_T0CTRL + scaleSrc * 4]; - logerror("Timer scale: timer %d is scaled by %08X\n", which, m_cpu_regs[NREG_T0CTRL + which * 4]); - } - if (scale != 0) - m_timer[which]->adjust(TIMER_PERIOD * scale, which); - if (LOG_TIMERS) logerror("Starting timer %d at a rate of %f Hz scale = %08X\n", which, ATTOSECONDS_TO_HZ((TIMER_PERIOD * (m_cpu_regs[offset + 1] + 1)).attoseconds()), scale); + m_timer[which]->adjust(attotime::from_double(m_timer_period[which]), which); + if (LOG_TIMERS) logerror("Starting timer %d at a rate of %f Hz\n", which, ATTOSECONDS_TO_HZ(attotime::from_double(m_timer_period[which]).as_attoseconds())); } /* timer disabled? */ else if ((olddata & 1) && !(m_cpu_regs[offset] & 1)) { - //if (m_cpu_regs[offset] & 2) - // logerror("Unexpected value: timer %d is prescaled\n", which); - uint32_t scale = 1; - if (m_cpu_regs[offset] & 2) { - uint32_t scaleSrc = (m_cpu_regs[offset] >> 2) & 0x3; - scale = m_cpu_regs[NREG_T0CTRL + scaleSrc * 4]; - logerror("Timer scale: timer %d is scaled by %08X\n", which, scale); - } - m_cpu_regs[offset + 1] = m_timer[which]->remaining().as_double() * SYSTEM_CLOCK / scale; + m_cpu_regs[offset + 1] = m_timer[which]->remaining().as_double() * SYSTEM_CLOCK; m_timer[which]->adjust(attotime::never, which); } break; @@ -1006,15 +980,7 @@ WRITE32_MEMBER(vrc5074_device::cpu_reg_w) if (m_cpu_regs[offset - 1] & 1) { - //if (m_cpu_regs[offset - 1] & 2) - // logerror("Unexpected value: timer %d is prescaled\n", which); - uint32_t scale = 1; - if (m_cpu_regs[offset - 1] & 2) { - uint32_t scaleSrc = (m_cpu_regs[offset - 1] >> 2) & 0x3; - scale = m_cpu_regs[NREG_T0CTRL + scaleSrc * 4]; - logerror("Timer scale: timer %d is scaled by %08X\n", which, scale); - } - m_timer[which]->adjust(TIMER_PERIOD * m_cpu_regs[offset] * scale, which); + m_timer[which]->adjust(attotime::from_hz(SYSTEM_CLOCK) * m_cpu_regs[offset], which); } break; } |