diff options
| author | Derek Hensley <hensley.derek58@gmail.com> | 2023-08-28 09:59:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-28 09:59:31 -0700 |
| commit | 1e3511efea9cf4379a04fca77f6a00cb170da28c (patch) | |
| tree | 7650c04105d35d867939d19e3421102ae511102f /include | |
| parent | fcfbb6c52feec4a01b46f0c2bcc037af373d4fe9 (diff) | |
Fault + Fault_drawer (#77)
* Fault OK
* fault_drawer OK
* Cleanup
* Cleanup pt 2
* Forgot to save
* PR
Diffstat (limited to 'include')
| -rw-r--r-- | include/boot_variables.h | 7 | ||||
| -rw-r--r-- | include/fault.h | 128 | ||||
| -rw-r--r-- | include/m_thread.h | 3 | ||||
| -rw-r--r-- | include/terminal.h | 40 |
4 files changed, 111 insertions, 67 deletions
diff --git a/include/boot_variables.h b/include/boot_variables.h index 8345c2c..8aa1cbe 100644 --- a/include/boot_variables.h +++ b/include/boot_variables.h @@ -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; diff --git a/include/fault.h b/include/fault.h index b24f732..4cf3c51 100644 --- a/include/fault.h +++ b/include/fault.h @@ -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(); - -// void FaultDrawer_SetOsSyncPrintfEnabled(); -// void FaultDrawer_DrawRecImpl(); -// void FaultDrawer_DrawChar(); -// void FaultDrawer_ColorToPrintColor(); -// void FaultDrawer_UpdatePrintColor(); -// void FaultDrawer_SetForeColor(); -// void FaultDrawer_SetBackColor(); +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 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 diff --git a/include/m_thread.h b/include/m_thread.h index 45cb851..19f6e1f 100644 --- a/include/m_thread.h +++ b/include/m_thread.h @@ -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 diff --git a/include/terminal.h b/include/terminal.h new file mode 100644 index 0000000..f4ed8d6 --- /dev/null +++ b/include/terminal.h @@ -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 |
