Port OoT's docs for fault.c and fault_drawer.c (#1199)

* fault.h

* some docs stealing

* fix building

* fault_internal.h

* pass

* finish stealing docs

* finish cleanup

* format

* warning

* Update src/boot_O2_g3/fault.c

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* Update src/boot_O2_g3/fault.c

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* Update src/boot_O2_g3/fault.c

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* review

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* arggggg

* arggggg part 2

* STACK

* PHYS_TO_K0(0x400000)

* format

* fix

* Instance

* format

* Neutral reset

* variables.h cleanup

* bss

* frameBuffer

* format

* Update src/boot_O2_g3/fault.c

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* review

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* Update src/boot_O2_g3/fault.c

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>

* bss

* bss

* bss

* callback cleanup

* fix function declarations

* fix again

* bss

* bss

* Update src/overlays/actors/ovl_En_Fishing/z_en_fishing.c

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>

* Update src/boot_O2_g3/fault.c

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>

* bss

* bss

* Update src/boot_O2_g3/fault.c

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>

* review

* import bss

* format

* minor cleanup

* bss

* review

* fix

* bss

* bss

* bss

* bss

* bss

* format

* a

* Z_PRIORITY_FAULT

* bss

* fix

* idle.c bss doesn't want to get fixed :c

* review

* bss

