From 86c2917cc08e343ea5797c6b3afa04b71a6fb471 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 14 Aug 2020 04:25:16 +0100 Subject: [PATCH 1/4] match load_map_bg Also added three new symbols to `undefined_syms.h`. Two of these are almost certainly string literals in `load_map_bg`, but we don't have rodata capability yet so they have to be declared in a different way. --- .../code_dc470_len_14c0/load_map_bg.s | 42 ------------------- include/variables.h | 3 ++ src/code_dc470_len_14c0.c | 35 ++++++++-------- undefined_syms.txt | 3 ++ 4 files changed, 24 insertions(+), 59 deletions(-) delete mode 100644 asm/nonmatchings/code_dc470_len_14c0/load_map_bg.s diff --git a/asm/nonmatchings/code_dc470_len_14c0/load_map_bg.s b/asm/nonmatchings/code_dc470_len_14c0/load_map_bg.s deleted file mode 100644 index 6e3b92dec3..0000000000 --- a/asm/nonmatchings/code_dc470_len_14c0/load_map_bg.s +++ /dev/null @@ -1,42 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel load_map_bg -/* 0DC470 80145D70 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 0DC474 80145D74 AFBF001C */ sw $ra, 0x1c($sp) -/* 0DC478 80145D78 1080001B */ beqz $a0, .L80145DE8 -/* 0DC47C 80145D7C AFB00018 */ sw $s0, 0x18($sp) -/* 0DC480 80145D80 0080802D */ daddu $s0, $a0, $zero -/* 0DC484 80145D84 0000202D */ daddu $a0, $zero, $zero -/* 0DC488 80145D88 3C05F5DE */ lui $a1, 0xf5de -/* 0DC48C 80145D8C 0C0B1EAF */ jal get_variable -/* 0DC490 80145D90 34A50180 */ ori $a1, $a1, 0x180 -/* 0DC494 80145D94 28420035 */ slti $v0, $v0, 0x35 -/* 0DC498 80145D98 1440000A */ bnez $v0, .L80145DC4 -/* 0DC49C 80145D9C 0200202D */ daddu $a0, $s0, $zero -/* 0DC4A0 80145DA0 3C058015 */ lui $a1, 0x8015 -/* 0DC4A4 80145DA4 24A5F120 */ addiu $a1, $a1, -0xee0 -/* 0DC4A8 80145DA8 0C01BB5C */ jal strcmp -/* 0DC4AC 80145DAC 0200202D */ daddu $a0, $s0, $zero -/* 0DC4B0 80145DB0 54400004 */ bnel $v0, $zero, .L80145DC4 -/* 0DC4B4 80145DB4 0200202D */ daddu $a0, $s0, $zero -/* 0DC4B8 80145DB8 3C108015 */ lui $s0, 0x8015 -/* 0DC4BC 80145DBC 2610F128 */ addiu $s0, $s0, -0xed8 -/* 0DC4C0 80145DC0 0200202D */ daddu $a0, $s0, $zero -.L80145DC4: -/* 0DC4C4 80145DC4 0C016B3A */ jal load_asset_by_name -/* 0DC4C8 80145DC8 27A50010 */ addiu $a1, $sp, 0x10 -/* 0DC4CC 80145DCC 0040802D */ daddu $s0, $v0, $zero -/* 0DC4D0 80145DD0 3C058020 */ lui $a1, 0x8020 -/* 0DC4D4 80145DD4 24A50000 */ addiu $a1, $a1, 0 -/* 0DC4D8 80145DD8 0C01BB7C */ jal decode_yay0 -/* 0DC4DC 80145DDC 0200202D */ daddu $a0, $s0, $zero -/* 0DC4E0 80145DE0 0C00AB1E */ jal general_heap_free -/* 0DC4E4 80145DE4 0200202D */ daddu $a0, $s0, $zero -.L80145DE8: -/* 0DC4E8 80145DE8 8FBF001C */ lw $ra, 0x1c($sp) -/* 0DC4EC 80145DEC 8FB00018 */ lw $s0, 0x18($sp) -/* 0DC4F0 80145DF0 03E00008 */ jr $ra -/* 0DC4F4 80145DF4 27BD0020 */ addiu $sp, $sp, 0x20 - diff --git a/include/variables.h b/include/variables.h index e4039c8b0f..fdd8d32246 100644 --- a/include/variables.h +++ b/include/variables.h @@ -15,6 +15,9 @@ extern s16* D_80151328; extern s16 D_8010CD10; extern s16 D_8010CD12; extern s32 D_801595A0; +extern u8 gCloudyFlowerFieldsBg; // "fla_bg" +extern u8 gSunnyFlowerFieldsBg; // "flb_bg" +extern UNK_TYPE gBackgroundImage; extern s8 D_8014F12F; // Triggers diff --git a/src/code_dc470_len_14c0.c b/src/code_dc470_len_14c0.c index 802dbe547a..8658e02fbb 100644 --- a/src/code_dc470_len_14c0.c +++ b/src/code_dc470_len_14c0.c @@ -1,25 +1,26 @@ #include "common.h" -INCLUDE_ASM(code_dc470_len_14c0, load_map_bg); -/* close match -void load_map_bg (s32 arg0) { - s32 tempvar0 = arg0; - s32 flowerfields_bg1 = 0x80140EE0; - s32 tempvar3 = get_variable(0, 0xF5DE0180); - if (tempvar0 == 0) { - return; - }else{ - if (tempvar3 > 0x0034) { - if (strcmp(tempvar0, 0x8014F120) == 0) { - tempvar0 = flowerfields_bg1; - } - load_asset_by_name (tempvar0, 0); +void load_map_bg(u8* optAssetName) { + UNK_PTR compressedData; + u32 assetSize; + u8* assetName; + + if (!optAssetName) return; + assetName = optAssetName; + + // StoryProgress check + if (get_variable(0, 0xF5DE0180) >= 0x35) { + // Use sunny Flower Fields bg rather than cloudy + // TODO: these globals should be string literals + if (!strcmp(assetName, &gCloudyFlowerFieldsBg)) { + assetName = &gSunnyFlowerFieldsBg; } } - decode_yay0(tempvar0, 0x80200000); - general_heap_free(tempvar0); + + compressedData = load_asset_by_name(assetName, &assetSize); + decode_yay0(compressedData, &gBackgroundImage); + general_heap_free(compressedData); } -*/ void func_80145DF8(void) { game_status* gameStatus = *gGameStatusPtr; diff --git a/undefined_syms.txt b/undefined_syms.txt index 0965e25b8e..d919d30ecf 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -36,6 +36,7 @@ D_8009A650 = 0x8009A650; D_800A0900 = 0x800A0900; D_800DC500 = 0x800DC500; D_8010F6D0 = 0x8010F6D0; +gBackgroundImage = 0x80200000; D_802C3000 = 0x802C3000; D_802DBD40 = 0x802DBD40; D_802E0D90 = 0x802E0D90; @@ -52,6 +53,8 @@ D_00316D90 = 0x00316D90; D_00316F30 = 0x00316F30; D_8010D000 = 0x8010D000; +gCloudyFlowerFieldsBg = 0x8014F120; +gSunnyFlowerFieldsBg = 0x8014F128; D_8014F12F = 0x8014F12F; D_8014F140 = 0x8014F140; D_80151308 = 0x80151308; From 15f3d1a5652392c977fb87c2f82d5c7ed1207f15 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 14 Aug 2020 04:37:24 +0100 Subject: [PATCH 2/4] use bg_header type for gBackgroundImage --- include/variables.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/variables.h b/include/variables.h index fdd8d32246..8ed697f621 100644 --- a/include/variables.h +++ b/include/variables.h @@ -17,7 +17,7 @@ extern s16 D_8010CD12; extern s32 D_801595A0; extern u8 gCloudyFlowerFieldsBg; // "fla_bg" extern u8 gSunnyFlowerFieldsBg; // "flb_bg" -extern UNK_TYPE gBackgroundImage; +extern bg_header gBackgroundImage; extern s8 D_8014F12F; // Triggers From d041f520abce4394a1d7211b1ae601e1866915e8 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 14 Aug 2020 05:15:00 +0100 Subject: [PATCH 3/4] explicitly check for NULL --- src/code_dc470_len_14c0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code_dc470_len_14c0.c b/src/code_dc470_len_14c0.c index 8658e02fbb..291dd60e2b 100644 --- a/src/code_dc470_len_14c0.c +++ b/src/code_dc470_len_14c0.c @@ -5,7 +5,7 @@ void load_map_bg(u8* optAssetName) { u32 assetSize; u8* assetName; - if (!optAssetName) return; + if (optAssetName == NULL) return; assetName = optAssetName; // StoryProgress check From 9eb74da229123d509ae0291eb0451e3975505e49 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Fri, 14 Aug 2020 05:25:13 +0100 Subject: [PATCH 4/4] use `char[]` type for string externs --- include/variables.h | 4 ++-- src/code_dc470_len_14c0.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/variables.h b/include/variables.h index 8ed697f621..34ec16f1d7 100644 --- a/include/variables.h +++ b/include/variables.h @@ -15,8 +15,8 @@ extern s16* D_80151328; extern s16 D_8010CD10; extern s16 D_8010CD12; extern s32 D_801595A0; -extern u8 gCloudyFlowerFieldsBg; // "fla_bg" -extern u8 gSunnyFlowerFieldsBg; // "flb_bg" +extern char gCloudyFlowerFieldsBg[]; // "fla_bg" +extern char gSunnyFlowerFieldsBg[]; // "flb_bg" extern bg_header gBackgroundImage; extern s8 D_8014F12F; diff --git a/src/code_dc470_len_14c0.c b/src/code_dc470_len_14c0.c index 291dd60e2b..4e3bc4a1db 100644 --- a/src/code_dc470_len_14c0.c +++ b/src/code_dc470_len_14c0.c @@ -1,9 +1,9 @@ #include "common.h" -void load_map_bg(u8* optAssetName) { +void load_map_bg(char* optAssetName) { UNK_PTR compressedData; u32 assetSize; - u8* assetName; + char* assetName; if (optAssetName == NULL) return; assetName = optAssetName; @@ -12,8 +12,8 @@ void load_map_bg(u8* optAssetName) { if (get_variable(0, 0xF5DE0180) >= 0x35) { // Use sunny Flower Fields bg rather than cloudy // TODO: these globals should be string literals - if (!strcmp(assetName, &gCloudyFlowerFieldsBg)) { - assetName = &gSunnyFlowerFieldsBg; + if (!strcmp(assetName, gCloudyFlowerFieldsBg)) { + assetName = gSunnyFlowerFieldsBg; } }