mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-05-28 00:16:30 -04:00
a1f0d32d66
* Update menus.c (#634) * Update common_data.yml (#635) * Renames for screenId and other changes (#636) * screenId renames * Rename surface map to collision mesh (#637) * Rename some stack vars (#638) * Fix syntax error (#639) * Rename some stack vars * Update collision.c * Collision Documentation (#640) * Collision related renames * update doxygen (#649) * change bool (#644) Co-authored-by: MegaMech <MegaMech@users.noreply.github.com> * Update (#642) * Delete trig_tables_bss.c (#650) * fix typo audio (#656) * fix typo src actor (#657) Co-authored-by: MegaMech <MegaMech@users.noreply.github.com> * fix typo include (#658) * fix course (#659) * fix typo debug (#660) * fix typo data (#661) * replace number with const (#665) * fix typo buffers (#655) * fix typo buffers * tweak ld file * rename to sMemoryPool * add a warning --------- * fix typo src (#654) * fix typo src * fix non matcing * Update code_80091750.c --------- * fix typo racing (#653) * fix typo racing * get it match * replace G_LINE3D to G_QUAD --------- * fix typo src (#652) * fix ending typo (#651) * Action more info when it doesn't match and fix first diff (#662) * Update linux-compile.yml * fix first-diff * Update first-diff.py --------- * document texture of kart (#663) * document texture of kart * change screenPlayerId to screenId * some documentation around object * Revert "some documentation around object" This reverts commit cbb39078e036bf2a417bed67359e910213acab28. * more rename --------- * Make evaluate_collision_players_palm_tree better (#667) This matches just the same as before, but using those two casts instead of shifts seems more likely to be accurate to the original source code Signed-off-by: Gabriel Ravier <gabravier@gmail.com> * add fedora instruciton (#666) * start documenting animation (#668) * start documenting animation * Update course_data.c * change comment * update libultra asm (#648) * update libultra asm * fix gcc __osThreadTail --------- * Document Vehicles (#641) * start doc collision * fix merge * finish rename fonction related to vehicle * document around waypoint of vehicle * make some modification * make some change and rename one * copy_ to oldPos * doc smoke ferry and train * some rename * fix some renaming * precise index * rename a funciton * simplify waypoint_vehicles * change some name * change some name * rename move_to_point_direction * fix some conflict * Update code_80005FD0.c * Update code_80005FD0.h --------- * Label a save info loop (#645) * save info * more gcc progress * fix a value and do a rename (#669) * update clang and add action (#664) * update clang and add action * try clang on course folder only * forget two file * Update course_displaylists.inc.c * forget few other file * Update course_vertices.inc.c * format all code while get it match * second pass * format other dir * disable clang format on bad ido code * fix some tabulation * revert format on tool dir * Update clang-format.yml * ignore gbi.h * add some read me instruction * fix error * format and fixing error * Update README.md --------- * Update linkonly_generator.py (#670) * format more file * update * fix compilation issue * remove course_metadata folder * re add course metadata folder * fix banshee bordwalk crash * fix windows eurk * Update CMakeLists.txt ---------
252 lines
7.3 KiB
C
252 lines
7.3 KiB
C
#include <libultraship.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
|