PavelCheckov wrote:
How would I write a printf function with this?
To display a character, take a look at the example
on PC Screen Font wiki page. You just repeat that code for every character and adjust the cursor position. A very very minimalistic string display example would be:
Code:
// PSF2 header
typedef struct {
uint32_t magic;
uint32_t version;
uint32_t headersize;
uint32_t flags;
uint32_t numglyph;
uint32_t bytesperglyph;
uint32_t height;
uint32_t width;
uint8_t glyphs;
} __attribute__((packed)) psf2_t;
extern volatile unsigned char _binary_font_psf_start;
void puts(char *s)
{
psf2_t *font = (psf2_t*)&_binary_font_psf_start;
int x,y,kx=0,line,mask,offs;
int bpl=(font->width+7)/8;
while(*s) {
unsigned char *glyph = (unsigned char*)&_binary_font_psf_start + font->headersize +
(*s>0&&*s<font->numglyph?*s:0)*font->bytesperglyph;
offs = (kx * (font->width+1) * 4);
for(y=0;y<font->height;y++) {
line=offs; mask=1<<(font->width-1);
for(x=0;x<font->width;x++) {
*((uint32_t*)(framebuffer_address+line))=((int)*glyph) & (mask)?0xFFFFFF:0;
mask>>=1; line+=4;
}
*((uint32_t*)((uint64_t)&fb+line))=0; glyph+=bpl; offs+=framebuffer_scanline;
}
s++; kx++;
}
}
As for the arguments, you should implement sprintf, construct the output buffer and pass that to this "puts" function.
You probably want more than this simple example, like handling newline characters, interpret UTF-8, proportional fonts etc. For these, you can find a ready-to-use, dependency free library,
Scalable Screen Font. It has a minimalistic routine, comparable to the PC Screen Font example above, see
ssfn_putc.
Cheers,
bzt