printf.c 679 Bytes
#include <stdarg.h>
#include <string.h>
#include "os.h"
#include "libfb.h"

struct _pos {
    int curs_x, curs_y;
    u16 color;
};

extern int _Printf(void *(*)(void *, const char *, size_t),
	        void *, const char *, ...);

static void *
prout(void *s, const char *buf, size_t n) {
	struct _pos* p = (struct _pos*)s;
	int i;
	for (i = 0 ; i < n; i++)
		fbPutChar(p->color, p->curs_x++, p->curs_y, *buf++);
	return s;
}

int
fbPrintf(u16 color, int curs_x, int curs_y, const char *fmt, ...) {
	int ans;
	struct _pos p;
	va_list ap;

	p.color = color; p.curs_x = curs_x; p.curs_y = curs_y;
	va_start(ap, fmt);
	ans = _Printf(prout, &p, fmt, ap);
	va_end(ap);
	return ans;
}