Skip to content

Commit

Permalink
GB MBC: Fix RTC initialization (fixes #825)
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Aug 3, 2017
1 parent 799a436 commit defc263
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -11,6 +11,7 @@ Bugfixes:
- Qt: Fix LOG argument order
- GB Memory: Prevent accessing empty SRAM (fixes mgba.io/i/831)
- GB, GBA: Fix crashes when attempting to identify null VFiles
- GB MBC: Fix RTC initialization (fixes mgba.io/i/825)
Misc:
- Qt: Don't rebuild library view if style hasn't changed
- SDL: Fix 2.0.5 build on macOS under some circumstances
Expand Down
11 changes: 10 additions & 1 deletion src/gb/mbc.c
Expand Up @@ -236,6 +236,15 @@ void GBMBCInit(struct GB* gb) {
gb->memory.rtcAccess = false;
gb->memory.activeRtcReg = 0;
gb->memory.rtcLatched = false;
gb->memory.rtcLastLatch = 0;
if (gb->memory.rtc) {
if (gb->memory.rtc->sample) {
gb->memory.rtc->sample(gb->memory.rtc);
}
gb->memory.rtcLastLatch = gb->memory.rtc->unixTime(gb->memory.rtc);
} else {
gb->memory.rtcLastLatch = time(0);
}
memset(&gb->memory.rtcRegs, 0, sizeof(gb->memory.rtcRegs));

GBResizeSram(gb, gb->sramSize);
Expand Down Expand Up @@ -801,7 +810,7 @@ void GBMBCRTCWrite(struct GB* gb) {
STORE_32LE(gb->memory.rtcRegs[2], 0, &rtcBuffer.latchedHour);
STORE_32LE(gb->memory.rtcRegs[3], 0, &rtcBuffer.latchedDays);
STORE_32LE(gb->memory.rtcRegs[4], 0, &rtcBuffer.latchedDaysHi);
STORE_64LE(rtcLastLatch, 0, &rtcBuffer.unixTime);
STORE_64LE(gb->memory.rtcLastLatch, 0, &rtcBuffer.unixTime);

if (vf->size(vf) == gb->sramSize) {
// Writing past the end of the file can invalidate the file mapping
Expand Down

0 comments on commit defc263

Please sign in to comment.