From e7e1938094081ba2e20232caca0239cb2290251f Mon Sep 17 00:00:00 2001 From: scnorton Date: Tue, 19 Sep 2017 16:17:23 -0400 Subject: [PATCH] Start decompilation of lilycove_lady --- asm/lilycove_lady.s | 95 +-------------------------------------------- include/global.h | 35 ++++++++++++++++- include/vars.h | 2 + ld_script.txt | 1 + src/lilycove_lady.c | 57 +++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 95 deletions(-) create mode 100644 src/lilycove_lady.c diff --git a/asm/lilycove_lady.s b/asm/lilycove_lady.s index fca8cb29b..76ba3e423 100644 --- a/asm/lilycove_lady.s +++ b/asm/lilycove_lady.s @@ -4,99 +4,6 @@ .syntax unified .text - - thumb_func_start GetLilycoveLadyId -GetLilycoveLadyId: @ 818D9AC - ldr r0, =gSaveBlock1Ptr - ldr r0, [r0] - ldr r1, =0x00003b58 - adds r0, r1 - ldrb r0, [r0] - bx lr - .pool - thumb_func_end GetLilycoveLadyId - - thumb_func_start sub_818D9C0 -sub_818D9C0: @ 818D9C0 - push {r4,r5,lr} - ldr r5, =0x00004010 - ldr r4, =gUnknown_0860B07E - bl GetLilycoveLadyId - lsls r0, 24 - lsrs r0, 23 - adds r0, r4 - ldrh r1, [r0] - adds r0, r5, 0 - bl VarSet - bl GetLilycoveLadyId - lsls r0, 24 - lsrs r0, 24 - cmp r0, 0x2 - bne _0818DA20 - ldr r0, =gSaveBlock1Ptr - ldr r1, [r0] - ldr r0, =0x00003b58 - adds r1, r0 - ldr r0, =0x00004011 - ldr r2, =gUnknown_0860B074 - ldrb r1, [r1, 0xD] - lsls r1, 1 - adds r1, r2 - ldrh r1, [r1] - bl VarSet - ldr r1, =gScriptResult - movs r0, 0x1 - b _0818DA24 - .pool -_0818DA20: - ldr r1, =gScriptResult - movs r0, 0 -_0818DA24: - strh r0, [r1] - pop {r4,r5} - pop {r0} - bx r0 - .pool - thumb_func_end sub_818D9C0 - - thumb_func_start SetLilycoveLady -SetLilycoveLady: @ 818DA30 - push {lr} - ldr r0, =gSaveBlock2Ptr - ldr r0, [r0] - ldrb r1, [r0, 0xB] - lsls r1, 8 - ldrb r0, [r0, 0xA] - orrs r0, r1 - movs r1, 0x6 - bl __umodsi3 - lsls r0, 16 - lsrs r0, 17 - adds r1, r0, 0 - cmp r0, 0x1 - beq _0818DA68 - cmp r0, 0x1 - bgt _0818DA5C - cmp r0, 0 - beq _0818DA62 - b _0818DA72 - .pool -_0818DA5C: - cmp r1, 0x2 - beq _0818DA6E - b _0818DA72 -_0818DA62: - bl SetLilycoveQuizLady - b _0818DA72 -_0818DA68: - bl SetLilycoveFavourLady - b _0818DA72 -_0818DA6E: - bl SetLilycoveContestLady -_0818DA72: - pop {r0} - bx r0 - thumb_func_end SetLilycoveLady thumb_func_start sub_818DA78 sub_818DA78: @ 818DA78 @@ -1927,5 +1834,5 @@ sub_818E990: @ 818E990 .pool thumb_func_end sub_818E990 - + .align 2, 0 @ Don't pad with nop. diff --git a/include/global.h b/include/global.h index e694a5974..764eff563 100644 --- a/include/global.h +++ b/include/global.h @@ -655,6 +655,39 @@ struct DaycareData #define FLAGS_COUNT 300 #define VARS_COUNT 256 +enum { + LILYCOVE_LADY_QUIZ, + LILYCOVE_LADY_FAVOUR, + LILYCOVE_LADY_CONTEST +}; + +typedef union // TODO +{ + struct + { + /*0x000*/ u8 id; + /*0x001*/ u8 language; + } quiz; + + struct + { + /*0x000*/ u8 id; + } flavor; + + struct + { + /*0x000*/ u8 id; + /*0x001*/ u8 filler_001[12]; + /*0x00d*/ u8 category; // maybe? + } contest; + + struct + { + /*0x000*/ u8 id; + /*0x001*/ u8 filler_001[535]; + } common; +} LilycoveLady; + struct SaveBlock1 { /*0x00*/ struct Coords16 pos; @@ -738,7 +771,7 @@ struct SaveBlock1 /*0x3728*/ struct RamScript ramScript; /*0x3B14*/ struct RecordMixingGift recordMixingGift; /*0x3B24*/ u8 seen2[52]; - /*0x3B58*/ u8 lilycoveLady[536]; // TODO: convert to a union + /*0x3B58*/ LilycoveLady lilycoveLady; // TODO: convert to a union /*0x3D70*/ u8 babyPhrase[24]; // TODO: convert to a struct // sizeof: 0x3D88 }; diff --git a/include/vars.h b/include/vars.h index 5da960640..7c0edeb77 100644 --- a/include/vars.h +++ b/include/vars.h @@ -12,6 +12,8 @@ #define VAR_0x4008 0x4008 #define VAR_0x4009 0x4009 #define VAR_0x400A 0x400A +#define VAR_0x4010 0x4010 +#define VAR_0x4011 0x4011 #define VAR_0x401F 0x401F #define VAR_RECYCLE_GOODS 0x4020 #define VAR_REPEL_STEP_COUNT 0x4021 diff --git a/ld_script.txt b/ld_script.txt index 8a3f3e139..cc43127e8 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -240,6 +240,7 @@ SECTIONS { asm/battle_controller_recorded_opponent.o(.text); asm/battle_controller_recorded_player.o(.text); asm/battle_dome_cards.o(.text); + src/lilycove_lady.o(.text); asm/lilycove_lady.o(.text); asm/battle_frontier_1.o(.text); asm/new_menu_helpers.o(.text); diff --git a/src/lilycove_lady.c b/src/lilycove_lady.c new file mode 100644 index 000000000..7f4c4824a --- /dev/null +++ b/src/lilycove_lady.c @@ -0,0 +1,57 @@ +// +// Created by Scott Norton on 9/19/17. +// + +#include "global.h" +#include "event_data.h" +#include "lilycove_lady.h" + +void SetLilycoveQuizLady(void); +void SetLilycoveFavourLady(void); +void SetLilycoveContestLady(void); + +extern const u16 gUnknown_0860B074[]; +extern const u16 gUnknown_0860B07E[]; + +u8 GetLilycoveLadyId(void) +{ + return gSaveBlock1Ptr->lilycoveLady.common.id; +} + +void sub_818D9C0(void) +{ + LilycoveLady *lilycoveLady; + + VarSet(VAR_0x4010, gUnknown_0860B07E[GetLilycoveLadyId()]); + if (GetLilycoveLadyId() == LILYCOVE_LADY_CONTEST) + { + lilycoveLady = &gSaveBlock1Ptr->lilycoveLady; + VarSet(VAR_0x4011, gUnknown_0860B074[lilycoveLady->contest.category]); + gScriptResult = TRUE; + } + else + { + gScriptResult = FALSE; + } +} + +void SetLilycoveLady(void) +{ + u16 id; + + id = ((gSaveBlock2Ptr->playerTrainerId[1] << 8) | gSaveBlock2Ptr->playerTrainerId[0]); + id %= 6; + id >>= 1; + switch (id) + { + case LILYCOVE_LADY_QUIZ: + SetLilycoveQuizLady(); + break; + case LILYCOVE_LADY_FAVOUR: + SetLilycoveFavourLady(); + break; + case LILYCOVE_LADY_CONTEST: + SetLilycoveContestLady(); + break; + } +}