Close

Design Strategies

A project log for Fungesector

A Befunge-93 interpreter which runs on x86 real mode

louis-paulLouis Paul 09/24/2024 at 01:410 Comments

Now that the "Hello sector" result was shown, it's time to design the Befunge-93 interpreter to run in real mode. The interpreter needs an editor where you can type the code and press the arrow keys to move the cursor, a location where you can load pre-stored codes and save the code you've written, an output display, an options screen to change the defaults and behaviors of interpreter and some help docs to explain how to use the interpreter.

How can I put all of these things on the program? I was looking in the docs of BIOS interrupts and there was an interrupt called INT 10,5 - Select Active Display Page. This is a interrupt where you can switch to a new display page of video adapter. Using mode 0x03 on VGA adapter there are 8 display pages available to use.

I imagined a kind of state machine to switch from a display page to another (for example, press any key to go to edit screen, press F1 to go to help page, press F5 to go to output display and run the code). Here is the draft of state machine that I imagined (made with JFLAP):

For interpreting the Befunge code, I'll use the technique usually used to implement videogame emulators (like the NES or Game Boy). This technique is called Fetch-Decode-Execute cycle:

The output display will operate like a teletype and you can use the keyboard when prompted for input. When the program ends, it should appear a message indicating that the program has finished and the user should press any key to go back to the editor.

For the case of infinite loop or to stop a running program before the end, the Ctrl-Break key should be pressed (there is a int 0x1b which handles this key). And when the program has a runtime error (like a unknown command), the program should be halted with a error message.

Discussions