newemuloop: fix read of timers which aren't turned on. fixes staff of kings launching

This commit is contained in:
zeromus 2009-07-15 21:57:23 +00:00
parent 7f13b77a78
commit 6275b5d746
1 changed files with 11 additions and 0 deletions

View File

@ -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;