shell: implement load command

This commit is contained in:
Virgil Dupras 2019-04-14 14:53:16 -04:00
parent 461c09f1e5
commit 942ff37bf8

View File

@ -21,7 +21,7 @@
; *** CONSTS *** ; *** CONSTS ***
; number of entries in shellCmdTbl ; number of entries in shellCmdTbl
SHELL_CMD_COUNT .equ 2 SHELL_CMD_COUNT .equ 3
; The command that was type isn't known to the shell ; The command that was type isn't known to the shell
SHELL_ERR_UNKNOWN_CMD .equ 0x01 SHELL_ERR_UNKNOWN_CMD .equ 0x01
@ -53,14 +53,13 @@ shellInit:
ld (SHELL_MEM_PTR), a ld (SHELL_MEM_PTR), a
ld (SHELL_BUF), a ld (SHELL_BUF), a
; print prompt ; print welcome
ld hl, .prompt ld hl, .welcome
call printstr call printstr
call printcrlf
ret ret
.prompt: .welcome:
.db "Collapse OS", 0 .db "Collapse OS", ASCII_CR, ASCII_LF, "> ", 0
shellLoop: shellLoop:
; First, let's wait until something is typed. ; First, let's wait until something is typed.
@ -93,14 +92,20 @@ shellLoop:
jr shellLoop jr shellLoop
.do: .do:
call printcrlf
ld hl, SHELL_BUF ld hl, SHELL_BUF
call shellParse call shellParse
; empty our buffer by writing a zero to its first char ; empty our buffer by writing a zero to its first char
xor a xor a
ld (hl), a ld (hl), a
ld hl, .prompt
call printstr
jr shellLoop jr shellLoop
.prompt:
.db "> ", 0
printcrlf: printcrlf:
ld a, ASCII_CR ld a, ASCII_CR
SHELL_PUTC SHELL_PUTC
@ -123,7 +128,7 @@ shellParse:
ld a, 4 ; 4 chars to compare ld a, 4 ; 4 chars to compare
call strncmp call strncmp
jr z, .found jr z, .found
ld a, 6 ld a, 7
call addDE call addDE
djnz .loop djnz .loop
@ -278,10 +283,48 @@ shellPeek:
pop af pop af
ret ret
; Format: 4 bytes name followed by 2 bytes jump. fill names with zeroes ; Load the specified number of bytes (max 0xff) from IO and write them in the
; current memory pointer (which doesn't change). For now, we can only load from
; SHELL_GETC, but a method of selecting IO sources is coming, making this
; command much more useful.
; Control is returned to the shell only after all bytes are read.
;
; Example: load 42
shellLoad:
push af
push bc
push hl
ld a, (de)
call parseHex
jr c, .error
jr .success
.error:
ld a, SHELL_ERR_BAD_ARGS
call shellPrintErr
jr .end
.success:
ld b, a
ld hl, (SHELL_MEM_PTR)
.loop: SHELL_GETC
ld (hl), a
inc hl
djnz .loop
.end:
pop hl
pop bc
pop af
ret
; Format: 4 bytes name followed by 3 bytes jump. fill names with zeroes
shellCmdTbl: shellCmdTbl:
.db "seek" .db "seek"
jr shellSeek jp shellSeek
.db "peek" .db "peek"
jr shellPeek jp shellPeek
.db "load"
jp shellLoad