From a97e70ee994f72b9eb38de965ebc9f3c2cd3d1a7 Mon Sep 17 00:00:00 2001 From: Tibo Date: Thu, 7 Oct 2021 18:03:32 +0200 Subject: [PATCH] handle commands coming from virtual keyboard --- messages.asm | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/messages.asm b/messages.asm index 8ed880c..a994642 100644 --- a/messages.asm +++ b/messages.asm @@ -63,9 +63,14 @@ int 0x10 .loop: ;; read a character, ASCII in al - mov ah, 0x00 ; Read character + mov ah, 0x0 ; Read character int 0x16 + ;; a null character will be sent before every command from the virtual keyboard + ;; so if a null is detected go to the virtual_kbd_loop instead + cmp al, 0x0 ; null + je .virtual_kbd_loop_init + mov ah, 0x1 mov dx, 0x0 int 0x14 @@ -81,20 +86,43 @@ int 0x10 jmp nonewline ; all other characters +.nl_reset_state: + mov byte[is_from_virtual_kbd], 0x0 ; reset state variable .nl: call newline jmp .loop +.virtual_kbd_loop_init: + mov byte[is_from_virtual_kbd], 0x1 ; update state variable +.virtual_kbd_loop: + ;; read a character, ASCII in al + mov ah, 0x0 + int 0x16 + + cmp al, 0x08 ; backspace + je change_color_mode + + cmp al, 0x1b ; esc + je beep + + ;; an enter character signifies the end of a command + ;; so a newline should get printed and then the program should resume + ;; from the main .loop again + cmp al, 0xD ; enter + je .nl_reset_state + + jmp nonewline ; all other characters + ;; Update the color_mode variable with a byte from the keyboard ;; ;; CLOBBERS ;; - ax ;; - bl change_color_mode: - call readbyte ; get byte from keyboard (in al) + call readbyte ; get byte from keyboard (in al) mov [color_mode], al ; store byte in color_mode variable - jmp start.loop + jmp compare_virtual_and_jump ;; Simulates going to a new line ;; @@ -181,7 +209,7 @@ beep: and al, 11111100b ; Clear bits 1 and 0 (disable speaker, clear channel select) out 61h, al ; Send new value - jmp start.loop + jmp compare_virtual_and_jump ;; Handles all other characters by writing them to the screen ;; @@ -212,7 +240,7 @@ nonewline: .eol: call newline - jmp start.loop + jmp compare_virtual_and_jump .noeol: ;; Move cursor forward @@ -220,6 +248,15 @@ nonewline: mov ah, 0x02 ; set cursor position, dh (row) already set, dl (col) updated on prev line int 0x10 + jmp compare_virtual_and_jump + +;; Compares the is_from_virtual_kbd state variable to 1 to check if the command +;; came from the virtual keyboard +;; if it did, jump to the virtual keyboard loop +;; if it didn't, jump to the main loop +compare_virtual_and_jump: + cmp byte[is_from_virtual_kbd], 0x1 + je start.virtual_kbd_loop jmp start.loop ;; Reads two characters from the keyboard buffer and converts them into a single byte @@ -273,6 +310,8 @@ read_duration: ;; Variable to store color mode information for writing to the screen color_mode: db 0x02 +;; State variable for detecting whether keystrokes are virtual or real +is_from_virtual_kbd: db 0x0 ;; Magic number must be in the last 2 bytes of the sector so ;; fill the binary with zeroes until it is 510 bytes in size