[bochs] Font rendering, working on font still. Does numbers.

This commit is contained in:
Kevin Lange 2011-03-28 15:18:48 -05:00
parent 6d95cf95a0
commit 88b93880a6
4 changed files with 577 additions and 15 deletions

497
kernel/core/vga_font.c Normal file
View File

@ -0,0 +1,497 @@
/* This is the default VGA 8 x 12 font */
char number_font[][12] = {
{ 0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 4 */
0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 8 */
0b00000000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00110000,
0b01111000,
0b01111000, /* 4 */
0b00110000,
0b00110000,
0b00000000,
0b00110000, /* 8 */
0b00110000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01100110,
0b01100110,
0b00100100, /* 4 */
0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 8 */
0b00000000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01101100,
0b01101100,
0b11111110, /* 4 */
0b01101100,
0b01101100,
0b01101100,
0b11111110, /* 8 */
0b01101100,
0b01101100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00110000,
0b00110000,
0b01111100,
0b11000000, /* 4 */
0b11000000,
0b01111000,
0b00001100,
0b00001100, /* 8 */
0b11111000,
0b00110000,
0b00110000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b11000100,
0b11001100, /* 4 */
0b00011000,
0b00110000,
0b01100000,
0b11001100, /* 8 */
0b10001100,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01110000,
0b11011000,
0b11011000, /* 4 */
0b01110000,
0b11111010,
0b11011110,
0b11001100, /* 8 */
0b11011100,
0b01110110,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00110000,
0b00110000,
0b00110000, /* 4 */
0b01100000,
0b00000000,
0b00000000,
0b00000000, /* 8 */
0b00000000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00001100,
0b00011000,
0b00110000, /* 4 */
0b01100000,
0b01100000,
0b01100000,
0b00110000, /* 8 */
0b00011000,
0b00001100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01100000,
0b00110000,
0b00011000, /* 4 */
0b00001100,
0b00001100,
0b00001100,
0b00011000, /* 8 */
0b00110000,
0b01100000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b01100110, /* 4 */
0b00111100,
0b11111111,
0b00111100,
0b01100110, /* 8 */
0b00000000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00000000, /** 4 */
0b00011000,
0b00011000,
0b01111110,
0b00011000, /* 8 */
0b00011000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 4 */
0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 8 */
0b00111000,
0b00111000,
0b01100000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 4 */
0b00000000,
0b00000000,
0b11111110,
0b00000000, /* 8 */
0b00000000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 4 */
0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 8 */
0b00111000,
0b00111000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000010,
0b00000110, /* 4 */
0b00001100,
0b00011000,
0b00110000,
0b01100000, /* 8 */
0b11000000,
0b10000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111100,
0b11000110,
0b11001110, /* 4 */
0b11011110,
0b11010110,
0b11110110,
0b11100110, /* 8 */
0b11000110,
0b01111100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00010000,
0b00110000,
0b11110000, /* 4 */
0b00110000,
0b00110000,
0b00110000,
0b00110000, /* 8 */
0b00110000,
0b11111100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111000,
0b11001100,
0b11001100, /* 4 */
0b00001100,
0b00011000,
0b00110000,
0b01100000, /* 8 */
0b11001100,
0b11111100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111000,
0b11001100,
0b00001100, /* 4 */
0b00001100,
0b00111000,
0b00001100,
0b00001100, /* 8 */
0b11001100,
0b01111000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00001100,
0b00011100,
0b00111100, /* 4 */
0b01101100,
0b11001100,
0b11111110,
0b00001100, /* 8 */
0b00001100,
0b00011110,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b11111100,
0b11000000,
0b11000000, /* 4 */
0b11000000,
0b11111000,
0b00001100,
0b00001100, /* 8 */
0b11001100,
0b01111000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00111000,
0b01100000,
0b11000000, /* 4 */
0b11000000,
0b11111000,
0b11001100,
0b11001100, /* 8 */
0b11001100,
0b01111000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b11111110,
0b11000110,
0b11000110, /* 4 */
0b00000110,
0b00001100,
0b00011000,
0b00110000, /* 8 */
0b00110000,
0b00110000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111000,
0b11001100,
0b11000100, /* 4 */
0b11000100,
0b01111000,
0b11001100,
0b11001100, /* 8 */
0b11001100,
0b01111000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111000,
0b11001100,
0b11001100, /* 4 */
0b11001100,
0b01111100,
0b00011000,
0b00011000, /* 8 */
0b00110000,
0b01110000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00111000, /* 4 */
0b00111000,
0b00000000,
0b00000000,
0b00111000, /* 8 */
0b00111000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00111000, /* 4 */
0b00111000,
0b00000000,
0b00000000,
0b00111000, /* 8 */
0b00111000,
0b00011000,
0b00110000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00001100,
0b00011000,
0b00110000, /* 4 */
0b01100000,
0b11000000,
0b01100000,
0b00110000, /* 8 */
0b00011000,
0b00001100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00000000,
0b00000000,
0b00000000, /* 4 */
0b01111110,
0b00000000,
0b01111110,
0b00000000, /* 8 */
0b00000000,
0b00000000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01100000,
0b00110000,
0b00011000, /* 4 */
0b00001100,
0b00000110,
0b00001100,
0b00011000, /* 8 */
0b00110000,
0b01100000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111000,
0b11001100,
0b00001100, /* 4 */
0b00011000,
0b00110000,
0b00110000,
0b00000000, /* 8 */
0b00110000,
0b00110000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b01111100,
0b11000110,
0b11000110, /* 4 */
0b11011110,
0b11010110,
0b11011110,
0b11000000, /* 8 */
0b11000000,
0b01111100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00110000,
0b01111000,
0b11001100, /* 4 */
0b11001100,
0b11001100,
0b11111100,
0b11001100, /* 8 */
0b11001100,
0b11001100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b11111100,
0b01100110,
0b01100110, /* 4 */
0b01100110,
0b01111100,
0b01100110,
0b01100110, /* 8 */
0b01100110,
0b11111100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b00111100,
0b01100110,
0b11000110, /* 4 */
0b11000000,
0b11000000,
0b11000000,
0b11000110, /* 8 */
0b01100110,
0b00111100,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b11111000,
0b01101100,
0b01100110, /* 4 */
0b01100110,
0b01100110,
0b01100110,
0b01100110, /* 8 */
0b01101100,
0b11111000,
0b00000000,
0b00000000 /* 12 */
},
{ 0b00000000,
0b11111110,
0b01100010,
0b01100000, /* 4 */
0b01100100,
0b01111100,
0b01100100,
0b01100000, /* 8 */
0b01100010,
0b11111110,
0b00000000,
0b00000000 /* 12 */
},
};

