add FATAL_ERROR macros

This commit is contained in:
DizzyEggg
2025-05-16 09:21:41 +02:00
parent dc39fa4329
commit 4dd46d4a10
6 changed files with 18 additions and 95 deletions

View File

@@ -4,33 +4,6 @@
.global GroundSpriteFile_Text
GroundSpriteFile_Text: @ Text
.string "../ground/ground_sprite.c\0"
.align 2,0
.global GroundSprite_ExtendPaletteAdd_Text
GroundSprite_ExtendPaletteAdd_Text: @ ExtendPaletteAdd
.string "GroundSprite_ExtendPaletteAdd\0"
.align 2,0
.global gUnknown_8117858
gUnknown_8117858: @ 8117858
.4byte GroundSpriteFile_Text
.byte 0xF0, 0x03, 0x00, 0x00
.4byte GroundSprite_ExtendPaletteAdd_Text
.global gUnknown_8117864
gUnknown_8117864: @ 8117864
.string "extend palette buffer error %08x\0"
.align 2,0
.global gUnknown_8117888
gUnknown_8117888: @ 8117888
.4byte GroundSpriteFile_Text
.byte 0xF8, 0x03, 0x00, 0x00
.4byte GroundSprite_ExtendPaletteAdd_Text
.global gUnknown_8117894
gUnknown_8117894: @ 8117894
.string "extend palette %3d[%3d] %04x set %04x %04x\0"

View File

@@ -9,6 +9,13 @@ typedef struct DebugLocation
/* 0x8 */ const u8 *func;
} DebugLocation;
// Macros for easier FatalError handling. FATAL_ERROR should be used as it gets the file, line and function name from gcc, however for matching purposes we always explicitly use FATAL_ERROR_ARGS
#define DEBUG_LOC_PTR(file, line, func)((&((DebugLocation){file, line, func})))
#define FATAL_ERROR_ARGS(file, line, str, ...) FatalError(DEBUG_LOC_PTR(file, line, __func__), str, __VA_ARGS__ )
#define FATAL_ERROR(str, ...) FATAL_ERROR_ARGS(__FILE__, __LINE__, str, __VA_ARGS__)
void FatalError(const DebugLocation *debug, const char *text, ...) NORETURN;
void Log(u8 num, const u8 *text, ...);
void NDS_DebugInit(void);

View File

@@ -175,7 +175,3 @@ const struct GroundEventTableEntry gGroundEnterLookupTable[58] = {
{ 161, 57},
{ -1, 0},
};
ALIGNED(4) const u8 gScenarioCalcLogString[] = "SCENARIO CALC [%3d] %4d %4d -> %4d %4d";
ALIGNED(4) const u8 EventFlagFile_Text[] = "../main/event_flag.c";

View File

@@ -463,7 +463,7 @@ void ScenarioCalc(s16 param_1,s32 param_2,s32 param_3)
param_1_s32 = param_1;
GetScriptVarScenario(param_1_s32,&local_18,&local_14);
Log(6,gScenarioCalcLogString,param_1_s32,local_18,local_14,param_2,param_3); // SCENARIO CALC [%3d] %4d %4d -> %4d %4d
Log(6,"SCENARIO CALC [%3d] %4d %4d -> %4d %4d",param_1_s32,local_18,local_14,param_2,param_3);
if ((param_1_s32 == 3) && ((param_2 != local_18 || (param_3 != local_14)))) {
SetScriptVarValue(NULL,CLEAR_COUNT,0);
}
@@ -650,14 +650,6 @@ void sub_8001D88(void)
}
}
ALIGNED(4) static const u8 sFlagCalc_Text[] = "_FlagCalc";
static const DebugLocation sFlagCalcDebugLocation = {
EventFlagFile_Text,
0x551,
sFlagCalc_Text
};
// arm9.bin::0200EC08
s32 _FlagCalc(s32 param_1, s32 param_2, enum FlagCalcOperation operation)
{
@@ -687,18 +679,10 @@ s32 _FlagCalc(s32 param_1, s32 param_2, enum FlagCalcOperation operation)
case CALC_RANDOM:
return OtherRandInt(param_2);
default:
FatalError(&sFlagCalcDebugLocation,"event flag expansion error %d", operation); // event flag expansion error %d
FATAL_ERROR_ARGS("../main/event_flag.c", 1361, "event flag expansion error %d", operation);
}
}
ALIGNED(4) static const u8 sFlagJudge_Text[] = "_FlagJudge";
static const DebugLocation sFlagJudgeDebugLocation = {
EventFlagFile_Text,
0x57C,
sFlagJudge_Text
};
// arm9.bin::0200EAE4
bool8 _FlagJudge(s32 param_1, s32 param_2, enum FlagJudgeOperation operation)
{
@@ -726,7 +710,7 @@ bool8 _FlagJudge(s32 param_1, s32 param_2, enum FlagJudgeOperation operation)
case JUDGE_BIT_SET:
return param_1 >> (param_2) & 1;
default:
FatalError(&sFlagJudgeDebugLocation,"event flag rule error %d", operation); // event flag rule error %d
FATAL_ERROR_ARGS("../main/event_flag.c", 1404, "event flag rule error %d", operation);
}
}

View File

