Skip to content

Commit 4510848

Browse files
committed
Match syncprintf.c
1 parent 27545b8 commit 4510848

File tree

5 files changed

+107
-13
lines changed

5 files changed

+107
-13
lines changed

include/libc/xstdio.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct {
2828
#define FLAGS_MINUS 4
2929
#define FLAGS_HASH 8
3030
#define FLAGS_ZERO 16
31-
typedef char *outfun(char*,const char*,size_t);
31+
typedef void *outfun(void*,const char*,size_t);
3232

3333
int _Printf(outfun prout, char *arg, const char *fmt, va_list args);
3434
void _Litob(_Pft *args, char type);

splat.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ segments:
324324
- [0x98AF0, data, libultra/os/exceptasm]
325325
- [0x98B30, .data, libultra/os/writehost]
326326
- [0x98B40, .data, libultra/os/readhost]
327-
- [0x98B50, data, libultra/libc/syncprintf]
327+
- [0x98B50, .data, libultra/libc/syncprintf]
328328
- [0x98B60, .data, libultra/io/contramread]
329329
- [0x98B70, .data, libultra/io/piacs]
330330
- [0x98B80, .data, libultra/os/rdbsend]

src/libultra/libc/syncprintf.c

+101-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,106 @@
1-
#include "common.h"
1+
// @DECOMP_OPT_FLAGS=-O3
2+
#include <PR/os.h>
3+
#include <PR/os_internal.h>
4+
#include <PR/rdb.h>
5+
#include <PR/rcp.h>
6+
#include "libc/xstdio.h"
7+
#include "libc/stdarg.h"
28

3-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/syncprintf/rmonPrintf.s")
9+
extern s32 __kmc_pt_mode;
410

5-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/syncprintf/proutSyncPrintf.s")
11+
static void* proutSyncPrintf(void* str, const char* buf, size_t n) {
12+
u32 sent = 0;
613

7-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/syncprintf/rmonPutchar.s")
14+
while (sent < n) {
15+
sent += __osRdbSend((u8*)(buf + sent), n - sent, RDB_TYPE_GtoH_PRINT);
16+
}
17+
return (void*)1;
18+
}
819

9-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/syncprintf/kmc_proutSyncPrintf.s")
20+
static volatile unsigned int* stat = (unsigned*)0xbff08004;
21+
static volatile unsigned int* wport = (unsigned*)0xbff08000;
22+
static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG);
1023

11-
#pragma GLOBAL_ASM("asm/nonmatchings/libultra/libc/syncprintf/osSyncPrintf.s")
24+
static void rmonPutchar(char c) {
25+
while (*piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) {
26+
}
27+
28+
while (!(*stat & 4)) {
29+
}
30+
31+
*wport = c;
32+
}
33+
34+
static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) {
35+
int i;
36+
char c;
37+
char* p;
38+
char* q;
39+
char xbuf[128];
40+
static int column = 0;
41+
42+
p = xbuf;
43+
44+
for (i = 0; i < n; i++) {
45+
c = *buf++;
46+
47+
switch (c) {
48+
case '\n':
49+
*p++ = '\n';
50+
column = 0;
51+
break;
52+
case '\t':
53+
do {
54+
*p++ = ' ';
55+
} while (++column % 8);
56+
break;
57+
default:
58+
column++;
59+
*p++ = c;
60+
break;
61+
}
62+
63+
if (c == '\n' || (p - xbuf) > 100) {
64+
rmonPutchar((p - xbuf) - 1);
65+
66+
q = xbuf;
67+
while (q != p) {
68+
rmonPutchar(*q++);
69+
}
70+
p = xbuf;
71+
}
72+
}
73+
if (p != xbuf) {
74+
rmonPutchar((p - xbuf) - 1);
75+
76+
q = xbuf;
77+
while (q != p) {
78+
rmonPutchar(*q++);
79+
}
80+
}
81+
return (void*)1;
82+
}
83+
84+
void osSyncPrintf(const char* fmt, ...) {
85+
int ans;
86+
va_list ap;
87+
88+
va_start(ap, fmt);
89+
if (__kmc_pt_mode) {
90+
ans = _Printf((outfun*)kmc_proutSyncPrintf, NULL, fmt, ap);
91+
} else {
92+
ans = _Printf(proutSyncPrintf, NULL, fmt, ap);
93+
}
94+
va_end(ap);
95+
}
96+
97+
void rmonPrintf(const char* fmt, ...) {
98+
int ans;
99+
va_list ap;
100+
101+
va_start(ap, fmt);
102+
if (__kmc_pt_mode) {
103+
ans = _Printf((outfun*)kmc_proutSyncPrintf, NULL, fmt, ap);
104+
}
105+
va_end(ap);
106+
}

src/libultra/os/initialize.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ OSTime osClockRate = OS_CLOCK_RATE;
2424
s32 osViClock = VI_NTSC_CLOCK;
2525
u32 __osShutdown = 0;
2626
u32 __OSGlobalIntMask = OS_IM_ALL;
27-
s32 gP64Enabled;
27+
s32 __kmc_pt_mode;
2828

2929
void __createSpeedParam();
3030

@@ -99,7 +99,7 @@ void osInitialize() {
9999

100100
// partner-64 stuff
101101
// note: not 100% sure what the below is doing, some comments may be wrong
102-
if (gP64Enabled == 0) {
102+
if (__kmc_pt_mode == 0) {
103103
p64Status = (u32 *)0xBFF08004;
104104
p64Struct = (u32 *)0xBFF00000;
105105

@@ -126,7 +126,7 @@ void osInitialize() {
126126
osInvalICache((void *)E_VEC, 0x24);
127127

128128
// mark partner mode as enabled
129-
gP64Enabled = 1;
129+
__kmc_pt_mode = 1;
130130

131131
// check some status bit
132132
if ((*p64Status & 0x10) == 0) {

symbol_addrs.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ Nan = 0x800a29b8; // size:0x4
704704
inf = 0x800a29bc; // size:0x4
705705
xldtob_rodata_0058 = 0x800a29c8; // size:0x8
706706
player_bss_0048 = 0x800a7d40;
707-
gP64Enabled = 0x800cd320; // size:0x4
707+
__kmc_pt_mode = 0x800cd320; // size:0x4
708708
__osEventStateTab = 0x800cd330; // size:0xc0
709709
__osContPifRam = 0x800cd3f0; // size:0x40
710710
__osContLastCmd = 0x800cd430; // size:0x1
@@ -775,7 +775,6 @@ al_syn_dma = 0x80012084; // type:func
775775
osViModeTable = 0x80096cd0; // size:0x1180
776776
__osCleanupThread_80080df0 = 0x80080df0; // type:func
777777
gIdleThread = 0x800a5dc0; // size:0x1b0
778-
pi_status_pointer = 0x80097f58; // size:0x4
779778
__CallBackDmaNew = 0x80001778; // type:func
780779
NOTosSetTime = 0x8003f4a8; // type:func
781780
gFramebufferCurrent = 0x800bccac; // size:0x4

0 commit comments

Comments
 (0)