From e5255d22f9a38b7240d77b477faa83bb593650e1 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 15 Nov 2019 08:59:26 -0500 Subject: [PATCH] zasm: make .org affect "@" symbol --- apps/zasm/README.md | 5 ++++- apps/zasm/directive.asm | 13 +++++++------ tools/emul/zasm/zasm.bin | Bin 4721 -> 4724 bytes tools/tests/unit/test_core.asm | 13 +++++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/apps/zasm/README.md b/apps/zasm/README.md index 1bc77b2..efcc78b 100644 --- a/apps/zasm/README.md +++ b/apps/zasm/README.md @@ -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 diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index b443f19..e796900 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -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 diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index b0c5406993b44faafc174261061973373b4cc123..feb88a7888eadc29eebfc38daa49dc2297682c21 100644 GIT binary patch delta 617 zcmX|;L1@!Z7{~WATRLXjbXA){Ta((=P^pJj=mZz-VXU@?p^hZ4f)vGr2Vn?ys|Ve@ z3SOQE4}##qgCHU$hk`YQC^W_IP}pRb93lpUIzdndg9Trrc=~_e|Kt7M|9$Ug_E(lM zDsP!4LOQvD=25rv41GoDWoL6TgaTbWFtpC&LoyTUVzIRCfZ6#TJR9Vq@{+tNKaw5j z*Z7=prU_rFVgWR=5UwDNJP7A0?^QU-Y6_naHky_*+P!kW3Af4Ta5}>RwWF3}XQ=fN z>!uXv7-7g~U5?Mpjf~tjDl01k0C@n%l!5W24tK~# zG*Q`8`QWx?k92cn2@?}W7t^@dv25FsX8f&34icME@fWwFWoqr=hkF goA$OmwxLa=nPj5qtpPq<%pY%MvP~~dG2PP5KQlobp8x;= delta 617 zcmX|;PiWI{6vy|=*3#-Xp@nMM?!mqxMtjtCTDC)_fdQ+InS1O}*R|Ok4c&EY5mP78Ho2IZotQVIHy9qRC}?J^0uC0BNIOCOj+G%NhruDQQww+cxV`E7 zGAI0kCKe-by(IM647XM{ebkMVe6AZW`Ga!O_d80;T2i;H2Wwl_2Q9co6U!N3-cE&v i*o88%ToOh@H%ty;hl4HmU8s=7barT(t%2M~XZ`@p&>gb? diff --git a/tools/tests/unit/test_core.asm b/tools/tests/unit/test_core.asm index 0c4fcd0..c3929ea 100644 --- a/tools/tests/unit/test_core.asm +++ b/tools/tests/unit/test_core.asm @@ -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 +