GBA SIO: Clean up lockstep cycle counting
Vicki Pfau vi@endrift.com
Mon, 08 Feb 2021 23:06:00 -0800
1 files changed,
9 insertions(+),
19 deletions(-)
jump to
M
src/gba/sio/lockstep.c
→
src/gba/sio/lockstep.c
@@ -149,11 +149,7 @@ }
// Flush ongoing transfer if (mTimingIsScheduled(&driver->p->p->timing, &node->event)) { - int oldWhen = node->event.when; - - mTimingDeschedule(&driver->p->p->timing, &node->event); - mTimingSchedule(&driver->p->p->timing, &node->event, 0); - node->eventDiff -= oldWhen - node->event.when; + node->eventDiff -= node->event.when - mTimingCurrentTime(&driver->p->p->timing); mTimingDeschedule(&driver->p->p->timing, &node->event); }@@ -190,15 +186,11 @@ mLOG(GBA_SIO, DEBUG, "Lockstep %i: Transfer initiated", node->id);
ATOMIC_STORE(node->p->d.transferActive, TRANSFER_STARTING); ATOMIC_STORE(node->p->d.transferCycles, GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(node->d.p->siocnt)][node->p->d.attached - 1]); - bool scheduled = mTimingIsScheduled(&driver->p->p->timing, &node->event); - int oldWhen = node->event.when; - - mTimingDeschedule(&driver->p->p->timing, &node->event); - mTimingSchedule(&driver->p->p->timing, &node->event, 0); - - if (scheduled) { - node->eventDiff -= oldWhen - node->event.when; + if (mTimingIsScheduled(&driver->p->p->timing, &node->event)) { + node->eventDiff -= node->event.when - mTimingCurrentTime(&driver->p->p->timing); + mTimingDeschedule(&driver->p->p->timing, &node->event); } + mTimingSchedule(&driver->p->p->timing, &node->event, 0); } else { value &= ~0x0080; }@@ -443,15 +435,13 @@
static void _GBASIOLockstepNodeProcessEvents(struct mTiming* timing, void* user, uint32_t cyclesLate) { struct GBASIOLockstepNode* node = user; mLockstepLock(&node->p->d); - if (node->p->d.attached < 2) { - mTimingSchedule(timing, &node->event, GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(node->d.p->siocnt)][0]); - mLockstepUnlock(&node->p->d); - return; - } + int32_t cycles = 0; node->nextEvent -= cyclesLate; node->eventDiff += cyclesLate; - if (node->nextEvent <= 0) { + if (node->p->d.attached < 2) { + cycles = GBASIOCyclesPerTransfer[GBASIOMultiplayerGetBaud(node->d.p->siocnt)][0]; + } else if (node->nextEvent <= 0) { if (!node->id) { cycles = _masterUpdate(node); } else {