diff --git a/include/structs.h b/include/structs.h index 77edb123cf..52ff4fe936 100644 --- a/include/structs.h +++ b/include/structs.h @@ -925,7 +925,7 @@ typedef union { } F3DVertex; typedef struct { -/* 0x00 */ void* fb; +/* 0x00 */ u16* fb; /* 0x04 */ u16 w; /* 0x06 */ u16 h; /* 0x08 */ u16 yStart; diff --git a/include/variables.h b/include/variables.h index e6d28ab344..a450393547 100644 --- a/include/variables.h +++ b/include/variables.h @@ -221,13 +221,14 @@ extern char D_80098C34[]; // D_80098C34 extern char D_80098C38[]; // D_80098C38 extern char D_80098C40[]; // D_80098C40 extern u8 faultDrawFont[8][128]; // D_80098C50 -extern UNK_TYPE1 D_80099050; // D_80099050 -extern UNK_TYPE1 D_80099054; // D_80099054 -extern UNK_TYPE1 D_8009905C; // D_8009905C -extern UNK_TYPE1 D_80099064; // D_80099064 -extern UNK_TYPE1 D_80099070; // D_80099070 -extern UNK_TYPE1 D_80099078; // D_80099078 -extern UNK_TYPE1 D_8009907C; // D_8009907C +extern char D_80099050[]; // D_80099050 +extern char D_80099054[]; // D_80099054 +extern char D_8009905C[]; // D_8009905C +extern char D_80099064[]; // D_80099064 +extern char D_80099070[]; // D_80099070 +extern char D_80099078[]; // D_80099078 +extern char D_8009907C[]; // D_8009907C +extern char D_80099080[]; // D_80099080 extern UNK_PTR D_80099090; // D_80099090 extern char D_800990B0[]; // D_800990B0 extern f32 D_800990C0; // D_800990C0 diff --git a/linker_scripts/code_script.txt b/linker_scripts/code_script.txt index eabce7f8f7..24526cf2a4 100644 --- a/linker_scripts/code_script.txt +++ b/linker_scripts/code_script.txt @@ -14,7 +14,7 @@ SECTIONS build/src/boot_O2_g3/CIC6105.o(.text) build/src/boot_O2_g3/boot_0x80081920.o(.text) build/src/boot_O2_g3_trapuv/fault.o(.text) - build/asm/boot_0x80083EB0.o(.text) + build/src/boot_O2_g3_trapuv/fault_drawer.o(.text) build/asm/loadfragment.o(.text) build/asm/loadfragment2.o(.text) build/asm/boot_0x80085130.o(.text) diff --git a/src/boot_O2_g3_trapuv/fault.c b/src/boot_O2_g3_trapuv/fault.c index df0395808d..98af262883 100644 --- a/src/boot_O2_g3_trapuv/fault.c +++ b/src/boot_O2_g3_trapuv/fault.c @@ -810,12 +810,10 @@ void Fault_ThreadEntry(void* arg) { if (msg == (OSMesg)1) { faultCtxt->msgId = 1; Fault_Log(D_80098A88); - } - else if (msg == (OSMesg)2) { + } else if (msg == (OSMesg)2) { faultCtxt->msgId = 2; Fault_Log(D_80098AC0); - } - else if (msg == (OSMesg)3) { + } else if (msg == (OSMesg)3) { Fault_SetOptions(); faultedThread = NULL; continue; diff --git a/src/boot_O2_g3_trapuv/fault_drawer.c b/src/boot_O2_g3_trapuv/fault_drawer.c new file mode 100644 index 0000000000..65a2da4014 --- /dev/null +++ b/src/boot_O2_g3_trapuv/fault_drawer.c @@ -0,0 +1,118 @@ +#include +#include + +void FaultDrawer_SetOsSyncPrintfEnabled(u32 enabled) { + faultDrawContext->osSyncPrintfEnabled = enabled; +} + + +#ifdef NON_MATCHING +//This function needs a lot of work +void FaultDrawer_DrawRecImpl(s32 xstart, s32 ystart, s32 xend, s32 yend, u16 color) { + s32 x; + s32 y; + u16* fb; + if (faultDrawContext->w - xstart > 0 && faultDrawContext->h - ystart > 0) { + for (y = 0; y < yend - ystart + 1; y++) { + fb = &faultDrawContext->fb[faultDrawContext->w * y]; + for (x = 0; x < xend - xstart + 1; x++) { + *fb++ = color; + } + } + + osWritebackDCacheAll(); + } +} +#else +GLOBAL_ASM("./asm/nonmatching/fault_drawer/FaultDrawer_DrawRecImpl.asm") +#endif + +GLOBAL_ASM("./asm/nonmatching/fault_drawer/FaultDrawer_DrawChar.asm") + +s32 FaultDrawer_ColorToPrintColor(u16 color) { + s32 i; + for (i = 0; i < 10; i++) { + if (color == faultDrawContext->printColors[i]) { + return i; + } + } + return -1; +} + +void FaultDrawer_UpdatePrintColor() { + s32 idx; + if (faultDrawContext->osSyncPrintfEnabled) { + Fault_Log(D_80099050); + idx = FaultDrawer_ColorToPrintColor(faultDrawContext->foreColor); + if (idx >= 0 && idx < 8) { + Fault_Log(D_80099054, idx); + } + idx = FaultDrawer_ColorToPrintColor(faultDrawContext->backColor); + if (idx >= 0 && idx < 8) { + Fault_Log(D_8009905C, idx); + } + } +} + +void FaultDrawer_SetForeColor(u16 color) { + faultDrawContext->foreColor = color; + FaultDrawer_UpdatePrintColor(); +} + +void FaultDrawer_SetBackColor(u16 color) { + faultDrawContext->backColor = color; + FaultDrawer_UpdatePrintColor(); +} + +void FaultDrawer_SetFontColor(u16 color) { + FaultDrawer_SetForeColor((u16)(color | 1)); //force alpha to be set +} + +void FaultDrawer_SetCharPad(s8 padW, s8 padH) { + faultDrawContext->charWPad = padW; + faultDrawContext->charHPad = padH; +} + +void FaultDrawer_SetCursor(s32 x, s32 y) { + if (faultDrawContext->osSyncPrintfEnabled) { + Fault_Log(D_80099064, (y - faultDrawContext->yStart) / (faultDrawContext->charH + faultDrawContext->charHPad), (x - faultDrawContext->xStart) / (faultDrawContext->charW + faultDrawContext->charWPad)); + } + faultDrawContext->cursorX = x; + faultDrawContext->cursorY = y; +} + +void FaultDrawer_FillScreen() { + if (faultDrawContext->osSyncPrintfEnabled) { + Fault_Log(D_80099070); + } + + FaultDrawer_DrawRecImpl(faultDrawContext->xStart, faultDrawContext->yStart, faultDrawContext->xEnd, faultDrawContext->yEnd, faultDrawContext->backColor | 1); + FaultDrawer_SetCursor(faultDrawContext->xStart, faultDrawContext->yStart); +} + +GLOBAL_ASM("./asm/nonmatching/fault_drawer/FaultDrawer_FormatStringFunc.asm") + +void FaultDrawer_VPrintf(char* str, char* args) { //va_list + _Printf((printf_func)FaultDrawer_FormatStringFunc, faultDrawContext, str, args); +} + +GLOBAL_ASM("./asm/nonmatching/fault_drawer/FaultDrawer_Printf.asm") + +GLOBAL_ASM("./asm/nonmatching/fault_drawer/FaultDrawer_DrawText.asm") + +void FaultDrawer_SetDrawerFB(void* fb, u16 w, u16 h) { + faultDrawContext->fb = (u16*)fb; + faultDrawContext->w = w; + faultDrawContext->h = h; +} + +void FaultDrawer_SetInputCallback(void(*callback)()) { + faultDrawContext->inputCallback = callback; +} + +void FaultDrawer_Init() { + faultDrawContext = &faultDrawContextStruct; + _bcopy(&faultDrawContextInit, faultDrawContext, sizeof(FaultDrawer)); + faultDrawContext->fb = (u16*)((osMemSize | 0x80000000) - 0x25800); +} + diff --git a/tables/objects.py b/tables/objects.py index bf8ce0da55..430c9b1ac3 100644 --- a/tables/objects.py +++ b/tables/objects.py @@ -8,7 +8,7 @@ 0x80081820:"CIC6105", 0x80081920:"", 0x80081980:"fault", - 0x80083EB0:"", + 0x80083EB0:"fault_drawer", 0x80084940:"loadfragment", 0x80084DB0:"loadfragment2", 0x80085130:"", diff --git a/tables/variables.py b/tables/variables.py index 3506a1de57..c98bdfe533 100644 --- a/tables/variables.py +++ b/tables/variables.py @@ -215,13 +215,14 @@ 0x80098C38:("D_80098C38","char","[]"), 0x80098C40:("D_80098C40","char","[]"), 0x80098C50:("faultDrawFont","u8","[8][128]"), - 0x80099050:("D_80099050","UNK_TYPE1",""), - 0x80099054:("D_80099054","UNK_TYPE1",""), - 0x8009905C:("D_8009905C","UNK_TYPE1",""), - 0x80099064:("D_80099064","UNK_TYPE1",""), - 0x80099070:("D_80099070","UNK_TYPE1",""), - 0x80099078:("D_80099078","UNK_TYPE1",""), - 0x8009907C:("D_8009907C","UNK_TYPE1",""), + 0x80099050:("D_80099050","char","[]"), + 0x80099054:("D_80099054","char","[]"), + 0x8009905C:("D_8009905C","char","[]"), + 0x80099064:("D_80099064","char","[]"), + 0x80099070:("D_80099070","char","[]"), + 0x80099078:("D_80099078","char","[]"), + 0x8009907C:("D_8009907C","char","[]"), + 0x80099080:("D_80099080","char","[]"), 0x80099090:("D_80099090","UNK_PTR",""), 0x800990B0:("D_800990B0","char","[]"), 0x800990C0:("D_800990C0","f32",""),