From 549787227a488a4f52e30ee0b14cb9bf331b327c Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 10 Aug 2020 15:57:38 -0700 Subject: [PATCH] Core: Add mTimingScheduleAbsolute --- include/mgba/core/timing.h | 1 + src/core/timing.c | 4 ++++ src/gba/timer.c | 3 +-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/mgba/core/timing.h b/include/mgba/core/timing.h index 10a64171e..3db79493c 100644 --- a/include/mgba/core/timing.h +++ b/include/mgba/core/timing.h @@ -35,6 +35,7 @@ void mTimingInit(struct mTiming* timing, int32_t* relativeCycles, int32_t* nextE void mTimingDeinit(struct mTiming* timing); void mTimingClear(struct mTiming* timing); void mTimingSchedule(struct mTiming* timing, struct mTimingEvent*, int32_t when); +void mTimingScheduleAbsolute(struct mTiming* timing, struct mTimingEvent*, int32_t when); void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent*); bool mTimingIsScheduled(const struct mTiming* timing, const struct mTimingEvent*); int32_t mTimingTick(struct mTiming* timing, int32_t cycles); diff --git a/src/core/timing.c b/src/core/timing.c index f9854c6ac..ddee6d332 100644 --- a/src/core/timing.c +++ b/src/core/timing.c @@ -50,6 +50,10 @@ void mTimingSchedule(struct mTiming* timing, struct mTimingEvent* event, int32_t *previous = event; } +void mTimingScheduleAbsolute(struct mTiming* timing, struct mTimingEvent* event, int32_t when) { + mTimingSchedule(timing, event, when - mTimingCurrentTime(timing)); +} + void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent* event) { if (timing->reroot) { timing->root = timing->reroot; diff --git a/src/gba/timer.c b/src/gba/timer.c index 512a1d05f..5b1bc5414 100644 --- a/src/gba/timer.c +++ b/src/gba/timer.c @@ -109,9 +109,8 @@ void GBATimerUpdateRegister(struct GBA* gba, int timer, int32_t cyclesLate) { tickIncrement = (0x10000 - tickIncrement) << prescaleBits; currentTime += tickIncrement; currentTime &= ~tickMask; - currentTime -= mTimingCurrentTime(&gba->timing); mTimingDeschedule(&gba->timing, ¤tTimer->event); - mTimingSchedule(&gba->timing, ¤tTimer->event, currentTime); + mTimingScheduleAbsolute(&gba->timing, ¤tTimer->event, currentTime); } void GBATimerWriteTMCNT_LO(struct GBA* gba, int timer, uint16_t reload) {