1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-02 15:55:59 +00:00
oot/src/code/z_debug.c

248 lines
7.7 KiB
C
Raw Normal View History

#include "global.h"
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
typedef struct {
2020-03-18 14:27:49 +00:00
u8 x;
u8 y;
u8 colorId;
char text[0x15];
} PrintTextBuffer;
2020-03-22 21:19:43 +00:00
typedef struct {
2020-03-18 14:27:49 +00:00
u16 push;
u16 held;
} InputCombo;
2020-03-22 21:19:43 +00:00
GameInfo* gGameInfo;
s32 D_8015FA94; // no known symbols
2020-03-18 16:31:36 +00:00
PrintTextBuffer D_8015FA98[0x16];
2020-03-18 14:27:49 +00:00
2020-03-22 21:19:43 +00:00
s16 D_8011E0B0 = 0; // PrintTextBuffer index
2020-03-18 16:31:36 +00:00
Color_RGBA8 printTextColors[] = {
{ 255, 255, 32, 192 }, { 255, 150, 128, 192 }, { 128, 96, 0, 64 }, { 192, 128, 16, 128 },
{ 255, 192, 32, 128 }, { 230, 230, 220, 64 }, { 128, 150, 255, 128 }, { 128, 255, 32, 128 },
2020-03-18 16:31:36 +00:00
};
2020-03-19 22:06:41 +00:00
InputCombo inputCombos[REG_GROUPS] = {
{ BTN_L, BTN_CUP }, { BTN_L, BTN_CLEFT }, { BTN_L, BTN_CDOWN }, { BTN_L, BTN_A }, { BTN_R, BTN_CDOWN },
{ BTN_L, BTN_CRIGHT }, { BTN_L, BTN_R }, { BTN_L, BTN_DLEFT }, { BTN_L, BTN_DRIGHT }, { BTN_L, BTN_DUP },
{ BTN_L, BTN_B }, { BTN_L, BTN_Z }, { BTN_L, BTN_DDOWN }, { BTN_R, BTN_A }, { BTN_R, BTN_B },
{ BTN_R, BTN_Z }, { BTN_R, BTN_L }, { BTN_R, BTN_CUP }, { BTN_R, BTN_CRIGHT }, { BTN_R, BTN_DLEFT },
{ BTN_R, BTN_CLEFT }, { BTN_R, BTN_START }, { BTN_L, BTN_START }, { BTN_R, BTN_DRIGHT }, { BTN_R, BTN_DUP },
{ BTN_START, BTN_R }, { BTN_START, BTN_A }, { BTN_START, BTN_B }, { BTN_START, BTN_CRIGHT },
2020-03-18 16:31:36 +00:00
};
char regChar[] = " SOPQMYDUIZCNKXcsiWAVHGmnBdkb";
2020-03-18 14:27:49 +00:00
2020-03-22 21:19:43 +00:00
// initialize GameInfo
void func_800636C0(void) {
2020-03-18 14:27:49 +00:00
s32 i;
2020-03-19 22:06:41 +00:00
gGameInfo = (GameInfo*)SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 260);
gGameInfo->regPage = 0;
gGameInfo->regGroup = 0;
gGameInfo->regCur = 0;
gGameInfo->dpadLast = 0;
2020-03-18 14:27:49 +00:00
gGameInfo->repeat = 0;
2020-03-22 21:19:43 +00:00
for (i = 0; i < ARRAY_COUNT(gGameInfo->data); i++) {
2020-03-18 14:27:49 +00:00
gGameInfo->data[i] = 0;
}
}
2020-03-22 21:19:43 +00:00
// Called when free movement is active.
// 8011D394 to enable camera debugger
void func_8006375C(s32 arg0, s32 arg1, const char* text) {
2020-03-17 04:31:30 +00:00
}
2020-03-22 21:19:43 +00:00
// Copy Camera Debugger Text
void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) {
2020-03-18 14:27:49 +00:00
PrintTextBuffer* buf;
2020-03-19 22:06:41 +00:00
char* bufText;
2020-03-23 00:38:25 +00:00
s16 i;
2020-03-18 14:27:49 +00:00
buf = &D_8015FA98[D_8011E0B0];
if (D_8011E0B0 < 0x16) {
buf->x = x;
buf->y = y;
buf->colorId = colorId;
i = 0;
2020-03-23 00:38:25 +00:00
bufText = buf->text;
while ((*bufText++ = *text++)) {
2020-03-23 00:38:25 +00:00
if (i++ > 0x14) {
break;
}
2020-03-18 14:27:49 +00:00
}
2020-03-19 22:06:41 +00:00
*bufText = '\0';
2020-03-18 14:27:49 +00:00
D_8011E0B0++;
}
}
2020-03-22 21:19:43 +00:00
// Draw Text
void func_80063828(GfxPrint* gfxPrint) {
2020-03-18 14:27:49 +00:00
s32 i;
Color_RGBA8* color;
PrintTextBuffer* buffer;
char* text;
i = 0;
2020-03-22 21:19:43 +00:00
if (D_8011E0B0 > 0) {
do {
2020-03-18 14:27:49 +00:00
buffer = &D_8015FA98[i];
text = buffer->text;
2020-03-18 16:31:36 +00:00
color = &printTextColors[buffer->colorId];
2020-03-18 14:27:49 +00:00
GfxPrint_SetColor(gfxPrint, color->r, color->g, color->b, color->a);
GfxPrint_SetPos(gfxPrint, buffer->x, buffer->y);
2020-03-22 21:19:43 +00:00
GfxPrint_Printf(gfxPrint, "%s", text);
2020-03-18 14:27:49 +00:00
i += 1;
} while (i < D_8011E0B0);
}
}
2020-03-22 21:19:43 +00:00
// Edit REG
2020-03-18 14:27:49 +00:00
void func_8006390C(Input* input) {
s32 dpad;
2020-03-19 22:06:41 +00:00
s32 regGroup;
2020-03-18 14:27:49 +00:00
s32 increment;
InputCombo* input_combo;
s32 i;
2020-03-17 04:31:30 +00:00
2020-03-20 00:10:32 +00:00
regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE;
dpad = input->cur.button & (BTN_DUP | BTN_DLEFT | BTN_DRIGHT | BTN_DDOWN);
if (CHECK_BTN_ALL(input->cur.button, BTN_L) || CHECK_BTN_ALL(input->cur.button, BTN_R) ||
CHECK_BTN_ALL(input->cur.button, BTN_START)) {
2020-03-18 16:31:36 +00:00
input_combo = inputCombos;
2020-03-22 21:19:43 +00:00
for (i = 0; i < REG_GROUPS; i++) {
if (~(~input_combo->push | input->cur.button) || ~(~input_combo->held | input->press.button)) {
2020-03-18 14:27:49 +00:00
input_combo++;
2020-03-22 21:19:43 +00:00
} else {
2020-03-18 14:27:49 +00:00
break;
2020-03-22 21:19:43 +00:00
}
2020-03-18 14:27:49 +00:00
}
2020-03-17 04:31:30 +00:00
2020-03-19 22:06:41 +00:00
if (i < REG_GROUPS) {
if (i == gGameInfo->regGroup) {
2020-03-20 00:10:32 +00:00
gGameInfo->regPage = (gGameInfo->regPage + 1) % (REG_PAGES + 1);
2020-03-18 14:27:49 +00:00
return;
}
2020-03-19 22:06:41 +00:00
gGameInfo->regGroup = i;
gGameInfo->regPage = 0;
2020-03-18 14:27:49 +00:00
}
2020-03-22 21:19:43 +00:00
} else {
switch (gGameInfo->regPage - 1) {
2020-03-20 00:10:32 +00:00
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
2020-03-17 04:31:30 +00:00
2020-03-22 21:19:43 +00:00
if (dpad == gGameInfo->dpadLast) {
gGameInfo->repeat--;
if (gGameInfo->repeat < 0) {
gGameInfo->repeat = 1;
} else {
dpad ^= gGameInfo->dpadLast;
}
} else {
gGameInfo->repeat = 0x10;
gGameInfo->dpadLast = dpad;
2020-03-18 14:27:49 +00:00
}
2020-03-17 04:31:30 +00:00
z_message_PAL, message_data_static and surrounding doc (#996) * Initial progress on z_message_PAL, very messy * Fix merge * Some more progress * Fix merge * More z_message_PAL * Small progress * More small progress * message_data_static files OK * Prepare z_message_tables * Matched another function, small updates * Attempt to use asm-processor static-symbols branch * Refactor text id declarations * Begin large text codes parser function * Fix merge * Refactor done * Build OK, add color and highscore names * Remove encoded text headers and automatically encode during build * Fix kanfont * Various cleanups * DISP macros * Another match aside data * Further progress * Small improvements * Deduplicate magic values for text control codes, small improvements * Tiny progress * Minor cleanups * Clean up z_message_PAL comment * Progress on large functions * Further progress on large functions * Changes to mkldscript to link .data in the .rodata section * data OK * Few improvements * Use gDPLoadTextureBlock macros where appropriate * rm z_message_tables, progress on large functions * 2 more matches * Improvements * Small progress * More progress on big function * progress * match func_80107980 * match Message_Update * match func_8010BED8 * done * Progress on remaining large functions * Small progress on largest function * Another match, extract text and move to assets, improve text build system * Small nonmatchings improvements * docs wip * Largest function maybe equivalent * Fix merge * Document do_action values, largest function is almost instruction-matching * Rename NAVI do_action to NONE, as that appears to be how that value is used in practice * Fix merge * one match * Last function is instruction-matching * Fix * Improvements thanks to engineer124 * Stack matched thanks to petrie911, now just a/v/low t regalloc issues, some cleanup * More variables labeled, use text state enum everywhere * More labels and names * Fix * Actor_IsTalking -> Actor_TalkRequested * Match func_8010C39C and remove unused asm * More docs * Mostly ocarina related docs * All msgModes named * Fix assetclean * Cleanup * Extraction fixes and headers * Suggestions * Review suggestions * Change text extraction again, only extract if the headers do not already exist * Fix * Use ast for charmap, fix assetclean for real this time * Review suggestions * BGM ids and ran formatter * Review comments * rename include_readonly to include_data_with_rodata * Remove leading 0s in number directives * Review suggestions for message_data_static * textbox pos enum comments, rename several enum names from Message to TextBox Co-authored-by: Thar0 <maximilianc64@gmail.com> Co-authored-by: Zelllll <56516451+Zelllll@users.noreply.github.com> Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain> Co-authored-by: Roman971 <romanlasnier@hotmail.com>
2021-11-23 01:20:30 +00:00
increment = CHECK_BTN_ANY(dpad, BTN_DRIGHT)
? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B)
? 1000
: CHECK_BTN_ALL(input->cur.button, BTN_A)
? 100
: CHECK_BTN_ALL(input->cur.button, BTN_B) ? 10 : 1)
: CHECK_BTN_ANY(dpad, BTN_DLEFT)
? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B)
? -1000
: CHECK_BTN_ALL(input->cur.button, BTN_A)
? -100
: CHECK_BTN_ALL(input->cur.button, BTN_B) ? -10 : -1)
: 0;
2020-03-22 21:19:43 +00:00
gGameInfo->data[gGameInfo->regCur + regGroup] += increment;
if (CHECK_BTN_ANY(dpad, BTN_DUP)) {
2020-03-22 21:19:43 +00:00
gGameInfo->regCur--;
if (gGameInfo->regCur < 0) {
gGameInfo->regCur = REG_PER_PAGE - 1;
}
} else if (CHECK_BTN_ANY(dpad, BTN_DDOWN)) {
2020-03-22 21:19:43 +00:00
gGameInfo->regCur++;
if (gGameInfo->regCur >= REG_PER_PAGE) {
gGameInfo->regCur = 0;
}
2020-03-18 14:27:49 +00:00
}
2020-03-22 21:19:43 +00:00
if (iREG(0)) {
iREG(0) = 0;
func_800AA000(0, iREG(1), iREG(2), iREG(3));
2020-03-18 14:27:49 +00:00
}
}
}
}
2020-03-22 21:19:43 +00:00
// Draw Memory Viewer
void func_80063C04(GfxPrint* gfxPrint) {
2020-03-18 14:27:49 +00:00
s32 i;
s32 page = (gGameInfo->regPage * REG_PER_PAGE) - REG_PER_PAGE;
s32 regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE;
s32 pad;
2020-03-19 22:06:41 +00:00
char name[3];
2020-03-18 14:27:49 +00:00
2020-03-22 21:19:43 +00:00
// set up register name string
2020-03-19 22:06:41 +00:00
name[0] = 'R';
2020-03-22 21:19:43 +00:00
name[1] = regChar[gGameInfo->regGroup]; // r_group type char
2020-03-19 22:06:41 +00:00
name[2] = '\0';
GfxPrint_SetColor(gfxPrint, 0, 128, 128, 128);
2020-03-18 14:27:49 +00:00
2020-03-22 21:19:43 +00:00
for (i = 0; i != REG_PER_PAGE; i++) {
if (i == gGameInfo->regCur) {
GfxPrint_SetColor(gfxPrint, 0, 255, 255, 255);
2020-03-18 14:27:49 +00:00
}
GfxPrint_SetPos(gfxPrint, 3, i + 5);
2020-03-19 22:06:41 +00:00
GfxPrint_Printf(gfxPrint, "%s%02d%6d", &name, page + i, gGameInfo->data[i + regGroup]);
2020-03-22 21:19:43 +00:00
if (i == gGameInfo->regCur) {
GfxPrint_SetColor(gfxPrint, 0, 128, 128, 128);
2020-03-18 14:27:49 +00:00
}
}
}
void func_80063D7C(GraphicsContext* gfxCtx) {
Gfx* sp7C;
Gfx* sp78;
GfxPrint gfxPrint;
Gfx* tempRet;
2020-03-18 14:27:49 +00:00
OPEN_DISPS(gfxCtx, "../z_debug.c", 628);
GfxPrint_Init(&gfxPrint);
sp78 = POLY_OPA_DISP;
tempRet = Graph_GfxPlusOne(POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempRet);
2020-03-19 22:06:41 +00:00
GfxPrint_Open(&gfxPrint, tempRet);
2020-03-18 14:27:49 +00:00
if ((OREG(0) == 1) || (OREG(0) == 8)) {
func_80063828(&gfxPrint);
}
2020-03-19 22:06:41 +00:00
if (gGameInfo->regPage != 0) {
2020-03-18 14:27:49 +00:00
func_80063C04(&gfxPrint);
}
D_8011E0B0 = 0;
sp7C = GfxPrint_Close(&gfxPrint);
gSPEndDisplayList(sp7C++);
Graph_BranchDlist(sp78, sp7C);
POLY_OPA_DISP = sp7C;
if (1) {}
CLOSE_DISPS(gfxCtx, "../z_debug.c", 664);
GfxPrint_Destroy(&gfxPrint);
2020-03-18 14:27:49 +00:00
}