1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-26 15:48:05 +11:00

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. ; in your glue file.
; *** CONSTS *** ; *** CONSTS ***
.equ ASCII_BS 0x08
.equ ASCII_CR 0x0d .equ ASCII_CR 0x0d
.equ ASCII_LF 0x0a .equ ASCII_LF 0x0a
.equ ASCII_DEL 0x7f
; *** DATA *** ; *** DATA ***
; Useful data to point to, when a pointer is needed. ; Useful data to point to, when a pointer is needed.

View File

@ -85,6 +85,8 @@ shellLoop:
jr z, .do ; char is CR? do! jr z, .do ; char is CR? do!
cp ASCII_LF cp ASCII_LF
jr z, .do ; char is LF? do! 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 ; Echo the received character right away so that we see what we type
call stdioPutC call stdioPutC
@ -127,6 +129,28 @@ shellLoop:
.prompt: .prompt:
.db "> ", 0 .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 ; Parse command (null terminated) at HL and calls it
shellParse: shellParse:
push af push af