From bb963c35a4b0ab035be39d0d95d1da50a01156a9 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Sat, 15 Jul 2017 19:46:27 +0200 Subject: [PATCH] while we're at it: emulate div/sqrt timings --- src/NDS.cpp | 28 ++++++++++++++++++++-------- src/NDS.h | 2 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/NDS.cpp b/src/NDS.cpp index a2f77eb5..10f3d640 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -717,11 +717,9 @@ void TimerStart(u32 id, u16 cnt) -void StartDiv() +void DivDone(u32 param) { - // TODO: division isn't instant! - - DivCnt &= ~0x2000; + DivCnt &= ~0xC000; switch (DivCnt & 0x0003) { @@ -792,20 +790,27 @@ void StartDiv() } if ((DivDenominator[0] | DivDenominator[1]) == 0) - DivCnt |= 0x2000; + DivCnt |= 0x4000; +} + +void StartDiv() +{ + NDS::CancelEvent(NDS::Event_Div); + DivCnt |= 0x8000; + NDS::ScheduleEvent(NDS::Event_Div, false, ((DivCnt&0x3)==0) ? 18:34, DivDone, 0); } // http://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2 -void StartSqrt() +void SqrtDone(u32 param) { - // TODO: sqrt isn't instant either. oh well - u64 val; u32 res = 0; u64 rem = 0; u32 prod = 0; u32 nbits, topshift; + SqrtCnt &= ~0x8000; + if (SqrtCnt & 0x0001) { val = *(u64*)&SqrtVal[0]; @@ -836,6 +841,13 @@ void StartSqrt() SqrtRes = res; } +void StartSqrt() +{ + NDS::CancelEvent(NDS::Event_Sqrt); + SqrtCnt |= 0x8000; + NDS::ScheduleEvent(NDS::Event_Sqrt, false, 13, SqrtDone, 0); +} + void debug(u32 param) diff --git a/src/NDS.h b/src/NDS.h index 2e53dd05..a1eab993 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -34,6 +34,8 @@ enum Event_ROMTransfer, Event_ROMSPITransfer, Event_SPITransfer, + Event_Div, + Event_Sqrt, Event_MAX };