mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 22:58:06 +11:00
lib/args: remove
This commit is contained in:
parent
5f2615a134
commit
2503bdfced
@ -1,111 +0,0 @@
|
|||||||
; *** Requirements ***
|
|
||||||
; lib/parse
|
|
||||||
;
|
|
||||||
; *** Consts ***
|
|
||||||
; maximum number of bytes to receive as args in all commands. Determines the
|
|
||||||
; size of the args variable.
|
|
||||||
.equ PARSE_ARG_MAXCOUNT 3
|
|
||||||
|
|
||||||
; *** Code ***
|
|
||||||
|
|
||||||
; Parse arguments at (HL) with specifiers at (DE) into (IX).
|
|
||||||
;
|
|
||||||
; Args specifiers are a series of flag for each arg:
|
|
||||||
; Bit 0 - arg present: if unset, we stop parsing there
|
|
||||||
; Bit 1 - is word: this arg is a word rather than a byte. Because our
|
|
||||||
; destination are bytes anyway, this doesn't change much except
|
|
||||||
; for whether we expect a space between the hex pairs. If set,
|
|
||||||
; you still need to have a specifier for the second part of
|
|
||||||
; the multibyte.
|
|
||||||
; Bit 2 - optional: If set and not present during parsing, we don't error out
|
|
||||||
; and write zero
|
|
||||||
;
|
|
||||||
; Bit 3 - String argument: If set, this argument is a string. A pointer to the
|
|
||||||
; read string, null terminated (max 0x20 chars) will
|
|
||||||
; be placed in the next two bytes. This has to be the
|
|
||||||
; last argument of the list and it stops parsing.
|
|
||||||
; Sets A to nonzero if there was an error during parsing, zero otherwise.
|
|
||||||
parseArgs:
|
|
||||||
push bc
|
|
||||||
push de
|
|
||||||
push hl
|
|
||||||
push ix
|
|
||||||
|
|
||||||
; init the arg value to a default 0
|
|
||||||
xor a
|
|
||||||
ld (ix), a
|
|
||||||
ld (ix+1), a
|
|
||||||
ld (ix+2), a
|
|
||||||
ld b, PARSE_ARG_MAXCOUNT
|
|
||||||
.loop:
|
|
||||||
ld a, (hl)
|
|
||||||
; is this the end of the line?
|
|
||||||
or a ; cp 0
|
|
||||||
jr z, .endofargs
|
|
||||||
|
|
||||||
; Get the specs
|
|
||||||
ld a, (de)
|
|
||||||
bit 0, a ; do we have an arg?
|
|
||||||
jr z, .error ; not set? then we have too many args
|
|
||||||
|
|
||||||
ld c, a ; save the specs for multibyte check later
|
|
||||||
bit 3, a ; is our arg a string?
|
|
||||||
jr z, .notAString
|
|
||||||
; our arg is a string. Let's place HL in our next two bytes and call
|
|
||||||
; it a day. Little endian, remember
|
|
||||||
ld (ix), l
|
|
||||||
ld (ix+1), h
|
|
||||||
jr .success ; directly to success: skip endofargs checks
|
|
||||||
|
|
||||||
.notAString:
|
|
||||||
call parseHexPair
|
|
||||||
jr c, .error
|
|
||||||
|
|
||||||
; we have a good arg and we need to write A in (IX).
|
|
||||||
ld (ix), a
|
|
||||||
|
|
||||||
; Good! increase counters
|
|
||||||
inc de
|
|
||||||
inc ix
|
|
||||||
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
|
|
||||||
; If we get here, it means that our next char *has* to be a null char
|
|
||||||
ld a, (hl)
|
|
||||||
or a ; cp 0
|
|
||||||
jr z, .success ; zero? great!
|
|
||||||
jr .error
|
|
||||||
|
|
||||||
.endofargs:
|
|
||||||
; We encountered our null char. Let's verify that we either have no
|
|
||||||
; more args or that they are optional
|
|
||||||
ld a, (de)
|
|
||||||
or a
|
|
||||||
jr z, .success ; no arg? success
|
|
||||||
bit 2, a
|
|
||||||
jr z, .error ; if unset, arg is not optional. error
|
|
||||||
; success
|
|
||||||
.success:
|
|
||||||
xor a
|
|
||||||
jr .end
|
|
||||||
.error:
|
|
||||||
inc a
|
|
||||||
.end:
|
|
||||||
pop ix
|
|
||||||
pop hl
|
|
||||||
pop de
|
|
||||||
pop bc
|
|
||||||
ret
|
|
||||||
|
|
@ -3,7 +3,6 @@ jp test
|
|||||||
.inc "core.asm"
|
.inc "core.asm"
|
||||||
.inc "lib/util.asm"
|
.inc "lib/util.asm"
|
||||||
.inc "lib/parse.asm"
|
.inc "lib/parse.asm"
|
||||||
.inc "lib/args.asm"
|
|
||||||
|
|
||||||
zasmGetPC:
|
zasmGetPC:
|
||||||
ret
|
ret
|
||||||
@ -11,12 +10,10 @@ zasmGetPC:
|
|||||||
testNum: .db 1
|
testNum: .db 1
|
||||||
|
|
||||||
test:
|
test:
|
||||||
ld hl, 0xffff
|
ld sp, 0xffff
|
||||||
ld sp, hl
|
|
||||||
|
|
||||||
call testParseHex
|
call testParseHex
|
||||||
call testParseHexPair
|
call testParseHexPair
|
||||||
call testParseArgs
|
|
||||||
|
|
||||||
; success
|
; success
|
||||||
xor a
|
xor a
|
||||||
@ -68,60 +65,6 @@ testParseHexPair:
|
|||||||
.saB: .db "aB", 0
|
.saB: .db "aB", 0
|
||||||
.s99: .db "99", 0
|
.s99: .db "99", 0
|
||||||
|
|
||||||
|
|
||||||
testParseArgs:
|
|
||||||
ld hl, .t1+6
|
|
||||||
ld de, .t1
|
|
||||||
ld iy, .t1+3
|
|
||||||
call .testargs
|
|
||||||
|
|
||||||
ld hl, .t2+6
|
|
||||||
ld de, .t2
|
|
||||||
ld iy, .t2+3
|
|
||||||
call .testargs
|
|
||||||
|
|
||||||
ld hl, .t3+6
|
|
||||||
ld de, .t3
|
|
||||||
ld iy, .t3+3
|
|
||||||
call .testargs
|
|
||||||
ret
|
|
||||||
|
|
||||||
; HL and DE must be set, and IY must point to expected results in IX
|
|
||||||
.testargs:
|
|
||||||
ld ix, sandbox
|
|
||||||
call parseArgs
|
|
||||||
jp nz, fail
|
|
||||||
ld a, (ix)
|
|
||||||
cp (iy)
|
|
||||||
jp nz, fail
|
|
||||||
ld a, (ix+1)
|
|
||||||
cp (iy+1)
|
|
||||||
jp nz, fail
|
|
||||||
ld a, (ix+2)
|
|
||||||
cp (iy+2)
|
|
||||||
jp nz, fail
|
|
||||||
jp nexttest
|
|
||||||
|
|
||||||
; Test data format: 3 bytes specs, 3 bytes expected (IX), then the arg string.
|
|
||||||
|
|
||||||
; Empty args with empty specs
|
|
||||||
.t1:
|
|
||||||
.db 0b0000, 0b0000, 0b0000
|
|
||||||
.db 0, 0, 0
|
|
||||||
.db 0
|
|
||||||
|
|
||||||
; One arg, one byte spec
|
|
||||||
.t2:
|
|
||||||
.db 0b0001, 0b0000, 0b0000
|
|
||||||
.db 0xe4, 0, 0
|
|
||||||
.db "e4", 0
|
|
||||||
|
|
||||||
; 3 args, 3 bytes spec
|
|
||||||
.t3:
|
|
||||||
.db 0b0001, 0b0001, 0b0001
|
|
||||||
.db 0xe4, 0xab, 0x99
|
|
||||||
.db "e4 ab 99", 0
|
|
||||||
|
|
||||||
nexttest:
|
nexttest:
|
||||||
ld a, (testNum)
|
ld a, (testNum)
|
||||||
inc a
|
inc a
|
||||||
|
Loading…
Reference in New Issue
Block a user