From c2d84563ddfcd9cd4947801d6078a9ddbe04703b Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 23 Jul 2019 16:01:23 -0400 Subject: [PATCH] zasm: allow duplicate const definition This will allow interesting override scenarios, adding flexibility. --- apps/zasm/README.md | 4 ++++ apps/zasm/directive.asm | 7 +++++++ tools/emul/zasm/zasm.bin | Bin 4659 -> 4663 bytes tools/tests/zasm/errtests.sh | 2 +- tools/tests/zasm/test7.asm | 5 +++++ tools/tests/zasm/test7.asm.expected | 1 + 6 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tools/tests/zasm/test7.asm create mode 100644 tools/tests/zasm/test7.asm.expected diff --git a/apps/zasm/README.md b/apps/zasm/README.md index 335660b..ac678db 100644 --- a/apps/zasm/README.md +++ b/apps/zasm/README.md @@ -115,6 +115,10 @@ allowed. An included file cannot have an `#inc` directive. **.equ**: Binds a symbol named after the first parameter to the value of the expression written as the second parameter. Example: `.equ foo 0x42+'A'` + + If the symbol specified has already been defined, no error occur and + the first value defined stays intact. This allows for "user override" + of programs. **.fill**: Outputs the number of null bytes specified by its argument, an expression. Often used with `$` to fill our binary up to a certain diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index e25ab4d..4bf8afc 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -149,6 +149,13 @@ handleEQU: ld hl, DIREC_SCRATCHPAD push ix \ pop de call symRegisterConst ; A and Z set + jr z, .end ; success + ; register ended up in error. We need to figure which error. If it's + ; a duplicate error, we ignore it and return success because, as per + ; ".equ" policy, it's fine to define the same const twice. The first + ; value has precedence. + cp ERR_DUPSYM + ; whatever the value of Z, it's the good one, return jr .end .badfmt: ld a, ERR_BAD_FMT diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index f74da551e3a493a0d8a133de77b333f872930f13..7a7a56f2f9818f6bad600c971b6c8f125d79a680 100644 GIT binary patch delta 452 zcmdn2vR#GgFv~_Jc1Fgg$y|&Uj5V8`8J{vTp4+U+EXgRiD?)+o>fMJI_n*9YxF+)H z*`Ce8EHaEhMFp(2OdK_l8s=9)f?wG)**Mk1ox}6PXM}H_oX%IP*A%H?`Sj}1vl(6r zDuN{mj1CNMH-I?eiY5tXqkR;F6-yHCKD~HWFG7R&pV(wRer3jv$wvGRj5U*s`8(X- zg`a&HaaZv(g!&PF_+^Bh-oBG}pWamjN?AqReF$a)<>BlfQ1;Wa-y$@O&uV%2pRJ$l zBv7s<6rmvl(N`bwP=oWXB2Z<0go5DTIL5zWOcFo=pfUB6?+Yj~CQW7%G*sSY(WtQV?DR+l5yb)!e?5>3*8MW#?DWY|g0`6(BM(&k`=`Mq@%3y|qyp<%)hLPA z`%j+b^{)8GcknZ!cOooKSSkVkATXfMJI_n*9YxFYiD z*^bS@EHaEhMFp(2OdJ)F8s=9)f?wG)**KNM?ZdOfr-ZMcoX%IPRTrsY`t<72vl(6r z3W6mGj1CNMH-I?8iY5tXqkR1&sI-%6DU{X zi_nmP=&O!+sKI$x5vZ~{LP79v9OK_GCJCSb(3tAUj|G$%<0i8S8ms;cS4@mNE8}Iy zXjIsFc5wX$>cJkynLEHMZkq0XN{nKEQ_rbBLXE=E_&{In#L8-VC0?3s>;r%B8*ul{Q diff --git a/tools/tests/zasm/errtests.sh b/tools/tests/zasm/errtests.sh index 87537a9..dd4a76b 100755 --- a/tools/tests/zasm/errtests.sh +++ b/tools/tests/zasm/errtests.sh @@ -55,5 +55,5 @@ chkerr "#inc foo" 19 chkerr "ld a, 0x100" 20 chkerr ".db 0x100" 20 chkerr "#inc \"doesnotexist\"" 21 -chkerr ".equ foo 42 \\ .equ foo 42" 22 +chkerr "foo:\\foo:" 22 chkoom diff --git a/tools/tests/zasm/test7.asm b/tools/tests/zasm/test7.asm new file mode 100644 index 0000000..c5976ad --- /dev/null +++ b/tools/tests/zasm/test7.asm @@ -0,0 +1,5 @@ +; It's fine to declare the same constant twice. Only the first value is +; kept +.equ FOO 42 +.equ FOO 22 +ld a, FOO diff --git a/tools/tests/zasm/test7.asm.expected b/tools/tests/zasm/test7.asm.expected new file mode 100644 index 0000000..29cc4ea --- /dev/null +++ b/tools/tests/zasm/test7.asm.expected @@ -0,0 +1 @@ +>* \ No newline at end of file