1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-03 00:06:37 +00:00
oot/src/boot/is_debug.c
Tharo dcf61174e9
Filename & line number args cleanup (#1891)
* Filename & line number args cleanup

* Use int for line number args over s32/u32

* Add missing const qualifiers from filename args

* Fix gcc warning in game.c

* Add comment to weird assignments in GameState_Init
2024-02-27 02:37:33 -05:00

104 lines
2.4 KiB
C

#include "global.h"
#define gISVDbgPrnAdrs ((ISVDbg*)0xB3FF0000)
#define ASCII_TO_U32(a, b, c, d) ((u32)((a << 24) | (b << 16) | (c << 8) | (d << 0)))
#if OOT_DEBUG
OSPiHandle* sISVHandle; // official name : is_Handle
void isPrintfInit(void) {
sISVHandle = osCartRomInit();
osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->put, 0);
osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->get, 0);
osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->magic, ASCII_TO_U32('I', 'S', '6', '4'));
}
#endif
void osSyncPrintfUnused(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
#if OOT_DEBUG
_Printf(is_proutSyncPrintf, NULL, fmt, args);
#endif
va_end(args);
}
void osSyncPrintf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
#if OOT_DEBUG
_Printf(is_proutSyncPrintf, NULL, fmt, args);
#endif
va_end(args);
}
// assumption
void rmonPrintf(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
#if OOT_DEBUG
_Printf(is_proutSyncPrintf, NULL, fmt, args);
#endif
va_end(args);
}
#if OOT_DEBUG
void* is_proutSyncPrintf(void* arg, const char* str, size_t count) {
u32 data;
s32 pos;
s32 start;
s32 end;
osEPiReadIo(sISVHandle, (u32)&gISVDbgPrnAdrs->magic, &data);
if (data != ASCII_TO_U32('I', 'S', '6', '4')) {
return (void*)1;
}
osEPiReadIo(sISVHandle, (u32)&gISVDbgPrnAdrs->get, &data);
pos = data;
osEPiReadIo(sISVHandle, (u32)&gISVDbgPrnAdrs->put, &data);
start = data;
end = start + count;
if (end >= 0xFFE0) {
end -= 0xFFE0;
if (pos < end || start < pos) {
return (void*)1;
}
} else {
if (start < pos && pos < end) {
return (void*)1;
}
}
while (count) {
u32 addr = (u32)&gISVDbgPrnAdrs->data + (start & 0xFFFFFFC);
s32 shift = ((3 - (start & 3)) * 8);
if (*str) {
osEPiReadIo(sISVHandle, addr, &data);
osEPiWriteIo(sISVHandle, addr, (*str << shift) | (data & ~(0xFF << shift)));
start++;
if (start >= 0xFFE0) {
start -= 0xFFE0;
}
}
count--;
str++;
}
osEPiWriteIo(sISVHandle, (u32)&gISVDbgPrnAdrs->put, start);
return (void*)1;
}
NORETURN void func_80002384(const char* exp, const char* file, int line) {
osSyncPrintf("File:%s Line:%d %s \n", file, line, exp);
while (true) {
;
}
}
#endif