From 605c631dc0db146cafa8a976f40547763c92bea4 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 14 Jun 2019 22:14:09 -0400 Subject: [PATCH] shell: add support for backspace It doesn't sound like much, but that backspace key is often useful... --- kernel/core.asm | 2 ++ kernel/shell.asm | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/kernel/core.asm b/kernel/core.asm index e3e257b..80ca9af 100644 --- a/kernel/core.asm +++ b/kernel/core.asm @@ -4,8 +4,10 @@ ; in your glue file. ; *** CONSTS *** +.equ ASCII_BS 0x08 .equ ASCII_CR 0x0d .equ ASCII_LF 0x0a +.equ ASCII_DEL 0x7f ; *** DATA *** ; Useful data to point to, when a pointer is needed. diff --git a/kernel/shell.asm b/kernel/shell.asm index 4f8d4d5..4505449 100644 --- a/kernel/shell.asm +++ b/kernel/shell.asm @@ -85,6 +85,8 @@ shellLoop: jr z, .do ; char is CR? do! cp ASCII_LF jr z, .do ; char is LF? do! + cp ASCII_DEL + jr z, .delchr ; Echo the received character right away so that we see what we type call stdioPutC @@ -127,6 +129,28 @@ shellLoop: .prompt: .db "> ", 0 +.delchr: + ld hl, SHELL_BUF + ld a, (hl) + or a ; cp 0 + jr z, shellLoop ; buffer empty? nothing to do + ; buffer not empty, let's delete + xor a ; look for null + call findchar ; HL points to end of buf + dec hl ; the char before it + xor a + ld (hl), a ; set to zero + ; Char deleted in buffer, now send BS + space + BS for the terminal + ; to clear its previous char + ld a, ASCII_BS + call stdioPutC + ld a, ' ' + call stdioPutC + ld a, ASCII_BS + call stdioPutC + jr shellLoop + + ; Parse command (null terminated) at HL and calls it shellParse: push af