---------

Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
Anghelo Carvajal
2023-07-08 14:41:25 -04:00
committed by GitHub
parent a506e8620a
commit b3eae0e5b7
41 changed files with 1007 additions and 874 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
#include "global.h"
#include "fault.h"
UNK_TYPE4 D_8009BE30;
UNK_TYPE4 D_8009BE34;
@@ -17,7 +18,7 @@ void CIC6105_PrintRomInfo(void) {
}
void CIC6105_AddRomInfoFaultPage(void) {
Fault_AddClient(&romInfoFaultClient, CIC6105_PrintRomInfo, 0, 0);
Fault_AddClient(&romInfoFaultClient, (void*)CIC6105_PrintRomInfo, NULL, NULL);
}
void CIC6105_RemoveRomInfoFaultPage(void) {
+587 -385
View File
File diff suppressed because it is too large Load Diff
+139 -96
View File
@@ -1,28 +1,64 @@
/**
* @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 "fault_internal.h"
#include "global.h"
#include "vt.h"
typedef struct {
/* 0x00 */ u16* frameBuffer;
/* 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 */ FaultDrawerCallback inputCallback;
} FaultDrawer; // size = 0x3C
extern const u32 sFaultDrawerFont[];
FaultDrawer sFaultDrawerStruct;
FaultDrawer sFaultDrawer;
FaultDrawer* sFaultDrawerInstance = &sFaultDrawer;
#define FAULT_DRAWER_CURSOR_X 22
#define FAULT_DRAWER_CURSOR_Y 16
FaultDrawer* sFaultDrawContext = &sFaultDrawerStruct;
FaultDrawer sFaultDrawerDefault = {
FAULT_FB_ADDRESS, // fb
SCREEN_WIDTH, // w
SCREEN_HEIGHT, // h
16, // yStart
223, // yEnd
22, // xStart
297, // xEnd
GPACK_RGBA5551(255, 255, 255, 255), // foreColor
GPACK_RGBA5551(0, 0, 0, 0), // backColor
22, // cursorX
16, // cursorY
sFaultDrawerFont, // font
8, // charW
8, // charH
0, // charWPad
0, // charHPad
FAULT_FB_ADDRESS, // frameBuffer
SCREEN_WIDTH, // w
SCREEN_HEIGHT, // h
FAULT_DRAWER_CURSOR_Y, // yStart
SCREEN_HEIGHT - FAULT_DRAWER_CURSOR_Y - 1, // yEnd
FAULT_DRAWER_CURSOR_X, // xStart
SCREEN_WIDTH - FAULT_DRAWER_CURSOR_X - 1, // xEnd
GPACK_RGBA5551(255, 255, 255, 255), // foreColor
GPACK_RGBA5551(0, 0, 0, 0), // backColor
FAULT_DRAWER_CURSOR_X, // cursorX
FAULT_DRAWER_CURSOR_Y, // cursorY
sFaultDrawerFont, // fontData
8, // charW
8, // charH
0, // charWPad
0, // charHPad
{
// printColors
GPACK_RGBA5551(0, 0, 0, 1), // BLACK
@@ -36,24 +72,24 @@ FaultDrawer sFaultDrawerDefault = {
GPACK_RGBA5551(120, 120, 120, 1), // DARK GRAY
GPACK_RGBA5551(176, 176, 176, 1), // LIGHT GRAY
},
0, // escCode
0, // osSyncPrintfEnabled
NULL, // inputCallback
false, // escCode
false, // osSyncPrintfEnabled
NULL, // inputCallback
};
//! TODO: Needs to be extracted
#pragma GLOBAL_ASM("asm/non_matchings/boot/fault_drawer/sFaultDrawerFont.s")
void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) {
sFaultDrawContext->osSyncPrintfEnabled = enabled;
sFaultDrawerInstance->osSyncPrintfEnabled = enabled;
}
void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 color) {
u16* fb;
u16* frameBuffer;
s32 x;
s32 y;
s32 xDiff = sFaultDrawContext->w - xStart;
s32 yDiff = sFaultDrawContext->h - yStart;
s32 xDiff = sFaultDrawerInstance->w - xStart;
s32 yDiff = sFaultDrawerInstance->h - yStart;
s32 xSize = xEnd - xStart + 1;
s32 ySize = yEnd - yStart + 1;
@@ -66,12 +102,12 @@ void FaultDrawer_DrawRecImpl(s32 xStart, s32 yStart, s32 xEnd, s32 yEnd, u16 col
ySize = yDiff;
}
fb = sFaultDrawContext->fb + sFaultDrawContext->w * yStart + xStart;
frameBuffer = sFaultDrawerInstance->frameBuffer + sFaultDrawerInstance->w * yStart + xStart;
for (y = 0; y < ySize; y++) {
for (x = 0; x < xSize; x++) {
*fb++ = color;
*frameBuffer++ = color;
}
fb += sFaultDrawContext->w - xSize;
frameBuffer += sFaultDrawerInstance->w - xSize;
}
osWritebackDCacheAll();
@@ -82,29 +118,29 @@ void FaultDrawer_DrawChar(char c) {
s32 x;
s32 y;
u32 data;
s32 cursorX = sFaultDrawContext->cursorX;
s32 cursorY = sFaultDrawContext->cursorY;
s32 cursorX = sFaultDrawerInstance->cursorX;
s32 cursorY = sFaultDrawerInstance->cursorY;
s32 shift = c % 4;
const u32* dataPtr = &sFaultDrawContext->font[(((c / 8) * 16) + ((c & 4) >> 2))];
u16* fb = sFaultDrawContext->fb + (sFaultDrawContext->w * cursorY) + cursorX;
const u32* dataPtr = &sFaultDrawerInstance->fontData[(((c / 8) * 16) + ((c & 4) >> 2))];
u16* frameBuffer = sFaultDrawerInstance->frameBuffer + (sFaultDrawerInstance->w * cursorY) + cursorX;
if ((sFaultDrawContext->xStart <= cursorX) &&
((sFaultDrawContext->charW + cursorX - 1) <= sFaultDrawContext->xEnd) &&
(sFaultDrawContext->yStart <= cursorY) &&
((sFaultDrawContext->charH + cursorY - 1) <= sFaultDrawContext->yEnd)) {
for (y = 0; y < sFaultDrawContext->charH; y++) {
if ((sFaultDrawerInstance->xStart <= cursorX) &&
((sFaultDrawerInstance->charW + cursorX - 1) <= sFaultDrawerInstance->xEnd) &&
(sFaultDrawerInstance->yStart <= cursorY) &&
((sFaultDrawerInstance->charH + cursorY - 1) <= sFaultDrawerInstance->yEnd)) {
for (y = 0; y < sFaultDrawerInstance->charH; y++) {
u32 mask = 0x10000000 << shift;
data = *dataPtr;
for (x = 0; x < sFaultDrawContext->charW; x++) {
for (x = 0; x < sFaultDrawerInstance->charW; x++) {
if (mask & data) {
fb[x] = sFaultDrawContext->foreColor;
} else if (sFaultDrawContext->backColor & 1) {
fb[x] = sFaultDrawContext->backColor;
frameBuffer[x] = sFaultDrawerInstance->foreColor;
} else if (sFaultDrawerInstance->backColor & 1) {
frameBuffer[x] = sFaultDrawerInstance->backColor;
}
mask >>= 4;
}
fb += sFaultDrawContext->w;
frameBuffer += sFaultDrawerInstance->w;
dataPtr += 2;
}
}
@@ -113,37 +149,39 @@ void FaultDrawer_DrawChar(char c) {
s32 FaultDrawer_ColorToPrintColor(u16 color) {
s32 i;
for (i = 0; i < 10; i++) {
if (color == sFaultDrawContext->printColors[i]) {
for (i = 0; i < ARRAY_COUNT(sFaultDrawerInstance->printColors); i++) {
if (color == sFaultDrawerInstance->printColors[i]) {
return i;
}
}
return -1;
}
void FaultDrawer_UpdatePrintColor() {
s32 idx;
void FaultDrawer_UpdatePrintColor(void) {
s32 index;
if (sFaultDrawContext->osSyncPrintfEnabled) {
if (sFaultDrawerInstance->osSyncPrintfEnabled) {
osSyncPrintf(VT_RST);
idx = FaultDrawer_ColorToPrintColor(sFaultDrawContext->foreColor);
if ((idx >= 0) && (idx < 8)) {
osSyncPrintf(VT_SGR("3%d"), idx);
index = FaultDrawer_ColorToPrintColor(sFaultDrawerInstance->foreColor);
if ((index >= 0) && (index < 8)) {
osSyncPrintf(VT_SGR("3%d"), index);
}
idx = FaultDrawer_ColorToPrintColor(sFaultDrawContext->backColor);
if ((idx >= 0) && (idx < 8)) {
osSyncPrintf(VT_SGR("4%d"), idx);
index = FaultDrawer_ColorToPrintColor(sFaultDrawerInstance->backColor);
if ((index >= 0) && (index < 8)) {
osSyncPrintf(VT_SGR("4%d"), index);
}
}
}
void FaultDrawer_SetForeColor(u16 color) {
sFaultDrawContext->foreColor = color;
sFaultDrawerInstance->foreColor = color;
FaultDrawer_UpdatePrintColor();
}
void FaultDrawer_SetBackColor(u16 color) {
sFaultDrawContext->backColor = color;
sFaultDrawerInstance->backColor = color;
FaultDrawer_UpdatePrintColor();
}
@@ -152,70 +190,71 @@ void FaultDrawer_SetFontColor(u16 color) {
}
void FaultDrawer_SetCharPad(s8 padW, s8 padH) {
sFaultDrawContext->charWPad = padW;
sFaultDrawContext->charHPad = padH;
sFaultDrawerInstance->charWPad = padW;
sFaultDrawerInstance->charHPad = padH;
}
void FaultDrawer_SetCursor(s32 x, s32 y) {
if (sFaultDrawContext->osSyncPrintfEnabled) {
osSyncPrintf(VT_CUP("%d", "%d"),
(y - sFaultDrawContext->yStart) / (sFaultDrawContext->charH + sFaultDrawContext->charHPad),
(x - sFaultDrawContext->xStart) / (sFaultDrawContext->charW + sFaultDrawContext->charWPad));
if (sFaultDrawerInstance->osSyncPrintfEnabled) {
osSyncPrintf(
VT_CUP("%d", "%d"),
(y - sFaultDrawerInstance->yStart) / (sFaultDrawerInstance->charH + sFaultDrawerInstance->charHPad),
(x - sFaultDrawerInstance->xStart) / (sFaultDrawerInstance->charW + sFaultDrawerInstance->charWPad));
}
sFaultDrawContext->cursorX = x;
sFaultDrawContext->cursorY = y;
sFaultDrawerInstance->cursorX = x;
sFaultDrawerInstance->cursorY = y;
}
void FaultDrawer_FillScreen() {
if (sFaultDrawContext->osSyncPrintfEnabled) {
if (sFaultDrawerInstance->osSyncPrintfEnabled) {
osSyncPrintf(VT_CLS);
}
FaultDrawer_DrawRecImpl(sFaultDrawContext->xStart, sFaultDrawContext->yStart, sFaultDrawContext->xEnd,
sFaultDrawContext->yEnd, sFaultDrawContext->backColor | 1);
FaultDrawer_SetCursor(sFaultDrawContext->xStart, sFaultDrawContext->yStart);
FaultDrawer_DrawRecImpl(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart, sFaultDrawerInstance->xEnd,
sFaultDrawerInstance->yEnd, sFaultDrawerInstance->backColor | 1);
FaultDrawer_SetCursor(sFaultDrawerInstance->xStart, sFaultDrawerInstance->yStart);
}
void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count) {
for (; count != 0; count--, str++) {
if (sFaultDrawContext->escCode) {
sFaultDrawContext->escCode = false;
if ((*str >= '1') && (*str <= '9')) {
FaultDrawer_SetForeColor(sFaultDrawContext->printColors[*str - '0']);
if (sFaultDrawerInstance->escCode) {
sFaultDrawerInstance->escCode = false;
if (*str >= '1' && *str <= '9') {
FaultDrawer_SetForeColor(sFaultDrawerInstance->printColors[*str - '0']);
}
} else {
switch (*str) {
case '\n':
if (sFaultDrawContext->osSyncPrintfEnabled) {
if (sFaultDrawerInstance->osSyncPrintfEnabled) {
osSyncPrintf("\n");
}
sFaultDrawContext->cursorX = sFaultDrawContext->w;
sFaultDrawerInstance->cursorX = sFaultDrawerInstance->w;
break;
case '\x1A':
sFaultDrawContext->escCode = true;
case FAULT_ESC:
sFaultDrawerInstance->escCode = true;
break;
default:
if (sFaultDrawContext->osSyncPrintfEnabled) {
if (sFaultDrawerInstance->osSyncPrintfEnabled) {
osSyncPrintf("%c", *str);
}
FaultDrawer_DrawChar(*str);
sFaultDrawContext->cursorX += sFaultDrawContext->charW + sFaultDrawContext->charWPad;
sFaultDrawerInstance->cursorX += sFaultDrawerInstance->charW + sFaultDrawerInstance->charWPad;
}
}
if (sFaultDrawContext->cursorX >= (sFaultDrawContext->xEnd - sFaultDrawContext->charW)) {
sFaultDrawContext->cursorX = sFaultDrawContext->xStart;
sFaultDrawContext->cursorY += sFaultDrawContext->charH + sFaultDrawContext->charHPad;
if (sFaultDrawContext->yEnd - sFaultDrawContext->charH <= sFaultDrawContext->cursorY) {
if (sFaultDrawContext->inputCallback != NULL) {
sFaultDrawContext->inputCallback();
if (sFaultDrawerInstance->cursorX >= (sFaultDrawerInstance->xEnd - sFaultDrawerInstance->charW)) {
sFaultDrawerInstance->cursorX = sFaultDrawerInstance->xStart;
sFaultDrawerInstance->cursorY += sFaultDrawerInstance->charH + sFaultDrawerInstance->charHPad;
if (sFaultDrawerInstance->yEnd - sFaultDrawerInstance->charH <= sFaultDrawerInstance->cursorY) {
if (sFaultDrawerInstance->inputCallback != NULL) {
sFaultDrawerInstance->inputCallback();
FaultDrawer_FillScreen();
}
sFaultDrawContext->cursorY = sFaultDrawContext->yStart;
sFaultDrawerInstance->cursorY = sFaultDrawerInstance->yStart;
}
}
}
@@ -227,17 +266,21 @@ void* FaultDrawer_FormatStringFunc(void* arg, const char* str, size_t count) {
const char D_80099080[] = "(null)";
void FaultDrawer_VPrintf(const char* fmt, va_list ap) {
_Printf(FaultDrawer_FormatStringFunc, sFaultDrawContext, fmt, ap);
s32 FaultDrawer_VPrintf(const char* fmt, va_list ap) {
return _Printf(FaultDrawer_FormatStringFunc, sFaultDrawerInstance, fmt, ap);
}
void FaultDrawer_Printf(const char* fmt, ...) {
s32 FaultDrawer_Printf(const char* fmt, ...) {
s32 ret;
va_list args;
va_start(args, fmt);
FaultDrawer_VPrintf(fmt, args);
ret = FaultDrawer_VPrintf(fmt, args);
va_end(args);
return ret;
}
void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) {
@@ -250,18 +293,18 @@ void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...) {
va_end(args);
}
void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) {
sFaultDrawContext->fb = (u16*)fb;
sFaultDrawContext->w = w;
sFaultDrawContext->h = h;
void FaultDrawer_SetDrawerFrameBuffer(void* frameBuffer, u16 w, u16 h) {
sFaultDrawerInstance->frameBuffer = frameBuffer;
sFaultDrawerInstance->w = w;
sFaultDrawerInstance->h = h;
}
void FaultDrawer_SetInputCallback(FaultDrawerCallback callback) {
sFaultDrawContext->inputCallback = callback;
sFaultDrawerInstance->inputCallback = callback;
}
void FaultDrawer_Init() {
sFaultDrawContext = &sFaultDrawerStruct;
bcopy(&sFaultDrawerDefault, sFaultDrawContext, sizeof(FaultDrawer));
sFaultDrawContext->fb = (u16*)((osMemSize | 0x80000000) - 0x25800);
sFaultDrawerInstance = &sFaultDrawer;
bcopy(&sFaultDrawerDefault, sFaultDrawerInstance, sizeof(FaultDrawer));
sFaultDrawerInstance->frameBuffer = (u16*)(PHYS_TO_K0(osMemSize) - SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(u16));
}
+1
View File
@@ -1,5 +1,6 @@
#include "prevent_bss_reordering.h"
#include "global.h"
#include "fault.h"
u8 sYaz0DataBuffer[0x400];
u8* sYaz0CurDataEnd;
+1
View File
@@ -1,5 +1,6 @@
#include "prevent_bss_reordering.h"
#include "global.h"
#include "fault.h"
#include "stack.h"
#include "stackcheck.h"
#include "z64thread.h"