[SeaBIOS] [PATCH 2/3] sercon: Add basic keyboard input support

Kevin O'Connor kevin at koconnor.net
Thu Oct 27 02:34:56 CEST 2016


Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 vgasrc/sercon.c  | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 vgasrc/vgainit.c |  3 ++-
 vgasrc/vgautil.h |  1 +
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/vgasrc/sercon.c b/vgasrc/sercon.c
index 35b60a5..11df1dc 100644
--- a/vgasrc/sercon.c
+++ b/vgasrc/sercon.c
@@ -99,6 +99,53 @@ sercon_clear_screen(void)
 
 
 /****************************************************************
+ * Serial port input
+ ****************************************************************/
+
+static u8
+enqueue_key(u16 keycode)
+{
+    u16 buffer_start = GET_BDA(kbd_buf_start_offset);
+    u16 buffer_end   = GET_BDA(kbd_buf_end_offset);
+
+    u16 buffer_head = GET_BDA(kbd_buf_head);
+    u16 buffer_tail = GET_BDA(kbd_buf_tail);
+
+    u16 temp_tail = buffer_tail;
+    buffer_tail += 2;
+    if (buffer_tail >= buffer_end)
+        buffer_tail = buffer_start;
+
+    if (buffer_tail == buffer_head)
+        return 0;
+
+    SET_FARVAR(SEG_BDA, *(u16*)(temp_tail+0), keycode);
+    SET_BDA(kbd_buf_tail, buffer_tail);
+    return 1;
+}
+
+void
+sercon_check_event(void)
+{
+    if (!CONFIG_VGA_SERCON)
+        return;
+
+    // XXX - move cursor if current position doesn't match last sent location
+
+    if (!(inb(SERCON_PORT + SEROFF_LSR) & 0x01))
+        // No input data
+        return;
+
+    u8 in = inb(SERCON_PORT + SEROFF_DATA);
+
+    // XXX - check for multi-byte input sequence
+
+    u16 keycode = in; // XXX - lookup real keycode
+    enqueue_key(keycode);
+}
+
+
+/****************************************************************
  * Interface functions
  ****************************************************************/
 
diff --git a/vgasrc/vgainit.c b/vgasrc/vgainit.c
index c6c8149..ec3996f 100644
--- a/vgasrc/vgainit.c
+++ b/vgasrc/vgainit.c
@@ -93,12 +93,13 @@ void VISIBLE16
 handle_timer_hook(void)
 {
     swcursor_check_event();
+    sercon_check_event();
 }
 
 static void
 hook_timer_irq(void)
 {
-    if (!CONFIG_VGA_EMULATE_TEXT)
+    if (!CONFIG_VGA_EMULATE_TEXT && !CONFIG_VGA_SERCON)
         return;
     extern void entry_timer_hook(void);
     extern void entry_timer_hook_extrastack(void);
diff --git a/vgasrc/vgautil.h b/vgasrc/vgautil.h
index 8436e60..7f42920 100644
--- a/vgasrc/vgautil.h
+++ b/vgasrc/vgautil.h
@@ -35,6 +35,7 @@ void clext_1012(struct bregs *regs);
 int clext_setup(void);
 
 // sercon.c
+void sercon_check_event(void);
 void sercon_write_pixel(u8 color, u16 x, u16 y);
 u8 sercon_read_pixel(u16 x, u16 y);
 struct cursorpos;
-- 
2.5.5




More information about the SeaBIOS mailing list