mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-12-24 12:30:05 +00:00
Fix RTC not always updating
Fixed an issue where RTC was not being updated if only the upper 32 bits (seconds) was read. Also simplified things by always updating the timestamp instead of only when the seconds changes.
This commit is contained in:
parent
01d7d6bac3
commit
50dbd5eccd
@ -855,18 +855,20 @@ void dppc_interpreter::ppc_mtmsr() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t calc_rtcl_value()
|
static inline void calc_rtcl_value()
|
||||||
{
|
{
|
||||||
uint64_t diff = get_virt_time_ns() - rtc_timestamp;
|
uint64_t new_ts = get_virt_time_ns();
|
||||||
|
uint64_t diff = new_ts - rtc_timestamp;
|
||||||
uint64_t rtc_inc = diff * tbr_freq_hz / NS_PER_SEC;
|
uint64_t rtc_inc = diff * tbr_freq_hz / NS_PER_SEC;
|
||||||
uint64_t rtc_l = rtc_lo + (rtc_inc << 7);
|
uint64_t rtc_l = rtc_lo + (rtc_inc << 7);
|
||||||
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
|
if (rtc_l >= ONE_BILLION_NS) { // check RTCL overflow
|
||||||
rtc_hi += rtc_l / ONE_BILLION_NS;
|
rtc_hi += rtc_l / ONE_BILLION_NS;
|
||||||
rtc_lo = rtc_l % ONE_BILLION_NS;
|
rtc_lo = rtc_l % ONE_BILLION_NS;
|
||||||
rtc_timestamp = get_virt_time_ns();
|
|
||||||
rtc_l = rtc_lo;
|
|
||||||
}
|
}
|
||||||
return rtc_l & 0x3FFFFF80UL;
|
else {
|
||||||
|
rtc_lo = rtc_l;
|
||||||
|
}
|
||||||
|
rtc_timestamp = new_ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dppc_interpreter::ppc_mfspr() {
|
void dppc_interpreter::ppc_mfspr() {
|
||||||
@ -880,9 +882,11 @@ void dppc_interpreter::ppc_mfspr() {
|
|||||||
|
|
||||||
switch (ref_spr) {
|
switch (ref_spr) {
|
||||||
case SPR::RTCL_U:
|
case SPR::RTCL_U:
|
||||||
ppc_state.spr[SPR::RTCL_U] = calc_rtcl_value();
|
calc_rtcl_value();
|
||||||
|
ppc_state.spr[SPR::RTCL_U] = rtc_lo & 0x3FFFFF80UL;
|
||||||
break;
|
break;
|
||||||
case SPR::RTCU_U:
|
case SPR::RTCU_U:
|
||||||
|
calc_rtcl_value();
|
||||||
ppc_state.spr[SPR::RTCU_U] = rtc_hi;
|
ppc_state.spr[SPR::RTCU_U] = rtc_hi;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user