diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index 295abbb..c1d8691 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -37,13 +37,13 @@ char* ascii_title = unsigned int g_multiboot_info_address; -uint32_t white = 0xFFFFFFFF; -uint32_t black = 0x00000000; -uint32_t red = 0x00FF0000; - uint32_t* framebuffer; int scanline; +// in characters, not pixels +uint32_t VGA_WIDTH; +uint32_t VGA_HEIGHT; + void kmain(multiboot2_info *mb_info) { @@ -78,34 +78,35 @@ serial_printf(3, "Framebuffer BPP: %u\r\n", fb_info->framebuffer_bpp); uint32_t pitch = fb_info->framebuffer_pitch; uint32_t bpp = fb_info->framebuffer_bpp; - scanline = width * (bpp/8); + //8x16 font padded with 1 for each char = 9px/char + VGA_WIDTH = width/9; + VGA_HEIGHT = height/9; + + scanline = width * (bpp/8); - draw_char('S', 2, 2, white, black); - draw_char('A', 3, 2, white, black); - draw_char('L', 4, 2, white, black); - draw_char('U', 5, 2, white, black); - draw_char('T', 6, 2, white, black); - int y_offset = 0; - for (int c=0; c<512; c++) + /* TEST print charset + int y_offset = 2; + for (int i=0; i<512; i++) { - //draw_char(framebuffer, (int)pitch, (int)bpp, 20+(c-65)*16, 110+y_offset, c, white, black); - if (c%100 == 0) y_offset += 30; + if (i%(width/9)==0) y_offset++; + draw_char(0+i, 0+i, y_offset, white, black); } - - - + */ + + /* TEST print red square for (uint32_t y = 0; y < 10; y++) { for (uint32_t x = 0; x < 10; x++) { putpixel(framebuffer, (int)pitch, (int)bpp, x, y, red); //framebuffer[y * (pitch / 4) + x] = 0xFF0000; // Rouge } } + */ log("Drew to framebuffer.\r\n", 3); } - puts("This should NOT work."); - + puts("This should work by now! Enter Graphics Mode."); + printf("\nMy name is %s, and I'm %d. 0x%x", "Alan", 34, 0xdeadbeef); while (1); diff --git a/src/libc/stdio.c b/src/libc/stdio.c index 0b5f63f..e606888 100644 --- a/src/libc/stdio.c +++ b/src/libc/stdio.c @@ -3,31 +3,33 @@ #include "string.h" #include "stdint.h" #include "../kernel/system.h" +#include "../drivers/framebuffer.h" -char* fb = (char *) 0x000B8000; -const unsigned VGA_WIDTH = 80; -const unsigned VGA_HEIGHT = 25; -const unsigned int COLOR = 0x7; +extern uint32_t* framebuffer; +extern uint32_t VGA_WIDTH; +extern uint32_t VGA_HEIGHT; unsigned int VGA_X = 0, VGA_Y = 0; +enum Colors +{ + // AARRGGBB? + white = 0xFFFFFFFF, + black = 0x00000000, + red = 0x00FF0000, + green = 0x0000FF00, + blue = 0x000000FF, +}; + void move_cursor(int x, int y) { - unsigned short pos = y*VGA_WIDTH+x; - - outb(FB_CMD_PORT, FB_HIGH_BYTE_CMD); - outb(FB_DATA_PORT, ((pos >> 8) & 0x00FF)); - outb(FB_CMD_PORT, FB_LOW_BYTE_CMD); - outb(FB_DATA_PORT, pos & 0x00FF); + VGA_X = x; + VGA_Y = y; } -void putchar(int x, int y, char c) +// stdio wrapper for draw_char in graphics mode +void putchar(unsigned short int c, int x, int y, uint32_t fg, uint32_t bg) { - fb[2*(y*VGA_WIDTH+x)] = c; -} - -void putcolor(int x, int y, unsigned int color) -{ - fb[2*(y*VGA_WIDTH+x)+1] = color; + draw_char(c, x, y, fg, bg); } void clear(void) @@ -36,23 +38,10 @@ void clear(void) { for (unsigned int x=0; x