diff options
Diffstat (limited to 'src/debug')
| -rw-r--r-- | src/debug/crash_screen_enhancement.c | 411 | ||||
| -rw-r--r-- | src/debug/crash_screen_enhancement.h | 8 | ||||
| -rw-r--r-- | src/debug/debug.c | 448 | ||||
| -rw-r--r-- | src/debug/debug.inc.c | 72 |
4 files changed, 438 insertions, 501 deletions
diff --git a/src/debug/crash_screen_enhancement.c b/src/debug/crash_screen_enhancement.c index 530a4486f..885ac45c4 100644 --- a/src/debug/crash_screen_enhancement.c +++ b/src/debug/crash_screen_enhancement.c @@ -6,215 +6,208 @@ #include "../crash_screen.h" #include "crash_screen_enhancement.h" -//s32 _Printf(char *(*prout)(char *, const char *, size_t), char *dst, const char *fmt, va_list args); - -// u32 crashScreenFont2[7 * 9 + 1] = { -// 0x70871c30,0x8988a250,0x88808290,0x88831c90,0x888402f8,0x88882210,0x71cf9c10,0xf9cf9c70,0x8228a288,0xf200a288,0x0bc11c78,0x0a222208,0x8a222288,0x71c21c70,0x23c738f8,0x5228a480,0x8a282280,0x8bc822f0,0xfa282280,0x8a28a480,0x8bc738f8,0xf9c89c08,0x82288808,0x82088808,0xf2ef8808,0x82288888,0x82288888,0x81c89c70,0x8a08a270,0x920da288,0xa20ab288,0xc20aaa88,0xa208a688,0x9208a288,0x8be8a270,0xf1cf1cf8,0x8a28a220,0x8a28a020,0xf22f1c20,0x82aa0220,0x82492220,0x81a89c20,0x8a28a288,0x8a28a288,0x8a289488,0x8a2a8850,0x894a9420,0x894aa220,0x70852220,0xf8011000,0x08020800,0x10840400,0x20040470,0x40840400,0x80020800,0xf8011000,0x70800000,0x88822200,0x08820400,0x108f8800,0x20821000,0x00022200,0x20800020 -// }; +#ifdef TARGET_N64 +s32 _Printf(char* (*prout)(char*, const char*, size_t), char* dst, const char* fmt, va_list args); + +u32 crashScreenFont2[7 * 9 + 1] = { + 0x70871c30, 0x8988a250, 0x88808290, 0x88831c90, 0x888402f8, 0x88882210, 0x71cf9c10, 0xf9cf9c70, 0x8228a288, + 0xf200a288, 0x0bc11c78, 0x0a222208, 0x8a222288, 0x71c21c70, 0x23c738f8, 0x5228a480, 0x8a282280, 0x8bc822f0, + 0xfa282280, 0x8a28a480, 0x8bc738f8, 0xf9c89c08, 0x82288808, 0x82088808, 0xf2ef8808, 0x82288888, 0x82288888, + 0x81c89c70, 0x8a08a270, 0x920da288, 0xa20ab288, 0xc20aaa88, 0xa208a688, 0x9208a288, 0x8be8a270, 0xf1cf1cf8, + 0x8a28a220, 0x8a28a020, 0xf22f1c20, 0x82aa0220, 0x82492220, 0x81a89c20, 0x8a28a288, 0x8a28a288, 0x8a289488, + 0x8a2a8850, 0x894a9420, 0x894aa220, 0x70852220, 0xf8011000, 0x08020800, 0x10840400, 0x20040470, 0x40840400, + 0x80020800, 0xf8011000, 0x70800000, 0x88822200, 0x08820400, 0x108f8800, 0x20821000, 0x00022200, 0x20800020 +}; // extern u64 osClockRate; -// u8 gCrashScreenCharToGlyph[128] = { -// -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -// -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, 43, -1, -1, 37, 38, -1, 42, -// -1, 39, 44, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 36, -1, -1, -1, -1, 40, -1, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1, -// }; - -// char *gCauseDesc[18] = { -// "Interrupt", -// "TLB modification", -// "TLB exception on load", -// "TLB exception on store", -// "Address error on load", -// "Address error on store", -// "Bus error on inst.", -// "Bus error on data", -// "System call exception", -// "Breakpoint exception", -// "Reserved instruction", -// "Coprocessor unusable", -// "Arithmetic overflow", -// "Trap exception", -// "Virtual coherency on inst.", -// "Floating point exception", -// "Watchpoint exception", -// "Virtual coherency on data", -// }; - -// char *gFpcsrDesc[6] = { -// "Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", -// "Inexact operation", -// }; - -// void crash_screen_draw_glyph_enhancement(s32 x, s32 y, s32 glyph) { -// const u32 *data; -// u16 *ptr; -// u32 bit; -// u32 rowMask; -// s32 i, j; - -// data = &crashScreenFont2[glyph / 5 * 7]; -// ptr = pFramebuffer + SCREEN_WIDTH * y + x; - -// for (i = 0; i < 7; i++) { -// bit = 0x80000000U >> ((glyph % 5) * 6); -// rowMask = *data++; - -// for (j = 0; j < 6; j++) { -// *ptr++ = (bit & rowMask) ? 0xffff : 1; -// bit >>= 1; -// } -// ptr += SCREEN_WIDTH - 6; -// } -// } - -// void crash_screen_draw_rect(s32 x, s32 y, s32 w, s32 h) { -// u16 *ptr; -// s32 i, j; - -// ptr = pFramebuffer + SCREEN_WIDTH * y + x; -// for (i = 0; i < h; i++) { -// for (j = 0; j < w; j++) { -// // 0xe738 = 0b1110011100111000 -// *ptr = ((*ptr & 0xe738) >> 2) | 1; -// ptr++; -// } -// ptr += SCREEN_WIDTH - w; -// } -// } - -// static char *write_to_buf(char *buffer, const char *data, size_t size) { -// return (char *) memcpy(buffer, data, size) + size; -// } - -// void crash_screen_print(s32 x, s32 y, const char *fmt, ...) { -// char *ptr; -// u32 glyph; -// s32 size; -// char buf[0x100]; - -// va_list args; -// va_start(args, fmt); - -// size = _Printf(write_to_buf, buf, fmt, args); - -// if (size > 0) { -// ptr = buf; - - -// while (size > 0) { - - -// glyph = gCrashScreenCharToGlyph[*ptr & 0x7f]; - -// if (glyph != 0xff) { -// crash_screen_draw_glyph_enhancement(x, y, glyph); -// } - -// size--; - -// ptr++; -// x += 6; -// } -// } - -// va_end(args); -// } - -// void crash_screen_sleep(s32 ms) { -// u64 cycles = ms * 1000LL * osClockRate / 1000000ULL; -// // osSetTime(0); -// // while (osGetTime() < cycles) { -// // } -// } - -// void crash_screen_print_float_reg(s32 x, s32 y, s32 regNum, void *addr) { -// u32 bits; -// s32 exponent; - -// bits = *(u32 *) addr; -// exponent = ((bits & 0x7f800000U) >> 0x17) - 0x7f; -// if ((exponent >= -0x7e && exponent <= 0x7f) || bits == 0) { -// crash_screen_print(x, y, "F%02d:%.3e", regNum, *(f32 *) addr); -// } else { -// crash_screen_print(x, y, "F%02d:---------", regNum); -// } -// } - -// void crash_screen_print_fpcsr(u32 fpcsr) { -// s32 i; -// u32 bit; - -// bit = 1 << 17; -// crash_screen_print(30, 155, "FPCSR:%08XH", fpcsr); -// for (i = 0; i < 6; i++) { -// if (fpcsr & bit) { -// crash_screen_print(132, 155, "(%s)", gFpcsrDesc[i]); -// return; -// } -// bit >>= 1; -// } -// } - - -// void crash_screen_draw(OSThread* thread) { -// s16 cause; -// __OSThreadContext *tc = &thread->context; - -// cause = (tc->cause >> 2) & 0x1f; -// if (cause == 23) { // EXC_WATCH -// cause = 16; -// } -// if (cause == 31) { // EXC_VCED -// cause = 17; -// } - -// osWritebackDCacheAll(); - -// crash_screen_draw_rect(25, 20, 270, 25); -// crash_screen_print(30, 25, "THREAD:%d (%s)", thread->id, gCauseDesc[cause]); -// crash_screen_print(30, 35, "PC:%08XH SR:%08XH VA:%08XH", tc->pc, tc->sr, tc->badvaddr); -// crash_screen_sleep(2000); -// crash_screen_draw_rect(25, 45, 270, 185); -// crash_screen_print(30, 50, "AT:%08XH V0:%08XH V1:%08XH", (u32) tc->at, (u32) tc->v0, -// (u32) tc->v1); -// crash_screen_print(30, 60, "A0:%08XH A1:%08XH A2:%08XH", (u32) tc->a0, (u32) tc->a1, -// (u32) tc->a2); -// crash_screen_print(30, 70, "A3:%08XH T0:%08XH T1:%08XH", (u32) tc->a3, (u32) tc->t0, -// (u32) tc->t1); -// crash_screen_print(30, 80, "T2:%08XH T3:%08XH T4:%08XH", (u32) tc->t2, (u32) tc->t3, -// (u32) tc->t4); -// crash_screen_print(30, 90, "T5:%08XH T6:%08XH T7:%08XH", (u32) tc->t5, (u32) tc->t6, -// (u32) tc->t7); -// crash_screen_print(30, 100, "S0:%08XH S1:%08XH S2:%08XH", (u32) tc->s0, (u32) tc->s1, -// (u32) tc->s2); -// crash_screen_print(30, 110, "S3:%08XH S4:%08XH S5:%08XH", (u32) tc->s3, (u32) tc->s4, -// (u32) tc->s5); -// crash_screen_print(30, 120, "S6:%08XH S7:%08XH T8:%08XH", (u32) tc->s6, (u32) tc->s7, -// (u32) tc->t8); -// crash_screen_print(30, 130, "T9:%08XH GP:%08XH SP:%08XH", (u32) tc->t9, (u32) tc->gp, -// (u32) tc->sp); -// crash_screen_print(30, 140, "S8:%08XH RA:%08XH", (u32) tc->s8, (u32) tc->ra); -// crash_screen_print_fpcsr(tc->fpcsr); -// crash_screen_print_float_reg(30, 170, 0, &tc->fp0.f.f_even); -// crash_screen_print_float_reg(120, 170, 2, &tc->fp2.f.f_even); -// crash_screen_print_float_reg(210, 170, 4, &tc->fp4.f.f_even); -// crash_screen_print_float_reg(30, 180, 6, &tc->fp6.f.f_even); -// crash_screen_print_float_reg(120, 180, 8, &tc->fp8.f.f_even); -// crash_screen_print_float_reg(210, 180, 10, &tc->fp10.f.f_even); -// crash_screen_print_float_reg(30, 190, 12, &tc->fp12.f.f_even); -// crash_screen_print_float_reg(120, 190, 14, &tc->fp14.f.f_even); -// crash_screen_print_float_reg(210, 190, 16, &tc->fp16.f.f_even); -// crash_screen_print_float_reg(30, 200, 18, &tc->fp18.f.f_even); -// crash_screen_print_float_reg(120, 200, 20, &tc->fp20.f.f_even); -// crash_screen_print_float_reg(210, 200, 22, &tc->fp22.f.f_even); -// crash_screen_print_float_reg(30, 210, 24, &tc->fp24.f.f_even); -// crash_screen_print_float_reg(120, 210, 26, &tc->fp26.f.f_even); -// crash_screen_print_float_reg(210, 210, 28, &tc->fp28.f.f_even); -// crash_screen_print_float_reg(30, 220, 30, &tc->fp30.f.f_even); -// osViBlack(false); -// osViSwapBuffer(pFramebuffer); -// } +u8 gCrashScreenCharToGlyph[128] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, 43, -1, -1, 37, 38, -1, 42, -1, 39, 44, -1, 0, 1, 2, 3, + 4, 5, 6, 7, 8, 9, 36, -1, -1, -1, -1, 40, -1, 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, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1, +}; + +char* gCauseDesc[18] = { + "Interrupt", + "TLB modification", + "TLB exception on load", + "TLB exception on store", + "Address error on load", + "Address error on store", + "Bus error on inst.", + "Bus error on data", + "System call exception", + "Breakpoint exception", + "Reserved instruction", + "Coprocessor unusable", + "Arithmetic overflow", + "Trap exception", + "Virtual coherency on inst.", + "Floating point exception", + "Watchpoint exception", + "Virtual coherency on data", +}; + +char* gFpcsrDesc[6] = { + "Unimplemented operation", "Invalid operation", "Division by zero", "Overflow", "Underflow", "Inexact operation", +}; + +void crash_screen_draw_glyph_enhancement(s32 x, s32 y, s32 glyph) { + const u32* data; + u16* ptr; + u32 bit; + u32 rowMask; + s32 i, j; + + data = &crashScreenFont2[glyph / 5 * 7]; + ptr = pFramebuffer + SCREEN_WIDTH * y + x; + + for (i = 0; i < 7; i++) { + bit = 0x80000000U >> ((glyph % 5) * 6); + rowMask = *data++; + + for (j = 0; j < 6; j++) { + *ptr++ = (bit & rowMask) ? 0xffff : 1; + bit >>= 1; + } + ptr += SCREEN_WIDTH - 6; + } +} + +void crash_screen_draw_rect(s32 x, s32 y, s32 w, s32 h) { + u16* ptr; + s32 i, j; + + ptr = pFramebuffer + SCREEN_WIDTH * y + x; + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++) { + // 0xe738 = 0b1110011100111000 + *ptr = ((*ptr & 0xe738) >> 2) | 1; + ptr++; + } + ptr += SCREEN_WIDTH - w; + } +} + +static char* write_to_buf(char* buffer, const char* data, size_t size) { + return (char*) memcpy(buffer, data, size) + size; +} + +void crash_screen_print(s32 x, s32 y, const char* fmt, ...) { + char* ptr; + u32 glyph; + s32 size; + char buf[0x100]; + + va_list args; + va_start(args, fmt); + + size = _Printf(write_to_buf, buf, fmt, args); + + if (size > 0) { + ptr = buf; + + while (size > 0) { + + glyph = gCrashScreenCharToGlyph[*ptr & 0x7f]; + + if (glyph != 0xff) { + crash_screen_draw_glyph_enhancement(x, y, glyph); + } + + size--; + + ptr++; + x += 6; + } + } + + va_end(args); +} + +void crash_screen_sleep(s32 ms) { + u64 cycles = ms * 1000LL * osClockRate / 1000000ULL; + osSetTime(0); + while (osGetTime() < cycles) {} +} + +void crash_screen_print_float_reg(s32 x, s32 y, s32 regNum, void* addr) { + u32 bits; + s32 exponent; + + bits = *(u32*) addr; + exponent = ((bits & 0x7f800000U) >> 0x17) - 0x7f; + if ((exponent >= -0x7e && exponent <= 0x7f) || bits == 0) { + crash_screen_print(x, y, "F%02d:%.3e", regNum, *(f32*) addr); + } else { + crash_screen_print(x, y, "F%02d:---------", regNum); + } +} + +void crash_screen_print_fpcsr(u32 fpcsr) { + s32 i; + u32 bit; + + bit = 1 << 17; + crash_screen_print(30, 155, "FPCSR:%08XH", fpcsr); + for (i = 0; i < 6; i++) { + if (fpcsr & bit) { + crash_screen_print(132, 155, "(%s)", gFpcsrDesc[i]); + return; + } + bit >>= 1; + } +} + +void crash_screen_draw(OSThread* thread) { + s16 cause; + __OSThreadContext* tc = &thread->context; + + cause = (tc->cause >> 2) & 0x1f; + if (cause == 23) { // EXC_WATCH + cause = 16; + } + if (cause == 31) { // EXC_VCED + cause = 17; + } + + osWritebackDCacheAll(); + + crash_screen_draw_rect(25, 20, 270, 25); + crash_screen_print(30, 25, "THREAD:%d (%s)", thread->id, gCauseDesc[cause]); + crash_screen_print(30, 35, "PC:%08XH SR:%08XH VA:%08XH", tc->pc, tc->sr, tc->badvaddr); + crash_screen_sleep(2000); + crash_screen_draw_rect(25, 45, 270, 185); + crash_screen_print(30, 50, "AT:%08XH V0:%08XH V1:%08XH", (u32) tc->at, (u32) tc->v0, (u32) tc->v1); + crash_screen_print(30, 60, "A0:%08XH A1:%08XH A2:%08XH", (u32) tc->a0, (u32) tc->a1, (u32) tc->a2); + crash_screen_print(30, 70, "A3:%08XH T0:%08XH T1:%08XH", (u32) tc->a3, (u32) tc->t0, (u32) tc->t1); + crash_screen_print(30, 80, "T2:%08XH T3:%08XH T4:%08XH", (u32) tc->t2, (u32) tc->t3, (u32) tc->t4); + crash_screen_print(30, 90, "T5:%08XH T6:%08XH T7:%08XH", (u32) tc->t5, (u32) tc->t6, (u32) tc->t7); + crash_screen_print(30, 100, "S0:%08XH S1:%08XH S2:%08XH", (u32) tc->s0, (u32) tc->s1, (u32) tc->s2); + crash_screen_print(30, 110, "S3:%08XH S4:%08XH S5:%08XH", (u32) tc->s3, (u32) tc->s4, (u32) tc->s5); + crash_screen_print(30, 120, "S6:%08XH S7:%08XH T8:%08XH", (u32) tc->s6, (u32) tc->s7, (u32) tc->t8); + crash_screen_print(30, 130, "T9:%08XH GP:%08XH SP:%08XH", (u32) tc->t9, (u32) tc->gp, (u32) tc->sp); + crash_screen_print(30, 140, "S8:%08XH RA:%08XH", (u32) tc->s8, (u32) tc->ra); + crash_screen_print_fpcsr(tc->fpcsr); + crash_screen_print_float_reg(30, 170, 0, &tc->fp0.f.f_even); + crash_screen_print_float_reg(120, 170, 2, &tc->fp2.f.f_even); + crash_screen_print_float_reg(210, 170, 4, &tc->fp4.f.f_even); + crash_screen_print_float_reg(30, 180, 6, &tc->fp6.f.f_even); + crash_screen_print_float_reg(120, 180, 8, &tc->fp8.f.f_even); + crash_screen_print_float_reg(210, 180, 10, &tc->fp10.f.f_even); + crash_screen_print_float_reg(30, 190, 12, &tc->fp12.f.f_even); + crash_screen_print_float_reg(120, 190, 14, &tc->fp14.f.f_even); + crash_screen_print_float_reg(210, 190, 16, &tc->fp16.f.f_even); + crash_screen_print_float_reg(30, 200, 18, &tc->fp18.f.f_even); + crash_screen_print_float_reg(120, 200, 20, &tc->fp20.f.f_even); + crash_screen_print_float_reg(210, 200, 22, &tc->fp22.f.f_even); + crash_screen_print_float_reg(30, 210, 24, &tc->fp24.f.f_even); + crash_screen_print_float_reg(120, 210, 26, &tc->fp26.f.f_even); + crash_screen_print_float_reg(210, 210, 28, &tc->fp28.f.f_even); + crash_screen_print_float_reg(30, 220, 30, &tc->fp30.f.f_even); + osViBlack(false); + osViSwapBuffer(pFramebuffer); +} +#endif diff --git a/src/debug/crash_screen_enhancement.h b/src/debug/crash_screen_enhancement.h index 5860f9226..3b3937ffa 100644 --- a/src/debug/crash_screen_enhancement.h +++ b/src/debug/crash_screen_enhancement.h @@ -7,14 +7,12 @@ void crash_screen_draw(OSThread* thread); // Add this to the top of main.c or crash_screen.c -//#define CRASH_SCREEN_ENHANCEMENT - - +// #define CRASH_SCREEN_ENHANCEMENT /** * Example of how to force crash screen to run. * Make sure to include the header crash_screen_enhancement.h in main.h -*/ + */ // void display_and_vsync(void) { // profiler_log_thread5_time(BEFORE_DISPLAY_LISTS); @@ -39,4 +37,4 @@ void crash_screen_draw(OSThread* thread); // gGlobalTimer++; // } -#endif // CRASH_SCREEN_ENHANCEMENT_H
\ No newline at end of file +#endif // CRASH_SCREEN_ENHANCEMENT_H diff --git a/src/debug/debug.c b/src/debug/debug.c index f5daa4397..a07cecd4b 100644 --- a/src/debug/debug.c +++ b/src/debug/debug.c @@ -7,245 +7,245 @@ u8 sDisplayListState = OK; -static u32 variable_to_u64(variableWatchAttributes *); -static void round_up_float(u32 *, u8); -static void u64_to_string(variableWatchAttributes *, u32, u8); -static u32 _strlen(const char *); -static void _memcpy(char *, const char *, u32); +static u32 variable_to_u64(variableWatchAttributes*); +static void round_up_float(u32*, u8); +static void u64_to_string(variableWatchAttributes*, u32, u8); +static u32 _strlen(const char*); +static void _memcpy(char*, const char*, u32); void display_dvdl(void) { - u32 variable; - u32 i, vNameLen; - u32 arraySize = sizeof(gMainVariableWatchList) / sizeof(variableWatchAttributes); - s32 text_y_possition = TEXT_Y_POSSITION; - u8 base; - char *vName, *cBuffer; - - load_debug_font(); - for (i = 0; i < arraySize; i++) { - variableWatchAttributes *currentAttribute = &gMainVariableWatchList[i]; - currentAttribute->characterBuffer = currentAttribute->buffer; - cBuffer = currentAttribute->characterBuffer; - vName = currentAttribute->variableName; - - variable = variable_to_u64(currentAttribute); - base = 0; - - if (currentAttribute->variableFlag & (DISPLAY_FLOAT_AS_TYPE | DISPLAY_FLOAT_WITH_ROUNDING)) { - if (currentAttribute->variableFlag & DISPLAY_FLOAT_NUMBER) { - sDisplayListState = BAD; - } else if (currentAttribute->variableFlag & DISPLAY_FLOAT_WITH_ROUNDING) { - round_up_float(&variable, currentAttribute->variableSize); - } - } - - switch (currentAttribute->variableFlag & 0x8F) { - case DISPLAY_FLOAT_NUMBER: - sprintf(cBuffer, "%.3f", *(f32*)&variable); - break; - case DISPLAY_HEXIDECIMAL_NUMBER: - base = HEXIDECIMAL; - break; - case DISPLAY_DECIMAL_NUMBER: - base = DECIMAL; - break; - case DISPLAY_OCTAL_NUMBER: - base = OCTAL; - break; - case DISPLAY_BINARY_NUMBER: - base = BINARY; - break; - default: - sDisplayListState = BAD; - } - if (base) { - u64_to_string(currentAttribute, variable, base); - } - - if (sDisplayListState == BAD) { - cBuffer = "NaN"; - } - sDisplayListState = OK; - - vNameLen = _strlen(vName); - - debug_print_str2(TEXT_X_POSSITION, text_y_possition, vName); - debug_print_str2(TEXT_X_POSSITION + (vNameLen * 0x8), text_y_possition, cBuffer); - text_y_possition += 0x8; - } - gSPDisplayList(gDisplayListHead++, D_0D007EB8); - gSPDisplayList(gDisplayListHead++, D_020076E0); - func_80093C98(1); + u32 variable; + u32 i, vNameLen; + u32 arraySize = sizeof(gMainVariableWatchList) / sizeof(variableWatchAttributes); + s32 text_y_possition = TEXT_Y_POSSITION; + u8 base; + char *vName, *cBuffer; + + load_debug_font(); + for (i = 0; i < arraySize; i++) { + variableWatchAttributes* currentAttribute = &gMainVariableWatchList[i]; + currentAttribute->characterBuffer = currentAttribute->buffer; + cBuffer = currentAttribute->characterBuffer; + vName = currentAttribute->variableName; + + variable = variable_to_u64(currentAttribute); + base = 0; + + if (currentAttribute->variableFlag & (DISPLAY_FLOAT_AS_TYPE | DISPLAY_FLOAT_WITH_ROUNDING)) { + if (currentAttribute->variableFlag & DISPLAY_FLOAT_NUMBER) { + sDisplayListState = BAD; + } else if (currentAttribute->variableFlag & DISPLAY_FLOAT_WITH_ROUNDING) { + round_up_float(&variable, currentAttribute->variableSize); + } + } + + switch (currentAttribute->variableFlag & 0x8F) { + case DISPLAY_FLOAT_NUMBER: + sprintf(cBuffer, "%.3f", *(f32*) &variable); + break; + case DISPLAY_HEXIDECIMAL_NUMBER: + base = HEXIDECIMAL; + break; + case DISPLAY_DECIMAL_NUMBER: + base = DECIMAL; + break; + case DISPLAY_OCTAL_NUMBER: + base = OCTAL; + break; + case DISPLAY_BINARY_NUMBER: + base = BINARY; + break; + default: + sDisplayListState = BAD; + } + if (base) { + u64_to_string(currentAttribute, variable, base); + } + + if (sDisplayListState == BAD) { + cBuffer = "NaN"; + } + sDisplayListState = OK; + + vNameLen = _strlen(vName); + + debug_print_str2(TEXT_X_POSSITION, text_y_possition, vName); + debug_print_str2(TEXT_X_POSSITION + (vNameLen * 0x8), text_y_possition, cBuffer); + text_y_possition += 0x8; + } + gSPDisplayList(gDisplayListHead++, D_0D007EB8); + gSPDisplayList(gDisplayListHead++, D_020076E0); + func_80093C98(1); } -static u32 variable_to_u64(variableWatchAttributes *attribute) { - u32 variable; - - switch (attribute->variableSize) { - case sizeof(u8): - variable = *((u8*) attribute->variablePointer); - break; - case sizeof(u16): - variable = *((u16*) attribute->variablePointer); - break; - case sizeof(u32): - case sizeof(u64): - variable = *((u32*) attribute->variablePointer); // no floating point rounding - break; - default: - sDisplayListState = BAD; - } - - return variable; +static u32 variable_to_u64(variableWatchAttributes* attribute) { + u32 variable; + + switch (attribute->variableSize) { + case sizeof(u8): + variable = *((u8*) attribute->variablePointer); + break; + case sizeof(u16): + variable = *((u16*) attribute->variablePointer); + break; + case sizeof(u32): + case sizeof(u64): + variable = *((u32*) attribute->variablePointer); // no floating point rounding + break; + default: + sDisplayListState = BAD; + } + + return variable; } -static void round_up_float(u32 *variable, u8 variableSize) { - switch (variableSize) { - case sizeof(u64): - case sizeof(u32): - *variable = (u32) (*(f32*) &*variable); - break; - default: - sDisplayListState = BAD; - } +static void round_up_float(u32* variable, u8 variableSize) { + switch (variableSize) { + case sizeof(u64): + case sizeof(u32): + *variable = (u32) (*(f32*) &*variable); + break; + default: + sDisplayListState = BAD; + } } -static void u64_to_string(variableWatchAttributes *attribute, u32 variable, u8 base) { - s32 signedVariable; - u32 stringDifference, indexesToFillAVariable, stringLengthWithZero; - u32 indexesToFillAByte, upperIndex, remainder; - u32 stringLength, lowerIndex, i; - u8 variableSize; - char *bufferedString; - char swapRegister; - - if (sDisplayListState == BAD) { - return; - } - - bufferedString = attribute->characterBuffer; - variableSize = attribute->variableSize; - - // converts a minus number into it's unsigned equivalent for proper string conversion - if (attribute->variableFlag & DISPLAY_SIGNED_NUMBER) { - switch (variableSize) { - case sizeof(u8): - signedVariable = (s8) variable; - if (signedVariable < 0) { - signedVariable = -signedVariable; - variable = (u8) signedVariable; - *bufferedString = '-'; - bufferedString++; - } - break; - case sizeof(u16): - signedVariable = (s16) variable; - if (signedVariable < 0) { - signedVariable = -signedVariable; - variable = (u16) signedVariable; - *bufferedString = '-'; - bufferedString++; - } - break; - case sizeof(u32): - case sizeof(u64): - signedVariable = (s32) variable; - if (signedVariable < 0) { - signedVariable = -signedVariable; - variable = (u32) signedVariable; - *bufferedString = '-'; - bufferedString++; - } - break; - } - } - - stringLength = 0; - - // convert u64 into a string but it gets put in reverse - if (base != HEXIDECIMAL) { - do { - stringLength++; - *bufferedString = variable % base + '0'; - bufferedString++; - variable /= base; - } while (variable != 0); - } else { - do { - stringLength++; - remainder = variable % 16; - - if ((remainder >= 0) && (remainder <= 9)) { - *bufferedString = '0' + remainder; - } else { - *bufferedString = 'A' + (remainder - 10); - } - - bufferedString++; - variable /= 16; - } while (variable != 0); - } - - bufferedString -= stringLength; - upperIndex = stringLength - 1; - - // flip string 4321 --> 1234 - for (lowerIndex = 0; lowerIndex < stringLength >> 1; lowerIndex++) { - swapRegister = bufferedString[lowerIndex]; - bufferedString[lowerIndex] = bufferedString[upperIndex]; - bufferedString[upperIndex] = swapRegister; - upperIndex--; - } - - switch (base) { - case BINARY: - indexesToFillAByte = 8; - break; - case OCTAL: - indexesToFillAByte = 3; - break; - case DECIMAL: - bufferedString[stringLength] = '\0'; - return; - case HEXIDECIMAL: - indexesToFillAByte = 2; - break; - } - - stringLengthWithZero = stringLength - 1; - indexesToFillAVariable = indexesToFillAByte * variableSize; - stringDifference = indexesToFillAVariable - stringLengthWithZero; - - // makes space and fills in extra space. u32 FE -> 000000FE - for (i = stringLength; i > 0; i--) { - bufferedString[stringDifference + i - 2] = bufferedString[i - 1]; - } - for (i = 0; i < stringDifference - 1; i++) { - bufferedString[i] = '0'; - } - bufferedString[indexesToFillAVariable] = '\0'; +static void u64_to_string(variableWatchAttributes* attribute, u32 variable, u8 base) { + s32 signedVariable; + u32 stringDifference, indexesToFillAVariable, stringLengthWithZero; + u32 indexesToFillAByte, upperIndex, remainder; + u32 stringLength, lowerIndex, i; + u8 variableSize; + char* bufferedString; + char swapRegister; + + if (sDisplayListState == BAD) { + return; + } + + bufferedString = attribute->characterBuffer; + variableSize = attribute->variableSize; + + // converts a minus number into it's unsigned equivalent for proper string conversion + if (attribute->variableFlag & DISPLAY_SIGNED_NUMBER) { + switch (variableSize) { + case sizeof(u8): + signedVariable = (s8) variable; + if (signedVariable < 0) { + signedVariable = -signedVariable; + variable = (u8) signedVariable; + *bufferedString = '-'; + bufferedString++; + } + break; + case sizeof(u16): + signedVariable = (s16) variable; + if (signedVariable < 0) { + signedVariable = -signedVariable; + variable = (u16) signedVariable; + *bufferedString = '-'; + bufferedString++; + } + break; + case sizeof(u32): + case sizeof(u64): + signedVariable = (s32) variable; + if (signedVariable < 0) { + signedVariable = -signedVariable; + variable = (u32) signedVariable; + *bufferedString = '-'; + bufferedString++; + } + break; + } + } + + stringLength = 0; + + // convert u64 into a string but it gets put in reverse + if (base != HEXIDECIMAL) { + do { + stringLength++; + *bufferedString = variable % base + '0'; + bufferedString++; + variable /= base; + } while (variable != 0); + } else { + do { + stringLength++; + remainder = variable % 16; + + if ((remainder >= 0) && (remainder <= 9)) { + *bufferedString = '0' + remainder; + } else { + *bufferedString = 'A' + (remainder - 10); + } + + bufferedString++; + variable /= 16; + } while (variable != 0); + } + + bufferedString -= stringLength; + upperIndex = stringLength - 1; + + // flip string 4321 --> 1234 + for (lowerIndex = 0; lowerIndex < stringLength >> 1; lowerIndex++) { + swapRegister = bufferedString[lowerIndex]; + bufferedString[lowerIndex] = bufferedString[upperIndex]; + bufferedString[upperIndex] = swapRegister; + upperIndex--; + } + + switch (base) { + case BINARY: + indexesToFillAByte = 8; + break; + case OCTAL: + indexesToFillAByte = 3; + break; + case DECIMAL: + bufferedString[stringLength] = '\0'; + return; + case HEXIDECIMAL: + indexesToFillAByte = 2; + break; + } + + stringLengthWithZero = stringLength - 1; + indexesToFillAVariable = indexesToFillAByte * variableSize; + stringDifference = indexesToFillAVariable - stringLengthWithZero; + + // makes space and fills in extra space. u32 FE -> 000000FE + for (i = stringLength; i > 0; i--) { + bufferedString[stringDifference + i - 2] = bufferedString[i - 1]; + } + for (i = 0; i < stringDifference - 1; i++) { + bufferedString[i] = '0'; + } + bufferedString[indexesToFillAVariable] = '\0'; } -static u32 _strlen(const char *str) { - u32 len; +static u32 _strlen(const char* str) { + u32 len; - len = 0; - for (; *str != '\0'; str++) { - len++; - } + len = 0; + for (; *str != '\0'; str++) { + len++; + } - return len; + return len; } // unused but may be useful -static void _memcpy(char *destStr, const char *copyStr, u32 copySize) { - u32 i; - - for (i = 0; i < copySize; i++) { - *destStr = *copyStr; - destStr++; - copyStr++; - } +static void _memcpy(char* destStr, const char* copyStr, u32 copySize) { + u32 i; + + for (i = 0; i < copySize; i++) { + *destStr = *copyStr; + destStr++; + copyStr++; + } } #endif diff --git a/src/debug/debug.inc.c b/src/debug/debug.inc.c index 82f26be03..983afea95 100644 --- a/src/debug/debug.inc.c +++ b/src/debug/debug.inc.c @@ -11,69 +11,15 @@ extern s32 gGlobalTimer; * The Size of the structure array is calculated at compile time. */ variableWatchAttributes gMainVariableWatchList[] = { - { - "Global Timer: ", - &gGlobalTimer, - sizeof(gGlobalTimer), - DISPLAY_DECIMAL_NUMBER | DISPLAY_SIGNED_NUMBER, - 0, 0 - }, - { - "Actors: ", - &gNumActors, - sizeof(gNumActors), - DISPLAY_DECIMAL_NUMBER, - 0, 0 - }, - { - "Player Type: ", - &gPlayers[0].type, - sizeof(gPlayerOne->type), - DISPLAY_HEXIDECIMAL_NUMBER, - 0, 0 - }, - { - "X ", - &gPlayers[0].pos[0], - sizeof(gPlayerOne->pos[0]), - DISPLAY_FLOAT_NUMBER, - 0, 0 - }, - { - "Y ", - &gPlayers[0].pos[1], - sizeof(gPlayerOne->pos[1]), - DISPLAY_FLOAT_NUMBER, - 0, 0 - }, - { - "Z ", - &gPlayers[0].pos[2], - sizeof(gPlayerOne->pos[2]), - DISPLAY_FLOAT_NUMBER, - 0, 0 - }, - { - "Torque 9C: ", - &gPlayers[0].currentSpeed, - sizeof(gPlayerOne->currentSpeed), - DISPLAY_FLOAT_NUMBER, - 0, 0 - }, - { - "Top Speed 214: ", - &gPlayers[0].topSpeed, - sizeof(gPlayerOne->topSpeed), - DISPLAY_FLOAT_NUMBER, - 0, 0 - }, - { - "Accel Offset C4: ", - &gPlayers[0].slopeAccel, - sizeof(gPlayerOne->slopeAccel), - DISPLAY_SIGNED_NUMBER, - 0, 0 - }, + { "Global Timer: ", &gGlobalTimer, sizeof(gGlobalTimer), DISPLAY_DECIMAL_NUMBER | DISPLAY_SIGNED_NUMBER, 0, 0 }, + { "Actors: ", &gNumActors, sizeof(gNumActors), DISPLAY_DECIMAL_NUMBER, 0, 0 }, + { "Player Type: ", &gPlayers[0].type, sizeof(gPlayerOne->type), DISPLAY_HEXIDECIMAL_NUMBER, 0, 0 }, + { "X ", &gPlayers[0].pos[0], sizeof(gPlayerOne->pos[0]), DISPLAY_FLOAT_NUMBER, 0, 0 }, + { "Y ", &gPlayers[0].pos[1], sizeof(gPlayerOne->pos[1]), DISPLAY_FLOAT_NUMBER, 0, 0 }, + { "Z ", &gPlayers[0].pos[2], sizeof(gPlayerOne->pos[2]), DISPLAY_FLOAT_NUMBER, 0, 0 }, + { "Torque 9C: ", &gPlayers[0].currentSpeed, sizeof(gPlayerOne->currentSpeed), DISPLAY_FLOAT_NUMBER, 0, 0 }, + { "Top Speed 214: ", &gPlayers[0].topSpeed, sizeof(gPlayerOne->topSpeed), DISPLAY_FLOAT_NUMBER, 0, 0 }, + { "Accel Offset C4: ", &gPlayers[0].slopeAccel, sizeof(gPlayerOne->slopeAccel), DISPLAY_SIGNED_NUMBER, 0, 0 }, }; |
