diff options
author | Rémi Calixte <remicalixte.rmc@gmail.com> | 2021-03-20 11:42:10 +0100 |
---|---|---|
committer | Rémi Calixte <remicalixte.rmc@gmail.com> | 2021-03-20 11:45:35 +0100 |
commit | bef877266c6af17c90581f56f5d4217fd4ecce23 (patch) | |
tree | 4efe531014c06c0d1565dae1188dd92ea533c1f5 | |
parent | 1a326c6b75b7e97bad781a1472bdbb29d90766b6 (diff) |
better names
-rw-r--r-- | arm9/arm9.lsf | 2 | ||||
-rw-r--r-- | arm9/global.inc | 7 | ||||
-rw-r--r-- | arm9/modules/22/asm/module_22.s | 10 | ||||
-rw-r--r-- | arm9/modules/41/asm/module_41.s | 10 | ||||
-rw-r--r-- | arm9/src/main.c | 4 | ||||
-rw-r--r-- | arm9/src/timer3.c | 67 | ||||
-rw-r--r-- | arm9/src/unk_02015E30.c | 7 | ||||
-rw-r--r-- | arm9/src/unk_02020AFC.c | 74 | ||||
-rw-r--r-- | include/timer3.h | 21 | ||||
-rw-r--r-- | include/unk_02015E30.h | 1 |
10 files changed, 107 insertions, 96 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/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..7bf66398 --- /dev/null +++ b/arm9/src/timer3.c @@ -0,0 +1,67 @@ +#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; + } + u32 *ptr = (u32 *)0x027e0000; + u32 offset = 0xffe; + ptr[offset] |= 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 & 64 && !(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/arm9/src/unk_02020AFC.c b/arm9/src/unk_02020AFC.c deleted file mode 100644 index 80d37755..00000000 --- a/arm9/src/unk_02020AFC.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "global.h" - -struct UnkStruct_02020AFC -{ - BOOL NeedReset; - vu64 Timer3Counter; -}; - -struct UnkStruct_02020AFC UNK_021C59B0; - -extern void FUN_02020B30(void); - -THUMB_FUNC void FUN_02020AFC() -{ - UNK_021C59B0.Timer3Counter = 0; - UNK_021C59B0.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, &FUN_02020B30); - OS_EnableIrqMask(0x40); // irq on timer3 overflow -} - - -THUMB_FUNC void FUN_02020B30() -{ - UNK_021C59B0.Timer3Counter++; - - if (UNK_021C59B0.NeedReset) - { - reg_OS_TM3CNT_H = 0; - reg_OS_TM3CNT_L = 0; - reg_OS_TM3CNT_H = 0xc1; - UNK_021C59B0.NeedReset = FALSE; - } - u32 *ptr = (u32 *)0x027e0000; - u32 offset = 0xffe; - ptr[offset] |= 0x40; - - OS_SetIrqFunction(0x40, &FUN_02020B30); -} - -THUMB_FUNC u64 FUN_02020B80() -{ - OSIntrMode intr_mode = OS_DisableInterrupts(); - - vu16 timer3 = reg_OS_TM3CNT_L; - vu64 unk1 = UNK_021C59B0.Timer3Counter & 0x0000ffffffffffff; - - if (reg_OS_IF & 64 && !(timer3 & 0x8000)) - { - unk1++; - } - - OS_RestoreInterrupts(intr_mode); - return (unk1 << 16) | timer3; -} - -THUMB_FUNC u64 FUN_02020BF4() -{ - return FUN_02020B80(); -} - -THUMB_FUNC u64 FUN_02020BFC(u64 param0) -{ - return (param0 << 6) / 33514; -} - -THUMB_FUNC u64 FUN_02020C14(u64 param0) -{ - return (param0 << 6) / 33514000; -} 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 { |