/
z_debug.c
243 lines (208 loc) · 7.74 KB
/
z_debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "global.h"
typedef struct {
u8 x;
u8 y;
u8 colorId;
char text[0x15];
} PrintTextBuffer;
typedef struct {
u16 push;
u16 held;
} InputCombo;
GameInfo* gGameInfo;
s32 D_8015FA94; // no known symbols
PrintTextBuffer D_8015FA98[0x16];
s16 D_8011E0B0 = 0; // PrintTextBuffer index
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 },
};
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 },
};
char regChar[] = " SOPQMYDUIZCNKXcsiWAVHGmnBdkb";
// initialize GameInfo
void func_800636C0(void) {
s32 i;
gGameInfo = (GameInfo*)SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 260);
gGameInfo->regPage = 0;
gGameInfo->regGroup = 0;
gGameInfo->regCur = 0;
gGameInfo->dpadLast = 0;
gGameInfo->repeat = 0;
for (i = 0; i < ARRAY_COUNT(gGameInfo->data); i++) {
gGameInfo->data[i] = 0;
}
}
// Called when free movement is active.
// 8011D394 to enable camera debugger
void func_8006375C(s32 arg0, s32 arg1, const char* text) {
}
// Copy Camera Debugger Text
void func_8006376C(u8 x, u8 y, u8 colorId, const char* text) {
PrintTextBuffer* buf;
char* bufText;
s16 i;
buf = &D_8015FA98[D_8011E0B0];
if (D_8011E0B0 < 0x16) {
buf->x = x;
buf->y = y;
buf->colorId = colorId;
i = 0;
bufText = buf->text;
while ((*bufText++ = *text++) != '\0') {
if (i++ > 0x14) {
break;
}
}
*bufText = '\0';
D_8011E0B0++;
}
}
// Draw Text
void func_80063828(GfxPrint* printer) {
s32 i;
Color_RGBA8* color;
PrintTextBuffer* buffer;
char* text;
i = 0;
if (D_8011E0B0 > 0) {
do {
buffer = &D_8015FA98[i];
text = buffer->text;
color = &printTextColors[buffer->colorId];
GfxPrint_SetColor(printer, color->r, color->g, color->b, color->a);
GfxPrint_SetPos(printer, buffer->x, buffer->y);
GfxPrint_Printf(printer, "%s", text);
i += 1;
} while (i < D_8011E0B0);
}
}
// Edit REG
void func_8006390C(Input* input) {
s32 dpad;
s32 regGroup;
s32 increment;
InputCombo* input_combo;
s32 i;
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)) {
input_combo = inputCombos;
for (i = 0; i < REG_GROUPS; i++) {
if (~(~input_combo->push | input->cur.button) || ~(~input_combo->held | input->press.button)) {
input_combo++;
} else {
break;
}
}
if (i < REG_GROUPS) {
if (i == gGameInfo->regGroup) {
gGameInfo->regPage = (gGameInfo->regPage + 1) % (REG_PAGES + 1);
return;
}
gGameInfo->regGroup = i;
gGameInfo->regPage = 0;
}
} else {
switch (gGameInfo->regPage - 1) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
if (dpad == gGameInfo->dpadLast) {
gGameInfo->repeat--;
if (gGameInfo->repeat < 0) {
gGameInfo->repeat = 1;
} else {
dpad ^= gGameInfo->dpadLast;
}
} else {
gGameInfo->repeat = 0x10;
gGameInfo->dpadLast = dpad;
}
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;
gGameInfo->data[gGameInfo->regCur + regGroup] += increment;
if (CHECK_BTN_ANY(dpad, BTN_DUP)) {
gGameInfo->regCur--;
if (gGameInfo->regCur < 0) {
gGameInfo->regCur = REG_PER_PAGE - 1;
}
} else if (CHECK_BTN_ANY(dpad, BTN_DDOWN)) {
gGameInfo->regCur++;
if (gGameInfo->regCur >= REG_PER_PAGE) {
gGameInfo->regCur = 0;
}
}
if (iREG(0)) {
iREG(0) = 0;
func_800AA000(0, iREG(1), iREG(2), iREG(3));
}
}
}
}
// Draw Memory Viewer
void func_80063C04(GfxPrint* printer) {
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;
char name[3];
// set up register name string
name[0] = 'R';
name[1] = regChar[gGameInfo->regGroup]; // r_group type char
name[2] = '\0';
GfxPrint_SetColor(printer, 0, 128, 128, 128);
for (i = 0; i != REG_PER_PAGE; i++) {
if (i == gGameInfo->regCur) {
GfxPrint_SetColor(printer, 0, 255, 255, 255);
}
GfxPrint_SetPos(printer, 3, i + 5);
GfxPrint_Printf(printer, "%s%02d%6d", &name, page + i, gGameInfo->data[i + regGroup]);
if (i == gGameInfo->regCur) {
GfxPrint_SetColor(printer, 0, 128, 128, 128);
}
}
}
void func_80063D7C(GraphicsContext* gfxCtx) {
Gfx* sp7C;
Gfx* sp78;
GfxPrint printer;
Gfx* tempRet;
OPEN_DISPS(gfxCtx, "../z_debug.c", 628);
GfxPrint_Init(&printer);
sp78 = POLY_OPA_DISP;
tempRet = Graph_GfxPlusOne(POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, tempRet);
GfxPrint_Open(&printer, tempRet);
if ((OREG(0) == 1) || (OREG(0) == 8)) {
func_80063828(&printer);
}
if (gGameInfo->regPage != 0) {
func_80063C04(&printer);
}
D_8011E0B0 = 0;
sp7C = GfxPrint_Close(&printer);
gSPEndDisplayList(sp7C++);
Graph_BranchDlist(sp78, sp7C);
POLY_OPA_DISP = sp7C;
if (1) {}
CLOSE_DISPS(gfxCtx, "../z_debug.c", 664);
GfxPrint_Destroy(&printer);
}