diff options
-rw-r--r-- | CMakeLists.txt | 9 | ||||
-rw-r--r-- | arm9/CMakeLists.txt | 18 | ||||
-rw-r--r-- | arm9/Makefile | 6 | ||||
-rw-r--r-- | arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s | 92 | ||||
-rw-r--r-- | arm9/modules/52/include/module_52.h | 30 | ||||
-rw-r--r-- | arm9/modules/52/src/module_52.c | 677 | ||||
-rw-r--r-- | arm9/src/main.c | 11 | ||||
-rw-r--r-- | arm9/src/math_util.c | 603 | ||||
-rw-r--r-- | arm9/src/overlay_manager.c | 4 | ||||
-rw-r--r-- | arm9/src/pokedex.c | 46 | ||||
-rw-r--r-- | arm9/src/text.c | 186 | ||||
-rw-r--r-- | arm9/src/unk_02015E30.c | 30 | ||||
-rw-r--r-- | arm9/src/unk_02021934.c | 46 | ||||
-rw-r--r-- | arm9/src/unk_0202E29C.c | 39 | ||||
-rw-r--r-- | arm9/src/unk_0202F150.c | 6 | ||||
-rw-r--r-- | arm9/src/unk_02031734.c | 4 | ||||
-rw-r--r-- | include/main.h | 8 | ||||
-rw-r--r-- | include/overlay_manager.h | 4 | ||||
-rw-r--r-- | include/unk_0202E29C.h | 7 | ||||
-rw-r--r-- | include/unk_0202F150.h | 2 | ||||
-rw-r--r-- | tools/fixrom/fixrom.c | 125 |
21 files changed, 891 insertions, 1062 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e21a731a..92d8aea2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,6 @@ -cmake_minimum_required (VERSION 2.8.11) +cmake_minimum_required (VERSION 3.15) +set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") project(PokeDiamond) set(CMAKE_CXX_STANDARD 17) set(CMAKE_C_STANDARD 11) @@ -13,10 +15,7 @@ endif(APPLE) add_compile_options(-fms-extensions) -file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c" "*.cpp") - -add_executable(PokeDiamond ${SOURCES}) -target_include_directories(PokeDiamond PRIVATE include include-mw arm9/lib/include arm7/lib/include arm9/modules/05/include arm9/modules/21/include arm9/modules/59/include arm9/modules/63/include) +add_subdirectory(arm9) add_executable(calcrom .github/calcrom/calcrom.cpp) target_include_directories(calcrom PRIVATE /usr/local/include) diff --git a/arm9/CMakeLists.txt b/arm9/CMakeLists.txt new file mode 100644 index 00000000..9170d823 --- /dev/null +++ b/arm9/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required (VERSION 3.15) +set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") +set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") +project(DP_Arm9) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 11) + +# TODO: Add commands + +enable_language(ASM) + +add_compile_options(-fms-extensions) + +file(GLOB_RECURSE SOURCES "*.c" "*.cpp") +file(GLOB MODULE_INC modules/*/include) + +add_executable(DP_Arm9 ${SOURCES}) +target_include_directories(DP_Arm9 PRIVATE ../include ../include-mw lib/include ${MODULE_INC}) diff --git a/arm9/Makefile b/arm9/Makefile index 8b84a135..6f05d1c5 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -110,7 +110,7 @@ ASM_PROCESSOR := $(ASM_PROCESSOR_DIR)/compile.sh # ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm9_thumb.s -o arm9.o ASFLAGS = -proc arm5te -i ../include -i .. -D$(GAME_VERSION) -D$(GAME_LANGUAGE) -CFLAGS = -O4,p -gccext,on -proc arm946e -fp soft -lang c99 -Cpp_exceptions off $(foreach dir,$(INCLUDE_DIRS),-i $(dir)) $(foreach dir,$(INCLUDE_RECURSIVE_DIRS),-ir $(dir)) -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) +CFLAGS = -O4,p -gccext,on -proc arm946e -ipa file -fp soft -lang c99 -Cpp_exceptions off $(foreach dir,$(INCLUDE_DIRS),-i $(dir)) $(foreach dir,$(INCLUDE_RECURSIVE_DIRS),-ir $(dir)) -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) CXXFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off $(foreach dir,$(INCLUDE_DIRS),-i $(dir)) $(foreach dir,$(INCLUDE_RECURSIVE_DIRS),-ir $(dir)) -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) LDFLAGS = -nodead -w off -proc v5te -interworking -map closure,unused -symtab sort -m _start LIBS := -Llib -lsyscall @@ -192,6 +192,10 @@ ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(LIB # TODO: Move out to lib/Makefile $(BUILD_DIR)/lib/%.o: MWCCVERSION = 1.2/sp2p3 +$(BUILD_DIR)/lib/%.o: CFLAGS = -O4,p -gccext,on -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -interworking -DFS_IMPLEMENT -enum int -W all -i ../include -ir ../include-mw -ir lib/include + +# FIXME: Using -ipa file breaks .rodata alignment +$(BUILD_DIR)/src/math_util.o: CFLAGS = -O4,p -gccext,on -proc arm946e -fp soft -lang c99 -Cpp_exceptions off $(foreach dir,$(INCLUDE_DIRS),-i $(dir)) $(foreach dir,$(INCLUDE_RECURSIVE_DIRS),-ir $(dir)) -interworking -DFS_IMPLEMENT -enum int -W all -D$(GAME_VERSION) -D$(GAME_LANGUAGE) ####################### Everything Else ###################### diff --git a/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s b/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s deleted file mode 100644 index a590ef02..00000000 --- a/arm9/asm/nonmatchings/GenerateFontHalfRowLookupTable.s +++ /dev/null @@ -1,92 +0,0 @@ -.section .text - -glabel GenerateFontHalfRowLookupTable - -.extern UNK_021C570C -.extern UNK_021C5734 - - push {r3-r7, lr} - sub sp, #0x30 - ldr r3, _0201C0F8 ; =UNK_021C570C - mov r5, #0x0 - str r5, [sp, #0x20] - str r0, [sp, #0x24] - str r2, [sp, #0x28] - str r1, [sp, #0x2c] - strh r1, [r3, #0x6] - strh r0, [r3, #0x2] - add r0, sp, #0x20 - strh r2, [r3, #0x4] - str r5, [sp, #0x14] - str r0, [sp, #0x8] - mov r12, r0 - mov lr, r0 - str r0, [sp, #0x18] -_0201C07E: - mov r0, #0x0 - str r0, [sp, #0x10] - ldr r0, [sp, #0x18] - str r0, [sp, #0x4] - ldr r0, [sp, #0x8] - ldr r0, [r0, #0x0] - str r0, [sp, #0x1c] -_0201C08C: - mov r0, #0x0 - str r0, [sp, #0xc] - mov r0, lr - str r0, [sp, #0x0] - ldr r0, [sp, #0x4] - ldr r0, [r0, #0x0] - lsl r7, r0, #0x4 -_0201C09A: - ldr r0, [sp, #0x0] - mov r3, #0x0 - ldr r0, [r0, #0x0] - mov r4, r12 - lsl r6, r0, #0x8 -_0201C0A4: - ldr r0, [r4, #0x0] - add r1, r7, #0x0 - lsl r0, r0, #0xc - orr r0, r6 - orr r1, r0 - ldr r0, [sp, #0x1c] - add r3, r3, #0x1 - add r2, r0, #0x0 - orr r2, r1 - lsl r1, r5, #0x1 - ldr r0, _0201C0FC ; =UNK_021C5734 - add r5, r5, #0x1 - add r4, r4, #0x4 - strh r2, [r0, r1] - cmp r3, #0x4 - blt _0201C0A4 - ldr r0, [sp, #0x0] - add r0, r0, #0x4 - str r0, [sp, #0x0] - ldr r0, [sp, #0xc] - add r0, r0, #0x1 - str r0, [sp, #0xc] - cmp r0, #0x4 - blt _0201C09A - ldr r0, [sp, #0x4] - add r0, r0, #0x4 - str r0, [sp, #0x4] - ldr r0, [sp, #0x10] - add r0, r0, #0x1 - str r0, [sp, #0x10] - cmp r0, #0x4 - blt _0201C08C - ldr r0, [sp, #0x8] - add r0, r0, #0x4 - str r0, [sp, #0x8] - ldr r0, [sp, #0x14] - add r0, r0, #0x1 - str r0, [sp, #0x14] - cmp r0, #0x4 - blt _0201C07E - add sp, #0x30 - pop {r3-r7, pc} - .balign 4 -_0201C0F8: .word UNK_021C570C -_0201C0FC: .word UNK_021C5734 diff --git a/arm9/modules/52/include/module_52.h b/arm9/modules/52/include/module_52.h index 4c47a82d..0adedc62 100644 --- a/arm9/modules/52/include/module_52.h +++ b/arm9/modules/52/include/module_52.h @@ -13,30 +13,24 @@ #include "unk_02024E64.h" #include "unk_020286F8.h" -const u8 MOD52_021D76F8[]; +extern const struct Unk21DBE18 MOD52_021D76E8; +extern const struct Unk21DBE18 MOD52_021D76D8; +extern const struct Unk21DBE18 MOD52_021D76C8; -THUMB_FUNC int MOD52_021D74E0(); -THUMB_FUNC int MOD52_021D74F8(struct UnkStruct_02006234 *param0); -THUMB_FUNC int MOD52_021D750C(); +THUMB_FUNC BOOL MOD52_021D74E0(struct UnkStruct_02006234 *arg1, u32 *arg2); +THUMB_FUNC BOOL MOD52_021D74F8(struct UnkStruct_02006234 *param0, u32 *unused); +THUMB_FUNC BOOL MOD52_021D750C(struct UnkStruct_02006234 *arg1, u32 *arg2); -THUMB_FUNC int MOD52_021D7528(); -THUMB_FUNC int MOD52_021D7540(struct UnkStruct_02006234 *param0); -THUMB_FUNC int MOD52_021D7560(); +THUMB_FUNC BOOL MOD52_021D7528(struct UnkStruct_02006234 *arg1, u32 *arg2); +THUMB_FUNC BOOL MOD52_021D7540(struct UnkStruct_02006234 *param0, u32 *unused); +THUMB_FUNC BOOL MOD52_021D7560(struct UnkStruct_02006234 *arg1, u32 *arg2); -THUMB_FUNC int MOD52_021D757C(); -THUMB_FUNC int MOD52_021D7594(struct UnkStruct_02006234 *param0); -THUMB_FUNC int MOD52_021D75E8(); +THUMB_FUNC BOOL MOD52_021D757C(struct UnkStruct_02006234 *arg1, u32 *arg2); +THUMB_FUNC BOOL MOD52_021D7594(struct UnkStruct_02006234 *param0, u32 *unused); +THUMB_FUNC BOOL MOD52_021D75E8(struct UnkStruct_02006234 *arg1, u32 *arg2); THUMB_FUNC void MOD52_021D7604(u32 heap_id, struct SaveBlock2 *sav2, BOOL set_trainerid); THUMB_FUNC void MOD52_021D7688(u32 param0, struct SaveBlock2 *sav2); THUMB_FUNC void MOD52_021D769C(u32 param0, struct SaveBlock2 *sav2); -struct MOD52_Struct -{ - int (*func1)(void); - int (*func2)(struct UnkStruct_02006234 *param0); - int (*func3)(void); - u32 terminator; -}; - #endif // POKEDIAMOND_MODULE_52_H
\ No newline at end of file diff --git a/arm9/modules/52/src/module_52.c b/arm9/modules/52/src/module_52.c index 1f74c77f..41f2706a 100644 --- a/arm9/modules/52/src/module_52.c +++ b/arm9/modules/52/src/module_52.c @@ -1,28 +1,173 @@ #include "module_52.h" #include "heap.h" #include "unk_0205FA2C.h" +#include "unk_02015E30.h" extern struct Unk21DBE18 UNK_020FD144; extern struct Unk21DBE18 UNK_020F2B7C; extern struct Unk21DBE18 UNK_020F2B8C; -extern void FUN_02015E3C(struct IGT *igt); extern int FUN_02053678(u32 random, u32 gender, u32 param2); -extern void FUN_020250C4(void *sav_ptr, u32 heap_id, const u8 param2[], u32 param3); +extern void FUN_020250C4(void *sav_ptr, u32 heap_id, const u16 param2[], u32 param3); extern void FUN_020377E0(struct SaveBlock2 *sav2); extern void FUN_0205ECD4(struct ScriptState *script_state); -THUMB_FUNC int MOD52_021D74E0() +const struct Unk21DBE18 MOD52_021D76E8 = { + MOD52_021D74E0, + MOD52_021D74F8, + MOD52_021D750C, + 0xFFFFFFFF, +}; + +const struct Unk21DBE18 MOD52_021D76D8 = { + MOD52_021D7528, + MOD52_021D7540, + MOD52_021D7560, + 0xFFFFFFFF, +}; + +const struct Unk21DBE18 MOD52_021D76C8 = { + MOD52_021D757C, + MOD52_021D7594, + MOD52_021D75E8, + 0xFFFFFFFF, +}; + +const u16 MOD52_021D76F8[] = { + ITEM_ORAN_BERRY, 1, + ITEM_CHERI_BERRY, 1, + ITEM_CHESTO_BERRY, 1, + ITEM_PECHA_BERRY, 1, + ITEM_ORAN_BERRY, 1, + ITEM_PECHA_BERRY, 1, + ITEM_RAZZ_BERRY, 2, + ITEM_BLUK_BERRY, 2, + ITEM_CHERI_BERRY, 1, + ITEM_ORAN_BERRY, 2, + ITEM_SITRUS_BERRY, 1, + ITEM_WEPEAR_BERRY, 2, + ITEM_WEPEAR_BERRY, 2, + ITEM_KELPSY_BERRY, 1, + ITEM_CHERI_BERRY, 1, + ITEM_PECHA_BERRY, 1, + ITEM_ORAN_BERRY, 1, + ITEM_ORAN_BERRY, 1, + ITEM_RAWST_BERRY, 1, + ITEM_RAWST_BERRY, 1, + ITEM_RAZZ_BERRY, 1, + ITEM_RAZZ_BERRY, 1, + ITEM_CHERI_BERRY, 1, + ITEM_ORAN_BERRY, 1, + ITEM_ORAN_BERRY, 1, + ITEM_BLUK_BERRY, 1, + ITEM_NANAB_BERRY, 2, + ITEM_RAZZ_BERRY, 2, + ITEM_BLUK_BERRY, 2, + ITEM_PINAP_BERRY, 2, + ITEM_LEPPA_BERRY, 1, + ITEM_CHESTO_BERRY, 1, + ITEM_RAZZ_BERRY, 1, + ITEM_RAZZ_BERRY, 1, + ITEM_PERSIM_BERRY, 1, + ITEM_NANAB_BERRY, 1, + ITEM_NANAB_BERRY, 1, + ITEM_FIGY_BERRY, 1, + ITEM_ASPEAR_BERRY, 1, + ITEM_ASPEAR_BERRY, 1, + ITEM_RAZZ_BERRY, 1, + ITEM_PINAP_BERRY, 1, + ITEM_SITRUS_BERRY, 1, + ITEM_CHESTO_BERRY, 1, + ITEM_WIKI_BERRY, 1, + ITEM_AGUAV_BERRY, 1, + ITEM_PECHA_BERRY, 1, + ITEM_ASPEAR_BERRY, 1, + ITEM_IAPAPA_BERRY, 1, + ITEM_GREPA_BERRY, 1, + ITEM_SITRUS_BERRY, 1, + ITEM_ASPEAR_BERRY, 1, + ITEM_TAMATO_BERRY, 1, + ITEM_LUM_BERRY, 1, + ITEM_PECHA_BERRY, 1, + ITEM_PINAP_BERRY, 1, + ITEM_PINAP_BERRY, 1, + ITEM_PINAP_BERRY, 1, + ITEM_PERSIM_BERRY, 1, + ITEM_PERSIM_BERRY, 1, + ITEM_NANAB_BERRY, 1, + ITEM_NANAB_BERRY, 1, + ITEM_AGUAV_BERRY, 1, + ITEM_IAPAPA_BERRY, 1, + ITEM_RAWST_BERRY, 1, + ITEM_RAWST_BERRY, 1, + ITEM_CHERI_BERRY, 1, + ITEM_SITRUS_BERRY, 1, + ITEM_CHESTO_BERRY, 1, + ITEM_POMEG_BERRY, 1, + ITEM_PECHA_BERRY, 2, + ITEM_BLUK_BERRY, 2, + ITEM_WIKI_BERRY, 1, + ITEM_MAGO_BERRY, 1, + ITEM_RAWST_BERRY, 1, + ITEM_PERSIM_BERRY, 1, + ITEM_FIGY_BERRY, 1, + ITEM_PINAP_BERRY, 2, + ITEM_LEPPA_BERRY, 1, + ITEM_PECHA_BERRY, 1, + ITEM_MAGO_BERRY, 1, + ITEM_HONDEW_BERRY, 1, + ITEM_WIKI_BERRY, 2, + ITEM_MAGO_BERRY, 2, + ITEM_AGUAV_BERRY, 2, + ITEM_QUALOT_BERRY, 1, + ITEM_SITRUS_BERRY, 2, + ITEM_BLUK_BERRY, 3, + ITEM_NANAB_BERRY, 3, + ITEM_WEPEAR_BERRY, 3, + ITEM_POMEG_BERRY, 1, + ITEM_POMEG_BERRY, 1, + ITEM_HONDEW_BERRY, 2, + ITEM_HONDEW_BERRY, 2, + ITEM_KELPSY_BERRY, 1, + ITEM_KELPSY_BERRY, 1, + ITEM_TAMATO_BERRY, 1, + ITEM_TAMATO_BERRY, 1, + ITEM_QUALOT_BERRY, 1, + ITEM_QUALOT_BERRY, 1, + ITEM_POMEG_BERRY, 1, + ITEM_POMEG_BERRY, 1, + ITEM_HONDEW_BERRY, 1, + ITEM_HONDEW_BERRY, 1, + ITEM_TAMATO_BERRY, 1, + ITEM_TAMATO_BERRY, 1, + ITEM_GREPA_BERRY, 1, + ITEM_GREPA_BERRY, 1, + ITEM_QUALOT_BERRY, 1, + ITEM_QUALOT_BERRY, 1, + ITEM_LUM_BERRY, 1, + ITEM_LEPPA_BERRY, 1, + ITEM_QUALOT_BERRY, 2, + ITEM_GREPA_BERRY, 2, + ITEM_KELPSY_BERRY, 2, + ITEM_KELPSY_BERRY, 2, + ITEM_GREPA_BERRY, 1, + ITEM_GREPA_BERRY, 1, +}; + +THUMB_FUNC BOOL MOD52_021D74E0(struct UnkStruct_02006234 *arg1, u32 *arg2) { +#pragma unused(arg1) +#pragma unused(arg2) FUN_0201681C(3, 0x4d, 2 << 16); InitializeMainRNG(); return 1; } -THUMB_FUNC int MOD52_021D74F8(struct UnkStruct_02006234 *param0) +THUMB_FUNC BOOL MOD52_021D74F8(struct UnkStruct_02006234 *param0, u32 *unused) { +#pragma unused(unused) struct SaveBlock2 *sav2 = (struct SaveBlock2 *)OverlayManager_GetField18(param0)[2]; // weird MOD52_021D769C(0x4d, sav2); @@ -30,24 +175,29 @@ THUMB_FUNC int MOD52_021D74F8(struct UnkStruct_02006234 *param0) return 1; } -THUMB_FUNC int MOD52_021D750C() +THUMB_FUNC BOOL MOD52_021D750C(struct UnkStruct_02006234 *arg1, u32 *arg2) { +#pragma unused(arg1) +#pragma unused(arg2) FUN_020168D0(0x4d); RegisterMainOverlay(0XFFFFFFFF, &UNK_020FD144); return 1; } -THUMB_FUNC int MOD52_021D7528() +THUMB_FUNC BOOL MOD52_021D7528(struct UnkStruct_02006234 *arg1, u32 *arg2) { +#pragma unused(arg1) +#pragma unused(arg2) FUN_0201681C(3, 0x4d, 2 << 16); InitializeMainRNG(); return 1; } -THUMB_FUNC int MOD52_021D7540(struct UnkStruct_02006234 *param0) +THUMB_FUNC BOOL MOD52_021D7540(struct UnkStruct_02006234 *param0, u32 *unused) { +#pragma unused(unused) struct SaveBlock2 *sav2 = (struct SaveBlock2 *)OverlayManager_GetField18(param0)[2]; // weird MOD52_021D7604(0x4d, sav2, 1); @@ -57,24 +207,29 @@ THUMB_FUNC int MOD52_021D7540(struct UnkStruct_02006234 *param0) return 1; } -THUMB_FUNC int MOD52_021D7560() +THUMB_FUNC BOOL MOD52_021D7560(struct UnkStruct_02006234 *arg1, u32 *arg2) { +#pragma unused(arg1) +#pragma unused(arg2) FUN_020168D0(0x4d); RegisterMainOverlay(0xFFFFFFFF, &UNK_020F2B7C); return 1; } -THUMB_FUNC int MOD52_021D757C() +THUMB_FUNC BOOL MOD52_021D757C(struct UnkStruct_02006234 *arg1, u32 *arg2) { +#pragma unused(arg1) +#pragma unused(arg2) FUN_0201681C(3, 0x4d, 2 << 16); InitializeMainRNG(); return 1; } -THUMB_FUNC int MOD52_021D7594(struct UnkStruct_02006234 *param0) +THUMB_FUNC BOOL MOD52_021D7594(struct UnkStruct_02006234 *param0, u32 *unused) { +#pragma unused(unused) struct SaveBlock2 *sav2 = (struct SaveBlock2 *)OverlayManager_GetField18(param0)[2]; // weird struct SavSysInfo *sav2_info = Sav2_SysInfo_get(sav2); @@ -93,8 +248,10 @@ THUMB_FUNC int MOD52_021D7594(struct UnkStruct_02006234 *param0) return 1; } -THUMB_FUNC int MOD52_021D75E8() +THUMB_FUNC BOOL MOD52_021D75E8(struct UnkStruct_02006234 *arg1, u32 *arg2) { +#pragma unused(arg1) +#pragma unused(arg2) FUN_020168D0(0x4d); RegisterMainOverlay(0XFFFFFFFF, &UNK_020F2B8C); @@ -124,7 +281,7 @@ THUMB_FUNC void MOD52_021D7604(u32 heap_id, struct SaveBlock2 *sav2, BOOL set_tr PlayerProfile_SetAvatar(player_data, (u8)avatar); - FUN_020250C4(FUN_02024ECC(sav2), heap_id, MOD52_021D76F8, 0x76); + FUN_020250C4(FUN_02024ECC(sav2), heap_id, MOD52_021D76F8, NELEMS(MOD52_021D76F8) / 2); } THUMB_FUNC void MOD52_021D7688(u32 unused, struct SaveBlock2 *sav2) @@ -149,499 +306,3 @@ THUMB_FUNC void MOD52_021D769C(u32 unused, struct SaveBlock2 *sav2) PlayerProfile_SetMoney(player_data, 3000); FUN_0205ECD4(SavArray_Flags_get(sav2)); } - -const struct MOD52_Struct MOD52_021D76C8 = { - MOD52_021D757C, - MOD52_021D7594, - MOD52_021D75E8, - 0xFFFFFFFF, -}; - -const struct MOD52_Struct MOD52_021D76D8 = { - MOD52_021D7528, - MOD52_021D7540, - MOD52_021D7560, - 0xFFFFFFFF, -}; - -const struct MOD52_Struct MOD52_021D76E8 = { - MOD52_021D74E0, - MOD52_021D74F8, - MOD52_021D750C, - 0xFFFFFFFF, -}; - -const u8 MOD52_021D76F8[] = { - 0x9B, - 0x00, - 0x01, - 0x00, - 0x95, - 0x00, - 0x01, - 0x00, - 0x96, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x01, - 0x00, - 0x9B, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x01, - 0x00, - 0xA4, - 0x00, - 0x02, - 0x00, - 0xA5, - 0x00, - 0x02, - 0x00, - 0x95, - 0x00, - 0x01, - 0x00, - 0x9B, - 0x00, - 0x02, - 0x00, - 0x9E, - 0x00, - 0x01, - 0x00, - 0xA7, - 0x00, - 0x02, - 0x00, - 0xA7, - 0x00, - 0x02, - 0x00, - 0xAA, - 0x00, - 0x01, - 0x00, - 0x95, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x01, - 0x00, - 0x9B, - 0x00, - 0x01, - 0x00, - 0x9B, - 0x00, - 0x01, - 0x00, - 0x98, - 0x00, - 0x01, - 0x00, - 0x98, - 0x00, - 0x01, - 0x00, - 0xA4, - 0x00, - 0x01, - 0x00, - 0xA4, - 0x00, - 0x01, - 0x00, - 0x95, - 0x00, - 0x01, - 0x00, - 0x9B, - 0x00, - 0x01, - 0x00, - 0x9B, - 0x00, - 0x01, - 0x00, - 0xA5, - 0x00, - 0x01, - 0x00, - 0xA6, - 0x00, - 0x02, - 0x00, - 0xA4, - 0x00, - 0x02, - 0x00, - 0xA5, - 0x00, - 0x02, - 0x00, - 0xA8, - 0x00, - 0x02, - 0x00, - 0x9A, - 0x00, - 0x01, - 0x00, - 0x96, - 0x00, - 0x01, - 0x00, - 0xA4, - 0x00, - 0x01, - 0x00, - 0xA4, - 0x00, - 0x01, - 0x00, - 0x9C, - 0x00, - 0x01, - 0x00, - 0xA6, - 0x00, - 0x01, - 0x00, - 0xA6, - 0x00, - 0x01, - 0x00, - 0x9F, - 0x00, - 0x01, - 0x00, - 0x99, - 0x00, - 0x01, - 0x00, - 0x99, - 0x00, - 0x01, - 0x00, - 0xA4, - 0x00, - 0x01, - 0x00, - 0xA8, - 0x00, - 0x01, - 0x00, - 0x9E, - 0x00, - 0x01, - 0x00, - 0x96, - 0x00, - 0x01, - 0x00, - 0xA0, - 0x00, - 0x01, - 0x00, - 0xA2, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x01, - 0x00, - 0x99, - 0x00, - 0x01, - 0x00, - 0xA3, - 0x00, - 0x01, - 0x00, - 0xAD, - 0x00, - 0x01, - 0x00, - 0x9E, - 0x00, - 0x01, - 0x00, - 0x99, - 0x00, - 0x01, - 0x00, - 0xAE, - 0x00, - 0x01, - 0x00, - 0x9D, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x01, - 0x00, - 0xA8, - 0x00, - 0x01, - 0x00, - 0xA8, - 0x00, - 0x01, - 0x00, - 0xA8, - 0x00, - 0x01, - 0x00, - 0x9C, - 0x00, - 0x01, - 0x00, - 0x9C, - 0x00, - 0x01, - 0x00, - 0xA6, - 0x00, - 0x01, - 0x00, - 0xA6, - 0x00, - 0x01, - 0x00, - 0xA2, - 0x00, - 0x01, - 0x00, - 0xA3, - 0x00, - 0x01, - 0x00, - 0x98, - 0x00, - 0x01, - 0x00, - 0x98, - 0x00, - 0x01, - 0x00, - 0x95, - 0x00, - 0x01, - 0x00, - 0x9E, - 0x00, - 0x01, - 0x00, - 0x96, - 0x00, - 0x01, - 0x00, - 0xA9, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x02, - 0x00, - 0xA5, - 0x00, - 0x02, - 0x00, - 0xA0, - 0x00, - 0x01, - 0x00, - 0xA1, - 0x00, - 0x01, - 0x00, - 0x98, - 0x00, - 0x01, - 0x00, - 0x9C, - 0x00, - 0x01, - 0x00, - 0x9F, - 0x00, - 0x01, - 0x00, - 0xA8, - 0x00, - 0x02, - 0x00, - 0x9A, - 0x00, - 0x01, - 0x00, - 0x97, - 0x00, - 0x01, - 0x00, - 0xA1, - 0x00, - 0x01, - 0x00, - 0xAC, - 0x00, - 0x01, - 0x00, - 0xA0, - 0x00, - 0x02, - 0x00, - 0xA1, - 0x00, - 0x02, - 0x00, - 0xA2, - 0x00, - 0x02, - 0x00, - 0xAB, - 0x00, - 0x01, - 0x00, - 0x9E, - 0x00, - 0x02, - 0x00, - 0xA5, - 0x00, - 0x03, - 0x00, - 0xA6, - 0x00, - 0x03, - 0x00, - 0xA7, - 0x00, - 0x03, - 0x00, - 0xA9, - 0x00, - 0x01, - 0x00, - 0xA9, - 0x00, - 0x01, - 0x00, - 0xAC, - 0x00, - 0x02, - 0x00, - 0xAC, - 0x00, - 0x02, - 0x00, - 0xAA, - 0x00, - 0x01, - 0x00, - 0xAA, - 0x00, - 0x01, - 0x00, - 0xAE, - 0x00, - 0x01, - 0x00, - 0xAE, - 0x00, - 0x01, - 0x00, - 0xAB, - 0x00, - 0x01, - 0x00, - 0xAB, - 0x00, - 0x01, - 0x00, - 0xA9, - 0x00, - 0x01, - 0x00, - 0xA9, - 0x00, - 0x01, - 0x00, - 0xAC, - 0x00, - 0x01, - 0x00, - 0xAC, - 0x00, - 0x01, - 0x00, - 0xAE, - 0x00, - 0x01, - 0x00, - 0xAE, - 0x00, - 0x01, - 0x00, - 0xAD, - 0x00, - 0x01, - 0x00, - 0xAD, - 0x00, - 0x01, - 0x00, - 0xAB, - 0x00, - 0x01, - 0x00, - 0xAB, - 0x00, - 0x01, - 0x00, - 0x9D, - 0x00, - 0x01, - 0x00, - 0x9A, - 0x00, - 0x01, - 0x00, - 0xAB, - 0x00, - 0x02, - 0x00, - 0xAD, - 0x00, - 0x02, - 0x00, - 0xAA, - 0x00, - 0x02, - 0x00, - 0xAA, - 0x00, - 0x02, - 0x00, - 0xAD, - 0x00, - 0x01, - 0x00, - 0xAD, - 0x00, - 0x01, - 0x00, -};
\ No newline at end of file diff --git a/arm9/src/main.c b/arm9/src/main.c index f7bcf7f0..117535b2 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -14,7 +14,7 @@ #include "timer3.h" #include "unk_02031734.h" #include "unk_0202F150.h" - +#include "module_52.h" FS_EXTERN_OVERLAY(MODULE_52); @@ -24,10 +24,6 @@ FS_EXTERN_OVERLAY(MODULE_63); struct Unk2106FA0 gBacklightTop; -extern BOOL OverlayManager_new(struct Unk21DBE18 *, s32 *, int); -extern BOOL OverlayManager_Run(int); -extern void OverlayManager_delete(int); - extern void InitSystemForTheGame(void); extern void InitGraphicMemory(void); extern void FUN_02022294(void); @@ -50,12 +46,11 @@ extern void FUN_0200A318(void); extern void FUN_0200E2D8(void); extern struct Unk21DBE18 MOD63_021DBE18; -extern struct Unk21DBE18 MOD52_021D76C8; extern u8 SDK_STATIC_BSS_START[]; -const int gGameVersion = GAME_VERSION; const int gGameLanguage = GAME_LANGUAGE; +const int gGameVersion = GAME_VERSION; THUMB_FUNC void NitroMain(void) { @@ -174,7 +169,7 @@ THUMB_FUNC void Main_RunOverlayManager(void) } } -THUMB_FUNC void RegisterMainOverlay(FSOverlayID id, struct Unk21DBE18 * arg1) +THUMB_FUNC void RegisterMainOverlay(FSOverlayID id, const struct Unk21DBE18 * arg1) { if (gBacklightTop.unk14 != NULL) ErrorHandling(); diff --git a/arm9/src/math_util.c b/arm9/src/math_util.c index 5aeb4f8e..4ecee59c 100644 --- a/arm9/src/math_util.c +++ b/arm9/src/math_util.c @@ -6,124 +6,461 @@ extern const s16 UNK_020FFA38[]; // temporary until further notice /* * Constant tables */ -const s32 gSineTable[] = +const fx32 gSineTable[] = { - 0x00000000, 0x00000047, 0x0000008F, 0x000000D6, - 0x0000011E, 0x00000165, 0x000001AC, 0x000001F3, - 0x0000023A, 0x00000281, 0x000002C7, 0x0000030E, - 0x00000354, 0x00000399, 0x000003DF, 0x00000424, - 0x00000469, 0x000004AE, 0x000004F2, 0x00000536, - 0x00000579, 0x000005BC, 0x000005FE, 0x00000640, - 0x00000682, 0x000006C3, 0x00000704, 0x00000744, - 0x00000783, 0x000007C2, 0x00000800, 0x0000083E, - 0x0000087B, 0x000008B7, 0x000008F2, 0x0000092D, - 0x00000968, 0x000009A1, 0x000009DA, 0x00000A12, - 0x00000A49, 0x00000A7F, 0x00000AB5, 0x00000AE9, - 0x00000B1D, 0x00000B50, 0x00000B82, 0x00000BB4, - 0x00000BE4, 0x00000C13, 0x00000C42, 0x00000C6F, - 0x00000C9C, 0x00000CC7, 0x00000CF2, 0x00000D1B, - 0x00000D44, 0x00000D6B, 0x00000D92, 0x00000DB7, - 0x00000DDB, 0x00000DFE, 0x00000E21, 0x00000E42, - 0x00000E61, 0x00000E80, 0x00000E9E, 0x00000EBA, - 0x00000ED6, 0x00000EF0, 0x00000F09, 0x00000F21, - 0x00000F38, 0x00000F4D, 0x00000F61, 0x00000F74, - 0x00000F86, 0x00000F97, 0x00000FA6, 0x00000FB5, - 0x00000FC2, 0x00000FCE, 0x00000FD8, 0x00000FE1, - 0x00000FEA, 0x00000FF0, 0x00000FF6, 0x00000FFA, - 0x00000FFE, 0x00000FFF, 0x00001000, 0x00000FFF, - 0x00000FFE, 0x00000FFA, 0x00000FF6, 0x00000FF0, - 0x00000FEA, 0x00000FE1, 0x00000FD8, 0x00000FCE, - 0x00000FC2, 0x00000FB5, 0x00000FA6, 0x00000F97, - 0x00000F86, 0x00000F74, 0x00000F61, 0x00000F4D, - 0x00000F38, 0x00000F21, 0x00000F09, 0x00000EF0, - 0x00000ED6, 0x00000EBA, 0x00000E9E, 0x00000E80, - 0x00000E61, 0x00000E42, 0x00000E21, 0x00000DFE, - 0x00000DDB, 0x00000DB7, 0x00000D92, 0x00000D6B, - 0x00000D44, 0x00000D1B, 0x00000CF2, 0x00000CC7, - 0x00000C9C, 0x00000C6F, 0x00000C42, 0x00000C13, - 0x00000BE4, 0x00000BB4, 0x00000B82, 0x00000B50, - 0x00000B1D, 0x00000AE9, 0x00000AB5, 0x00000A7F, - 0x00000A49, 0x00000A12, 0x000009DA, 0x000009A1, - 0x00000968, 0x0000092D, 0x000008F2, 0x000008B7, - 0x0000087B, 0x0000083E, 0x00000800, 0x000007C2, - 0x00000783, 0x00000744, 0x00000704, 0x000006C3, - 0x00000682, 0x00000640, 0x000005FE, 0x000005BC, - 0x00000579, 0x00000536, 0x000004F2, 0x000004AE, - 0x00000469, 0x00000424, 0x000003DF, 0x00000399, - 0x00000354, 0x0000030E, 0x000002C7, 0x00000281, - 0x0000023A, 0x000001F3, 0x000001AC, 0x00000165, - 0x0000011E, 0x000000D6, 0x0000008F, 0x00000047, - 0x00000000, 0xFFFFFFB9, 0xFFFFFF71, 0xFFFFFF2A, - 0xFFFFFEE2, 0xFFFFFE9B, 0xFFFFFE54, 0xFFFFFE0D, - 0xFFFFFDC6, 0xFFFFFD7F, 0xFFFFFD39, 0xFFFFFCF2, - 0xFFFFFCAC, 0xFFFFFC67, 0xFFFFFC21, 0xFFFFFBDC, - 0xFFFFFB97, 0xFFFFFB52, 0xFFFFFB0E, 0xFFFFFACA, - 0xFFFFFA87, 0xFFFFFA44, 0xFFFFFA02, 0xFFFFF9C0, - 0xFFFFF97E, 0xFFFFF93D, 0xFFFFF8FC, 0xFFFFF8BC, - 0xFFFFF87D, 0xFFFFF83E, 0xFFFFF800, 0xFFFFF7C2, - 0xFFFFF785, 0xFFFFF749, 0xFFFFF70E, 0xFFFFF6D3, - 0xFFFFF698, 0xFFFFF65F, 0xFFFFF626, 0xFFFFF5EE, - 0xFFFFF5B7, 0xFFFFF581, 0xFFFFF54B, 0xFFFFF517, - 0xFFFFF4E3, 0xFFFFF4B0, 0xFFFFF47E, 0xFFFFF44C, - 0xFFFFF41C, 0xFFFFF3ED, 0xFFFFF3BE, 0xFFFFF391, - 0xFFFFF364, 0xFFFFF339, 0xFFFFF30E, 0xFFFFF2E5, - 0xFFFFF2BC, 0xFFFFF295, 0xFFFFF26E, 0xFFFFF249, - 0xFFFFF225, 0xFFFFF202, 0xFFFFF1DF, 0xFFFFF1BE, - 0xFFFFF19F, 0xFFFFF180, 0xFFFFF162, 0xFFFFF146, - 0xFFFFF12A, 0xFFFFF110, 0xFFFFF0F7, 0xFFFFF0DF, - 0xFFFFF0C8, 0xFFFFF0B3, 0xFFFFF09F, 0xFFFFF08C, - 0xFFFFF07A, 0xFFFFF069, 0xFFFFF05A, 0xFFFFF04B, - 0xFFFFF03E, 0xFFFFF032, 0xFFFFF028, 0xFFFFF01F, - 0xFFFFF016, 0xFFFFF010, 0xFFFFF00A, 0xFFFFF006, - 0xFFFFF002, 0xFFFFF001, 0xFFFFF000, 0xFFFFF001, - 0xFFFFF002, 0xFFFFF006, 0xFFFFF00A, 0xFFFFF010, - 0xFFFFF016, 0xFFFFF01F, 0xFFFFF028, 0xFFFFF032, - 0xFFFFF03E, 0xFFFFF04B, 0xFFFFF05A, 0xFFFFF069, - 0xFFFFF07A, 0xFFFFF08C, 0xFFFFF09F, 0xFFFFF0B3, - 0xFFFFF0C8, 0xFFFFF0DF, 0xFFFFF0F7, 0xFFFFF110, - 0xFFFFF12A, 0xFFFFF146, 0xFFFFF162, 0xFFFFF180, - 0xFFFFF19F, 0xFFFFF1BE, 0xFFFFF1DF, 0xFFFFF202, - 0xFFFFF225, 0xFFFFF249, 0xFFFFF26E, 0xFFFFF295, - 0xFFFFF2BC, 0xFFFFF2E5, 0xFFFFF30E, 0xFFFFF339, - 0xFFFFF364, 0xFFFFF391, 0xFFFFF3BE, 0xFFFFF3ED, - 0xFFFFF41C, 0xFFFFF44C, 0xFFFFF47E, 0xFFFFF4B0, - 0xFFFFF4E3, 0xFFFFF517, 0xFFFFF54B, 0xFFFFF581, - 0xFFFFF5B7, 0xFFFFF5EE, 0xFFFFF626, 0xFFFFF65F, - 0xFFFFF698, 0xFFFFF6D3, 0xFFFFF70E, 0xFFFFF749, - 0xFFFFF785, 0xFFFFF7C2, 0xFFFFF800, 0xFFFFF83E, - 0xFFFFF87D, 0xFFFFF8BC, 0xFFFFF8FC, 0xFFFFF93D, - 0xFFFFF97E, 0xFFFFF9C0, 0xFFFFFA02, 0xFFFFFA44, - 0xFFFFFA87, 0xFFFFFACA, 0xFFFFFB0E, 0xFFFFFB52, - 0xFFFFFB97, 0xFFFFFBDC, 0xFFFFFC21, 0xFFFFFC67, - 0xFFFFFCAC, 0xFFFFFCF2, 0xFFFFFD39, 0xFFFFFD7F, - 0xFFFFFDC6, 0xFFFFFE0D, 0xFFFFFE54, 0xFFFFFE9B, - 0xFFFFFEE2, 0xFFFFFF2A, 0xFFFFFF71, 0xFFFFFFB9, - 0x00000000, 0x00000047, 0x0000008F, 0x000000D6, - 0x0000011E, 0x00000165, 0x000001AC, 0x000001F3, - 0x0000023A, 0x00000281, 0x000002C7, 0x0000030E, - 0x00000354, 0x00000399, 0x000003DF, 0x00000424, - 0x00000469, 0x000004AE, 0x000004F2, 0x00000536, - 0x00000579, 0x000005BC, 0x000005FE, 0x00000640, - 0x00000682, 0x000006C3, 0x00000704, 0x00000744, - 0x00000783, 0x000007C2, 0x00000800, 0x0000083E, - 0x0000087B, 0x000008B7, 0x000008F2, 0x0000092D, - 0x00000968, 0x000009A1, 0x000009DA, 0x00000A12, - 0x00000A49, 0x00000A7F, 0x00000AB5, 0x00000AE9, - 0x00000B1D, 0x00000B50, 0x00000B82, 0x00000BB4, - 0x00000BE4, 0x00000C13, 0x00000C42, 0x00000C6F, - 0x00000C9C, 0x00000CC7, 0x00000CF2, 0x00000D1B, - 0x00000D44, 0x00000D6B, 0x00000D92, 0x00000DB7, - 0x00000DDB, 0x00000DFE, 0x00000E21, 0x00000E42, - 0x00000E61, 0x00000E80, 0x00000E9E, 0x00000EBA, - 0x00000ED6, 0x00000EF0, 0x00000F09, 0x00000F21, - 0x00000F38, 0x00000F4D, 0x00000F61, 0x00000F74, - 0x00000F86, 0x00000F97, 0x00000FA6, 0x00000FB5, - 0x00000FC2, 0x00000FCE, 0x00000FD8, 0x00000FE1, - 0x00000FEA, 0x00000FF0, 0x00000FF6, 0x00000FFA, - 0x00000FFE, 0x00000FFF + FX32_CONST(0.0), // sin(0) + FX32_CONST(0.017333984375), // sin(1) + FX32_CONST(0.034912109375), // sin(2) + FX32_CONST(0.05224609375), // sin(3) + FX32_CONST(0.06982421875), // sin(4) + FX32_CONST(0.087158203125), // sin(5) + FX32_CONST(0.1044921875), // sin(6) + FX32_CONST(0.121826171875), // sin(7) + FX32_CONST(0.13916015625), // sin(8) + FX32_CONST(0.156494140625), // sin(9) + FX32_CONST(0.173583984375), // sin(10) + FX32_CONST(0.19091796875), // sin(11) + FX32_CONST(0.2080078125), // sin(12) + FX32_CONST(0.224853515625), // sin(13) + FX32_CONST(0.241943359375), // sin(14) + FX32_CONST(0.2587890625), // sin(15) + FX32_CONST(0.275634765625), // sin(16) + FX32_CONST(0.29248046875), // sin(17) + FX32_CONST(0.30908203125), // sin(18) + FX32_CONST(0.32568359375), // sin(19) + FX32_CONST(0.342041015625), // sin(20) + FX32_CONST(0.3583984375), // sin(21) + FX32_CONST(0.37451171875), // sin(22) + FX32_CONST(0.390625), // sin(23) + FX32_CONST(0.40673828125), // sin(24) + FX32_CONST(0.422607421875), // sin(25) + FX32_CONST(0.4384765625), // sin(26) + FX32_CONST(0.4541015625), // sin(27) + FX32_CONST(0.469482421875), // sin(28) + FX32_CONST(0.48486328125), // sin(29) + FX32_CONST(0.5), // sin(30) + FX32_CONST(0.51513671875), // sin(31) + FX32_CONST(0.530029296875), // sin(32) + FX32_CONST(0.544677734375), // sin(33) + FX32_CONST(0.55908203125), // sin(34) + FX32_CONST(0.573486328125), // sin(35) + FX32_CONST(0.587890625), // sin(36) + FX32_CONST(0.601806640625), // sin(37) + FX32_CONST(0.61572265625), // sin(38) + FX32_CONST(0.62939453125), // sin(39) + FX32_CONST(0.642822265625), // sin(40) + FX32_CONST(0.656005859375), // sin(41) + FX32_CONST(0.669189453125), // sin(42) + FX32_CONST(0.681884765625), // sin(43) + FX32_CONST(0.694580078125), // sin(44) + FX32_CONST(0.70703125), // sin(45) + FX32_CONST(0.71923828125), // sin(46) + FX32_CONST(0.7314453125), // sin(47) + FX32_CONST(0.7431640625), // sin(48) + FX32_CONST(0.754638671875), // sin(49) + FX32_CONST(0.76611328125), // sin(50) + FX32_CONST(0.777099609375), // sin(51) + FX32_CONST(0.7880859375), // sin(52) + FX32_CONST(0.798583984375), // sin(53) + FX32_CONST(0.80908203125), // sin(54) + FX32_CONST(0.819091796875), // sin(55) + FX32_CONST(0.8291015625), // sin(56) + FX32_CONST(0.838623046875), // sin(57) + FX32_CONST(0.84814453125), // sin(58) + FX32_CONST(0.857177734375), // sin(59) + FX32_CONST(0.865966796875), // sin(60) + FX32_CONST(0.87451171875), // sin(61) + FX32_CONST(0.883056640625), // sin(62) + FX32_CONST(0.89111328125), // sin(63) + FX32_CONST(0.898681640625), // sin(64) + FX32_CONST(0.90625), // sin(65) + FX32_CONST(0.91357421875), // sin(66) + FX32_CONST(0.92041015625), // sin(67) + FX32_CONST(0.92724609375), // sin(68) + FX32_CONST(0.93359375), // sin(69) + FX32_CONST(0.939697265625), // sin(70) + FX32_CONST(0.945556640625), // sin(71) + FX32_CONST(0.951171875), // sin(72) + FX32_CONST(0.956298828125), // sin(73) + FX32_CONST(0.961181640625), // sin(74) + FX32_CONST(0.9658203125), // sin(75) + FX32_CONST(0.97021484375), // sin(76) + FX32_CONST(0.974365234375), // sin(77) + FX32_CONST(0.97802734375), // sin(78) + FX32_CONST(0.981689453125), // sin(79) + FX32_CONST(0.98486328125), // sin(80) + FX32_CONST(0.98779296875), // sin(81) + FX32_CONST(0.990234375), // sin(82) + FX32_CONST(0.992431640625), // sin(83) + FX32_CONST(0.99462890625), // sin(84) + FX32_CONST(0.99609375), // sin(85) + FX32_CONST(0.99755859375), // sin(86) + FX32_CONST(0.99853515625), // sin(87) + FX32_CONST(0.99951171875), // sin(88) + FX32_CONST(0.999755859375), // sin(89) + FX32_CONST(1.0), // sin(90) + FX32_CONST(0.999755859375), // sin(91) + FX32_CONST(0.99951171875), // sin(92) + FX32_CONST(0.99853515625), // sin(93) + FX32_CONST(0.99755859375), // sin(94) + FX32_CONST(0.99609375), // sin(95) + FX32_CONST(0.99462890625), // sin(96) + FX32_CONST(0.992431640625), // sin(97) + FX32_CONST(0.990234375), // sin(98) + FX32_CONST(0.98779296875), // sin(99) + FX32_CONST(0.98486328125), // sin(100) + FX32_CONST(0.981689453125), // sin(101) + FX32_CONST(0.97802734375), // sin(102) + FX32_CONST(0.974365234375), // sin(103) + FX32_CONST(0.97021484375), // sin(104) + FX32_CONST(0.9658203125), // sin(105) + FX32_CONST(0.961181640625), // sin(106) + FX32_CONST(0.956298828125), // sin(107) + FX32_CONST(0.951171875), // sin(108) + FX32_CONST(0.945556640625), // sin(109) + FX32_CONST(0.939697265625), // sin(110) + FX32_CONST(0.93359375), // sin(111) + FX32_CONST(0.92724609375), // sin(112) + FX32_CONST(0.92041015625), // sin(113) + FX32_CONST(0.91357421875), // sin(114) + FX32_CONST(0.90625), // sin(115) + FX32_CONST(0.898681640625), // sin(116) + FX32_CONST(0.89111328125), // sin(117) + FX32_CONST(0.883056640625), // sin(118) + FX32_CONST(0.87451171875), // sin(119) + FX32_CONST(0.865966796875), // sin(120) + FX32_CONST(0.857177734375), // sin(121) + FX32_CONST(0.84814453125), // sin(122) + FX32_CONST(0.838623046875), // sin(123) + FX32_CONST(0.8291015625), // sin(124) + FX32_CONST(0.819091796875), // sin(125) + FX32_CONST(0.80908203125), // sin(126) + FX32_CONST(0.798583984375), // sin(127) + FX32_CONST(0.7880859375), // sin(128) + FX32_CONST(0.777099609375), // sin(129) + FX32_CONST(0.76611328125), // sin(130) + FX32_CONST(0.754638671875), // sin(131) + FX32_CONST(0.7431640625), // sin(132) + FX32_CONST(0.7314453125), // sin(133) + FX32_CONST(0.71923828125), // sin(134) + FX32_CONST(0.70703125), // sin(135) + FX32_CONST(0.694580078125), // sin(136) + FX32_CONST(0.681884765625), // sin(137) + FX32_CONST(0.669189453125), // sin(138) + FX32_CONST(0.656005859375), // sin(139) + FX32_CONST(0.642822265625), // sin(140) + FX32_CONST(0.62939453125), // sin(141) + FX32_CONST(0.61572265625), // sin(142) + FX32_CONST(0.601806640625), // sin(143) + FX32_CONST(0.587890625), // sin(144) + FX32_CONST(0.573486328125), // sin(145) + FX32_CONST(0.55908203125), // sin(146) + FX32_CONST(0.544677734375), // sin(147) + FX32_CONST(0.530029296875), // sin(148) + FX32_CONST(0.51513671875), // sin(149) + FX32_CONST(0.5), // sin(150) + FX32_CONST(0.48486328125), // sin(151) + FX32_CONST(0.469482421875), // sin(152) + FX32_CONST(0.4541015625), // sin(153) + FX32_CONST(0.4384765625), // sin(154) + FX32_CONST(0.422607421875), // sin(155) + FX32_CONST(0.40673828125), // sin(156) + FX32_CONST(0.390625), // sin(157) + FX32_CONST(0.37451171875), // sin(158) + FX32_CONST(0.3583984375), // sin(159) + FX32_CONST(0.342041015625), // sin(160) + FX32_CONST(0.32568359375), // sin(161) + FX32_CONST(0.30908203125), // sin(162) + FX32_CONST(0.29248046875), // sin(163) + FX32_CONST(0.275634765625), // sin(164) + FX32_CONST(0.2587890625), // sin(165) + FX32_CONST(0.241943359375), // sin(166) + FX32_CONST(0.224853515625), // sin(167) + FX32_CONST(0.2080078125), // sin(168) + FX32_CONST(0.19091796875), // sin(169) + FX32_CONST(0.173583984375), // sin(170) + FX32_CONST(0.156494140625), // sin(171) + FX32_CONST(0.13916015625), // sin(172) + FX32_CONST(0.121826171875), // sin(173) + FX32_CONST(0.1044921875), // sin(174) + FX32_CONST(0.087158203125), // sin(175) + FX32_CONST(0.06982421875), // sin(176) + FX32_CONST(0.05224609375), // sin(177) + FX32_CONST(0.034912109375), // sin(178) + FX32_CONST(0.017333984375), // sin(179) + FX32_CONST(0.0), // sin(180) + FX32_CONST(-0.017333984375), // sin(181) + FX32_CONST(-0.034912109375), // sin(182) + FX32_CONST(-0.05224609375), // sin(183) + FX32_CONST(-0.06982421875), // sin(184) + FX32_CONST(-0.087158203125), // sin(185) + FX32_CONST(-0.1044921875), // sin(186) + FX32_CONST(-0.121826171875), // sin(187) + FX32_CONST(-0.13916015625), // sin(188) + FX32_CONST(-0.156494140625), // sin(189) + FX32_CONST(-0.173583984375), // sin(190) + FX32_CONST(-0.19091796875), // sin(191) + FX32_CONST(-0.2080078125), // sin(192) + FX32_CONST(-0.224853515625), // sin(193) + FX32_CONST(-0.241943359375), // sin(194) + FX32_CONST(-0.2587890625), // sin(195) + FX32_CONST(-0.275634765625), // sin(196) + FX32_CONST(-0.29248046875), // sin(197) + FX32_CONST(-0.30908203125), // sin(198) + FX32_CONST(-0.32568359375), // sin(199) + FX32_CONST(-0.342041015625), // sin(200) + FX32_CONST(-0.3583984375), // sin(201) + FX32_CONST(-0.37451171875), // sin(202) + FX32_CONST(-0.390625), // sin(203) + FX32_CONST(-0.40673828125), // sin(204) + FX32_CONST(-0.422607421875), // sin(205) + FX32_CONST(-0.4384765625), // sin(206) + FX32_CONST(-0.4541015625), // sin(207) + FX32_CONST(-0.469482421875), // sin(208) + FX32_CONST(-0.48486328125), // sin(209) + FX32_CONST(-0.5), // sin(210) + FX32_CONST(-0.51513671875), // sin(211) + FX32_CONST(-0.530029296875), // sin(212) + FX32_CONST(-0.544677734375), // sin(213) + FX32_CONST(-0.55908203125), // sin(214) + FX32_CONST(-0.573486328125), // sin(215) + FX32_CONST(-0.587890625), // sin(216) + FX32_CONST(-0.601806640625), // sin(217) + FX32_CONST(-0.61572265625), // sin(218) + FX32_CONST(-0.62939453125), // sin(219) + FX32_CONST(-0.642822265625), // sin(220) + FX32_CONST(-0.656005859375), // sin(221) + FX32_CONST(-0.669189453125), // sin(222) + FX32_CONST(-0.681884765625), // sin(223) + FX32_CONST(-0.694580078125), // sin(224) + FX32_CONST(-0.70703125), // sin(225) + FX32_CONST(-0.71923828125), // sin(226) + FX32_CONST(-0.7314453125), // sin(227) + FX32_CONST(-0.7431640625), // sin(228) + FX32_CONST(-0.754638671875), // sin(229) + FX32_CONST(-0.76611328125), // sin(230) + FX32_CONST(-0.777099609375), // sin(231) + FX32_CONST(-0.7880859375), // sin(232) + FX32_CONST(-0.798583984375), // sin(233) + FX32_CONST(-0.80908203125), // sin(234) + FX32_CONST(-0.819091796875), // sin(235) + FX32_CONST(-0.8291015625), // sin(236) + FX32_CONST(-0.838623046875), // sin(237) + FX32_CONST(-0.84814453125), // sin(238) + FX32_CONST(-0.857177734375), // sin(239) + FX32_CONST(-0.865966796875), // sin(240) + FX32_CONST(-0.87451171875), // sin(241) + FX32_CONST(-0.883056640625), // sin(242) + FX32_CONST(-0.89111328125), // sin(243) + FX32_CONST(-0.898681640625), // sin(244) + FX32_CONST(-0.90625), // sin(245) + FX32_CONST(-0.91357421875), // sin(246) + FX32_CONST(-0.92041015625), // sin(247) + FX32_CONST(-0.92724609375), // sin(248) + FX32_CONST(-0.93359375), // sin(249) + FX32_CONST(-0.939697265625), // sin(250) + FX32_CONST(-0.945556640625), // sin(251) + FX32_CONST(-0.951171875), // sin(252) + FX32_CONST(-0.956298828125), // sin(253) + FX32_CONST(-0.961181640625), // sin(254) + FX32_CONST(-0.9658203125), // sin(255) + FX32_CONST(-0.97021484375), // sin(256) + FX32_CONST(-0.974365234375), // sin(257) + FX32_CONST(-0.97802734375), // sin(258) + FX32_CONST(-0.981689453125), // sin(259) + FX32_CONST(-0.98486328125), // sin(260) + FX32_CONST(-0.98779296875), // sin(261) + FX32_CONST(-0.990234375), // sin(262) + FX32_CONST(-0.992431640625), // sin(263) + FX32_CONST(-0.99462890625), // sin(264) + FX32_CONST(-0.99609375), // sin(265) + FX32_CONST(-0.99755859375), // sin(266) + FX32_CONST(-0.99853515625), // sin(267) + FX32_CONST(-0.99951171875), // sin(268) + FX32_CONST(-0.999755859375), // sin(269) + FX32_CONST(-1.0), // sin(270) + FX32_CONST(-0.999755859375), // sin(271) + FX32_CONST(-0.99951171875), // sin(272) + FX32_CONST(-0.99853515625), // sin(273) + FX32_CONST(-0.99755859375), // sin(274) + FX32_CONST(-0.99609375), // sin(275) + FX32_CONST(-0.99462890625), // sin(276) + FX32_CONST(-0.992431640625), // sin(277) + FX32_CONST(-0.990234375), // sin(278) + FX32_CONST(-0.98779296875), // sin(279) + FX32_CONST(-0.98486328125), // sin(280) + FX32_CONST(-0.981689453125), // sin(281) + FX32_CONST(-0.97802734375), // sin(282) + FX32_CONST(-0.974365234375), // sin(283) + FX32_CONST(-0.97021484375), // sin(284) + FX32_CONST(-0.9658203125), // sin(285) + FX32_CONST(-0.961181640625), // sin(286) + FX32_CONST(-0.956298828125), // sin(287) + FX32_CONST(-0.951171875), // sin(288) + FX32_CONST(-0.945556640625), // sin(289) + FX32_CONST(-0.939697265625), // sin(290) + FX32_CONST(-0.93359375), // sin(291) + FX32_CONST(-0.92724609375), // sin(292) + FX32_CONST(-0.92041015625), // sin(293) + FX32_CONST(-0.91357421875), // sin(294) + FX32_CONST(-0.90625), // sin(295) + FX32_CONST(-0.898681640625), // sin(296) + FX32_CONST(-0.89111328125), // sin(297) + FX32_CONST(-0.883056640625), // sin(298) + FX32_CONST(-0.87451171875), // sin(299) + FX32_CONST(-0.865966796875), // sin(300) + FX32_CONST(-0.857177734375), // sin(301) + FX32_CONST(-0.84814453125), // sin(302) + FX32_CONST(-0.838623046875), // sin(303) + FX32_CONST(-0.8291015625), // sin(304) + FX32_CONST(-0.819091796875), // sin(305) + FX32_CONST(-0.80908203125), // sin(306) + FX32_CONST(-0.798583984375), // sin(307) + FX32_CONST(-0.7880859375), // sin(308) + FX32_CONST(-0.777099609375), // sin(309) + FX32_CONST(-0.76611328125), // sin(310) + FX32_CONST(-0.754638671875), // sin(311) + FX32_CONST(-0.7431640625), // sin(312) + FX32_CONST(-0.7314453125), // sin(313) + FX32_CONST(-0.71923828125), // sin(314) + FX32_CONST(-0.70703125), // sin(315) + FX32_CONST(-0.694580078125), // sin(316) + FX32_CONST(-0.681884765625), // sin(317) + FX32_CONST(-0.669189453125), // sin(318) + FX32_CONST(-0.656005859375), // sin(319) + FX32_CONST(-0.642822265625), // sin(320) + FX32_CONST(-0.62939453125), // sin(321) + FX32_CONST(-0.61572265625), // sin(322) + FX32_CONST(-0.601806640625), // sin(323) + FX32_CONST(-0.587890625), // sin(324) + FX32_CONST(-0.573486328125), // sin(325) + FX32_CONST(-0.55908203125), // sin(326) + FX32_CONST(-0.544677734375), // sin(327) + FX32_CONST(-0.530029296875), // sin(328) + FX32_CONST(-0.51513671875), // sin(329) + FX32_CONST(-0.5), // sin(330) + FX32_CONST(-0.48486328125), // sin(331) + FX32_CONST(-0.469482421875), // sin(332) + FX32_CONST(-0.4541015625), // sin(333) + FX32_CONST(-0.4384765625), // sin(334) + FX32_CONST(-0.422607421875), // sin(335) + FX32_CONST(-0.40673828125), // sin(336) + FX32_CONST(-0.390625), // sin(337) + FX32_CONST(-0.37451171875), // sin(338) + FX32_CONST(-0.3583984375), // sin(339) + FX32_CONST(-0.342041015625), // sin(340) + FX32_CONST(-0.32568359375), // sin(341) + FX32_CONST(-0.30908203125), // sin(342) + FX32_CONST(-0.29248046875), // sin(343) + FX32_CONST(-0.275634765625), // sin(344) + FX32_CONST(-0.2587890625), // sin(345) + FX32_CONST(-0.241943359375), // sin(346) + FX32_CONST(-0.224853515625), // sin(347) + FX32_CONST(-0.2080078125), // sin(348) + FX32_CONST(-0.19091796875), // sin(349) + FX32_CONST(-0.173583984375), // sin(350) + FX32_CONST(-0.156494140625), // sin(351) + FX32_CONST(-0.13916015625), // sin(352) + FX32_CONST(-0.121826171875), // sin(353) + FX32_CONST(-0.1044921875), // sin(354) + FX32_CONST(-0.087158203125), // sin(355) + FX32_CONST(-0.06982421875), // sin(356) + FX32_CONST(-0.05224609375), // sin(357) + FX32_CONST(-0.034912109375), // sin(358) + FX32_CONST(-0.017333984375), // sin(359) + FX32_CONST(0.0), // sin(360) + FX32_CONST(0.017333984375), // sin(361) + FX32_CONST(0.034912109375), // sin(362) + FX32_CONST(0.05224609375), // sin(363) + FX32_CONST(0.06982421875), // sin(364) + FX32_CONST(0.087158203125), // sin(365) + FX32_CONST(0.1044921875), // sin(366) + FX32_CONST(0.121826171875), // sin(367) + FX32_CONST(0.13916015625), // sin(368) + FX32_CONST(0.156494140625), // sin(369) + FX32_CONST(0.173583984375), // sin(370) + FX32_CONST(0.19091796875), // sin(371) + FX32_CONST(0.2080078125), // sin(372) + FX32_CONST(0.224853515625), // sin(373) + FX32_CONST(0.241943359375), // sin(374) + FX32_CONST(0.2587890625), // sin(375) + FX32_CONST(0.275634765625), // sin(376) + FX32_CONST(0.29248046875), // sin(377) + FX32_CONST(0.30908203125), // sin(378) + FX32_CONST(0.32568359375), // sin(379) + FX32_CONST(0.342041015625), // sin(380) + FX32_CONST(0.3583984375), // sin(381) + FX32_CONST(0.37451171875), // sin(382) + FX32_CONST(0.390625), // sin(383) + FX32_CONST(0.40673828125), // sin(384) + FX32_CONST(0.422607421875), // sin(385) + FX32_CONST(0.4384765625), // sin(386) + FX32_CONST(0.4541015625), // sin(387) + FX32_CONST(0.469482421875), // sin(388) + FX32_CONST(0.48486328125), // sin(389) + FX32_CONST(0.5), // sin(390) + FX32_CONST(0.51513671875), // sin(391) + FX32_CONST(0.530029296875), // sin(392) + FX32_CONST(0.544677734375), // sin(393) + FX32_CONST(0.55908203125), // sin(394) + FX32_CONST(0.573486328125), // sin(395) + FX32_CONST(0.587890625), // sin(396) + FX32_CONST(0.601806640625), // sin(397) + FX32_CONST(0.61572265625), // sin(398) + FX32_CONST(0.62939453125), // sin(399) + FX32_CONST(0.642822265625), // sin(400) + FX32_CONST(0.656005859375), // sin(401) + FX32_CONST(0.669189453125), // sin(402) + FX32_CONST(0.681884765625), // sin(403) + FX32_CONST(0.694580078125), // sin(404) + FX32_CONST(0.70703125), // sin(405) + FX32_CONST(0.71923828125), // sin(406) + FX32_CONST(0.7314453125), // sin(407) + FX32_CONST(0.7431640625), // sin(408) + FX32_CONST(0.754638671875), // sin(409) + FX32_CONST(0.76611328125), // sin(410) + FX32_CONST(0.777099609375), // sin(411) + FX32_CONST(0.7880859375), // sin(412) + FX32_CONST(0.798583984375), // sin(413) + FX32_CONST(0.80908203125), // sin(414) + FX32_CONST(0.819091796875), // sin(415) + FX32_CONST(0.8291015625), // sin(416) + FX32_CONST(0.838623046875), // sin(417) + FX32_CONST(0.84814453125), // sin(418) + FX32_CONST(0.857177734375), // sin(419) + FX32_CONST(0.865966796875), // sin(420) + FX32_CONST(0.87451171875), // sin(421) + FX32_CONST(0.883056640625), // sin(422) + FX32_CONST(0.89111328125), // sin(423) + FX32_CONST(0.898681640625), // sin(424) + FX32_CONST(0.90625), // sin(425) + FX32_CONST(0.91357421875), // sin(426) + FX32_CONST(0.92041015625), // sin(427) + FX32_CONST(0.92724609375), // sin(428) + FX32_CONST(0.93359375), // sin(429) + FX32_CONST(0.939697265625), // sin(430) + FX32_CONST(0.945556640625), // sin(431) + FX32_CONST(0.951171875), // sin(432) + FX32_CONST(0.956298828125), // sin(433) + FX32_CONST(0.961181640625), // sin(434) + FX32_CONST(0.9658203125), // sin(435) + FX32_CONST(0.97021484375), // sin(436) + FX32_CONST(0.974365234375), // sin(437) + FX32_CONST(0.97802734375), // sin(438) + FX32_CONST(0.981689453125), // sin(439) + FX32_CONST(0.98486328125), // sin(440) + FX32_CONST(0.98779296875), // sin(441) + FX32_CONST(0.990234375), // sin(442) + FX32_CONST(0.992431640625), // sin(443) + FX32_CONST(0.99462890625), // sin(444) + FX32_CONST(0.99609375), // sin(445) + FX32_CONST(0.99755859375), // sin(446) + FX32_CONST(0.99853515625), // sin(447) + FX32_CONST(0.99951171875), // sin(448) + FX32_CONST(0.999755859375), // sin(449) }; -const u16 UNK_020EDC7E[] = // rotations? +static const u16 UNK_020EDC7E[] = // rotations? { 0x0000, 0x00B7, 0x016D, 0x0223, 0x02D9, 0x038F, 0x0445, 0x04FB, 0x05B1, 0x0667, 0x071D, 0x07D3, 0x0889, 0x093F, 0x09F5, 0x0AAB, 0x0B61, 0x0C17, 0x0CCD, 0x0D83, @@ -255,31 +592,41 @@ THUMB_FUNC s32 Sin32(s32 degrees) * Random number generators */ static u32 sMTRNG_State[624]; // Mersenne Twister seed storage/buffer +#ifdef NONMATCHING +// Using -ipa file makes the following hack unnecessary, +// but for some reason forces UNK_020EDC7E to align to +// word rather than short... +static u32 sLCRNG_State; +#define sMTRNG_State_2 sMTRNG_State +#else static union { u32 LC_State; // Linear-congruential seed storage/buffer u32 MTRNG_State[]; // Don't bother asking why Game Freak did this. Just don't. } sRNGHack; +#define sLCRNG_State sRNGHack.LC_State +#define sMTRNG_State_2 (sRNGHack.MTRNG_State + 1) +#endif // Returns the Linear-congruential buffer in full. THUMB_FUNC u32 GetLCRNGSeed() { - return sRNGHack.LC_State; + return sLCRNG_State; } // Initializes the Linear-congruential buffer with a 32-bit seed. THUMB_FUNC void SetLCRNGSeed(u32 seed) { - sRNGHack.LC_State = seed; + sLCRNG_State = seed; } // Calculates an unsigned 16-bit random integer using the Linear-congruential algorithm. THUMB_FUNC u16 LCRandom(void) { // cycle the RNG - sRNGHack.LC_State *= 0x41C64E6D; - sRNGHack.LC_State += 0x6073; - return (u16)(sRNGHack.LC_State / 65536); // shut up the compiler + sLCRNG_State *= 0x41C64E6D; + sLCRNG_State += 0x6073; + return (u16)(sLCRNG_State / 65536); // shut up the compiler } // Returns a cheap, psuedo-random unsigned 32-bit random integer from a seed. @@ -294,7 +641,7 @@ static u32 sMTRNG_XOR[2] = {0, 0x9908b0df}; // Mersenne Twister XOR mask table // Initializes the Mersenne Twister buffer with a 32-bit seed. THUMB_FUNC void SetMTRNGSeed(u32 seed) { - sRNGHack.MTRNG_State[0+1] = seed; + sMTRNG_State_2[0] = seed; for (sMTRNG_Cycles = 1; sMTRNG_Cycles < 624; sMTRNG_Cycles++) sMTRNG_State[sMTRNG_Cycles] = 1812433253 * (sMTRNG_State[sMTRNG_Cycles - 1] ^ (sMTRNG_State[sMTRNG_Cycles - 1] >> 30)) + sMTRNG_Cycles; @@ -310,7 +657,7 @@ THUMB_FUNC u32 MTRandom(void) { if (sMTRNG_Cycles == 625) SetMTRNGSeed(5489); - + for (i = 0; i < 227; i++) { val = (sMTRNG_State[i] & 0x80000000) | (sMTRNG_State[i + 1] & 0x7fffffff); @@ -321,20 +668,20 @@ THUMB_FUNC u32 MTRandom(void) val = (sMTRNG_State[i] & 0x80000000) | (sMTRNG_State[i + 1] & 0x7fffffff); sMTRNG_State[i] = sMTRNG_State[i + -227] ^ (val >> 1) ^ sMTRNG_XOR[val & 0x1]; } - - val = (sRNGHack.MTRNG_State[623+1] & 0x80000000) | (sRNGHack.MTRNG_State[0+1] & 0x7fffffff); - sRNGHack.MTRNG_State[623+1] = sRNGHack.MTRNG_State[396+1] ^ (val >> 1) ^ sMTRNG_XOR[val & 0x1]; + + val = (sMTRNG_State_2[623] & 0x80000000) | (sMTRNG_State_2[0] & 0x7fffffff); + sMTRNG_State_2[623] = sMTRNG_State_2[396] ^ (val >> 1) ^ sMTRNG_XOR[val & 0x1]; sMTRNG_Cycles = 0; } - + val = sMTRNG_State[sMTRNG_Cycles++]; // has to be this way in order to match - + val ^= val >> 11; val ^= (val << 7) & 0x9d2c5680; val ^= (val << 15) & 0xefc60000; val ^= val >> 18; - + return val; } diff --git a/arm9/src/overlay_manager.c b/arm9/src/overlay_manager.c index a59e15ac..0a03a87d 100644 --- a/arm9/src/overlay_manager.c +++ b/arm9/src/overlay_manager.c @@ -4,7 +4,7 @@ #include "heap.h" #include "overlay_manager.h" -THUMB_FUNC struct UnkStruct_02006234 * OverlayManager_new(struct Unk21DBE18 * ovly_mgr, int * a1, u32 heap_id) +THUMB_FUNC struct UnkStruct_02006234 * OverlayManager_new(const struct Unk21DBE18 * ovly_mgr, s32 * a1, u32 heap_id) { struct UnkStruct_02006234 * ret = (struct UnkStruct_02006234 *)AllocFromHeap(heap_id, sizeof(struct UnkStruct_02006234)); ret->ovly_mgr = *ovly_mgr; @@ -38,7 +38,7 @@ THUMB_FUNC void OverlayManager_FreeData(struct UnkStruct_02006234 * a0) a0->unk1C = NULL; } -THUMB_FUNC int * OverlayManager_GetField18(struct UnkStruct_02006234 * a0) +THUMB_FUNC s32 * OverlayManager_GetField18(struct UnkStruct_02006234 * a0) { return a0->unk18; } diff --git a/arm9/src/pokedex.c b/arm9/src/pokedex.c index bd1ea254..d86afa6a 100644 --- a/arm9/src/pokedex.c +++ b/arm9/src/pokedex.c @@ -226,12 +226,11 @@ void Pokedex_InitSeenDeoxysFormesArray(struct Pokedex * pokedex) static inline BOOL HasUnownLetterBeenSeen(struct Pokedex * pokedex, u8 letter) { - u8 * arr; s32 i; + u8 * arr; for (i = 0, arr = (u8 *)pokedex; i < 28; i++, arr++) { - u8 val = arr[0x010C]; - if (letter == val) + if (letter == *(arr + 0x10C)) return TRUE; } return FALSE; @@ -239,12 +238,11 @@ static inline BOOL HasUnownLetterBeenSeen(struct Pokedex * pokedex, u8 letter) static inline s32 FindFirstAvailableUnownLetterSlot(struct Pokedex * pokedex) { - u8 * arr; s32 i; + u8 * arr; for (i = 0, arr = (u8 *)pokedex; i < 28; i++, arr++) { - u8 val = arr[0x010C]; - if (val == 0xFF) + if (*(arr + 0x10C) == 0xFF) break; } return i; @@ -320,26 +318,26 @@ s32 FUN_020242C8(struct Pokedex * pokedex, u16 species, s32 r4) return r1; } -const u16 sSinnohDexMythicalMons[] = { - SPECIES_MANAPHY -}; - -const u16 sNationalDexMythicalMons[] = { - SPECIES_MEW, - SPECIES_LUGIA, - SPECIES_HO_OH, - SPECIES_CELEBI, - SPECIES_JIRACHI, - SPECIES_DEOXYS, - SPECIES_PHIONE, - SPECIES_MANAPHY, - SPECIES_DARKRAI, - SPECIES_SHAYMIN, - SPECIES_ARCEUS -}; - BOOL Pokedex_SpeciesIsNotMythical(u16 species) { + static const u16 sSinnohDexMythicalMons[] = { + SPECIES_MANAPHY + }; + + static const u16 sNationalDexMythicalMons[] = { + SPECIES_MEW, + SPECIES_LUGIA, + SPECIES_HO_OH, + SPECIES_CELEBI, + SPECIES_JIRACHI, + SPECIES_DEOXYS, + SPECIES_PHIONE, + SPECIES_MANAPHY, + SPECIES_DARKRAI, + SPECIES_SHAYMIN, + SPECIES_ARCEUS + }; + s32 i; BOOL ret = TRUE; for (i = 0; i < (s32)NELEMS(sNationalDexMythicalMons); i++) diff --git a/arm9/src/text.c b/arm9/src/text.c index aadb84c0..3034baab 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -7,7 +7,10 @@ const struct FontInfo *gFonts = NULL; u16 UNK_021C5734[0x100]; u32 UNK_021C5714[8]; -u8 UNK_021C570C[8]; +u16 UNK_021C570E; +u16 UNK_021C5710; +u16 UNK_021C5712; +u8 UNK_021C570C; extern u32 FUN_0200CA7C(void (*func)(u32, struct TextPrinter *), struct TextPrinter *printer, u32 param2); @@ -187,7 +190,7 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s printer->printerTemplate = *printerTemplate; printer->printerTemplate.currentChar = String_c_str((struct String *)printer->printerTemplate.currentChar); //TODO clean up printer->callback = callback; - UNK_021C570C[0] = 0; + UNK_021C570C = 0; FUN_0201C1A8(printer); if (speed != 0xff && speed != 0) { @@ -222,7 +225,7 @@ THUMB_FUNC u16 AddTextPrinter(struct TextPrinterTemplate *printerTemplate, u32 s THUMB_FUNC void RunTextPrinter(u32 param0, struct TextPrinter *printer) { #pragma unused(param0) - if (UNK_021C570C[0] == 0) + if (UNK_021C570C == 0) { if (printer->Unk29 == 0) { @@ -268,156 +271,39 @@ THUMB_FUNC u32 RenderFont(struct TextPrinter *printer) } } -#ifdef NONMATCHING THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor) { - u32 fg12, bg12, shadow12; - u32 temp; - - u16 *current = UNK_021C570C; - - bg12 = bgColor << 12; - fg12 = fgColor << 12; - shadow12 = shadowColor << 12; - - temp = (bgColor << 8) | (bgColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (bgColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (bgColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (fgColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (fgColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (fgColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (shadowColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (shadowColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (shadowColor << 4) | bgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (bgColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (bgColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (bgColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (fgColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (fgColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (fgColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (shadowColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (shadowColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (shadowColor << 4) | fgColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (bgColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (bgColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (bgColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (fgColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (fgColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (fgColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (bgColor << 8) | (shadowColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (fgColor << 8) | (shadowColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; - - temp = (shadowColor << 8) | (shadowColor << 4) | shadowColor; - *(current++) = (bg12) | temp; - *(current++) = (fg12) | temp; - *(current++) = (shadow12) | temp; + s32 r5 = 0; + u32 sp20[4]; + s32 i; // sp14 + s32 j; // sp10 + s32 k; // spC + s32 l; // r3 + + sp20[0] = 0; + sp20[1] = fgColor; + sp20[2] = shadowColor; + sp20[3] = bgColor; + + // FIXME: Need these to be accessed by a pointer to UNK_021C570C + UNK_021C5712 = bgColor; + UNK_021C570E = fgColor; + UNK_021C5710 = shadowColor; + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + for (k = 0; k < 4; k++) + { + for (l = 0; l < 4; l++) + { + UNK_021C5734[r5++] = (u16)((sp20[l] << 12) | (sp20[k] << 8) | (sp20[j] << 4) | (sp20[i] << 0)); + } + } + } + } } -#else -GLOBAL_ASM("asm/nonmatchings/GenerateFontHalfRowLookupTable.s") -#endif THUMB_FUNC void DecompressGlyphTile(const u16 *src, u16 *dst) { diff --git a/arm9/src/unk_02015E30.c b/arm9/src/unk_02015E30.c index 8be466fb..2f7b5bb5 100644 --- a/arm9/src/unk_02015E30.c +++ b/arm9/src/unk_02015E30.c @@ -1,35 +1,37 @@ #include "unk_02015E30.h" -struct UnkStruct_02015E30 UNK_021C4898; +u64 UNK_021C48B0; +u64 UNK_021C48A8; +u64 UNK_021C48A0; +struct IGT * UNK_021C489C; +u32 UNK_021C4898; THUMB_FUNC void FUN_02015E30() { - UNK_021C4898.unk00 = 0; + UNK_021C4898 = 0; } THUMB_FUNC void FUN_02015E3C(struct IGT *igt) { - struct UnkStruct_02015E30 *unk1 = &UNK_021C4898; - UNK_021C4898.unk00 = 1; - UNK_021C4898.unk10 = 0; - UNK_021C4898.unk14 = 0; - UNK_021C4898.unk08 = 0; - UNK_021C4898.unk04 = igt; + UNK_021C4898 = 1; + UNK_021C48A8 = 0; + UNK_021C48A0 = 0; + UNK_021C489C = igt; - UNK_021C4898.unk18 = GetTimer3Count(); + UNK_021C48B0 = GetTimer3Count(); } THUMB_FUNC void FUN_02015E60() { - if (UNK_021C4898.unk00 != 0) + if (UNK_021C4898 != 0) { - u64 res = Timer3CountToSeconds(GetTimer3Count() - UNK_021C4898.unk18); + u64 res = Timer3CountToSeconds(GetTimer3Count() - UNK_021C48B0); - if (UNK_021C4898.unk08 < res) + if (UNK_021C48A0 < res) { - AddIGTSeconds(UNK_021C4898.unk04, (u32)(res - UNK_021C4898.unk08)); - UNK_021C4898.unk08 = res; + AddIGTSeconds(UNK_021C489C, (u32)(res - UNK_021C48A0)); + UNK_021C48A0 = res; } } } diff --git a/arm9/src/unk_02021934.c b/arm9/src/unk_02021934.c index cd66a136..ebc600fa 100644 --- a/arm9/src/unk_02021934.c +++ b/arm9/src/unk_02021934.c @@ -109,31 +109,31 @@ struct String * StringDup(struct String * src, u32 heap_id) return dest; } -static const u16 sCharset_JP[10] = { - 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, - 0xA7, 0xA8, 0xA9, 0xAA, 0xAB -}; - -static const u16 sCharset_EN[10] = { - 0x121, 0x122, 0x123, 0x124, 0x125, - 0x126, 0x127, 0x128, 0x129, 0x12A -}; - -static const u32 sPowersOfTen[10] = { - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000 -}; - void String16_FormatInteger(struct String * str, int num, u32 ndigits, int strConvMode, BOOL whichCharset) { + static const u16 sCharset_EN[10] = { + 0x121, 0x122, 0x123, 0x124, 0x125, + 0x126, 0x127, 0x128, 0x129, 0x12A + }; + + static const u16 sCharset_JP[10] = { + 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, + 0xA7, 0xA8, 0xA9, 0xAA, 0xAB + }; + + static const u32 sPowersOfTen[10] = { + 1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000 + }; + ASSERT_STR16(str); const u16 * charbase; diff --git a/arm9/src/unk_0202E29C.c b/arm9/src/unk_0202E29C.c index 36c18b16..5f99ca8f 100644 --- a/arm9/src/unk_0202E29C.c +++ b/arm9/src/unk_0202E29C.c @@ -247,21 +247,20 @@ THUMB_FUNC void FUN_0202E538() THUMB_FUNC void FUN_0202E56C(u32 param0) { - UNK_021C59E8.unk8->unkDAD = - (UNK_021C59E8.unk8->unkDAD & ~8 | (u32)((u8)param0 << 0x1f) >> 0x1c); + UNK_021C59E8.unk8->unkDAD_3 = (u8)param0; } THUMB_FUNC void FUN_0202E594() { UNK_021C59E8.unk8->unkCB4 = 0; - UNK_021C59E8.unk8->unkDAD &= ~1; + UNK_021C59E8.unk8->unkDAD_0 = 0; - UNK_021C59E8.unk8->unkDAD &= ~4; + UNK_021C59E8.unk8->unkDAD_2 = 0; UNK_021C59E8.unk8->unkDAA = 0; - UNK_021C59E8.unk8->unkDAD &= ~0x10; + UNK_021C59E8.unk8->unkDAD_4 = 0; UNK_021C59E8.unk8->unkDAC = 0; @@ -281,8 +280,7 @@ THUMB_FUNC BOOL FUN_0202E5F8(u32 param0, u32 param1, u32 param2) UNK_021C59E8.unk8->unkDAB = 1; } - UNK_021C59E8.unk8->unkDAD = - (UNK_021C59E8.unk8->unkDAD & ~0x20 | (u32)((u8)param2 << 0x1f) >> 0x1a); + UNK_021C59E8.unk8->unkDAD_5 = (u8)param2; if (FUN_0202CBD4() == 1 && FUN_0202CBFC() != 0) { return TRUE; @@ -659,10 +657,9 @@ THUMB_FUNC void FUN_0202EBD0(u16 param0) FUN_0202DF54(); FUN_0202EB7C(); - if (FUN_0202D19C() == 0 && FUN_0202EE24() == 0 && - ((u32)(UNK_021C59E8.unk8->unkDAD << 0x1d) >> 0x1f) != 0) + if (FUN_0202D19C() == 0 && FUN_0202EE24() == 0 && UNK_021C59E8.unk8->unkDAD_2) { - UNK_021C59E8.unk8->unkDAD = (UNK_021C59E8.unk8->unkDAD & ~1) | 1; + UNK_021C59E8.unk8->unkDAD_0 = 1; } if (UNK_021C59E8.unk8->unkDA6 == 0xFFFF) @@ -670,10 +667,10 @@ THUMB_FUNC void FUN_0202EBD0(u16 param0) UNK_021C59E8.unk8->unkDA6 = param0; } - if (((u32)(UNK_021C59E8.unk8->unkDAD << 0x1e) >> 0x1f) != 0 && + if (UNK_021C59E8.unk8->unkDAD_1 && UNK_021C59E8.unk8->unkDA6 > param0) { - UNK_021C59E8.unk8->unkDAD = (UNK_021C59E8.unk8->unkDAD & ~1) | 1; + UNK_021C59E8.unk8->unkDAD_0 = 1; } if (FUN_0202CBE8() == 25) @@ -713,7 +710,7 @@ THUMB_FUNC void FUN_0202EBD0(u16 param0) if (UNK_021C59E8.unk8 != NULL) { - UNK_021C59E8.unk8->unkDAD = (UNK_021C59E8.unk8->unkDAD & ~1) | 1; + UNK_021C59E8.unk8->unkDAD_0 = 1; return; } break; @@ -731,7 +728,7 @@ THUMB_FUNC void FUN_0202EBD0(u16 param0) } u16 r5 = UNK_021C59E8.unk8->unkDA4; - if ((u32)(UNK_021C59E8.unk8->unkDAD << 0x1c) >> 0x1f != 0) + if (UNK_021C59E8.unk8->unkDAD_3) { UNK_021C59E8.unk0++; } @@ -743,7 +740,7 @@ THUMB_FUNC void FUN_0202EBD0(u16 param0) r5, FUN_0202D858((u16)FUN_02033534()), FUN_0202EEE8((u16)FUN_02033534()), - (u32)(UNK_021C59E8.unk8->unkDAD << 0x1a) >> 0x1f); + UNK_021C59E8.unk8->unkDAD_5); UNK_021C59E8.unk8->unkDA8 = (u8)r5; @@ -848,7 +845,7 @@ THUMB_FUNC BOOL FUN_0202EE44() THUMB_FUNC BOOL FUN_0202EE60() { - if (UNK_021C59E8.unk8 != NULL && (u32)(UNK_021C59E8.unk8->unkDAD << 0x1f) >> 0x1f != 0) + if (UNK_021C59E8.unk8 != NULL && UNK_021C59E8.unk8->unkDAD_0) { return TRUE; } @@ -860,8 +857,7 @@ THUMB_FUNC void FUN_0202EE84(u32 param0) { if (UNK_021C59E8.unk8 != NULL) { - UNK_021C59E8.unk8->unkDAD = - (UNK_021C59E8.unk8->unkDAD & ~4) | (u32)((u8)param0 << 0x1f) >> 0x1d; + UNK_021C59E8.unk8->unkDAD_2 = (u8)param0; } } @@ -869,8 +865,7 @@ THUMB_FUNC void FUN_0202EEB0(u32 param0) { if (UNK_021C59E8.unk8 != NULL) { - UNK_021C59E8.unk8->unkDAD = - (UNK_021C59E8.unk8->unkDAD & ~2) | (u32)((u8)param0 << 0x1f) >> 0x1e; + UNK_021C59E8.unk8->unkDAD_1 = (u8)param0; UNK_021C59E8.unk8->unkDA6 = 0xFFFF; } @@ -1038,7 +1033,7 @@ THUMB_FUNC u32 FUN_0202F03C() { if (UNK_021C59E8.unk8 != NULL) { - return (u32)(UNK_021C59E8.unk8->unkDAD << 0x1b) >> 0x1f; + return UNK_021C59E8.unk8->unkDAD_4; } return 0; @@ -1048,7 +1043,7 @@ THUMB_FUNC void FUN_0202F05C() { if (UNK_021C59E8.unk8 != NULL) { - UNK_021C59E8.unk8->unkDAD |= 0x10; + UNK_021C59E8.unk8->unkDAD_4 = 1; } } diff --git a/arm9/src/unk_0202F150.c b/arm9/src/unk_0202F150.c index d52857c1..1586dae5 100644 --- a/arm9/src/unk_0202F150.c +++ b/arm9/src/unk_0202F150.c @@ -10,8 +10,8 @@ struct struct UnkStruct0202F150 *unk04; } UNK_021C59F4; -vu8 UNK_02105D58 = 4; vu8 UNK_02105D59 = 4; +vu8 UNK_02105D58 = 4; extern void FUN_0202D7D8(u8 *param0, u32 param1, struct UnkStruct0202F150_sub1 *param2); extern u32 FUN_0200CA60(void (*param0)(), u32 param1, u32 param2); @@ -336,9 +336,9 @@ THUMB_FUNC void FUN_0202F910(int param0) FUN_0202F820(param0); } -THUMB_FUNC u32 FUN_0202F918(u32 param0, u32 param1, u32 param2, u32 param3) +THUMB_FUNC BOOL FUN_0202F918(u32 param0, u32 param1, u32 param2, u32 param3) { - u32 ret = 1; + BOOL ret = TRUE; if (FUN_02033534() < 0x13) { ret = FUN_0202E5F8(param0, param1, param3); diff --git a/arm9/src/unk_02031734.c b/arm9/src/unk_02031734.c index 65ed3bc4..57764b82 100644 --- a/arm9/src/unk_02031734.c +++ b/arm9/src/unk_02031734.c @@ -18,12 +18,10 @@ const struct UnkStruct_02031734_const1 UNK_020EEC5C = { { (u32)FUN_02032234, (u32)FUN_0203234C, 0 } }; +char UNK_02105D64[] = " FULL"; char UNK_02105D5C[] = "FREAK"; - char UNK_02105D6C[] = " GAME"; -char UNK_02105D64[] = " FULL"; - struct UnkStruct_02031734 *UNK_021C5A00; extern void FUN_0202D8D0(u32 param0, u32 param1, u32 param2); diff --git a/include/main.h b/include/main.h index d40e22f9..2e424e09 100644 --- a/include/main.h +++ b/include/main.h @@ -20,7 +20,7 @@ struct UnkStruct_02006234 struct Unk21DBE18 ovly_mgr; u32 unk10; u32 unk14; - int * unk18; + s32 * unk18; void * unk1C; struct SaveBlock2 * unk20; u32 unk24; @@ -31,9 +31,9 @@ struct Unk2106FA0 PMBackLightSwitch unk0; s32 unk4; FSOverlayID unk8; - s32 unkC; + struct UnkStruct_02006234 *unkC; FSOverlayID unk10; - struct Unk21DBE18 * unk14; + const struct Unk21DBE18 * unk14; s32 unk18; s32 unk1C; struct SaveBlock2 * unk20; @@ -113,7 +113,7 @@ extern struct Main gMain; void FUN_02000DF4(void); void Main_RunOverlayManager(void); -void RegisterMainOverlay(FSOverlayID id, struct Unk21DBE18 * arg1); +void RegisterMainOverlay(FSOverlayID id, const struct Unk21DBE18 * arg1); void FUN_02000E9C(void); void FUN_02000EC8(u32 parameter); void FUN_02000EE8(void); diff --git a/include/overlay_manager.h b/include/overlay_manager.h index 193bc7e8..8d9bd6e3 100644 --- a/include/overlay_manager.h +++ b/include/overlay_manager.h @@ -5,12 +5,12 @@ struct Unk21DBE18; -struct UnkStruct_02006234 * OverlayManager_new(struct Unk21DBE18 * ovly_mgr, int * a1, u32 heap_id); +struct UnkStruct_02006234 * OverlayManager_new(const struct Unk21DBE18 * ovly_mgr, s32 * a1, u32 heap_id); void OverlayManager_delete(struct UnkStruct_02006234 * a0); void * OverlayManager_CreateAndGetData(struct UnkStruct_02006234 * a0, u32 size, u32 heap_id); void * OverlayManager_GetData(struct UnkStruct_02006234 * a0); void OverlayManager_FreeData(struct UnkStruct_02006234 * a0); -int * OverlayManager_GetField18(struct UnkStruct_02006234 * a0); +s32 * OverlayManager_GetField18(struct UnkStruct_02006234 * a0); BOOL OverlayManager_Run(struct UnkStruct_02006234 * a0); #endif //POKEDIAMOND_OVERLAY_MANAGER_H diff --git a/include/unk_0202E29C.h b/include/unk_0202E29C.h index d4316336..92998f7c 100644 --- a/include/unk_0202E29C.h +++ b/include/unk_0202E29C.h @@ -68,7 +68,12 @@ struct UnkStruct_0202E29C u8 unkDAA; u8 unkDAB; u8 unkDAC; - u8 unkDAD; + u8 unkDAD_0:1; + u8 unkDAD_1:1; + u8 unkDAD_2:1; + u8 unkDAD_3:1; + u8 unkDAD_4:1; + u8 unkDAD_5:1; u8 unkDAE[0x2]; }; diff --git a/include/unk_0202F150.h b/include/unk_0202F150.h index ea0846c6..8f5cdd3e 100644 --- a/include/unk_0202F150.h +++ b/include/unk_0202F150.h @@ -93,7 +93,7 @@ THUMB_FUNC void FUN_0202F5A4(); THUMB_FUNC void FUN_0202F820(int param0); THUMB_FUNC void FUN_0202F8D4(); THUMB_FUNC void FUN_0202F910(int param0); -THUMB_FUNC u32 FUN_0202F918(u32 param0, u32 param1, u32 param2, u32 param3); +THUMB_FUNC BOOL FUN_0202F918(u32 param0, u32 param1, u32 param2, u32 param3); THUMB_FUNC u32 FUN_0202F950(u32 param0, u32 param1, u32 param2); THUMB_FUNC void FUN_0202F984(); THUMB_FUNC void FUN_0202F9E0(u32 param0); diff --git a/tools/fixrom/fixrom.c b/tools/fixrom/fixrom.c index 6c5f5da1..59fbd327 100644 --- a/tools/fixrom/fixrom.c +++ b/tools/fixrom/fixrom.c @@ -6,8 +6,12 @@ #include <stdnoreturn.h> #include <stdarg.h> -#define HEADER_SIZE 0x4000 +#define HEADER_SIZE 0x4000 +#define HEADER_CODE_OFFSET 0xC +#define HEADER_SECURE_CRC_OFFSET 0x6C +#define HEADER_CRC_OFFSET 0x15E +// ROM header buffer uint8_t RomHeader[HEADER_SIZE]; static inline noreturn __attribute__((format(printf, 1, 2))) void fatal_error(const char * message, ...) @@ -21,6 +25,9 @@ static inline noreturn __attribute__((format(printf, 1, 2))) void fatal_error(co exit(EXIT_FAILURE); } +// Pedantic check to make sure you're writing to or reading from a valid range +// within the ROM header buffer. +// Call twice, once with the first offset and again with the last address. static inline void OffsetCheck(int offset) { if (offset < 0 || offset >= HEADER_SIZE) @@ -29,80 +36,77 @@ static inline void OffsetCheck(int offset) } } +// Wrapper for memcpy that writes to the ROM header buffer +static inline uint8_t * SafeCopyToHeader(int offset, const void * src, size_t size) +{ + OffsetCheck(offset); + OffsetCheck(offset + size - 1); + return memcpy(RomHeader + offset, src, size); +} + +// Read a 16-bit word from the header buffer static inline uint16_t HeaderReadU16LE(int offset) { OffsetCheck(offset); + OffsetCheck(offset + 1); return RomHeader[offset] | (RomHeader[offset + 1] << 8); } +// Read a 32-bit word from the header buffer static inline uint32_t HeaderReadU32LE(int offset) { OffsetCheck(offset); + OffsetCheck(offset + 3); return RomHeader[offset] | (RomHeader[offset + 1] << 8) | (RomHeader[offset + 2] << 16) | (RomHeader[offset + 3] << 24); } +// Write a 16-bit word to the header buffer static inline void HeaderWriteU16LE(int offset, uint16_t value) { OffsetCheck(offset); + OffsetCheck(offset + 1); RomHeader[offset] = value; RomHeader[offset + 1] = value >> 8; } +// Write a 32-bit word to the header buffer static inline void HeaderWriteU32LE(int offset, uint32_t value) { OffsetCheck(offset); + OffsetCheck(offset + 3); RomHeader[offset] = value; RomHeader[offset + 1] = value >> 8; RomHeader[offset + 2] = value >> 16; RomHeader[offset + 3] = value >> 24; } +// Standard CRC16 routine +#define CRC16_POLYNOMIAL 0xA001 + static uint16_t Calc_CRC16(uint8_t * data, size_t length, uint16_t crc) { - static uint16_t CrcTable[16] = { - 0x0000, - 0xCC01, - 0xD801, - 0x1400, - 0xF001, - 0x3C00, - 0x2800, - 0xE401, - 0xA001, - 0x6C00, - 0x7800, - 0xB401, - 0x5000, - 0x9C01, - 0x8801, - 0x4400, - }; - - uint16_t x = 0; - uint16_t y; - uint16_t bit = 0; - uint8_t * end = data + length; - while (data < end) - { - if (bit == 0) - { - x = data[0] | (data[1] << 8); - } - y = CrcTable[crc & 15]; - crc >>= 4; - crc ^= y; - y = CrcTable[(x >> bit) & 15]; - crc ^= y; - bit += 4; - if (bit == 16) - { - data += 2; - bit = 0; + static uint16_t CrcTable[256] = {}; + static int initialized = 0; + int i; + + if (!initialized) { + for (i = 0; i < 256; i++) { + int c = i; + for (int j = 0; j < 8; j++) { + c = (c >> 1) ^ ((c & 1) ? CRC16_POLYNOMIAL : 0); + } + CrcTable[i] = c; } + initialized = 1; } + + for (i = 0; i < length; i++) { + crc = (crc >> 8) ^ CrcTable[(uint8_t)crc] ^ CrcTable[data[i]]; + } + return crc; } @@ -114,20 +118,24 @@ int main(int argc, char ** argv) int override_code = 0; FILE * rom = NULL; + // Parse arguments for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--secure-crc") == 0) { + // Enforce zero or one if (override_crc) { fatal_error("multiple --secure-crc options specified"); } + // Parse integer char * endptr; unsigned long secure_crc_l = strtoul(argv[++i], &endptr, 0); if (secure_crc_l == 0 && endptr == argv[i]) { fatal_error("argument to --secure-crc must be an integer"); } - if (secure_crc_l >= 0x10000) + // Enforce width + if (secure_crc_l > UINT16_MAX) { fatal_error("argument to --secure-crc must be a 16-bit integer"); } @@ -136,55 +144,66 @@ int main(int argc, char ** argv) } else if (strcmp(argv[i], "--game-code") == 0) { + // Enforce zero or one if (override_code) { fatal_error("multiple --game-code options specified"); } - if (strlen(argv[++i]) > 4) + // Enforce max length + if (strlen(argv[++i]) > sizeof(game_code)) { fatal_error("argument to --game-code must be 4 characters or fewer"); } - strncpy(game_code, argv[i], 4); + memset(game_code, 0, sizeof(game_code)); + strncpy(game_code, argv[i], sizeof(game_code)); override_code = 1; } - else + // Positional arguments + else if (rom == NULL) { - if (rom != NULL) - { - fatal_error("unrecognized %s argument: %s", argv[i][0] == '-' ? "flag" : "positional", argv[i]); - } rom = fopen(argv[i], "r+b"); if (rom == NULL) { fatal_error(argv[i][0] == '-' ? "unrecognized flag argument: %s" : "unable to open file '%s' for reading", argv[i]); } } + else + { + // Invalid argument, complain about it + fatal_error("unrecognized %s argument: %s", argv[i][0] == '-' ? "flag" : "positional", argv[i]); + } } + // Read header to buffer if (fread(RomHeader, 1, HEADER_SIZE, rom) != HEADER_SIZE) { fatal_error("error reading the ROM header"); } + // Update CRC if (override_crc) { - HeaderWriteU16LE(0x6C, secure_crc); + HeaderWriteU16LE(HEADER_SECURE_CRC_OFFSET, secure_crc); } - + + // Update code if (override_code) { - memcpy(RomHeader + 0xC, game_code, 4); + SafeCopyToHeader(HEADER_CODE_OFFSET, game_code, sizeof(game_code)); } - uint16_t header_crc = Calc_CRC16((uint8_t *)RomHeader, 0x15E, 0xFFFF); - HeaderWriteU16LE(0x15E, header_crc); + // Recompute CRC of header not including the crc offset + uint16_t header_crc = Calc_CRC16((uint8_t *)RomHeader, HEADER_CRC_OFFSET, 0xFFFF); + HeaderWriteU16LE(HEADER_CRC_OFFSET, header_crc); + // Write the header back fseek(rom, 0, SEEK_SET); if (fwrite(RomHeader, 1, HEADER_SIZE, rom) != HEADER_SIZE) { fatal_error("error writing the ROM header"); } + // Hooray, we done did it! fclose(rom); return EXIT_SUCCESS; } |