decompile time events

This commit is contained in:
DizzyEggg 2018-01-29 15:55:34 +01:00
parent 10037ac0e1
commit d728124a7b
8 changed files with 299 additions and 240 deletions

View File

@ -2472,15 +2472,15 @@ _080AC3B6:
bx r0 bx r0
thumb_func_end play_some_sound thumb_func_end play_some_sound
thumb_func_start sub_80AC3BC thumb_func_start IsWeatherChangeComplete
sub_80AC3BC: @ 80AC3BC IsWeatherChangeComplete: @ 80AC3BC
ldr r0, =gUnknown_02038454 ldr r0, =gUnknown_02038454
ldr r1, =0x000006d3 ldr r1, =0x000006d3
adds r0, r1 adds r0, r1
ldrb r0, [r0] ldrb r0, [r0]
bx lr bx lr
.pool .pool
thumb_func_end sub_80AC3BC thumb_func_end IsWeatherChangeComplete
thumb_func_start sub_80AC3D0 thumb_func_start sub_80AC3D0
sub_80AC3D0: @ 80AC3D0 sub_80AC3D0: @ 80AC3D0

View File

@ -1,225 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start GetMirageRnd
GetMirageRnd: @ 8137890
push {r4,lr}
ldr r0, =0x00004024
bl VarGet
adds r4, r0, 0
lsls r4, 16
lsrs r4, 16
ldr r0, =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
.pool
thumb_func_end GetMirageRnd
thumb_func_start SetMirageRnd
SetMirageRnd: @ 81378BC
push {r4,lr}
adds r4, r0, 0
ldr r0, =0x00004024
lsrs r1, r4, 16
bl VarSet
ldr r0, =0x00004025
lsls r4, 16
lsrs r4, 16
adds r1, r4, 0
bl VarSet
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end SetMirageRnd
thumb_func_start InitMirageRnd
InitMirageRnd: @ 81378E4
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 SetMirageRnd
pop {r4}
pop {r0}
bx r0
thumb_func_end InitMirageRnd
thumb_func_start UpdateMirageRnd
UpdateMirageRnd: @ 8137904
push {r4,lr}
lsls r0, 16
lsrs r4, r0, 16
bl GetMirageRnd
adds r1, r0, 0
cmp r4, 0
beq _08137928
ldr r3, =0x41c64e6d
ldr r2, =0x00003039
_08137918:
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 _08137918
_08137928:
adds r0, r1, 0
bl SetMirageRnd
pop {r4}
pop {r0}
bx r0
.pool
thumb_func_end UpdateMirageRnd
thumb_func_start IsMirageIslandPresent
IsMirageIslandPresent: @ 813793C
push {r4-r6,lr}
bl GetMirageRnd
lsrs r6, r0, 16
movs r5, 0
_08137946:
movs r0, 0x64
adds r1, r5, 0
muls r1, r0
ldr r0, =gPlayerParty
adds r4, r1, r0
adds r0, r4, 0
movs r1, 0xB
bl GetMonData
cmp r0, 0
beq _08137978
adds r0, r4, 0
movs r1, 0
bl GetMonData
ldr r1, =0x0000ffff
ands r1, r0
cmp r1, r6
bne _08137978
movs r0, 0x1
b _08137980
.pool
_08137978:
adds r5, 0x1
cmp r5, 0x5
ble _08137946
movs r0, 0
_08137980:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end IsMirageIslandPresent
thumb_func_start UpdateShoalTideFlag
UpdateShoalTideFlag: @ 8137988
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 _081379CE
bl RtcCalcLocalTime
ldr r1, =gUnknown_085B2B44
ldr r0, =gLocalTime
ldrb r0, [r0, 0x2]
lsls r0, 24
asrs r0, 24
adds r0, r1
ldrb r0, [r0]
cmp r0, 0
beq _081379C8
ldr r0, =0x0000089a
bl FlagSet
b _081379CE
.pool
_081379C8:
ldr r0, =0x0000089a
bl FlagClear
_081379CE:
pop {r0}
bx r0
.pool
thumb_func_end UpdateShoalTideFlag
thumb_func_start Task_WaitWeather
Task_WaitWeather: @ 81379D8
push {r4,lr}
lsls r0, 24
lsrs r4, r0, 24
bl sub_80AC3BC
lsls r0, 24
cmp r0, 0
beq _081379F2
bl EnableBothScriptContexts
adds r0, r4, 0
bl DestroyTask
_081379F2:
pop {r4}
pop {r0}
bx r0
thumb_func_end Task_WaitWeather
thumb_func_start WaitWeather
WaitWeather: @ 81379F8
push {lr}
ldr r0, =Task_WaitWeather
movs r1, 0x50
bl CreateTask
pop {r0}
bx r0
.pool
thumb_func_end WaitWeather
thumb_func_start InitBirchState
InitBirchState: @ 8137A0C
push {lr}
ldr r0, =0x00004049
bl GetVarPointer
movs r1, 0
strh r1, [r0]
pop {r0}
bx r0
.pool
thumb_func_end InitBirchState
thumb_func_start UpdateBirchState
UpdateBirchState: @ 8137A20
push {r4,r5,lr}
adds r4, r0, 0
lsls r4, 16
lsrs r4, 16
ldr r0, =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
.pool
thumb_func_end UpdateBirchState

