Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print function mdebug #90

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/libc/sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
// TODO: this comes from a header
#ident "$Revision: 1.23 $"

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

int sprintf(char* dst, const char* fmt, ...) {
s32 ans;
int sprintf(char* s, const char* fmt, ...) {
int ans;
va_list ap;
va_start(ap, fmt);
ans = _Printf(proutSprintf, dst, fmt, ap);
ans = _Printf(proutSprintf, s, fmt, ap);
if (ans >= 0) {
dst[ans] = 0;
s[ans] = 0;
}
return ans;
}
static char* proutSprintf(char* dst, const char* src, size_t count) {
return (char*)memcpy((u8*)dst, (u8*)src, count) + count;
static void* proutSprintf(void* s, const char* buf, size_t n) {
return (char*)memcpy(s, buf, n) + n;
}
11 changes: 5 additions & 6 deletions src/libc/syncprintf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdarg.h"
#include "PR/os.h"
#include "PR/os_internal.h"
#include "PR/rdb.h"
#include "xstdio.h"
#include "PR/rcp.h"
Expand All @@ -12,7 +13,7 @@ extern void* __printfunc;
extern u32 __kmc_pt_mode;

static void* proutSyncPrintf(void* str, const char* buf, size_t n) {
size_t sent = 0;
u32 sent = 0;

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

static void rmonPutchar(char c) {
u32 data;

while (*piok & (PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY)) {
}

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

p = &xbuf;
p = xbuf;

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

#else

void __osSyncVPrintf(const char* fmt, va_list args) {
void __osSyncVPrintf(const char* fmt, va_list ap) {

int ans;
#ifndef _FINALROM
if (__printfunc != NULL) {
ans = _Printf(__printfunc, NULL, fmt, args);
ans = _Printf(__printfunc, NULL, fmt, ap);
}
#endif
}
Expand Down
31 changes: 15 additions & 16 deletions src/libc/xldtob.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

#define BUFF_LEN 0x20

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

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

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

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

void _Ldtob(_Pft* px, char code) {
char buff[BUFF_LEN];
char *p;
f64 ldval;
s16 err;
s16 nsig;
s16 xexp;
ldouble ldval;
short err;
short nsig;
short xexp;

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

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

err = _Ldunscale(&xexp, px);
err = _Ldunscale(&xexp, &px->v.ld);
if (err > 0) {
memcpy(px->s, err == 2 ? "NaN" : "Inf", px->n1 = 3);
return;
Expand All @@ -87,7 +86,7 @@ void _Ldtob(_Pft* px, char code) {
}
}
} else if (xexp > 0) {
f64 factor = 1;
ldouble factor = 1;

xexp &= ~3;

Expand Down Expand Up @@ -160,9 +159,9 @@ void _Ldtob(_Pft* px, char code) {
_Genld(px, code, p, nsig, xexp);
}

s16 _Ldunscale(s16* pex, _Pft* px) {
u16* ps = (u16*)px;
s16 xchar = (ps[_D0] & _DMASK) >> _DOFF;
short _Ldunscale(short* pex, ldouble* px) {
unsigned short* ps = (unsigned short*)px;
short xchar = (ps[_D0] & _DMASK) >> _DOFF;


if (xchar == _DMAX) {
Expand All @@ -181,7 +180,7 @@ s16 _Ldunscale(s16* pex, _Pft* px) {
}
}

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

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

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

if (n < px->width) {
px->nz0 = px->width - n;
Expand Down
38 changes: 19 additions & 19 deletions src/libc/xlitob.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,47 @@
static char ldigs[] = "0123456789abcdef";
static char udigs[] = "0123456789ABCDEF";

void _Litob(_Pft *args, char type) {
void _Litob(_Pft *px, char code) {
char buff[BUFF_LEN];
const char *digs;
s32 base;
s32 i;
int base;
int i;
unsigned long long ullval;

digs = (type == 'X') ? udigs : ldigs;
digs = (code == 'X') ? udigs : ldigs;

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

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

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

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

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

args->v.ll = qr.quot;
px->v.ll = qr.quot;
buff[--i] = digs[qr.rem];
}

args->n1 = BUFF_LEN - i;
px->n1 = BUFF_LEN - i;

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

if (args->n1 < args->prec) {
args->nz0 = args->prec - args->n1;
if (px->n1 < px->prec) {
px->nz0 = px->prec - px->n1;
}

if (args->prec < 0 && (args->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
if ((i = args->width - args->n0 - args->nz0 - args->n1) > 0) {
args->nz0 += i;
if (px->prec < 0 && (px->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) {
if ((i = px->width - px->n0 - px->nz0 - px->n1) > 0) {
px->nz0 += i;
}
}
}
Loading
Loading