From ee0006e83551c2bd342d84dae6b48b4fe6043d46 Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 25 Mar 2015 23:35:27 -0700 Subject: add hex printing...ish --- src/kernel/main.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/kernel/main.c b/src/kernel/main.c index ec18738..c1c6ab6 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -5,20 +5,44 @@ void vga_graphics_write(char); void vga_graphics_write_with_attr(char, char); void vga_graphics_write_str(char*); +void vga_graphics_byte_hex(char); +//void vga_graphics_short_hex(short); +//void vga_graphics_int_hex(int); +//void vga_graphics_long_hex(long); + +void clear(); + static short CURSOR_LOC = 0; +static char* HEX_CHARS = "0123456789abcdef"; +char foo[] = "hello how are you"; void _start() { + clear(); vga_graphics_write_with_attr('a', 1); vga_graphics_write_with_attr('/', 2); vga_graphics_write_with_attr('b', 3); - char foo[] = "hello how are you"; vga_graphics_write_str(foo); + vga_graphics_write(':'); + vga_graphics_write(' '); + vga_graphics_byte_hex(0x40); while(1) { } } +void clear() { + int TERM_WIDTH = 80; + int TERM_HEIGHT = 25; + + int i = 0; + while(i < TERM_WIDTH * TERM_HEIGHT) { + vga_graphics_write_with_attr(' ', 7); + i++; + } + CURSOR_LOC = 0; +} + void vga_graphics_write_str(char* str) { while(*str) { - vga_graphics_write(*str++); + vga_graphics_write_with_attr(*str++, 7); } } @@ -32,6 +56,13 @@ void vga_graphics_write(char value) { CURSOR_LOC += 2; } +void vga_graphics_byte_hex(char value) { + char low = value & 0x0f; + char high = (value & 0xf0) >> 4; + vga_graphics_write(HEX_CHARS[high]); + vga_graphics_write(HEX_CHARS[low]); +} + void vga_graphics_write_at_offset(char value, short offset) { __asm__( "mov %0, %%al \n" -- cgit v1.1