This commit is contained in:
alex 2021-07-19 09:22:43 +01:00 committed by GitHub
parent 2a4966887c
commit 035a0e6db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 134 additions and 112 deletions

View File

@ -16,9 +16,19 @@
#define PHYSICAL_TO_VIRTUAL(addr) (void*)((u32)(addr) + 0x80000000)
#define VIRTUAL_TO_PHYSICAL(addr) (u32)((u8*)(addr) - 0x80000000)
#define ASSERT(condition) if (!(condition)) { while (1) {} }
#define PANIC() ASSERT(0)
#define STATIC_ASSERT(condition) enum { static_assert_fail = 1/(!!(condition)) } // Causes division by zero ("not integer constant") if false
#ifdef DEBUG
#define ASSERT(condition) \
if (!(condition)) { \
func_80025F44("Assertion failed: " #condition, __FILE__, __LINE__); \
while (TRUE) {} \
}
#define PANIC() \
func_80025F44("Panic!", __FILE__, __LINE__); \
while (TRUE) {}
#else
#define ASSERT(condition) if (!(condition)) { while (TRUE) {} }
#define PANIC() while (TRUE) {}
#endif
#define BADGE_MENU_PAGE(index) (&gBadgeMenuPages[index])
#define ITEM_MENU_PAGE(index) (&gItemMenuPages[index])

View File

@ -1,88 +0,0 @@
#include "common.h"
#include "stdlib/stdarg.h"
u32 func_80025D74(void* arg0, const unsigned char* str, s32 count);
void func_80025C60(void) {
osEPiWriteIo(carthandle, 0xB3FF0014, 0);
osEPiWriteIo(carthandle, 0xB3FF0004, 0);
osEPiWriteIo(carthandle, 0xB3FF0000, ASCII_TO_U32('I', 'S', '6', '4'));
}
void func_80025CC0(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_Printf(func_80025D74, NULL, fmt, args);
}
void func_80025CFC(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_Printf(func_80025D74, NULL, fmt, args);
}
void func_80025D38(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_Printf(func_80025D74, NULL, fmt, args);
}
u32 func_80025D74(void* arg0, const unsigned char* str, s32 count) {
u32 data;
s32 pos;
s32 start;
s32 end;
osEPiReadIo(carthandle, 0xB3FF0000, &data);
if (data != ASCII_TO_U32('I', 'S', '6', '4')) {
return 1;
}
osEPiReadIo(carthandle, 0xB3FF0004, &data);
pos = data;
osEPiReadIo(carthandle, 0xB3FF0014, &data);
start = data;
end = start + count;
if (end >= 0xffe0) {
end -= 0xffe0;
if (pos < end || start < pos) {
return 1;
}
} else {
if (start < pos && pos < end) {
return 1;
}
}
while (count) {
if (*str) {
u32 addr = 0xB3FF0020 + (start & 0xffffffc);
s32 shift = ((3 - (start & 3)) * 8);
osEPiReadIo(carthandle, addr, &data);
osEPiWriteIo(carthandle, addr, (data & ~(0xff << shift)) | (*str << shift));
start++;
if (start >= 0xffe0) {
start -= 0xffe0;
}
}
count--;
str++;
}
osEPiWriteIo(carthandle, 0xB3FF0014, start);
return 1;
}
// Nop issue with the rodata string
#ifdef NON_MATCHING
void func_80025F44(char* arg0, char* file, s32 line) {
func_80025CFC("File:%s Line:%d %s \n", file, line, arg0);
PANIC();
}
#else
INCLUDE_ASM(void, "1060_len_310", func_80025F44, char* arg0, char* file, s32 line);
#endif

View File

@ -31,7 +31,7 @@ void boot_main(void) {
nuGfxDisplayOff();
crash_create_monitor();
func_80025C60();
is_debug_init();
nuGfxInit();
gGameStatusPtr->contBitPattern = nuContInit();
func_8002D160();

100
src/is_debug.c Normal file
View File

@ -0,0 +1,100 @@
#include "common.h"
#include "stdlib/stdarg.h"
typedef struct {
/* 0x00 */ u32 magic;
/* 0x04 */ u32 get;
/* 0x08 */ char unk_08[0x14-0x08];
/* 0x14 */ u32 put;
/* 0x18 */ char unk_18[0x20-0x18];
/* 0x20 */ char data[0x10000-0x20];
} ISVDbg;
#define gISVDbgPrnAdrs ((ISVDbg*) 0xb3ff0000)
u32 is_debug_print(void* arg0, const unsigned char* str, s32 count);
void is_debug_init(void) {
osEPiWriteIo(carthandle, (u32) &gISVDbgPrnAdrs->put, 0);
osEPiWriteIo(carthandle, (u32) &gISVDbgPrnAdrs->get, 0);
osEPiWriteIo(carthandle, (u32) &gISVDbgPrnAdrs->magic, ASCII_TO_U32('I', 'S', '6', '4'));
}
void printf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_Printf(is_debug_print, NULL, fmt, args);
}
void osSyncPrintf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_Printf(is_debug_print, NULL, fmt, args);
}
void rmonPrintf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
_Printf(is_debug_print, NULL, fmt, args);
}
u32 is_debug_print(void* arg0, const unsigned char* str, s32 count) {
u32 data;
s32 pos;
s32 start;
s32 end;
osEPiReadIo(carthandle, (u32) &gISVDbgPrnAdrs->magic, &data);
if (data != ASCII_TO_U32('I', 'S', '6', '4')) {
return 1;
}
osEPiReadIo(carthandle, (u32) &gISVDbgPrnAdrs->get, &data);
pos = data;
osEPiReadIo(carthandle, (u32) &gISVDbgPrnAdrs->put, &data);
start = data;
end = start + count;
if (end >= 0xffe0) {
end -= 0xffe0;
if (pos < end || start < pos) {
return 1;
}
} else {
if (start < pos && pos < end) {
return 1;
}
}
while (count) {
if (*str) {
u32 addr = (u32) &gISVDbgPrnAdrs->data + (start & 0xffffffc);
s32 shift = ((3 - (start & 3)) * 8);
osEPiReadIo(carthandle, addr, &data);
osEPiWriteIo(carthandle, addr, (data & ~(0xff << shift)) | (*str << shift));
start++;
if (start >= 0xffe0) {
start -= 0xffe0;
}
}
count--;
str++;
}
osEPiWriteIo(carthandle, (u32)&gISVDbgPrnAdrs->put, start);
return 1;
}
// Nop issue with the rodata string
#ifdef NON_MATCHING
void func_80025F44(const char* message, char* file, s32 line) {
osSyncPrintf("File:%s Line:%d %s \n", file, line, message);
while (TRUE) {
;
}
}
#else
INCLUDE_ASM(void, "is_debug", func_80025F44, char* arg0, char* file, s32 line);
#endif

