From 9de7f458447396e562b631570b857a03b1028434 Mon Sep 17 00:00:00 2001 From: Ogre Date: Fri, 15 Sep 2023 01:02:28 +0200 Subject: [PATCH] Refactored a whole bunch more Build: OK --- include/ability.h | 35 +++++++++--------- include/common.h | 4 --- include/include_asm.h | 8 +++++ splat.yaml | 1 + src/ability.c | 83 +++++++++++++++++++++++++++++++++++++++++++ src/class.c | 83 ++----------------------------------------- src/equipment.c | 3 +- 7 files changed, 115 insertions(+), 102 deletions(-) create mode 100644 src/ability.c diff --git a/include/ability.h b/include/ability.h index 17f3666..5ab50f1 100644 --- a/include/ability.h +++ b/include/ability.h @@ -6,25 +6,26 @@ #include "element.h" typedef struct { - /* 0x00 */ char* name; - /* 0x04 */ u8 field_0x4; - /* 0x05 */ Element element; - /* 0x06 */ u8 field_0x6; - /* 0x07 */ u8 field_0x7; - /* 0x08 */ u8 field_0x8; - /* 0x09 */ u8 field_0x9; - /* 0x0a */ u8 field_0xa; - /* 0x0b */ u8 field_0xb; - /* 0x0c */ u8 field_0xc; - /* 0x0d */ u8 field_0xd; - /* 0x0e */ u8 field_0xe; - /* 0x0f */ u8 field_0xf; + /* 0x00 */ char *name; + /* 0x04 */ u8 field_0x4; + /* 0x05 */ Element element; + /* 0x06 */ u8 field_0x6; + /* 0x07 */ u8 field_0x7; + /* 0x08 */ u8 field_0x8; + /* 0x09 */ u8 field_0x9; + /* 0x0a */ u8 field_0xa; + /* 0x0b */ u8 field_0xb; + /* 0x0c */ u8 field_0xc; + /* 0x0d */ u8 field_0xd; + /* 0x0e */ u8 field_0xe; + /* 0x0f */ u8 field_0xf; } AbilityData; // size:0x10 -extern AbilityData ABILITY_DATA[]; - -extern char* ability_get_name(u8 index); -extern Element ability_get_element(u8 index, u16 arg1, u16 arg2, s32 arg3, u16 arg4); +extern AbilityData ABILITY_DATA[]; +extern char *ability_get_name(u8 index); +extern u8 ability_get_field_0x4(u8 index); +extern Element ability_get_element(u8 index, u16 arg1, u16 arg2, s32 arg3, + u16 arg4); #endif // __ABILITY_H__ \ No newline at end of file diff --git a/include/common.h b/include/common.h index 9007721..f7a8dce 100644 --- a/include/common.h +++ b/include/common.h @@ -35,9 +35,6 @@ typedef u8 bool; #define ARRAY_LENGTH(x) ((sizeof(x)) / (sizeof(x[0]))) #include "character.h" -#include "equipment.h" -#include "ability.h" -#include "class.h" typedef struct { /* 0x00 */ s32 field_0x0; @@ -475,7 +472,6 @@ extern void *__virtual_mem_alloc(u32); extern void *__MusIntMemMalloc(s32 size); extern ALHeap D_800B1A70; - extern void __character_initialise(CharacterSlot *arg0, u8 level); extern u16 character_get_item(CharacterSlot* character, u8 slot); extern void __character_handle_levelup(CharacterSlot *slot); diff --git a/include/include_asm.h b/include/include_asm.h index b814ea5..9f438aa 100644 --- a/include/include_asm.h +++ b/include/include_asm.h @@ -23,6 +23,14 @@ #define INCLUDE_ASM(TYPE, FOLDER, NAME, ARGS...) INCLUDE_ASM_INTERNAL(TYPE, "nonmatchings", FOLDER, NAME, ARGS) #define INCLUDE_ASM_SHIFT(TYPE, FOLDER, NAME, ARGS...) INCLUDE_ASM_INTERNAL(TYPE, "shiftable", FOLDER, NAME, ARGS) + +#define INCLUDE_RODATA(FOLDER, NAME) \ + __asm__( \ + ".section .rodata\n" \ + "\t.include \""FOLDER"/"#NAME".s\"\n" \ + ".section .text" \ + ) + #endif __asm__(".include \"include/macro.inc\"\n"); #else diff --git a/splat.yaml b/splat.yaml index 5d2efc6..1a40f6d 100644 --- a/splat.yaml +++ b/splat.yaml @@ -440,6 +440,7 @@ segments: - [0x42C30, c] - [0x42C90, asm] - [0x43100, c, "class"] + - [0x44340, c, "ability"] - [0x45480, c, "equipment"] - [0x45AE0, c] - [0x45CB0, asm] diff --git a/src/ability.c b/src/ability.c new file mode 100644 index 0000000..92cef18 --- /dev/null +++ b/src/ability.c @@ -0,0 +1,83 @@ +#include "ability.h" + +#include "common.h" +#include "equipment.h" +#include "class.h" + +/* 44340 8016E440 */ +char* ability_get_name(u8 index) { + return ABILITY_DATA[index].name; +} + +/* 44358 8016E458 */ +u8 ability_get_field_0x4(u8 index) { + return ABILITY_DATA[index].field_0x4; +} + +/* 44370 8016E470 */ +Element ability_get_element(u8 index, u16 arg1, u16 arg2, s32 arg3, u16 arg4) { + u16 item_index; + + if (ABILITY_DATA[index].element != ELEMENT_INVALID && ABILITY_DATA[index].element != 0xF) + return ABILITY_DATA[index].element; + + if (ABILITY_DATA[index].field_0x4 == 3) { + item_index = equipment_get_first_spellbook(arg1, arg2, arg3, arg4); + } else { + item_index = equipment_get_first_weapon(arg1, arg2, arg3, arg4); + } + + if (item_index == 0) + return ELEMENT_PHYSICAL; + + return equipment_get_element(item_index); +} + + +INCLUDE_ASM(const s32, "ability", func_8016E50C); + +INCLUDE_ASM(const s32, "ability", func_8016EA34); + +/* 449EC 8016EAEC */ +u16 character_get_item(CharacterSlot* character, u8 slot) { + u16 item_id; + + item_id = 0; + switch(slot) { + case 0: + item_id = character->item_upper_left; + break; + + case 1: + item_id = character->item_upper_right; + break; + + case 2: + item_id = character->item_lower_left; + break; + + case 3: + item_id = character->item_lower_right; + break; + } + + if (item_id == 0) { + item_id = FP_CLASS_GET_ITEM[slot](character->portrait, character->class); + } + return item_id; +} + + +INCLUDE_ASM(const s32, "ability", __character_handle_levelup); + +INCLUDE_ASM(const s32, "ability", __character_initialise); + +INCLUDE_ASM(const s32, "ability", func_8016F4E0); + +INCLUDE_ASM(const s32, "ability", func_8016F500); + +INCLUDE_ASM(const s32, "ability", func_8016F520); + +INCLUDE_ASM(const s32, "ability", func_8016F540); + +INCLUDE_ASM(const s32, "ability", func_8016F560); diff --git a/src/class.c b/src/class.c index 6b27bd0..e989de9 100644 --- a/src/class.c +++ b/src/class.c @@ -1,6 +1,7 @@ +#include "class.h" + #include "common.h" -#include "element.h" -#include "equipment.h" +#include "ability.h" INCLUDE_ASM(const s32, "class", func_8016D200); @@ -262,81 +263,3 @@ u8 class_get_ability_hitcount(u8 portrait, u8 class, u8 row) { return CLASS_DATA[portrait].ability_back_hitcount != 0xFF ? CLASS_DATA[portrait].ability_back_hitcount : CLASS_DATA[class].ability_back_hitcount; } } - -/* 44340 8016E440 */ -char* ability_get_name(u8 index) { - return ABILITY_DATA[index].name; -} - -/* 44358 8016E458 */ -u8 ability_get_field_0x4(u8 index) { - return ABILITY_DATA[index].field_0x4; -} - -/* 44370 8016E470 */ -Element ability_get_element(u8 index, u16 arg1, u16 arg2, s32 arg3, u16 arg4) { - u16 item_index; - - if (ABILITY_DATA[index].element != ELEMENT_INVALID && ABILITY_DATA[index].element != 0xF) - return ABILITY_DATA[index].element; - - if (ABILITY_DATA[index].field_0x4 == 3) { - item_index = equipment_get_first_spellbook(arg1, arg2, arg3, arg4); - } else { - item_index = equipment_get_first_weapon(arg1, arg2, arg3, arg4); - } - - if (item_index == 0) - return ELEMENT_PHYSICAL; - - return equipment_get_element(item_index); -} - - -INCLUDE_ASM(const s32, "class", func_8016E50C); - -INCLUDE_ASM(const s32, "class", func_8016EA34); - -/* 449EC 8016EAEC */ -u16 character_get_item(CharacterSlot* character, u8 slot) { - u16 item_id; - - item_id = 0; - switch(slot) { - case 0: - item_id = character->item_upper_left; - break; - - case 1: - item_id = character->item_upper_right; - break; - - case 2: - item_id = character->item_lower_left; - break; - - case 3: - item_id = character->item_lower_right; - break; - } - - if (item_id == 0) { - item_id = FP_CLASS_GET_ITEM[slot](character->portrait, character->class); - } - return item_id; -} - - -INCLUDE_ASM(const s32, "class", __character_handle_levelup); - -INCLUDE_ASM(const s32, "class", __character_initialise); - -INCLUDE_ASM(const s32, "class", func_8016F4E0); - -INCLUDE_ASM(const s32, "class", func_8016F500); - -INCLUDE_ASM(const s32, "class", func_8016F520); - -INCLUDE_ASM(const s32, "class", func_8016F540); - -INCLUDE_ASM(const s32, "class", func_8016F560); diff --git a/src/equipment.c b/src/equipment.c index b31d719..965bcc5 100644 --- a/src/equipment.c +++ b/src/equipment.c @@ -1,6 +1,7 @@ +#include "equipment.h" + #include "common.h" #include "element.h" -#include "equipment.h" /* 45480 8016F580 */ u8 equipment_get_field_0x1b(EquipmentId index) {