mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-30 20:18:06 +11:00
zasm: a bit of refactoring
This commit is contained in:
parent
f6dddaa380
commit
70f61ec451
@ -13,6 +13,8 @@ INSTR_TBLP_ROWSIZE .equ 8
|
|||||||
call parseLine
|
call parseLine
|
||||||
ld b, 0
|
ld b, 0
|
||||||
ld c, a ; written bytes
|
ld c, a ; written bytes
|
||||||
|
ld hl, curUpcode
|
||||||
|
call copy
|
||||||
ret
|
ret
|
||||||
|
|
||||||
unsetZ:
|
unsetZ:
|
||||||
@ -33,6 +35,17 @@ rlaX:
|
|||||||
djnz .loop
|
djnz .loop
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
; Copy BC bytes from (HL) to (DE).
|
||||||
|
copy:
|
||||||
|
push bc
|
||||||
|
push de
|
||||||
|
push hl
|
||||||
|
ldir
|
||||||
|
pop hl
|
||||||
|
pop de
|
||||||
|
pop bc
|
||||||
|
ret
|
||||||
|
|
||||||
; If string at (HL) starts with ( and ends with ), "enter" into the parens
|
; If string at (HL) starts with ( and ends with ), "enter" into the parens
|
||||||
; (advance HL and put a null char at the end of the string) and set Z.
|
; (advance HL and put a null char at the end of the string) and set Z.
|
||||||
; Otherwise, do nothing and reset Z.
|
; Otherwise, do nothing and reset Z.
|
||||||
@ -480,45 +493,17 @@ matchPrimaryRow:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Parse line at (HL) and write resulting opcode(s) in (DE). Returns the number
|
; Compute the upcode for argspec row at (DE) and arguments in curArg{1,2} and
|
||||||
; of bytes written in A.
|
; writes the resulting upcode in curUpcode. A is the number if bytes written
|
||||||
;
|
; to curUpcode (can be zero if something went wrong).
|
||||||
; Overwrites IX
|
getUpcode:
|
||||||
parseLine:
|
push ix
|
||||||
call readLine
|
|
||||||
; Check whether we have errors. We don't do any parsing if we do.
|
|
||||||
ld a, (curArg1)
|
|
||||||
cp 0xff
|
|
||||||
jr z, .error
|
|
||||||
ret z
|
|
||||||
ld a, (curArg2)
|
|
||||||
cp 0xff
|
|
||||||
jr nz, .noerror
|
|
||||||
.error:
|
|
||||||
ld a, 0
|
|
||||||
ret
|
|
||||||
.noerror:
|
|
||||||
push de
|
push de
|
||||||
ld de, instrTBlPrimary
|
push hl
|
||||||
ld b, INSTR_TBLP_CNT
|
|
||||||
.loop:
|
|
||||||
ld a, (de)
|
|
||||||
call matchPrimaryRow
|
|
||||||
jr z, .match
|
|
||||||
ld a, INSTR_TBLP_ROWSIZE
|
|
||||||
call JUMP_ADDDE
|
|
||||||
djnz .loop
|
|
||||||
; no match
|
|
||||||
xor a
|
|
||||||
pop de
|
|
||||||
ret
|
|
||||||
.match:
|
|
||||||
; We have our matching instruction row. We're getting pretty near our
|
|
||||||
; goal here!
|
|
||||||
; First, let's go in IX mode. It's easier to deal with offsets here.
|
; First, let's go in IX mode. It's easier to deal with offsets here.
|
||||||
ld ixh, d
|
ld ixh, d
|
||||||
ld ixl, e
|
ld ixl, e
|
||||||
; First, let's see if we're dealing with a group here
|
; now, let's see if we're dealing with a group here
|
||||||
ld a, (ix+4) ; first argspec
|
ld a, (ix+4) ; first argspec
|
||||||
call isGroupId
|
call isGroupId
|
||||||
jr z, .firstArgIsGroup
|
jr z, .firstArgIsGroup
|
||||||
@ -534,7 +519,6 @@ parseLine:
|
|||||||
.isGroup:
|
.isGroup:
|
||||||
; A is a group, good, now let's get its value. DE is pointing to
|
; A is a group, good, now let's get its value. DE is pointing to
|
||||||
; the argument.
|
; the argument.
|
||||||
push hl
|
|
||||||
ld h, a
|
ld h, a
|
||||||
ld a, (de)
|
ld a, (de)
|
||||||
call findInGroup ; we don't check for match, it's supposed to
|
call findInGroup ; we don't check for match, it's supposed to
|
||||||
@ -554,7 +538,6 @@ parseLine:
|
|||||||
; At this point, we have a properly displaced value in A. We'll want
|
; At this point, we have a properly displaced value in A. We'll want
|
||||||
; to OR it with the opcode.
|
; to OR it with the opcode.
|
||||||
or (ix+7) ; upcode
|
or (ix+7) ; upcode
|
||||||
pop hl
|
|
||||||
|
|
||||||
; Success!
|
; Success!
|
||||||
jr .writeFirstOpcode
|
jr .writeFirstOpcode
|
||||||
@ -563,14 +546,13 @@ parseLine:
|
|||||||
ld a, (ix+7) ; upcode is on 8th byte
|
ld a, (ix+7) ; upcode is on 8th byte
|
||||||
.writeFirstOpcode:
|
.writeFirstOpcode:
|
||||||
; At the end, we have our final opcode in A!
|
; At the end, we have our final opcode in A!
|
||||||
pop de
|
ld de, curUpcode
|
||||||
ld (de), a
|
ld (de), a
|
||||||
|
|
||||||
; Good, we are probably finished here for many primary opcodes. However,
|
; Good, we are probably finished here for many primary opcodes. However,
|
||||||
; some primary opcodes take 8 or 16 bit constants as an argument and
|
; some primary opcodes take 8 or 16 bit constants as an argument and
|
||||||
; if that's the case here, we need to write it too.
|
; if that's the case here, we need to write it too.
|
||||||
; We still have our instruction row in IX. Let's revisit it.
|
; We still have our instruction row in IX. Let's revisit it.
|
||||||
push hl ; we use HL to point to the currently read arg
|
|
||||||
ld a, (ix+4) ; first argspec
|
ld a, (ix+4) ; first argspec
|
||||||
ld hl, curArg1
|
ld hl, curArg1
|
||||||
call checkNOrM
|
call checkNOrM
|
||||||
@ -625,6 +607,45 @@ parseLine:
|
|||||||
xor a
|
xor a
|
||||||
.end:
|
.end:
|
||||||
pop hl
|
pop hl
|
||||||
|
pop de
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Parse line at (HL) and write resulting opcode(s) in curUpcode. Returns the
|
||||||
|
; number of bytes written in A.
|
||||||
|
parseLine:
|
||||||
|
call readLine
|
||||||
|
; Check whether we have errors. We don't do any parsing if we do.
|
||||||
|
ld a, (curArg1)
|
||||||
|
cp 0xff
|
||||||
|
jr z, .error
|
||||||
|
ret z
|
||||||
|
ld a, (curArg2)
|
||||||
|
cp 0xff
|
||||||
|
jr nz, .noerror
|
||||||
|
.error:
|
||||||
|
xor a
|
||||||
|
ret
|
||||||
|
.noerror:
|
||||||
|
push de
|
||||||
|
ld de, instrTBlPrimary
|
||||||
|
ld b, INSTR_TBLP_CNT
|
||||||
|
.loop:
|
||||||
|
ld a, (de)
|
||||||
|
call matchPrimaryRow
|
||||||
|
jr z, .match
|
||||||
|
ld a, INSTR_TBLP_ROWSIZE
|
||||||
|
call JUMP_ADDDE
|
||||||
|
djnz .loop
|
||||||
|
; no match
|
||||||
|
xor a
|
||||||
|
jr .end
|
||||||
|
.match:
|
||||||
|
; We have our matching instruction row. We're getting pretty near our
|
||||||
|
; goal here!
|
||||||
|
call getUpcode
|
||||||
|
.end:
|
||||||
|
pop de
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
@ -795,6 +816,9 @@ curArg1:
|
|||||||
curArg2:
|
curArg2:
|
||||||
.db 0, 0, 0
|
.db 0, 0, 0
|
||||||
|
|
||||||
|
curUpcode:
|
||||||
|
.db 0, 0, 0, 0
|
||||||
|
|
||||||
; space for tmp stuff
|
; space for tmp stuff
|
||||||
tmpBuf:
|
tmpBuf:
|
||||||
.fill 0x20
|
.fill 0x20
|
||||||
|
Loading…
Reference in New Issue
Block a user