summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYamaArashi <shadow962@live.com>2017-05-04 00:10:25 -0700
committerYamaArashi <shadow962@live.com>2017-05-04 00:21:04 -0700
commitd7284694ec3543b84074f52938ea5e6666e17599 (patch)
treef401f21a422181f09bc7ff7f1c24025543823009
parentf492004cb605a45b0b43e94121a0f504d7fb10cc (diff)
decompile time_events
-rw-r--r--asm/time_events.s243
-rw-r--r--data/specials.inc6
-rw-r--r--data/time_events.s31
-rw-r--r--include/asm.inc.h2
-rw-r--r--include/pokemon.h6
-rw-r--r--include/rom4.h2
-rw-r--r--include/vars.h3
-rw-r--r--ld_script.txt4
-rw-r--r--src/clock.c4
-rw-r--r--src/rom4.c2
-rw-r--r--src/time_events.c118
11 files changed, 135 insertions, 286 deletions
diff --git a/asm/time_events.s b/asm/time_events.s
deleted file mode 100644
index 09202f2ef..000000000
--- a/asm/time_events.s
+++ /dev/null
@@ -1,243 +0,0 @@
- .include "constants/gba_constants.inc"
- .include "constants/species_constants.inc"
- .include "asm/macros.inc"
-
- .syntax unified
-
- .text
-
- thumb_func_start sub_810D280
-sub_810D280: @ 810D280
- push {r4,lr}
- ldr r0, _0810D2A4 @ =0x00004024
- bl VarGet
- adds r4, r0, 0
- lsls r4, 16
- lsrs r4, 16
- ldr r0, _0810D2A8 @ =0x00004025
- bl VarGet
- lsls r0, 16
- lsrs r0, 16
- lsls r4, 16
- orrs r4, r0
- adds r0, r4, 0
- pop {r4}
- pop {r1}
- bx r1
- .align 2, 0
-_0810D2A4: .4byte 0x00004024
-_0810D2A8: .4byte 0x00004025
- thumb_func_end sub_810D280
-
- thumb_func_start sub_810D2AC
-sub_810D2AC: @ 810D2AC
- push {r4,lr}
- adds r4, r0, 0
- ldr r0, _0810D2CC @ =0x00004024
- lsrs r1, r4, 16
- bl VarSet
- ldr r0, _0810D2D0 @ =0x00004025
- lsls r4, 16
- lsrs r4, 16
- adds r1, r4, 0
- bl VarSet
- pop {r4}
- pop {r0}
- bx r0
- .align 2, 0
-_0810D2CC: .4byte 0x00004024
-_0810D2D0: .4byte 0x00004025
- thumb_func_end sub_810D2AC
-
- thumb_func_start unref_sub_810D2D4
-unref_sub_810D2D4: @ 810D2D4
- push {r4,lr}
- bl Random
- adds r4, r0, 0
- bl Random
- lsls r4, 16
- lsls r0, 16
- lsrs r0, 16
- orrs r4, r0
- adds r0, r4, 0
- bl sub_810D2AC
- pop {r4}
- pop {r0}
- bx r0
- thumb_func_end unref_sub_810D2D4
-
- thumb_func_start sub_810D2F4
-sub_810D2F4: @ 810D2F4
- push {r4,lr}
- lsls r0, 16
- lsrs r4, r0, 16
- bl sub_810D280
- adds r1, r0, 0
- cmp r4, 0
- beq _0810D318
- ldr r3, _0810D324 @ =0x41c64e6d
- ldr r2, _0810D328 @ =0x00003039
-_0810D308:
- adds r0, r1, 0
- muls r0, r3
- adds r1, r0, r2
- subs r0, r4, 0x1
- lsls r0, 16
- lsrs r4, r0, 16
- cmp r4, 0
- bne _0810D308
-_0810D318:
- adds r0, r1, 0
- bl sub_810D2AC
- pop {r4}
- pop {r0}
- bx r0
- .align 2, 0
-_0810D324: .4byte 0x41c64e6d
-_0810D328: .4byte 0x00003039
- thumb_func_end sub_810D2F4
-
- thumb_func_start sub_810D32C
-sub_810D32C: @ 810D32C
- push {r4-r6,lr}
- bl sub_810D280
- lsrs r6, r0, 16
- movs r5, 0
-_0810D336:
- movs r0, 0x64
- adds r1, r5, 0
- muls r1, r0
- ldr r0, _0810D360 @ =gPlayerParty
- adds r4, r1, r0
- adds r0, r4, 0
- movs r1, 0xB
- bl GetMonData
- cmp r0, 0
- beq _0810D368
- adds r0, r4, 0
- movs r1, 0
- bl GetMonData
- ldr r1, _0810D364 @ =0x0000ffff
- ands r1, r0
- cmp r1, r6
- bne _0810D368
- movs r0, 0x1
- b _0810D370
- .align 2, 0
-_0810D360: .4byte gPlayerParty
-_0810D364: .4byte 0x0000ffff
-_0810D368:
- adds r5, 0x1
- cmp r5, 0x5
- ble _0810D336
- movs r0, 0
-_0810D370:
- pop {r4-r6}
- pop {r1}
- bx r1
- thumb_func_end sub_810D32C
-
- thumb_func_start UpdateShoalTideFlag
-UpdateShoalTideFlag: @ 810D378
- push {lr}
- bl get_map_light_from_warp0
- lsls r0, 24
- lsrs r0, 24
- bl is_light_level_1_2_3_5_or_6
- lsls r0, 24
- cmp r0, 0
- beq _0810D3BE
- bl RtcCalcLocalTime
- ldr r1, _0810D3AC @ =gUnknown_083F8340
- ldr r0, _0810D3B0 @ =gLocalTime
- ldrb r0, [r0, 0x2]
- lsls r0, 24
- asrs r0, 24
- adds r0, r1
- ldrb r0, [r0]
- cmp r0, 0
- beq _0810D3B8
- ldr r0, _0810D3B4 @ =0x0000083a
- bl FlagSet
- b _0810D3BE
- .align 2, 0
-_0810D3AC: .4byte gUnknown_083F8340
-_0810D3B0: .4byte gLocalTime
-_0810D3B4: .4byte 0x0000083a
-_0810D3B8:
- ldr r0, _0810D3C4 @ =0x0000083a
- bl FlagReset
-_0810D3BE:
- pop {r0}
- bx r0
- .align 2, 0
-_0810D3C4: .4byte 0x0000083a
- thumb_func_end UpdateShoalTideFlag
-
- thumb_func_start sub_810D3C8
-sub_810D3C8: @ 810D3C8
- push {r4,lr}
- lsls r0, 24
- lsrs r4, r0, 24
- bl sub_807DDFC
- lsls r0, 24
- cmp r0, 0
- beq _0810D3E2
- bl EnableBothScriptContexts
- adds r0, r4, 0
- bl DestroyTask
-_0810D3E2:
- pop {r4}
- pop {r0}
- bx r0
- thumb_func_end sub_810D3C8
-
- thumb_func_start sub_810D3E8
-sub_810D3E8: @ 810D3E8
- push {lr}
- ldr r0, _0810D3F8 @ =sub_810D3C8
- movs r1, 0x50
- bl CreateTask
- pop {r0}
- bx r0
- .align 2, 0
-_0810D3F8: .4byte sub_810D3C8
- thumb_func_end sub_810D3E8
-
- thumb_func_start sub_810D3FC
-sub_810D3FC: @ 810D3FC
- push {lr}
- ldr r0, _0810D40C @ =0x00004049
- bl GetVarPointer
- movs r1, 0
- strh r1, [r0]
- pop {r0}
- bx r0
- .align 2, 0
-_0810D40C: .4byte 0x00004049
- thumb_func_end sub_810D3FC
-
- thumb_func_start UpdateBirchState
-UpdateBirchState: @ 810D410
- push {r4,r5,lr}
- adds r4, r0, 0
- lsls r4, 16
- lsrs r4, 16
- ldr r0, _0810D438 @ =0x00004049
- bl GetVarPointer
- adds r5, r0, 0
- ldrh r0, [r5]
- adds r4, r0
- strh r4, [r5]
- ldrh r0, [r5]
- movs r1, 0x7
- bl __umodsi3
- strh r0, [r5]
- pop {r4,r5}
- pop {r0}
- bx r0
- .align 2, 0
-_0810D438: .4byte 0x00004049
- thumb_func_end UpdateBirchState
-
- .align 2, 0 @ Don't pad with nop.
diff --git a/data/specials.inc b/data/specials.inc
index 11572e1f3..76763781d 100644
--- a/data/specials.inc
+++ b/data/specials.inc
@@ -209,9 +209,9 @@ gSpecials::
.4byte ExitSafariMode
.4byte SafariZoneGetPokeblockNameInFeeder
.4byte sub_810BAF4
- .4byte sub_810D32C
+ .4byte IsMirageIslandPresent
.4byte UpdateShoalTideFlag
- .4byte sub_810D3FC
+ .4byte InitBirchState
.4byte ScriptGetPokedexInfo
.4byte ShowPokedexRatingMessage
.4byte DoPCTurnOnEffect
@@ -284,7 +284,7 @@ gSpecials::
.4byte sub_80818A4
.4byte sub_80818FC
.4byte ShowBattleTowerRecords
- .4byte sub_810D3E8
+ .4byte WaitWeather
.4byte sub_810F414
.4byte sub_810F424
.4byte player_get_direction_lower_nybble
diff --git a/data/time_events.s b/data/time_events.s
deleted file mode 100644
index bccafb3ef..000000000
--- a/data/time_events.s
+++ /dev/null
@@ -1,31 +0,0 @@
- .include "asm/macros.inc"
- .include "constants/constants.inc"
-
- .section .rodata
-
- .align 2
-gUnknown_083F8340:: @ 83F8340
- .byte 1
- .byte 1
- .byte 1
- .byte 0
- .byte 0
- .byte 0
- .byte 0
- .byte 0
- .byte 0
- .byte 1
- .byte 1
- .byte 1
- .byte 1
- .byte 1
- .byte 1
- .byte 0
- .byte 0
- .byte 0
- .byte 0
- .byte 0
- .byte 0
- .byte 1
- .byte 1
- .byte 1
diff --git a/include/asm.inc.h b/include/asm.inc.h
index d0fe6e354..416917fa6 100644
--- a/include/asm.inc.h
+++ b/include/asm.inc.h
@@ -356,7 +356,7 @@ s16 sub_810CAE4(u8, struct Pokeblock *);
void sub_810CC80(void);
// asm/time_events.o
-u8 sub_810D32C(void);
+u8 IsMirageIslandPresent(void);
// asm/field_specials.o
void ResetCyclingRoadChallengeData(void);
diff --git a/include/pokemon.h b/include/pokemon.h
index e0ad7136c..39bde80cb 100644
--- a/include/pokemon.h
+++ b/include/pokemon.h
@@ -114,6 +114,8 @@
#define TYPE_DRAGON 0x10
#define TYPE_DARK 0x11
+#define PARTY_SIZE 6
+
enum {
NATURE_HARDY,
NATURE_LONELY,
@@ -376,8 +378,8 @@ struct PokemonStorage
u8 unkArray[14];
};
-extern struct Pokemon gPlayerParty[6];
-extern struct Pokemon gEnemyParty[6];
+extern struct Pokemon gPlayerParty[PARTY_SIZE];
+extern struct Pokemon gEnemyParty[PARTY_SIZE];
void ZeroBoxMonData(struct BoxPokemon *boxMon);
void ZeroMonData(struct Pokemon *mon);
diff --git a/include/rom4.h b/include/rom4.h
index f78386213..476a0e103 100644
--- a/include/rom4.h
+++ b/include/rom4.h
@@ -100,7 +100,7 @@ void sub_8054164(void);
u8 get_map_light_level_by_bank_and_number(s8 mapGroup, s8 mapNum);
// get_map_light_level_from_warp
u8 sav1_map_get_light_level(void);
-// get_map_light_from_warp0
+u8 get_map_light_from_warp0(void);
bool8 is_light_level_1_2_3_5_or_6(u8 a1);
bool8 is_light_level_1_2_3_or_6(u8 a1);
u8 is_light_level_8_or_9(u8);
diff --git a/include/vars.h b/include/vars.h
index 3fc71dc15..5477ba98a 100644
--- a/include/vars.h
+++ b/include/vars.h
@@ -7,6 +7,7 @@
#define VAR_FIRST_POKE 0x4023
#define VAR_MIRAGE_RND_H 0x4024
#define VAR_MIRAGE_RND_L 0x4025
+#define VAR_SECRET_BASE_MAP 0x4026
#define VAR_HAPPINESS_STEP_COUNTER 0x402A
#define VAR_POISON_STEP_COUNTER 0x402B
@@ -18,6 +19,8 @@
#define VAR_NATIONAL_DEX 0x4046
#define VAR_SHROOMISH_SIZE_RECORD 0x4047
+#define VAR_BIRCH_STATE 0x4049
+
#define VAR_POKELOT_RND1 0x404B
#define VAR_POKELOT_RND2 0x404C
diff --git a/ld_script.txt b/ld_script.txt
index 6d21f6442..c329ef736 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -213,7 +213,7 @@ SECTIONS {
asm/pokeblock.o(.text);
asm/fldeff_flash.o(.text);
src/post_battle_event_funcs.o(.text);
- asm/time_events.o(.text);
+ src/time_events.o(.text);
asm/birch_pc.o(.text);
src/hof_pc.o(.text);
asm/field_specials.o(.text);
@@ -426,7 +426,7 @@ SECTIONS {
src/wallclock.o(.rodata);
data/pokeblock.o(.rodata);
data/fldeff_flash.o(.rodata);
- data/time_events.o(.rodata);
+ src/time_events.o(.rodata);
data/field_specials.o(.rodata);
data/pokedex_area_screen.o(.rodata);
data/evolution_scene.o(.rodata);
diff --git a/src/clock.c b/src/clock.c
index ceb140774..4ec49807c 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -12,7 +12,7 @@ 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 UpdateMirageRnd(u16);
extern void UpdateBirchState(u16);
extern void sub_810F618(u16);
@@ -53,7 +53,7 @@ static void UpdatePerDay(struct Time *time)
sub_80BE8C4(newDays);
sub_8080834(newDays);
UpdatePartyPokerusTime(newDays);
- sub_810D2F4(newDays);
+ UpdateMirageRnd(newDays);
UpdateBirchState(newDays);
sub_810F618(newDays);
SetRandomLotteryNumber(newDays);
diff --git a/src/rom4.c b/src/rom4.c
index ba1b31348..3d388fd6d 100644
--- a/src/rom4.c
+++ b/src/rom4.c
@@ -932,7 +932,7 @@ void sub_80540D0(s16 *a1, u16 *a2)
void sub_8054164(void)
{
- if ((gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 45) && !sub_810D32C())
+ if ((gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 45) && !IsMirageIslandPresent())
{
gUnknown_02029816 = TRUE;
gUnknown_02029814 = GetMirageIslandMon();
diff --git a/src/time_events.c b/src/time_events.c
new file mode 100644
index 000000000..8cbf52a1a
--- /dev/null
+++ b/src/time_events.c
@@ -0,0 +1,118 @@
+#include "global.h"
+#include "event_data.h"
+#include "pokemon.h"
+#include "rng.h"
+#include "rom4.h"
+#include "rtc.h"
+#include "script.h"
+#include "task.h"
+
+extern bool8 sub_807DDFC(void);
+
+u32 GetMirageRnd(void)
+{
+ u32 hi = VarGet(VAR_MIRAGE_RND_H);
+ u32 lo = VarGet(VAR_MIRAGE_RND_L);
+ return (hi << 16) | lo;
+}
+
+void SetMirageRnd(u32 rnd)
+{
+ VarSet(VAR_MIRAGE_RND_H, rnd >> 16);
+ VarSet(VAR_MIRAGE_RND_L, rnd);
+}
+
+// unused
+void InitMirageRnd(void)
+{
+ SetMirageRnd((Random() << 16) | Random());
+}
+
+void UpdateMirageRnd(u16 days)
+{
+ s32 rnd = GetMirageRnd();
+ while (days)
+ {
+ rnd = 1103515245 * rnd + 12345;
+ days--;
+ }
+ SetMirageRnd(rnd);
+}
+
+bool8 IsMirageIslandPresent(void)
+{
+ u16 rnd = GetMirageRnd() >> 16;
+ int i;
+
+ for (i = 0; i < PARTY_SIZE; i++)
+ if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && (GetMonData(&gPlayerParty[i], MON_DATA_PERSONALITY) & 0xFFFF) == rnd)
+ return TRUE;
+
+ return FALSE;
+}
+
+void UpdateShoalTideFlag(void)
+{
+ static const u8 tide[] =
+ {
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 1,
+ 1,
+ 1,
+ };
+
+ if (is_light_level_1_2_3_5_or_6(get_map_light_from_warp0()))
+ {
+ RtcCalcLocalTime();
+ if (tide[gLocalTime.hours])
+ FlagSet(SYS_SHOAL_TIDE);
+ else
+ FlagReset(SYS_SHOAL_TIDE);
+ }
+}
+
+static void Task_WaitWeather(u8 taskId)
+{
+ if (sub_807DDFC())
+ {
+ EnableBothScriptContexts();
+ DestroyTask(taskId);
+ }
+}
+
+void WaitWeather(void)
+{
+ CreateTask(Task_WaitWeather, 80);
+}
+
+void InitBirchState(void)
+{
+ *(u16 *)GetVarPointer(VAR_BIRCH_STATE) = 0;
+}
+
+void UpdateBirchState(u16 days)
+{
+ u16 *state = GetVarPointer(VAR_BIRCH_STATE);
+ *state += days;
+ *state %= 7;
+}