Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
is_debug.c
Go to the documentation of this file.
1#include "common.h"
2#include "stdlib/stdarg.h"
3#include "nu/nusys.h"
4
5void crash_screen_set_assert_info(const char* message);
6typedef struct {
7 /* 0x00 */ u32 magic;
8 /* 0x04 */ u32 get;
9 /* 0x08 */ char unk_08[0x14-0x08];
10 /* 0x14 */ u32 put;
11 /* 0x18 */ char unk_18[0x20-0x18];
12 /* 0x20 */ char data[0x10000-0x20];
13} ISVDbg;
14
15#define gISVDbgPrnAdrs ((ISVDbg*) 0xb3ff0000)
16
17char* is_debug_print(char* arg0, const char* str, size_t count);
18
19void is_debug_init(void) {
20 osEPiWriteIo(nuPiCartHandle, (u32) &gISVDbgPrnAdrs->put, 0);
21 osEPiWriteIo(nuPiCartHandle, (u32) &gISVDbgPrnAdrs->get, 0);
22 osEPiWriteIo(nuPiCartHandle, (u32) &gISVDbgPrnAdrs->magic, ASCII_TO_U32('I', 'S', '6', '4'));
23}
24
25void printf(const char* fmt, ...) {
26 va_list args;
27 va_start(args, fmt);
28
29 _Printf(is_debug_print, NULL, fmt, args);
30}
31
32void osSyncPrintf(const char* fmt, ...) {
33 va_list args;
34 va_start(args, fmt);
35
36 _Printf(is_debug_print, NULL, fmt, args);
37}
38
39void rmonPrintf(const char* fmt, ...) {
40 va_list args;
41 va_start(args, fmt);
42
43 _Printf(is_debug_print, NULL, fmt, args);
44}
45
46char* is_debug_print(char* arg0, const char* str, size_t count) {
47 u32 data;
48 s32 pos;
49 s32 start;
50 s32 end;
51
52 osEPiReadIo(nuPiCartHandle, (u32) &gISVDbgPrnAdrs->magic, &data);
53 if (data != ASCII_TO_U32('I', 'S', '6', '4')) {
54 return (char*) 1;
55 }
56 osEPiReadIo(nuPiCartHandle, (u32) &gISVDbgPrnAdrs->get, &data);
57 pos = data;
58 osEPiReadIo(nuPiCartHandle, (u32) &gISVDbgPrnAdrs->put, &data);
59 start = data;
60 end = start + count;
61 if (end >= 0xffe0) {
62 end -= 0xffe0;
63 if (pos < end || start < pos) {
64 return (char*) 1;
65 }
66 } else {
67 if (start < pos && pos < end) {
68 return (char*) 1;
69 }
70 }
71 while (count) {
72 u8 c = *str;
73
74 if (c != 0) {
75 u32 addr = (u32) &gISVDbgPrnAdrs->data + (start & 0xffffffc);
76 s32 shift = ((3 - (start & 3)) * 8);
77
78 osEPiReadIo(nuPiCartHandle, addr, &data);
79 osEPiWriteIo(nuPiCartHandle, addr, (data & ~(0xff << shift)) | ((u8)*str << shift));
80
81 start++;
82 if (start >= 0xffe0) {
83 start -= 0xffe0;
84 }
85 }
86 count--;
87 str++;
88 }
89 osEPiWriteIo(nuPiCartHandle, (u32)&gISVDbgPrnAdrs->put, start);
90 return (char*) 1;
91}
92
93void is_debug_panic(const char* message) {
95 *(volatile u32*)0 = 0; // Crash so we can see the crash screen
96}
Vec3s pos
Definition demo_api.c:17
#define is_debug_panic
void is_debug_init(void)
Definition is_debug.c:19
char * is_debug_print(char *arg0, const char *str, size_t count)
Definition is_debug.c:46
void osSyncPrintf(const char *fmt,...)
Definition is_debug.c:32
void printf(const char *fmt,...)
Definition is_debug.c:25
u32 get
Definition is_debug.c:8
u32 magic
Definition is_debug.c:7
void crash_screen_set_assert_info(const char *message)
#define gISVDbgPrnAdrs
Definition is_debug.c:15
void rmonPrintf(const char *fmt,...)
Definition is_debug.c:39
u32 put
Definition is_debug.c:10
#define ASCII_TO_U32(a, b, c, d)
Definition macros.h:179