mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 12:28:06 +11:00
shell: place cmd metadata next to the routine
This will facilitate the inclusion of extra commands other parts might want to define.
This commit is contained in:
parent
f571664853
commit
4600b5299c
@ -18,6 +18,20 @@ addDE:
|
|||||||
ld e, a
|
ld e, a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; copy (DE) into DE, little endian style (addresses in z80 are always have
|
||||||
|
; their LSB before their MSB)
|
||||||
|
intoDE:
|
||||||
|
push af
|
||||||
|
ld a, (de)
|
||||||
|
inc de
|
||||||
|
ex af, af'
|
||||||
|
ld a, (de)
|
||||||
|
ld d, a
|
||||||
|
ex af, af'
|
||||||
|
ld e, a
|
||||||
|
pop af
|
||||||
|
ret
|
||||||
|
|
||||||
; add the value of A into HL
|
; add the value of A into HL
|
||||||
addHL:
|
addHL:
|
||||||
add a, l
|
add a, l
|
||||||
|
@ -137,11 +137,13 @@ shellParse:
|
|||||||
ld b, a
|
ld b, a
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
|
push de ; we need to keep that table entry around...
|
||||||
|
call intoDE ; Jump from the table entry to the cmd addr.
|
||||||
ld a, 4 ; 4 chars to compare
|
ld a, 4 ; 4 chars to compare
|
||||||
call strncmp
|
call strncmp
|
||||||
|
pop de
|
||||||
jr z, .found
|
jr z, .found
|
||||||
ld a, 7 + SHELL_CMD_ARGS_MAXSIZE
|
inc de
|
||||||
call addDE
|
|
||||||
djnz .loop
|
djnz .loop
|
||||||
|
|
||||||
; exhausted loop? not found
|
; exhausted loop? not found
|
||||||
@ -150,12 +152,18 @@ shellParse:
|
|||||||
jr .end
|
jr .end
|
||||||
|
|
||||||
.found:
|
.found:
|
||||||
; we found our command. Now, let's parse our args.
|
; we found our command. DE points to its table entry. Now, let's parse
|
||||||
|
; our args.
|
||||||
|
call intoDE ; Jump from the table entry to the cmd addr.
|
||||||
|
|
||||||
|
; advance the HL pointer to the beginning of the args.
|
||||||
ld a, 4
|
ld a, 4
|
||||||
call addHL
|
call addHL
|
||||||
|
|
||||||
; Now, let's have DE point to the argspecs
|
; Now, let's have DE point to the argspecs
|
||||||
ld a, 4
|
ld a, 4
|
||||||
call addDE
|
call addDE
|
||||||
|
|
||||||
; We're ready to parse args
|
; We're ready to parse args
|
||||||
call shellParseArgs
|
call shellParseArgs
|
||||||
cp 0
|
cp 0
|
||||||
@ -295,12 +303,22 @@ shellParseArgs:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
; *** COMMANDS ***
|
; *** COMMANDS ***
|
||||||
|
; A command is a 4 char names, followed by a SHELL_CMD_ARGS_MAXSIZE bytes of
|
||||||
|
; argument specs, followed by the routine. Then, a simple table of addresses
|
||||||
|
; is compiled in a block and this is what is iterated upon when we want all
|
||||||
|
; available commands.
|
||||||
|
;
|
||||||
|
; Format: 4 bytes name followed by SHELL_CMD_ARGS_MAXSIZE bytes specifiers,
|
||||||
|
; followed by 3 bytes jump. fill names with zeroes
|
||||||
|
;
|
||||||
; 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.
|
||||||
|
|
||||||
|
|
||||||
; Set memory pointer to the specified address (word).
|
; Set memory pointer to the specified address (word).
|
||||||
; Example: seek 01fe
|
; Example: seek 01fe
|
||||||
|
shellSeekCmd:
|
||||||
|
.db "seek", 0b011, 0b001, 0
|
||||||
shellSeek:
|
shellSeek:
|
||||||
push af
|
push af
|
||||||
push de
|
push de
|
||||||
@ -336,6 +354,8 @@ shellSeek:
|
|||||||
; optional numerical byte arg is supplied, this number of bytes will be printed
|
; optional numerical byte arg is supplied, this number of bytes will be printed
|
||||||
;
|
;
|
||||||
; Example: peek 2 (will print 2 bytes)
|
; Example: peek 2 (will print 2 bytes)
|
||||||
|
shellPeekCmd:
|
||||||
|
.db "peek", 0b101, 0, 0
|
||||||
shellPeek:
|
shellPeek:
|
||||||
push af
|
push af
|
||||||
push bc
|
push bc
|
||||||
@ -374,6 +394,8 @@ shellPeek:
|
|||||||
; Control is returned to the shell only after all bytes are read.
|
; Control is returned to the shell only after all bytes are read.
|
||||||
;
|
;
|
||||||
; Example: load 42
|
; Example: load 42
|
||||||
|
shellLoadCmd:
|
||||||
|
.db "load", 0b001, 0, 0
|
||||||
shellLoad:
|
shellLoad:
|
||||||
push af
|
push af
|
||||||
push bc
|
push bc
|
||||||
@ -397,6 +419,8 @@ shellLoad:
|
|||||||
; parameters, A and HL. The first one is a byte, the second, a word. These are
|
; parameters, A and HL. The first one is a byte, the second, a word. These are
|
||||||
; the values that A and HL are going to be set to just before calling.
|
; the values that A and HL are going to be set to just before calling.
|
||||||
; Example: run 42 cafe
|
; Example: run 42 cafe
|
||||||
|
shellCallCmd:
|
||||||
|
.db "call", 0b101, 0b111, 0b001
|
||||||
shellCall:
|
shellCall:
|
||||||
push af
|
push af
|
||||||
push hl
|
push hl
|
||||||
@ -431,15 +455,6 @@ shellCall:
|
|||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Format: 4 bytes name followed by SHELL_CMD_ARGS_MAXSIZE bytes specifiers,
|
|
||||||
; followed by 3 bytes jump. fill names with zeroes
|
|
||||||
shellCmdTbl:
|
shellCmdTbl:
|
||||||
.db "seek", 0b011, 0b001, 0
|
.dw shellSeekCmd, shellPeekCmd, shellLoadCmd, shellCallCmd
|
||||||
jp shellSeek
|
|
||||||
.db "peek", 0b101, 0, 0
|
|
||||||
jp shellPeek
|
|
||||||
.db "load", 0b001, 0, 0
|
|
||||||
jp shellLoad
|
|
||||||
.db "call", 0b101, 0b111, 0b001
|
|
||||||
jp shellCall
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user