Refactored a whole bunch more

Build: OK
This commit is contained in:
Ogre 2023-09-15 01:02:28 +02:00
parent 5f32f2a1c5
commit 9de7f45844
7 changed files with 115 additions and 102 deletions

View File

@ -6,7 +6,7 @@
#include "element.h"
typedef struct {
/* 0x00 */ char* name;
/* 0x00 */ char *name;
/* 0x04 */ u8 field_0x4;
/* 0x05 */ Element element;
/* 0x06 */ u8 field_0x6;
@ -23,8 +23,9 @@ typedef struct {
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 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__

View File

@ -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);

View File

@ -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

View File

@ -440,6 +440,7 @@ segments:
- [0x42C30, c]
- [0x42C90, asm]
- [0x43100, c, "class"]
- [0x44340, c, "ability"]
- [0x45480, c, "equipment"]
- [0x45AE0, c]
- [0x45CB0, asm]

83
src/ability.c Normal file
View File

@ -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);

View File

@ -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);

View File

@ -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) {