Running BASIC Code from OptROM: Difference between revisions
Line 5: | Line 5: | ||
== Short Conversation from M100SIG == | == Short Conversation from M100SIG == | ||
Fm: Stan Wong 70346,1267 | Fm: Stan Wong 70346,1267 To: Denny Thomas 76701,40 | ||
To: Denny Thomas 76701,40 | |||
Paul's on the right track about the Basic interpreter. The Basic code never | Paul's on the right track about the Basic interpreter. The Basic code never | ||
moves but there is a | moves but there is a ROM call that interprets each tokenized statement. Other | ||
ROM routines find the next statement to execute. Its been a while but my | |||
memory is sort of dim on the subject but each | 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 | 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 | null. Three nulls indicate the end of the program (end-of-statement null | ||
followed by a line number of zero). | followed by a line number of zero). | ||
A small program could switch to the | A small program could switch to the OptROM, read a BASIC line (tokenized) | ||
into | into RAM, switch back to system ROM, and then feed it to the interpreter loop. | ||
There is no housekeeping since | 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. | of each line I believe that there is also the address of the next statement. | ||
That needs to be fixed up also. | That needs to be fixed up also. Anyway, it's a fairly starightforward | ||
proposition. | 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 | re-figure out what's what (in any case I got all my info from Robert | ||
Covington's ROM maps in the DLs). | Covington's ROM maps in the DLs). |
Revision as of 11:37, 22 February 2008
This is a place for collecting thoughts on how to embed and run BASIC code in an OptROM. Clearly, this is possible since UR2 implements Idea as a BASIC program.
Short Conversation from M100SIG
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. Its 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 OptROM, 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).
Thoughts from Ken Pettit
I have looked a the BASIC interpreter quite a bit. The main program execution loop (for M100) is at address 0804h. The first few function calls perform things like checking for ON COM, ON TIME, CTRL-BREAK, etc. The middle part executes the next instruction, and the last part steps forward to the next instruction / line #. This routine would have to be rewritten to run in RAM and fetch BASIC lines from OptROM. Additionally, the routine below it would have to be rewritten too - it pushes the 0804h return address on the stack that most BASIC instructions use by doing a simple "RET' . This would have to push the address of the re-written RAM based loop.
The problem areas will be in handling the ON TIME, ON COM, ON KEY, and STOP (CTRL-BREAK uses the STOP instruction). From what I remember, these perform an absolute "JMP" into the ROM which then lead back to the 0804h loop and/or search for line numbered BASIC lines in RAM.