Josh,
Turns out it actually *IS* possible to execute code past the end of an
ELSE block from the IF cod block. And I believe it doesn't violate the
programming contest rules. If you are very careful that is.
The Rules state:
2. The 10 lines must not contain any self-written machine programs
3. All code must be visible in the listing: self-modifying code or
hidden initializations are not allowed
So running a machine language routine is okay as long as it is not
self-written or self-modifying. Initializing A$="blah" with a 5 byte ML
routine and then jumping to it should be okay, so long as it doesn't
modify anything. Given this, it is possible to use a CALL instruction
as the last operation in an IF statement and have it skip over the ELSE
code.
A CALL operation will push the address of the next BASIC instruction to
be executed to the stack (normally held in HL) prior to executing the
CALL. You can pass parameters in A and HL as part of the CALL
instruction. So the idea is to pre-calculate the number of bytes the
ELSE code occupies and then simply skip it by popping that "next
instruction address" from the stack, adding to it and simply returning.
A DAD D or DAD B instruction would be needed, but these don't actually
*appear* in the listing and can't be used. But there is a DAD D, RET at
address 4598H that can be used. So the ML code in A$ would be:
POP D Pop ret address
POP D Get BASIC line address (These are all
characters that will "appear" in a listing of the program.)
JMP 4598H
4598H:
DAD D Add offset to BASIC line
RET Return to BASIC execution at new line location
Then issue a CALL 0,offset BASIC instruction. The only tricky part is
to get "offset" right or the BASIC intrepreter will get lost in it's
parsing of the code. I tested this out with a simple program that I
could provide.
Ken
On 1/30/18 6:16 PM, John R. Hogerhuis wrote:
Download some The Rainbow coco magazines online. They had a one liner
contest ongoing and they printed the winners to fill dead space in the
magazine. Lots of tricks there.
Some things I can think of:
Compute complicated logic and do one IF then else. Traditional
Microsoft basic is “unstructured” definitely no endif.
Use loops even if it’s kind of inappropriate since you can have
multiple loops in the same line.
Tail recursion with goto. Idea is that your single conditional is at
the end of the line and you go back to the same line or proceed to the
next line.
I think the Basic Stack is pretty limited for actual GOSUB recursion
but you could try it
Model 100 basic has some ability to create interrupt / events
handlers. For example, on serial data. I think maybe keys and timers too.
On goto / on GOSUB are good for major control flow.
I don’t know if your contest has limitations on embedded ML. Of course
in ml you can do any possible control flow. You can embed machine
code using data statements or, more efficiently as static strings,
dynamic strings or REM statements.
Also there’s the ROM you can call into.
— John.