I'm using [url=http://www.inp.nsk.su./~bolkhov/files/fonts/univga/]univga[url] for the font. Here is my code:
Code: Select all
; boot.asm
MODE_TYPE equ 0
WIDTH equ 640
HEIGHT equ 480
DEPTH equ 16
Code: Select all
int x_ = 0, y_ = font.Height;
void putpixel(int x, int y, int color) {
unsigned char* screen = (unsigned char*) 0xA0000;
// Hard-coded
unsigned where = x*2 + y*1280;
screen[where] = color & 255; // BLUE
screen[where + 1] = (color >> 8) & 255; // GREEN
screen[where + 2] = (color >> 16) & 255; // RED
}
unsigned char reverse(unsigned char b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
void drawchar(char c, int x, int y, int fgcolor, int bgcolor)
{
int cx, cy;
int mask[8]={1,2,4,8,16,32,64,128};
// Font layout starts from space (ascii 32)
// Skip first character
const unsigned char *glyph = font.Bitmap + ((int)c - 32 + 1) * font.Height;
for(cy = 0; cy < font.Height; cy++){
for(cx = 0; cx < font.Width; cx++) {
// For some reason it draws the glyphs backwards
putpixel(x + cx, y + cy - 12, reverse(glyph[cy]) & mask[cx] ? fgcolor : bgcolor);
}
}
x_ += font.Width;
if (x_ >= 640)
{
x_ = 0;
y_ += font.Height;
}
}
void drawchar(char c)
{
drawchar(c, x_, y_, 0xFFFFFF, 0xAAAAAA);
}
void drawstring(int x, int y, const char* input)
{
char buffer[strlen(input) + 1];
memcpy(buffer, input, strlen(input)+1);
char * ptr = buffer;
while (*ptr)
{
if (*ptr == '\n')
{
x = 0;
y += font.Height;
x_ = x;
y_ = y;
} else {
drawchar(*ptr, x, y, 0xFFFFFF, 0xAAAAAA);
x += font.Width;
}
++ptr;
}
}
void drawstring(const char* input)
{
drawstring(x_, y_, input);
}