View File

@ -1,7 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.section .rodata
gUnknown_085B2B44:: @ 85B2B44
.byte 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01

View File

@ -1,12 +1,175 @@
#ifndef GUARD_WEATHER_H #ifndef GUARD_WEATHER_H
#define GUARD_WEATHER_H #define GUARD_WEATHER_H
void fade_screen(u8, s8); #include "sprite.h"
// Controls how the weather should be changing the screen palettes.
enum {
WEATHER_PAL_STATE_CHANGING_WEATHER,
WEATHER_PAL_STATE_SCREEN_FADING_IN,
WEATHER_PAL_STATE_SCREEN_FADING_OUT,
WEATHER_PAL_STATE_IDLE,
};
struct Weather
{
union
{
struct
{
struct Sprite *rainSprites[24];
struct Sprite *snowflakeSprites[101];
struct Sprite *cloudSprites[3];
} s1;
struct
{
u8 filler0[0xA0];
struct Sprite *fog1Sprites[20];
struct Sprite *ashSprites[20];
struct Sprite *fog2Sprites[20];
struct Sprite *sandstormSprites1[20];
struct Sprite *sandstormSprites2[5];
} s2;
} sprites;
u8 gammaShifts[19][32];
u8 altGammaShifts[19][32];
s8 gammaIndex;
s8 gammaTargetIndex;
u8 gammaStepDelay;
u8 gammaStepFrameCounter;
u16 fadeDestColor;
u8 palProcessingState;
u8 fadeScreenCounter;
bool8 readyForInit;
u8 taskId;
u8 unknown_6CA;
u8 unknown_6CB;
u16 initStep;
u16 finishStep;
u8 currWeather;
u8 nextWeather;
u8 weatherGfxLoaded;
bool8 weatherChangeComplete;
u8 weatherPicSpritePalIndex;
u8 altGammaSpritePalIndex;
u16 unknown_6D6;
u8 unknown_6D8;
u8 unknown_6D9;
u8 rainSpriteCount;
u8 unknown_6DB;
u8 unknown_6DC;
u8 rainStrength;
/*0x6DE*/ u8 cloudSpritesCreated;
u8 filler_6DF[1];
u16 unknown_6E0;
u16 unknown_6E2;
u8 snowflakeSpriteCount;
u8 unknown_6E5;
u16 unknown_6E6;
u16 thunderCounter;
u8 unknown_6EA;
u8 unknown_6EB;
u8 unknown_6EC;
u8 unknown_6ED;
u16 fog1ScrollPosX;
u16 unknown_6F0;
u16 unknown_6F2;
u8 lightenedFogSpritePals[6];
u8 lightenedFogSpritePalsCount;
u8 fog1SpritesCreated;
u16 unknown_6FC;
u16 unknown_6FE;
u8 ashSpritesCreated;
u8 filler_701[3];
u32 unknown_704;
u32 unknown_708;
u8 filler_70C[2];
u16 unknown_70E;
u16 unknown_710;
u16 unknown_712;
u16 unknown_714;
u8 sandstormSprites1Created;
u8 sandstormSprites2Created;
u16 unknown_718;
u16 unknown_71A;
u16 unknown_71C;
u16 unknown_71E;
u16 unknown_720;
u16 unknown_722;
u8 fog2SpritesCreated;
u8 filler_725[1];
u16 unknown_726;
u16 unknown_728;
u16 unknown_72A;
u16 unknown_72C;
u8 unknown_72E;
u8 filler_72F;
u16 currBlendEVA;
u16 currBlendEVB;
u16 targetBlendEVA;
u16 targetBlendEVB;
u8 blendUpdateCounter;
u8 blendFrameCounter;
u8 blendDelay;
u8 filler_73B[0x3C-0x3B];
s16 unknown_73C;
s16 unknown_73E;
s16 unknown_740;
s16 unknown_742;
u8 filler_744[0xD-4];
s8 loadDroughtPalsIndex;
u8 loadDroughtPalsOffset;
};
void StartWeather(void);
void ChangeWeather(u8 weather);
void sub_807C988(u8 effect);
void sub_807C9B4(u8 effect);
void Task_WeatherInit(u8);
void Task_WeatherMain(u8);
void sub_807CAE8(void);
void nullsub_38(void);
void SetWeatherScreenFadeOut(void);
enum
{
FADE_FROM_BLACK,
FADE_TO_BLACK,
FADE_FROM_WHITE,
FADE_TO_WHITE,
};
void FadeScreen(u8, u8);
// ...
void UpdateSpritePaletteWithWeather(u8 tag);
void ApplyWeatherGammaShiftToPal(u8);
// ...
void Weather_SetBlendCoeffs(u8, u8);
// ...
void PlayRainSoundEffect(void);
// ...
void SetSav1Weather(u32); void SetSav1Weather(u32);
u8 GetSav1Weather(void); u8 GetSav1Weather(void);
void sub_80AEDBC(void); void SetSav1WeatherFromCurrMapHeader(void);
// ...
void DoCurrentWeather(void); void DoCurrentWeather(void);
void sub_8080750();
bool8 IsWeatherNotFadingIn(void);
bool8 IsWeatherChangeComplete(void);
void SetWeather(u32);
void UpdateWeatherPerDay(u16);
void PreservePaletteInWeather(u8 index);
void ResetPreservedPalettesInWeather(void);
extern void ResetDroughtWeatherPaletteLoading(void);
void ResetDroughtWeatherPaletteLoading(void);
bool8 LoadDroughtWeatherPalettes(void);
u8 GetCurrentWeather(void);
void LoadCustomWeatherSpritePalette(const u16 *palette);
extern struct Weather gWeather;
extern struct Weather *const gWeatherPtr;
#endif // GUARD_WEATHER_H #endif // GUARD_WEATHER_H

