shell: allow cmds to be shorter than 4 chars

This commit is contained in:
Virgil Dupras 2019-07-21 15:57:55 -04:00
parent 70a42e8c4d
commit 77d805ea0f
3 changed files with 26 additions and 28 deletions

View File

@ -19,30 +19,18 @@
.equ PGM_RAMEND PGM_HANDLE+FS_HANDLE_SIZE
; Routine suitable to plug into SHELL_CMDHOOK. HL points to the full cmdline.
; We can mutate it because the shell doesn't do anything with it afterwards.
; which has been processed to replace the first ' ' with a null char.
pgmShellHook:
call fsIsOn
jr nz, .noFile
; first first space and replace it with zero so that we have something
; suitable for fsFindFN.
push hl ; remember beginning
ld a, ' '
call findchar
jr nz, .noarg ; if we have no arg, we want DE to point to the
; null char. Also, we have no replacement to
; make
; replace space with nullchar
xor a
ld (hl), a
inc hl ; make HL point to the beginning of args
.noarg:
ex de, hl ; DE now points to the beginning of args or to \0 if
; no args
pop hl ; HL points to cmdname, properly null-terminated
; (HL) is suitable for a direct fsFindFN call
call fsFindFN
jr nz, .noFile
; We have a file! Load it and run it.
ex de, hl ; but first, make HL point to unparsed args.
; We have a file! Advance HL to args
xor a
call findchar
inc hl ; beginning of args
; Alright, ready to run!
jp pgmRun
.noFile:
ld a, SHELL_ERR_IO_ERROR

View File

@ -100,9 +100,23 @@ shellParse:
push hl
push ix
; Before looking for a suitable command, let's make the cmd line more
; usable by replacing the first ' ' with a null char. This way, cmp is
; easy to make.
push hl ; --> lvl 1
ld a, ' '
call findchar
jr z, .hasArgs
; no arg, (HL) is zero to facilitate processing later, add a second
; null next to that one to indicate unambiguously that we have no args.
inc hl
.hasArgs:
xor a
ld (hl), a
pop hl ; <-- lvl 1, beginning of cmd
ld de, shellCmdTbl
ld a, SHELL_CMD_COUNT
ld b, a
ld b, SHELL_CMD_COUNT
.loop:
push de ; we need to keep that table entry around...
@ -131,13 +145,9 @@ shellParse:
call intoDE ; Jump from the table entry to the cmd addr.
; advance the HL pointer to the beginning of the args.
ld a, ' '
xor a
call findchar
or a ; end of string? don't increase HL
jr z, .noargs
inc hl ; char after space
.noargs:
inc hl ; beginning of args
; Now, let's have DE point to the argspecs
ld a, 4
call addDE

View File

@ -123,7 +123,7 @@ f1PutC:
jp fsPutC
edCmd:
.db "eded", 0b1001, 0, 0
.db "ed", 0, 0, 0b1001, 0, 0
push hl \ pop ix
ld l, (ix)
ld h, (ix+1)