#include <stdio.h>
#include <stdarg.h>

#include <gctypes.h>
#include "font.h"
#include "../screen.h"

void screen_draw_char(int x, int y, unsigned char character, u16 color)
{
	int ni=(FONT_WIDTH*FONT_HIGH*(character-1));
	int py, px;
	for(py=y; py<y+FONT_HIGH; py++)
	{
		for(px=x; px<x+FONT_WIDTH; px++)
		{
			if(FONT[ni]==0x00)
				screen_put_pixel(px,py,color);

			ni++;
		}	
	}
}
void screen_print(int x, int y, const char *msg, u16 color)
{
	int xx = x;
	unsigned char ch = 0, *str=(unsigned char*)msg;

	while(*str != 0) {
		ch = *str++;
		switch(ch)
		{
			case '\n':
				x=xx;
				y+=FONT_HIGH;
				break;
			case '\r':
				break;
			default:
				screen_draw_char(x, y, ch, color);
				x+=FONT_WIDTH;
		}
		if (x>=screen_w) break;
		if (y>=screen_h) break;
	}
}
void screen_printf(int x, int y, u16 color, const char *str, ...)
{
	va_list ap;
	char szBuf[512];

	va_start(ap, str);
	vsprintf(szBuf, str, ap);
	va_end(ap);

	screen_print(x, y, szBuf, color);
}
