diff options
-rw-r--r-- | asm/rom.s | 134 | ||||
-rw-r--r-- | include/global.h | 6 | ||||
-rw-r--r-- | include/play_time.h | 9 | ||||
-rw-r--r-- | iwram_syms.txt | 2 | ||||
-rw-r--r-- | src/play_time.c | 73 |
5 files changed, 99 insertions, 125 deletions
@@ -31,7 +31,7 @@ AgbMain: ; 800024C bl CheckForFlashMemory bl init_saveblock_ptrs_and_set_copyright_callback2 bl sound_sources_off - bl SeedRngAndSetTrainerId + bl SeedRngWithRtc ldr r0, _080002EC movs r4, 0 strb r4, [r0] @@ -107,7 +107,7 @@ _08000304: bl CallCallbacksWrapper strb r7, [r4] _0800032C: - bl sub_8052C7C + bl PlayTimeCounter_Update bl sound_something bl WaitForVBlank b _080002A4 @@ -201,8 +201,8 @@ _080003DC: .4byte 0x03001770 _080003E0: .4byte 0x0000043c thumb_func_end SetMainCallback2 - thumb_func_start SeedRngAndSetTrainerId -SeedRngAndSetTrainerId: ; 80003E4 + thumb_func_start SeedRngWithRtc +SeedRngWithRtc: ; 80003E4 push {lr} bl GameFreakRTC_GetNumMinutes adds r2, r0, 0 @@ -215,7 +215,7 @@ SeedRngAndSetTrainerId: ; 80003E4 bx r0 .align 2 _080003FC: .4byte 0x0000ffff - thumb_func_end SeedRngAndSetTrainerId + thumb_func_end SeedRngWithRtc thumb_func_start InitKeypadData InitKeypadData: ; 8000400 @@ -164965,123 +164965,7 @@ _08052C20: .4byte 0x0000016f _08052C24: .4byte 0x03004854 thumb_func_end sub_8052BD0 - thumb_func_start sub_8052C28 -sub_8052C28: ; 8052C28 - ldr r1, _08052C40 - movs r0, 0 - strb r0, [r1] - ldr r1, _08052C44 - movs r2, 0 - movs r0, 0 - strh r0, [r1, 0xE] - strb r2, [r1, 0x10] - strb r2, [r1, 0x11] - strb r2, [r1, 0x12] - bx lr - .align 2 -_08052C40: .4byte 0x0300057c -_08052C44: .4byte 0x02024ea4 - thumb_func_end sub_8052C28 - - thumb_func_start sub_8052C48 -sub_8052C48: ; 8052C48 - push {lr} - ldr r1, _08052C64 - movs r0, 0x1 - strb r0, [r1] - ldr r0, _08052C68 - ldrh r1, [r0, 0xE] - ldr r0, _08052C6C - cmp r1, r0 - bls _08052C5E - bl sub_8052CDC -_08052C5E: - pop {r0} - bx r0 - .align 2 -_08052C64: .4byte 0x0300057c -_08052C68: .4byte 0x02024ea4 -_08052C6C: .4byte 0x000003e7 - thumb_func_end sub_8052C48 - - thumb_func_start sub_8052C70 -sub_8052C70: ; 8052C70 - ldr r1, _08052C78 - movs r0, 0 - strb r0, [r1] - bx lr - .align 2 -_08052C78: .4byte 0x0300057c - thumb_func_end sub_8052C70 - - thumb_func_start sub_8052C7C -sub_8052C7C: ; 8052C7C - push {lr} - ldr r0, _08052CD0 - ldrb r0, [r0] - cmp r0, 0x1 - bne _08052CCC - ldr r1, _08052CD4 - ldrb r0, [r1, 0x12] - adds r0, 0x1 - movs r2, 0 - strb r0, [r1, 0x12] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3B - bls _08052CCC - strb r2, [r1, 0x12] - ldrb r0, [r1, 0x11] - adds r0, 0x1 - strb r0, [r1, 0x11] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3B - bls _08052CCC - strb r2, [r1, 0x11] - ldrb r0, [r1, 0x10] - adds r0, 0x1 - strb r0, [r1, 0x10] - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x3B - bls _08052CCC - strb r2, [r1, 0x10] - ldrh r0, [r1, 0xE] - adds r0, 0x1 - strh r0, [r1, 0xE] - lsls r0, 16 - ldr r1, _08052CD8 - cmp r0, r1 - bls _08052CCC - bl sub_8052CDC -_08052CCC: - pop {r0} - bx r0 - .align 2 -_08052CD0: .4byte 0x0300057c -_08052CD4: .4byte 0x02024ea4 -_08052CD8: .4byte 0x03e70000 - thumb_func_end sub_8052C7C - - thumb_func_start sub_8052CDC -sub_8052CDC: ; 8052CDC - ldr r1, _08052CF4 - movs r0, 0x2 - strb r0, [r1] - ldr r1, _08052CF8 - ldr r0, _08052CFC - strh r0, [r1, 0xE] - movs r0, 0x3B - strb r0, [r1, 0x10] - strb r0, [r1, 0x11] - strb r0, [r1, 0x12] - bx lr - .align 2 -_08052CF4: .4byte 0x0300057c -_08052CF8: .4byte 0x02024ea4 -_08052CFC: .4byte 0x000003e7 - thumb_func_end sub_8052CDC + .include "genasm/play_time.s" thumb_func_start write_word_to_mem write_word_to_mem: ; 8052D00 @@ -165311,7 +165195,7 @@ _08052E7E: movs r5, 0 strb r5, [r0, 0x9] bl set_player_trainer_id - bl sub_8052C28 + bl PlayTimeCounter_Reset bl sub_8052D78 bl sub_8069030 bl sub_80BD7A8 @@ -168182,7 +168066,7 @@ c2_load_new_map_2: ; 8054410 bl ResetSafariZoneFlag_ bl NewGameInitData bl player_avatar_init_params_reset - bl sub_8052C48 + bl PlayTimeCounter_Start bl script_env_1_init bl script_env_2_disable ldr r1, _08054454 @@ -168546,7 +168430,7 @@ c2_8056854: ; 8054734 bl InTrainerHill bl sub_805308C bl sub_8055FC0 - bl sub_8052C48 + bl PlayTimeCounter_Start bl script_env_1_init bl script_env_2_disable bl sub_80479F8 diff --git a/include/global.h b/include/global.h index faed7fbcc..fec0500f7 100644 --- a/include/global.h +++ b/include/global.h @@ -45,6 +45,12 @@ struct SaveBlock2 { u8 playerName[8]; u8 playerGender; + u16 playerTrainerId; + u16 playerSecretId; + u16 playTimeHours; + u8 playTimeMinutes; + u8 playTimeSeconds; + u8 playTimeVBlanks; }; extern struct SaveBlock2 gSaveBlock2; diff --git a/include/play_time.h b/include/play_time.h new file mode 100644 index 000000000..ac64b62fb --- /dev/null +++ b/include/play_time.h @@ -0,0 +1,9 @@ +#ifndef GUARD_PLAY_TIME_H +#define GUARD_PLAY_TIME_H + +void PlayTimeCounter_Reset(); +void PlayTimeCounter_Start(); +void PlayTimeCounter_Stop(); +void PlayTimeCounter_Update(); + +#endif // GUARD_PLAY_TIME_H diff --git a/iwram_syms.txt b/iwram_syms.txt index b9128685f..96d059ec9 100644 --- a/iwram_syms.txt +++ b/iwram_syms.txt @@ -1 +1,3 @@ +gPlayTimeCounterState = 0x300057C; + gUnknownStringVar = 0x3002900; diff --git a/src/play_time.c b/src/play_time.c new file mode 100644 index 000000000..f11973d56 --- /dev/null +++ b/src/play_time.c @@ -0,0 +1,73 @@ +#include "global.h" + +enum +{ + STOPPED, + RUNNING, + MAXED_OUT +}; + +extern u8 gPlayTimeCounterState; + +void PlayTimeCounter_SetToMax(); + +void PlayTimeCounter_Reset() +{ + gPlayTimeCounterState = STOPPED; + + gSaveBlock2.playTimeHours = 0; + gSaveBlock2.playTimeMinutes = 0; + gSaveBlock2.playTimeSeconds = 0; + gSaveBlock2.playTimeVBlanks = 0; +} + +void PlayTimeCounter_Start() +{ + gPlayTimeCounterState = RUNNING; + + if (gSaveBlock2.playTimeHours > 999) + PlayTimeCounter_SetToMax(); +} + +void PlayTimeCounter_Stop() +{ + gPlayTimeCounterState = STOPPED; +} + +void PlayTimeCounter_Update() +{ + if (gPlayTimeCounterState == RUNNING) + { + gSaveBlock2.playTimeVBlanks++; + + if (gSaveBlock2.playTimeVBlanks > 59) + { + gSaveBlock2.playTimeVBlanks = 0; + gSaveBlock2.playTimeSeconds++; + + if (gSaveBlock2.playTimeSeconds > 59) + { + gSaveBlock2.playTimeSeconds = 0; + gSaveBlock2.playTimeMinutes++; + + if (gSaveBlock2.playTimeMinutes > 59) + { + gSaveBlock2.playTimeMinutes = 0; + gSaveBlock2.playTimeHours++; + + if (gSaveBlock2.playTimeHours > 999) + PlayTimeCounter_SetToMax(); + } + } + } + } +} + +void PlayTimeCounter_SetToMax() +{ + gPlayTimeCounterState = MAXED_OUT; + gSaveBlock2.playTimeHours = 999; + gSaveBlock2.playTimeMinutes = 59; + gSaveBlock2.playTimeSeconds = 59; + gSaveBlock2.playTimeVBlanks = 59; +} |