very cool debug display list (#348)

* added a very cool debug display list ^^ (prints variables to screen)

* Decompiled various functions
This commit is contained in:
tomas
2023-08-04 19:04:49 +00:00
committed by GitHub
parent 2e5b2737f3
commit 9d716d921a
60 changed files with 1291 additions and 2213 deletions
+78
View File
@@ -0,0 +1,78 @@
/**
* please do not include this file.
* ONLY FOR DEBUG PURPOSE
*/
#ifndef _VARIABLES_H_
#define _VARIABLES_H_
// #include <actors_extended.h> does not work
#include <actors.h>
#include <camera.h>
#include <camera_junk.h>
#include <ceremony_and_credits.h>
#include <code_800029B0.h>
#include <code_80004740.h>
#include <code_80005FD0.h>
#include <code_8001F980.h>
#include <code_80027D00.h>
#include <code_8003DC40.h>
#include <code_80057C60.h>
#include <code_8006E9C0.h>
#include <code_80071F00.h>
#include <code_80086E70.h>
#include <code_8008C1D0.h>
#include <code_80091440.h>
#include <code_80091750.h>
#include <code_800AF9B0.h>
#include <code_800B45E0.h>
#include <code_80280000.h>
#include <code_80280650.h>
#include <code_80281780.h>
#include <code_80281C40.h>
#include <code_802AAA70.h>
#include <common_textures.h>
#include <credits.h>
#include <data_segment2.h>
#include <framebuffers.h>
#include <hud_renderer.h>
#include <kart_dma.h>
#include <main.h>
#include <math_util_2.h>
#include <math_util.h>
#include <memory.h>
#include <menus.h>
#include <profiler.h>
#include <race_logic.h>
#include <render_courses.h>
#include <skybox_and_splitscreen.h>
#include <spawn_players.h>
#include <staff_ghosts.h>
#include <textures.h>
#include <actor_types.h>
#include <common_structs.h>
#include <config.h>
#include <course.h>
#include <course_offsets.h>
#include <debug.h>
#include <defines.h>
#include <functions.h>
#include <global.h>
#include <kart_attributes.h>
#include <macros.h>
#include <mk64.h>
#include <objects.h>
// #include <packed_displaylist_symbols_gen.h> does not work
#include <packed_displaylist_symbols.h>
#include <segments.h>
#include <segment_symbols.h>
#include <sounds.h>
#include <trig_tables.h>
#include <types.h>
#include <ultra64.h>
#include <variables.h>
#include <vehicles.h>
#include <vertice_count_gen.h>
#include <waypoints.h>
#endif
+251
View File
@@ -0,0 +1,251 @@
#include <ultra64.h>
#include <debug.h>
#include "debug.inc.c"
#include <libc/stdio.h>
#if DVDL
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);
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);
}
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 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;
len = 0;
for (; *str != '\0'; str++) {
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++;
}
}
#endif
+58
View File
@@ -0,0 +1,58 @@
#include <ultra64.h>
#include <debug.h>
#include "all_variables.h"
#if DVDL
extern s32 gGlobalTimer;
/**
* Edit this to edit what displays on the screen while the DVDL is active.
* 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].unk_000,
sizeof(gPlayerOne->unk_000),
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
},
};
#endif