mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 01:08:06 +11:00
zasm: code consolidation
This commit is contained in:
parent
98ad223ee1
commit
8241298c8f
@ -57,7 +57,6 @@ I_SBC .equ 0x2f
|
|||||||
I_SCF .equ 0x30
|
I_SCF .equ 0x30
|
||||||
I_SUB .equ 0x31
|
I_SUB .equ 0x31
|
||||||
I_XOR .equ 0x32
|
I_XOR .equ 0x32
|
||||||
I_BAD .equ 0xff
|
|
||||||
|
|
||||||
; Checks whether A is 'N' or 'M'
|
; Checks whether A is 'N' or 'M'
|
||||||
checkNOrM:
|
checkNOrM:
|
||||||
@ -77,27 +76,15 @@ checknmxy:
|
|||||||
cp 'y'
|
cp 'y'
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Reads instruction mnemonic in (HL) and returns the corresponding ID (I_*)
|
; Reads string in (HL) and returns the corresponding ID (I_*) in A. Sets Z if
|
||||||
; in A. I_BAD if there's no match.
|
; there's a match.
|
||||||
getInstID:
|
getInstID:
|
||||||
push bc
|
push bc
|
||||||
push de
|
push de
|
||||||
ld b, I_XOR+1 ; I_XOR is the last
|
ld b, I_XOR+1 ; I_XOR is the last
|
||||||
|
ld c, 4
|
||||||
ld de, instrNames
|
ld de, instrNames
|
||||||
.loop:
|
call findStringInList
|
||||||
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:
|
|
||||||
pop de
|
pop de
|
||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
@ -788,7 +775,7 @@ parseTokens:
|
|||||||
push hl
|
push hl
|
||||||
push de
|
push de
|
||||||
ld a, (tokInstr)
|
ld a, (tokInstr)
|
||||||
cp I_BAD
|
cp TOK_BAD
|
||||||
jr z, .error ; for now, we treat blank lines as errors
|
jr z, .error ; for now, we treat blank lines as errors
|
||||||
ld hl, tokArg1
|
ld hl, tokArg1
|
||||||
ld de, curArg1
|
ld de, curArg1
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
; *** Requirements ***
|
; *** Requirements ***
|
||||||
; JUMP_UPCASE
|
; JUMP_UPCASE
|
||||||
|
|
||||||
|
; *** Consts ***
|
||||||
|
TOK_INSTR .equ 0x01
|
||||||
|
TOK_BAD .equ 0xff
|
||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
; Parse line in (HL) and read the next token in (DE). For now, it only supports
|
; 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
|
; instructions. Arguments must be tokenized with the appropriate specialized
|
||||||
@ -19,6 +23,10 @@ tokenize:
|
|||||||
ex hl, de
|
ex hl, de
|
||||||
call getInstID
|
call getInstID
|
||||||
ex hl, de
|
ex hl, de
|
||||||
|
jr z, .match
|
||||||
|
; no match
|
||||||
|
ld a, TOK_BAD
|
||||||
|
.match:
|
||||||
ld (de), a
|
ld (de), a
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -65,4 +65,30 @@ enterParens:
|
|||||||
call JUMP_UNSETZ
|
call JUMP_UNSETZ
|
||||||
ret
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user