summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDragorn421 <Dragorn421@users.noreply.github.com>2024-08-28 09:38:42 +0200
committerGitHub <noreply@github.com>2024-08-28 09:38:42 +0200
commit68818044db4f6c644ca8be80f0ad4b54a7587f44 (patch)
treec4fb993f82cc4513f5cd584aa7ba68b0965751ab /include
parentaa97586659dbd24174258e0437ab9411a9747d3d (diff)
[ntsc-1.2] Decompile fault.c (#2046)
* wip decomp ntsc-1.2 fault.c * more ntsc-1.2 fault.c * decompiled fault_v1.c * name fault_v1 functions, wip * try to clean up build system (two versions of the fault system coexisting) * cleanup * cleanup2 * fix build gc-eu-mq-dbg * match 2 more, ty anon * matched * review * more review * fixup spec * `(uintptr_t)ptr op int` instead of `ptr op (type*)int` * move fault.h out of global headers, properly include fault.h and versions.h * compile all fault_*.c files regardless of version by overriding FAULT_VERSION * n64 FaultMgr.framebuffer s32 -> u16* * FaultMgr.framebuffer -> FaultMgr.fb * make gc FaultMgr.fb u16* (yes, thats everything) * bss * fix Fault_Printf return type * noop FaultDrawer_SetFontColor, FaultDrawer_SetCharPad in fault_n64 * fault_color_ stuff is only for fault_gc * rm empty line in makefile * I guess `D_80105A90_unknown` is `[sg]TotalAllocFailures` * bss * `Fault_WaitInput` -> `Fault_WaitForInput` * use named fault funcs in pointers array * FAULT_OOT{N64,GC} -> FAULT_{N64,GC} * Apply suggestions from code review Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com> * review, sync fault_{gc,n64} * Apply `FPCSR_CE` suggestions from code review Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> --------- Co-authored-by: Derek Hensley <hensley.derek58@gmail.com> Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/fault.h44
-rw-r--r--include/padmgr.h7
-rw-r--r--include/variables.h2
-rw-r--r--include/versions.h8
-rw-r--r--include/z64.h1
5 files changed, 54 insertions, 8 deletions
diff --git a/include/fault.h b/include/fault.h
index df125487e..996f1f8d6 100644
--- a/include/fault.h
+++ b/include/fault.h
@@ -4,7 +4,9 @@
#include "ultra64.h"
#include "attributes.h"
#include "padmgr.h"
+#include "versions.h"
+#if FAULT_VERSION == FAULT_GC
// These are the same as the 3-bit ansi color codes
#define FAULT_COLOR_BLACK 0
#define FAULT_COLOR_RED 1
@@ -23,6 +25,7 @@
#define FAULT_ESC '\x1A'
#define FAULT_COLOR(n) "\x1A" FAULT_COLOR_EXPAND_AND_STRINGIFY(FAULT_COLOR_ ## n)
+#endif
typedef struct FaultClient {
/* 0x00 */ struct FaultClient* next;
@@ -31,11 +34,13 @@ typedef struct FaultClient {
/* 0x0C */ void* arg1;
} FaultClient; // size = 0x10
+#if FAULT_VERSION == FAULT_GC
typedef struct FaultAddrConvClient {
/* 0x00 */ struct FaultAddrConvClient* next;
/* 0x04 */ void* callback;
/* 0x08 */ void* arg;
} FaultAddrConvClient; // size = 0xC
+#endif
// Initialization
@@ -51,15 +56,32 @@ NORETURN void Fault_AddHungupAndCrash(const char* file, int line);
void Fault_AddClient(FaultClient* client, void* callback, void* arg0, void* arg1);
void Fault_RemoveClient(FaultClient* client);
+#if FAULT_VERSION == FAULT_GC
void Fault_AddAddrConvClient(FaultAddrConvClient* client, void* callback, void* arg);
void Fault_RemoveAddrConvClient(FaultAddrConvClient* client);
+#endif
// For use in Fault Client callbacks
-void Fault_WaitForInput(void);
-void Fault_FillScreenBlack(void);
void Fault_SetFrameBuffer(void* fb, u16 w, u16 h);
+void Fault_WaitForInput(void);
+
+#if FAULT_VERSION == FAULT_N64
+
+// Not implemented. Silently noop-ing is fine, these are not essential for functionality.
+#define FaultDrawer_SetFontColor(color) (void)0
+#define FaultDrawer_SetCharPad(padW, padH) (void)0
+
+void Fault_SetCursor(s32 x, s32 y);
+s32 Fault_Printf(const char* fmt, ...);
+void Fault_DrawText(s32 x, s32 y, const char* fmt, ...);
+#define FaultDrawer_SetCursor Fault_SetCursor
+#define FaultDrawer_Printf Fault_Printf
+#define FaultDrawer_DrawText Fault_DrawText
+
+#elif FAULT_VERSION == FAULT_GC
+
void FaultDrawer_SetForeColor(u16 color);
void FaultDrawer_SetBackColor(u16 color);
void FaultDrawer_SetFontColor(u16 color);
@@ -69,9 +91,19 @@ s32 FaultDrawer_VPrintf(const char* fmt, va_list args);
s32 FaultDrawer_Printf(const char* fmt, ...);
void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...);
+#endif
+
+#if FAULT_VERSION == FAULT_N64
+
+extern vs32 gFaultMsgId;
+
+#define FAULT_MSG_ID gFaultMsgId
+
+#elif FAULT_VERSION == FAULT_GC
+
typedef struct FaultMgr {
/* 0x000 */ OSThread thread;
- /* 0x1B0 */ char unk_1B0[0x600]; // probably an unused internal thread stack for `Fault_ClientRunTask`/`clientThreadSp`
+ /* 0x1B0 */ char unk_1B0[0x600];
/* 0x7B0 */ OSMesgQueue queue;
/* 0x7C8 */ OSMesg msg;
/* 0x7CC */ u8 exit;
@@ -84,10 +116,14 @@ typedef struct FaultMgr {
/* 0x7DC */ FaultAddrConvClient* addrConvClients;
/* 0x7E0 */ char unk_7E0[0x4];
/* 0x7E4 */ Input inputs[MAXCONTROLLERS];
- /* 0x844 */ void* fb;
+ /* 0x844 */ u16* fb;
/* 0x848 */ void* clientThreadSp;
} FaultMgr; // size = 0x850
extern FaultMgr gFaultMgr;
+#define FAULT_MSG_ID gFaultMgr.msgId
+
+#endif
+
#endif
diff --git a/include/padmgr.h b/include/padmgr.h
index 0e7be4cda..efd245c7d 100644
--- a/include/padmgr.h
+++ b/include/padmgr.h
@@ -3,6 +3,7 @@
#include "ultra64.h"
#include "irqmgr.h"
+#include "versions.h"
typedef enum ControllerPakType {
CONT_PAK_NONE,
@@ -50,9 +51,9 @@ void PadMgr_Init(PadMgr* padMgr, OSMesgQueue* serialEventQueue, IrqMgr* irqMgr,
// Fetching inputs
-// This function cannot be prototyped here without AVOID_UB because it is called incorrectly in fault.c (see bug in
-// `Fault_PadCallback`)
-#ifdef AVOID_UB
+// This function cannot be prototyped here in all configurations because it is called incorrectly in fault_gc.c
+// (see bug in `Fault_PadCallback`)
+#if FAULT_VERSION == FAULT_N64 || defined(AVOID_UB)
void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 gameRequest);
#endif
diff --git a/include/variables.h b/include/variables.h
index 87ac90bd9..739a76818 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -248,4 +248,6 @@ extern u64 gGfxSPTaskStack[SP_DRAM_STACK_SIZE64]; // 0x400 bytes
extern GfxPool gGfxPools[2]; // 0x24820 bytes
extern u8 gAudioHeap[0x38000]; // 0x38000 bytes
+extern u32 gTotalAllocFailures;
+
#endif
diff --git a/include/versions.h b/include/versions.h
index b135ae390..a000cf0bc 100644
--- a/include/versions.h
+++ b/include/versions.h
@@ -16,4 +16,12 @@
#define GC_EU_MQ 12
#define GC_JP_CE 13
+#define FAULT_N64 1 // in OoT N64
+#define FAULT_GC 2 // in OoT GC
+#if PLATFORM_N64
+#define FAULT_VERSION FAULT_N64
+#else
+#define FAULT_VERSION FAULT_GC
+#endif
+
#endif
diff --git a/include/z64.h b/include/z64.h
index 39325ad9a..b84ce02a1 100644
--- a/include/z64.h
+++ b/include/z64.h
@@ -52,7 +52,6 @@
#include "regs.h"
#include "irqmgr.h"
#include "padmgr.h"
-#include "fault.h"
#include "sched.h"
#include "rumble.h"
#include "mempak.h"