zasm: add support for .equ
This commit is contained in:
parent
6d4515cd03
commit
89848dbfe2
@ -2,19 +2,25 @@
|
|||||||
|
|
||||||
.equ D_DB 0x00
|
.equ D_DB 0x00
|
||||||
.equ D_DW 0x01
|
.equ D_DW 0x01
|
||||||
|
.equ D_EQU 0x02
|
||||||
.equ D_BAD 0xff
|
.equ D_BAD 0xff
|
||||||
|
|
||||||
|
; *** Variables ***
|
||||||
|
.equ DIREC_SCRATCHPAD DIREC_RAMSTART
|
||||||
|
.equ DIREC_RAMEND DIREC_SCRATCHPAD+SCRATCHPAD_SIZE
|
||||||
; *** CODE ***
|
; *** CODE ***
|
||||||
|
|
||||||
; 4 bytes per row, fill with zero
|
; 4 bytes per row, fill with zero
|
||||||
directiveNames:
|
directiveNames:
|
||||||
.db ".DB", 0
|
.db ".DB", 0
|
||||||
.db ".DW", 0
|
.db ".DW", 0
|
||||||
|
.db ".EQU"
|
||||||
|
|
||||||
; This is a list of handlers corresponding to indexes in directiveNames
|
; This is a list of handlers corresponding to indexes in directiveNames
|
||||||
directiveHandlers:
|
directiveHandlers:
|
||||||
.dw handleDB
|
.dw handleDB
|
||||||
.dw handleDW
|
.dw handleDW
|
||||||
|
.dw handleEQU
|
||||||
|
|
||||||
handleDB:
|
handleDB:
|
||||||
push hl
|
push hl
|
||||||
@ -42,12 +48,54 @@ handleDW:
|
|||||||
pop hl
|
pop hl
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
handleEQU:
|
||||||
|
call zasmIsFirstPass
|
||||||
|
jr z, .begin
|
||||||
|
; 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
|
||||||
|
ld a, (hl)
|
||||||
|
call parseNumberOrSymbol
|
||||||
|
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
|
||||||
|
|
||||||
; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if
|
; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if
|
||||||
; there's a match.
|
; there's a match.
|
||||||
getDirectiveID:
|
getDirectiveID:
|
||||||
push bc
|
push bc
|
||||||
push de
|
push de
|
||||||
ld b, D_DW+1 ; D_DW is last
|
ld b, D_EQU+1 ; D_EQU is last
|
||||||
ld c, 4
|
ld c, 4
|
||||||
ld de, directiveNames
|
ld de, directiveNames
|
||||||
call findStringInList
|
call findStringInList
|
||||||
|
@ -47,8 +47,9 @@ jp zasmMain
|
|||||||
#include "tok.asm"
|
#include "tok.asm"
|
||||||
#include "parse.asm"
|
#include "parse.asm"
|
||||||
#include "instr.asm"
|
#include "instr.asm"
|
||||||
|
.equ DIREC_RAMSTART IO_RAMEND
|
||||||
#include "directive.asm"
|
#include "directive.asm"
|
||||||
.equ SYM_RAMSTART IO_RAMEND
|
.equ SYM_RAMSTART DIREC_RAMEND
|
||||||
#include "symbol.asm"
|
#include "symbol.asm"
|
||||||
|
|
||||||
; Read file through blockdev ID in H and outputs its upcodes through blockdev
|
; Read file through blockdev ID in H and outputs its upcodes through blockdev
|
||||||
@ -134,6 +135,8 @@ parseLine:
|
|||||||
.direc:
|
.direc:
|
||||||
ld a, c ; D_*
|
ld a, c ; D_*
|
||||||
call parseDirective
|
call parseDirective
|
||||||
|
or a ; cp 0
|
||||||
|
jr z, .success ; if zero, shortcut through
|
||||||
ld b, a ; save output byte count
|
ld b, a ; save output byte count
|
||||||
call incOutputOffset
|
call incOutputOffset
|
||||||
call zasmIsFirstPass
|
call zasmIsFirstPass
|
||||||
|
@ -11,3 +11,5 @@ label2:
|
|||||||
.dw 3742
|
.dw 3742
|
||||||
.dw 0x3742
|
.dw 0x3742
|
||||||
ld a, (label1)
|
ld a, (label1)
|
||||||
|
.equ foobar 0x1234
|
||||||
|
ld hl, foobar
|
||||||
|
Loading…
Reference in New Issue
Block a user