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 <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
24
25int printf(const char* restrict fmt, ...) {
26 va_list args;
27 va_start(args, fmt);
28
29 return _Printf(is_debug_print, NULL, fmt, args);
30}
31
32int __printf_chk(int flag, const char* restrict fmt, ...) {
33 va_list args;
34 va_start(args, fmt);
35 (void)flag;
36
37 return _Printf(is_debug_print, NULL, fmt, args);
38}
39
40int puts(const char* s) {
41 printf("%s\n", s);
42 return 0;
43}
44
45void osSyncPrintf(const char* fmt, ...) {
46 va_list args;
47 va_start(args, fmt);
48
49 _Printf(is_debug_print, NULL, fmt, args);
50}
51
52void rmonPrintf(const char* fmt, ...) {
53 va_list args;
54 va_start(args, fmt);
55
56 _Printf(is_debug_print, NULL, fmt, args);
57}
58
59char* is_debug_print(char* arg0, const char* str, size_t count) {
60 u32 data;
61 s32 pos;
62 s32 start;
63 s32 end;
64
66 if (data != ASCII_TO_U32('I', 'S', '6', '4')) {
67 return (char*) 1;
68 }
70 pos = data;
72 start = data;
73 end = start + count;
74 if (end >= 0xffe0) {
75 end -= 0xffe0;
76 if (pos < end || start < pos) {
77 return (char*) 1;
78 }
79 } else {
80 if (start < pos && pos < end) {
81 return (char*) 1;
82 }
83 }
84 while (count) {
85 u8 c = *str;
86
87 if (c != 0) {
88 u32 addr = (u32) &gISVDbgPrnAdrs->data + (start & 0xffffffc);
89 s32 shift = ((3 - (start & 3)) * 8);
90
91 osEPiReadIo(nuPiCartHandle, addr, &data);
92 osEPiWriteIo(nuPiCartHandle, addr, (data & ~(0xff << shift)) | ((u8)*str << shift));
93
94 start++;
95 if (start >= 0xffe0) {
96 start -= 0xffe0;
97 }
98 }
99 count--;
100 str++;
101 }
103 return (char*) 1;
104}
105
106void is_debug_panic(const char* message) {
108 *(volatile u32*)0 = 0; // Crash so we can see the crash screen
110}
BSS s32 PopupMenu_SelectedIndex
Vec3s pos
Definition demo_api.c:17
#define is_debug_panic
int _Printf(outfun prout, char *arg, const char *fmt, va_list args)
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:59
void osSyncPrintf(const char *fmt,...)
Definition is_debug.c:45
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:52
int printf(const char *restrict fmt,...)
Definition is_debug.c:25
int __printf_chk(int flag, const char *restrict fmt,...)
Definition is_debug.c:32
u32 put
Definition is_debug.c:10
int puts(const char *s)
Definition is_debug.c:40
#define ASCII_TO_U32(a, b, c, d)
Definition macros.h:183