From 7bc578801eef4e55a4cd5aaec5e27299f7e16ead Mon Sep 17 00:00:00 2001 From: dark-samus Date: Sat, 18 Jul 2020 17:26:22 -0400 Subject: [PATCH 1/2] match DemoJoystickRadial and DemoJoystickXY --- .../code_fe0b0_len_5a0/DemoJoystickRadial.s | 51 ------------------ .../asm/code_fe0b0_len_5a0/DemoJoystickXY.s | 41 -------------- papermario/include/common_structs.h | 4 +- papermario/src/code_fe0b0_len_5a0.c | 53 ++++++++----------- 4 files changed, 24 insertions(+), 125 deletions(-) delete mode 100644 papermario/asm/code_fe0b0_len_5a0/DemoJoystickRadial.s delete mode 100644 papermario/asm/code_fe0b0_len_5a0/DemoJoystickXY.s diff --git a/papermario/asm/code_fe0b0_len_5a0/DemoJoystickRadial.s b/papermario/asm/code_fe0b0_len_5a0/DemoJoystickRadial.s deleted file mode 100644 index dd006d2a4e..0000000000 --- a/papermario/asm/code_fe0b0_len_5a0/DemoJoystickRadial.s +++ /dev/null @@ -1,51 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -.include "globals.inc" - -DemoJoystickRadial: -/* 0FE514 802D9B64 27BDFFD0 */ addiu $sp, $sp, -0x30 -/* 0FE518 802D9B68 AFB10014 */ sw $s1, 0x14($sp) -/* 0FE51C 802D9B6C 0080882D */ daddu $s1, $a0, $zero -/* 0FE520 802D9B70 AFBF0018 */ sw $ra, 0x18($sp) -/* 0FE524 802D9B74 AFB00010 */ sw $s0, 0x10($sp) -/* 0FE528 802D9B78 F7B60028 */ sdc1 $f22, 0x28($sp) -/* 0FE52C 802D9B7C F7B40020 */ sdc1 $f20, 0x20($sp) -/* 0FE530 802D9B80 8E30000C */ lw $s0, 0xc($s1) -/* 0FE534 802D9B84 8E050000 */ lw $a1, ($s0) -/* 0FE538 802D9B88 0C0B210B */ jal get_float_variable -/* 0FE53C 802D9B8C 26100004 */ addiu $s0, $s0, 4 -/* 0FE540 802D9B90 0220202D */ daddu $a0, $s1, $zero -/* 0FE544 802D9B94 8E050000 */ lw $a1, ($s0) -/* 0FE548 802D9B98 0C0B210B */ jal get_float_variable -/* 0FE54C 802D9B9C 46000586 */ mov.s $f22, $f0 -/* 0FE550 802D9BA0 46000506 */ mov.s $f20, $f0 -/* 0FE554 802D9BA4 0C00A8BB */ jal sin_deg -/* 0FE558 802D9BA8 4600A306 */ mov.s $f12, $f20 -/* 0FE55C 802D9BAC 4600B002 */ mul.s $f0, $f22, $f0 -/* 0FE560 802D9BB0 00000000 */ nop -/* 0FE564 802D9BB4 4600A306 */ mov.s $f12, $f20 -/* 0FE568 802D9BB8 3C108007 */ lui $s0, 0x8007 -/* 0FE56C 802D9BBC 2610419C */ addiu $s0, $s0, 0x419c -/* 0FE570 802D9BC0 8E030000 */ lw $v1, ($s0) -/* 0FE574 802D9BC4 4600008D */ trunc.w.s $f2, $f0 -/* 0FE578 802D9BC8 44021000 */ mfc1 $v0, $f2 -/* 0FE57C 802D9BCC 0C00A8D4 */ jal cos_deg -/* 0FE580 802D9BD0 A062006A */ sb $v0, 0x6a($v1) -/* 0FE584 802D9BD4 4600B582 */ mul.s $f22, $f22, $f0 -/* 0FE588 802D9BD8 00000000 */ nop -/* 0FE58C 802D9BDC 8E030000 */ lw $v1, ($s0) -/* 0FE590 802D9BE0 4600B08D */ trunc.w.s $f2, $f22 -/* 0FE594 802D9BE4 44021000 */ mfc1 $v0, $f2 -/* 0FE598 802D9BE8 00000000 */ nop -/* 0FE59C 802D9BEC A062006B */ sb $v0, 0x6b($v1) -/* 0FE5A0 802D9BF0 8FBF0018 */ lw $ra, 0x18($sp) -/* 0FE5A4 802D9BF4 8FB10014 */ lw $s1, 0x14($sp) -/* 0FE5A8 802D9BF8 8FB00010 */ lw $s0, 0x10($sp) -/* 0FE5AC 802D9BFC D7B60028 */ ldc1 $f22, 0x28($sp) -/* 0FE5B0 802D9C00 D7B40020 */ ldc1 $f20, 0x20($sp) -/* 0FE5B4 802D9C04 24020002 */ addiu $v0, $zero, 2 -/* 0FE5B8 802D9C08 03E00008 */ jr $ra -/* 0FE5BC 802D9C0C 27BD0030 */ addiu $sp, $sp, 0x30 - -.set reorder diff --git a/papermario/asm/code_fe0b0_len_5a0/DemoJoystickXY.s b/papermario/asm/code_fe0b0_len_5a0/DemoJoystickXY.s deleted file mode 100644 index bbc4f41efb..0000000000 --- a/papermario/asm/code_fe0b0_len_5a0/DemoJoystickXY.s +++ /dev/null @@ -1,41 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -.include "globals.inc" - -DemoJoystickXY: -/* 0FE5C0 802D9C10 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 0FE5C4 802D9C14 AFB10014 */ sw $s1, 0x14($sp) -/* 0FE5C8 802D9C18 0080882D */ daddu $s1, $a0, $zero -/* 0FE5CC 802D9C1C AFBF0018 */ sw $ra, 0x18($sp) -/* 0FE5D0 802D9C20 AFB00010 */ sw $s0, 0x10($sp) -/* 0FE5D4 802D9C24 F7B40020 */ sdc1 $f20, 0x20($sp) -/* 0FE5D8 802D9C28 8E30000C */ lw $s0, 0xc($s1) -/* 0FE5DC 802D9C2C 8E050000 */ lw $a1, ($s0) -/* 0FE5E0 802D9C30 0C0B210B */ jal get_float_variable -/* 0FE5E4 802D9C34 26100004 */ addiu $s0, $s0, 4 -/* 0FE5E8 802D9C38 0220202D */ daddu $a0, $s1, $zero -/* 0FE5EC 802D9C3C 8E050000 */ lw $a1, ($s0) -/* 0FE5F0 802D9C40 0C0B210B */ jal get_float_variable -/* 0FE5F4 802D9C44 46000506 */ mov.s $f20, $f0 -/* 0FE5F8 802D9C48 3C048007 */ lui $a0, 0x8007 -/* 0FE5FC 802D9C4C 2484419C */ addiu $a0, $a0, 0x419c -/* 0FE600 802D9C50 8C830000 */ lw $v1, ($a0) -/* 0FE604 802D9C54 4600A08D */ trunc.w.s $f2, $f20 -/* 0FE608 802D9C58 44021000 */ mfc1 $v0, $f2 -/* 0FE60C 802D9C5C 00000000 */ nop -/* 0FE610 802D9C60 A062006A */ sb $v0, 0x6a($v1) -/* 0FE614 802D9C64 8C830000 */ lw $v1, ($a0) -/* 0FE618 802D9C68 4600008D */ trunc.w.s $f2, $f0 -/* 0FE61C 802D9C6C 44021000 */ mfc1 $v0, $f2 -/* 0FE620 802D9C70 00000000 */ nop -/* 0FE624 802D9C74 A062006B */ sb $v0, 0x6b($v1) -/* 0FE628 802D9C78 8FBF0018 */ lw $ra, 0x18($sp) -/* 0FE62C 802D9C7C 8FB10014 */ lw $s1, 0x14($sp) -/* 0FE630 802D9C80 8FB00010 */ lw $s0, 0x10($sp) -/* 0FE634 802D9C84 D7B40020 */ ldc1 $f20, 0x20($sp) -/* 0FE638 802D9C88 24020002 */ addiu $v0, $zero, 2 -/* 0FE63C 802D9C8C 03E00008 */ jr $ra -/* 0FE640 802D9C90 27BD0028 */ addiu $sp, $sp, 0x28 - -.set reorder diff --git a/papermario/include/common_structs.h b/papermario/include/common_structs.h index 8b50f45e2f..ebba118170 100644 --- a/papermario/include/common_structs.h +++ b/papermario/include/common_structs.h @@ -6,8 +6,8 @@ typedef struct { /* 0x00 */ char unk_00[0x68]; /* 0x68 */ u16 demoButtonInput; - /* 0x6A */ u8 demoStickX; - /* 0x6B */ u8 demoStickY; + /* 0x6A */ s8 demoStickX; + /* 0x6B */ s8 demoStickY; /* 0x6C */ char unk_6C[0x5]; /* 0x71 */ s8 demoState; } game_status; diff --git a/papermario/src/code_fe0b0_len_5a0.c b/papermario/src/code_fe0b0_len_5a0.c index a0e92d9295..d9cdd65678 100644 --- a/papermario/src/code_fe0b0_len_5a0.c +++ b/papermario/src/code_fe0b0_len_5a0.c @@ -35,41 +35,32 @@ s32 DemoSetButtons(ScriptContext* script) { return 2; } -void __attribute__((naked)) DemoJoystickRadial(void) { - __asm__( - ".include \"asm/code_fe0b0_len_5a0/DemoJoystickRadial.s\"\n" - ); -} -/*s32 DemoJoystickRadial(ScriptContext* script) { - float a; - float b; - s32* nextPos = script->ptrReadPos + 1; - - a = get_float_variable(script, *script->ptrReadPos); - b = get_float_variable(script, nextPos); - - gGameStatus->demoStickX = (s32)(a * sin_deg(b)); - gGameStatus->demoStickY = (s32)(a * cos_deg(b)); - - return 2; -}*/ - -void __attribute__((naked)) DemoJoystickXY(void) { - __asm__( - ".include \"asm/code_fe0b0_len_5a0/DemoJoystickXY.s\"\n" - ); -} -/*s32 DemoJoystickXY(ScriptContext* script) { +s32 DemoJoystickRadial(ScriptContext* script) { float a; float b; s32* thisPos = script->ptrReadPos; - s32* nextPos = script->ptrReadPos + 1; + game_status **status = &gGameStatus; - a = get_float_variable(script, *thisPos); - b = get_float_variable(script, *nextPos); + a = get_float_variable(script, *thisPos++); + b = get_float_variable(script, *thisPos); - gGameStatus->demoStickX = a; - gGameStatus->demoStickY = b; + (*status)->demoStickX = a * sin_deg(b); + (*status)->demoStickY = a * cos_deg(b); return 2; -}*/ +} + +s32 DemoJoystickXY(ScriptContext* script) { + float a; + float b; + s32* thisPos = script->ptrReadPos; + game_status **status = &gGameStatus; + + a = get_float_variable(script, *thisPos++); + b = get_float_variable(script, *thisPos); + + (*status)->demoStickX = a; + (*status)->demoStickY = b; + + return 2; +} From b889313aad2baf099fe38db98f3aaaf6bd9c9606 Mon Sep 17 00:00:00 2001 From: dark-samus Date: Sat, 18 Jul 2020 23:56:17 -0400 Subject: [PATCH 2/2] better code for matching funcs --- papermario/include/variables.h | 2 +- papermario/src/code_fe0b0_len_5a0.c | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/papermario/include/variables.h b/papermario/include/variables.h index 7fed04a287..feedcf7897 100644 --- a/papermario/include/variables.h +++ b/papermario/include/variables.h @@ -4,7 +4,7 @@ #include "ultra64.h" #include "common_structs.h" -extern game_status* gGameStatus; +extern game_status* gGameStatus[1]; extern s16* D_80151328; #endif diff --git a/papermario/src/code_fe0b0_len_5a0.c b/papermario/src/code_fe0b0_len_5a0.c index d9cdd65678..6c638ff5db 100644 --- a/papermario/src/code_fe0b0_len_5a0.c +++ b/papermario/src/code_fe0b0_len_5a0.c @@ -16,22 +16,22 @@ s32 EnableSpriteShading(ScriptContext* script) { } s32 getDemoState(ScriptContext* script) { - set_variable(script, *script->ptrReadPos, gGameStatus->demoState); + set_variable(script, *script->ptrReadPos, (*gGameStatus)->demoState); return 2; } s32 DemoPressButton(ScriptContext* script) { - gGameStatus->demoButtonInput |= get_variable(script, *script->ptrReadPos); + (*gGameStatus)->demoButtonInput |= get_variable(script, *script->ptrReadPos); return 2; } s32 DemoReleaseButton(ScriptContext* script) { - gGameStatus->demoButtonInput &= ~get_variable(script, *script->ptrReadPos); + (*gGameStatus)->demoButtonInput &= ~get_variable(script, *script->ptrReadPos); return 2; } s32 DemoSetButtons(ScriptContext* script) { - gGameStatus->demoButtonInput = get_variable(script, *script->ptrReadPos); + (*gGameStatus)->demoButtonInput = get_variable(script, *script->ptrReadPos); return 2; } @@ -39,13 +39,12 @@ s32 DemoJoystickRadial(ScriptContext* script) { float a; float b; s32* thisPos = script->ptrReadPos; - game_status **status = &gGameStatus; a = get_float_variable(script, *thisPos++); - b = get_float_variable(script, *thisPos); + b = get_float_variable(script, *thisPos++); - (*status)->demoStickX = a * sin_deg(b); - (*status)->demoStickY = a * cos_deg(b); + (*gGameStatus)->demoStickX = a * sin_deg(b); + (*gGameStatus)->demoStickY = a * cos_deg(b); return 2; } @@ -54,13 +53,12 @@ s32 DemoJoystickXY(ScriptContext* script) { float a; float b; s32* thisPos = script->ptrReadPos; - game_status **status = &gGameStatus; a = get_float_variable(script, *thisPos++); - b = get_float_variable(script, *thisPos); + b = get_float_variable(script, *thisPos++); - (*status)->demoStickX = a; - (*status)->demoStickY = b; + (*gGameStatus)->demoStickX = a; + (*gGameStatus)->demoStickY = b; return 2; }