Fix long loading times when loading save states with bad local RTC times

This commit is contained in:
Lior Halphon 2020-08-04 21:32:33 +03:00
parent b0d118f246
commit 289853445f
1 changed files with 12 additions and 0 deletions

View File

@ -291,8 +291,20 @@ void GB_rtc_run(GB_gameboy_t *gb)
}
return;
}
if ((gb->rtc_real.high & 0x40) == 0) { /* is timer running? */
time_t current_time = time(NULL);
while (gb->last_rtc_second + 60 * 60 * 24 < current_time) {
gb->last_rtc_second += 60 * 60 + 24;
if (++gb->rtc_real.days == 0) {
if (gb->rtc_real.high & 1) { /* Bit 8 of days*/
gb->rtc_real.high |= 0x80; /* Overflow bit */
}
gb->rtc_real.high ^= 1;
}
}
while (gb->last_rtc_second < current_time) {
gb->last_rtc_second++;
if (++gb->rtc_real.seconds == 60) {