GB MBC: Fix RTC access when no save file is loaded
Jeffrey Pfau jeffrey@endrift.com
Sun, 25 Sep 2016 23:43:05 -0700
2 files changed,
9 insertions(+),
1 deletions(-)
M
CHANGES
→
CHANGES
@@ -20,6 +20,7 @@ - GB, GBA: Fix emulator hardlocking when halting with IRQs off
- SDL: Attach rumble in SDL frontend - GBA Hardware: Improve Game Boy Player rumble behavior - GB: Initialize audio properly + - GB MBC: Fix RTC access when no save file is loaded Misc: - All: Only update version info if needed - FFmpeg: Encoding cleanup
M
src/gb/mbc.c
→
src/gb/mbc.c
@@ -624,6 +624,9 @@
void GBMBCRTCRead(struct GB* gb) { struct GBMBCRTCSaveBuffer rtcBuffer; struct VFile* vf = gb->sramVf; + if (!vf) { + return; + } ssize_t end = vf->seek(vf, -sizeof(rtcBuffer), SEEK_END); switch (end & 0x1FFF) { case 0:@@ -645,6 +648,11 @@ LOAD_64LE(gb->memory.rtcLastLatch, 0, &rtcBuffer.unixTime);
} void GBMBCRTCWrite(struct GB* gb) { + struct VFile* vf = gb->sramVf; + if (!vf) { + return; + } + uint8_t rtcRegs[5]; memcpy(rtcRegs, gb->memory.rtcRegs, sizeof(rtcRegs)); time_t rtcLastLatch = gb->memory.rtcLastLatch;@@ -663,7 +671,6 @@ STORE_32LE(gb->memory.rtcRegs[3], 0, &rtcBuffer.latchedDays);
STORE_32LE(gb->memory.rtcRegs[4], 0, &rtcBuffer.latchedDaysHi); STORE_64LE(rtcLastLatch, 0, &rtcBuffer.unixTime); - struct VFile* vf = gb->sramVf; vf->seek(vf, gb->sramSize, SEEK_SET); vf->write(vf, &rtcBuffer, sizeof(rtcBuffer)); }