View File

@ -68,6 +68,15 @@ bochs_set_bank(
bochs_current_bank = bank;
}
static void
bochs_set_point(
uint16_t x,
uint16_t y,
uint32_t color
) {
BOCHS_VID_MEMORY[(y * bochs_resolution_x + x) % BOCHS_BANK_SIZE] = color;
}
void
bochs_set_coord(
uint16_t x,
@ -125,3 +134,41 @@ bochs_draw_logo(char * filename) {
i += row_width;
}
}
void
bochs_fill_rect(
uint16_t x,
uint16_t y,
uint16_t w,
uint16_t h,
uint32_t color
) {
for (uint16_t i = y; i < h + y; ++i) {
bochs_set_bank(y * bochs_resolution_x / BOCHS_BANK_SIZE);
for (uint16_t j = x; j < w + x; ++j) {
bochs_set_point(j,i,color);
}
}
}
void
bochs_write_number(
uint8_t val,
uint16_t x,
uint16_t y,
uint32_t fg,
uint32_t bg
) {
char * c = number_font[val + 0x10];
for (uint8_t i = 0; i < 12; ++i) {
bochs_set_bank((y+i) * bochs_resolution_x / BOCHS_BANK_SIZE);
if (c[i] & 0x80) { bochs_set_point(x,y+i,fg); } else { bochs_set_point(x,y+i,bg); }
if (c[i] & 0x40) { bochs_set_point(x+1,y+i,fg); } else { bochs_set_point(x+1,y+i,bg); }
if (c[i] & 0x20) { bochs_set_point(x+2,y+i,fg); } else { bochs_set_point(x+2,y+i,bg); }
if (c[i] & 0x10) { bochs_set_point(x+3,y+i,fg); } else { bochs_set_point(x+3,y+i,bg); }
if (c[i] & 0x08) { bochs_set_point(x+4,y+i,fg); } else { bochs_set_point(x+4,y+i,bg); }
if (c[i] & 0x04) { bochs_set_point(x+5,y+i,fg); } else { bochs_set_point(x+5,y+i,bg); }
if (c[i] & 0x02) { bochs_set_point(x+6,y+i,fg); } else { bochs_set_point(x+6,y+i,bg); }
if (c[i] & 0x01) { bochs_set_point(x+7,y+i,fg); } else { bochs_set_point(x+7,y+i,bg); }
}
}

