mirror of https://github.com/mgba-emu/mgba.git
GB MBC: Fix RTC loading when file size is off
This commit is contained in:
parent
676d428f91
commit
86901d93b6
1
CHANGES
1
CHANGES
|
@ -19,6 +19,7 @@ Bugfixes:
|
||||||
- GB Memory: Prevent accessing empty SRAM (fixes mgba.io/i/831)
|
- GB Memory: Prevent accessing empty SRAM (fixes mgba.io/i/831)
|
||||||
- GB, GBA: Fix crashes when attempting to identify null VFiles
|
- GB, GBA: Fix crashes when attempting to identify null VFiles
|
||||||
- GB MBC: Fix RTC initialization (fixes mgba.io/i/825)
|
- GB MBC: Fix RTC initialization (fixes mgba.io/i/825)
|
||||||
|
- GB MBC: Fix RTC loading when file size is off
|
||||||
Misc:
|
Misc:
|
||||||
- GBA Timer: Use global cycles for timers
|
- GBA Timer: Use global cycles for timers
|
||||||
- GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
|
- GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
|
||||||
|
|
13
src/gb/mbc.c
13
src/gb/mbc.c
|
@ -960,17 +960,10 @@ void GBMBCRTCRead(struct GB* gb) {
|
||||||
if (!vf) {
|
if (!vf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ssize_t end = vf->seek(vf, -sizeof(rtcBuffer), SEEK_END);
|
vf->seek(vf, gb->sramSize, SEEK_SET);
|
||||||
switch (end & 0x1FFF) {
|
if (vf->read(vf, &rtcBuffer, sizeof(rtcBuffer)) < (ssize_t) sizeof(rtcBuffer) - 4) {
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case 0x1FFC:
|
|
||||||
vf->seek(vf, -sizeof(rtcBuffer) - 4, SEEK_END);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
vf->read(vf, &rtcBuffer, sizeof(rtcBuffer));
|
|
||||||
|
|
||||||
LOAD_32LE(gb->memory.rtcRegs[0], 0, &rtcBuffer.latchedSec);
|
LOAD_32LE(gb->memory.rtcRegs[0], 0, &rtcBuffer.latchedSec);
|
||||||
LOAD_32LE(gb->memory.rtcRegs[1], 0, &rtcBuffer.latchedMin);
|
LOAD_32LE(gb->memory.rtcRegs[1], 0, &rtcBuffer.latchedMin);
|
||||||
|
@ -1004,7 +997,7 @@ void GBMBCRTCWrite(struct GB* gb) {
|
||||||
STORE_32LE(gb->memory.rtcRegs[4], 0, &rtcBuffer.latchedDaysHi);
|
STORE_32LE(gb->memory.rtcRegs[4], 0, &rtcBuffer.latchedDaysHi);
|
||||||
STORE_64LE(gb->memory.rtcLastLatch, 0, &rtcBuffer.unixTime);
|
STORE_64LE(gb->memory.rtcLastLatch, 0, &rtcBuffer.unixTime);
|
||||||
|
|
||||||
if (vf->size(vf) == gb->sramSize) {
|
if ((size_t) vf->size(vf) < gb->sramSize + sizeof(rtcBuffer)) {
|
||||||
// Writing past the end of the file can invalidate the file mapping
|
// Writing past the end of the file can invalidate the file mapping
|
||||||
vf->unmap(vf, gb->memory.sram, gb->sramSize);
|
vf->unmap(vf, gb->memory.sram, gb->sramSize);
|
||||||
gb->memory.sram = NULL;
|
gb->memory.sram = NULL;
|
||||||
|
|
Loading…
Reference in New Issue