GBA: Count up timers should not count themselves

This commit is contained in:
Jeffrey Pfau 2016-09-14 01:34:53 -07:00
parent dd76386f4c
commit fa92b4cd0e
3 changed files with 16 additions and 9 deletions

View File

@ -40,6 +40,7 @@ Bugfixes:
- Qt: Fix being unable to pause manually when using auto-pausing
- GBA Memory: Fix ldm {pc}
- GBA Video: Fix out-of-order OBJWIN
- GBA: Count up timers should not count themselves
Misc:
- 3DS: Use blip_add_delta_fast for a small speed improvement
- OpenGL: Log shader compilation failure

View File

@ -306,7 +306,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
struct GBATimer* nextTimer;
timer = &gba->timers[0];
if (GBATimerFlagsIsEnable(timer->flags)) {
if (GBATimerFlagsIsEnable(timer->flags) && timer->nextEvent != INT_MAX) {
timer->nextEvent -= cycles;
timer->lastEvent -= cycles;
while (timer->nextEvent <= 0) {
@ -333,7 +333,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
if (GBATimerFlagsIsCountUp(nextTimer->flags)) {
++gba->memory.io[REG_TM1CNT_LO >> 1];
if (!gba->memory.io[REG_TM1CNT_LO >> 1]) {
nextTimer->nextEvent = 0;
nextTimer->nextEvent = cycles;
}
}
}
@ -341,7 +341,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
}
timer = &gba->timers[1];
if (GBATimerFlagsIsEnable(timer->flags)) {
if (GBATimerFlagsIsEnable(timer->flags) && timer->nextEvent != INT_MAX) {
timer->nextEvent -= cycles;
timer->lastEvent -= cycles;
if (timer->nextEvent <= 0) {
@ -372,7 +372,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
if (GBATimerFlagsIsCountUp(nextTimer->flags)) {
++gba->memory.io[REG_TM2CNT_LO >> 1];
if (!gba->memory.io[REG_TM2CNT_LO >> 1]) {
nextTimer->nextEvent = 0;
nextTimer->nextEvent = cycles;
}
}
}
@ -382,7 +382,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
}
timer = &gba->timers[2];
if (GBATimerFlagsIsEnable(timer->flags)) {
if (GBATimerFlagsIsEnable(timer->flags) && timer->nextEvent != INT_MAX) {
timer->nextEvent -= cycles;
timer->lastEvent -= cycles;
if (timer->nextEvent <= 0) {
@ -403,7 +403,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
if (GBATimerFlagsIsCountUp(nextTimer->flags)) {
++gba->memory.io[REG_TM3CNT_LO >> 1];
if (!gba->memory.io[REG_TM3CNT_LO >> 1]) {
nextTimer->nextEvent = 0;
nextTimer->nextEvent = cycles;
}
}
}
@ -413,7 +413,7 @@ static int32_t GBATimersProcessEvents(struct GBA* gba, int32_t cycles) {
}
timer = &gba->timers[3];
if (GBATimerFlagsIsEnable(timer->flags)) {
if (GBATimerFlagsIsEnable(timer->flags) && timer->nextEvent != INT_MAX) {
timer->nextEvent -= cycles;
timer->lastEvent -= cycles;
if (timer->nextEvent <= 0) {

View File

@ -883,10 +883,16 @@ 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_16(gba->timers[i].oldReload, 0, &state->timers[i].oldReload);
LOAD_32(gba->timers[i].lastEvent, 0, &state->timers[i].lastEvent);
LOAD_32(gba->timers[i].nextEvent, 0, &state->timers[i].nextEvent);
LOAD_32(gba->timers[i].overflowInterval, 0, &state->timers[i].overflowInterval);
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;
gba->timers[i].nextEvent = INT_MAX;
} else {
LOAD_32(gba->timers[i].lastEvent, 0, &state->timers[i].lastEvent);
LOAD_32(gba->timers[i].nextEvent, 0, &state->timers[i].nextEvent);
}
LOAD_16(gba->memory.dma[i].reg, (REG_DMA0CNT_HI + i * 12), state->io);
LOAD_32(gba->memory.dma[i].nextSource, 0, &state->dma[i].nextSource);
LOAD_32(gba->memory.dma[i].nextDest, 0, &state->dma[i].nextDest);