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
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

View File

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