Debug mode (#1185)

* OK

* Docs

* PR

* Format

* Update include/z64debug_display.h

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

* Update include/z64debug_display.h

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

---------

Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com>
This commit is contained in:
Derek Hensley
2023-03-07 21:06:49 -08:00
committed by GitHub
parent c917880261
commit 184f5858ff
13 changed files with 241 additions and 52 deletions
+2 -1
View File
@@ -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) {
+10 -9
View File
@@ -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);
}
+153 -6
View File
@@ -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);
}
}
+1
View File
@@ -1,4 +1,5 @@
#include "global.h"
#include "z64debug_display.h"
#include "z64quake.h"
#include "z64rumble.h"
#include "z64shrink_window.h"