1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-02-04 02:44:24 +00:00
oot/include/fault.h
Dragorn421 68818044db
[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>
2024-08-28 09:38:42 +02:00

129 lines
3.5 KiB
C

#ifndef FAULT_H
#define FAULT_H
#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
#define FAULT_COLOR_GREEN 2
#define FAULT_COLOR_YELLOW 3
#define FAULT_COLOR_BLUE 4
#define FAULT_COLOR_MAGENTA 5
#define FAULT_COLOR_CYAN 6
#define FAULT_COLOR_WHITE 7
// Additional color codes
#define FAULT_COLOR_DARK_GRAY 8
#define FAULT_COLOR_LIGHT_GRAY 9
#define FAULT_COLOR_STRINGIFY(s) #s
#define FAULT_COLOR_EXPAND_AND_STRINGIFY(s) FAULT_COLOR_STRINGIFY(s)
#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;
/* 0x04 */ void* callback;
/* 0x08 */ void* arg0;
/* 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
void Fault_Init(void);
// Fatal Errors
NORETURN void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2);
NORETURN void Fault_AddHungupAndCrash(const char* file, int line);
// Client Registration
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_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);
void FaultDrawer_SetCharPad(s8 padW, s8 padH);
void FaultDrawer_SetCursor(s32 x, s32 y);
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];
/* 0x7B0 */ OSMesgQueue queue;
/* 0x7C8 */ OSMesg msg;
/* 0x7CC */ u8 exit;
/* 0x7CD */ u8 msgId;
/* 0x7CE */ u8 faultHandlerEnabled;
/* 0x7CF */ u8 autoScroll;
/* 0x7D0 */ OSThread* faultedThread;
/* 0x7D4 */ void (*padCallback)(Input* inputs);
/* 0x7D8 */ FaultClient* clients;
/* 0x7DC */ FaultAddrConvClient* addrConvClients;
/* 0x7E0 */ char unk_7E0[0x4];
/* 0x7E4 */ Input inputs[MAXCONTROLLERS];
/* 0x844 */ u16* fb;
/* 0x848 */ void* clientThreadSp;
} FaultMgr; // size = 0x850
extern FaultMgr gFaultMgr;
#define FAULT_MSG_ID gFaultMgr.msgId
#endif
#endif