Friday, July 13, 2007

How to run BASIC programs from OptROM

Thinking on how to run BASIC programs from OptROM, I dug up an old Compuserve post from the M100SIG archives.


Fm: Stan Wong 70346,1267
To: Denny Thomas 76701,40

Paul's on the right track about the Basic interpreter. The Basic code never moves but there is a rom call that interprets each tokenized statement. Other rom routines find the next statement to execute. It's been a while but my memory is sort of dim on the subject but each Basic statement in storage is prefixed with the line line followed by the statement tokens followed by a null. Three nulls indicate the end of the program (end-of-statement null followed by a line number of zero).

A small program could switch to the option rom, read a Basic line (tokenized) into ram, switch back to system rom, and then feed it to the interpreter loop. There is no housekeeping since Basic takes care of it. Oops, I forgot, as part of each line I believe that there is also the address of the next statement. That needs to be fixed up also. Anyway, it's a fairly starightforward proposition. If there is any interest I can dive back into my notes and re-figure out what's what (in any case I got all my info from Robert Covington's ROM maps in the DLs).
Seems like that would work. That would sure be something nice to have working for Rex users.

I guess one would have are some initial questions:
  • Where to store the line of BASIC code to be run
  • How do you get to/from the inner interpreter in a way that gets you back to the OptROM? What's the right entry point?
  • What should the "next line" pointer be set to?
  • Is there any initial setup/cleanup that we need to do to ensure we enter properly and exit cleanly back to MENU
  • Ideally since the idea here is to make a turnkey BASIC program it would be nice to make sure we always return cleanly to menu, never get dumped to BASIC prompt. Or if we are using an environment running from OptROM that the user gets returned to that.
Anyway reading some of these old posts it is pretty clear why Idea from URII is so craptastic compared to Thought from SuperROM... Idea is written in BASIC!