summaryrefslogtreecommitdiff
path: root/src/vga.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vga.c')
-rw-r--r--src/vga.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/src/vga.c b/src/vga.c
index 767d45f..0133ddf 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -1,7 +1,10 @@
#include "vga.h"
+#include <stdbool.h>
+
#include "string.h"
+static bool params_ok( vga_t *vga, const int x, const int y );
static int calculate_offset( vga_t *vga );
static uint8_t calculate_color_cell( vga_t *vga );
@@ -32,6 +35,9 @@ void vga_clear_screen( vga_t *vga )
void vga_set_cursor( vga_t *vga, const int x, const int y )
{
+ // TODO: PANIC? OUT OF BOUND ACCESS
+ if( !params_ok( vga, x, y ) ) return;
+
vga->cursor_x = x;
vga->cursor_y = y;
}
@@ -62,16 +68,49 @@ static uint8_t calculate_color_cell( vga_t *vga )
return cell;
}
-void vga_put_char( vga_t *vga, const int x, const int y, const uint8_t c )
+static bool params_ok( vga_t *vga, const int x, const int y )
+{
+ if( x > vga->res_x || y > vga->res_y ) return false;
+
+ return true;
+}
+
+void vga_put_char_at( vga_t *vga, const int x, const int y, const char c )
{
- // TODO: PANIC? OUT OF BOUND ACCESS
- if( x > vga->res_x || y > vga->res_y ) return;
-
vga_set_cursor( vga, x, y );
-
+ vga_put_char( vga, c );
+}
+
+
+void vga_put_string_at( vga_t *vga, const int x, const int y, const char *s )
+{
+ vga_set_cursor( vga, x, y );
+ vga_put_string( vga, s );
+}
+
+void vga_put_char( vga_t *vga, const char c )
+{
int offset = calculate_offset( vga );
volatile uint8_t *VIDEO_MEMORY = (uint8_t *)0xb8000;
- *(VIDEO_MEMORY+offset) = c;
- *(VIDEO_MEMORY+offset+1) = calculate_color_cell( vga );
+ *(VIDEO_MEMORY+offset) = (uint8_t)c;
+ *(VIDEO_MEMORY+offset+1) = calculate_color_cell( vga );
+
+ vga->cursor_x++;
+ if( vga->cursor_x >= vga->res_x ) {
+ vga->cursor_x = 0;
+ vga->cursor_y++;
+ if( vga->cursor_y >= vga->res_y ) {
+ // TODO: implement scrolling
+ vga->res_y = 0;
+ }
+ }
+}
+
+void vga_put_string( vga_t *vga, const char *s )
+{
+ for( size_t i = 0; i < strlen( s ); i++ ) {
+ vga_put_char( vga, s[i] );
+ }
}
+