Skip to content

Commit

Permalink
GBA Timers: Fix deserializing count-up timers
Browse files Browse the repository at this point in the history
  • Loading branch information
endrift committed Feb 26, 2020
1 parent 77a67f8 commit 03d85b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Emulation fixes:
- GBA SIO: Fix Multiplayer busy bit
- GBA SIO: Fix double-unloading active driver
- GBA SIO: Fix copying Normal mode transfer values
- GBA Timers: Fix deserializing count-up timers
- GBA Video: Latch scanline at end of Hblank (fixes mgba.io/i/1319)
- GBA Video: Fix Hblank timing
Other fixes:
Expand Down
13 changes: 5 additions & 8 deletions src/gba/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,16 +964,13 @@ void GBAIODeserialize(struct GBA* gba, const struct GBASerializedState* state) {
for (i = 0; i < 4; ++i) {
LOAD_16(gba->timers[i].reload, 0, &state->timers[i].reload);
LOAD_32(gba->timers[i].flags, 0, &state->timers[i].flags);
if (i > 0 && GBATimerFlagsIsCountUp(gba->timers[i].flags)) {
// Overwrite invalid values in savestate
gba->timers[i].lastEvent = 0;
} else {
LOAD_32(when, 0, &state->timers[i].lastEvent);
gba->timers[i].lastEvent = when + mTimingCurrentTime(&gba->timing);
}
LOAD_32(when, 0, &state->timers[i].lastEvent);
gba->timers[i].lastEvent = when + mTimingCurrentTime(&gba->timing);
LOAD_32(when, 0, &state->timers[i].nextEvent);
if (GBATimerFlagsIsEnable(gba->timers[i].flags)) {
if ((i < 1 || !GBATimerFlagsIsCountUp(gba->timers[i].flags)) && GBATimerFlagsIsEnable(gba->timers[i].flags)) {
mTimingSchedule(&gba->timing, &gba->timers[i].event, when);
} else {
gba->timers[i].event.when = when + mTimingCurrentTime(&gba->timing);
}

LOAD_16(gba->memory.dma[i].reg, (REG_DMA0CNT_HI + i * 12), state->io);
Expand Down

0 comments on commit 03d85b4

Please sign in to comment.