mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 08:58:06 +11:00
zasm: start matching args
We now properly match arg-less operations.
This commit is contained in:
parent
b3af6e0115
commit
453cf3d74a
@ -5,9 +5,9 @@ ld b, 0
|
|||||||
ld c, a ; written bytes
|
ld c, a ; written bytes
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Sets Z is A is ' ', CR, LF, or null.
|
; Sets Z is A is ';', CR, LF, or null.
|
||||||
isSep:
|
isLineEnd:
|
||||||
cp ' '
|
cp ';'
|
||||||
ret z
|
ret z
|
||||||
cp 0
|
cp 0
|
||||||
ret z
|
ret z
|
||||||
@ -16,17 +16,28 @@ isSep:
|
|||||||
cp 0x0a
|
cp 0x0a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; read word in (HL) and put it in curWord, null terminated. A is the read
|
; Sets Z is A is ' ' or ','
|
||||||
; length.
|
isSep:
|
||||||
|
cp ' '
|
||||||
|
ret z
|
||||||
|
cp ','
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Sets Z is A is ' ', ',', ';', CR, LF, or null.
|
||||||
|
isSepOrLineEnd:
|
||||||
|
call isSep
|
||||||
|
ret z
|
||||||
|
call isLineEnd
|
||||||
|
ret
|
||||||
|
|
||||||
|
; read word in (HL) and put it in (DE), null terminated. A is the read
|
||||||
|
; length. HL is advanced to the next separator char.
|
||||||
readWord:
|
readWord:
|
||||||
push bc
|
push bc
|
||||||
push de
|
|
||||||
push hl
|
|
||||||
ld de, curWord
|
|
||||||
ld b, 4
|
ld b, 4
|
||||||
.loop:
|
.loop:
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
call isSep
|
call isSepOrLineEnd
|
||||||
jr z, .success
|
jr z, .success
|
||||||
call JUMP_UPCASE
|
call JUMP_UPCASE
|
||||||
ld (de), a
|
ld (de), a
|
||||||
@ -43,25 +54,93 @@ readWord:
|
|||||||
xor a
|
xor a
|
||||||
ld (de), a
|
ld (de), a
|
||||||
.end:
|
.end:
|
||||||
pop hl
|
|
||||||
pop de
|
|
||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; (HL) being a string, advance it to the next non-sep character.
|
||||||
|
; Set Z if we could do it before the line ended, reset Z if we couldn't.
|
||||||
|
toWord:
|
||||||
|
.loop:
|
||||||
|
ld a, (hl)
|
||||||
|
call isLineEnd
|
||||||
|
jr z, .error
|
||||||
|
call isSep
|
||||||
|
jr nz, .success
|
||||||
|
inc hl
|
||||||
|
jr .loop
|
||||||
|
.error:
|
||||||
|
; we need the Z flag to be unset and it is set now. Let's CP with
|
||||||
|
; something it can't be equal to, something not a line end.
|
||||||
|
cp 'a' ; Z flag unset
|
||||||
|
ret
|
||||||
|
.success:
|
||||||
|
; We need the Z flag to be set and it is unset. Let's compare it with
|
||||||
|
; itself to return a set Z
|
||||||
|
cp a
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
readLine:
|
||||||
|
push de
|
||||||
|
xor a
|
||||||
|
ld (curWord), a
|
||||||
|
ld (curArg1), a
|
||||||
|
ld (curArg2), a
|
||||||
|
ld de, curWord
|
||||||
|
call readWord
|
||||||
|
call toWord
|
||||||
|
jr nz, .end
|
||||||
|
ld de, curArg1
|
||||||
|
call readWord
|
||||||
|
call toWord
|
||||||
|
jr nz, .end
|
||||||
|
ld de, curArg2
|
||||||
|
call readWord
|
||||||
|
.end:
|
||||||
|
pop de
|
||||||
|
ret
|
||||||
|
|
||||||
|
; match argument string at (HL) with argspec A.
|
||||||
|
; Set Z/NZ on match
|
||||||
|
matchArg:
|
||||||
|
cp 0
|
||||||
|
jr z, .matchnone
|
||||||
|
; Z is unset. TODO: implement rest
|
||||||
|
jr .end
|
||||||
|
.matchnone:
|
||||||
|
ld a, (hl)
|
||||||
|
cp 0 ; arg must be null to match
|
||||||
|
.end:
|
||||||
|
ret
|
||||||
|
|
||||||
; Compare primary row at (DE) with string at curWord. Sets Z flag if there's a
|
; Compare primary row at (DE) with string at curWord. Sets Z flag if there's a
|
||||||
; match, reset if not.
|
; match, reset if not.
|
||||||
matchPrimaryRow:
|
matchPrimaryRow:
|
||||||
push hl
|
push hl
|
||||||
|
push ix
|
||||||
ld hl, curWord
|
ld hl, curWord
|
||||||
ld a, 4
|
ld a, 4
|
||||||
call JUMP_STRNCMP
|
call JUMP_STRNCMP
|
||||||
|
jr nz, .end
|
||||||
|
; name matches, let's see the rest
|
||||||
|
ld ixh, d
|
||||||
|
ld ixl, e
|
||||||
|
ld hl, curArg1
|
||||||
|
ld a, (ix+4)
|
||||||
|
call matchArg
|
||||||
|
jr nz, .end
|
||||||
|
ld hl, curArg2
|
||||||
|
ld a, (ix+5)
|
||||||
|
call matchArg
|
||||||
|
.end:
|
||||||
|
pop ix
|
||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse line at (HL) and write resulting opcode(s) in (DE). Returns the number
|
; Parse line at (HL) and write resulting opcode(s) in (DE). Returns the number
|
||||||
; of bytes written in A.
|
; of bytes written in A.
|
||||||
parseLine:
|
parseLine:
|
||||||
call readWord
|
call readLine
|
||||||
push de
|
push de
|
||||||
ld de, instTBlPrimary
|
ld de, instTBlPrimary
|
||||||
.loop:
|
.loop:
|
||||||
@ -87,6 +166,30 @@ parseLine:
|
|||||||
ld a, 1
|
ld a, 1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; In instruction metadata below, argument types arge indicated with a single
|
||||||
|
; char mnemonic that is called "argspec". This is the table of correspondance.
|
||||||
|
; Single letters are represented by themselves, so we don't need as much
|
||||||
|
; metadata.
|
||||||
|
|
||||||
|
argspecsSingle:
|
||||||
|
.db "ABCDEHL", 0
|
||||||
|
|
||||||
|
; Format: 1 byte argspec + 4 chars string
|
||||||
|
argspecTbl:
|
||||||
|
.db 'h', "HL", 0, 0
|
||||||
|
.db 'l', "(HL)"
|
||||||
|
.db 'd', "DE", 0, 0
|
||||||
|
.db 'e', "(DE)"
|
||||||
|
.db 'b', "BC", 0, 0
|
||||||
|
.db 'c', "(BC)"
|
||||||
|
.db 'a', "AF", 0, 0
|
||||||
|
.db 'f', "AF'", 0
|
||||||
|
.db 'x', "(IX)"
|
||||||
|
.db 'y', "(IY)"
|
||||||
|
.db 's', "SP", 0, 0
|
||||||
|
.db 'p', "(SP)"
|
||||||
|
.db 0
|
||||||
|
|
||||||
; This is a list of primary instructions (single upcode) that lead to a
|
; This is a list of primary instructions (single upcode) that lead to a
|
||||||
; constant (no group code to insert).
|
; constant (no group code to insert).
|
||||||
; That doesn't mean that they don't take any argument though. For example,
|
; That doesn't mean that they don't take any argument though. For example,
|
||||||
@ -148,4 +251,8 @@ instTBlPrimary:
|
|||||||
; enough space for 4 chars and a null
|
; enough space for 4 chars and a null
|
||||||
curWord:
|
curWord:
|
||||||
.db 0, 0, 0, 0, 0
|
.db 0, 0, 0, 0, 0
|
||||||
|
curArg1:
|
||||||
|
.db 0, 0, 0, 0, 0
|
||||||
|
curArg2:
|
||||||
|
.db 0, 0, 0, 0, 0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user