aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-07-15 19:46:27 +0200
committerStapleButter <thetotalworm@gmail.com>2017-07-15 19:46:27 +0200
commitbb963c35a4b0ab035be39d0d95d1da50a01156a9 (patch)
treef20e19663c22c7634d0d15233652b5005c4e1d02 /src
parent0d58fcb5d6cb124049d88a0146b0756fbd52030c (diff)
while we're at it: emulate div/sqrt timings
Diffstat (limited to 'src')
-rw-r--r--src/NDS.cpp28
-rw-r--r--src/NDS.h2
2 files changed, 22 insertions, 8 deletions
diff --git a/src/NDS.cpp b/src/NDS.cpp
index a2f77eb..10f3d64 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;
}
-// http://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2
-void StartSqrt()
+void StartDiv()
{
- // TODO: sqrt isn't instant either. oh well
+ 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 SqrtDone(u32 param)
+{
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 2e53dd0..a1eab99 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
};