summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arm9/arm9.lsf2
-rw-r--r--arm9/asm/unk_02020AFC.s165
-rw-r--r--arm9/global.inc7
-rw-r--r--arm9/modules/22/asm/module_22.s10
-rw-r--r--arm9/modules/41/asm/module_41.s10
-rw-r--r--arm9/src/main.c4
-rw-r--r--arm9/src/timer3.c66
-rw-r--r--arm9/src/unk_02015E30.c7
-rw-r--r--include/timer3.h21
-rw-r--r--include/unk_02015E30.h1
10 files changed, 106 insertions, 187 deletions
diff --git a/arm9/arm9.lsf b/arm9/arm9.lsf
index ba128605..1b6a6d66 100644
--- a/arm9/arm9.lsf
+++ b/arm9/arm9.lsf
@@ -69,7 +69,7 @@ Static arm9
Object unk_0201E7D8.o
Object unk_0201F06C.o
Object unk_020208B8.o
- Object unk_02020AFC.o
+ Object timer3.o
Object error_handling.o
Object unk_02020C44.o
Object unk_0202134C.o
diff --git a/arm9/asm/unk_02020AFC.s b/arm9/asm/unk_02020AFC.s
deleted file mode 100644
index 3d43d259..00000000
--- a/arm9/asm/unk_02020AFC.s
+++ /dev/null
@@ -1,165 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .section .bss
-
- .global UNK_021C59B0
-UNK_021C59B0: ; 0x021C59B0
- .space 0xc
-
- .text
-
- thumb_func_start FUN_02020AFC
-FUN_02020AFC: ; 0x02020AFC
- push {r3, lr}
- ldr r0, _02020B24 ; =UNK_021C59B0
- mov r2, #0x0
- str r2, [r0, #0x4]
- str r2, [r0, #0x8]
- ldr r1, _02020B28 ; =0x0400010E
- str r2, [r0, #0x0]
- strh r2, [r1, #0x0]
- sub r0, r1, #0x2
- strh r2, [r0, #0x0]
- mov r0, #0xc1
- strh r0, [r1, #0x0]
- ldr r1, _02020B2C ; =FUN_02020B30
- mov r0, #0x40
- bl OS_SetIrqFunction
- mov r0, #0x40
- bl OS_EnableIrqMask
- pop {r3, pc}
- .balign 4
-_02020B24: .word UNK_021C59B0
-_02020B28: .word 0x0400010E
-_02020B2C: .word FUN_02020B30
-
- thumb_func_start FUN_02020B30
-FUN_02020B30: ; 0x02020B30
- ldr r0, _02020B68 ; =UNK_021C59B0
- mov r3, #0x0
- ldr r1, [r0, #0x4]
- ldr r2, [r0, #0x8]
- add r1, r1, #0x1
- adc r2, r3
- str r1, [r0, #0x4]
- str r2, [r0, #0x8]
- ldr r1, [r0, #0x0]
- cmp r1, #0x0
- beq _02020B54
- ldr r2, _02020B6C ; =0x0400010E
- strh r3, [r2, #0x0]
- sub r1, r2, #0x2
- strh r3, [r1, #0x0]
- mov r1, #0xc1
- strh r1, [r2, #0x0]
- str r3, [r0, #0x0]
-_02020B54:
- ldr r3, _02020B70 ; =0x027E0000
- ldr r1, _02020B74 ; =0x00003FF8
- mov r0, #0x40
- ldr r2, [r3, r1]
- orr r2, r0
- str r2, [r3, r1]
- ldr r3, _02020B78 ; =OS_SetIrqFunction
- ldr r1, _02020B7C ; =FUN_02020B30
- bx r3
- nop
-_02020B68: .word UNK_021C59B0
-_02020B6C: .word 0x0400010E
-_02020B70: .word 0x027E0000
-_02020B74: .word 0x00003FF8
-_02020B78: .word OS_SetIrqFunction
-_02020B7C: .word FUN_02020B30
-
- thumb_func_start FUN_02020B80
-FUN_02020B80: ; 0x02020B80
- push {r4-r5, lr}
- sub sp, #0xc
- bl OS_DisableInterrupts
- ldr r1, _02020BE4 ; =0x0400010C
- add r3, sp, #0x0
- ldrh r1, [r1, #0x0]
- ldr r2, _02020BE8 ; =0x0000FFFF
- strh r1, [r3, #0x0]
- ldr r1, _02020BEC ; =UNK_021C59B0
- ldr r5, [r1, #0x4]
- ldr r4, [r1, #0x8]
- mov r1, #0x0
- mvn r1, r1
- and r1, r5
- str r1, [sp, #0x4]
- and r2, r4
- ldr r1, _02020BF0 ; =0x04000214
- str r2, [sp, #0x8]
- ldr r2, [r1, #0x0]
- mov r1, #0x40
- tst r2, r1
- beq _02020BC4
- ldrh r2, [r3, #0x0]
- lsl r1, r1, #0x9
- tst r1, r2
- bne _02020BC4
- ldr r2, [sp, #0x4]
- mov r1, #0x0
- ldr r3, [sp, #0x8]
- add r2, r2, #0x1
- adc r3, r1
- str r2, [sp, #0x4]
- str r3, [sp, #0x8]
-_02020BC4:
- bl OS_RestoreInterrupts
- ldr r2, [sp, #0x4]
- ldr r1, [sp, #0x8]
- lsr r0, r2, #0x10
- lsl r1, r1, #0x10
- orr r1, r0
- add r0, sp, #0x0
- lsl r3, r2, #0x10
- ldrh r2, [r0, #0x0]
- asr r0, r2, #0x1f
- orr r1, r0
- add r0, r3, #0x0
- orr r0, r2
- add sp, #0xc
- pop {r4-r5, pc}
- .balign 4
-_02020BE4: .word 0x0400010C
-_02020BE8: .word 0x0000FFFF
-_02020BEC: .word UNK_021C59B0
-_02020BF0: .word 0x04000214
-
- thumb_func_start FUN_02020BF4
-FUN_02020BF4: ; 0x02020BF4
- ldr r3, _02020BF8 ; =FUN_02020B80
- bx r3
- .balign 4
-_02020BF8: .word FUN_02020B80
-
- thumb_func_start FUN_02020BFC
-FUN_02020BFC: ; 0x02020BFC
- push {r3, lr}
- lsr r2, r0, #0x1a
- lsl r1, r1, #0x6
- orr r1, r2
- ldr r2, _02020C10 ; =0x000082EA
- lsl r0, r0, #0x6
- mov r3, #0x0
- bl _ll_udiv
- pop {r3, pc}
- .balign 4
-_02020C10: .word 0x000082EA
-
- thumb_func_start FUN_02020C14
-FUN_02020C14: ; 0x02020C14
- push {r3, lr}
- lsr r2, r0, #0x1a
- lsl r1, r1, #0x6
- orr r1, r2
- ldr r2, _02020C28 ; =0x01FF6210
- lsl r0, r0, #0x6
- mov r3, #0x0
- bl _ll_udiv
- pop {r3, pc}
- .balign 4
-_02020C28: .word 0x01FF6210
diff --git a/arm9/global.inc b/arm9/global.inc
index 0190b134..ebbd0c24 100644
--- a/arm9/global.inc
+++ b/arm9/global.inc
@@ -1353,10 +1353,9 @@
.extern FUN_02020AB0
.extern FUN_02020ACC
.extern FUN_02020AE8
-.extern FUN_02020AFC
-.extern FUN_02020BF4
-.extern FUN_02020BFC
-.extern FUN_02020C14
+.extern GetTimer3Count
+.extern Timer3CountToMilliSeconds
+.extern Timer3CountToSeconds
.extern FUN_02020C44
.extern FUN_02020C90
.extern FUN_02020CB0
diff --git a/arm9/modules/22/asm/module_22.s b/arm9/modules/22/asm/module_22.s
index ef079cdb..e58e406b 100644
--- a/arm9/modules/22/asm/module_22.s
+++ b/arm9/modules/22/asm/module_22.s
@@ -657,7 +657,7 @@ MOD22_02254D00: ; 0x02254D00
eor r0, r3
orr r0, r1
beq _02254D32
- bl FUN_02020BF4
+ bl GetTimer3Count
add r5, r4, #0
add r5, #0xc
ldr r7, [r4, #0x14]
@@ -672,7 +672,7 @@ MOD22_02254D00: ; 0x02254D00
str r3, [r5, #4]
b _02254D3A
_02254D32:
- bl FUN_02020BF4
+ bl GetTimer3Count
str r0, [r4, #0xc]
str r1, [r4, #0x10]
_02254D3A:
@@ -687,7 +687,7 @@ _02254D3A:
MOD22_02254D44: ; 0x02254D44
push {r4, lr}
add r4, r0, #0
- bl FUN_02020BF4
+ bl GetTimer3Count
str r0, [r4, #0x14]
str r1, [r4, #0x18]
mov r0, #0
@@ -706,12 +706,12 @@ MOD22_02254D58: ; 0x02254D58
bne _02254D66
b _02254E7C
_02254D66:
- bl FUN_02020BF4
+ bl GetTimer3Count
ldr r3, [r5, #0xc]
ldr r2, [r5, #0x10]
sub r0, r0, r3
sbc r1, r2
- bl FUN_02020BFC
+ bl Timer3CountToMilliSeconds
ldr r2, _02254E80 ; =0x04000280
mov r3, #1
strh r3, [r2]
diff --git a/arm9/modules/41/asm/module_41.s b/arm9/modules/41/asm/module_41.s
index a60736df..637c100f 100644
--- a/arm9/modules/41/asm/module_41.s
+++ b/arm9/modules/41/asm/module_41.s
@@ -1046,7 +1046,7 @@ MOD41_0225504C: ; 0x0225504C
add r5, r0, #0
add r4, r5, #0
add r4, #0x48
- bl FUN_02020BF4
+ bl GetTimer3Count
str r0, [r5, #0x68]
str r1, [r5, #0x6c]
mov r2, #0
@@ -1105,7 +1105,7 @@ MOD41_022550BC: ; 0x022550BC
mov r1, #0
add r0, #0x88
str r1, [r0]
- bl FUN_02020BF4
+ bl GetTimer3Count
str r0, [r4, #0x70]
str r1, [r4, #0x74]
pop {r4, pc}
@@ -1115,7 +1115,7 @@ MOD41_022550BC: ; 0x022550BC
MOD41_022550D0: ; 0x022550D0
push {r3, r4, r5, r6, r7, lr}
add r4, r0, #0
- bl FUN_02020BF4
+ bl GetTimer3Count
add r5, r4, #0
add r5, #0x68
ldr r7, [r4, #0x70]
@@ -1155,12 +1155,12 @@ MOD41_02255108: ; 0x02255108
ldr r0, [r0]
cmp r0, #0
beq _0225516A
- bl FUN_02020BF4
+ bl GetTimer3Count
ldr r3, [r4, #0x68]
ldr r2, [r4, #0x6c]
sub r0, r0, r3
sbc r1, r2
- bl FUN_02020C14
+ bl Timer3CountToSeconds
add r5, r0, #0
add r0, r4, #0
add r0, #0x80
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)
{
diff --git a/include/timer3.h b/include/timer3.h
new file mode 100644
index 00000000..be6e1da8
--- /dev/null
+++ b/include/timer3.h
@@ -0,0 +1,21 @@
+#ifndef POKEDIAMOND_TIMER3_H
+#define POKEDIAMOND_TIMER3_H
+
+
+#include "global.h"
+
+struct Timer3Data
+{
+ BOOL NeedReset;
+ vu64 Timer3Counter;
+};
+
+THUMB_FUNC void Init_Timer3();
+THUMB_FUNC void CountUpTimer3();
+THUMB_FUNC u64 internal_GetTimer3Count();
+THUMB_FUNC u64 GetTimer3Count();
+THUMB_FUNC u64 Timer3CountToMilliSeconds(u64 count);
+THUMB_FUNC u64 Timer3CountToSeconds(u64 count);
+
+
+#endif //POKEDIAMOND_TIMER3_H
diff --git a/include/unk_02015E30.h b/include/unk_02015E30.h
index 32a46d39..6a4d6c15 100644
--- a/include/unk_02015E30.h
+++ b/include/unk_02015E30.h
@@ -3,6 +3,7 @@
#include "global.h"
#include "igt.h"
+#include "timer3.h"
struct UnkStruct_02015E30
{