Permalink
Browse files

GB MBC: Fix RTC initialization (fixes #825)

  • Loading branch information...
endrift committed Jul 30, 2017
1 parent 558a3ab commit a330df2f1fc617254e793702ebb5e3ed869af804
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
@@ -18,6 +18,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:
- GBA Timer: Use global cycles for timers
- GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
View
@@ -255,6 +255,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);
@@ -993,7 +1002,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 a330df2

Please sign in to comment.