Misc 42e0 funcs, new SQ macro, removing no-builtin

This commit is contained in:
Ethan Roseman 2020-09-11 16:29:52 -04:00
parent bba1cc33fa
commit ddb9f77fc1
18 changed files with 80 additions and 254 deletions

View File

@ -5,7 +5,6 @@
"files.insertFinalNewline": true, "files.insertFinalNewline": true,
"editor.rulers": [120], "editor.rulers": [120],
"clang-tidy.compilerArgs": [ "clang-tidy.compilerArgs": [
"-fno-builtin",
"-std=gnu89", "-std=gnu89",
"-Iinclude", "-Iinclude",
"-Iinclude/PR", "-Iinclude/PR",

View File

@ -45,10 +45,10 @@ OBJCOPY = $(CROSS)objcopy
TARGET = papermario TARGET = papermario
CPPFLAGS = -fno-builtin -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 CPPFLAGS = -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2
ASFLAGS = -EB -Iinclude -march=vr4300 -mtune=vr4300 ASFLAGS = -EB -Iinclude -march=vr4300 -mtune=vr4300
OLDASFLAGS = -EB -Iinclude OLDASFLAGS = -EB -Iinclude
CFLAGS = -fno-builtin -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 CFLAGS = -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 LDFLAGS = -T undefined_syms.txt -T $(LD_SCRIPT) -Map $(BUILD_DIR)/papermario.map --no-check-sections
######################## Targets ############################# ######################## Targets #############################

View File

@ -1,19 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel _advance_rng
/* 004D00 80029900 3C035D58 */ lui $v1, 0x5d58
/* 004D04 80029904 3C048007 */ lui $a0, 0x8007
/* 004D08 80029908 24844410 */ addiu $a0, $a0, 0x4410
/* 004D0C 8002990C 8C820000 */ lw $v0, ($a0)
/* 004D10 80029910 34638B65 */ ori $v1, $v1, 0x8b65
/* 004D14 80029914 00430018 */ mult $v0, $v1
/* 004D18 80029918 3C038007 */ lui $v1, 0x8007
/* 004D1C 8002991C 8C63419C */ lw $v1, 0x419c($v1)
/* 004D20 80029920 00002812 */ mflo $a1
/* 004D24 80029924 24A20001 */ addiu $v0, $a1, 1
/* 004D28 80029928 AC820000 */ sw $v0, ($a0)
/* 004D2C 8002992C 03E00008 */ jr $ra
/* 004D30 80029930 AC620138 */ sw $v0, 0x138($v1)

View File

@ -1,13 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel copy_matrix
/* 004B20 80029720 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 004B24 80029724 AFBF0010 */ sw $ra, 0x10($sp)
/* 004B28 80029728 0C019194 */ jal bcopy
/* 004B2C 8002972C 24060040 */ addiu $a2, $zero, 0x40
/* 004B30 80029730 8FBF0010 */ lw $ra, 0x10($sp)
/* 004B34 80029734 03E00008 */ jr $ra
/* 004B38 80029738 27BD0018 */ addiu $sp, $sp, 0x18

View File

@ -1,29 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel dist2D
/* 0052D4 80029ED4 44861000 */ mtc1 $a2, $f2
/* 0052D8 80029ED8 00000000 */ nop
/* 0052DC 80029EDC 460C1301 */ sub.s $f12, $f2, $f12
/* 0052E0 80029EE0 460C6302 */ mul.s $f12, $f12, $f12
/* 0052E4 80029EE4 00000000 */ nop
/* 0052E8 80029EE8 44871000 */ mtc1 $a3, $f2
/* 0052EC 80029EEC 00000000 */ nop
/* 0052F0 80029EF0 460E1381 */ sub.s $f14, $f2, $f14
/* 0052F4 80029EF4 460E7382 */ mul.s $f14, $f14, $f14
/* 0052F8 80029EF8 00000000 */ nop
/* 0052FC 80029EFC 460E6300 */ add.s $f12, $f12, $f14
/* 005300 80029F00 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 005304 80029F04 46006004 */ sqrt.s $f0, $f12
/* 005308 80029F08 46000032 */ c.eq.s $f0, $f0
/* 00530C 80029F0C 00000000 */ nop
/* 005310 80029F10 45010003 */ bc1t .L80029F20
/* 005314 80029F14 AFBF0010 */ sw $ra, 0x10($sp)
/* 005318 80029F18 0C0187BC */ jal sqrtf
/* 00531C 80029F1C 00000000 */ nop
.L80029F20:
/* 005320 80029F20 8FBF0010 */ lw $ra, 0x10($sp)
/* 005324 80029F24 03E00008 */ jr $ra
/* 005328 80029F28 27BD0018 */ addiu $sp, $sp, 0x18

View File

@ -1,35 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel dist3D
/* 00532C 80029F2C 44872000 */ mtc1 $a3, $f4
/* 005330 80029F30 00000000 */ nop
/* 005334 80029F34 460C2301 */ sub.s $f12, $f4, $f12
/* 005338 80029F38 460C6302 */ mul.s $f12, $f12, $f12
/* 00533C 80029F3C 00000000 */ nop
/* 005340 80029F40 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 005344 80029F44 C7A20028 */ lwc1 $f2, 0x28($sp)
/* 005348 80029F48 460E1081 */ sub.s $f2, $f2, $f14
/* 00534C 80029F4C 46021082 */ mul.s $f2, $f2, $f2
/* 005350 80029F50 00000000 */ nop
/* 005354 80029F54 C7A0002C */ lwc1 $f0, 0x2c($sp)
/* 005358 80029F58 44862000 */ mtc1 $a2, $f4
/* 00535C 80029F5C 00000000 */ nop
/* 005360 80029F60 46040001 */ sub.s $f0, $f0, $f4
/* 005364 80029F64 46000002 */ mul.s $f0, $f0, $f0
/* 005368 80029F68 00000000 */ nop
/* 00536C 80029F6C 46026300 */ add.s $f12, $f12, $f2
/* 005370 80029F70 46006300 */ add.s $f12, $f12, $f0
/* 005374 80029F74 46006004 */ sqrt.s $f0, $f12
/* 005378 80029F78 46000032 */ c.eq.s $f0, $f0
/* 00537C 80029F7C 00000000 */ nop
/* 005380 80029F80 45010003 */ bc1t .L80029F90
/* 005384 80029F84 AFBF0010 */ sw $ra, 0x10($sp)
/* 005388 80029F88 0C0187BC */ jal sqrtf
/* 00538C 80029F8C 00000000 */ nop
.L80029F90:
/* 005390 80029F90 8FBF0010 */ lw $ra, 0x10($sp)
/* 005394 80029F94 03E00008 */ jr $ra
/* 005398 80029F98 27BD0018 */ addiu $sp, $sp, 0x18

View File

@ -1,31 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel get_clamped_angle_diff
/* 005028 80029C28 460C7001 */ sub.s $f0, $f14, $f12
/* 00502C 80029C2C 3C014334 */ lui $at, 0x4334
/* 005030 80029C30 44811000 */ mtc1 $at, $f2
/* 005034 80029C34 46000005 */ abs.s $f0, $f0
/* 005038 80029C38 4600103E */ c.le.s $f2, $f0
/* 00503C 80029C3C 00000000 */ nop
/* 005040 80029C40 4500000D */ bc1f .L80029C78
/* 005044 80029C44 00000000 */ nop
/* 005048 80029C48 460C703C */ c.lt.s $f14, $f12
/* 00504C 80029C4C 00000000 */ nop
/* 005050 80029C50 45000005 */ bc1f .L80029C68
/* 005054 80029C54 00000000 */ nop
/* 005058 80029C58 3C0143B4 */ lui $at, 0x43b4
/* 00505C 80029C5C 44810000 */ mtc1 $at, $f0
/* 005060 80029C60 0800A71E */ j .L80029C78
/* 005064 80029C64 46007380 */ add.s $f14, $f14, $f0
.L80029C68:
/* 005068 80029C68 3C0143B4 */ lui $at, 0x43b4
/* 00506C 80029C6C 44810000 */ mtc1 $at, $f0
/* 005070 80029C70 00000000 */ nop
/* 005074 80029C74 46007381 */ sub.s $f14, $f14, $f0
.L80029C78:
/* 005078 80029C78 03E00008 */ jr $ra
/* 00507C 80029C7C 460C7001 */ sub.s $f0, $f14, $f12

View File

@ -1,18 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel get_player_normal_yaw
/* 005220 80029E20 44806000 */ mtc1 $zero, $f12
/* 005224 80029E24 3C028007 */ lui $v0, 0x8007
/* 005228 80029E28 8C42419C */ lw $v0, 0x419c($v0)
/* 00522C 80029E2C 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 005230 80029E30 AFBF0010 */ sw $ra, 0x10($sp)
/* 005234 80029E34 8C460128 */ lw $a2, 0x128($v0)
/* 005238 80029E38 8C470130 */ lw $a3, 0x130($v0)
/* 00523C 80029E3C 0C00A720 */ jal atan2
/* 005240 80029E40 46006386 */ mov.s $f14, $f12
/* 005244 80029E44 8FBF0010 */ lw $ra, 0x10($sp)
/* 005248 80029E48 03E00008 */ jr $ra
/* 00524C 80029E4C 27BD0018 */ addiu $sp, $sp, 0x18

View File

@ -1,23 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel length2D
/* 0043F0 80028FF0 460C6302 */ mul.s $f12, $f12, $f12
/* 0043F4 80028FF4 00000000 */ nop
/* 0043F8 80028FF8 460E7382 */ mul.s $f14, $f14, $f14
/* 0043FC 80028FFC 00000000 */ nop
/* 004400 80029000 460E6300 */ add.s $f12, $f12, $f14
/* 004404 80029004 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 004408 80029008 46006004 */ sqrt.s $f0, $f12
/* 00440C 8002900C 46000032 */ c.eq.s $f0, $f0
/* 004410 80029010 00000000 */ nop
/* 004414 80029014 45010003 */ bc1t .L80029024
/* 004418 80029018 AFBF0010 */ sw $ra, 0x10($sp)
/* 00441C 8002901C 0C0187BC */ jal sqrtf
/* 004420 80029020 00000000 */ nop
.L80029024:
/* 004424 80029024 8FBF0010 */ lw $ra, 0x10($sp)
/* 004428 80029028 03E00008 */ jr $ra
/* 00442C 8002902C 27BD0018 */ addiu $sp, $sp, 0x18

View File

@ -1,16 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel mem_clear
/* 004A00 80029600 18A00005 */ blez $a1, .L80029618
/* 004A04 80029604 00000000 */ nop
.L80029608:
/* 004A08 80029608 A0800000 */ sb $zero, ($a0)
/* 004A0C 8002960C 24A5FFFF */ addiu $a1, $a1, -1
/* 004A10 80029610 1CA0FFFD */ bgtz $a1, .L80029608
/* 004A14 80029614 24840001 */ addiu $a0, $a0, 1
.L80029618:
/* 004A18 80029618 03E00008 */ jr $ra
/* 004A1C 8002961C 00000000 */ nop

View File

@ -1,16 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel poll_rumble
/* 0042E0 80028EE0 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 0042E4 80028EE4 AFBF0010 */ sw $ra, 0x10($sp)
/* 0042E8 80028EE8 0C017FBC */ jal nuContRmbCheck
/* 0042EC 80028EEC 0000202D */ daddu $a0, $zero, $zero
/* 0042F0 80028EF0 0000202D */ daddu $a0, $zero, $zero
/* 0042F4 80028EF4 0C017FE4 */ jal nuContRmbModeSet
/* 0042F8 80028EF8 24050002 */ addiu $a1, $zero, 2
/* 0042FC 80028EFC 8FBF0010 */ lw $ra, 0x10($sp)
/* 004300 80028F00 03E00008 */ jr $ra
/* 004304 80028F04 27BD0018 */ addiu $sp, $sp, 0x18

View File

@ -1,12 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel sign
/* 0048B0 800294B0 04800002 */ bltz $a0, .L800294BC
/* 0048B4 800294B4 2402FFFF */ addiu $v0, $zero, -1
/* 0048B8 800294B8 0004102A */ slt $v0, $zero, $a0
.L800294BC:
/* 0048BC 800294BC 03E00008 */ jr $ra
/* 0048C0 800294C0 00000000 */ nop

View File

@ -1,27 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel signF
/* 004E7C 80029A7C 44801000 */ mtc1 $zero, $f2
/* 004E80 80029A80 00000000 */ nop
/* 004E84 80029A84 460C103C */ c.lt.s $f2, $f12
/* 004E88 80029A88 00000000 */ nop
/* 004E8C 80029A8C 45010009 */ bc1t .L80029AB4
/* 004E90 80029A90 00000000 */ nop
/* 004E94 80029A94 3C01BF80 */ lui $at, 0xbf80
/* 004E98 80029A98 44810000 */ mtc1 $at, $f0
/* 004E9C 80029A9C 4602603C */ c.lt.s $f12, $f2
/* 004EA0 80029AA0 00000000 */ nop
/* 004EA4 80029AA4 45010005 */ bc1t .L80029ABC
/* 004EA8 80029AA8 00000000 */ nop
/* 004EAC 80029AAC 03E00008 */ jr $ra
/* 004EB0 80029AB0 46001006 */ mov.s $f0, $f2
.L80029AB4:
/* 004EB4 80029AB4 3C013F80 */ lui $at, 0x3f80
/* 004EB8 80029AB8 44810000 */ mtc1 $at, $f0
.L80029ABC:
/* 004EBC 80029ABC 03E00008 */ jr $ra
/* 004EC0 80029AC0 00000000 */ nop

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
COMPILER_OPTS="-fno-builtin -std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C" COMPILER_OPTS="-std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C"
shopt -s globstar shopt -s globstar

View File

@ -9,4 +9,6 @@
#define ASSERT(condition) if (!(condition)) { while (1) {} } #define ASSERT(condition) if (!(condition)) { while (1) {} }
#define SQ(x) (x*x)
#endif #endif

View File

@ -12,6 +12,7 @@ extern ActionState gPlayerActionState;
extern PlayerAnim gPlayerAnimation; extern PlayerAnim gPlayerAnimation;
extern PlayerStatus gPlayerStatus; extern PlayerStatus gPlayerStatus;
extern GameStatus* gGameStatusPtr[1]; extern GameStatus* gGameStatusPtr[1];
extern s32 D_80074410;
extern StaticItem gItemTable[364]; extern StaticItem gItemTable[364];
extern s16 gMainGameState; /* 0 = battle, 1 = pause, 2 = world */ extern s16 gMainGameState; /* 0 = battle, 1 = pause, 2 = world */
extern UNK_FUN_PTR(gCurrentUpdateFunction); extern UNK_FUN_PTR(gCurrentUpdateFunction);

View File

@ -1,6 +1,10 @@
#include "common.h" #include "common.h"
INCLUDE_ASM("code_42e0_len_1f60", poll_rumble); void poll_rumble(void) {
// TODO: replace with defines
nuContRmbCheck(0);
nuContRmbModeSet(0, 2);
}
INCLUDE_ASM("code_42e0_len_1f60", start_rumble); INCLUDE_ASM("code_42e0_len_1f60", start_rumble);
@ -8,7 +12,9 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80028F8C);
INCLUDE_ASM("code_42e0_len_1f60", func_80028FE0); INCLUDE_ASM("code_42e0_len_1f60", func_80028FE0);
INCLUDE_API_ASM("code_42e0_len_1f60", length2D); f32 length2D(f32 x, f32 y) {
return sqrtf(SQ(x) + SQ(y));
}
HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, void* addr, s32 size); HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, void* addr, s32 size);
@ -22,21 +28,42 @@ INCLUDE_ASM("code_42e0_len_1f60", _heap_realloc);
INCLUDE_API_ASM("code_42e0_len_1f60", cosine); INCLUDE_API_ASM("code_42e0_len_1f60", cosine);
INCLUDE_API_ASM("code_42e0_len_1f60", sign); s32 sign(s32 val) {
s32 ret = -1;
if (val >= 0) {
ret = val > 0;
}
return ret;
}
INCLUDE_ASM("code_42e0_len_1f60", int_to_string); INCLUDE_ASM("code_42e0_len_1f60", int_to_string);
INCLUDE_ASM("code_42e0_len_1f60", mem_clear); void mem_clear(s8* data, s32 numBytes) {
while (numBytes > 0) {
*data = 0;
data++;
numBytes--;
}
}
INCLUDE_ASM("code_42e0_len_1f60", transform_point); INCLUDE_ASM("code_42e0_len_1f60", transform_point);
INCLUDE_ASM("code_42e0_len_1f60", copy_matrix); void copy_matrix(Matrix4f* src, Matrix4f* dest) {
bcopy(src, dest, sizeof(Matrix4f));
}
INCLUDE_ASM("code_42e0_len_1f60", dma_copy); INCLUDE_ASM("code_42e0_len_1f60", dma_copy);
INCLUDE_ASM("code_42e0_len_1f60", func_80029860); INCLUDE_ASM("code_42e0_len_1f60", func_80029860);
INCLUDE_ASM("code_42e0_len_1f60", _advance_rng); s32 _advance_rng(void) {
s32* rngVal = &D_80074410;
(*gGameStatusPtr)->nextRNG = *rngVal = (*rngVal * 0x5D588B65) + 1;
return *rngVal;
}
INCLUDE_ASM("code_42e0_len_1f60", func_80029934); INCLUDE_ASM("code_42e0_len_1f60", func_80029934);
@ -44,23 +71,58 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80029994);
s32 INCLUDE_ASM("code_42e0_len_1f60", rand_int, s32 arg0); s32 INCLUDE_ASM("code_42e0_len_1f60", rand_int, s32 arg0);
INCLUDE_API_ASM("code_42e0_len_1f60", signF); f32 signF(f32 val) {
f32 ret;
if (!(val > 0.0f)) {
ret = -1.0f;
if (!(val < 0.0f)) {
ret = 0.0f;
}
} else {
ret = 1.0f;
}
return ret;
}
INCLUDE_API_ASM("code_42e0_len_1f60", round); INCLUDE_API_ASM("code_42e0_len_1f60", round);
f32 INCLUDE_ASM("code_42e0_len_1f60", clamp_angle, f32 theta); f32 INCLUDE_ASM("code_42e0_len_1f60", clamp_angle, f32 theta);
INCLUDE_ASM("code_42e0_len_1f60", get_clamped_angle_diff); f32 get_clamped_angle_diff(f32 a, f32 b) {
if (fabsf(b - a) >= 180.0f) {
if (b < a) {
b += 360.0f;
} else {
b -= 360.0f;
}
}
return b - a;
}
f32 INCLUDE_ASM("code_42e0_len_1f60", atan2, f32 startX, f32 startZ, f32 endX, f32 endZ); f32 INCLUDE_ASM("code_42e0_len_1f60", atan2, f32 startX, f32 startZ, f32 endX, f32 endZ);
INCLUDE_ASM("code_42e0_len_1f60", get_player_normal_yaw); f32 get_player_normal_yaw(void) {
return atan2(0, 0, (*gGameStatusPtr)->playerTraceNormal[0], (*gGameStatusPtr)->playerTraceNormal[2]);
}
INCLUDE_ASM("code_42e0_len_1f60", get_player_normal_pitch); INCLUDE_ASM("code_42e0_len_1f60", get_player_normal_pitch);
f32 INCLUDE_ASM("code_42e0_len_1f60", dist2D, f32 ax, f32 ay, f32 bx, f32 by); f32 dist2D(f32 ax, f32 ay, f32 bx, f32 by) {
f32 xDiff = bx - ax;
f32 yDiff = by - ay;
f32 INCLUDE_ASM("code_42e0_len_1f60", dist3D, f32 ax, f32 ay, f32 az, f32 bx, f32 by, f32 bz); return sqrtf(SQ(xDiff) + SQ(yDiff));
}
f32 dist3D(f32 ax, f32 ay, f32 az, f32 bx, f32 by, f32 bz) {
f32 xDiff = bx - ax;
f32 yDiff = by - ay;
f32 zDiff = bz - az;
return sqrtf(SQ(xDiff) + SQ(yDiff) + SQ(zDiff));
}
void INCLUDE_ASM("code_42e0_len_1f60", add_vec2D_polar, f32* x, f32* y, f32 r, f32 theta); void INCLUDE_ASM("code_42e0_len_1f60", add_vec2D_polar, f32* x, f32* y, f32 r, f32 theta);

View File

@ -1,4 +1,5 @@
gGameStatusPtr = 0x8007419C; gGameStatusPtr = 0x8007419C;
D_80074410 = 0x80074410;
gUIStatus = 0x8010EF58; gUIStatus = 0x8010EF58;
gPlayerData = 0x8010F290; gPlayerData = 0x8010F290;
gPlayerActionState = 0x8010F07C; gPlayerActionState = 0x8010F07C;