From 245acc3c4c34f12a22c0ec6585487862efd6c1f4 Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Wed, 6 Jun 2007 12:34:52 +0000 Subject: [PATCH] Manage VT100 get_cursor_position command --- second/keyboard.c | 5 +++++ second/keyboard.h | 1 + second/vga.c | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/second/keyboard.c b/second/keyboard.c index 3ab992b..2a9aa3f 100644 --- a/second/keyboard.c +++ b/second/keyboard.c @@ -364,3 +364,8 @@ int keyboard_getchar() return buffer_get(); } + +void keyboard_inject(char *s) +{ + buffer_putstring(s); +} diff --git a/second/keyboard.h b/second/keyboard.h index 9b3c211..35a9245 100644 --- a/second/keyboard.h +++ b/second/keyboard.h @@ -126,3 +126,4 @@ extern void keyboard_get_scancode(int *modifiers, int *code); extern int keyboard_convert_scancode(int modifiers, int scancode); extern int keyboard_keypressed(void); extern int keyboard_getchar(); +extern void keyboard_inject(char *s); diff --git a/second/vga.c b/second/vga.c index 6c02350..53906b6 100644 --- a/second/vga.c +++ b/second/vga.c @@ -14,6 +14,7 @@ #include "misc.h" #include "vga.h" +#include "keyboard.h" QDGlobals qd; @@ -676,13 +677,21 @@ vga_put(char c) case 'H': /* set cursor position */ tmp_y = strtol(vga.escape_stack + 1, &end, 10); + if (tmp_y > vga.siz_h) + tmp_y = vga.siz_h; + else if (tmp_y < 1) + tmp_y = 1; if (*end == ';') { tmp_x = strtol(end + 1, &end, 10); + if (tmp_x > vga.siz_w) + tmp_x = vga.siz_w; + else if (tmp_x < 1) + tmp_x = 1; if (*end == 'H') { - vga.pos_x = tmp_x; - vga.pos_y = tmp_y; + vga.pos_x = tmp_x - 1; + vga.pos_y = tmp_y - 1; goto exit_escape; } } @@ -703,6 +712,16 @@ vga_put(char c) } break; + case 'n': /* get cursor position */ + if(strcmp("[6n", vga.escape_stack) == 0) + { + char buf[16]; + + sprintf(buf, "\033[%ld;%ldR", vga.pos_y + 1, vga.pos_x + 1); + keyboard_inject(buf); + } + break; + default: goto exit; }