Skip to content

Commit 2717d45

Browse files
authored
Print function mdebug (#90)
* xprintf mdebug * xlitob mdebug * xldtob mdebug * sprintf mdebug * syncprintf mdebug * ldouble + remove ultratypes.h from xstdio.h * double only for IDO
1 parent 6e861af commit 2717d45

File tree

6 files changed

+127
-125
lines changed

6 files changed

+127
-125
lines changed

src/libc/sprintf.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
// TODO: this comes from a header
66
#ident "$Revision: 1.23 $"
77

8-
static char* proutSprintf(char* dst, const char* src, size_t count);
8+
static void* proutSprintf(void* s, const char* buf, size_t n);
99

10-
int sprintf(char* dst, const char* fmt, ...) {
11-
s32 ans;
10+
int sprintf(char* s, const char* fmt, ...) {
11+
int ans;
1212
va_list ap;
1313
va_start(ap, fmt);
14-
ans = _Printf(proutSprintf, dst, fmt, ap);
14+
ans = _Printf(proutSprintf, s, fmt, ap);
1515
if (ans >= 0) {
16-
dst[ans] = 0;
16+
s[ans] = 0;
1717
}
1818
return ans;
1919
}
20-
static char* proutSprintf(char* dst, const char* src, size_t count) {
21-
return (char*)memcpy((u8*)dst, (u8*)src, count) + count;
20+
static void* proutSprintf(void* s, const char* buf, size_t n) {
21+
return (char*)memcpy(s, buf, n) + n;
2222
}

src/libc/syncprintf.c

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "stdarg.h"
22
#include "PR/os.h"
3+
#include "PR/os_internal.h"
34
#include "PR/rdb.h"
45
#include "xstdio.h"
56
#include "PR/rcp.h"
@@ -12,7 +13,7 @@ extern void* __printfunc;
1213
extern u32 __kmc_pt_mode;
1314

1415
static void* proutSyncPrintf(void* str, const char* buf, size_t n) {
15-
size_t sent = 0;
16+
u32 sent = 0;
1617

1718
while (sent < n) {
1819
sent += __osRdbSend(buf + sent, n - sent, RDB_TYPE_GtoH_PRINT);
@@ -25,8 +26,6 @@ static volatile unsigned int* wport = (unsigned*)0xbff08000;
2526
static volatile unsigned int* piok = (unsigned*)PHYS_TO_K1(PI_STATUS_REG);
2627

2728
static void rmonPutchar(char c) {
28-
u32 data;
29-
3029
while (*piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) {
3130
}
3231

@@ -44,7 +43,7 @@ static void* kmc_proutSyncPrintf(void* str, const char* buf, int n) {
4443
char xbuf[128];
4544
static int column = 0;
4645

47-
p = &xbuf;
46+
p = xbuf;
4847

4948
for (i = 0; i < n; i++) {
5049
c = *buf++;
@@ -117,12 +116,12 @@ void rmonPrintf(const char* fmt, ...) {
117116

118117
#else
119118

120-
void __osSyncVPrintf(const char* fmt, va_list args) {
119+
void __osSyncVPrintf(const char* fmt, va_list ap) {
121120

122121
int ans;
123122
#ifndef _FINALROM
124123
if (__printfunc != NULL) {
125-
ans = _Printf(__printfunc, NULL, fmt, args);
124+
ans = _Printf(__printfunc, NULL, fmt, ap);
126125
}
127126
#endif
128127
}

src/libc/xldtob.c

+15-16
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
#define BUFF_LEN 0x20
1111

12-
static s16 _Ldunscale(s16* pex, _Pft* px);
13-
static void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp);
12+
static short _Ldunscale(short* pex, ldouble* px);
13+
static void _Genld(_Pft* px, char code, unsigned char* p, short nsig, short xexp);
1414

15-
static const double pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L};
15+
static const ldouble pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L};
1616

1717
// float properties
1818
#define _D0 0
@@ -41,17 +41,16 @@ static const double pows[] = {10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L
4141
#define _D2 2
4242
#define _D3 3
4343

44-
#define ALIGN(s, align) (((u32)(s) + ((align)-1)) & ~((align)-1))
44+
#define ALIGN(s, align) (((unsigned int)(s) + ((align)-1)) & ~((align)-1))
4545

4646
void _Ldtob(_Pft* px, char code) {
4747
char buff[BUFF_LEN];
4848
char *p;
49-
f64 ldval;
50-
s16 err;
51-
s16 nsig;
52-
s16 xexp;
49+
ldouble ldval;
50+
short err;
51+
short nsig;
52+
short xexp;
5353

54-
// char unused[0x4];
5554
p = buff;
5655
ldval = px->v.ld;
5756

@@ -61,7 +60,7 @@ void _Ldtob(_Pft* px, char code) {
6160
px->prec = 1;
6261
}
6362

64-
err = _Ldunscale(&xexp, px);
63+
err = _Ldunscale(&xexp, &px->v.ld);
6564
if (err > 0) {
6665
memcpy(px->s, err == 2 ? "NaN" : "Inf", px->n1 = 3);
6766
return;
@@ -87,7 +86,7 @@ void _Ldtob(_Pft* px, char code) {
8786
}
8887
}
8988
} else if (xexp > 0) {
90-
f64 factor = 1;
89+
ldouble factor = 1;
9190

9291
xexp &= ~3;
9392

@@ -160,9 +159,9 @@ void _Ldtob(_Pft* px, char code) {
160159
_Genld(px, code, p, nsig, xexp);
161160
}
162161

163-
s16 _Ldunscale(s16* pex, _Pft* px) {
164-
u16* ps = (u16*)px;
165-
s16 xchar = (ps[_D0] & _DMASK) >> _DOFF;
162+
short _Ldunscale(short* pex, ldouble* px) {
163+
unsigned short* ps = (unsigned short*)px;
164+
short xchar = (ps[_D0] & _DMASK) >> _DOFF;
166165

167166

168167
if (xchar == _DMAX) {
@@ -181,7 +180,7 @@ s16 _Ldunscale(s16* pex, _Pft* px) {
181180
}
182181
}
183182

184-
void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp) {
183+
void _Genld(_Pft* px, char code, unsigned char* p, short nsig, short xexp) {
185184
const unsigned char point = '.';
186185

187186
if (nsig <= 0) {
@@ -299,7 +298,7 @@ void _Genld(_Pft* px, char code, u8* p, s16 nsig, s16 xexp) {
299298
}
300299

301300
if ((px->flags & 0x14) == 0x10) {
302-
s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2;
301+
int n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2;
303302

304303
if (n < px->width) {
305304
px->nz0 = px->width - n;

src/libc/xlitob.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@
1212
static char ldigs[] = "0123456789abcdef";
1313
static char udigs[] = "0123456789ABCDEF";
1414

15-
void _Litob(_Pft *args, char type) {
15+
void _Litob(_Pft *px, char code) {
1616
char buff[BUFF_LEN];
1717
const char *digs;
18-
s32 base;
19-
s32 i;
18+
int base;
19+
int i;
2020
unsigned long long ullval;
2121

22-
digs = (type == 'X') ? udigs : ldigs;
22+
digs = (code == 'X') ? udigs : ldigs;
2323

24-
base = (type == 'o') ? 8 : ((type != 'x' && type != 'X') ? 10 : 16);
24+
base = (code == 'o') ? 8 : ((code != 'x' && code != 'X') ? 10 : 16);
2525
i = BUFF_LEN;
26-
ullval = args->v.ll;
26+
ullval = px->v.ll;
2727

28-
if ((type == 'd' || type == 'i') && args->v.ll < 0) {
28+
if ((code == 'd' || code == 'i') && px->v.ll < 0) {
2929
ullval = -ullval;
3030
}
3131

32-
if (ullval != 0 || args->prec != 0) {
32+
if (ullval != 0 || px->prec != 0) {
3333
buff[--i] = digs[ullval % base];
3434
}
3535

36-
args->v.ll = ullval / base;
36+
px->v.ll = ullval / base;
3737

38-
while (args->v.ll > 0 && i > 0) {
39-
lldiv_t qr = lldiv(args->v.ll, base);
38+
while (px->v.ll > 0 && i > 0) {
39+
lldiv_t qr = lldiv(px->v.ll, base);
4040

41-
args->v.ll = qr.quot;
41+
px->v.ll = qr.quot;
4242
buff[--i] = digs[qr.rem];
4343
}
4444

45-
args->n1 = BUFF_LEN - i;
45+
px->n1 = BUFF_LEN - i;
4646

47-
memcpy(args->s, buff + i, args->n1);
47+
memcpy(px->s, buff + i, px->n1);
4848

49-
if (args->n1 < args->prec) {
50-
args->nz0 = args->prec - args->n1;
49+
if (px->n1 < px->prec) {
50+
px->nz0 = px->prec - px->n1;
5151
}
5252

53-
if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
54-
if ((i = args->width - args->n0 - args->nz0 - args->n1) > 0) {
55-
args->nz0 += i;
53+
if (px->prec < 0 && (px->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
54+
if ((i = px->width - px->n0 - px->nz0 - px->n1) > 0) {
55+
px->nz0 += i;
5656
}
5757
}
5858
}

0 commit comments

Comments
 (0)