shell: add error codes to cmds
This commit is contained in:
parent
12c23f52e0
commit
c996da8ac8
@ -31,6 +31,7 @@ table describes those codes:
|
|||||||
|------|---------------------------|
|
|------|---------------------------|
|
||||||
| `01` | Unknown command |
|
| `01` | Unknown command |
|
||||||
| `02` | Badly formatted arguments |
|
| `02` | Badly formatted arguments |
|
||||||
|
| `03` | Out of bounds |
|
||||||
|
|
||||||
## seek
|
## seek
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
; BLOCKDEV_COUNT: The number of devices we manage.
|
; BLOCKDEV_COUNT: The number of devices we manage.
|
||||||
|
|
||||||
; *** CONSTS ***
|
; *** CONSTS ***
|
||||||
|
BLOCKDEV_ERR_OUT_OF_BOUNDS .equ 0x03
|
||||||
|
|
||||||
; *** VARIABLES ***
|
; *** VARIABLES ***
|
||||||
; A memory pointer to a device table. A device table is a list of addresses
|
; A memory pointer to a device table. A device table is a list of addresses
|
||||||
; pointing to GetC and PutC routines.
|
; pointing to GetC and PutC routines.
|
||||||
@ -73,14 +75,14 @@ blkSel:
|
|||||||
blkBselCmd:
|
blkBselCmd:
|
||||||
.db "bsel", 0b001, 0, 0
|
.db "bsel", 0b001, 0, 0
|
||||||
blkBsel:
|
blkBsel:
|
||||||
ret
|
|
||||||
push af
|
|
||||||
ld a, (hl) ; argument supplied
|
ld a, (hl) ; argument supplied
|
||||||
cp BLOCKDEV_COUNT
|
cp BLOCKDEV_COUNT
|
||||||
ret nz ; if selection >= device count, don't do anything
|
jr nc, .error ; if selection >= device count, error
|
||||||
; (will devise a unified cmd error system later)
|
|
||||||
call blkSel
|
call blkSel
|
||||||
pop af
|
xor a
|
||||||
|
ret
|
||||||
|
.error:
|
||||||
|
ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Reads one character from blockdev ID specified at A and returns its value
|
; Reads one character from blockdev ID specified at A and returns its value
|
||||||
|
@ -152,8 +152,7 @@ shellParse:
|
|||||||
|
|
||||||
; exhausted loop? not found
|
; exhausted loop? not found
|
||||||
ld a, SHELL_ERR_UNKNOWN_CMD
|
ld a, SHELL_ERR_UNKNOWN_CMD
|
||||||
call shellPrintErr
|
jr .error
|
||||||
jr .end
|
|
||||||
|
|
||||||
.found:
|
.found:
|
||||||
; we found our command. DE points to its table entry. Now, let's parse
|
; we found our command. DE points to its table entry. Now, let's parse
|
||||||
@ -182,10 +181,13 @@ shellParse:
|
|||||||
ld ixl, e
|
ld ixl, e
|
||||||
; Ready to roll!
|
; Ready to roll!
|
||||||
call callIX
|
call callIX
|
||||||
|
cp 0
|
||||||
|
jr nz, .error ; if A is non-zero, we have an error
|
||||||
jr .end
|
jr .end
|
||||||
|
|
||||||
.parseerror:
|
.parseerror:
|
||||||
ld a, SHELL_ERR_BAD_ARGS
|
ld a, SHELL_ERR_BAD_ARGS
|
||||||
|
.error:
|
||||||
call shellPrintErr
|
call shellPrintErr
|
||||||
.end:
|
.end:
|
||||||
pop ix
|
pop ix
|
||||||
@ -318,6 +320,9 @@ shellParseArgs:
|
|||||||
; When these commands are called, HL points to the first byte of the
|
; When these commands are called, HL points to the first byte of the
|
||||||
; parsed command args.
|
; parsed command args.
|
||||||
;
|
;
|
||||||
|
; If the command is a success, it should set A to zero. If the command results
|
||||||
|
; in an error, it should set an error code in A.
|
||||||
|
;
|
||||||
; Extra commands: Other parts might define new commands. You can add these
|
; Extra commands: Other parts might define new commands. You can add these
|
||||||
; commands to your shell. First, set SHELL_EXTRA_CMD_COUNT to
|
; commands to your shell. First, set SHELL_EXTRA_CMD_COUNT to
|
||||||
; the number of extra commands to add, then add a ".dw"
|
; the number of extra commands to add, then add a ".dw"
|
||||||
@ -329,7 +334,6 @@ shellParseArgs:
|
|||||||
shellSeekCmd:
|
shellSeekCmd:
|
||||||
.db "seek", 0b011, 0b001, 0
|
.db "seek", 0b011, 0b001, 0
|
||||||
shellSeek:
|
shellSeek:
|
||||||
push af
|
|
||||||
push de
|
push de
|
||||||
push hl
|
push hl
|
||||||
|
|
||||||
@ -355,7 +359,7 @@ shellSeek:
|
|||||||
|
|
||||||
pop hl
|
pop hl
|
||||||
pop de
|
pop de
|
||||||
pop af
|
xor a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
@ -366,7 +370,6 @@ shellSeek:
|
|||||||
shellPeekCmd:
|
shellPeekCmd:
|
||||||
.db "peek", 0b101, 0, 0
|
.db "peek", 0b101, 0, 0
|
||||||
shellPeek:
|
shellPeek:
|
||||||
push af
|
|
||||||
push bc
|
push bc
|
||||||
push de
|
push de
|
||||||
push hl
|
push hl
|
||||||
@ -393,7 +396,7 @@ shellPeek:
|
|||||||
pop hl
|
pop hl
|
||||||
pop de
|
pop de
|
||||||
pop bc
|
pop bc
|
||||||
pop af
|
xor a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Load the specified number of bytes (max 0xff) from IO and write them in the
|
; Load the specified number of bytes (max 0xff) from IO and write them in the
|
||||||
@ -406,7 +409,6 @@ shellPeek:
|
|||||||
shellLoadCmd:
|
shellLoadCmd:
|
||||||
.db "load", 0b001, 0, 0
|
.db "load", 0b001, 0, 0
|
||||||
shellLoad:
|
shellLoad:
|
||||||
push af
|
|
||||||
push bc
|
push bc
|
||||||
push hl
|
push hl
|
||||||
|
|
||||||
@ -421,7 +423,7 @@ shellLoad:
|
|||||||
.end:
|
.end:
|
||||||
pop hl
|
pop hl
|
||||||
pop bc
|
pop bc
|
||||||
pop af
|
xor a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Calls the routine where the memory pointer currently points. This can take two
|
; Calls the routine where the memory pointer currently points. This can take two
|
||||||
@ -431,7 +433,6 @@ shellLoad:
|
|||||||
shellCallCmd:
|
shellCallCmd:
|
||||||
.db "call", 0b101, 0b111, 0b001
|
.db "call", 0b101, 0b111, 0b001
|
||||||
shellCall:
|
shellCall:
|
||||||
push af
|
|
||||||
push hl
|
push hl
|
||||||
push ix
|
push ix
|
||||||
|
|
||||||
@ -461,7 +462,7 @@ shellCall:
|
|||||||
.end:
|
.end:
|
||||||
pop ix
|
pop ix
|
||||||
pop hl
|
pop hl
|
||||||
pop af
|
xor a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; This table is at the very end of the file on purpose. The idea is to be able
|
; This table is at the very end of the file on purpose. The idea is to be able
|
||||||
|
Loading…
Reference in New Issue
Block a user