kmcprintf.c
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "xstdio.h"
#include "osint.h"
/* #include "os_internal.h" */
#include "rdb.h"
#ifndef _FINALROM
static void *proutSyncPrintf(void *str, const char *buf, size_t n)
{
size_t sent = 0;
while(sent < n)
{
sent += __osRdbSend((u8*)&buf[sent],(u32)(n-sent),(size_t)RDB_TYPE_GtoH_PRINT);
}
return ((void *) 1); /* return a fake pointer so that it's not NULL */
}
volatile static unsigned *stat= (unsigned *)0xbff08004;
volatile static unsigned *wport=(unsigned *)0xbff08000;
volatile static unsigned *piok= (unsigned *)0xa4600010;
extern s32 __kmc_pt_mode;
static void rmonPutchar(char c)
{
while((*piok & 3)!=0) ;
while((*stat & 4)==0) ;
*wport=(unsigned int)c;
}
static void *kmc_proutSyncPrintf(void *str, const char *buf, int n)
{
int i;
char c,*p,*q,xbuf[128];
static int column = 0;
p=xbuf;
for(i=0;i<n;++i){
c=*(buf++);
switch (c) {
case '\n':
*(p++)='\n';
column = 0;
break;
case '\t':
do{
*(p++)=' ';
}while(++column % 8);
break;
default:
column++;
*(p++)=c;
break;
}
if(c=='\n' || (p-xbuf)>100){
rmonPutchar((char)((p-xbuf)-1));
q=xbuf;
while(q!=p){
rmonPutchar(*(q++));
}
p=xbuf;
}
}
if(p!=xbuf){
rmonPutchar((char)((p-xbuf)-1));
q=xbuf;
while(q!=p){
rmonPutchar(*(q++));
}
}
return ((void *) 1); /* return a fake pointer so that it's not NULL */
}
#endif
static void kmcErrorHandler(s16, s16, ...);
#include "oserr.h"
OSErrorHandler __kmcErrorHandler = kmcErrorHandler;
static void
kmcErrorHandler(s16 code, s16 numArgs, ...)
{
#ifndef _FINALROM
int ans;
va_list ap;
char * fmt;
fmt = __os_error_message[code];
va_start(ap, numArgs);
if(__kmc_pt_mode){
ans = _Printf((void *)&kmc_proutSyncPrintf, NULL, fmt, ap);
}
else{
ans = _Printf(&proutSyncPrintf, NULL, fmt, ap);
}
va_end(ap);
osSyncPrintf("\n");
#endif
}