Skip to content

Commit

Permalink
Print stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
hensldm committed Jun 24, 2024
1 parent de1f5a6 commit a54be84
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/libc/sprintf.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "xstdio.h"
#include "string.h"
#include "xstdio.h"
#include "os.h"

// TODO: this comes from a header
Expand Down
29 changes: 15 additions & 14 deletions src/libc/xldtob.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdlib.h"
#include "string.h"
#include "xstdio.h"
#include "stdlib.h"
#include "getopt.h"

// TODO: these come from headers
#ident "$Revision: 1.23 $"
Expand All @@ -9,8 +10,8 @@

#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, _Pft* 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};

Expand Down Expand Up @@ -41,15 +42,15 @@ 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;
double ldval;
short err;
short nsig;
short xexp;

// char unused[0x4];
p = buff;
Expand Down Expand Up @@ -87,7 +88,7 @@ void _Ldtob(_Pft* px, char code) {
}
}
} else if (xexp > 0) {
f64 factor = 1;
double factor = 1;

xexp &= ~3;

Expand Down Expand Up @@ -160,9 +161,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, _Pft* px) {
unsigned short* ps = (unsigned short*)px;
short xchar = (ps[_D0] & _DMASK) >> _DOFF;


if (xchar == _DMAX) {
Expand All @@ -181,7 +182,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 +300,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
5 changes: 3 additions & 2 deletions src/libc/xlitob.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "stdlib.h"
#include "getopt.h"
#include "string.h"
#include "xstdio.h"

Expand All @@ -15,8 +16,8 @@ static char udigs[] = "0123456789ABCDEF";
void _Litob(_Pft *args, char type) {
char buff[BUFF_LEN];
const char *digs;
s32 base;
s32 i;
int base;
int i;
unsigned long long ullval;

digs = (type == 'X') ? udigs : ldigs;
Expand Down
21 changes: 11 additions & 10 deletions src/libc/xprintf.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "macros.h"
#include "string.h"
#include "stdarg.h"
#include "stdlib.h"
#include "getopt.h"
#include "xstdio.h"
#include "string.h"

// TODO: these come from headers
#ident "$Revision: 1.34 $"
Expand Down Expand Up @@ -47,7 +48,7 @@ int _Printf(outfun prout, char *arg, const char *fmt, va_list args) {

x.nchar = 0;

while (TRUE) {
while (1) {
const char *s;
char c;
const char *t;
Expand Down Expand Up @@ -152,13 +153,13 @@ static void _Putfld(_Pft *x, va_list *args, char type, char *buff) {
if (x->qual == 'l') {
x->v.ll = va_arg(*args, int);
} else if (x->qual == 'L') {
x->v.ll = va_arg(*args, s64);
x->v.ll = va_arg(*args, long long);
} else {
x->v.ll = va_arg(*args, int);
}

if (x->qual == 'h') {
x->v.ll = (s16)x->v.ll;
x->v.ll = (short)x->v.ll;
}

if (x->v.ll < 0) {
Expand All @@ -180,13 +181,13 @@ static void _Putfld(_Pft *x, va_list *args, char type, char *buff) {
if (x->qual == 'l') {
x->v.ll = va_arg(*args, int);
} else if (x->qual == 'L') {
x->v.ll = va_arg(*args, s64);
x->v.ll = va_arg(*args, long long);
} else {
x->v.ll = va_arg(*args, int);
}

if (x->qual == 'h') {
x->v.ll = (u16)x->v.ll;
x->v.ll = (unsigned short)x->v.ll;
} else if (x->qual == 0) {
x->v.ll = (unsigned int)x->v.ll;
}
Expand All @@ -208,7 +209,7 @@ static void _Putfld(_Pft *x, va_list *args, char type, char *buff) {
case 'E':
case 'G':
//... okay?
x->v.ld = x->qual == 'L' ? va_arg(*args, f64) : va_arg(*args, f64);
x->v.ld = x->qual == 'L' ? va_arg(*args, double) : va_arg(*args, double);

if (LDSIGN(x->v.ld))
buff[x->n0++] = '-';
Expand All @@ -223,11 +224,11 @@ static void _Putfld(_Pft *x, va_list *args, char type, char *buff) {

case 'n':
if (x->qual == 'h') {
*(va_arg(*args, u16 *)) = x->nchar;
*(va_arg(*args, unsigned short *)) = x->nchar;
} else if (x->qual == 'l') {
*va_arg(*args, unsigned int *) = x->nchar;
} else if (x->qual == 'L') {
*va_arg(*args, u64 *) = x->nchar;
*va_arg(*args, unsigned long long *) = x->nchar;
} else {
*va_arg(*args, unsigned int *) = x->nchar;
}
Expand Down
2 changes: 0 additions & 2 deletions src/libc/xstdio.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#ifndef _XSTDIO_H
#define _XSTDIO_H
#include "PR/ultratypes.h"
#include "stdlib.h"
#include "stdarg.h"

typedef struct {
Expand Down

0 comments on commit a54be84

Please sign in to comment.