diff options
Diffstat (limited to 'src/vga.c')
-rw-r--r-- | src/vga.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include <stdbool.h> #include "string.h" +#include "stdlib.h" static bool params_ok( vga_t *vga, const int x, const int y ); static int calculate_offset( vga_t *vga ); @@ -17,6 +18,10 @@ void vga_init( vga_t *vga ) vga->res_y = VGA_DEFAULT_RES_Y; vga->color = VGA_COLOR_DARK_GREY; vga->background_color = VGA_COLOR_BLACK; + + // set up ports + port8_init( &vga->crtc_index_port, 0x3d4 ); + port8_init( &vga->crtc_data_port, 0x3d5 ); // TODO: get current position from VGA hardware vga_set_cursor_from_hardware( vga ); @@ -41,12 +46,25 @@ void vga_set_cursor( vga_t *vga, const int x, const int y ) vga->cursor_x = x; vga->cursor_y = y; + + // TODO: have a silent mode where we don't update the cursor + vga_set_cursor_on_hardware( vga ); } void vga_set_cursor_from_hardware( vga_t *vga ) { } +void vga_set_cursor_on_hardware( vga_t *vga ) +{ + uint16_t hw_cursor_pos = vga->cursor_x + vga->cursor_y * vga->res_x; + + port8_write( &vga->crtc_index_port, 15 ); + port8_write( &vga->crtc_index_port, hw_cursor_pos & 0xff ); + port8_write( &vga->crtc_index_port, 14 ); + port8_write( &vga->crtc_index_port, hw_cursor_pos >> 8 ); +} + int vga_get_cursor_x( vga_t *vga ) { return vga->cursor_x; @@ -142,6 +160,16 @@ void vga_put_string( vga_t *vga, const char *s ) } } +void vga_put_hex( vga_t *vga, const uint32_t v ) +{ + char buf[9]; + + strlcpy( buf, "0x", 9 ); + vga_put_string( vga, (const char *)buf ); + itoa( v, (char *)buf, 16 ); + vga_put_string( vga, (const char *)buf ); +} + void vga_put_newline( vga_t *vga ) { vga->cursor_x = 0; |