On Wed, Jun 18, 2025 at 6:11 AM Alex ... <[email protected]> wrote:

> John,
> This morning I did some poking around with this. MFORTH compiles words
> into memory when you define them and it leaves them there even when you BYE
> out of the interpreter.
>
> I guess in theory to use a FORTH word from BASIC all you'd have to do is
> grab the xt with ', do whatever is necessary to switch to the OPTROM, then
> CALL the xt address of your word. For FORTH : words, the very first
> instruction is always JMP ENTER (C3 5C 01), which is an OPTROM address.
> It's probably going to EXIT back to the MFORTH interpreter after it's done,
> or crash because something wasn't set up right. I'm not enough of a BASIC
> wizard to know how to actually try this from there, but you can re-open
> MFORTH and run a word that got left in memory if you know its xt address
> and it wasn't overwritten.
>
> For assembled CODE words, it might even be easier, since the xt points
> straight to your code. If you leave off NEXT before END-CODE, you might be
> able to avoid returning to MFORTH's interpreter entirely.
>
> If you're curious, MFORTH's memory map and dictionary headers are
> described in src/MFORTH/main.asm
>
>
I will take a look... if using the "compile forth into a CO" approach it
needs a few things. I'm thinking first the CO would be generated into the
filesystem from within MFORTH using some word we'd write.

The CO would be launched by the user clearing space for it to run and
launching it, or by clearing space and just keeping it at its located point
and calling it.

Then you need logic to do the "There and Back Again."

"There" means entering the option ROM forth interpreter with knowledge of
the CO's "main" execution token. So we'd need to put that execution token
(XT) in a register or a fixed location. Or it could be placed on the stack.
So if we CALLed a location in MFORTH, the stacked address could be
considered the COs main XT.

Whatever is called in MFORTH needs to initialize the threaded
interpreter... setting up data and return stack, IP, etc. There's code for
all that there but I think what's new is doing that *and then* running our
passed XT.

"back again" could be just putting a code word at the end of the CO that
warm starts the BASIC interpreter.

So: missing bits are

1. Coding entry/exit boilerplate
2. Writing a CO generator word that can generate a CO with the entry/exit
boilerplate designed to run at a desired location since COs are not
normally relocatable
3. Adding some entry point to MFORTH that does all the interpreter
initialization and then jumps to a user word.

-- John.

Reply via email to