summaryrefslogtreecommitdiff
path: root/arm9/src
diff options
context:
space:
mode:
Diffstat (limited to 'arm9/src')
-rw-r--r--arm9/src/main.c4
-rw-r--r--arm9/src/timer3.c66
-rw-r--r--arm9/src/unk_02015E30.c7
3 files changed, 70 insertions, 7 deletions
diff --git a/arm9/src/main.c b/arm9/src/main.c
index 86f0f6af..c50fbaff 100644
--- a/arm9/src/main.c
+++ b/arm9/src/main.c
@@ -11,6 +11,7 @@
#include "poke_overlay.h"
#include "player_data.h"
#include "sound.h"
+#include "timer3.h"
FS_EXTERN_OVERLAY(MODULE_52);
FS_EXTERN_OVERLAY(MODULE_63);
@@ -34,7 +35,6 @@ extern void FUN_02002C14(void);
extern void FUN_02002C50(int, int);
extern struct SaveBlock2 * SaveBlock2_new(void);
extern void * FUN_02029EF8(struct SaveBlock2 *);
-extern void FUN_02020AFC(void);
extern int FUN_020337E8(int);
extern void FUN_02034188(int, int);
extern int FUN_020227FC(struct SaveBlock2 *);
@@ -75,7 +75,7 @@ THUMB_FUNC void NitroMain(void)
gBacklightTop.unk18 = -1;
gBacklightTop.unk20 = SaveBlock2_new();
InitSoundData(FUN_02029EF8(gBacklightTop.unk20), Sav2_PlayerData_GetOptionsAddr(gBacklightTop.unk20));
- FUN_02020AFC();
+ Init_Timer3();
if (FUN_020337E8(3) == 3)
FUN_02034188(3, 0);
if (FUN_020227FC(gBacklightTop.unk20) == 0)
diff --git a/arm9/src/timer3.c b/arm9/src/timer3.c
new file mode 100644
index 00000000..1799fd24
--- /dev/null
+++ b/arm9/src/timer3.c
@@ -0,0 +1,66 @@
+#include "timer3.h"
+
+struct Timer3Data timer3_data;
+
+
+THUMB_FUNC void Init_Timer3()
+{
+ timer3_data.Timer3Counter = 0;
+ timer3_data.NeedReset = FALSE;
+
+ reg_OS_TM3CNT_H = 0;
+ reg_OS_TM3CNT_L = 0;
+ reg_OS_TM3CNT_H = 0xc1; // start timer3 with f/64 and irq enable
+
+ OS_SetIrqFunction(0x40, &CountUpTimer3);
+ OS_EnableIrqMask(0x40); // irq on timer3 overflow
+}
+
+
+THUMB_FUNC void CountUpTimer3()
+{
+ timer3_data.Timer3Counter++;
+
+ if (timer3_data.NeedReset)
+ {
+ reg_OS_TM3CNT_H = 0;
+ reg_OS_TM3CNT_L = 0;
+ reg_OS_TM3CNT_H = 0xc1;
+ timer3_data.NeedReset = FALSE;
+ }
+
+ *(vu32 *)HW_INTR_CHECK_BUF |= 0x40;
+
+ OS_SetIrqFunction(0x40, &CountUpTimer3);
+}
+
+THUMB_FUNC u64 internal_GetTimer3Count()
+{
+ OSIntrMode intr_mode = OS_DisableInterrupts();
+
+ vu16 timer3 = reg_OS_TM3CNT_L;
+ vu64 timer3_counter = timer3_data.Timer3Counter & 0x0000ffffffffffff;
+
+ if (reg_OS_IF & 0x40 && !(timer3 & 0x8000))
+ {
+ timer3_counter++;
+ }
+
+ OS_RestoreInterrupts(intr_mode);
+ return (timer3_counter << 16) | timer3;
+}
+
+THUMB_FUNC u64 GetTimer3Count()
+{
+ return internal_GetTimer3Count();
+}
+
+THUMB_FUNC u64 Timer3CountToMilliSeconds(u64 count)
+{
+ return (count *64) / 33514;
+}
+
+THUMB_FUNC u64 Timer3CountToSeconds(u64 count)
+{
+ return (count *64) / HW_SYSTEM_CLOCK;
+}
diff --git a/arm9/src/unk_02015E30.c b/arm9/src/unk_02015E30.c
index d52fb236..8be466fb 100644
--- a/arm9/src/unk_02015E30.c
+++ b/arm9/src/unk_02015E30.c
@@ -1,9 +1,6 @@
#include "unk_02015E30.h"
-extern u64 FUN_02020BF4();
-extern u64 FUN_02020C14(u64 param0);
-
struct UnkStruct_02015E30 UNK_021C4898;
THUMB_FUNC void FUN_02015E30()
@@ -20,14 +17,14 @@ THUMB_FUNC void FUN_02015E3C(struct IGT *igt)
UNK_021C4898.unk08 = 0;
UNK_021C4898.unk04 = igt;
- UNK_021C4898.unk18 = FUN_02020BF4();
+ UNK_021C4898.unk18 = GetTimer3Count();
}
THUMB_FUNC void FUN_02015E60()
{
if (UNK_021C4898.unk00 != 0)
{
- u64 res = FUN_02020C14(FUN_02020BF4() - UNK_021C4898.unk18);
+ u64 res = Timer3CountToSeconds(GetTimer3Count() - UNK_021C4898.unk18);
if (UNK_021C4898.unk08 < res)
{