79 lines
1.1 KiB
C
79 lines
1.1 KiB
C
#include"stdio.h"
|
|
|
|
FILE*stdout=&(FILE){.fd=0,.offset=(unsigned short*)0xb8000,.seek=0};
|
|
|
|
void fputc(char c,FILE*f)
|
|
{
|
|
if(c=='\n')
|
|
f->seek=(f->seek+WIDTH)/WIDTH*WIDTH;
|
|
else
|
|
f->offset[f->seek++]=0x1f00|c;
|
|
}
|
|
|
|
// puts to FILE
|
|
void fputs(FILE*f,char*s)
|
|
{
|
|
for(unsigned i=0;s[i];++i)
|
|
//*f->offset++=0x1f00|s[i];
|
|
fputc(s[i],f);
|
|
fputc('\n',f);
|
|
}
|
|
|
|
// print to FILE
|
|
void fprint(FILE*f,char*s)
|
|
{
|
|
for(unsigned i=0;s[i];++i)
|
|
fputc(s[i],f);
|
|
}
|
|
|
|
// print integer
|
|
void fprinti(FILE*f,int d)
|
|
{
|
|
char b[32];
|
|
int i=0;
|
|
|
|
if(d<0)
|
|
{
|
|
fprint(f,"-");
|
|
d=-d;
|
|
}
|
|
|
|
// Get each digit as character
|
|
while(d>0)
|
|
{
|
|
int m=d%10;
|
|
d/=10;
|
|
b[i++]=m+'0';
|
|
}
|
|
b[i]=0;
|
|
|
|
// Print reversed string
|
|
for(i;i>=0;--i)
|
|
if(b[i]>31)
|
|
fputc(b[i],f);
|
|
}
|
|
|
|
// print integer (hex)
|
|
void fprinti16(FILE*f,unsigned int d)
|
|
{
|
|
static char g[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
|
static char b[32];
|
|
int i=0;
|
|
|
|
fprint(f,"0x");
|
|
|
|
// Get each digit as character
|
|
while(d>0)
|
|
{
|
|
unsigned int m=d%16;
|
|
d/=16;
|
|
b[i++]=g[m];
|
|
}
|
|
b[i]=0;
|
|
|
|
// Print reversed string
|
|
for(i;i>=0;--i)
|
|
if(b[i]>31)
|
|
fputc(b[i],f);
|
|
}
|