View File

@ -191,7 +191,14 @@ extern int detect_cpu();
extern void graphics_install_bochs();
extern void bochs_set_bank(uint16_t bank);
extern void bochs_set_coord(uint16_t x, uint16_t y, uint32_t color);
extern void bochs_fill_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint32_t color);
extern void bochs_draw_logo(char *);
extern void bochs_scroll();
extern void bochs_write_number(uint8_t val, uint16_t x, uint16_t y, uint32_t fg, uint32_t bg);
extern uint16_t bochs_resolution_x;
extern uint16_t bochs_resolution_y;
extern uint16_t bochs_resolution_b;
extern char number_font[][12];
#endif

View File

@ -151,23 +151,34 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp)
get_time(&hours, &minutes, &seconds);
__asm__ __volatile__ ("cli");
store_csr();
set_serial(0);
set_csr(0);
place_csr(70,0);
/* It would help a lot if I had %.2d */
/* kprintf("[%.2d:%.2d:%.2d]", hours, minutes, seconds); */
writech('[');
kprintf("%d", hours / 10);
kprintf("%d", hours % 10);
writech(':');
kprintf("%d", minutes / 10);
kprintf("%d", minutes % 10);
writech(':');
kprintf("%d", seconds / 10);
kprintf("%d", seconds % 10);
writech(']');
restore_csr();
if (bochs_resolution_x) {
bochs_write_number(hours / 10, bochs_resolution_x - 8 * 8, 0, 0x00FFFFFF, 0x0);
bochs_write_number(hours % 10, bochs_resolution_x - 8 * 7, 0, 0x00FFFFFF, 0x0);
bochs_write_number( 10, bochs_resolution_x - 8 * 6, 0, 0x00FFFFFF, 0x0);
bochs_write_number(minutes / 10, bochs_resolution_x - 8 * 5, 0, 0x00FFFFFF, 0x0);
bochs_write_number(minutes % 10, bochs_resolution_x - 8 * 4, 0, 0x00FFFFFF, 0x0);
bochs_write_number( 10, bochs_resolution_x - 8 * 3, 0, 0x00FFFFFF, 0x0);
bochs_write_number(seconds / 10, bochs_resolution_x - 8 * 2, 0, 0x00FFFFFF, 0x0);
bochs_write_number(seconds % 10, bochs_resolution_x - 8 * 1, 0, 0x00FFFFFF, 0x0);
} else {
store_csr();
set_serial(0);
set_csr(0);
place_csr(70,0);
writech('[');
kprintf("%d", hours / 10);
kprintf("%d", hours % 10);
writech(':');
kprintf("%d", minutes / 10);
kprintf("%d", minutes % 10);
writech(':');
kprintf("%d", seconds / 10);
kprintf("%d", seconds % 10);
writech(']');
restore_csr();
}
__asm__ __volatile__ ("sti");
__asm__ __volatile__ ("hlt");
}