2020-10-03 15:22:44 +00:00
|
|
|
#include "global.h"
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
typedef struct {
|
2023-01-12 21:06:31 +00:00
|
|
|
/* 0x0 */ u8 x;
|
|
|
|
/* 0x1 */ u8 y;
|
|
|
|
/* 0x2 */ u8 colorIndex;
|
|
|
|
/* 0x3 */ char text[21];
|
|
|
|
} DebugCamTextBufferEntry; // size = 0x18
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
typedef struct {
|
2023-01-12 21:06:31 +00:00
|
|
|
/* 0x0 */ u16 hold;
|
|
|
|
/* 0x2 */ u16 press;
|
2022-07-14 23:02:07 +00:00
|
|
|
} InputCombo; // size = 0x4
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
RegEditor* gRegEditor;
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
DebugCamTextBufferEntry sDebugCamTextBuffer[22];
|
2022-12-30 01:23:09 +00:00
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
s16 sDebugCamTextEntryCount = 0;
|
2022-12-30 01:23:09 +00:00
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
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
|
2020-03-18 16:31:36 +00:00
|
|
|
};
|
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
InputCombo sRegGroupInputCombos[REG_GROUPS] = {
|
|
|
|
{ BTN_L, BTN_CUP }, // REG
|
|
|
|
{ BTN_L, BTN_CLEFT }, // SREG
|
|
|
|
{ BTN_L, BTN_CDOWN }, // OREG
|
|
|
|
{ BTN_L, BTN_A }, // PREG
|
|
|
|
{ BTN_R, BTN_CDOWN }, // QREG
|
|
|
|
{ BTN_L, BTN_CRIGHT }, // MREG
|
|
|
|
{ BTN_L, BTN_R }, // YREG
|
|
|
|
{ BTN_L, BTN_DLEFT }, // DREG
|
|
|
|
{ BTN_L, BTN_DRIGHT }, // UREG
|
|
|
|
{ BTN_L, BTN_DUP }, // IREG
|
|
|
|
{ BTN_L, BTN_B }, // ZREG
|
|
|
|
{ BTN_L, BTN_Z }, // CREG
|
|
|
|
{ BTN_L, BTN_DDOWN }, // NREG
|
|
|
|
{ BTN_R, BTN_A }, // KREG
|
|
|
|
{ BTN_R, BTN_B }, // XREG
|
|
|
|
{ BTN_R, BTN_Z }, // cREG
|
|
|
|
{ BTN_R, BTN_L }, // sREG
|
|
|
|
{ BTN_R, BTN_CUP }, // iREG
|
|
|
|
{ BTN_R, BTN_CRIGHT }, // WREG
|
|
|
|
{ BTN_R, BTN_DLEFT }, // AREG
|
|
|
|
{ BTN_R, BTN_CLEFT }, // VREG
|
|
|
|
{ BTN_R, BTN_START }, // HREG
|
|
|
|
{ BTN_L, BTN_START }, // GREG
|
|
|
|
{ BTN_R, BTN_DRIGHT }, // mREG
|
|
|
|
{ BTN_R, BTN_DUP }, // nREG
|
|
|
|
{ BTN_START, BTN_R }, // BREG
|
|
|
|
{ BTN_START, BTN_A }, // dREG
|
|
|
|
{ BTN_START, BTN_B }, // kREG
|
|
|
|
{ BTN_START, BTN_CRIGHT }, // bREG
|
|
|
|
|
2020-03-18 16:31:36 +00:00
|
|
|
};
|
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
char sRegGroupChars[REG_GROUPS] = {
|
|
|
|
' ', // REG
|
|
|
|
'S', // SREG
|
|
|
|
'O', // OREG
|
|
|
|
'P', // PREG
|
|
|
|
'Q', // QREG
|
|
|
|
'M', // MREG
|
|
|
|
'Y', // YREG
|
|
|
|
'D', // DREG
|
|
|
|
'U', // UREG
|
|
|
|
'I', // IREG
|
|
|
|
'Z', // ZREG
|
|
|
|
'C', // CREG
|
|
|
|
'N', // NREG
|
|
|
|
'K', // KREG
|
|
|
|
'X', // XREG
|
|
|
|
'c', // cREG
|
|
|
|
's', // sREG
|
|
|
|
'i', // iREG
|
|
|
|
'W', // WREG
|
|
|
|
'A', // AREG
|
|
|
|
'V', // VREG
|
|
|
|
'H', // HREG
|
|
|
|
'G', // GREG
|
|
|
|
'm', // mREG
|
|
|
|
'n', // nREG
|
|
|
|
'B', // BREG
|
|
|
|
'd', // dREG
|
|
|
|
'k', // kREG
|
|
|
|
'b', // bREG
|
|
|
|
};
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
void Regs_Init(void) {
|
2020-03-18 14:27:49 +00:00
|
|
|
s32 i;
|
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor = SystemArena_MallocDebug(sizeof(RegEditor), "../z_debug.c", 260);
|
|
|
|
gRegEditor->regPage = 0;
|
|
|
|
gRegEditor->regGroup = 0;
|
|
|
|
gRegEditor->regCur = 0;
|
|
|
|
gRegEditor->dPadInputPrev = 0;
|
|
|
|
gRegEditor->inputRepeatTimer = 0;
|
|
|
|
for (i = 0; i < ARRAY_COUNT(gRegEditor->data); i++) {
|
|
|
|
gRegEditor->data[i] = 0;
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
// Function is stubbed. Name is assumed by similarities in signature to `DebugCamera_ScreenTextColored` and usage.
|
|
|
|
void DebugCamera_ScreenText(u8 x, u8 y, const char* text) {
|
2020-03-17 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
void DebugCamera_ScreenTextColored(u8 x, u8 y, u8 colorIndex, const char* text) {
|
|
|
|
DebugCamTextBufferEntry* entry = &sDebugCamTextBuffer[sDebugCamTextEntryCount];
|
2022-07-14 23:02:07 +00:00
|
|
|
char* textDest;
|
|
|
|
s16 charCount;
|
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
if (sDebugCamTextEntryCount < ARRAY_COUNT(sDebugCamTextBuffer)) {
|
2022-07-14 23:02:07 +00:00
|
|
|
entry->x = x;
|
|
|
|
entry->y = y;
|
|
|
|
entry->colorIndex = colorIndex;
|
|
|
|
|
|
|
|
// Copy text into the entry, truncating if needed
|
|
|
|
charCount = 0;
|
|
|
|
textDest = entry->text;
|
2022-12-30 01:23:09 +00:00
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
while ((*textDest++ = *text++) != '\0') {
|
|
|
|
if (charCount++ > (ARRAY_COUNT(entry->text) - 1)) {
|
2020-03-23 00:38:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
2022-12-30 01:23:09 +00:00
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
*textDest = '\0';
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
sDebugCamTextEntryCount++;
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
void DebugCamera_DrawScreenText(GfxPrint* printer) {
|
2020-03-18 14:27:49 +00:00
|
|
|
s32 i;
|
|
|
|
Color_RGBA8* color;
|
2023-01-12 21:06:31 +00:00
|
|
|
DebugCamTextBufferEntry* entry;
|
2022-07-14 23:02:07 +00:00
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
for (i = 0; i < sDebugCamTextEntryCount; i++) {
|
|
|
|
entry = &sDebugCamTextBuffer[i];
|
|
|
|
color = &sDebugCamTextColors[entry->colorIndex];
|
2022-07-14 23:02:07 +00:00
|
|
|
|
|
|
|
GfxPrint_SetColor(printer, color->r, color->g, color->b, color->a);
|
|
|
|
GfxPrint_SetPos(printer, entry->x, entry->y);
|
|
|
|
GfxPrint_Printf(printer, "%s", entry->text);
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 01:23:09 +00:00
|
|
|
/**
|
|
|
|
* Updates the state of the Reg Editor according to user input.
|
|
|
|
* Also contains a controller rumble test that can be interfaced with via related REGs.
|
2022-12-30 18:55:14 +00:00
|
|
|
*/
|
2022-10-15 05:40:00 +00:00
|
|
|
void Regs_UpdateEditor(Input* input) {
|
2022-07-14 23:02:07 +00:00
|
|
|
s32 dPadInputCur;
|
2022-10-15 05:40:00 +00:00
|
|
|
s32 pageDataStart = ((gRegEditor->regGroup * REG_PAGES) + gRegEditor->regPage - 1) * REGS_PER_PAGE;
|
2020-03-18 14:27:49 +00:00
|
|
|
s32 increment;
|
|
|
|
s32 i;
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
dPadInputCur = input->cur.button & (BTN_DUP | BTN_DLEFT | BTN_DRIGHT | BTN_DDOWN);
|
2022-12-30 01:23:09 +00:00
|
|
|
|
2020-10-03 15:22:44 +00:00
|
|
|
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)) {
|
2022-07-14 23:02:07 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
for (i = 0; i < REG_GROUPS; i++) {
|
2022-07-14 23:02:07 +00:00
|
|
|
if (CHECK_BTN_ALL(input->cur.button, sRegGroupInputCombos[i].hold) &&
|
|
|
|
CHECK_BTN_ALL(input->press.button, sRegGroupInputCombos[i].press)) {
|
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
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
// If a combo corresponding to a reg group was found
|
2020-03-19 22:06:41 +00:00
|
|
|
if (i < REG_GROUPS) {
|
2022-10-15 05:40:00 +00:00
|
|
|
if (i == gRegEditor->regGroup) {
|
2022-07-14 23:02:07 +00:00
|
|
|
// Same reg group as current, advance page index
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor->regPage = (gRegEditor->regPage + 1) % (REG_PAGES + 1);
|
2022-07-14 23:02:07 +00:00
|
|
|
} else {
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor->regGroup = i; // Switch current reg group
|
|
|
|
gRegEditor->regPage = 0; // Disable reg editor
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2022-10-15 05:40:00 +00:00
|
|
|
switch (gRegEditor->regPage) {
|
2020-03-20 00:10:32 +00:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2022-07-14 23:02:07 +00:00
|
|
|
case 6:
|
2022-10-15 05:40:00 +00:00
|
|
|
if (dPadInputCur == gRegEditor->dPadInputPrev) {
|
|
|
|
gRegEditor->inputRepeatTimer--;
|
|
|
|
if (gRegEditor->inputRepeatTimer < 0) {
|
|
|
|
gRegEditor->inputRepeatTimer = 1;
|
2020-03-22 21:19:43 +00:00
|
|
|
} else {
|
2022-10-15 05:40:00 +00:00
|
|
|
dPadInputCur ^= gRegEditor->dPadInputPrev;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor->inputRepeatTimer = 16;
|
|
|
|
gRegEditor->dPadInputPrev = dPadInputCur;
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
2020-03-17 04:31:30 +00:00
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
increment =
|
|
|
|
CHECK_BTN_ANY(dPadInputCur, BTN_DRIGHT) ? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B) ? 1000
|
2021-12-06 00:11:38 +00:00
|
|
|
: CHECK_BTN_ALL(input->cur.button, BTN_A) ? 100
|
|
|
|
: CHECK_BTN_ALL(input->cur.button, BTN_B) ? 10
|
|
|
|
: 1)
|
2022-07-14 23:02:07 +00:00
|
|
|
: CHECK_BTN_ANY(dPadInputCur, BTN_DLEFT) ? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B) ? -1000
|
2021-12-06 00:11:38 +00:00
|
|
|
: 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
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor->data[gRegEditor->regCur + pageDataStart] += increment;
|
2022-07-14 23:02:07 +00:00
|
|
|
|
|
|
|
if (CHECK_BTN_ANY(dPadInputCur, BTN_DUP)) {
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor->regCur--;
|
|
|
|
if (gRegEditor->regCur < 0) {
|
|
|
|
gRegEditor->regCur = REGS_PER_PAGE - 1;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2022-07-14 23:02:07 +00:00
|
|
|
} else if (CHECK_BTN_ANY(dPadInputCur, BTN_DDOWN)) {
|
2022-10-15 05:40:00 +00:00
|
|
|
gRegEditor->regCur++;
|
|
|
|
if (gRegEditor->regCur >= REGS_PER_PAGE) {
|
|
|
|
gRegEditor->regCur = 0;
|
2020-03-22 21:19:43 +00:00
|
|
|
}
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
2022-07-14 23:02:07 +00:00
|
|
|
|
2020-03-22 21:19:43 +00:00
|
|
|
if (iREG(0)) {
|
|
|
|
iREG(0) = 0;
|
2022-09-27 16:40:26 +00:00
|
|
|
Rumble_Request(0.0f, iREG(1), iREG(2), iREG(3));
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
2022-07-14 23:02:07 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
void Regs_DrawEditor(GfxPrint* printer) {
|
2020-03-18 14:27:49 +00:00
|
|
|
s32 i;
|
2022-10-15 05:40:00 +00:00
|
|
|
s32 pageStart = (gRegEditor->regPage - 1) * REGS_PER_PAGE;
|
|
|
|
s32 pageDataStart = ((gRegEditor->regGroup * REG_PAGES) + gRegEditor->regPage - 1) * REGS_PER_PAGE;
|
2021-02-14 00:49:40 +00:00
|
|
|
s32 pad;
|
2022-07-14 23:02:07 +00:00
|
|
|
char regGroupName[3];
|
|
|
|
|
|
|
|
regGroupName[0] = 'R';
|
2022-10-15 05:40:00 +00:00
|
|
|
regGroupName[1] = sRegGroupChars[gRegEditor->regGroup];
|
2022-07-14 23:02:07 +00:00
|
|
|
regGroupName[2] = '\0';
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint_SetColor(printer, 0, 128, 128, 128);
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2022-07-14 23:02:07 +00:00
|
|
|
for (i = 0; i < REGS_PER_PAGE; i++) {
|
2022-10-15 05:40:00 +00:00
|
|
|
if (i == gRegEditor->regCur) {
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint_SetColor(printer, 0, 255, 255, 255);
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
2022-07-14 23:02:07 +00:00
|
|
|
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint_SetPos(printer, 3, i + 5);
|
2022-10-15 05:40:00 +00:00
|
|
|
GfxPrint_Printf(printer, "%s%02d%6d", regGroupName, pageStart + i, gRegEditor->data[i + pageDataStart]);
|
2022-07-14 23:02:07 +00:00
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
if (i == gRegEditor->regCur) {
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint_SetColor(printer, 0, 128, 128, 128);
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 01:23:09 +00:00
|
|
|
/**
|
|
|
|
* Draws the Reg Editor and Debug Camera text on screen
|
|
|
|
*/
|
|
|
|
void Debug_DrawText(GraphicsContext* gfxCtx) {
|
2022-07-14 23:02:07 +00:00
|
|
|
Gfx* gfx;
|
|
|
|
Gfx* opaStart;
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint printer;
|
2022-07-14 23:02:07 +00:00
|
|
|
s32 pad;
|
2020-03-18 14:27:49 +00:00
|
|
|
|
2020-08-29 23:00:17 +00:00
|
|
|
OPEN_DISPS(gfxCtx, "../z_debug.c", 628);
|
|
|
|
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint_Init(&printer);
|
2022-07-14 23:02:07 +00:00
|
|
|
opaStart = POLY_OPA_DISP;
|
|
|
|
gfx = Graph_GfxPlusOne(POLY_OPA_DISP);
|
|
|
|
gSPDisplayList(OVERLAY_DISP++, gfx);
|
|
|
|
GfxPrint_Open(&printer, gfx);
|
2020-03-18 14:27:49 +00:00
|
|
|
|
|
|
|
if ((OREG(0) == 1) || (OREG(0) == 8)) {
|
2023-01-12 21:06:31 +00:00
|
|
|
DebugCamera_DrawScreenText(&printer);
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 05:40:00 +00:00
|
|
|
if (gRegEditor->regPage != 0) {
|
|
|
|
Regs_DrawEditor(&printer);
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 21:06:31 +00:00
|
|
|
sDebugCamTextEntryCount = 0;
|
2022-07-14 23:02:07 +00:00
|
|
|
|
|
|
|
gfx = GfxPrint_Close(&printer);
|
|
|
|
gSPEndDisplayList(gfx++);
|
|
|
|
Graph_BranchDlist(opaStart, gfx);
|
|
|
|
POLY_OPA_DISP = gfx;
|
2020-08-29 23:00:17 +00:00
|
|
|
|
2021-02-14 00:49:40 +00:00
|
|
|
if (1) {}
|
2020-08-29 23:00:17 +00:00
|
|
|
|
|
|
|
CLOSE_DISPS(gfxCtx, "../z_debug.c", 664);
|
|
|
|
|
2021-11-28 13:48:17 +00:00
|
|
|
GfxPrint_Destroy(&printer);
|
2020-03-18 14:27:49 +00:00
|
|
|
}
|