From 90d2ddf2f604a37ead3f99d1d9986f466754fa27 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Tue, 1 Sep 2020 21:45:06 -0400 Subject: [PATCH 1/5] Finished code_6000.c --- .../code_6000/collision_heap_create.s | 23 ------------ .../code_6000/collision_heap_free.s | 28 --------------- .../code_6000/collision_heap_malloc.s | 25 ------------- include/functions.h | 1 + src/code_42e0_len_1f60.c | 2 +- src/code_6000.c | 35 +++++++++++-------- 6 files changed, 23 insertions(+), 91 deletions(-) delete mode 100644 asm/nonmatchings/code_6000/collision_heap_create.s delete mode 100644 asm/nonmatchings/code_6000/collision_heap_free.s delete mode 100644 asm/nonmatchings/code_6000/collision_heap_malloc.s diff --git a/asm/nonmatchings/code_6000/collision_heap_create.s b/asm/nonmatchings/code_6000/collision_heap_create.s deleted file mode 100644 index 495d6c074e..0000000000 --- a/asm/nonmatchings/code_6000/collision_heap_create.s +++ /dev/null @@ -1,23 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel collision_heap_create -/* 006174 8002AD74 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 006178 8002AD78 AFBF0010 */ sw $ra, 0x10($sp) -/* 00617C 8002AD7C 3C050001 */ lui $a1, 1 -/* 006180 8002AD80 3C048027 */ lui $a0, 0x8027 -/* 006184 8002AD84 24848000 */ addiu $a0, $a0, -0x8000 -/* 006188 8002AD88 0C00A40C */ jal _heap_create -/* 00618C 8002AD8C 34A58000 */ ori $a1, $a1, 0x8000 -/* 006190 8002AD90 0040202D */ daddu $a0, $v0, $zero -/* 006194 8002AD94 2402FFFF */ addiu $v0, $zero, -1 -/* 006198 8002AD98 0040182D */ daddu $v1, $v0, $zero -/* 00619C 8002AD9C 54830001 */ bnel $a0, $v1, .L8002ADA4 -/* 0061A0 8002ADA0 0000102D */ daddu $v0, $zero, $zero -.L8002ADA4: -/* 0061A4 8002ADA4 8FBF0010 */ lw $ra, 0x10($sp) -/* 0061A8 8002ADA8 03E00008 */ jr $ra -/* 0061AC 8002ADAC 27BD0018 */ addiu $sp, $sp, 0x18 - - diff --git a/asm/nonmatchings/code_6000/collision_heap_free.s b/asm/nonmatchings/code_6000/collision_heap_free.s deleted file mode 100644 index a7a7c04b41..0000000000 --- a/asm/nonmatchings/code_6000/collision_heap_free.s +++ /dev/null @@ -1,28 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel collision_heap_free -/* 0061F4 8002ADF4 3C028007 */ lui $v0, 0x8007 -/* 0061F8 8002ADF8 8C42419C */ lw $v0, 0x419c($v0) -/* 0061FC 8002ADFC 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 006200 8002AE00 AFBF0010 */ sw $ra, 0x10($sp) -/* 006204 8002AE04 80420070 */ lb $v0, 0x70($v0) -/* 006208 8002AE08 0080282D */ daddu $a1, $a0, $zero -/* 00620C 8002AE0C 3C04803E */ lui $a0, 0x803e -/* 006210 8002AE10 2484A800 */ addiu $a0, $a0, -0x5800 -/* 006214 8002AE14 14400003 */ bnez $v0, .L8002AE24 -/* 006218 8002AE18 00000000 */ nop -/* 00621C 8002AE1C 3C048027 */ lui $a0, 0x8027 -/* 006220 8002AE20 24848000 */ addiu $a0, $a0, -0x8000 -.L8002AE24: -/* 006224 8002AE24 0C00A487 */ jal _heap_free -/* 006228 8002AE28 00000000 */ nop -/* 00622C 8002AE2C 8FBF0010 */ lw $ra, 0x10($sp) -/* 006230 8002AE30 03E00008 */ jr $ra -/* 006234 8002AE34 27BD0018 */ addiu $sp, $sp, 0x18 - -/* 006238 8002AE38 00000000 */ nop -/* 00623C 8002AE3C 00000000 */ nop - - diff --git a/asm/nonmatchings/code_6000/collision_heap_malloc.s b/asm/nonmatchings/code_6000/collision_heap_malloc.s deleted file mode 100644 index ba19258281..0000000000 --- a/asm/nonmatchings/code_6000/collision_heap_malloc.s +++ /dev/null @@ -1,25 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel collision_heap_malloc -/* 0061B0 8002ADB0 3C028007 */ lui $v0, 0x8007 -/* 0061B4 8002ADB4 8C42419C */ lw $v0, 0x419c($v0) -/* 0061B8 8002ADB8 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 0061BC 8002ADBC AFBF0010 */ sw $ra, 0x10($sp) -/* 0061C0 8002ADC0 80420070 */ lb $v0, 0x70($v0) -/* 0061C4 8002ADC4 0080282D */ daddu $a1, $a0, $zero -/* 0061C8 8002ADC8 3C048027 */ lui $a0, 0x8027 -/* 0061CC 8002ADCC 24848000 */ addiu $a0, $a0, -0x8000 -/* 0061D0 8002ADD0 10400003 */ beqz $v0, .L8002ADE0 -/* 0061D4 8002ADD4 00000000 */ nop -/* 0061D8 8002ADD8 3C04803E */ lui $a0, 0x803e -/* 0061DC 8002ADDC 2484A800 */ addiu $a0, $a0, -0x5800 -.L8002ADE0: -/* 0061E0 8002ADE0 0C00A41B */ jal _heap_malloc -/* 0061E4 8002ADE4 00000000 */ nop -/* 0061E8 8002ADE8 8FBF0010 */ lw $ra, 0x10($sp) -/* 0061EC 8002ADEC 03E00008 */ jr $ra -/* 0061F0 8002ADF0 27BD0018 */ addiu $sp, $sp, 0x18 - - diff --git a/include/functions.h b/include/functions.h index 0a3a55ae47..30daffa043 100644 --- a/include/functions.h +++ b/include/functions.h @@ -8,6 +8,7 @@ void osCleanupThread(void); s32 heap_malloc(s32 size); +HeapNode* _heap_create(s32 addr, s32 size); void clone_model(u16 srcModelID, u16 newModelID); void update_collider_transform(s16 colliderID); diff --git a/src/code_42e0_len_1f60.c b/src/code_42e0_len_1f60.c index dbc3b124de..86f99aedad 100644 --- a/src/code_42e0_len_1f60.c +++ b/src/code_42e0_len_1f60.c @@ -10,7 +10,7 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80028FE0); INCLUDE_API_ASM("code_42e0_len_1f60", length2D); -INCLUDE_ASM("code_42e0_len_1f60", _heap_create); +HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, s32 addr, s32 size); INCLUDE_ASM("code_42e0_len_1f60", _heap_malloc); diff --git a/src/code_6000.c b/src/code_6000.c index 6bc9d6a12b..e67e3f2989 100644 --- a/src/code_6000.c +++ b/src/code_6000.c @@ -4,8 +4,6 @@ extern s32 D_80268000; extern s32 D_802FB800; extern s32 D_803DA800; -// s32 _heap_free(s32 addr, s32 size); - s32 general_heap_create(void) { return _heap_create(&D_802FB800, 0x54000); } @@ -50,16 +48,25 @@ s32 heap_free(s32 size) { } } -INCLUDE_ASM("code_6000", collision_heap_create); - -INCLUDE_ASM("code_6000", collision_heap_malloc); - -#ifdef NON_MATCHING -s32 collision_heap_free(s32 size) { - s32 isBattle = (*gGameStatusPtr)->isBattle; - - return _heap_free((isBattle == 0) ? (&D_80268000) : (&D_803DA800), size); +s32 collision_heap_create(void) { + if (_heap_create(&D_80268000, 0x18000) == -1) { + return -1; + } + return 0; +} + +s32 collision_heap_malloc(s32 size) { + if (!(*gGameStatusPtr)->isBattle) { + return _heap_malloc(&D_80268000, size); + } else { + return _heap_malloc(&D_803DA800, size); + } +} + +s32 collision_heap_free(s32 size) { + if (!(*gGameStatusPtr)->isBattle) { + _heap_free(&D_80268000, size); + } else { + _heap_free(&D_803DA800, size); + } } -#else -INCLUDE_ASM("code_6000", collision_heap_free); -#endif From ee8d55d6a2209302dd8e252d0af44cc719bf4958 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Wed, 2 Sep 2020 12:37:33 -0400 Subject: [PATCH 2/5] PR fixes and a couple more --- .../code_6240_len_c00/fio_erase_flash.s | 17 ----------------- .../code_6240_len_c00/fio_init_flash.s | 13 ------------- include/functions.h | 2 +- src/code_42e0_len_1f60.c | 2 +- src/code_6000.c | 12 ++++++------ src/code_6240_len_c00.c | 8 ++++++-- 6 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 asm/nonmatchings/code_6240_len_c00/fio_erase_flash.s delete mode 100644 asm/nonmatchings/code_6240_len_c00/fio_init_flash.s diff --git a/asm/nonmatchings/code_6240_len_c00/fio_erase_flash.s b/asm/nonmatchings/code_6240_len_c00/fio_erase_flash.s deleted file mode 100644 index 73ab34c4ae..0000000000 --- a/asm/nonmatchings/code_6240_len_c00/fio_erase_flash.s +++ /dev/null @@ -1,17 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel fio_erase_flash -/* 006E1C 8002BA1C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 006E20 8002BA20 AFBF0010 */ sw $ra, 0x10($sp) -/* 006E24 8002BA24 0C01BD09 */ jal osFlashSectorErase -/* 006E28 8002BA28 000421C0 */ sll $a0, $a0, 7 -/* 006E2C 8002BA2C 8FBF0010 */ lw $ra, 0x10($sp) -/* 006E30 8002BA30 03E00008 */ jr $ra -/* 006E34 8002BA34 27BD0018 */ addiu $sp, $sp, 0x18 - -/* 006E38 8002BA38 00000000 */ nop -/* 006E3C 8002BA3C 00000000 */ nop - - diff --git a/asm/nonmatchings/code_6240_len_c00/fio_init_flash.s b/asm/nonmatchings/code_6240_len_c00/fio_init_flash.s deleted file mode 100644 index 92f1a87fa2..0000000000 --- a/asm/nonmatchings/code_6240_len_c00/fio_init_flash.s +++ /dev/null @@ -1,13 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - - -glabel fio_init_flash -/* 006C4C 8002B84C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* 006C50 8002B850 AFBF0010 */ sw $ra, 0x10($sp) -/* 006C54 8002B854 0C01BBDA */ jal osFlashInit -/* 006C58 8002B858 00000000 */ nop -/* 006C5C 8002B85C 8FBF0010 */ lw $ra, 0x10($sp) -/* 006C60 8002B860 03E00008 */ jr $ra -/* 006C64 8002B864 27BD0018 */ addiu $sp, $sp, 0x18 - diff --git a/include/functions.h b/include/functions.h index 30daffa043..2ea26784c5 100644 --- a/include/functions.h +++ b/include/functions.h @@ -8,7 +8,7 @@ void osCleanupThread(void); s32 heap_malloc(s32 size); -HeapNode* _heap_create(s32 addr, s32 size); +HeapNode* _heap_create(u32* addr, s32 size); void clone_model(u16 srcModelID, u16 newModelID); void update_collider_transform(s16 colliderID); diff --git a/src/code_42e0_len_1f60.c b/src/code_42e0_len_1f60.c index 86f99aedad..38fa969f21 100644 --- a/src/code_42e0_len_1f60.c +++ b/src/code_42e0_len_1f60.c @@ -10,7 +10,7 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80028FE0); INCLUDE_API_ASM("code_42e0_len_1f60", length2D); -HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, s32 addr, s32 size); +HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, u32* addr, s32 size); INCLUDE_ASM("code_42e0_len_1f60", _heap_malloc); diff --git a/src/code_6000.c b/src/code_6000.c index e67e3f2989..40fd58abc9 100644 --- a/src/code_6000.c +++ b/src/code_6000.c @@ -4,7 +4,7 @@ extern s32 D_80268000; extern s32 D_802FB800; extern s32 D_803DA800; -s32 general_heap_create(void) { +HeapNode* general_heap_create(void) { return _heap_create(&D_802FB800, 0x54000); } @@ -21,7 +21,7 @@ s32 general_heap_free(s32 size) { } s32 battle_heap_create(void) { - if (_heap_create(&D_803DA800, 0x25800) == -1) { + if ((s32)_heap_create(&D_803DA800, 0x25800) == -1) { return -1; } else { return 0; @@ -49,7 +49,7 @@ s32 heap_free(s32 size) { } s32 collision_heap_create(void) { - if (_heap_create(&D_80268000, 0x18000) == -1) { + if ((s32)_heap_create(&D_80268000, 0x18000) == -1) { return -1; } return 0; @@ -63,10 +63,10 @@ s32 collision_heap_malloc(s32 size) { } } -s32 collision_heap_free(s32 size) { +s32 collision_heap_free(UNK_PTR data) { if (!(*gGameStatusPtr)->isBattle) { - _heap_free(&D_80268000, size); + _heap_free(&D_80268000, data); } else { - _heap_free(&D_803DA800, size); + _heap_free(&D_803DA800, data); } } diff --git a/src/code_6240_len_c00.c b/src/code_6240_len_c00.c index b3afcfc4a0..cbc4cc07bf 100644 --- a/src/code_6240_len_c00.c +++ b/src/code_6240_len_c00.c @@ -26,10 +26,14 @@ INCLUDE_ASM("code_6240_len_c00", fio_deserialize_state); INCLUDE_ASM("code_6240_len_c00", fio_serialize_state); -INCLUDE_ASM("code_6240_len_c00", fio_init_flash); +void fio_init_flash(void) { + osFlashInit(); +} INCLUDE_ASM("code_6240_len_c00", fio_read_flash); INCLUDE_ASM("code_6240_len_c00", fio_write_flash); -INCLUDE_ASM("code_6240_len_c00", fio_erase_flash); +void fio_erase_flash(s32 pageNum) { + osFlashSectorErase(pageNum * 128); +} From 11e3e9b35eb29372ebdd9a61b37560e5055fae00 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Wed, 2 Sep 2020 12:51:45 -0400 Subject: [PATCH 3/5] tiny change --- include/functions.h | 2 +- src/code_42e0_len_1f60.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/functions.h b/include/functions.h index 2ea26784c5..aeedf2514b 100644 --- a/include/functions.h +++ b/include/functions.h @@ -8,7 +8,7 @@ void osCleanupThread(void); s32 heap_malloc(s32 size); -HeapNode* _heap_create(u32* addr, s32 size); +HeapNode* _heap_create(UNK_PTR addr, s32 size); void clone_model(u16 srcModelID, u16 newModelID); void update_collider_transform(s16 colliderID); diff --git a/src/code_42e0_len_1f60.c b/src/code_42e0_len_1f60.c index 38fa969f21..78ef1ba6fd 100644 --- a/src/code_42e0_len_1f60.c +++ b/src/code_42e0_len_1f60.c @@ -10,7 +10,7 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80028FE0); INCLUDE_API_ASM("code_42e0_len_1f60", length2D); -HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, u32* addr, s32 size); +HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, UNK_PTR addr, s32 size); INCLUDE_ASM("code_42e0_len_1f60", _heap_malloc); From c92a46ae0dfc2b3f04d365a2153f791f643d421d Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Wed, 2 Sep 2020 14:20:29 -0400 Subject: [PATCH 4/5] PR comments, Makefile change --- Makefile | 10 +++++----- include/functions.h | 2 +- src/code_42e0_len_1f60.c | 2 +- src/code_6000.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index dfb3a3ed84..b20b97b024 100644 --- a/Makefile +++ b/Makefile @@ -45,11 +45,11 @@ OBJCOPY = $(CROSS)objcopy TARGET = papermario -CPPFLAGS = -fno-builtin -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 -ASFLAGS = -EB -march=vr4300 -mtune=vr4300 -Iinclude -OLDASFLAGS= -EB -Iinclude -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 +CPPFLAGS = -fno-builtin -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 +ASFLAGS = -EB -Iinclude --mips3 -march=vr4300 -mtune=vr4300 +OLDASFLAGS = -EB -Iinclude --mips3 +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 ######################## Targets ############################# diff --git a/include/functions.h b/include/functions.h index aeedf2514b..d45eacafdd 100644 --- a/include/functions.h +++ b/include/functions.h @@ -8,7 +8,7 @@ void osCleanupThread(void); s32 heap_malloc(s32 size); -HeapNode* _heap_create(UNK_PTR addr, s32 size); +HeapNode* _heap_create(void* addr, s32 size); void clone_model(u16 srcModelID, u16 newModelID); void update_collider_transform(s16 colliderID); diff --git a/src/code_42e0_len_1f60.c b/src/code_42e0_len_1f60.c index 78ef1ba6fd..7976950534 100644 --- a/src/code_42e0_len_1f60.c +++ b/src/code_42e0_len_1f60.c @@ -10,7 +10,7 @@ INCLUDE_ASM("code_42e0_len_1f60", func_80028FE0); INCLUDE_API_ASM("code_42e0_len_1f60", length2D); -HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, UNK_PTR addr, s32 size); +HeapNode* INCLUDE_ASM("code_42e0_len_1f60", _heap_create, void* addr, s32 size); INCLUDE_ASM("code_42e0_len_1f60", _heap_malloc); diff --git a/src/code_6000.c b/src/code_6000.c index 40fd58abc9..8377ef60d9 100644 --- a/src/code_6000.c +++ b/src/code_6000.c @@ -63,7 +63,7 @@ s32 collision_heap_malloc(s32 size) { } } -s32 collision_heap_free(UNK_PTR data) { +s32 collision_heap_free(void* data) { if (!(*gGameStatusPtr)->isBattle) { _heap_free(&D_80268000, data); } else { From a8cf83b098d74140df9e07ac54a8bc92b8a6beab Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Wed, 2 Sep 2020 14:35:25 -0400 Subject: [PATCH 5/5] removing -mips3 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b20b97b024..20f062eb23 100644 --- a/Makefile +++ b/Makefile @@ -46,8 +46,8 @@ OBJCOPY = $(CROSS)objcopy TARGET = papermario CPPFLAGS = -fno-builtin -Iinclude -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 -ASFLAGS = -EB -Iinclude --mips3 -march=vr4300 -mtune=vr4300 -OLDASFLAGS = -EB -Iinclude --mips3 +ASFLAGS = -EB -Iinclude -march=vr4300 -mtune=vr4300 +OLDASFLAGS = -EB -Iinclude 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