80 lines
1.1 KiB
C
80 lines
1.1 KiB
C
#include"stdio.h"
|
|
#include"stdint.h"
|
|
|
|
FILE*stdout=&(FILE){.fd=0,.offset=(uint16_t*)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(uint32_t 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(uint32_t i=0;s[i];++i)
|
|
fputc(s[i],f);
|
|
}
|
|
|
|
// print integer
|
|
void fprinti(FILE*f,int32_t d)
|
|
{
|
|
char b[32];
|
|
int32_t i=0;
|
|
|
|
if(d<0)
|
|
{
|
|
fprint(f,"-");
|
|
d=-d;
|
|
}
|
|
|
|
// Get each digit as character
|
|
while(d>0)
|
|
{
|
|
int32_t m=d%10;
|
|
d/=10;
|
|
b[i++]=m+'0';
|
|
}
|
|
b[i]=0;
|
|
|
|
// Print reversed string
|
|
for(;i>=0;--i)
|
|
if(b[i]>31)
|
|
fputc(b[i],f);
|
|
}
|
|
|
|
// print integer (hex)
|
|
void fprinti16(FILE*f,uint32_t d)
|
|
{
|
|
static char g[]={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
|
|
static char b[32];
|
|
int32_t i=0;
|
|
|
|
fprint(f,"0x");
|
|
|
|
// Get each digit as character
|
|
while(d>0)
|
|
{
|
|
uint32_t m=d%16;
|
|
d/=16;
|
|
b[i++]=g[m];
|
|
}
|
|
b[i]=0;
|
|
|
|
// Print reversed string
|
|
for(;i>=0;--i)
|
|
if(b[i]>31)
|
|
fputc(b[i],f);
|
|
}
|