View File

@ -70,6 +70,8 @@ void warp1_set_2(s8 mapGroup, s8 mapNum, s8 warpNum);
void c2_load_new_map(void); void c2_load_new_map(void);
void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused); void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused);
void mapldr_default(void); void mapldr_default(void);
u8 get_map_light_from_warp0(void);
bool8 is_light_level_1_2_3_5_or_6(u8 a1);
void IncrementGameStat(u8); void IncrementGameStat(u8);
u32 GetGameStat(u8); u32 GetGameStat(u8);

8
include/time_events.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef GUARD_TIME_EVENTS_H
#define GUARD_TIME_EVENTS_H
void UpdateMirageRnd(u16);
u8 IsMirageIslandPresent(void);
void UpdateBirchState(u16);
#endif // GUARD_TIME_EVENTS_H

View File

@ -185,7 +185,7 @@ SECTIONS {
src/pokeblock.o(.text); src/pokeblock.o(.text);
asm/fldeff_flash.o(.text); asm/fldeff_flash.o(.text);
asm/post_battle_event_funcs.o(.text); asm/post_battle_event_funcs.o(.text);
asm/time_events.o(.text); src/time_events.o(.text);
asm/birch_pc.o(.text); asm/birch_pc.o(.text);
src/hof_pc.o(.text); src/hof_pc.o(.text);
asm/field_specials.o(.text); asm/field_specials.o(.text);
@ -472,7 +472,7 @@ SECTIONS {
src/wallclock.o(.rodata); src/wallclock.o(.rodata);
src/pokeblock.o(.rodata); src/pokeblock.o(.rodata);
data/fldeff_flash.o(.rodata); data/fldeff_flash.o(.rodata);
data/time_events.o(.rodata); src/time_events.o(.rodata);
data/field_specials.o(.rodata); data/field_specials.o(.rodata);
data/battle_records.o(.rodata); data/battle_records.o(.rodata);
data/pokedex_area_screen.o(.rodata); data/pokedex_area_screen.o(.rodata);

118
src/time_events.c Normal file
View File

@ -0,0 +1,118 @@
#include "global.h"
#include "time_events.h"
#include "event_data.h"
#include "field_weather.h"
#include "pokemon.h"
#include "random.h"
#include "overworld.h"
#include "rtc.h"
#include "script.h"
#include "task.h"
static u32 GetMirageRnd(void)
{
u32 hi = VarGet(VAR_MIRAGE_RND_H);
u32 lo = VarGet(VAR_MIRAGE_RND_L);
return (hi << 16) | lo;
}
static 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, // 00
1, // 01
1, // 02
0, // 03
0, // 04
0, // 05
0, // 06
0, // 07
0, // 08
1, // 09
1, // 10
1, // 11
1, // 12
1, // 13
1, // 14
0, // 15
0, // 16
0, // 17
0, // 18
0, // 19
0, // 20
1, // 21
1, // 22
1, // 23
};
if (is_light_level_1_2_3_5_or_6(get_map_light_from_warp0()))
{
RtcCalcLocalTime();
if (tide[gLocalTime.hours])
FlagSet(FLAG_SYS_SHOAL_TIDE);
else
FlagClear(FLAG_SYS_SHOAL_TIDE);
}
}
static void Task_WaitWeather(u8 taskId)
{
if (IsWeatherChangeComplete())
{
EnableBothScriptContexts();
DestroyTask(taskId);
}
}
void WaitWeather(void)
{
CreateTask(Task_WaitWeather, 80);
}
void InitBirchState(void)
{
*GetVarPointer(VAR_BIRCH_STATE) = 0;
}
void UpdateBirchState(u16 days)
{
u16 *state = GetVarPointer(VAR_BIRCH_STATE);
*state += days;
*state %= 7;
}