diff --git a/include/functions.h b/include/functions.h index 7f1dd1efa..278188680 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1227,15 +1227,6 @@ s32 Actor_TrackPlayerSetFocusHeight(PlayState* play, Actor* actor, Vec3s* headRo s32 Actor_TrackPlayer(PlayState* play, Actor* actor, Vec3s* headRot, Vec3s* torsoRot, Vec3f focusPos); void SaveContext_Init(void); void GameInfo_Init(void); -DebugDispObject* DebugDisplay_Init(void); -void DebugDisplay_DrawObjects(PlayState* play); -DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX, f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type, GraphicsContext* gfxCtx); -// void func_800E9C90(void); -// void func_800E9CA0(s32 param_1, UNK_TYPE1 param_2, s8* param_3); -// void func_800E9CFC(void); -// void func_800E9DBC(void); -// void func_800E9E94(void); -void func_800E9F78(GraphicsContext* gfxCtx); void Cutscene_Init(PlayState* play, CutsceneContext* csCtx); void Cutscene_Start(PlayState* play, CutsceneContext* csCtx); diff --git a/include/z64.h b/include/z64.h index 028162a1e..732fbce3c 100644 --- a/include/z64.h +++ b/include/z64.h @@ -858,16 +858,6 @@ typedef struct { /* 0x14 */ Gfx* dList; } VisMono; // size = 0x18 -typedef struct DebugDispObject { - /* 0x00 */ Vec3f pos; - /* 0x0C */ Vec3s rot; - /* 0x14 */ Vec3f scale; - /* 0x20 */ Color_RGBA8 color; - /* 0x24 */ s16 type; - /* 0x28 */ struct DebugDispObject* next; - /* 0x2C */ s32 pad; //Padding not in the OOT version -} DebugDispObject; // size = 0x30 - typedef struct { /* 0x0 */ f32 rangeSq; /* 0x4 */ f32 leashScale; diff --git a/include/z64debug_display.h b/include/z64debug_display.h new file mode 100644 index 000000000..885a3839c --- /dev/null +++ b/include/z64debug_display.h @@ -0,0 +1,25 @@ +#ifndef Z64DEBUG_DISPLAY_H +#define Z64DEBUG_DISPLAY_H + +#include "color.h" +#include "ultra64.h" +#include "z64math.h" + +struct GraphicsContext; +struct PlayState; + +typedef struct DebugDispObject { + /* 0x00 */ Vec3f pos; + /* 0x0C */ Vec3s rot; + /* 0x14 */ Vec3f scale; + /* 0x20 */ Color_RGBA8 color; + /* 0x24 */ s16 type; + /* 0x28 */ struct DebugDispObject* next; + /* 0x2C */ s32 pad; // Padding is not in the OoT version +} DebugDispObject; // size = 0x30 + +DebugDispObject* DebugDisplay_Init(void); +void DebugDisplay_DrawObjects(struct PlayState* play); +DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX, f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type, struct GraphicsContext* gfxCtx); + +#endif diff --git a/include/z64debug_text.h b/include/z64debug_text.h new file mode 100644 index 000000000..65595f99e --- /dev/null +++ b/include/z64debug_text.h @@ -0,0 +1,36 @@ +#ifndef Z64DEBUG_TEXT_H +#define Z64DEBUG_TEXT_H + +#include "ultra64.h" + +struct GraphicsContext; + +typedef enum { + /* 0 */ DEBUG_TEXT_BLACK, + /* 1 */ DEBUG_TEXT_BLUE, + /* 2 */ DEBUG_TEXT_RED, + /* 3 */ DEBUG_TEXT_PURPLE, + /* 4 */ DEBUG_TEXT_GREEN, + /* 5 */ DEBUG_TEXT_CYAN, + /* 6 */ DEBUG_TEXT_YELLOW, + /* 7 */ DEBUG_TEXT_WHITE +} DebugTextColor; + +typedef enum { + /* 0 */ DEBUG_CAM_TEXT_YELLOW, + /* 1 */ DEBUG_CAM_TEXT_PEACH, + /* 2 */ DEBUG_CAM_TEXT_BROWN, + /* 3 */ DEBUG_CAM_TEXT_ORANGE, + /* 4 */ DEBUG_CAM_TEXT_GOLD, + /* 5 */ DEBUG_CAM_TEXT_WHITE, + /* 6 */ DEBUG_CAM_TEXT_BLUE, + /* 7 */ DEBUG_CAM_TEXT_GREEN +} DebugCamTextColor; + +void Debug_ClearTextDrawFlags(void); +void Debug_ScreenText(s32 index, s32 colorIndex, const char* text); +void DebugCamera_ScreenText(u8 x, u8 y, u8 colorIndex, const char* text); +void Debug_DrawText(struct GraphicsContext* gfxCtx); + + +#endif diff --git a/spec b/spec index 17a411dc4..404d10026 100644 --- a/spec +++ b/spec @@ -458,8 +458,6 @@ beginseg include "build/src/code/z_debug.o" include "build/src/code/z_debug_display.o" include "build/src/code/z_debug_mode.o" - include "build/data/code/z_debug_mode.data.o" - include "build/data/code/z_debug_mode.bss.o" include "build/src/code/z_demo.o" include "build/src/code/z_draw.o" include "build/src/code/z_eff_footmark.o" diff --git a/src/code/game.c b/src/code/game.c index b7069d312..f3c381e68 100644 --- a/src/code/game.c +++ b/src/code/game.c @@ -1,5 +1,6 @@ #include "global.h" #include "system_malloc.h" +#include "z64debug_text.h" #include "z64rumble.h" #include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h" @@ -90,7 +91,7 @@ void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx) { { s32 requiredScopeTemp; - func_800E9F78(gfxCtx); + Debug_DrawText(gfxCtx); } if (R_ENABLE_ARENA_DBG != 0) { diff --git a/src/code/z_debug_display.c b/src/code/z_debug_display.c index f98b8636e..d9f20d72b 100644 --- a/src/code/z_debug_display.c +++ b/src/code/z_debug_display.c @@ -1,13 +1,14 @@ +#include "z64debug_display.h" #include "global.h" DebugDispObject* sDebugObjectListHead; typedef struct { - /* 0x00 */ s16 drawType; // indicates which draw function to use when displaying the object - /* 0x04 */ void* drawArg; // segment address (display list or texture) passed to the draw funciton when called -} DebugDispObjectInfo; // size = 0x8 + /* 0x0 */ s16 drawType; // indicates which draw function to use when displaying the object + /* 0x4 */ void* drawArg; // segment address (display list or texture) passed to the draw funciton when called +} DebugDispObjectInfo; // size = 0x8 -typedef void (*DebugDispObject_DrawFunc)(DebugDispObject*, void*, PlayState*); +typedef void (*DebugDispObjectDrawFunc)(DebugDispObject*, void*, PlayState*); void DebugDisplay_DrawSpriteI8(DebugDispObject*, void*, PlayState*); void DebugDisplay_DrawPolygon(DebugDispObject*, void*, PlayState*); @@ -44,12 +45,12 @@ DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, #include "code/debug_display/debug_display.c" -DebugDispObject_DrawFunc sDebugObjectDrawFuncTable[] = { DebugDisplay_DrawSpriteI8, DebugDisplay_DrawPolygon }; +DebugDispObjectDrawFunc sDebugObjectDrawFuncTable[] = { DebugDisplay_DrawSpriteI8, DebugDisplay_DrawPolygon }; DebugDispObjectInfo sDebugObjectInfoTable[] = { { 0, sDebugDisplayCircleTex }, { 0, sDebugDisplayCrossTex }, { 0, sDebugDisplayBallTex }, - { 0, sDebugDisplayCursorTex }, { 1, &sDebugDisplay1DL }, { 1, &sDebugDisplay3DL }, - { 1, &sDebugDisplay2DL }, + { 0, sDebugDisplayCursorTex }, { 1, sDebugDisplay1DL }, { 1, sDebugDisplay3DL }, + { 1, sDebugDisplay2DL }, }; void DebugDisplay_DrawObjects(PlayState* play) { @@ -86,7 +87,7 @@ void DebugDisplay_DrawSpriteI8(DebugDispObject* dispObj, void* texture, PlayStat Lights1 sDebugDisplayLight1 = gdSPDefLights1(128, 128, 128, 255, 255, 255, 73, 73, 73); -void DebugDisplay_DrawPolygon(DebugDispObject* dispObj, void* arg1, PlayState* play) { +void DebugDisplay_DrawPolygon(DebugDispObject* dispObj, void* dList, PlayState* play) { OPEN_DISPS(play->state.gfxCtx); func_8012C588(play->state.gfxCtx); @@ -99,7 +100,7 @@ void DebugDisplay_DrawPolygon(DebugDispObject* dispObj, void* arg1, PlayState* p Matrix_Scale(dispObj->scale.x, dispObj->scale.y, dispObj->scale.z, MTXMODE_APPLY); gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(play->state.gfxCtx), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); - gSPDisplayList(POLY_XLU_DISP++, arg1); + gSPDisplayList(POLY_XLU_DISP++, dList); CLOSE_DISPS(play->state.gfxCtx); } diff --git a/src/code/z_debug_mode.c b/src/code/z_debug_mode.c index 0682b3693..a1b464463 100644 --- a/src/code/z_debug_mode.c +++ b/src/code/z_debug_mode.c @@ -1,13 +1,160 @@ +#include "z64debug_text.h" #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug_mode/func_800E9C90.s") +typedef struct { + /* 0x0 */ u8 colorIndex; + /* 0x1 */ char text[11]; +} DebugTextBufferEntry; // size = 0xC -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug_mode/func_800E9CA0.s") +typedef struct { + /* 0x0 */ u8 x; + /* 0x1 */ u8 y; + /* 0x2 */ u8 colorIndex; + /* 0x3 */ char text[41]; +} DebugCamTextBufferEntry; // size = 0x2C -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug_mode/func_800E9CFC.s") +#define DEBUG_TEXT_DRAW_TEXT (1 << 0) +#define DEBUG_TEXT_DRAW_CAM_TEXT (1 << 1) -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug_mode/func_800E9DBC.s") +s32 sDebugTextDrawFlags = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug_mode/func_800E9E94.s") +DebugTextBufferEntry sDebugTextBuffer[] = { + { DEBUG_TEXT_BLACK, " " }, { DEBUG_TEXT_BLACK, " " }, { DEBUG_TEXT_BLACK, " " }, + { DEBUG_TEXT_BLACK, " " }, { DEBUG_TEXT_BLACK, " " }, { DEBUG_TEXT_BLACK, " " }, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_debug_mode/func_800E9F78.s") +Color_RGBA8 sDebugTextColors[] = { + { 0, 0, 0, 64 }, // DEBUG_TEXT_BLACK + { 0, 0, 255, 64 }, // DEBUG_TEXT_BLUE + { 255, 0, 0, 64 }, // DEBUG_TEXT_RED + { 255, 0, 255, 64 }, // DEBUG_TEXT_PURPLE + { 0, 255, 0, 64 }, // DEBUG_TEXT_GREEN + { 0, 255, 255, 64 }, // DEBUG_TEXT_CYAN + { 255, 255, 0, 64 }, // DEBUG_TEXT_YELLOW + { 255, 255, 255, 64 }, // DEBUG_TEXT_WHITE +}; + +DebugCamTextBufferEntry sDebugCamTextBuffer[80]; + +s16 sDebugCamTextEntryCount = 0; + +Color_RGBA8 sDebugCamTextColors[] = { + { 255, 255, 32, 192 }, // DEBUG_CAM_TEXT_YELLOW + { 255, 150, 128, 192 }, // DEBUG_CAM_TEXT_PEACH + { 128, 96, 0, 64 }, // DEBUG_CAM_TEXT_BROWN + { 192, 128, 16, 128 }, // DEBUG_CAM_TEXT_ORANGE + { 255, 192, 32, 128 }, // DEBUG_CAM_TEXT_GOLD + { 230, 230, 220, 64 }, // DEBUG_CAM_TEXT_WHITE + { 128, 150, 255, 128 }, // DEBUG_CAM_TEXT_BLUE + { 128, 255, 32, 128 }, // DEBUG_CAM_TEXT_GREEN +}; + +void Debug_ClearTextDrawFlags(void) { + sDebugTextDrawFlags = 0; +} + +void Debug_ScreenText(s32 index, s32 colorIndex, const char* text) { + DebugTextBufferEntry* entry = &sDebugTextBuffer[index]; + char* textDest = entry->text; + + sDebugTextDrawFlags |= DEBUG_TEXT_DRAW_TEXT; + entry->colorIndex = colorIndex; + + do { + *textDest++ = *text; + } while (*text++ != '\0'); +} + +void Debug_DrawScreenText(GfxPrint* printer) { + DebugTextBufferEntry* entry; + Color_RGBA8* color; + s32 y; + + entry = sDebugTextBuffer; + for (y = 20; y < 20 + ARRAY_COUNT(sDebugTextBuffer); y++) { + GfxPrint_SetPos(printer, 26, y); + color = &sDebugTextColors[entry->colorIndex]; + GfxPrint_SetColor(printer, color->r, color->g, color->b, color->a); + GfxPrint_Printf(printer, "%s", entry->text); + *entry->text = '\0'; + entry++; + } +} + +void DebugCamera_ScreenText(u8 x, u8 y, u8 colorIndex, const char* text) { + DebugCamTextBufferEntry* entry = &sDebugCamTextBuffer[sDebugCamTextEntryCount]; + char* textDest; + s16 charCount; + + sDebugTextDrawFlags |= DEBUG_TEXT_DRAW_CAM_TEXT; + if (sDebugCamTextEntryCount < ARRAY_COUNT(sDebugCamTextBuffer)) { + entry->x = x; + entry->y = y; + entry->colorIndex = colorIndex; + + // Copy text into the entry, truncating if needed + charCount = 0; + textDest = entry->text; + + while ((*textDest++ = *text++) != '\0') { + if (charCount++ >= ARRAY_COUNT(entry->text)) { + break; + } + } + + *textDest = '\0'; + + sDebugCamTextEntryCount++; + } +} + +void DebugCamera_DrawScreenText(GfxPrint* printer) { + DebugCamTextBufferEntry* entry; + Color_RGBA8* color; + s32 i; + + for (i = 0; i < sDebugCamTextEntryCount; i++) { + entry = &sDebugCamTextBuffer[i]; + color = &sDebugCamTextColors[entry->colorIndex]; + + GfxPrint_SetColor(printer, color->r, color->g, color->b, color->a); + GfxPrint_SetPos(printer, entry->x, entry->y); + GfxPrint_Printf(printer, "%s", entry->text); + } +} + +void Debug_DrawText(GraphicsContext* gfxCtx) { + Gfx* gfx; + Gfx* gfxHead; + GfxPrint printer; + + if (THGA_GetSize(&gfxCtx->polyOpa) >= 0x2800) { + GfxPrint_Init(&printer); + + OPEN_DISPS(gfxCtx); + + gfxHead = POLY_OPA_DISP; + gfx = Graph_GfxPlusOne(gfxHead); + gSPDisplayList(DEBUG_DISP++, gfx); + + GfxPrint_Open(&printer, gfx); + + if (sDebugTextDrawFlags & DEBUG_TEXT_DRAW_CAM_TEXT) { + DebugCamera_DrawScreenText(&printer); + } + sDebugCamTextEntryCount = 0; + + if (sDebugTextDrawFlags & DEBUG_TEXT_DRAW_TEXT) { + Debug_DrawScreenText(&printer); + } + + gfx = GfxPrint_Close(&printer); + gSPEndDisplayList(gfx++); + Graph_BranchDlist(gfxHead, gfx); + POLY_OPA_DISP = gfx; + + CLOSE_DISPS(gfxCtx); + + GfxPrint_Destroy(&printer); + } +} diff --git a/src/code/z_play.c b/src/code/z_play.c index f7e3dc521..712b94f11 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -1,4 +1,5 @@ #include "global.h" +#include "z64debug_display.h" #include "z64quake.h" #include "z64rumble.h" #include "z64shrink_window.h" diff --git a/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c b/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c index 5b4f80ee6..571583114 100644 --- a/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c +++ b/src/overlays/actors/ovl_TG_Sw/z_tg_sw.c @@ -5,6 +5,7 @@ */ #include "z_tg_sw.h" +#include "z64debug_display.h" #define FLAGS (ACTOR_FLAG_10) diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index ca5efdcf4..39a4c7c2b 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -1527,12 +1527,12 @@ 0x800E97D8:("DebugDisplay_DrawPolygon",), 0x800E992C:("DebugDisplay_DrawPath",), 0x800E99B0:("DebugDisplay_PathDisplayList",), - 0x800E9C90:("func_800E9C90",), - 0x800E9CA0:("func_800E9CA0",), - 0x800E9CFC:("func_800E9CFC",), - 0x800E9DBC:("func_800E9DBC",), - 0x800E9E94:("func_800E9E94",), - 0x800E9F78:("func_800E9F78",), + 0x800E9C90:("Debug_ClearTextDrawFlags",), + 0x800E9CA0:("Debug_ScreenText",), + 0x800E9CFC:("Debug_DrawScreenText",), + 0x800E9DBC:("DebugCamera_ScreenText",), + 0x800E9E94:("DebugCamera_DrawScreenText",), + 0x800E9F78:("Debug_DrawText",), 0x800EA060:("Cutscene_Init",), 0x800EA0D4:("Cutscene_Start",), 0x800EA0EC:("Cutscene_End",), diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt index 57991aeb5..f680f6bca 100644 --- a/tools/disasm/variables.txt +++ b/tools/disasm/variables.txt @@ -3926,9 +3926,7 @@ 0x801F3F5A:("D_801F3F5A","UNK_TYPE1","",0x1), 0x801F3F60:("gGameInfo","GameInfo*","",0x4), 0x801F3F70:("sDebugObjectListHead","UNK_TYPE1","",0x1), - 0x801F3F80:("D_801F3F80","UNK_TYPE1","",0x1), - 0x801F3F83:("D_801F3F83","UNK_TYPE1","",0x1), - 0x801F48C8:("D_801F48C8","UNK_TYPE1","",0x1), + 0x801F3F80:("D_801F3F80","UNK_TYPE1","",0xDC0), 0x801F4D40:("seqId","u16","",0x2), 0x801F4D42:("sCutsceneQuakeIndex","UNK_TYPE2","",0x2), 0x801F4D48:("sCutsceneCameraInfo","UNK_TYPE","",0x80), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 2992965d7..0f80073e7 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -1041,12 +1041,12 @@ asm/non_matchings/code/z_debug_display/func_800E95F4.s,func_800E95F4,0x800E95F4, asm/non_matchings/code/z_debug_display/func_800E97D8.s,func_800E97D8,0x800E97D8,0x55 asm/non_matchings/code/z_debug_display/func_800E992C.s,func_800E992C,0x800E992C,0x21 asm/non_matchings/code/z_debug_display/func_800E99B0.s,func_800E99B0,0x800E99B0,0xB8 -asm/non_matchings/code/z_debug_mode/func_800E9C90.s,func_800E9C90,0x800E9C90,0x4 -asm/non_matchings/code/z_debug_mode/func_800E9CA0.s,func_800E9CA0,0x800E9CA0,0x17 -asm/non_matchings/code/z_debug_mode/func_800E9CFC.s,func_800E9CFC,0x800E9CFC,0x30 -asm/non_matchings/code/z_debug_mode/func_800E9DBC.s,func_800E9DBC,0x800E9DBC,0x36 -asm/non_matchings/code/z_debug_mode/func_800E9E94.s,func_800E9E94,0x800E9E94,0x39 -asm/non_matchings/code/z_debug_mode/func_800E9F78.s,func_800E9F78,0x800E9F78,0x3A +asm/non_matchings/code/z_debug_mode/Debug_ClearTextDrawFlags.s,Debug_ClearTextDrawFlags,0x800E9C90,0x4 +asm/non_matchings/code/z_debug_mode/Debug_ScreenText.s,Debug_ScreenText,0x800E9CA0,0x17 +asm/non_matchings/code/z_debug_mode/Debug_DrawScreenText.s,Debug_DrawScreenText,0x800E9CFC,0x30 +asm/non_matchings/code/z_debug_mode/DebugCamera_ScreenText.s,DebugCamera_ScreenText,0x800E9DBC,0x36 +asm/non_matchings/code/z_debug_mode/DebugCamera_DrawScreenText.s,DebugCamera_DrawScreenText,0x800E9E94,0x39 +asm/non_matchings/code/z_debug_mode/Debug_DrawText.s,Debug_DrawText,0x800E9F78,0x3A asm/non_matchings/code/z_demo/Cutscene_Init.s,Cutscene_Init,0x800EA060,0x1D asm/non_matchings/code/z_demo/Cutscene_Start.s,Cutscene_Start,0x800EA0D4,0x6 asm/non_matchings/code/z_demo/Cutscene_End.s,Cutscene_End,0x800EA0EC,0x9