summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorProjectRevoTPP <projectrevotpp@hotmail.com>2017-01-04 22:20:17 -0500
committerYamaArashi <YamaArashi@users.noreply.github.com>2017-01-04 19:20:17 -0800
commit4b16d04dccb8013712d9f8853f13a21084718635 (patch)
tree3a86f80a24e26c893844495f2d7a6781484fe384
parentb11ce5c17d95104e496d4ef6e90df750ed319ff5 (diff)
decompile clock.c (#161)
* remove matsuda debug menu from ld_script * decompile clock.c * formatting
-rw-r--r--asm/clock.s176
-rw-r--r--include/global.h10
-rw-r--r--ld_script.txt2
-rw-r--r--src/clock.c91
4 files changed, 97 insertions, 182 deletions
diff --git a/asm/clock.s b/asm/clock.s
deleted file mode 100644
index a1c162682..000000000
--- a/asm/clock.s
+++ /dev/null
@@ -1,176 +0,0 @@
- .include "constants/gba_constants.inc"
- .include "constants/species_constants.inc"
- .include "asm/macros.inc"
-
- .syntax unified
-
- .text
-
- thumb_func_start sub_806A328
-sub_806A328: @ 806A328
- push {lr}
- ldr r0, _0806A350 @ =0x00000835
- bl FlagSet
- bl RtcCalcLocalTime
- ldr r2, _0806A354 @ =gSaveBlock2
- adds r2, 0xA0
- ldr r3, _0806A358 @ =gLocalTime
- ldr r0, [r3]
- ldr r1, [r3, 0x4]
- str r0, [r2]
- str r1, [r2, 0x4]
- ldr r0, _0806A35C @ =0x00004040
- ldrh r1, [r3]
- bl VarSet
- pop {r0}
- bx r0
- .align 2, 0
-_0806A350: .4byte 0x00000835
-_0806A354: .4byte gSaveBlock2
-_0806A358: .4byte gLocalTime
-_0806A35C: .4byte 0x00004040
- thumb_func_end sub_806A328
-
- thumb_func_start DoTimeBasedEvents
-DoTimeBasedEvents: @ 806A360
- push {r4,lr}
- ldr r0, _0806A388 @ =0x00000835
- bl FlagGet
- lsls r0, 24
- cmp r0, 0
- beq _0806A380
- bl RtcCalcLocalTime
- ldr r4, _0806A38C @ =gLocalTime
- adds r0, r4, 0
- bl sub_806A390
- adds r0, r4, 0
- bl sub_806A3F4
-_0806A380:
- pop {r4}
- pop {r0}
- bx r0
- .align 2, 0
-_0806A388: .4byte 0x00000835
-_0806A38C: .4byte gLocalTime
- thumb_func_end DoTimeBasedEvents
-
- thumb_func_start sub_806A390
-sub_806A390: @ 806A390
- push {r4-r6,lr}
- adds r5, r0, 0
- ldr r0, _0806A3F0 @ =0x00004040
- bl GetVarPointer
- adds r6, r0, 0
- ldrh r0, [r6]
- movs r2, 0
- ldrsh r1, [r5, r2]
- cmp r0, r1
- beq _0806A3EA
- cmp r0, r1
- bgt _0806A3EA
- ldrh r4, [r5]
- subs r4, r0
- lsls r4, 16
- lsrs r4, 16
- bl ClearUpperFlags
- adds r0, r4, 0
- bl sub_80FA220
- adds r0, r4, 0
- bl sub_80BE8C4
- adds r0, r4, 0
- bl sub_8080834
- adds r0, r4, 0
- bl UpdatePartyPokerusTime
- adds r0, r4, 0
- bl sub_810D2F4
- adds r0, r4, 0
- bl UpdateBirchState
- adds r0, r4, 0
- bl sub_810F618
- adds r0, r4, 0
- bl SetRandomLotteryNumber
- ldrh r0, [r5]
- strh r0, [r6]
-_0806A3EA:
- pop {r4-r6}
- pop {r0}
- bx r0
- .align 2, 0
-_0806A3F0: .4byte 0x00004040
- thumb_func_end sub_806A390
-
- thumb_func_start sub_806A3F4
-sub_806A3F4: @ 806A3F4
- push {r4-r6,lr}
- sub sp, 0x8
- adds r5, r0, 0
- mov r4, sp
- ldr r6, _0806A448 @ =gSaveBlock2 + 0xA0
- mov r0, sp
- adds r1, r6, 0
- adds r2, r5, 0
- bl CalcTimeDifference
- mov r0, sp
- movs r2, 0
- ldrsh r1, [r0, r2]
- lsls r0, r1, 1
- adds r0, r1
- lsls r1, r0, 4
- subs r1, r0
- lsls r1, 5
- movs r2, 0x2
- ldrsb r2, [r4, r2]
- lsls r0, r2, 4
- subs r0, r2
- lsls r0, 2
- adds r1, r0
- movs r0, 0x3
- ldrsb r0, [r4, r0]
- adds r0, r1, r0
- cmp r0, 0
- beq _0806A43E
- cmp r0, 0
- blt _0806A43E
- bl BerryTreeTimeUpdate
- ldr r0, [r5]
- ldr r1, [r5, 0x4]
- str r0, [r6]
- str r1, [r6, 0x4]
-_0806A43E:
- add sp, 0x8
- pop {r4-r6}
- pop {r0}
- bx r0
- .align 2, 0
-_0806A448: .4byte gSaveBlock2 + 0xA0
- thumb_func_end sub_806A3F4
-
- thumb_func_start sub_806A44C
-sub_806A44C: @ 806A44C
- push {lr}
- bl sub_806A328
- ldr r0, _0806A45C @ =c2_exit_to_overworld_1_continue_scripts_restart_music
- bl SetMainCallback2
- pop {r0}
- bx r0
- .align 2, 0
-_0806A45C: .4byte c2_exit_to_overworld_1_continue_scripts_restart_music
- thumb_func_end sub_806A44C
-
- thumb_func_start sub_806A460
-sub_806A460: @ 806A460
- push {lr}
- ldr r0, _0806A474 @ =Cb2_StartWallClock
- bl SetMainCallback2
- ldr r1, _0806A478 @ =gMain
- ldr r0, _0806A47C @ =sub_806A44C
- str r0, [r1, 0x8]
- pop {r0}
- bx r0
- .align 2, 0
-_0806A474: .4byte Cb2_StartWallClock
-_0806A478: .4byte gMain
-_0806A47C: .4byte sub_806A44C
- thumb_func_end sub_806A460
-
- .align 2, 0 @ Don't pad with nop.
diff --git a/include/global.h b/include/global.h
index 3ad3f3988..30f935521 100644
--- a/include/global.h
+++ b/include/global.h
@@ -359,10 +359,10 @@ extern struct SaveBlock1 gSaveBlock1;
struct Time
{
- s16 days;
- s8 hours;
- s8 minutes;
- s8 seconds;
+ /* 0x00 */ s16 days;
+ /* 0x02 */ s8 hours;
+ /* 0x03 */ s8 minutes;
+ /* 0x04 */ s8 seconds;
};
struct Pokedex
@@ -386,7 +386,7 @@ struct SaveBlock2_Sub
/*0x04CC, 0x0574*/ u8 filler_4CC[0x31C];
};
-struct SaveBlock2
+struct SaveBlock2 /* 0x02024EA4 */
{
/*0x00*/ u8 playerName[8];
/*0x08*/ u8 playerGender; // MALE, FEMALE
diff --git a/ld_script.txt b/ld_script.txt
index d0af456cd..c86a82a0f 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -90,7 +90,7 @@ SECTIONS {
src/event_data.o(.text);
src/coord_event_weather.o(.text);
asm/field_tasks.o(.text);
- asm/clock.o(.text);
+ src/clock.o(.text);
asm/reset_rtc_screen.o(.text);
asm/party_menu.o(.text);
src/start_menu.o(.text);
diff --git a/src/clock.c b/src/clock.c
new file mode 100644
index 000000000..cc0892f34
--- /dev/null
+++ b/src/clock.c
@@ -0,0 +1,91 @@
+#include "global.h"
+#include "main.h"
+#include "rtc.h"
+#include "event_data.h"
+#include "lottery_corner.h"
+#include "berry.h"
+#include "rom4.h"
+#include "wallclock.h"
+
+extern void sub_80FA220(u16);
+extern void sub_80BE8C4(u16);
+extern void sub_8080834(u16);
+extern void UpdatePartyPokerusTime(u16);
+extern void sub_810D2F4(u16);
+extern void UpdateBirchState(u16);
+extern void sub_810F618(u16);
+
+void sub_806A390(struct Time *time);
+void sub_806A3F4(struct Time *time);
+void sub_806A328(void);
+
+void sub_806A328(void)
+{
+ FlagSet(0x835);
+ RtcCalcLocalTime();
+ gSaveBlock2.lastBerryTreeUpdate = gLocalTime;
+ VarSet(0x4040, gLocalTime.days);
+}
+
+void DoTimeBasedEvents(void)
+{
+ if(FlagGet(0x835))
+ {
+ RtcCalcLocalTime();
+ sub_806A390(&gLocalTime);
+ sub_806A3F4(&gLocalTime);
+ }
+}
+
+void sub_806A390(struct Time *time)
+{
+ u16 *varPtr = GetVarPointer(0x4040);
+ int days = *varPtr;
+ u16 newDays;
+
+ if(days != time->days && days <= time->days)
+ {
+ newDays = time->days - days;
+ ClearUpperFlags();
+ sub_80FA220(newDays);
+ sub_80BE8C4(newDays);
+ sub_8080834(newDays);
+ UpdatePartyPokerusTime(newDays);
+ sub_810D2F4(newDays);
+ UpdateBirchState(newDays);
+ sub_810F618(newDays);
+ SetRandomLotteryNumber(newDays);
+ *varPtr = time->days;
+ }
+}
+
+void sub_806A3F4(struct Time *time)
+{
+ struct Time newTime;
+ s32 totalSeconds;
+
+ CalcTimeDifference(&newTime, &gSaveBlock2.lastBerryTreeUpdate, time);
+ totalSeconds = 1440 * newTime.days + 60 * newTime.hours + newTime.minutes;
+
+ // there's no way to get the correct assembly other than with this nested if check. so dumb.
+ if(totalSeconds != 0)
+ {
+ if(totalSeconds >= 0)
+ {
+ BerryTreeTimeUpdate(totalSeconds);
+ gSaveBlock2.lastBerryTreeUpdate = *time;
+ }
+ }
+}
+
+void sub_806A44C(void)
+{
+ sub_806A328();
+ SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music);
+}
+
+void sub_806A460(void)
+{
+ SetMainCallback2(Cb2_StartWallClock);
+ gMain.field_8 = sub_806A44C;
+}