diff --git a/blk/204 b/blk/204 index 2ec567c..5a1e462 100644 --- a/blk/204 +++ b/blk/204 @@ -8,3 +8,9 @@ byte that is taken care of. We still need to adjust by another byte before writing the offset. + + + + + + (cont.) diff --git a/blk/205 b/blk/205 new file mode 100644 index 0000000..46a587a --- /dev/null +++ b/blk/205 @@ -0,0 +1,16 @@ +Structured flow + +z80a also has words that behave similarly to IF..THEN and +BEGIN..UNTIL. + +On the IF side, we have IFZ, IFNZ, IFC, IFNC, and THEN,. When +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. + +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 +with a label. + + (cont.) diff --git a/blk/206 b/blk/206 new file mode 100644 index 0000000..7cb441a --- /dev/null +++ b/blk/206 @@ -0,0 +1,3 @@ +On top of that, you have the very nice BREAK, instruction, +which must also be preceeded by a JRxx, and will jump to the +PC following the next AGAIN, diff --git a/blk/246 b/blk/246 index ab00527..89581ad 100644 --- a/blk/246 +++ b/blk/246 @@ -1,13 +1,16 @@ ( Place BEGIN, where you want to jump back and AGAIN after a relative jump operator. Just like BSET and BWR. ) : BEGIN, PC ; -: AGAIN, PC - 1- A, ; - : BSET PC SWAP ! ; -: BWR @ AGAIN, ; ( same as BSET, but we need to write a placeholder ) : FJR, PC 0 A, ; : IFZ, JRNZ, FJR, ; : IFNZ, JRZ, FJR, ; : IFC, JRNC, FJR, ; : IFNC, JRC, FJR, ; +: THEN, + DUP PC ( l l pc ) + -^ 1- ( l off ) + ( warning: l is a PC offset, not a mem addr! ) + SWAP ORG @ + BIN( @ - ( off addr ) + C! ; diff --git a/blk/247 b/blk/247 index e905c43..e0d77cc 100644 --- a/blk/247 +++ b/blk/247 @@ -1,9 +1,8 @@ -: THEN, - DUP PC ( l l pc ) - -^ 1- ( l off ) - ( warning: l is a PC offset, not a mem addr! ) - SWAP ORG @ + BIN( @ - ( off addr ) - C! -; : FWR BSET 0 A, ; : FSET @ THEN, ; +: BREAK, FJR, 0x8000 OR ; +: BREAK?, DUP 0x8000 AND IF + 0x7fff AND 1 ALLOT THEN, -1 ALLOT + THEN ; +: AGAIN, BREAK?, PC - 1- A, ; +: BWR @ AGAIN, ; diff --git a/blk/291 b/blk/291 index 0ab0445..d4e025f 100644 --- a/blk/291 +++ b/blk/291 @@ -13,4 +13,4 @@ PC ORG @ 4 + ! ( find ) NEG, A DECr, ( special case. zero len? we never find anything. ) - JRZ, L1 FWR ( fail-B296 ) ( cont. ) + IFNZ, ( fail-B296 ) ( cont. ) diff --git a/blk/293 b/blk/293 index 8e46e96..fa542eb 100644 --- a/blk/293 +++ b/blk/293 @@ -9,8 +9,7 @@ HL DECss, LDA(DE), (HL) CPr, - JRNZ, L2 FWR ( loopend ) + JRNZ, BREAK, DJNZ, AGAIN, - L2 FSET ( loopend ) THEN, ( cont. ) diff --git a/blk/296 b/blk/296 index 11cceb6..9e8b9b2 100644 --- a/blk/296 +++ b/blk/296 @@ -1,4 +1,4 @@ - L1 FSET ( fail ) + THEN, ( zero length check, B291 ) A XORr, A INCr, L2 FSET ( end ) diff --git a/blk/328 b/blk/328 index b8f3ed0..2ac50ad 100644 --- a/blk/328 +++ b/blk/328 @@ -2,15 +2,13 @@ CODE S= DE POPqq, HL POPqq, chkPS, - BEGIN, ( loop ) + BEGIN, LDA(DE), (HL) CPr, - JRNZ, L1 FWR ( not equal? break early to "end". - NZ is set. ) + JRNZ, BREAK, ( not equal? break early. NZ is set. ) A ORr, ( if our char is null, stop ) HL INCss, DE INCss, - JRNZ, AGAIN, ( loop ) -L1 FSET ( end ) + JRNZ, AGAIN, PUSHZ, ;CODE