View File

@ -1,6 +1,8 @@
#include "common.h"
#include "stdlib/stdarg.h"
// TODO: use src/is_debug.c instead as this file is identical between versions
u32 func_80025D74(void* arg0, const unsigned char* str, s32 count);
void func_80025C60(void) {

View File

@ -194,10 +194,9 @@ void free_npc_by_index(s32 listIndex) {
}
if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
if (!(npc->flags & NPC_FLAG_1000000) && spr_free_sprite(npc->spriteInstanceID)) {
PANIC();
}
ASSERT((npc->flags & NPC_FLAG_1000000) || !spr_free_sprite(npc->spriteInstanceID));
}
delete_shadow(npc->shadowIndex);
for (i = 0; i < 2; i++) {
@ -224,10 +223,9 @@ void free_npc(Npc* npc) {
}
if (!(npc->flags & NPC_FLAG_NO_ANIMS_LOADED)) {
if (!(npc->flags & NPC_FLAG_1000000) && spr_free_sprite(npc->spriteInstanceID) != 0) {
PANIC();
}
ASSERT((npc->flags & NPC_FLAG_1000000) || !spr_free_sprite(npc->spriteInstanceID));
}
delete_shadow(npc->shadowIndex);
for (i = 0; i < 2; i++) {

View File

@ -138,7 +138,7 @@ glabel func_80240158_EC2358
/* EC2524 80240324 00000000 */ nop
.L80240328:
/* EC2528 80240328 3C048024 */ lui $a0, %hi(D_80244F88_EC7188)
/* EC252C 8024032C 0C00973F */ jal func_80025CFC
/* EC252C 8024032C 0C00973F */ jal osSyncPrintf
/* EC2530 80240330 24844F88 */ addiu $a0, $a0, %lo(D_80244F88_EC7188)
.L80240334:
/* EC2534 80240334 C60C0038 */ lwc1 $f12, 0x38($s0)

View File

@ -144,7 +144,7 @@ glabel func_802404B0_ED46D0
/* ED48CC 802406AC 3C058024 */ lui $a1, %hi(D_80244BEC_ED8E0C)
/* ED48D0 802406B0 24A54BEC */ addiu $a1, $a1, %lo(D_80244BEC_ED8E0C)
/* ED48D4 802406B4 24060053 */ addiu $a2, $zero, 0x53
/* ED48D8 802406B8 0C00973F */ jal func_80025CFC
/* ED48D8 802406B8 0C00973F */ jal osSyncPrintf
/* ED48DC 802406BC 0040382D */ daddu $a3, $v0, $zero
/* ED48E0 802406C0 3C02FD10 */ lui $v0, 0xfd10
.L802406C4:
@ -308,7 +308,7 @@ glabel func_802404B0_ED46D0
/* ED4B4C 8024092C 3C058024 */ lui $a1, %hi(D_80244BEC_ED8E0C)
/* ED4B50 80240930 24A54BEC */ addiu $a1, $a1, %lo(D_80244BEC_ED8E0C)
/* ED4B54 80240934 2406006B */ addiu $a2, $zero, 0x6b
/* ED4B58 80240938 0C00973F */ jal func_80025CFC
/* ED4B58 80240938 0C00973F */ jal osSyncPrintf
/* ED4B5C 8024093C 0040382D */ daddu $a3, $v0, $zero
/* ED4B60 80240940 3C02FD10 */ lui $v0, 0xfd10
.L80240944:

View File

@ -358,7 +358,7 @@ glabel func_80240B10_ED4D30
/* ED5270 80241050 3C058024 */ lui $a1, %hi(D_80244BEC_ED8E0C)
/* ED5274 80241054 24A54BEC */ addiu $a1, $a1, %lo(D_80244BEC_ED8E0C)
/* ED5278 80241058 240600AF */ addiu $a2, $zero, 0xaf
/* ED527C 8024105C 0C00973F */ jal func_80025CFC
/* ED527C 8024105C 0C00973F */ jal osSyncPrintf
/* ED5280 80241060 0040382D */ daddu $a3, $v0, $zero
.L80241064:
/* ED5284 80241064 36B5013F */ ori $s5, $s5, 0x13f
@ -417,7 +417,7 @@ glabel func_80240B10_ED4D30
/* ED5358 80241138 3C058024 */ lui $a1, %hi(D_80244BEC_ED8E0C)
/* ED535C 8024113C 24A54BEC */ addiu $a1, $a1, %lo(D_80244BEC_ED8E0C)
/* ED5360 80241140 240600BA */ addiu $a2, $zero, 0xba
/* ED5364 80241144 0C00973F */ jal func_80025CFC
/* ED5364 80241144 0C00973F */ jal osSyncPrintf
/* ED5368 80241148 0040382D */ daddu $a3, $v0, $zero
.L8024114C:
/* ED536C 8024114C 8E840000 */ lw $a0, ($s4)

View File

@ -70,7 +70,7 @@ glabel func_802400F0_ED8F10
/* ED8FF8 802401D8 8E060084 */ lw $a2, 0x84($s0)
/* ED8FFC 802401DC 8E070088 */ lw $a3, 0x88($s0)
/* ED9000 802401E0 3C048024 */ lui $a0, %hi(D_80243170_EDBF90)
/* ED9004 802401E4 0C00973F */ jal func_80025CFC
/* ED9004 802401E4 0C00973F */ jal osSyncPrintf
/* ED9008 802401E8 24843170 */ addiu $a0, $a0, %lo(D_80243170_EDBF90)
/* ED900C 802401EC 8FBF002C */ lw $ra, 0x2c($sp)
/* ED9010 802401F0 8FB20028 */ lw $s2, 0x28($sp)

View File

@ -14,7 +14,7 @@ glabel func_80025F44
/* 134C 80025F4C 0080382D */ daddu $a3, $a0, $zero
/* 1350 80025F50 3C048009 */ lui $a0, %hi(D_80097D30)
/* 1354 80025F54 24847D30 */ addiu $a0, $a0, %lo(D_80097D30)
/* 1358 80025F58 0C00973F */ jal func_80025CFC
/* 1358 80025F58 0C00973F */ jal osSyncPrintf
/* 135C 80025F5C 00000000 */ nop
.L80025F60:
/* 1360 80025F60 080097D8 */ j .L80025F60

View File

@ -40,7 +40,7 @@ segments:
vram: 0x80025C00
subsegments:
- [0x1000, hasm, entry_point]
- [0x1060, c, 1060_len_310]
- [0x1060, c, is_debug]
- [0x1370, c, 1370_len_7d0]
- [0x1b40, c, main_loop]
- [0x3bf0, c, input]
@ -290,7 +290,7 @@ segments:
- [0x6FA70, data] # has scripts?
- [0x70E30, .data, battle/battle]
- [0x71430, data]
- [0x73130, .rodata, 1060_len_310]
- [0x73130, .rodata, is_debug]
- [0x73148, .rodata, main_loop]
- [0x73160, .rodata, 43F0]
- [0x73200, .rodata, curtains]

View File

@ -1,9 +1,9 @@
entry_point = 0x80025C00; // type:func rom:0x1000
func_80025C60 = 0x80025C60; // type:func rom:0x1060
func_80025CC0 = 0x80025CC0; // type:func rom:0x10C0
func_80025CFC = 0x80025CFC; // type:func rom:0x10FC
func_80025D38 = 0x80025D38; // type:func rom:0x1138
func_80025D74 = 0x80025D74; // type:func rom:0x1174
is_debug_init = 0x80025C60; // type:func rom:0x1060
printf = 0x80025CC0; // type:func rom:0x10C0
osSyncPrintf = 0x80025CFC; // type:func rom:0x10FC
rmonPrintf = 0x80025D38; // type:func rom:0x1138
is_debug_print = 0x80025D74; // type:func rom:0x1174
func_80025F44 = 0x80025F44; // type:func rom:0x1344
boot_main = 0x80025F70; // type:func rom:0x1370
gfxRetrace_Callback = 0x8002605C; // type:func rom:0x145C