shell: add support for backspace

It doesn't sound like much, but that backspace key is often useful...
This commit is contained in:
Virgil Dupras 2019-06-14 22:14:09 -04:00
parent e7c07cdd9a
commit 605c631dc0
2 changed files with 26 additions and 0 deletions

View File

@ -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.

View File

@ -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