Permalink
Browse files

GB MBC: Fix RTC initialization (fixes #825)

  • Loading branch information...
endrift committed Jul 30, 2017
1 parent 799a436 commit defc263711529cdd4d58b74c53d33f3b677ecca6
Showing with 294 additions and 2 deletions.
  1. +1 −0 CHANGES
  2. +10 −1 src/gb/mbc.c
  3. +283 −1 src/gb/test/rtc.c
View
@@ -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
View
@@ -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);
@@ -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
Oops, something went wrong.

0 comments on commit defc263

Please sign in to comment.