Make parseArgs not expect a leading space
This commit is contained in:
parent
f8bd8eeaaf
commit
21c677a950
@ -27,6 +27,8 @@ zasmMain:
|
|||||||
ld de, .argspecs
|
ld de, .argspecs
|
||||||
ld ix, ZASM_RAMSTART
|
ld ix, ZASM_RAMSTART
|
||||||
call parseArgs
|
call parseArgs
|
||||||
|
ld hl, 0
|
||||||
|
ld de, 0
|
||||||
ld a, SHELL_ERR_BAD_ARGS
|
ld a, SHELL_ERR_BAD_ARGS
|
||||||
ret nz
|
ret nz
|
||||||
|
|
||||||
@ -35,7 +37,6 @@ zasmMain:
|
|||||||
ld a, (ZASM_RAMSTART) ; blkdev in ID
|
ld a, (ZASM_RAMSTART) ; blkdev in ID
|
||||||
ld de, IO_IN_GETC
|
ld de, IO_IN_GETC
|
||||||
call blkSel
|
call blkSel
|
||||||
inc hl
|
|
||||||
ld a, (ZASM_RAMSTART+1) ; blkdev out ID
|
ld a, (ZASM_RAMSTART+1) ; blkdev out ID
|
||||||
ld de, IO_OUT_GETC
|
ld de, IO_OUT_GETC
|
||||||
call blkSel
|
call blkSel
|
||||||
|
@ -69,7 +69,6 @@ parseHexPair:
|
|||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; TODO: make parseArgs not expect a leading space.
|
|
||||||
; Parse arguments at (HL) with specifiers at (DE) into (IX).
|
; Parse arguments at (HL) with specifiers at (DE) into (IX).
|
||||||
;
|
;
|
||||||
; Args specifiers are a series of flag for each arg:
|
; Args specifiers are a series of flag for each arg:
|
||||||
@ -94,7 +93,6 @@ parseArgs:
|
|||||||
push ix
|
push ix
|
||||||
|
|
||||||
ld b, PARSE_ARG_MAXCOUNT
|
ld b, PARSE_ARG_MAXCOUNT
|
||||||
xor c
|
|
||||||
.loop:
|
.loop:
|
||||||
; init the arg value to a default 0
|
; init the arg value to a default 0
|
||||||
xor a
|
xor a
|
||||||
@ -105,22 +103,12 @@ parseArgs:
|
|||||||
or a ; cp 0
|
or a ; cp 0
|
||||||
jr z, .endofargs
|
jr z, .endofargs
|
||||||
|
|
||||||
; do we have a proper space char?
|
|
||||||
cp ' '
|
|
||||||
jr z, .hasspace ; We're fine
|
|
||||||
|
|
||||||
; is our previous arg a multibyte? (argspec still in C)
|
|
||||||
bit 1, c
|
|
||||||
jr z, .error ; bit not set? error
|
|
||||||
dec hl ; offset the "inc hl" below
|
|
||||||
|
|
||||||
.hasspace:
|
|
||||||
; Get the specs
|
; Get the specs
|
||||||
ld a, (de)
|
ld a, (de)
|
||||||
bit 0, a ; do we have an arg?
|
bit 0, a ; do we have an arg?
|
||||||
jr z, .error ; not set? then we have too many args
|
jr z, .error ; not set? then we have too many args
|
||||||
ld c, a ; save the specs for the next loop
|
|
||||||
inc hl ; (hl) points to a space, go next
|
ld c, a ; save the specs for multibyte check later
|
||||||
bit 3, a ; is our arg a string?
|
bit 3, a ; is our arg a string?
|
||||||
jr z, .notAString
|
jr z, .notAString
|
||||||
; our arg is a string. Let's place HL in our next two bytes and call
|
; our arg is a string. Let's place HL in our next two bytes and call
|
||||||
@ -128,9 +116,11 @@ parseArgs:
|
|||||||
ld (ix), l
|
ld (ix), l
|
||||||
ld (ix+1), h
|
ld (ix+1), h
|
||||||
jr .success ; directly to success: skip endofargs checks
|
jr .success ; directly to success: skip endofargs checks
|
||||||
|
|
||||||
.notAString:
|
.notAString:
|
||||||
call parseHexPair
|
call parseHexPair
|
||||||
jr c, .error
|
jr c, .error
|
||||||
|
|
||||||
; we have a good arg and we need to write A in (IX).
|
; we have a good arg and we need to write A in (IX).
|
||||||
ld (ix), a
|
ld (ix), a
|
||||||
|
|
||||||
@ -138,10 +128,23 @@ parseArgs:
|
|||||||
inc de
|
inc de
|
||||||
inc ix
|
inc ix
|
||||||
inc hl ; get to following char (generally a space)
|
inc hl ; get to following char (generally a space)
|
||||||
|
|
||||||
|
; Our arg is parsed, our pointers are increased. Normally, HL should
|
||||||
|
; point to a space *unless* our argspec indicates a multibyte arg.
|
||||||
|
bit 1, c
|
||||||
|
jr nz, .nospacecheck ; bit set? no space check
|
||||||
|
; do we have a proper space char (or null char)?
|
||||||
|
ld a, (hl)
|
||||||
|
or a
|
||||||
|
jr z, .endofargs
|
||||||
|
cp ' '
|
||||||
|
jr nz, .error
|
||||||
|
inc hl
|
||||||
|
.nospacecheck:
|
||||||
djnz .loop
|
djnz .loop
|
||||||
; If we get here, it means that our next char *has* to be a null char
|
; If we get here, it means that our next char *has* to be a null char
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
cp 0
|
or a ; cp 0
|
||||||
jr z, .success ; zero? great!
|
jr z, .success ; zero? great!
|
||||||
jr .error
|
jr .error
|
||||||
|
|
||||||
@ -149,12 +152,11 @@ parseArgs:
|
|||||||
; We encountered our null char. Let's verify that we either have no
|
; We encountered our null char. Let's verify that we either have no
|
||||||
; more args or that they are optional
|
; more args or that they are optional
|
||||||
ld a, (de)
|
ld a, (de)
|
||||||
cp 0
|
or a
|
||||||
jr z, .success ; no arg? success
|
jr z, .success ; no arg? success
|
||||||
bit 2, a
|
bit 2, a
|
||||||
jr nz, .success ; if set, arg is optional. success
|
jr z, .error ; if unset, arg is not optional. error
|
||||||
jr .error
|
; success
|
||||||
|
|
||||||
.success:
|
.success:
|
||||||
xor a
|
xor a
|
||||||
jr .end
|
jr .end
|
||||||
|
@ -168,7 +168,11 @@ shellParse:
|
|||||||
; advance the HL pointer to the beginning of the args.
|
; advance the HL pointer to the beginning of the args.
|
||||||
ld a, ' '
|
ld a, ' '
|
||||||
call findchar
|
call findchar
|
||||||
|
or a ; end of string? don't increase HL
|
||||||
|
jr z, .noargs
|
||||||
|
inc hl ; char after space
|
||||||
|
|
||||||
|
.noargs:
|
||||||
; 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
|
||||||
|
@ -21,3 +21,4 @@
|
|||||||
.equ fsSeek 0x30
|
.equ fsSeek 0x30
|
||||||
.equ fsTell 0x33
|
.equ fsTell 0x33
|
||||||
.equ cpHLDE 0x36
|
.equ cpHLDE 0x36
|
||||||
|
.equ parseArgs 0x39
|
||||||
|
@ -58,7 +58,7 @@ init:
|
|||||||
halt
|
halt
|
||||||
|
|
||||||
.zasmArgs:
|
.zasmArgs:
|
||||||
.db " 0 1", 0
|
.db "0 1", 0
|
||||||
|
|
||||||
; *** I/O ***
|
; *** I/O ***
|
||||||
emulGetC:
|
emulGetC:
|
||||||
|
Loading…
Reference in New Issue
Block a user