term: Fix bug introduced when moving from int to size_t for coordinates. Fixes #110
diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c
index 075a5dda..d48c6ea9 100644
--- a/stage23/drivers/vga_textmode.s2.c
+++ b/stage23/drivers/vga_textmode.s2.c
@@ -242,10 +242,18 @@ void text_move_character(size_t new_x, size_t new_y, size_t old_x, size_t old_y)
void text_set_cursor_pos(size_t x, size_t y) {
clear_cursor();
if (x >= VD_COLS / 2) {
- x = VD_COLS / 2 - 1;
+ if ((int)x < 0) {
+ x = 0;
+ } else {
+ x = VD_COLS / 2 - 1;
+ }
}
if (y >= VD_ROWS) {
- y = VD_ROWS - 1;
+ if ((int)y < 0) {
+ y = 0;
+ } else {
+ y = VD_ROWS - 1;
+ }
}
cursor_offset = y * VD_COLS + x * 2;
draw_cursor();
diff --git a/stage23/lib/gterm.c b/stage23/lib/gterm.c
index 5c3804f1..ca2310b0 100644
--- a/stage23/lib/gterm.c
+++ b/stage23/lib/gterm.c
@@ -416,10 +416,18 @@ bool gterm_disable_cursor(void) {
void gterm_set_cursor_pos(size_t x, size_t y) {
clear_cursor();
if (x >= cols) {
- x = cols - 1;
+ if ((int)x < 0) {
+ x = 0;
+ } else {
+ x = cols - 1;
+ }
}
if (y >= rows) {
- y = rows - 1;
+ if ((int)y < 0) {
+ y = 0;
+ } else {
+ y = rows - 1;
+ }
}
cursor_x = x;
cursor_y = y;
