From f02ad05c4f6e5e4c81875969bdd133d197b6e938 Mon Sep 17 00:00:00 2001 From: dark-samus Date: Sat, 22 Aug 2020 03:43:30 -0400 Subject: [PATCH] merge master --- Makefile | 2 +- .../code_dc470_len_14c0/func_80145EC0.s | 14 -- .../code_dc470_len_14c0/func_8014720C.s | 8 ++ .../code_dc470_len_14c0/func_8014721C.s | 11 ++ .../code_e79b0_len_1920/func_802C39F8.s | 66 ---------- .../code_e79b0_len_1920/func_802C3C10.s | 69 ++++++++++ .../code_f8f60_len_1560/func_802D4BDC.s | 38 ------ .../code_f8f60_len_1560/func_802D4C4C.s | 40 ------ include/common_structs.h | 5 +- include/variables.h | 2 +- src/code_dc470_len_14c0.c | 13 +- src/code_dd930_len_1c0.c | 57 ++++---- src/code_e79b0_len_1920.c | 99 ++++++++++++-- src/code_f8f60_len_1560.c | 124 +++++++++++++++--- undefined_syms.txt | 8 +- 15 files changed, 330 insertions(+), 226 deletions(-) create mode 100644 asm/nonmatchings/code_dc470_len_14c0/func_8014720C.s create mode 100644 asm/nonmatchings/code_dc470_len_14c0/func_8014721C.s create mode 100644 asm/nonmatchings/code_e79b0_len_1920/func_802C3C10.s delete mode 100644 asm/nonmatchings/code_f8f60_len_1560/func_802D4BDC.s delete mode 100644 asm/nonmatchings/code_f8f60_len_1560/func_802D4C4C.s diff --git a/Makefile b/Makefile index dfb3a3ed84..7716b11546 100644 --- a/Makefile +++ b/Makefile @@ -47,7 +47,7 @@ TARGET = papermario CPPFLAGS = -fno-builtin -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 ASFLAGS = -EB -march=vr4300 -mtune=vr4300 -Iinclude -OLDASFLAGS= -EB -Iinclude +OLDASFLAGS= -EB -Iinclude -G 0 CFLAGS = -fno-builtin -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 LDFLAGS = -T undefined_syms.txt -T $(LD_SCRIPT) -Map $(BUILD_DIR)/papermario.map --no-check-sections diff --git a/asm/nonmatchings/code_dc470_len_14c0/func_80145EC0.s b/asm/nonmatchings/code_dc470_len_14c0/func_80145EC0.s index 85f40e5aea..1da2d82819 100644 --- a/asm/nonmatchings/code_dc470_len_14c0/func_80145EC0.s +++ b/asm/nonmatchings/code_dc470_len_14c0/func_80145EC0.s @@ -1284,17 +1284,3 @@ glabel func_80145EC0 /* 0DD900 80147200 D7B400A8 */ ldc1 $f20, 0xa8($sp) /* 0DD904 80147204 03E00008 */ jr $ra /* 0DD908 80147208 27BD00B8 */ addiu $sp, $sp, 0xb8 - -/* 0DD90C 8014720C 24020001 */ addiu $v0, $zero, 1 -/* 0DD910 80147210 3C018015 */ lui $at, 0x8015 -/* 0DD914 80147214 03E00008 */ jr $ra -/* 0DD918 80147218 A022F12F */ sb $v0, -0xed1($at) - -/* 0DD91C 8014721C 3C018015 */ lui $at, 0x8015 -/* 0DD920 80147220 03E00008 */ jr $ra -/* 0DD924 80147224 A020F12F */ sb $zero, -0xed1($at) - -/* 0DD928 80147228 00000000 */ nop -/* 0DD92C 8014722C 00000000 */ nop - - diff --git a/asm/nonmatchings/code_dc470_len_14c0/func_8014720C.s b/asm/nonmatchings/code_dc470_len_14c0/func_8014720C.s new file mode 100644 index 0000000000..abe452e51c --- /dev/null +++ b/asm/nonmatchings/code_dc470_len_14c0/func_8014720C.s @@ -0,0 +1,8 @@ +.set noat # allow manual use of $at +.set noreorder # don't insert nops after branches + +glabel func_8014720C +/* 0DD90C 8014720C 24020001 */ addiu $v0, $zero, 1 +/* 0DD910 80147210 3C018015 */ lui $at, 0x8015 +/* 0DD914 80147214 03E00008 */ jr $ra +/* 0DD918 80147218 A022F12F */ sb $v0, -0xed1($at) \ No newline at end of file diff --git a/asm/nonmatchings/code_dc470_len_14c0/func_8014721C.s b/asm/nonmatchings/code_dc470_len_14c0/func_8014721C.s new file mode 100644 index 0000000000..7561281047 --- /dev/null +++ b/asm/nonmatchings/code_dc470_len_14c0/func_8014721C.s @@ -0,0 +1,11 @@ +.set noat # allow manual use of $at +.set noreorder # don't insert nops after branches + + +glabel func_8014721C +/* 0DD91C 8014721C 3C018015 */ lui $at, 0x8015 +/* 0DD920 80147220 03E00008 */ jr $ra +/* 0DD924 80147224 A020F12F */ sb $zero, -0xed1($at) + +/* 0DD928 80147228 00000000 */ nop +/* 0DD92C 8014722C 00000000 */ nop \ No newline at end of file diff --git a/asm/nonmatchings/code_e79b0_len_1920/func_802C39F8.s b/asm/nonmatchings/code_e79b0_len_1920/func_802C39F8.s index dec2619782..1afe70132a 100644 --- a/asm/nonmatchings/code_e79b0_len_1920/func_802C39F8.s +++ b/asm/nonmatchings/code_e79b0_len_1920/func_802C39F8.s @@ -149,69 +149,3 @@ glabel func_802C39F8 /* 0E85B4 802C3C04 8FB00010 */ lw $s0, 0x10($sp) /* 0E85B8 802C3C08 03E00008 */ jr $ra /* 0E85BC 802C3C0C 27BD0028 */ addiu $sp, $sp, 0x28 - -/* 0E85C0 802C3C10 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 0E85C4 802C3C14 AFB10014 */ sw $s1, 0x14($sp) -/* 0E85C8 802C3C18 0080882D */ daddu $s1, $a0, $zero -/* 0E85CC 802C3C1C AFBF0018 */ sw $ra, 0x18($sp) -/* 0E85D0 802C3C20 AFB00010 */ sw $s0, 0x10($sp) -/* 0E85D4 802C3C24 92220000 */ lbu $v0, ($s1) -/* 0E85D8 802C3C28 3C013F80 */ lui $at, 0x3f80 -/* 0E85DC 802C3C2C 44810000 */ mtc1 $at, $f0 -/* 0E85E0 802C3C30 8E240060 */ lw $a0, 0x60($s1) -/* 0E85E4 802C3C34 AE250008 */ sw $a1, 8($s1) -/* 0E85E8 802C3C38 AE25015C */ sw $a1, 0x15c($s1) -/* 0E85EC 802C3C3C AE250164 */ sw $a1, 0x164($s1) -/* 0E85F0 802C3C40 A2200002 */ sb $zero, 2($s1) -/* 0E85F4 802C3C44 AE200154 */ sw $zero, 0x154($s1) -/* 0E85F8 802C3C48 00461025 */ or $v0, $v0, $a2 -/* 0E85FC 802C3C4C A2220000 */ sb $v0, ($s1) -/* 0E8600 802C3C50 10800004 */ beqz $a0, .L802C3C64 -/* 0E8604 802C3C54 E6200150 */ swc1 $f0, 0x150($s1) -/* 0E8608 802C3C58 0C00AB4B */ jal heap_free -/* 0E860C 802C3C5C 00000000 */ nop -/* 0E8610 802C3C60 AE200060 */ sw $zero, 0x60($s1) -.L802C3C64: -/* 0E8614 802C3C64 8E240068 */ lw $a0, 0x68($s1) -/* 0E8618 802C3C68 10800003 */ beqz $a0, .L802C3C78 -/* 0E861C 802C3C6C 0000802D */ daddu $s0, $zero, $zero -/* 0E8620 802C3C70 0C0B0FCF */ jal kill_script -/* 0E8624 802C3C74 00000000 */ nop -.L802C3C78: -/* 0E8628 802C3C78 3C03802E */ lui $v1, 0x802e -/* 0E862C 802C3C7C 8C63A890 */ lw $v1, -0x5770($v1) -/* 0E8630 802C3C80 00101080 */ sll $v0, $s0, 2 -/* 0E8634 802C3C84 00431021 */ addu $v0, $v0, $v1 -/* 0E8638 802C3C88 8C440000 */ lw $a0, ($v0) -/* 0E863C 802C3C8C 10800006 */ beqz $a0, .L802C3CA8 -/* 0E8640 802C3C90 26100001 */ addiu $s0, $s0, 1 -/* 0E8644 802C3C94 8C82006C */ lw $v0, 0x6c($a0) -/* 0E8648 802C3C98 14510003 */ bne $v0, $s1, .L802C3CA8 -/* 0E864C 802C3C9C 00000000 */ nop -/* 0E8650 802C3CA0 0C0B0FCF */ jal kill_script -/* 0E8654 802C3CA4 00000000 */ nop -.L802C3CA8: -/* 0E8658 802C3CA8 2A020080 */ slti $v0, $s0, 0x80 -/* 0E865C 802C3CAC 1440FFF2 */ bnez $v0, .L802C3C78 -/* 0E8660 802C3CB0 2402FFFF */ addiu $v0, $zero, -1 -/* 0E8664 802C3CB4 A2220006 */ sb $v0, 6($s1) -/* 0E8668 802C3CB8 A2220007 */ sb $v0, 7($s1) -/* 0E866C 802C3CBC 3C01802E */ lui $at, 0x802e -/* 0E8670 802C3CC0 C4209CA8 */ lwc1 $f0, -0x6358($at) -/* 0E8674 802C3CC4 0220202D */ daddu $a0, $s1, $zero -/* 0E8678 802C3CC8 AE200064 */ sw $zero, 0x64($s1) -/* 0E867C 802C3CCC AE20006C */ sw $zero, 0x6c($s1) -/* 0E8680 802C3CD0 AE200068 */ sw $zero, 0x68($s1) -/* 0E8684 802C3CD4 AE200154 */ sw $zero, 0x154($s1) -/* 0E8688 802C3CD8 AE200158 */ sw $zero, 0x158($s1) -/* 0E868C 802C3CDC 0C0B0C52 */ jal find_script_labels -/* 0E8690 802C3CE0 E6200150 */ swc1 $f0, 0x150($s1) -/* 0E8694 802C3CE4 0C0B0CE4 */ jal func_802C3390 -/* 0E8698 802C3CE8 0220202D */ daddu $a0, $s1, $zero -/* 0E869C 802C3CEC 0220102D */ daddu $v0, $s1, $zero -/* 0E86A0 802C3CF0 8FBF0018 */ lw $ra, 0x18($sp) -/* 0E86A4 802C3CF4 8FB10014 */ lw $s1, 0x14($sp) -/* 0E86A8 802C3CF8 8FB00010 */ lw $s0, 0x10($sp) -/* 0E86AC 802C3CFC 03E00008 */ jr $ra -/* 0E86B0 802C3D00 27BD0020 */ addiu $sp, $sp, 0x20 - diff --git a/asm/nonmatchings/code_e79b0_len_1920/func_802C3C10.s b/asm/nonmatchings/code_e79b0_len_1920/func_802C3C10.s new file mode 100644 index 0000000000..de9bd3f500 --- /dev/null +++ b/asm/nonmatchings/code_e79b0_len_1920/func_802C3C10.s @@ -0,0 +1,69 @@ +.set noat # allow manual use of $at +.set noreorder # don't insert nops after branches + + +glabel func_802C3C10 +/* 0E85C0 802C3C10 27BDFFE0 */ addiu $sp, $sp, -0x20 +/* 0E85C4 802C3C14 AFB10014 */ sw $s1, 0x14($sp) +/* 0E85C8 802C3C18 0080882D */ daddu $s1, $a0, $zero +/* 0E85CC 802C3C1C AFBF0018 */ sw $ra, 0x18($sp) +/* 0E85D0 802C3C20 AFB00010 */ sw $s0, 0x10($sp) +/* 0E85D4 802C3C24 92220000 */ lbu $v0, ($s1) +/* 0E85D8 802C3C28 3C013F80 */ lui $at, 0x3f80 +/* 0E85DC 802C3C2C 44810000 */ mtc1 $at, $f0 +/* 0E85E0 802C3C30 8E240060 */ lw $a0, 0x60($s1) +/* 0E85E4 802C3C34 AE250008 */ sw $a1, 8($s1) +/* 0E85E8 802C3C38 AE25015C */ sw $a1, 0x15c($s1) +/* 0E85EC 802C3C3C AE250164 */ sw $a1, 0x164($s1) +/* 0E85F0 802C3C40 A2200002 */ sb $zero, 2($s1) +/* 0E85F4 802C3C44 AE200154 */ sw $zero, 0x154($s1) +/* 0E85F8 802C3C48 00461025 */ or $v0, $v0, $a2 +/* 0E85FC 802C3C4C A2220000 */ sb $v0, ($s1) +/* 0E8600 802C3C50 10800004 */ beqz $a0, .L802C3C64 +/* 0E8604 802C3C54 E6200150 */ swc1 $f0, 0x150($s1) +/* 0E8608 802C3C58 0C00AB4B */ jal heap_free +/* 0E860C 802C3C5C 00000000 */ nop +/* 0E8610 802C3C60 AE200060 */ sw $zero, 0x60($s1) +.L802C3C64: +/* 0E8614 802C3C64 8E240068 */ lw $a0, 0x68($s1) +/* 0E8618 802C3C68 10800003 */ beqz $a0, .L802C3C78 +/* 0E861C 802C3C6C 0000802D */ daddu $s0, $zero, $zero +/* 0E8620 802C3C70 0C0B0FCF */ jal kill_script +/* 0E8624 802C3C74 00000000 */ nop +.L802C3C78: +/* 0E8628 802C3C78 3C03802E */ lui $v1, 0x802e +/* 0E862C 802C3C7C 8C63A890 */ lw $v1, -0x5770($v1) +/* 0E8630 802C3C80 00101080 */ sll $v0, $s0, 2 +/* 0E8634 802C3C84 00431021 */ addu $v0, $v0, $v1 +/* 0E8638 802C3C88 8C440000 */ lw $a0, ($v0) +/* 0E863C 802C3C8C 10800006 */ beqz $a0, .L802C3CA8 +/* 0E8640 802C3C90 26100001 */ addiu $s0, $s0, 1 +/* 0E8644 802C3C94 8C82006C */ lw $v0, 0x6c($a0) +/* 0E8648 802C3C98 14510003 */ bne $v0, $s1, .L802C3CA8 +/* 0E864C 802C3C9C 00000000 */ nop +/* 0E8650 802C3CA0 0C0B0FCF */ jal kill_script +/* 0E8654 802C3CA4 00000000 */ nop +.L802C3CA8: +/* 0E8658 802C3CA8 2A020080 */ slti $v0, $s0, 0x80 +/* 0E865C 802C3CAC 1440FFF2 */ bnez $v0, .L802C3C78 +/* 0E8660 802C3CB0 2402FFFF */ addiu $v0, $zero, -1 +/* 0E8664 802C3CB4 A2220006 */ sb $v0, 6($s1) +/* 0E8668 802C3CB8 A2220007 */ sb $v0, 7($s1) +/* 0E866C 802C3CBC 3C01802E */ lui $at, 0x802e +/* 0E8670 802C3CC0 C4209CA8 */ lwc1 $f0, -0x6358($at) +/* 0E8674 802C3CC4 0220202D */ daddu $a0, $s1, $zero +/* 0E8678 802C3CC8 AE200064 */ sw $zero, 0x64($s1) +/* 0E867C 802C3CCC AE20006C */ sw $zero, 0x6c($s1) +/* 0E8680 802C3CD0 AE200068 */ sw $zero, 0x68($s1) +/* 0E8684 802C3CD4 AE200154 */ sw $zero, 0x154($s1) +/* 0E8688 802C3CD8 AE200158 */ sw $zero, 0x158($s1) +/* 0E868C 802C3CDC 0C0B0C52 */ jal find_script_labels +/* 0E8690 802C3CE0 E6200150 */ swc1 $f0, 0x150($s1) +/* 0E8694 802C3CE4 0C0B0CE4 */ jal func_802C3390 +/* 0E8698 802C3CE8 0220202D */ daddu $a0, $s1, $zero +/* 0E869C 802C3CEC 0220102D */ daddu $v0, $s1, $zero +/* 0E86A0 802C3CF0 8FBF0018 */ lw $ra, 0x18($sp) +/* 0E86A4 802C3CF4 8FB10014 */ lw $s1, 0x14($sp) +/* 0E86A8 802C3CF8 8FB00010 */ lw $s0, 0x10($sp) +/* 0E86AC 802C3CFC 03E00008 */ jr $ra +/* 0E86B0 802C3D00 27BD0020 */ addiu $sp, $sp, 0x20 \ No newline at end of file diff --git a/asm/nonmatchings/code_f8f60_len_1560/func_802D4BDC.s b/asm/nonmatchings/code_f8f60_len_1560/func_802D4BDC.s deleted file mode 100644 index a8eb3a2bae..0000000000 --- a/asm/nonmatchings/code_f8f60_len_1560/func_802D4BDC.s +++ /dev/null @@ -1,38 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel func_802D4BDC -/* 0F958C 802D4BDC 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0F9590 802D4BE0 AFBF0010 */ sw $ra, 0x10($sp) -/* 0F9594 802D4BE4 10A00003 */ beqz $a1, .L802D4BF4 -/* 0F9598 802D4BE8 0080182D */ daddu $v1, $a0, $zero -/* 0F959C 802D4BEC AC600070 */ sw $zero, 0x70($v1) -/* 0F95A0 802D4BF0 AC600074 */ sw $zero, 0x74($v1) -.L802D4BF4: -/* 0F95A4 802D4BF4 8C620070 */ lw $v0, 0x70($v1) -/* 0F95A8 802D4BF8 14400011 */ bnez $v0, .L802D4C40 -/* 0F95AC 802D4BFC 0000102D */ daddu $v0, $zero, $zero -/* 0F95B0 802D4C00 8C620074 */ lw $v0, 0x74($v1) -/* 0F95B4 802D4C04 240400FF */ addiu $a0, $zero, 0xff -/* 0F95B8 802D4C08 14440003 */ bne $v0, $a0, .L802D4C18 -/* 0F95BC 802D4C0C 2442000A */ addiu $v0, $v0, 0xa -/* 0F95C0 802D4C10 080B5310 */ j .L802D4C40 -/* 0F95C4 802D4C14 24020002 */ addiu $v0, $zero, 2 - -.L802D4C18: -/* 0F95C8 802D4C18 AC620074 */ sw $v0, 0x74($v1) -/* 0F95CC 802D4C1C 28420100 */ slti $v0, $v0, 0x100 -/* 0F95D0 802D4C20 50400001 */ beql $v0, $zero, .L802D4C28 -/* 0F95D4 802D4C24 AC640074 */ sw $a0, 0x74($v1) -.L802D4C28: -/* 0F95D8 802D4C28 C4600074 */ lwc1 $f0, 0x74($v1) -/* 0F95DC 802D4C2C 46800020 */ cvt.s.w $f0, $f0 -/* 0F95E0 802D4C30 44050000 */ mfc1 $a1, $f0 -/* 0F95E4 802D4C34 0C04DF69 */ jal func_80137DA4 -/* 0F95E8 802D4C38 2404000A */ addiu $a0, $zero, 0xa -/* 0F95EC 802D4C3C 0000102D */ daddu $v0, $zero, $zero -.L802D4C40: -/* 0F95F0 802D4C40 8FBF0010 */ lw $ra, 0x10($sp) -/* 0F95F4 802D4C44 03E00008 */ jr $ra -/* 0F95F8 802D4C48 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/nonmatchings/code_f8f60_len_1560/func_802D4C4C.s b/asm/nonmatchings/code_f8f60_len_1560/func_802D4C4C.s deleted file mode 100644 index bf28e2dd04..0000000000 --- a/asm/nonmatchings/code_f8f60_len_1560/func_802D4C4C.s +++ /dev/null @@ -1,40 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel func_802D4C4C -/* 0F95FC 802D4C4C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0F9600 802D4C50 AFBF0010 */ sw $ra, 0x10($sp) -/* 0F9604 802D4C54 10A00004 */ beqz $a1, .L802D4C68 -/* 0F9608 802D4C58 0080182D */ daddu $v1, $a0, $zero -/* 0F960C 802D4C5C 240200FF */ addiu $v0, $zero, 0xff -/* 0F9610 802D4C60 AC600070 */ sw $zero, 0x70($v1) -/* 0F9614 802D4C64 AC620074 */ sw $v0, 0x74($v1) -.L802D4C68: -/* 0F9618 802D4C68 8C620070 */ lw $v0, 0x70($v1) -/* 0F961C 802D4C6C 14400012 */ bnez $v0, .L802D4CB8 -/* 0F9620 802D4C70 0000102D */ daddu $v0, $zero, $zero -/* 0F9624 802D4C74 8C620074 */ lw $v0, 0x74($v1) -/* 0F9628 802D4C78 14400006 */ bnez $v0, .L802D4C94 -/* 0F962C 802D4C7C 2442FFF6 */ addiu $v0, $v0, -0xa -/* 0F9630 802D4C80 3C05BF80 */ lui $a1, 0xbf80 -/* 0F9634 802D4C84 0C04DF69 */ jal func_80137DA4 -/* 0F9638 802D4C88 240400FF */ addiu $a0, $zero, 0xff -/* 0F963C 802D4C8C 080B532E */ j .L802D4CB8 -/* 0F9640 802D4C90 24020002 */ addiu $v0, $zero, 2 - -.L802D4C94: -/* 0F9644 802D4C94 04410002 */ bgez $v0, .L802D4CA0 -/* 0F9648 802D4C98 AC620074 */ sw $v0, 0x74($v1) -/* 0F964C 802D4C9C AC600074 */ sw $zero, 0x74($v1) -.L802D4CA0: -/* 0F9650 802D4CA0 C4600074 */ lwc1 $f0, 0x74($v1) -/* 0F9654 802D4CA4 46800020 */ cvt.s.w $f0, $f0 -/* 0F9658 802D4CA8 44050000 */ mfc1 $a1, $f0 -/* 0F965C 802D4CAC 0C04DF69 */ jal func_80137DA4 -/* 0F9660 802D4CB0 2404000A */ addiu $a0, $zero, 0xa -/* 0F9664 802D4CB4 0000102D */ daddu $v0, $zero, $zero -.L802D4CB8: -/* 0F9668 802D4CB8 8FBF0010 */ lw $ra, 0x10($sp) -/* 0F966C 802D4CBC 03E00008 */ jr $ra -/* 0F9670 802D4CC0 27BD0018 */ addiu $sp, $sp, 0x18 \ No newline at end of file diff --git a/include/common_structs.h b/include/common_structs.h index df735d4d15..f84e23917c 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -230,7 +230,7 @@ typedef struct ScriptInstance { /* 0x002 */ u8 currentOpcode; /* 0x003 */ u8 priority; /* 0x004 */ u8 groupFlags; - /* 0x005 */ u8 blocked; /* 1 = blocking */ + /* 0x005 */ s8 blocked; /* 1 = blocking */ /* 0x006 */ s8 loopDepth; /* how many nested loops we are in, >= 8 hangs forever */ /* 0x007 */ s8 switchDepth; /* how many nested switches we are in, max = 8 */ /* 0x008 */ Bytecode* ptrNextLine; @@ -1353,7 +1353,8 @@ typedef struct PlayerStatus { /* 0x0BE */ u8 renderMode; /* 0x0BF */ char unk_BF; /* 0x0C0 */ u32* decorationList; - /* 0x0C4 */ char unk_C4[8]; + /* 0x0C4 */ char unk_C4[4]; + /* 0x0C8 */ UNK_PTR unk_C8; /* 0x0CC */ s32 shadowID; /* 0x0D0 */ char unk_D0[12]; /* 0x0DC */ s32 currentButtons; diff --git a/include/variables.h b/include/variables.h index 2c39320eb9..a33454c454 100644 --- a/include/variables.h +++ b/include/variables.h @@ -51,8 +51,8 @@ extern s16 D_8010CD12; extern s32 D_801595A0; extern char gCloudyFlowerFieldsBg[]; // "fla_bg" extern char gSunnyFlowerFieldsBg[]; // "flb_bg" -extern BackgroundHeader gBackgroundImage; extern s8 D_8014F12F; +extern BackgroundHeader gBackgroundImage; extern PrintContext* gCurrentPrintContext; extern PrintContext* D_802DB268; diff --git a/src/code_dc470_len_14c0.c b/src/code_dc470_len_14c0.c index fd520fcead..75edbd0903 100644 --- a/src/code_dc470_len_14c0.c +++ b/src/code_dc470_len_14c0.c @@ -11,7 +11,6 @@ void load_map_bg(char* 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; } @@ -56,7 +55,7 @@ void set_background_size(s16 startX, s16 startY, s16 sizeX, s16 sizeY) { u16 func_80145E98(s32 arg0, s32 arg1, s32 arg2) { s32 temp_lo; - temp_lo = (arg1 - (u16)(arg0)) * arg2; + temp_lo = (arg1 - (u16)arg0) * arg2; if (temp_lo < 0) { temp_lo = temp_lo + 0xFF; } @@ -65,3 +64,13 @@ u16 func_80145E98(s32 arg0, s32 arg1, s32 arg2) { } INCLUDE_ASM("code_dc470_len_14c0", func_80145EC0); + +INCLUDE_ASM("code_dc470_len_14c0", func_8014720C); +/*void func_8014720C(void) { + D_8014F12F = 1; +}*/ + +INCLUDE_ASM("code_dc470_len_14c0", func_8014721C); +/*void func_8014721C(void) { + D_8014F12F = 0; +}*/ diff --git a/src/code_dd930_len_1c0.c b/src/code_dd930_len_1c0.c index f69c288ec2..002e79c6b2 100644 --- a/src/code_dd930_len_1c0.c +++ b/src/code_dd930_len_1c0.c @@ -1,10 +1,11 @@ #include "common.h" +// TODO: most likely part of the MusicPlayer struct typedef struct { - s16 unk0; - s16 unk2; - s32 unk4; - s32 unk8; + s16 flags; + s16 state; + s32 fadeOutTime; + s32 fadeInTime; s32 unkC; } struct_80147230; @@ -18,58 +19,58 @@ void func_80147230(void) { void update_music_players(void) { struct_80147230* temp = &D_8015C7C0; - switch (temp->unk2) { - case 0: + switch (temp->state) { + case 0: // idle break; - case 1: - if (temp->unk0 & 1) { + case 1: // fading in + if (temp->flags & 1) { s32 phi_v0; - if (temp->unk4 < 0xFA) { - phi_v0 = func_800554A4(0, temp->unk4); + if (temp->fadeOutTime < 0xFA) { + phi_v0 = func_800554A4(0, temp->fadeOutTime); } else { - phi_v0 = func_800554E8(0, temp->unk4); + phi_v0 = func_800554E8(0, temp->fadeOutTime); } if (phi_v0 != 0) { return; } } - temp->unk2 = 2; + temp->state = 2; break; - case 2: - if (temp->unk0 & 1) { + case 2: // fading out + if (temp->flags & 1) { if (func_800555E4(0) != 0) { return; } - temp->unk0 &= ~1; + temp->flags &= ~1; } - if (temp->unk8 < 0) { - temp->unk2 = 0; - } else if (func_80055448(temp->unk8) == 0) { + if (temp->fadeInTime < 0) { + temp->state = 0; + } else if (func_80055448(temp->fadeInTime) == 0) { if (func_80055464(0, 0) == 0) { - temp->unk2 = 0; - temp->unk0 |= 1; + temp->state = 0; + temp->flags |= 1; } } break; } } -s32 play_ambient_sounds(s32 arg0, s32 arg1) { +s32 play_ambient_sounds(s32 fadeInTime, s32 fadeOutTime) { struct_80147230* temp1 = &D_8015C7C0; struct_80147230* temp2 = &D_8015C7C0; - if ((*gGameStatusPtr)->musicEnabled == 0) { - func_800554A4(temp1->unk8, arg1); - temp1->unk0 &= ~1; + if (!(*gGameStatusPtr)->musicEnabled) { + func_800554A4(temp1->fadeInTime, fadeOutTime); + temp1->flags &= ~1; return 1; } - if (temp1->unk8 == arg0) { + if (temp1->fadeInTime == fadeInTime) { return 2; } - temp2->unk8 = arg0; - temp2->unk4 = arg1; - temp2->unk2 = 1; + temp2->fadeInTime = fadeInTime; + temp2->fadeOutTime = fadeOutTime; + temp2->state = 1; return 1; } diff --git a/src/code_e79b0_len_1920.c b/src/code_e79b0_len_1920.c index ec1e500f73..567518e8a6 100644 --- a/src/code_e79b0_len_1920.c +++ b/src/code_e79b0_len_1920.c @@ -16,20 +16,100 @@ INCLUDE_ASM("code_e79b0_len_1920", start_script_in_group); INCLUDE_ASM("code_e79b0_len_1920", start_child_script); -INCLUDE_ASM("code_e79b0_len_1920", func_802C39F8); +//INCLUDE_ASM("code_e79b0_len_1920", func_802C39F8); + +extern s32 gStaticScriptCounter; +extern s32 D_802D9CA4; +extern s32 gNumScripts; +extern s32 D_802DAC98; + +//INCLUDE_ASM(code_e79b0_len_1920, func_802C39F8); +ScriptInstance* func_802C39F8(ScriptInstance* parentScript, Bytecode* nextLine, s32 newState) { + ScriptInstance** curScript = gCurrentScriptListPtr; + ScriptInstance* child; + ScriptInstance** temp3; + s32* temp6; + s32 temp2; + s32 temp7; + s32 i; + + for(i = 0; i < ARRAY_COUNT(gCurrentScriptListPtr); i++){ + if (curScript[i] == NULL) { + break; + } + } + + temp3 = gCurrentScriptListPtr; + ASSERT(i < ARRAY_COUNT(gCurrentScriptListPtr)); + temp2 = i; + + child = heap_malloc(sizeof(ScriptInstance)); + temp3[temp2] = child; + temp7 = gNumScripts++; + ASSERT(child != NULL); + + child->state = newState | 1; + child->ptrNextLine = nextLine; + child->ptrFirstLine = nextLine; + child->ptrCurrentLine = nextLine; + child->currentOpcode = 0; + child->deleted = 0; + child->blockingParent = NULL; + child->parentScript = parentScript; + child->childScript = NULL; + child->priority = parentScript->priority; + child->uniqueID = gStaticScriptCounter++; + child->ownerActorID = parentScript->ownerActorID; + child->ownerID = parentScript->ownerID; + child->loopDepth = -1; + child->switchDepth = -1; + child->groupFlags = parentScript->groupFlags; + child->ptrSavedPosition = NULL; + child->array = parentScript->array; + child->flagArray = parentScript->flagArray; + child->timeScale = gGlobalTimeSpace; + child->frameCounter = 0; + child->unk_158 = 0; + + for(i = 0; i < ARRAY_COUNT(child->varTable); i++) { + child->varTable[i] = parentScript->varTable[i]; + } + + for(i = 0; i < ARRAY_COUNT(child->varFlags); i++){ + child->varFlags[i] = parentScript->varFlags[i]; + } + + find_script_labels(child); + if (D_802D9CA4 != 0) { + temp7 = D_802DAC98++; + gScriptIndexList[temp7] = temp2; + gScriptIdList[temp7] = child->uniqueID; + } + + temp6 = &gStaticScriptCounter; + if (*temp6 == 0) { + *temp6 = 1; + } + func_802C3390(child); + return child; +} + +INCLUDE_ASM(code_e79b0_len_1920, func_802C3C10) -#ifdef NON_MATCHING ScriptInstance* restart_script(ScriptInstance* script) { + Bytecode* temp; script->loopDepth = -1; script->switchDepth = -1; script->currentOpcode = 0; - script->frameCounter = 0; // TODO: force compiler to not optimise away this + script->frameCounter = 0; + + temp = script->ptrFirstLine; + script->ptrNextLine = temp; + script->ptrCurrentLine = temp; + script->timeScale = 1.0f; script->frameCounter = 0; script->unk_158 = 0; - script->ptrNextLine = script->ptrFirstLine; - script->ptrCurrentLine = script->ptrFirstLine; - script->timeScale = 1.0f; script->timeScale = gGlobalTimeSpace; @@ -38,9 +118,6 @@ ScriptInstance* restart_script(ScriptInstance* script) { return script; } -#else -INCLUDE_ASM("code_e79b0_len_1920", restart_script); -#endif INCLUDE_ASM("code_e79b0_len_1920", update_scripts); @@ -107,7 +184,7 @@ void set_script_timescale(ScriptInstance* script, f32 timescale) { #ifdef NON_MATCHING // TODO: figure out why compiler/assembler isn't putting SWC1 in delay slot void set_global_timespace(f32 timeScale) { - //gGlobalTimeSpace = timeScale; + gGlobalTimeSpace = timeScale; } #else INCLUDE_ASM("code_e79b0_len_1920", set_global_timespace); @@ -116,7 +193,7 @@ INCLUDE_ASM("code_e79b0_len_1920", set_global_timespace); #ifdef NON_MATCHING // TODO: figure out why compiler/assembler isn't putting LWC1 in delay slot f32 get_global_timespace(void) { - //return gGlobalTimeSpace; + return gGlobalTimeSpace; } #else INCLUDE_ASM("code_e79b0_len_1920", get_global_timespace); diff --git a/src/code_f8f60_len_1560.c b/src/code_f8f60_len_1560.c index 04dba50abc..db765476c6 100644 --- a/src/code_f8f60_len_1560.c +++ b/src/code_f8f60_len_1560.c @@ -188,8 +188,6 @@ ApiStatus AddVectorPolar(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -INCLUDE_API_ASM("code_f8f60_len_1560", func_802D4BDC); -/* ApiStatus func_802D4BDC(ScriptInstance* script, s32 initialCall) { s32* t0 = &script->functionTemp[0]; s32* t1 = &script->functionTemp[1]; @@ -202,32 +200,55 @@ ApiStatus func_802D4BDC(ScriptInstance* script, s32 initialCall) { if (*t0 == 0) { t1v = *t1; - if (t1v != 0xFF) { - t1v += 0xA; - *t1 = t1v; - if (t1v < 0x100) { - // Void, debug stuff was probably here - } - t1v = 0xFF; - func_80137DA4(0xA, (f32) *t1); - } else { + if (t1v == 255) { return ApiStatus_DONE2; } + + t1v += 10; + *t1 = t1v; + if (t1v > 255) { + *t1 = 255; + } + + func_80137DA4(10, *t1); } - return 0; + return ApiStatus_BLOCK; } -*/ -// Very similar to func_802D4BDC -INCLUDE_API_ASM("code_f8f60_len_1560", func_802D4C4C); +ApiStatus func_802D4C4C(ScriptInstance* script, s32 initialCall) { + s32* t0 = &script->functionTemp[0]; + s32* t1 = &script->functionTemp[1]; + s32 t1v; + + if (initialCall) { + *t0 = 0; + *t1 = 255; + } + + if (*t0 == 0) { + t1v = *t1; + if (t1v == 0) { + func_80137DA4(255, -1.0f); + return ApiStatus_DONE2; + } + t1v -= 10; + *t1 = t1v; + if(t1v < 0) { + *t1 = 0; + } + func_80137DA4(10, *t1); + } + + return ApiStatus_BLOCK; +} ApiStatus func_802D4CC4(ScriptInstance* script, s32 initialCall) { s32 value = get_variable(script, *script->ptrReadPos); if (value < 0) { - func_80137DA4(0xFF, -1.0f); + func_80137DA4(255, -1.0f); } else { - func_80137DA4(0xA, value); + func_80137DA4(10, value); } return ApiStatus_DONE2; @@ -249,6 +270,67 @@ ApiStatus func_802D4D88(ScriptInstance* script, s32 initialCall) { } INCLUDE_ASM("code_f8f60_len_1560", setup_path_data); +/*void setup_path_data(s32 numVecs, f32* arg1, struct Vec3f* arg2, struct Vec3f* arg3) { + struct Vec3f *temp_s4; + f32 *temp_s7; + s32 i; + + temp_s7 = heap_malloc(numVecs * sizeof(f32)); + temp_s4 = heap_malloc(numVecs * sizeof(Vec3f)); + arg1[0] = 0.0f; + + for (i = 1; i < numVecs; i++) { + arg1[i] = (arg1[i - 1] + sqrtf(SQ(arg2[i].x - arg2[i - 1].x) + SQ(arg2[i].y - arg2[i - 1].y) + SQ(arg2[i].z - arg2[i - 1].z))); + } + + for (i = 1; i < numVecs; i++) { + arg1[i] = arg1[i] / arg1[numVecs - 1]; + } + + arg3[0].x = 0; + arg3[0].y = 0; + arg3[0].z = 0; + + arg3[numVecs - 1].x = 0; + arg3[numVecs - 1].y = 0; + arg3[numVecs - 1].z = 0; + + for (i = 0; i < (numVecs - 1); i++) { + temp_s7[i] = arg1[i + 1] - arg1[i]; + temp_s4[i + 1].x = ((arg2[i + 1].x - arg2[i].x) / temp_s7[i]); + temp_s4[i + 1].y = ((arg2[i + 1].y - arg2[i].y) / temp_s7[i]); + temp_s4[i + 1].z = ((arg2[i + 1].z - arg2[i].z) / temp_s7[i]); + } + + arg3[0].x = temp_s4[2].x - temp_s4[1].x; + arg3[0].y = temp_s4[2].y - temp_s4[1].y; + arg3[0].z = temp_s4[2].z - temp_s4[1].z; + temp_s4[1].x = ((arg1[2] - arg1[0]) * 2); + temp_s4[1].y = ((arg1[2] - arg1[0]) * 2); + temp_s4[1].z = ((arg1[2] - arg1[0]) * 2); + + for (i = 1; i < numVecs - 2; i++) { + arg3[i + 1].x = (temp_s4[i + 2].x - temp_s4[i].x) - (arg3[i].x * (temp_s7[i] / temp_s4[i].x)); + arg3[i + 1].y = (temp_s4[i + 2].y - temp_s4[i].y) - (arg3[i].y * (temp_s7[i] / temp_s4[i].y)); + arg3[i + 1].z = (temp_s4[i + 2].z - temp_s4[i].z) - (arg3[i].z * (temp_s7[i] / temp_s4[i].z)); + temp_s4[i].x = ((arg1[i + 2] - arg1[i]) * 2) - (temp_s7[i] * (temp_s7[i] / temp_s4[i].x)); + temp_s4[i].y = ((arg1[i + 2] - arg1[i]) * 2) - (temp_s7[i] * (temp_s7[i] / temp_s4[i].y)); + temp_s4[i].z = ((arg1[i + 2] - arg1[i]) * 2) - (temp_s7[i] * (temp_s7[i] / temp_s4[i].z)); + } + + arg3[numVecs - 2].x = arg3[numVecs - 2].x - (temp_s7[numVecs - 2] * arg3[numVecs - 1].x); + arg3[numVecs - 2].y = arg3[numVecs - 2].y - (temp_s7[numVecs - 2] * arg3[numVecs - 1].y); + arg3[numVecs - 2].z = arg3[numVecs - 2].z - (temp_s7[numVecs - 2] * arg3[numVecs - 1].z); + + for(i = (numVecs - 2); i > 0; i--) { + arg3[i].x = (arg3[i].x - (temp_s7[0] * arg3[i].x)) / temp_s4[i].x; + arg3[i].y = (arg3[i].y - (temp_s7[0] * arg3[i].y)) / temp_s4[i].y; + arg3[i].z = (arg3[i].z - (temp_s7[0] * arg3[i].z)) / temp_s4[i].z; + } + + heap_free(temp_s7); + heap_free(temp_s4); +}*/ INCLUDE_ASM("code_f8f60_len_1560", func_802D5270); @@ -334,10 +416,10 @@ ApiStatus ShowStatusMenu(ScriptInstance* script, s32 isInitialCall) { } ApiStatus SetGameMode(ScriptInstance* script, s32 isInitialCall) { - set_game_mode( - // Clear upper half - (get_variable(script, *script->ptrReadPos) << 0x10) >> 0x10 - ); + s16 mode = get_variable(script, *script->ptrReadPos); + + set_game_mode(mode); + return ApiStatus_DONE2; } diff --git a/undefined_syms.txt b/undefined_syms.txt index 0d342669f7..6f42547761 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -5,7 +5,11 @@ gPlayerStatus = 0x8010EFC8; gItemTable = 0x800878E0; gWorldScriptList = 0x802DA490; gBattleScriptList = 0x802DA690; +gNumScripts = 0x802DA488; gCurrentScriptListPtr = 0x802DA890; +D_802DAC98 = 0x802DAC98; +gStaticScriptCounter = 0x802D9CA0; +D_802D9CA4 = 0x802D9CA4; gGlobalTimeSpace = 0x802D9CA8; D_80147574 = 0x80147574; @@ -60,8 +64,8 @@ D_00316D90 = 0x00316D90; D_00316F30 = 0x00316F30; D_8010D000 = 0x8010D000; -gCloudyFlowerFieldsBg = 0x8014F120; -gSunnyFlowerFieldsBg = 0x8014F128; +gCloudyFlowerFieldsBg = 0x8014F120; +gSunnyFlowerFieldsBg = 0x8014F128; D_8014F12F = 0x8014F12F; D_8014F140 = 0x8014F140; D_80151308 = 0x80151308;