diff options
| author | Dragorn421 <Dragorn421@users.noreply.github.com> | 2021-10-03 05:17:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-02 23:17:09 -0400 |
| commit | f1d27bf6531fd6579d09dcf3078ee97c57b6fff1 (patch) | |
| tree | 54d463be5b46f7fe77d1da1d8c34972db9092262 /src/code/fault.c | |
| parent | 5c95f70d5913ade28916464812c89c4dfa209e9e (diff) | |
Fix/cleanup/rephrase miscellaneous stuff (#983)
* Add parens around params usage in VEC_SET macro
* Remove unnecessary space character in a xml
* Use defines instead of magic values in head/tail magic comments
* Use `OS_USEC_TO_CYCLES` to make a time look better in `Graph_TaskSet00`
* `0x25800` -> `sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])`
* `0x803DA800` -> `0x80400000 - frame buffer size`
* Use `OS_VI_` defines instead of hex
* Add empty line after some variable declarations
* Remove unused `extern CutsceneData` in `z_bg_dy_yoseizo.c`
* `Matrix_MtxFToYXZRotS` does not use `MTXMODE_`
* Use `MTXMODE_` more
* Remove `ASCII_TO_U32`, use `'IS64'`
* Add explicit `!= NULL` in some ternaries
* Use `INV_CONTENT`, `AMMO` macros more
* Use `PLAYER_AP_` enum more to compare to `Player#heldItemActionParam`
* Get rid of lowercase hex (outside libultra)
* `gWindMill*` -> `gWindmill*`
* Format and small fix enums in `z_boss_mo.h`
* Use `CHECK_BTN_ANY` more
* Fix xz/xy mistake in comment in tektite
* Rephrase comments mentioning "the devs" in a more neutral way
* Clean-up some objectively useless parens
* Fix some negative values written as u16 instead of s16 in ichains
* `SKJ_ACTON_` -> `SKJ_ACTION_`
* Run formatter
* Fix unk_ offset of `TransformUpdateIndex#unk_10` -> `unk_0E`
* Remove comments using in-game text
* Remove `U` suffix from integer literals
* Revert "Remove `ASCII_TO_U32`, use `'IS64'`"
This reverts commit c801337dde9fe5e8b7a7ecf85ad3629bf5b87aaf.
* Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`
* Add empty line after decl x2
* Revert "Use `PLAYER_STR_*` to compare to `CUR_UPG_VALUE(UPG_STRENGTH)`"
This reverts commit d80bdb32da449edc74e02b8ab3f5a2c532e74bdb.
* Make `CUR_UPG_VALUE(UPG_STRENGTH)` compare to integers (eventually needs its own enum)
* Only use `PLAYER_SHIELD_` enum with `Player#currentShield`
* Only use `PLAYER_TUNIC_` enum with `Player#currentTunic`
Diffstat (limited to 'src/code/fault.c')
| -rw-r--r-- | src/code/fault.c | 81 |
1 files changed, 46 insertions, 35 deletions
diff --git a/src/code/fault.c b/src/code/fault.c index 91e517552..aaf9237b2 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -39,6 +39,7 @@ extern FaultThreadStruct gFaultStruct; void Fault_SleepImpl(u32 duration) { u64 value = (duration * OS_CPU_COUNTER) / 1000ull; + Sleep_Cycles(value); } @@ -102,6 +103,7 @@ void Fault_ProcessClientContext(FaultClientContext* ctx) { u32 Fault_ProcessClient(u32 callback, u32 param0, u32 param1) { FaultClientContext a; + a.callback = callback; a.param0 = param0; a.param1 = param1; @@ -118,6 +120,7 @@ void Fault_AddClient(FaultClient* client, void* callback, void* param0, void* pa { FaultClient* iter = sFaultStructPtr->clients; + while (iter != NULL) { if (iter == client) { alreadyExists = true; @@ -186,6 +189,7 @@ void Fault_AddAddrConvClient(FaultAddrConvClient* client, void* callback, void* { FaultAddrConvClient* iter = sFaultStructPtr->addrConvClients; + while (iter != NULL) { if (iter == client) { alreadyExists = true; @@ -347,9 +351,9 @@ void Fault_DrawCornerRec(u16 color) { void Fault_PrintFReg(s32 idx, f32* value) { u32 raw = *(u32*)value; - s32 v0 = ((raw & 0x7f800000) >> 0x17) - 0x7f; + s32 v0 = ((raw & 0x7F800000) >> 0x17) - 0x7F; - if ((v0 >= -0x7e && v0 < 0x80) || raw == 0) { + if ((v0 >= -0x7E && v0 < 0x80) || raw == 0) { FaultDrawer_Printf("F%02d:%14.7e ", idx, *value); } else { FaultDrawer_Printf("F%02d: %08x(16) ", idx, raw); @@ -358,9 +362,9 @@ void Fault_PrintFReg(s32 idx, f32* value) { void Fault_LogFReg(s32 idx, f32* value) { u32 raw = *(u32*)value; - s32 v0 = ((raw & 0x7f800000) >> 0x17) - 0x7f; + s32 v0 = ((raw & 0x7F800000) >> 0x17) - 0x7F; - if ((v0 >= -0x7e && v0 < 0x80) || raw == 0) { + if ((v0 >= -0x7E && v0 < 0x80) || raw == 0) { osSyncPrintf("F%02d:%14.7e ", idx, *value); } else { osSyncPrintf("F%02d: %08x(16) ", idx, *(u32*)value); @@ -370,6 +374,7 @@ void Fault_LogFReg(s32 idx, f32* value) { void Fault_PrintFPCR(u32 value) { s32 i; u32 flag = 0x20000; + FaultDrawer_Printf("FPCSR:%08xH ", value); for (i = 0; i < 6; i++) { if (value & flag) { @@ -384,6 +389,7 @@ void Fault_PrintFPCR(u32 value) { void Fault_LogFPCR(u32 value) { s32 i; u32 flag = 0x20000; + osSyncPrintf("FPCSR:%08xH ", value); for (i = 0; i < 6; i++) { if (value & flag) { @@ -396,11 +402,12 @@ void Fault_LogFPCR(u32 value) { void Fault_PrintThreadContext(OSThread* t) { __OSThreadContext* ctx; - s32 causeStrIdx = (s32)((((u32)t->context.cause >> 2) & 0x1f) << 0x10) >> 0x10; + s32 causeStrIdx = (s32)((((u32)t->context.cause >> 2) & 0x1F) << 0x10) >> 0x10; + if (causeStrIdx == 0x17) { causeStrIdx = 0x10; } - if (causeStrIdx == 0x1f) { + if (causeStrIdx == 0x1F) { causeStrIdx = 0x11; } @@ -433,10 +440,10 @@ void Fault_PrintThreadContext(OSThread* t) { Fault_PrintFReg(6, &ctx->fp6.f.f_even); FaultDrawer_Printf("\n"); Fault_PrintFReg(8, &ctx->fp8.f.f_even); - Fault_PrintFReg(0xa, &ctx->fp10.f.f_even); + Fault_PrintFReg(0xA, &ctx->fp10.f.f_even); FaultDrawer_Printf("\n"); - Fault_PrintFReg(0xc, &ctx->fp12.f.f_even); - Fault_PrintFReg(0xe, &ctx->fp14.f.f_even); + Fault_PrintFReg(0xC, &ctx->fp12.f.f_even); + Fault_PrintFReg(0xE, &ctx->fp14.f.f_even); FaultDrawer_Printf("\n"); Fault_PrintFReg(0x10, &ctx->fp16.f.f_even); Fault_PrintFReg(0x12, &ctx->fp18.f.f_even); @@ -445,21 +452,22 @@ void Fault_PrintThreadContext(OSThread* t) { Fault_PrintFReg(0x16, &ctx->fp22.f.f_even); FaultDrawer_Printf("\n"); Fault_PrintFReg(0x18, &ctx->fp24.f.f_even); - Fault_PrintFReg(0x1a, &ctx->fp26.f.f_even); + Fault_PrintFReg(0x1A, &ctx->fp26.f.f_even); FaultDrawer_Printf("\n"); - Fault_PrintFReg(0x1c, &ctx->fp28.f.f_even); - Fault_PrintFReg(0x1e, &ctx->fp30.f.f_even); + Fault_PrintFReg(0x1C, &ctx->fp28.f.f_even); + Fault_PrintFReg(0x1E, &ctx->fp30.f.f_even); FaultDrawer_Printf("\n"); FaultDrawer_SetCharPad(0, 0); } void Fault_LogThreadContext(OSThread* t) { __OSThreadContext* ctx; - s32 causeStrIdx = (s32)((((u32)t->context.cause >> 2) & 0x1f) << 0x10) >> 0x10; + s32 causeStrIdx = (s32)((((u32)t->context.cause >> 2) & 0x1F) << 0x10) >> 0x10; + if (causeStrIdx == 0x17) { causeStrIdx = 0x10; } - if (causeStrIdx == 0x1f) { + if (causeStrIdx == 0x1F) { causeStrIdx = 0x11; } @@ -488,10 +496,10 @@ void Fault_LogThreadContext(OSThread* t) { Fault_LogFReg(6, &ctx->fp6.f.f_even); osSyncPrintf("\n"); Fault_LogFReg(8, &ctx->fp8.f.f_even); - Fault_LogFReg(0xa, &ctx->fp10.f.f_even); + Fault_LogFReg(0xA, &ctx->fp10.f.f_even); osSyncPrintf("\n"); - Fault_LogFReg(0xc, &ctx->fp12.f.f_even); - Fault_LogFReg(0xe, &ctx->fp14.f.f_even); + Fault_LogFReg(0xC, &ctx->fp12.f.f_even); + Fault_LogFReg(0xE, &ctx->fp14.f.f_even); osSyncPrintf("\n"); Fault_LogFReg(0x10, &ctx->fp16.f.f_even); Fault_LogFReg(0x12, &ctx->fp18.f.f_even); @@ -500,17 +508,18 @@ void Fault_LogThreadContext(OSThread* t) { Fault_LogFReg(0x16, &ctx->fp22.f.f_even); osSyncPrintf("\n"); Fault_LogFReg(0x18, &ctx->fp24.f.f_even); - Fault_LogFReg(0x1a, &ctx->fp26.f.f_even); + Fault_LogFReg(0x1A, &ctx->fp26.f.f_even); osSyncPrintf("\n"); - Fault_LogFReg(0x1c, &ctx->fp28.f.f_even); - Fault_LogFReg(0x1e, &ctx->fp30.f.f_even); + Fault_LogFReg(0x1C, &ctx->fp28.f.f_even); + Fault_LogFReg(0x1E, &ctx->fp30.f.f_even); osSyncPrintf("\n"); } OSThread* Fault_FindFaultedThread() { OSThread* iter = __osGetActiveQueue(); + while (iter->priority != -1) { - if (iter->priority > 0 && iter->priority < 0x7f && (iter->flags & 3)) { + if (iter->priority > 0 && iter->priority < 0x7F && (iter->flags & 3)) { return iter; } iter = iter->tlnext; @@ -520,10 +529,11 @@ OSThread* Fault_FindFaultedThread() { void Fault_Wait5Seconds(void) { OSTime start[2]; // to make the function allocate 0x28 bytes of stack instead of 0x20 + start[0] = osGetTime(); do { Fault_Sleep(0x10); - } while ((osGetTime() - start[0]) < OS_USEC_TO_CYCLES(5000000) + 1); // 0xdf84759 + } while ((osGetTime() - start[0]) < OS_USEC_TO_CYCLES(5000000) + 1); sFaultStructPtr->faultActive = true; } @@ -684,8 +694,8 @@ void Fault_DrawMemDumpPage(const char* title, u32* addr, u32 param_3) { if (alignedAddr < (u32*)0x80000000) { alignedAddr = (u32*)0x80000000; } - if (alignedAddr > (u32*)0x807fff00) { - alignedAddr = (u32*)0x807fff00; + if (alignedAddr > (u32*)0x807FFF00) { + alignedAddr = (u32*)0x807FFF00; } alignedAddr = (u32*)((u32)alignedAddr & ~3); @@ -693,7 +703,7 @@ void Fault_DrawMemDumpPage(const char* title, u32* addr, u32 param_3) { Fault_FillScreenBlack(); FaultDrawer_SetCharPad(-2, 0); - FaultDrawer_DrawText(0x24, 0x12, "%s %08x", title ? title : "PrintDump", alignedAddr); + FaultDrawer_DrawText(0x24, 0x12, "%s %08x", title != NULL ? title : "PrintDump", alignedAddr); if (alignedAddr >= (u32*)0x80000000 && alignedAddr < (u32*)0xC0000000) { for (y = 0x1C; y != 0xE2; y += 9) { FaultDrawer_DrawText(0x18, y, "%06x", writeAddr); @@ -717,8 +727,8 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { if (addr < 0x80000000) { addr = 0x80000000; } - if (addr > 0x807fff00) { - addr = 0x807fff00; + if (addr > 0x807FFF00) { + addr = 0x807FFF00; } addr &= ~0xF; @@ -884,7 +894,7 @@ void Fault_ResumeThread(OSThread* t) { t->context.cause = 0; t->context.fpcsr = 0; t->context.pc += 4; - *(u32*)t->context.pc = 0xd; + *(u32*)t->context.pc = 0xD; osWritebackDCache(t->context.pc, 4); osInvalICache(t->context.pc, 4); osStartThread(t); @@ -892,9 +902,10 @@ void Fault_ResumeThread(OSThread* t) { void Fault_CommitFB() { u16* fb; + osViSetYScale(1.0f); osViSetMode(&osViModeNtscLan1); - osViSetSpecialFeatures(0x42); // gama_disable|dither_fliter_enable_aa_mode3_disable + osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_DITHER_FILTER_ON); osViBlack(false); if (sFaultStructPtr->fb) { @@ -902,7 +913,7 @@ void Fault_CommitFB() { } else { fb = (u16*)osViGetNextFramebuffer(); if ((u32)fb == 0x80000000) { - fb = (u16*)((osMemSize | 0x80000000) - 0x25800); + fb = (u16*)((osMemSize | 0x80000000) - sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])); } } @@ -972,7 +983,7 @@ void Fault_ThreadEntry(void* arg) { } } while (faultedThread == NULL); - __osSetFpcCsr(__osGetFpcCsr() & -0xf81); + __osSetFpcCsr(__osGetFpcCsr() & -0xF81); sFaultStructPtr->faultedThread = faultedThread; while (!sFaultStructPtr->faultHandlerEnabled) { @@ -1045,11 +1056,11 @@ void Fault_Init(void) { void Fault_HangupFaultClient(const char* arg0, const char* arg1) { osSyncPrintf("HungUp on Thread %d\n", osGetThreadId(0)); - osSyncPrintf("%s\n", arg0 ? arg0 : "(NULL)"); - osSyncPrintf("%s\n", arg1 ? arg1 : "(NULL)"); + osSyncPrintf("%s\n", arg0 != NULL ? arg0 : "(NULL)"); + osSyncPrintf("%s\n", arg1 != NULL ? arg1 : "(NULL)"); FaultDrawer_Printf("HungUp on Thread %d\n", osGetThreadId(0)); - FaultDrawer_Printf("%s\n", arg0 ? arg0 : "(NULL)"); - FaultDrawer_Printf("%s\n", arg1 ? arg1 : "(NULL)"); + FaultDrawer_Printf("%s\n", arg0 != NULL ? arg0 : "(NULL)"); + FaultDrawer_Printf("%s\n", arg1 != NULL ? arg1 : "(NULL)"); } void Fault_AddHungupAndCrashImpl(const char* arg0, const char* arg1) { |
