all repos — mgba @ c280d8efa62247084bee013523484aed8d8dfb5c

mGBA Game Boy Advance Emulator

GB: Fix timer edge conditions
Jeffrey Pfau jeffrey@endrift.com
Sat, 17 Sep 2016 01:00:21 -0700
commit

c280d8efa62247084bee013523484aed8d8dfb5c

parent

e82c9aadea0133744f6f6c309312f44caaa51eb0

1 files changed, 19 insertions(+), 4 deletions(-)

jump to
M src/gb/mbc.csrc/gb/mbc.c

@@ -183,18 +183,33 @@ time_t currentLatch = t;

t -= *rtcLastLatch; *rtcLastLatch = currentLatch; - unsigned diff; + int64_t diff; diff = rtcRegs[0] + t % 60; + if (diff < 0) { + diff += 60; + t -= 60; + } rtcRegs[0] = diff % 60; - t = t / 60 + diff / 60; + t /= 60; + t += diff / 60; diff = rtcRegs[1] + t % 60; + if (diff < 0) { + diff += 60; + t -= 60; + } rtcRegs[1] = diff % 60; - t = t / 60 + diff / 60; + t /= 60; + t += diff / 60; diff = rtcRegs[2] + t % 24; + if (diff < 0) { + diff += 24; + t -= 24; + } rtcRegs[2] = diff % 24; - t = t / 24 + diff / 24; + t /= 24; + t += diff / 24; diff = rtcRegs[3] + ((rtcRegs[4] & 1) << 8) + (t & 0x1FF); rtcRegs[3] = diff;