@@ -455,9 +455,6 @@ void sub_80A69FC(struct UnkGroundSpriteStruct *ptr)
}
}
extern const DebugLocation gUnknown_8117858;
extern const DebugLocation gUnknown_8117888;
void GroundSprite_ExtendPaletteAdd(struct UnkGroundSpriteStruct *ptr, u16 a1)
{
OpenedFile *file;
@@ -497,7 +494,7 @@ void GroundSprite_ExtendPaletteAdd(struct UnkGroundSpriteStruct *ptr, u16 a1)
r8 = 1;
sub108Ptr = &gUnknown_3001B7C->unk108[1];
if (sub108Ptr->unk2 > 0) {
FatalError(&gUnknown_8117858, gUnknown_8117864, a1);
FATAL_ERROR_ARGS("../ground/ground_sprite.c", 1008, "extend palette buffer error %08x", a1);
}
}
else {
@@ -510,7 +507,7 @@ void GroundSprite_ExtendPaletteAdd(struct UnkGroundSpriteStruct *ptr, u16 a1)
}
if (r8 >= UNK_3001B7C_SUB108_COUNT) {
FatalError(&gUnknown_8117888, gUnknown_8117864, a1);
FATAL_ERROR_ARGS("../ground/ground_sprite.c", 1016, "extend palette buffer error %08x", a1);
}
}

View File

@@ -71,8 +71,6 @@ static HeapDescriptor *DoCreateSubHeap(struct unkMemoryStruct *a, u32 b);
static void *DoAlloc(HeapDescriptor *heap, s32 size, u32 a2);
static void InitHeapInternal(void);
ALIGNED(4) static const char sFileNameText[] = "../system/memory_locate.c";
void InitHeap(void)
{
InitHeapInternal();
@@ -325,14 +323,6 @@ static s32 MemorySearchFromBack(HeapDescriptor *heap, s32 atb, s32 size)
return -1;
}
ALIGNED(4) static const char sText_LocateSetFront[] = "_LocateSetFront";
static const DebugLocation sLocateSetFrontDebugLocation =
{
.file = sFileNameText,
.line = 581,
.func = sText_LocateSetFront
};
static struct HeapFreeListElement * _LocateSetFront(HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group)
{
s32 i;
@@ -352,7 +342,7 @@ static struct HeapFreeListElement * _LocateSetFront(HeapDescriptor *heap, s32 in
heap->freeCount++;
if (heap->freeCount > heap->freeListLength) {
FatalError(&sLocateSetFrontDebugLocation, "Memory Locate sprit max over [%3d/%3d]", heap->freeCount, heap->freeListLength);
FATAL_ERROR_ARGS("../system/memory_locate.c", 581, "Memory Locate sprit max over [%3d/%3d]", heap->freeCount, heap->freeListLength);
}
block = &heap->freeList[index + 1];
@@ -369,14 +359,6 @@ static struct HeapFreeListElement * _LocateSetFront(HeapDescriptor *heap, s32 in
return curr;
}
ALIGNED(4) static const char sText_LocateSetBack[] = "_LocateSetBack";
static const DebugLocation sLocateSetBackDebugLocation =
{
.file = sFileNameText,
.line = 673,
.func = sText_LocateSetBack
};
static struct HeapFreeListElement * _LocateSetBack(HeapDescriptor *heap, s32 index, s32 atb, s32 size, s32 group)
{
s32 i;
@@ -397,7 +379,7 @@ static struct HeapFreeListElement * _LocateSetBack(HeapDescriptor *heap, s32 ind
heap->freeCount++;
if (heap->freeCount > heap->freeListLength) {
FatalError(&sLocateSetBackDebugLocation, "Memory Locate sprit max over [%3d/%3d]", heap->freeCount, heap->freeListLength);
FATAL_ERROR_ARGS("../system/memory_locate.c", 673, "Memory Locate sprit max over [%3d/%3d]", heap->freeCount, heap->freeListLength);
}
curr->block.size -= sizeAligned;
@@ -415,14 +397,6 @@ static struct HeapFreeListElement * _LocateSetBack(HeapDescriptor *heap, s32 ind
return curr;
}
ALIGNED(4) static const char sText_LocateSet[] = "_LocateSet";
static const DebugLocation sLocateSetDebugLocation =
{
.file = sFileNameText,
.line = 812,
.func = sText_LocateSet
};
static void * _LocateSet(HeapDescriptor *heap, s32 size, s32 group)
{
s32 index;
@@ -454,9 +428,8 @@ static void * _LocateSet(HeapDescriptor *heap, s32 size, s32 group)
}
error:
FatalError(&sLocateSetDebugLocation,
"Memroy LocateSet [%p] buffer %8x size can't locate\n atb %02x grp %3d ",
heap, size, atb, group);
FATAL_ERROR_ARGS("../system/memory_locate.c", 812, "Memroy LocateSet [%p] buffer %8x size can't locate\n atb %02x grp %3d ",
heap, size, atb, group);
}
// arm9.bin::02010DE0
@@ -470,8 +443,6 @@ void MemoryFree(void *a)
DoFree(&sMainHeapDescriptor, a);
}
ALIGNED(4) static const char sText_MemoryLocate_LocalCreate[] = "MemoryLocate_LocalCreate";
UNUSED static HeapDescriptor *MemoryLocate_LocalCreate(HeapDescriptor *parentHeap, u32 size, u32 param_3, u32 group)
{
s32 index;
@@ -485,12 +456,7 @@ UNUSED static HeapDescriptor *MemoryLocate_LocalCreate(HeapDescriptor *parentHea
index = MemorySearchFromBack(parentHeap, 9, size);
if (index < 0) {
static const DebugLocation debugInfo = {
.file = sFileNameText,
.line = 1109,
.func = sText_MemoryLocate_LocalCreate
};
FatalError(&debugInfo, "Memroy LocalCreate buffer %08x size can't locate", size);
FATAL_ERROR_ARGS("../system/memory_locate.c", 1109, "Memroy LocalCreate buffer %08x size can't locate", size);
}
foundSet = _LocateSetBack(parentHeap, index, 9, size, group);
@@ -609,4 +575,4 @@ UNUSED static void nullsub_141(void)
UNUSED static void nullsub_142(void)
{
}
}