zasm: make .org affect "@" symbol

This commit is contained in:
Virgil Dupras 2019-11-15 08:59:26 -05:00
parent 79e04189b0
commit e5255d22f9
4 changed files with 24 additions and 7 deletions

View File

@ -101,7 +101,10 @@ it was placed there.
Whenever a `.equ` directive is evaluated, its resulting value is saved in a Whenever a `.equ` directive is evaluated, its resulting value is saved in a
special "last value" register that can then be used in any expression. This special "last value" register that can then be used in any expression. This
is very useful for variable definitions and for jump tables. last value is referenced with the `@` special symbol. This is very useful for
variable definitions and for jump tables.
Note that `.org` also affect the last value.
## Includes ## Includes

View File

@ -18,7 +18,7 @@
; *** CODE *** ; *** CODE ***
; 3 bytes per row, fill with zero ; 3 bytes per row, fill with zero
directiveNames: dirNames:
.db "DB", 0 .db "DB", 0
.db "DW", 0 .db "DW", 0
.db "EQU" .db "EQU"
@ -28,8 +28,8 @@ directiveNames:
.db "INC" .db "INC"
.db "BIN" .db "BIN"
; This is a list of handlers corresponding to indexes in directiveNames ; This is a list of handlers corresponding to indexes in dirNames
directiveHandlers: dirHandlers:
.dw handleDB .dw handleDB
.dw handleDW .dw handleDW
.dw handleEQU .dw handleEQU
@ -184,6 +184,7 @@ handleORG:
call parseExpr call parseExpr
jr nz, .badarg jr nz, .badarg
push ix \ pop hl push ix \ pop hl
ld (DIREC_LASTVAL), hl
call zasmSetOrg call zasmSetOrg
cp a ; ensure Z cp a ; ensure Z
ret ret
@ -310,7 +311,7 @@ getDirectiveID:
inc hl inc hl
ld b, D_BIN+1 ; D_BIN is last ld b, D_BIN+1 ; D_BIN is last
ld c, 3 ld c, 3
ld de, directiveNames ld de, dirNames
call findStringInList call findStringInList
pop de pop de
pop bc pop bc
@ -324,9 +325,9 @@ getDirectiveID:
; error, A contains the error number (ERR_*). ; error, A contains the error number (ERR_*).
parseDirective: parseDirective:
push de push de
; double A to have a proper offset in directiveHandlers ; double A to have a proper offset in dirHandlers
add a, a add a, a
ld de, directiveHandlers ld de, dirHandlers
call addDE call addDE
call intoDE call intoDE
push de \ pop ix push de \ pop ix

Binary file not shown.

View File

@ -1,3 +1,8 @@
.equ foo 456 ; AFTER_ORG should not get that value
.org 0x1234
.equ AFTER_ORG @
.org 0
jp test jp test
.inc "core.asm" .inc "core.asm"
@ -40,6 +45,13 @@ test:
jp nz, fail jp nz, fail
call nexttest call nexttest
; test that "@" is updated by a .org directive
ld hl, AFTER_ORG
ld de, 0x1234
call cpHLDE
jp nz, fail
call nexttest
; *** cpHLDE *** ; *** cpHLDE ***
ld hl, 0x42 ld hl, 0x42
ld de, 0x42 ld de, 0x42
@ -73,3 +85,4 @@ nexttest:
fail: fail:
ld a, (testNum) ld a, (testNum)
halt halt