2019-05-01 11:40:22 +10:00
|
|
|
; *** CONSTS ***
|
|
|
|
|
2019-05-02 04:07:01 +10:00
|
|
|
.equ D_DB 0x00
|
|
|
|
.equ D_DW 0x01
|
2019-05-12 12:11:05 +10:00
|
|
|
.equ D_EQU 0x02
|
2019-05-02 04:07:01 +10:00
|
|
|
.equ D_BAD 0xff
|
2019-05-01 11:40:22 +10:00
|
|
|
|
2019-05-12 12:11:05 +10:00
|
|
|
; *** Variables ***
|
|
|
|
.equ DIREC_SCRATCHPAD DIREC_RAMSTART
|
|
|
|
.equ DIREC_RAMEND DIREC_SCRATCHPAD+SCRATCHPAD_SIZE
|
2019-05-01 11:40:22 +10:00
|
|
|
; *** CODE ***
|
|
|
|
|
|
|
|
; 4 bytes per row, fill with zero
|
|
|
|
directiveNames:
|
|
|
|
.db ".DB", 0
|
2019-05-02 04:07:01 +10:00
|
|
|
.db ".DW", 0
|
2019-05-12 12:11:05 +10:00
|
|
|
.db ".EQU"
|
2019-05-01 11:40:22 +10:00
|
|
|
|
2019-05-02 01:26:41 +10:00
|
|
|
; This is a list of handlers corresponding to indexes in directiveNames
|
|
|
|
directiveHandlers:
|
|
|
|
.dw handleDB
|
2019-05-02 04:07:01 +10:00
|
|
|
.dw handleDW
|
2019-05-12 12:11:05 +10:00
|
|
|
.dw handleEQU
|
2019-05-02 01:26:41 +10:00
|
|
|
|
|
|
|
handleDB:
|
|
|
|
push hl
|
|
|
|
call toWord
|
|
|
|
call readWord
|
|
|
|
ld hl, scratchpad
|
2019-05-15 03:53:12 +10:00
|
|
|
call parseLiteral
|
2019-05-02 01:26:41 +10:00
|
|
|
ld a, ixl
|
|
|
|
ld (direcData), a
|
|
|
|
ld a, 1
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2019-05-02 04:07:01 +10:00
|
|
|
handleDW:
|
|
|
|
push hl
|
|
|
|
call toWord
|
|
|
|
call readWord
|
|
|
|
ld hl, scratchpad
|
2019-05-15 05:26:29 +10:00
|
|
|
call parseExpr
|
2019-05-02 04:07:01 +10:00
|
|
|
ld a, ixl
|
|
|
|
ld (direcData), a
|
|
|
|
ld a, ixh
|
|
|
|
ld (direcData+1), a
|
|
|
|
ld a, 2
|
|
|
|
pop hl
|
|
|
|
ret
|
2019-05-02 01:26:41 +10:00
|
|
|
|
2019-05-12 12:11:05 +10:00
|
|
|
handleEQU:
|
|
|
|
call zasmIsFirstPass
|
2019-05-12 22:50:29 +10:00
|
|
|
jr nz, .begin
|
2019-05-12 12:11:05 +10:00
|
|
|
; first pass? .equ are noops
|
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
.begin:
|
|
|
|
push hl
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
; Read our constant name
|
|
|
|
call toWord
|
|
|
|
call readWord
|
|
|
|
; We can't register our symbol yet: we don't have our value!
|
|
|
|
; Let's copy it over.
|
|
|
|
push hl
|
|
|
|
ld hl, scratchpad
|
|
|
|
ld de, DIREC_SCRATCHPAD
|
|
|
|
ld bc, SCRATCHPAD_SIZE
|
|
|
|
ldir
|
|
|
|
pop hl
|
|
|
|
|
|
|
|
; Now, read the value associated to it
|
|
|
|
call toWord
|
|
|
|
call readWord
|
|
|
|
ld hl, scratchpad
|
2019-05-15 05:26:29 +10:00
|
|
|
call parseExpr
|
2019-05-12 12:11:05 +10:00
|
|
|
jr nz, .error
|
|
|
|
ld hl, DIREC_SCRATCHPAD
|
|
|
|
ld d, ixh
|
|
|
|
ld e, ixl
|
|
|
|
call symRegister
|
|
|
|
jr .end
|
|
|
|
.error:
|
|
|
|
.end:
|
|
|
|
xor a ; 0 bytes written
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
pop hl
|
|
|
|
ret
|
|
|
|
|
2019-05-01 11:40:22 +10:00
|
|
|
; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if
|
|
|
|
; there's a match.
|
|
|
|
getDirectiveID:
|
|
|
|
push bc
|
|
|
|
push de
|
2019-05-12 12:11:05 +10:00
|
|
|
ld b, D_EQU+1 ; D_EQU is last
|
2019-05-01 11:40:22 +10:00
|
|
|
ld c, 4
|
|
|
|
ld de, directiveNames
|
|
|
|
call findStringInList
|
|
|
|
pop de
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2019-05-02 01:26:41 +10:00
|
|
|
; Parse directive specified in A (D_* const) with args in (HL) and act in
|
|
|
|
; an appropriate manner. If the directive results in writing data at its
|
|
|
|
; current location, that data is in (direcData) and A is the number of bytes
|
|
|
|
; in it.
|
2019-05-01 11:40:22 +10:00
|
|
|
parseDirective:
|
2019-05-02 01:26:41 +10:00
|
|
|
push de
|
|
|
|
; double A to have a proper offset in directiveHandlers
|
|
|
|
add a, a
|
|
|
|
ld de, directiveHandlers
|
|
|
|
call JUMP_ADDDE
|
2019-05-02 04:07:01 +10:00
|
|
|
call JUMP_INTODE
|
2019-05-02 01:26:41 +10:00
|
|
|
ld ixh, d
|
|
|
|
ld ixl, e
|
|
|
|
pop de
|
|
|
|
jp (ix)
|
|
|
|
|
|
|
|
; *** Variables ***
|
|
|
|
direcData:
|
|
|
|
.fill 2
|