mirror of
https://github.com/zeldaret/af.git
synced 2026-10-01 23:42:04 -04:00
Fault + Fault_drawer (#77)
* Fault OK * fault_drawer OK * Cleanup * Cleanup pt 2 * Forgot to save * PR
This commit is contained in:
@@ -226,6 +226,9 @@ build/src/boot/libc64/%.o: OPTFLAGS := -O2
|
||||
|
||||
# per-file flags
|
||||
|
||||
build/src/boot/fault.o: CFLAGS += -trapuv
|
||||
build/src/boot/fault_drawer.o: CFLAGS += -trapuv
|
||||
|
||||
# cc & asm-processor
|
||||
build/src/%.o: CC := $(ASM_PROC) $(ASM_PROC_FLAGS) $(CC) -- $(AS) $(ASFLAGS) --
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
// extern UNK_TYPE D_FLT_8003BBCC_jp;
|
||||
extern OSPiHandle* carthandle; // TODO: Determine where this goes
|
||||
|
||||
// extern UNK_TYPE D_8003BBF0_jp;
|
||||
// extern UNK_TYPE D_8003BC38_jp;
|
||||
// extern UNK_TYPE D_8003BC50_jp;
|
||||
// extern UNK_TYPE D_8003BC90_jp;
|
||||
// extern UNK_TYPE D_8003BC94_jp;
|
||||
@@ -245,11 +243,6 @@ extern OSPiHandle* carthandle; // TODO: Determine where this goes
|
||||
// extern UNK_TYPE B_80040AC8_jp;
|
||||
// extern UNK_TYPE B_80040ACC_jp;
|
||||
// extern UNK_TYPE B_80040AD0_jp;
|
||||
// extern UNK_TYPE B_80040AE0_jp;
|
||||
// extern UNK_TYPE B_80040AE4_jp;
|
||||
// extern UNK_TYPE B_80040AE8_jp;
|
||||
// extern UNK_TYPE B_800410E8_jp;
|
||||
// extern UNK_TYPE B_80041108_jp;
|
||||
// extern UNK_TYPE B_800418D6_jp;
|
||||
extern struct_800418D8* B_800418D8_jp;
|
||||
// extern UNK_TYPE B_80041960_jp;
|
||||
|
||||
+67
-59
@@ -2,8 +2,31 @@
|
||||
#define FAULT_H
|
||||
|
||||
#include "ultra64.h"
|
||||
#include "unk.h"
|
||||
#include "attributes.h"
|
||||
#include "libc/stdarg.h"
|
||||
#include "libc/stdint.h"
|
||||
#include "libu64/pad.h"
|
||||
#include "stack.h"
|
||||
|
||||
// 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)
|
||||
|
||||
|
||||
typedef void (*FaultClientCallback)(void*, void*);
|
||||
@@ -26,67 +49,52 @@ typedef struct FaultAddrConvClient {
|
||||
/* 0x8 */ void* arg;
|
||||
} FaultAddrConvClient; // size = 0xC
|
||||
|
||||
// void Fault_SleepImpl();
|
||||
// void Fault_ClientProcessThread();
|
||||
// void Fault_ClientRunTask();
|
||||
// void Fault_ProcessClient();
|
||||
void Fault_AddClient(FaultClient* client, FaultClientCallback callback, void* arg0, void* arg1);
|
||||
void Fault_RemoveClient(FaultClient* client);
|
||||
void Fault_AddAddrConvClient(FaultAddrConvClient* client, FaultAddrConvClientCallback callback, void* arg);
|
||||
void Fault_RemoveAddrConvClient(FaultAddrConvClient* client);
|
||||
// void Fault_ConvertAddress();
|
||||
// void Fault_Sleep();
|
||||
// void Fault_PadCallback();
|
||||
// void Fault_UpdatePadImpl();
|
||||
// void Fault_WaitForInputImpl();
|
||||
// void Fault_WaitForInput();
|
||||
// void Fault_DrawRec();
|
||||
// void Fault_FillScreenBlack();
|
||||
// void Fault_FillScreenRed();
|
||||
// void Fault_DrawCornerRec();
|
||||
// void Fault_PrintFReg();
|
||||
// void Fault_LogFReg();
|
||||
// void Fault_PrintFPCSR();
|
||||
// void Fault_LogFPCSR();
|
||||
// void Fault_PrintThreadContext();
|
||||
// void Fault_LogThreadContext();
|
||||
// void Fault_FindFaultedThread();
|
||||
// void Fault_Wait5Seconds();
|
||||
// void Fault_WaitForButtonCombo();
|
||||
// void Fault_DrawMemDumpContents();
|
||||
// void Fault_DrawMemDump();
|
||||
// void Fault_WalkStack();
|
||||
// void Fault_DrawStackTrace();
|
||||
// void Fault_LogStackTrace();
|
||||
// void Fault_ResumeThread();
|
||||
// void Fault_DisplayFrameBuffer();
|
||||
// void Fault_ProcessClients();
|
||||
// void Fault_UpdatePad();
|
||||
// void Fault_ThreadEntry();
|
||||
// void Fault_SetFrameBuffer();
|
||||
// void Fault_Init();
|
||||
// void Fault_HungupFaultClient();
|
||||
NORETURN void Fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2);
|
||||
// NORETURN void Fault_AddHungupAndCrash();
|
||||
typedef struct FaultMgr {
|
||||
/* 0x000 */ OSThread thread;
|
||||
/* 0x1B0 */ STACK(stack, 0x600); // probably an unused internal thread stack for `fault_ClientRunTask`/`clientThreadSp`
|
||||
/* 0x7B0 */ OSMesgQueue queue;
|
||||
/* 0x7C8 */ OSMesg msg[1];
|
||||
/* 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 */ UNK_TYPE1 unk_7E0[0x4];
|
||||
/* 0x7E4 */ Input inputs[MAXCONTROLLERS];
|
||||
/* 0x844 */ void* fb;
|
||||
/* 0x848 */ void* clientThreadSp;
|
||||
} FaultMgr; // size = 0x850
|
||||
|
||||
// void FaultDrawer_SetOsSyncPrintfEnabled();
|
||||
// void FaultDrawer_DrawRecImpl();
|
||||
// void FaultDrawer_DrawChar();
|
||||
// void FaultDrawer_ColorToPrintColor();
|
||||
// void FaultDrawer_UpdatePrintColor();
|
||||
// void FaultDrawer_SetForeColor();
|
||||
// void FaultDrawer_SetBackColor();
|
||||
|
||||
void fault_AddClient(FaultClient* client, FaultClientCallback callback, void* arg0, void* arg1);
|
||||
void fault_RemoveClient(FaultClient* client);
|
||||
void fault_AddressConverterAddClient(FaultAddrConvClient* client, FaultAddrConvClientCallback callback, void* arg);
|
||||
void fault_AddressConverterRemoveClient(FaultAddrConvClient* client);
|
||||
void fault_WaitForInput(void);
|
||||
void fault_FillScreenBlack(void);
|
||||
void fault_SetFrameBuffer(void* fb, u16 w, u16 h);
|
||||
void fault_Init(void);
|
||||
NORETURN void fault_AddHungupAndCrashImpl(const char* exp1, const char* exp2);
|
||||
NORETURN void fault_AddHungupAndCrash(const char* file, s32 line);
|
||||
|
||||
void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled);
|
||||
void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color);
|
||||
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 arg0, s32 arg1);
|
||||
// void FaultDrawer_FillScreen();
|
||||
// void FaultDrawer_PrintCallback();
|
||||
// void FaultDrawer_VPrintf();
|
||||
void FaultDrawer_Printf(const char* fmt, ...);
|
||||
// void FaultDrawer_DrawText();
|
||||
// void FaultDrawer_SetDrawerFB();
|
||||
// void FaultDrawer_SetInputCallback();
|
||||
// void FaultDrawer_WritebackFBDCache();
|
||||
// void FaultDrawer_Init();
|
||||
void FaultDrawer_SetCursor(s32 x, s32 y);
|
||||
void FaultDrawer_FillScreen(void);
|
||||
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, ...);
|
||||
void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h);
|
||||
void FaultDrawer_SetInputCallback(void (*callback)(void));
|
||||
void FaultDrawer_Init(void);
|
||||
|
||||
extern FaultMgr gFaultMgr;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define M_THREAD_H
|
||||
|
||||
#define M_THREAD_ID_IDLE 1
|
||||
#define M_THREAD_ID_FAULT 2
|
||||
#define M_THREAD_ID_MAIN 3
|
||||
#define M_THREAD_ID_DMAMGR 8
|
||||
#define M_THREAD_ID_IRQMGR 9
|
||||
@@ -10,6 +11,8 @@
|
||||
#define M_PRIORITY_IDLE 12
|
||||
#define M_PRIORITY_MAIN 12
|
||||
#define M_PRIORITY_DMAMGR 17
|
||||
#define M_PRIORITY_FAULT_CLIENT (OS_PRIORITY_APPMAX - 1)
|
||||
#define M_PRIORITY_FAULT OS_PRIORITY_APPMAX
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef TERMINAL_H
|
||||
#define TERMINAL_H
|
||||
|
||||
// VT_: Helper macros for printing colored text to terminals, using ANSI escape codes
|
||||
// VT stands for Virtual Terminal
|
||||
|
||||
// 3-bit color codes
|
||||
#define VT_COLOR_BLACK 0
|
||||
#define VT_COLOR_RED 1
|
||||
#define VT_COLOR_GREEN 2
|
||||
#define VT_COLOR_YELLOW 3
|
||||
#define VT_COLOR_BLUE 4
|
||||
#define VT_COLOR_MAGENTA 5
|
||||
#define VT_COLOR_CYAN 6
|
||||
#define VT_COLOR_WHITE 7
|
||||
|
||||
#define VT_COLOR_FOREGROUND 3
|
||||
#define VT_COLOR_BACKGROUND 4
|
||||
|
||||
#define VT_COLOR_EXPAND0(type, color) #type #color
|
||||
#define VT_COLOR_EXPAND1(type, color) VT_COLOR_EXPAND0(type, color)
|
||||
#define VT_COLOR(type, color) VT_COLOR_EXPAND1(VT_COLOR_##type, VT_COLOR_##color)
|
||||
|
||||
#define VT_ESC "\x1b"
|
||||
#define VT_CSI "["
|
||||
#define VT_CUP(x, y) VT_ESC VT_CSI y ";" x "H"
|
||||
#define VT_ED(n) VT_ESC VT_CSI #n "J"
|
||||
#define VT_SGR(n) VT_ESC VT_CSI n "m"
|
||||
|
||||
// Add more macros if necessary
|
||||
#define VT_COL(back, fore) VT_SGR(VT_COLOR(BACKGROUND, back) ";" VT_COLOR(FOREGROUND, fore))
|
||||
#define VT_FGCOL(color) VT_SGR(VT_COLOR(FOREGROUND, color))
|
||||
#define VT_BGCOL(color) VT_SGR(VT_COLOR(BACKGROUND, color))
|
||||
#define VT_RST VT_SGR("")
|
||||
#define VT_CLS VT_ED(2)
|
||||
|
||||
// ASCII BEL character, plays an alert tone
|
||||
#define BEL '\a'
|
||||
|
||||
#endif
|
||||
@@ -46,48 +46,48 @@ osSyncPrintfUnused = 0x800272C0; // type:func
|
||||
osSyncPrintf = 0x800272DC; // type:func
|
||||
rmonPrintf = 0x800272F8; // type:func
|
||||
|
||||
Fault_SleepImpl = 0x80027320; // type:func
|
||||
Fault_ClientProcessThread = 0x80027390; // type:func
|
||||
Fault_ClientRunTask = 0x80027404; // type:func
|
||||
Fault_ProcessClient = 0x80027588; // type:func
|
||||
Fault_AddClient = 0x800275DC; // type:func
|
||||
Fault_RemoveClient = 0x800276C0; // type:func
|
||||
Fault_AddAddrConvClient = 0x800277B8; // type:func
|
||||
Fault_RemoveAddrConvClient = 0x80027890; // type:func
|
||||
Fault_ConvertAddress = 0x80027988; // type:func
|
||||
Fault_Sleep = 0x80027A3C; // type:func
|
||||
Fault_PadCallback = 0x80027A78; // type:func
|
||||
Fault_UpdatePadImpl = 0x80027AB4; // type:func
|
||||
Fault_WaitForInputImpl = 0x80027B00; // type:func
|
||||
Fault_WaitForInput = 0x80027C4C; // type:func
|
||||
Fault_DrawRec = 0x80027C98; // type:func
|
||||
Fault_FillScreenBlack = 0x80027CF8; // type:func
|
||||
Fault_FillScreenRed = 0x80027D4C; // type:func
|
||||
Fault_DrawCornerRec = 0x80027DA0; // type:func
|
||||
Fault_PrintFReg = 0x80027DF4; // type:func
|
||||
Fault_LogFReg = 0x80027EA0; // type:func
|
||||
Fault_PrintFPCSR = 0x80027F50; // type:func
|
||||
Fault_LogFPCSR = 0x80027FF4; // type:func
|
||||
Fault_PrintThreadContext = 0x8002808C; // type:func
|
||||
Fault_LogThreadContext = 0x800283A8; // type:func
|
||||
Fault_FindFaultedThread = 0x800286A4; // type:func
|
||||
Fault_Wait5Seconds = 0x8002872C; // type:func
|
||||
Fault_WaitForButtonCombo = 0x800287BC; // type:func
|
||||
Fault_DrawMemDumpContents = 0x80028A88; // type:func
|
||||
Fault_DrawMemDump = 0x80028BF4; // type:func
|
||||
Fault_WalkStack = 0x80028DF8; // type:func
|
||||
Fault_DrawStackTrace = 0x80028F88; // type:func
|
||||
Fault_LogStackTrace = 0x80029108; // type:func
|
||||
Fault_ResumeThread = 0x80029278; // type:func
|
||||
Fault_DisplayFrameBuffer = 0x800292F4; // type:func
|
||||
Fault_ProcessClients = 0x800293B4; // type:func
|
||||
Fault_UpdatePad = 0x80029494; // type:func
|
||||
Fault_ThreadEntry = 0x800294D0; // type:func
|
||||
Fault_SetFrameBuffer = 0x80029830; // type:func
|
||||
Fault_Init = 0x80029884; // type:func
|
||||
Fault_HungupFaultClient = 0x800299B8; // type:func
|
||||
Fault_AddHungupAndCrashImpl = 0x80029AB4; // type:func
|
||||
Fault_AddHungupAndCrash = 0x80029B0C; // type:func
|
||||
fault_SleepImpl = 0x80027320; // type:func
|
||||
fault_ClientProcessThread = 0x80027390; // type:func
|
||||
fault_ClientRunTask = 0x80027404; // type:func
|
||||
fault_ProcessClient = 0x80027588; // type:func
|
||||
fault_AddClient = 0x800275DC; // type:func
|
||||
fault_RemoveClient = 0x800276C0; // type:func
|
||||
fault_AddressConverterAddClient = 0x800277B8; // type:func
|
||||
fault_AddressConverterRemoveClient = 0x80027890; // type:func
|
||||
fault_ConvertAddress = 0x80027988; // type:func
|
||||
fault_Sleep = 0x80027A3C; // type:func
|
||||
fault_PadCallback = 0x80027A78; // type:func
|
||||
fault_UpdatePadImpl = 0x80027AB4; // type:func
|
||||
fault_WaitForInputImpl = 0x80027B00; // type:func
|
||||
fault_WaitForInput = 0x80027C4C; // type:func
|
||||
fault_DrawRec = 0x80027C98; // type:func
|
||||
fault_FillScreenBlack = 0x80027CF8; // type:func
|
||||
fault_FillScreenRed = 0x80027D4C; // type:func
|
||||
fault_DrawCornerRec = 0x80027DA0; // type:func
|
||||
fault_PrintFReg = 0x80027DF4; // type:func
|
||||
fault_LogFReg = 0x80027EA0; // type:func
|
||||
fault_PrintFPCSR = 0x80027F50; // type:func
|
||||
fault_LogFPCSR = 0x80027FF4; // type:func
|
||||
fault_PrintThreadContext = 0x8002808C; // type:func
|
||||
fault_LogThreadContext = 0x800283A8; // type:func
|
||||
FindFaultedThread = 0x800286A4; // type:func
|
||||
fault_Wait5Seconds = 0x8002872C; // type:func
|
||||
fault_WaitForButtonCombo = 0x800287BC; // type:func
|
||||
fault_DrawMemDumpContents = 0x80028A88; // type:func
|
||||
fault_DrawMemDump = 0x80028BF4; // type:func
|
||||
fault_WalkStack = 0x80028DF8; // type:func
|
||||
fault_DrawStackTrace = 0x80028F88; // type:func
|
||||
fault_LogStackTrace = 0x80029108; // type:func
|
||||
fault_ResumeThread = 0x80029278; // type:func
|
||||
fault_DisplayFrameBuffer = 0x800292F4; // type:func
|
||||
fault_ProcessClients = 0x800293B4; // type:func
|
||||
fault_UpdatePad = 0x80029494; // type:func
|
||||
fault_ThreadEntry = 0x800294D0; // type:func
|
||||
fault_SetFrameBuffer = 0x80029830; // type:func
|
||||
fault_Init = 0x80029884; // type:func
|
||||
fault_HungupFaultClient = 0x800299B8; // type:func
|
||||
fault_AddHungupAndCrashImpl = 0x80029AB4; // type:func
|
||||
fault_AddHungupAndCrash = 0x80029B0C; // type:func
|
||||
|
||||
FaultDrawer_SetOsSyncPrintfEnabled = 0x80029B70; // type:func
|
||||
FaultDrawer_DrawRecImpl = 0x80029B80; // type:func
|
||||
@@ -272,8 +272,8 @@ gViConfigXScale = 0x8003BBC8; // type:f32
|
||||
gViConfigYScale = 0x8003BBCC; // type:f32
|
||||
carthandle = 0x8003BBD0; //
|
||||
gDmaMgrDmaBuffSize = 0x8003BBE0; //
|
||||
D_8003BBF0_jp = 0x8003BBF0; //
|
||||
D_8003BC38_jp = 0x8003BC38; //
|
||||
sExceptionNames = 0x8003BBF0; //
|
||||
sFpExceptionNames = 0x8003BC38; //
|
||||
D_8003BC50_jp = 0x8003BC50; //
|
||||
|
||||
D_8003BC90_jp = 0x8003BC90; // size:0x4
|
||||
@@ -458,7 +458,7 @@ RO_STR_8003DE00_jp = 0x8003DE00; // type:asciz
|
||||
RO_STR_8003DE04_jp = 0x8003DE04; // type:asciz
|
||||
RO_STR_8003DE0C_jp = 0x8003DE0C; // type:asciz
|
||||
jtbl_8003DE1C_jp = 0x8003DE1C; // type:jtbl
|
||||
RO_8003DE50_jp = 0x8003DE50; //
|
||||
sFaultDrawerFont = 0x8003DE50; //
|
||||
RO_STR_8003E250_jp = 0x8003E250; // type:asciz
|
||||
RO_STR_8003E254_jp = 0x8003E254; // type:asciz
|
||||
RO_STR_8003E25C_jp = 0x8003E25C; // type:asciz
|
||||
@@ -545,21 +545,14 @@ B_80040AC4_jp = 0x80040AC4; //
|
||||
B_80040AC8_jp = 0x80040AC8; //
|
||||
B_80040ACC_jp = 0x80040ACC; //
|
||||
B_80040AD0_jp = 0x80040AD0; //
|
||||
B_80040AE0_jp = 0x80040AE0; //
|
||||
B_80040AE4_jp = 0x80040AE4; // type:u8
|
||||
B_80040AE8_jp = 0x80040AE8; //
|
||||
B_800410E8_jp = 0x800410E8; //
|
||||
B_80041108_jp = 0x80041108; // type:u8
|
||||
B_800418D6_jp = 0x800418D6; // type:s8
|
||||
B_800418D8_jp = 0x800418D8; //
|
||||
B_80041960_jp = 0x80041960; // type:s8
|
||||
B_80041964_jp = 0x80041964; // type:u16
|
||||
B_80041970_jp = 0x80041970; // type:u16
|
||||
B_80041972_jp = 0x80041972; // type:u16
|
||||
B_80041980_jp = 0x80041980; // type:u16
|
||||
B_80041982_jp = 0x80041982; // type:u16
|
||||
B_80041995_jp = 0x80041995; // type:s8
|
||||
B_80041998_jp = 0x80041998; //
|
||||
|
||||
sFaultInstance = 0x80040AE0; //
|
||||
sFaultAwaitingInput = 0x80040AE4; // type:u8
|
||||
sFaultStack = 0x80040AE8; //
|
||||
sFaultThreadInfo = 0x800410E8; //
|
||||
gFaultMgr = 0x80041108; // size:0x850
|
||||
|
||||
sFaultDrawer = 0x80041960; // size:0x3C
|
||||
|
||||
__gfxprint_default_flags = 0x800419A0; // type:u8 size:0x1
|
||||
|
||||
|
||||
+1333
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,318 @@
|
||||
/**
|
||||
* @file fault_drawer.c
|
||||
*
|
||||
* Implements routines for drawing text with a fixed font directly to a framebuffer, used in displaying
|
||||
* the crash screen implemented by fault.c
|
||||
*/
|
||||
#include "fault.h"
|
||||
#include "macros.h"
|
||||
#include "libc64/aprintf.h"
|
||||
#include "libc/stdarg.h"
|
||||
#include "libc/stdbool.h"
|
||||
#include "terminal.h"
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ u16* fb;
|
||||
/* 0x04 */ u16 w;
|
||||
/* 0x06 */ u16 h;
|
||||
/* 0x08 */ u16 yStart;
|
||||
/* 0x0A */ u16 yEnd;
|
||||
/* 0x0C */ u16 xStart;
|
||||
/* 0x0E */ u16 xEnd;
|
||||
/* 0x10 */ u16 foreColor;
|
||||
/* 0x12 */ u16 backColor;
|
||||
/* 0x14 */ u16 cursorX;
|
||||
/* 0x16 */ u16 cursorY;
|
||||
/* 0x18 */ const u32* fontData;
|
||||
/* 0x1C */ u8 charW;
|
||||
/* 0x1D */ u8 charH;
|
||||
/* 0x1E */ s8 charWPad;
|
||||
/* 0x1F */ s8 charHPad;
|
||||
/* 0x20 */ u16 printColors[10];
|
||||
/* 0x34 */ u8 escCode; // bool
|
||||
/* 0x35 */ u8 osSyncPrintfEnabled;
|
||||
/* 0x38 */ void (*inputCallback)(void);
|
||||
} FaultDrawer; // size = 0x3C
|
||||
|
||||
// TODO: Extract sFaultDrawerFont
|
||||
extern const u32 sFaultDrawerFont[];
|
||||
#pragma GLOBAL_ASM("asm/jp/nonmatchings/boot/fault_drawer/sFaultDrawerFont.s")
|
||||
|
||||
#define FAULT_DRAWER_CURSOR_X 22
|
||||
#define FAULT_DRAWER_CURSOR_Y 16
|
||||
|
||||
FaultDrawer sFaultDrawerDefault = {
|
||||
(u16*)(PHYS_TO_K0(0x400000) - sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])),
|
||||
SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT,
|
||||
FAULT_DRAWER_CURSOR_Y,
|
||||
SCREEN_HEIGHT - FAULT_DRAWER_CURSOR_Y - 1,
|
||||
FAULT_DRAWER_CURSOR_X,
|
||||
SCREEN_WIDTH - FAULT_DRAWER_CURSOR_X - 1,
|
||||
GPACK_RGBA5551(255, 255, 255, 1),
|
||||
GPACK_RGBA5551(0, 0, 0, 0),
|
||||
FAULT_DRAWER_CURSOR_X,
|
||||
FAULT_DRAWER_CURSOR_Y,
|
||||
sFaultDrawerFont,
|
||||
8,
|
||||
8,
|
||||
0,
|
||||
0,
|
||||
{
|
||||
GPACK_RGBA5551(0, 0, 0, 1),
|
||||
GPACK_RGBA5551(255, 0, 0, 1),
|
||||
GPACK_RGBA5551(0, 255, 0, 1),
|
||||
GPACK_RGBA5551(255, 255, 0, 1),
|
||||
GPACK_RGBA5551(0, 0, 255, 1),
|
||||
GPACK_RGBA5551(255, 0, 255, 1),
|
||||
GPACK_RGBA5551(0, 255, 255, 1),
|
||||
GPACK_RGBA5551(255, 255, 255, 1),
|
||||
GPACK_RGBA5551(120, 120, 120, 1),
|
||||
GPACK_RGBA5551(176, 176, 176, 1),
|
||||
},
|
||||
false,
|
||||
false,
|
||||
NULL,
|
||||
};
|
||||
|
||||
FaultDrawer sFaultDrawer;
|
||||
|
||||
void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) {
|
||||
sFaultDrawer.osSyncPrintfEnabled = enabled;
|
||||
}
|
||||
|
||||
void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color) {
|
||||
u16* fb;
|
||||
s32 x;
|
||||
s32 y;
|
||||
s32 xDiff = sFaultDrawer.w - xStart;
|
||||
s32 yDiff = sFaultDrawer.h - yStart;
|
||||
s32 xSize = xEnd - xStart + 1;
|
||||
s32 ySize = yEnd - yStart + 1;
|
||||
|
||||
if ((xDiff > 0) && (yDiff > 0)) {
|
||||
if (xDiff < xSize) {
|
||||
xSize = xDiff;
|
||||
}
|
||||
|
||||
if (yDiff < ySize) {
|
||||
ySize = yDiff;
|
||||
}
|
||||
|
||||
fb = sFaultDrawer.fb + sFaultDrawer.w * yStart + xStart;
|
||||
for (y = 0; y < ySize; y++) {
|
||||
for (x = 0; x < xSize; x++) {
|
||||
*fb++ = color;
|
||||
}
|
||||
fb += sFaultDrawer.w - xSize;
|
||||
}
|
||||
|
||||
osWritebackDCacheAll();
|
||||
}
|
||||
}
|
||||
|
||||
void FaultDrawer_DrawChar(char c) {
|
||||
FaultDrawer* faultDrawer = &sFaultDrawer;
|
||||
s32 x;
|
||||
s32 y;
|
||||
u32 data;
|
||||
s32 cursorX = sFaultDrawer.cursorX;
|
||||
s32 cursorY = sFaultDrawer.cursorY;
|
||||
s32 shift = c % 4;
|
||||
const u32* dataPtr = &faultDrawer->fontData[((c / 8) * 16) + ((c & 4) >> 2)];
|
||||
u16* fb = sFaultDrawer.fb + (sFaultDrawer.w * cursorY) + cursorX;
|
||||
|
||||
if ((sFaultDrawer.xStart <= cursorX) && ((sFaultDrawer.charW + cursorX - 1) <= sFaultDrawer.xEnd) &&
|
||||
(sFaultDrawer.yStart <= cursorY) && ((sFaultDrawer.charH + cursorY - 1) <= sFaultDrawer.yEnd)) {
|
||||
for (y = 0; y < sFaultDrawer.charH; y++) {
|
||||
u32 mask = 0x10000000 << shift;
|
||||
|
||||
data = *dataPtr;
|
||||
for (x = 0; x < sFaultDrawer.charW; x++) {
|
||||
if (mask & data) {
|
||||
fb[x] = sFaultDrawer.foreColor;
|
||||
} else if (sFaultDrawer.backColor & 1) {
|
||||
fb[x] = sFaultDrawer.backColor;
|
||||
}
|
||||
mask >>= 4;
|
||||
}
|
||||
fb += sFaultDrawer.w;
|
||||
dataPtr += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s32 FaultDrawer_ColorToPrintColor(u16 color) {
|
||||
s32 i;
|
||||
|
||||
for (i = 0; i < ARRAY_COUNT(sFaultDrawer.printColors); i++) {
|
||||
if (color == sFaultDrawer.printColors[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void FaultDrawer_UpdatePrintColor(void) {
|
||||
s32 idx;
|
||||
|
||||
if (sFaultDrawer.osSyncPrintfEnabled) {
|
||||
osSyncPrintf(VT_RST);
|
||||
|
||||
idx = FaultDrawer_ColorToPrintColor(sFaultDrawer.foreColor);
|
||||
if (idx >= 0 && idx < ARRAY_COUNT(sFaultDrawer.printColors) - 2) {
|
||||
osSyncPrintf(VT_SGR("3%d"), idx);
|
||||
}
|
||||
|
||||
idx = FaultDrawer_ColorToPrintColor(sFaultDrawer.backColor);
|
||||
if (idx >= 0 && idx < ARRAY_COUNT(sFaultDrawer.printColors) - 2) {
|
||||
osSyncPrintf(VT_SGR("4%d"), idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FaultDrawer_SetForeColor(u16 color) {
|
||||
sFaultDrawer.foreColor = color;
|
||||
FaultDrawer_UpdatePrintColor();
|
||||
}
|
||||
|
||||
void FaultDrawer_SetBackColor(u16 color) {
|
||||
sFaultDrawer.backColor = color;
|
||||
FaultDrawer_UpdatePrintColor();
|
||||
}
|
||||
|
||||
void FaultDrawer_SetFontColor(u16 color) {
|
||||
FaultDrawer_SetForeColor(color | 1); // force alpha to be set
|
||||
}
|
||||
|
||||
void FaultDrawer_SetCharPad(s8 padW, s8 padH) {
|
||||
sFaultDrawer.charWPad = padW;
|
||||
sFaultDrawer.charHPad = padH;
|
||||
}
|
||||
|
||||
void FaultDrawer_SetCursor(s32 x, s32 y) {
|
||||
if (sFaultDrawer.osSyncPrintfEnabled) {
|
||||
osSyncPrintf(VT_CUP("%d", "%d"), (y - sFaultDrawer.yStart) / (sFaultDrawer.charH + sFaultDrawer.charHPad),
|
||||
(x - sFaultDrawer.xStart) / (sFaultDrawer.charW + sFaultDrawer.charWPad));
|
||||
}
|
||||
sFaultDrawer.cursorX = x;
|
||||
sFaultDrawer.cursorY = y;
|
||||
}
|
||||
|
||||
void FaultDrawer_FillScreen(void) {
|
||||
if (sFaultDrawer.osSyncPrintfEnabled) {
|
||||
osSyncPrintf(VT_CLS);
|
||||
}
|
||||
|
||||
FaultDrawer_DrawRecImpl(sFaultDrawer.xStart, sFaultDrawer.yStart, sFaultDrawer.xEnd, sFaultDrawer.yEnd,
|
||||
sFaultDrawer.backColor | 1);
|
||||
FaultDrawer_SetCursor(sFaultDrawer.xStart, sFaultDrawer.yStart);
|
||||
}
|
||||
|
||||
char* FaultDrawer_PrintCallback(char* arg, const char* str, size_t count) {
|
||||
for (; count != 0; count--, str++) {
|
||||
s32 curXStart;
|
||||
s32 curXEnd;
|
||||
|
||||
if (sFaultDrawer.escCode) {
|
||||
sFaultDrawer.escCode = false;
|
||||
if (*str > '0' && *str <= '9') {
|
||||
FaultDrawer_SetForeColor(sFaultDrawer.printColors[*str - '0']);
|
||||
}
|
||||
|
||||
curXStart = sFaultDrawer.cursorX;
|
||||
curXEnd = sFaultDrawer.xEnd - sFaultDrawer.charW;
|
||||
} else {
|
||||
switch (*str) {
|
||||
case '\n':
|
||||
if (sFaultDrawer.osSyncPrintfEnabled) {
|
||||
osSyncPrintf("\n");
|
||||
}
|
||||
|
||||
sFaultDrawer.cursorX = sFaultDrawer.w;
|
||||
curXStart = sFaultDrawer.cursorX;
|
||||
curXEnd = sFaultDrawer.xEnd - sFaultDrawer.charW;
|
||||
break;
|
||||
|
||||
case FAULT_ESC:
|
||||
sFaultDrawer.escCode = true;
|
||||
curXStart = sFaultDrawer.cursorX;
|
||||
curXEnd = sFaultDrawer.xEnd - sFaultDrawer.charW;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (sFaultDrawer.osSyncPrintfEnabled) {
|
||||
osSyncPrintf("%c", *str);
|
||||
}
|
||||
|
||||
FaultDrawer_DrawChar(*str);
|
||||
sFaultDrawer.cursorX += sFaultDrawer.charW + sFaultDrawer.charWPad;
|
||||
|
||||
curXStart = sFaultDrawer.cursorX;
|
||||
curXEnd = sFaultDrawer.xEnd - sFaultDrawer.charW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (curXEnd <= curXStart) {
|
||||
sFaultDrawer.cursorX = sFaultDrawer.xStart;
|
||||
sFaultDrawer.cursorY += sFaultDrawer.charH + sFaultDrawer.charHPad;
|
||||
if (sFaultDrawer.yEnd - sFaultDrawer.charH <= sFaultDrawer.cursorY) {
|
||||
if (sFaultDrawer.inputCallback) {
|
||||
sFaultDrawer.inputCallback();
|
||||
FaultDrawer_FillScreen();
|
||||
}
|
||||
sFaultDrawer.cursorY = sFaultDrawer.yStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
osWritebackDCacheAll();
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
const char D_8003E280[] = "(null)";
|
||||
|
||||
s32 FaultDrawer_VPrintf(const char* fmt, va_list args) {
|
||||
return _Printf(FaultDrawer_PrintCallback, (void*)&sFaultDrawer, fmt, args);
|
||||
}
|
||||
|
||||
s32 FaultDrawer_Printf(const char* fmt, ...) {
|
||||
s32 ret;
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
ret = FaultDrawer_VPrintf(fmt, args);
|
||||
|
||||
va_end(args);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
FaultDrawer_SetCursor(x, y);
|
||||
FaultDrawer_VPrintf(fmt, args);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) {
|
||||
sFaultDrawer.fb = fb;
|
||||
sFaultDrawer.w = w;
|
||||
sFaultDrawer.h = h;
|
||||
}
|
||||
|
||||
void FaultDrawer_SetInputCallback(void (*callback)(void)) {
|
||||
sFaultDrawer.inputCallback = callback;
|
||||
}
|
||||
|
||||
void FaultDrawer_WritebackFBDCache(void) {
|
||||
osWritebackDCache(sFaultDrawer.fb, sFaultDrawer.w * sFaultDrawer.h * sizeof(u16));
|
||||
}
|
||||
|
||||
void FaultDrawer_Init(void) {
|
||||
bcopy(&sFaultDrawerDefault, &sFaultDrawer, sizeof(FaultDrawer));
|
||||
sFaultDrawer.fb = (u16*)(PHYS_TO_K0(osMemSize) - sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH]));
|
||||
}
|
||||
+1
-1
@@ -49,7 +49,7 @@ void ovlmgr_LoadImpl(RomOffset vromStart, UNUSED RomOffset vromEndUnused, void*
|
||||
|
||||
if (ovlRelocs == NULL) {
|
||||
sprintf(ovlSizeStr, "%ld", ovlSize);
|
||||
Fault_AddHungupAndCrashImpl("ovlmgr: Out of Memory", ovlSizeStr);
|
||||
fault_AddHungupAndCrashImpl("ovlmgr: Out of Memory", ovlSizeStr);
|
||||
}
|
||||
|
||||
Overlay_Load(vromStart, vromEnd, ovlStart, ovlEnd, vramStart, vramEnd, allocatedRamAddr, ovlRelocs);
|
||||
|
||||
@@ -59,7 +59,7 @@ NORETURN void DmaMgr_Error(DmaRequest* req, const char* file, const char* errorN
|
||||
}
|
||||
|
||||
sprintf(buff2, "%07X %08X %X %.50s", vrom, vram, size, (file != NULL) ? file : "???");
|
||||
Fault_AddHungupAndCrashImpl(buff1, buff2);
|
||||
fault_AddHungupAndCrashImpl(buff1, buff2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -253,7 +253,7 @@ void Actor_draw(Game_Play* game_play, Actor* actor) {
|
||||
FaultClient faultClient;
|
||||
LightsN* light;
|
||||
|
||||
Fault_AddClient(&faultClient, func_80056380_jp, actor, "Actor_draw");
|
||||
fault_AddClient(&faultClient, func_80056380_jp, actor, "Actor_draw");
|
||||
|
||||
//! FAKE
|
||||
if (1) {}
|
||||
@@ -289,7 +289,7 @@ void Actor_draw(Game_Play* game_play, Actor* actor) {
|
||||
|
||||
CLOSE_DISPS(game_play->state.gfxCtx);
|
||||
|
||||
Fault_RemoveClient(&faultClient);
|
||||
fault_RemoveClient(&faultClient);
|
||||
}
|
||||
|
||||
s32 Actor_draw_actor_no_culling_check(Actor* actor) {
|
||||
|
||||
@@ -96,12 +96,12 @@ FaultAddrConvClient sActorOverlayTableFaultAddrConvClient;
|
||||
|
||||
void actor_dlftbls_init(void) {
|
||||
actor_dlftbls_num = ACTOR_ID_MAX;
|
||||
Fault_AddClient(&sActorOverlayTableFaultClient, ActorOverlayTable_FaultClient, NULL, NULL);
|
||||
Fault_AddAddrConvClient(&sActorOverlayTableFaultAddrConvClient, ActorOverlayTable_FaultAddrConv, NULL);
|
||||
fault_AddClient(&sActorOverlayTableFaultClient, ActorOverlayTable_FaultClient, NULL, NULL);
|
||||
fault_AddressConverterAddClient(&sActorOverlayTableFaultAddrConvClient, ActorOverlayTable_FaultAddrConv, NULL);
|
||||
}
|
||||
|
||||
void actor_dlftbls_cleanup(void) {
|
||||
Fault_RemoveClient(&sActorOverlayTableFaultClient);
|
||||
Fault_RemoveAddrConvClient(&sActorOverlayTableFaultAddrConvClient);
|
||||
fault_RemoveClient(&sActorOverlayTableFaultClient);
|
||||
fault_AddressConverterRemoveClient(&sActorOverlayTableFaultAddrConvClient);
|
||||
actor_dlftbls_num = 0;
|
||||
}
|
||||
|
||||
+2
-2
@@ -42,11 +42,11 @@ s32 zelda_CheckArena(void) {
|
||||
|
||||
void zelda_InitArena(void* heap, size_t size) {
|
||||
__osMallocInit(&zelda_arena, heap, size);
|
||||
Fault_AddClient(&B_80141FC8_jp, (void*)ArenaImpl_FaultClient, &zelda_arena, NULL);
|
||||
fault_AddClient(&B_80141FC8_jp, (void*)ArenaImpl_FaultClient, &zelda_arena, NULL);
|
||||
}
|
||||
|
||||
void zelda_CleanupArena(void) {
|
||||
Fault_RemoveClient(&B_80141FC8_jp);
|
||||
fault_RemoveClient(&B_80141FC8_jp);
|
||||
__osMallocCleanup(&zelda_arena);
|
||||
}
|
||||
|
||||
|
||||
@@ -297,13 +297,13 @@ dummy_label_255895:
|
||||
D_8010DCE4_jp = var_s0;
|
||||
SubmenuArea_visit = NULL;
|
||||
|
||||
Fault_AddClient(&B_80144670_jp, func_800C47B4_jp, NULL, NULL);
|
||||
Fault_AddAddrConvClient(&B_80144680_jp, func_800C497C_jp, NULL);
|
||||
fault_AddClient(&B_80144670_jp, func_800C47B4_jp, NULL, NULL);
|
||||
fault_AddressConverterAddClient(&B_80144680_jp, func_800C497C_jp, NULL);
|
||||
}
|
||||
|
||||
void mSM_submenu_ovlptr_cleanup(mSM* submenu) {
|
||||
Fault_RemoveClient(&B_80144670_jp);
|
||||
Fault_RemoveAddrConvClient(&B_80144680_jp);
|
||||
fault_RemoveClient(&B_80144670_jp);
|
||||
fault_AddressConverterRemoveClient(&B_80144680_jp);
|
||||
if (SubmenuArea_visit != NULL) {
|
||||
SubmenuArea_DoUnlink(SubmenuArea_visit, submenu);
|
||||
SubmenuArea_visit = NULL;
|
||||
|
||||
+8
-5
@@ -13,8 +13,8 @@
|
||||
- [0x0017F0, c, boot/z_std_dma]
|
||||
- [0x0022A0, asm, boot/yaz0]
|
||||
- [0x0026C0, c, boot/syncprintf]
|
||||
- [0x002720, asm, boot/fault]
|
||||
- [0x004F70, asm, boot/fault_drawer]
|
||||
- [0x002720, c, boot/fault]
|
||||
- [0x004F70, c, boot/fault_drawer]
|
||||
|
||||
- [0x0059F0, c, boot/libu64/pad]
|
||||
- [0x005BE0, asm, boot/libu64/stackcheck]
|
||||
@@ -216,7 +216,8 @@
|
||||
|
||||
- [0x016FD0, data, boot/016FD0]
|
||||
- [0x016FE0, .data, boot/z_std_dma]
|
||||
- [0x016FF0, data, boot/016FF0]
|
||||
- [0x016FF0, .data, boot/fault]
|
||||
- [0x017050, .data, boot/fault_drawer]
|
||||
|
||||
- [0x017090, data, boot/libu64/stackcheck]
|
||||
|
||||
@@ -263,8 +264,8 @@
|
||||
- [0x0185B0, .rodata, boot/ovlmgr]
|
||||
- [0x0185D0, .rodata, boot/z_std_dma]
|
||||
- [0x0187F0, rodata, boot/0187F0]
|
||||
- [0x018840, rodata, boot/018840]
|
||||
- [0x019250, rodata, boot/019250]
|
||||
- [0x018840, .rodata, boot/fault]
|
||||
- [0x019250, .rodata, boot/fault_drawer]
|
||||
|
||||
# libu64
|
||||
- [0x019690, rodata, boot/libu64/gfxprint]
|
||||
@@ -294,6 +295,8 @@
|
||||
- { start: 0x019D40, type: .bss, vram: 0x8003FF30, name: boot/viconfig }
|
||||
- { start: 0x019D40, type: .bss, vram: 0x8003FF40, name: boot/z_std_dma }
|
||||
- { start: 0x019D40, type: bss, vram: 0x800406C0, name: boot/800406C0 }
|
||||
- { start: 0x019D40, type: .bss, vram: 0x80040AE0, name: boot/fault }
|
||||
- { start: 0x019D40, type: .bss, vram: 0x80041960, name: boot/fault_drawer }
|
||||
|
||||
# libu64
|
||||
- { start: 0x019D40, type: bss, vram: 0x800419A0, name: boot/libu64/gfxprint }
|
||||
|
||||
Reference in New Issue
Block a user