1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 20:18:04 +11:00

zasm: code consolidation

This commit is contained in:
Virgil Dupras 2019-04-30 21:13:37 -04:00
parent 98ad223ee1
commit 8241298c8f
3 changed files with 40 additions and 19 deletions

View File

@ -57,7 +57,6 @@ I_SBC .equ 0x2f
I_SCF .equ 0x30
I_SUB .equ 0x31
I_XOR .equ 0x32
I_BAD .equ 0xff
; Checks whether A is 'N' or 'M'
checkNOrM:
@ -77,27 +76,15 @@ checknmxy:
cp 'y'
ret
; Reads instruction mnemonic in (HL) and returns the corresponding ID (I_*)
; in A. I_BAD if there's no match.
; Reads string in (HL) and returns the corresponding ID (I_*) in A. Sets Z if
; there's a match.
getInstID:
push bc
push de
ld b, I_XOR+1 ; I_XOR is the last
ld c, 4
ld de, instrNames
.loop:
ld a, 4
call JUMP_STRNCMP
ld a, 4
call JUMP_ADDDE
jr z, .match
djnz .loop
; no match
ld a, I_BAD
jr .end
.match:
ld a, I_XOR+1
sub b
.end:
call findStringInList
pop de
pop bc
ret
@ -788,7 +775,7 @@ parseTokens:
push hl
push de
ld a, (tokInstr)
cp I_BAD
cp TOK_BAD
jr z, .error ; for now, we treat blank lines as errors
ld hl, tokArg1
ld de, curArg1

View File

@ -5,6 +5,10 @@
; *** Requirements ***
; JUMP_UPCASE
; *** Consts ***
TOK_INSTR .equ 0x01
TOK_BAD .equ 0xff
; *** Code ***
; Parse line in (HL) and read the next token in (DE). For now, it only supports
; instructions. Arguments must be tokenized with the appropriate specialized
@ -19,6 +23,10 @@ tokenize:
ex hl, de
call getInstID
ex hl, de
jr z, .match
; no match
ld a, TOK_BAD
.match:
ld (de), a
ret

View File

@ -65,4 +65,30 @@ enterParens:
call JUMP_UNSETZ
ret
; Find string (HL) in string list (DE) of size B. Each string is C bytes wide.
; Returns the index of the found string. Sets Z if found, unsets Z if not found.
findStringInList:
push de
push bc
.loop:
ld a, c
call JUMP_STRNCMP
ld a, c
call JUMP_ADDDE
jr z, .match
djnz .loop
; no match, Z is unset
pop bc
pop de
ret
.match:
; Now, we want the index of our string, which is equal to our initial B
; minus our current B. To get this, we have to play with our registers
; and stack a bit.
ld d, b
pop bc
ld a, b
sub d
pop de
cp a ; ensure Z
ret