From 6275b5d7469627bb5ed7288739a94732411a8be6 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 15 Jul 2009 21:57:23 +0000 Subject: [PATCH] newemuloop: fix read of timers which aren't turned on. fixes staff of kings launching --- desmume/src/MMU.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 1cd42888f..6537e04bf 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -1310,6 +1310,11 @@ static INLINE u16 read_timer(int proc, int timerIndex) if(MMU.timerMODE[proc][timerIndex] == 0xFFFF) return MMU.timer[proc][timerIndex]; + //sometimes a timer will be read when it is not enabled. + //we should have the value cached + if(!MMU.timerON[proc][timerIndex]) + return MMU.timer[proc][timerIndex]; + //for unchained timers, we do not keep the timer up to date. its value will need to be calculated here s32 diff = (s32)(nds.timerCycle[proc][timerIndex] - nds_timer); assert(diff>=0); @@ -1331,6 +1336,12 @@ static INLINE void write_timer(int proc, int timerIndex, u16 val) if(val&0x80) MMU.timer[proc][timerIndex] = MMU.timerReload[proc][timerIndex]; + else + { + if(MMU.timerON[proc][timerIndex]) + //read the timer value one last time + MMU.timer[proc][timerIndex] = read_timer(proc,timerIndex); + } MMU.timerON[proc][timerIndex] = val & 0x80;