summaryrefslogtreecommitdiff
path: root/src/debug.c
blob: 0716330c42b0670490c9f662afcac80407e48019 (plain)
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
244
245
246
247
248
249
#include <stdarg.h>
#include <stdio.h>
#include "gba/gba.h"
#include "config.h"
#include "debug.h"

extern void Hang();
static void FatalErrorHang(void) __attribute__((noreturn));

extern bool32 gNDS_DebugEnabled;
extern u8 gUnknown_203B150;

ALIGNED(4) const char gFuncFileLineString[] = "func = '%s'\nfile = '%s'  line = %5d";

ALIGNED(4) const char gNotEntryText[] = "--- not entry ---";
ALIGNED(4) const char gFuncFileLineStringWPrefix[] = "%sfunc = '%s'\nfile = '%s'  line = %5d\n";

ALIGNED(4) const char gFuncFileLineString2[] = "func = '%s'\nfile = '%s'  line = %5d\n";

ALIGNED(4) const char debug_fill14[] = "pksdir0";
ALIGNED(4) const char gDebugPrintPrefix[] = "  Print  ";
ALIGNED(4) const char debug_fill13[] = "pksdir0";

ALIGNED(4) const char Performance_Text[] = "Performance";
ALIGNED(4) const char MemoryCard_Text[] = "Memory Card";
ALIGNED(4) const char Memory_Text[] = "Memory";
ALIGNED(4) const char Flag_Text[] = "Flag";
ALIGNED(4) const char Se_Text[] = "Se";
ALIGNED(4) const char Bgm_Text[] = "Bgm";
ALIGNED(4) const char Sound_Text[] = "Sound";
ALIGNED(4) const char Dungeon_Text[] = "Dungeon";
ALIGNED(4) const char GroundScript_Text[] = "GroundScript";
ALIGNED(4) const char Ground_Text[] = "Ground";


ALIGNED(4) const char gNotMountText[] = "not mount log system";
ALIGNED(4) const char debug_fill9[] = "pksdir0";
ALIGNED(4) const char debug_fill10[] = "pksdir0";
ALIGNED(4) const char debug_fill11[] = "pksdir0";
ALIGNED(4) const char debug_fill12[] = "pksdir0";

ALIGNED(4) const char gFatalText[] = "!!!!! Fatal !!!!!\n";
ALIGNED(4) const char gFatalErrorBufferPlaceholder[] = "%s\n";

ALIGNED(4) const char debug_fill0[] = "pksdir0";
ALIGNED(4) const char debug_fill1[] = "pksdir0";
ALIGNED(4) const char debug_fill2[] = "pksdir0";
ALIGNED(4) const char debug_fill3[] = "pksdir0";
ALIGNED(4) const char debug_fill4[] = "pksdir0";
ALIGNED(4) const char debug_fill5[] = "pksdir0";
ALIGNED(4) const char debug_fill6[] = "pksdir0";
ALIGNED(4) const char debug_fill7[] = "pksdir0";
ALIGNED(4) const char debug_fill8[] = "pksdir0";

void NDS_DebugInit(void)
{
    nullsub_26();
    nullsub_27();
    nullsub_29();
    nullsub_30();
    nullsub_31();
    nullsub_32();
    nullsub_28();
    gNDS_DebugEnabled = TRUE;
}

void nullsub_25(void)
{
}

void nullsub_26(void)
{
}

// Unused
void PrintFuncFileLineOrNotEntry(char * buf, struct DebugLocation *debug)
{
    if(debug != NULL)
    {
        sprintf(buf, gFuncFileLineString, debug->func, debug->file, debug->line);
    }
    else
    {
        sprintf(buf, gNotEntryText);
    }
}

void PrintFuncFileLine(char *buf, struct DebugLocation *loc, const char* prefix)
{
    sprintf(buf, gFuncFileLineStringWPrefix, prefix, loc->func, loc->file, loc->line);
}

void PrintMessageWithFuncFileLine(u8 *buffer, struct DebugLocation *debug, const char *text, ...)
{
    va_list vArgv;
    u32 length;

    va_start(vArgv, text);
    vsprintf(buffer, text, vArgv);
    length = strlen(buffer);
    sprintf(&buffer[length], gFuncFileLineString2, debug->func, debug->file, debug->line);
    va_end(vArgv);
}

void nullsub_199(void)
{
}

void nullsub_27(void)
{
}

// Unused
void sub_8011B08(void)
{
    gUnknown_203B150 = 1;
}

// Unused
void sub_8011B14(void)
{
    gUnknown_203B150 = 0;
}

// Unused
u8 sub_8011B20(void)
{
    gUnknown_203B150 = !gUnknown_203B150;
    return gUnknown_203B150;
}

// unused
u8 sub_8011B3C(void)
{
    return gUnknown_203B150;
}

// unused
void nullsub_137(void)
{

}

static void FatalErrorPrintFuncFileLine(const char *prefix, struct DebugLocation *debug)
{
    char buf[0x100];
    if(prefix != NULL){
        PrintFuncFileLine(buf, debug, prefix);
    }
    else
    {
        PrintFuncFileLine(buf, debug, gDebugPrintPrefix);
    }
}

static void FatalErrorFormatMessage(const char *text, ...)
{
    char bufPrint[0x100];
    va_list vArgv;
    va_start(vArgv, text);
    vsprintf(bufPrint, text, vArgv);
    va_end(vArgv);
}


void sub_8011B88(const char *text, ...)
{
    char bufPrint[0x100];
    va_list vArgv;
    va_start(vArgv, text);
    vsprintf(bufPrint, text, vArgv);
    va_end(vArgv);
}

void nullsub_28(void)
{
}

u32 sub_8011BA4(void)
{
    return 0;
}

// Unused
u32 sub_8011BA8(void)
{
    return 0;
}

// Unused
const char *GetNotMountText(void)
{
    return gNotMountText;
}

// Unused
void UnusedHang(void)
{
    Hang();
}

void Log(u8 *buffer, const char *text, ...)
{
    va_list vArgv;
    va_start(vArgv, text);
    va_end(vArgv);
}

// Unused
void sub_8011BC8(u32 r0, u32 r1, u32 r2, ...)
{
    va_list vArgv;
    va_start(vArgv, r2);
    va_end(vArgv);
}

void nullsub_29()
{
}

void nullsub_30()
{
}

void nullsub_31()
{
}

void nullsub_32()
{
}

static void FatalErrorHang()
{
    Hang();
}

void FatalError(struct DebugLocation *debug, const char *text, ...) 
{
    char buf[0x100];
    va_list vArgv;

    FatalErrorPrintFuncFileLine(gFatalText, debug);
    va_start(vArgv, text);
    vsprintf(buf, text, vArgv);
    va_end(vArgv);
    FatalErrorFormatMessage(gFatalErrorBufferPlaceholder, buf);
    FatalErrorHang();
}