From 74f46c1288480666cbe2a6c4c3f6a2f0edf30a9e Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 7 Dec 2020 23:06:12 -0500 Subject: [PATCH] z80a: add ELSE, --- blk.fs | 7 +++---- doc/asm.txt | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/blk.fs b/blk.fs index 5eaccfe..f023d0a 100644 --- a/blk.fs +++ b/blk.fs @@ -300,11 +300,10 @@ CREATE lblnext 0 , ( stable ABI until set in B300 ) : IFC, JRNC, FJR, ; : IFNC, JRC, FJR, ; : THEN, - DUP PC ( l l pc ) - -^ 1- ( l off ) + DUP PC ( l l pc ) -^ 1- ( l off ) ( warning: l is a PC offset, not a mem addr! ) - SWAP ORG @ + BIN( @ - ( off addr ) - C! ; + SWAP ORG @ + BIN( @ - ( off addr ) C! ; +: ELSE, JR, FJR, SWAP THEN, ; ( ----- 027 ) : FWR BSET 0 C, ; : FSET @ THEN, ; diff --git a/doc/asm.txt b/doc/asm.txt index 5d0ccfa..a20731a 100644 --- a/doc/asm.txt +++ b/doc/asm.txt @@ -87,6 +87,11 @@ the opposite condition is met, a relative jump is made to THEN,'s PC. For example, if you have IFZ, a jump is made when Z is unset. +There can be an ELSE, in the middle of an IF, and THEN,. When +present, IF, jumps to it when the condition is unmet. When the +condition is met, upon reaching the ELSE, we unconditionally +jump to the THEN,. + On the BEGIN,..AGAIN, side, it's a bit different. You start with your BEGIN, instruction, and then later you issue a JRxx, instr followed by AGAIN,. Exactly like you would do @@ -96,7 +101,7 @@ On top of that, you have the very nice BREAK, instruction, which must also be preceded by a JRxx, and will jump to the PC following the next AGAIN,. Examples: -IFZ, NOP, THEN, +IFZ, NOP, ELSE, NOP, THEN, BEGIN, NOP, JR, AGAIN, ( unconditional ) BEGIN, NOP, JRZ, AGAIN, ( conditional ) BEGIN, NOP, JRZ, BREAK, JR, AGAIN, ( break off the loop )