8-bit BASIC virtual machine?

For several years now, I have been diving down a number of different rabbit holes in my quest to find a way to create text adventures for modern and retro 8-bit machines.

In this sometimes random quest I keep encountering the concept of creating interpreters or virtual machines to increase compatibility across platforms.

Recently, I began to wonder if it would be possible or practical to create a virtual machine for 8-bit machines that could run BASIC programs that had been written and converted to suitable byte code on a modern PC.

My idea would include creating up to three virtual machines for each physical machine. One for ANSI Minimal BASIC, one for ANSI Full BASIC and one for ANSI Full BASIC with the optional graphics module.

The latter is unlikely to be possible for every 8-bit system, as memory size and graphics capabilities varied so much.

The main advantages to this system would be that the same code could run on multiple machines and that it should (in theory) be faster than interpreted BASIC.

Has anything like this been tried before? Is it remotely possible or practical?

3 Likes

If I understand the question properly, the 8-bit BASIC virtual machine concept has been around at least since the People’s Computer Company Tiny BASIC project in 1975, although they called it an “intermediate language”. Multiple machines, yes; faster, no.

3 Likes

Basic 09 for OS/9 ( 6809 ) had two versions if remember right. B-code for compact code,
and machine code for speed. Pascal P-code was weird, it ran as virtual system. With
a single floppy I did not play with both much on the coco.

I’m presuming you know about the Zcode stuff from Infocom? (and many others now)

-Gordon

1 Like

@Michael_Barry That looks promising. At least I know it’s not a completely impractical idea.


@oldben I’ve heard of Pascal P-code, but have never used it. I don’t remember it being available for any of the 8-bit computers I owned.

Did it work on tape-based machines?


@drogon Infocom’s Z-machine was designed to be used on systems with a disk drive to load data during play. I want something that works with tape-based systems.

Level 9’s A-machine would likely be a good fit, but I’d need to reverse engineer that system as the source code is not (yet) available.

Looks like you might be after the ultimate holy grail of “write once, run anywhere”… Which Java was supposed to be, but it won’t run on 8-bitters… However…

Plasma may be at least worth a read:

The other thing (close to my heart) is BCPL. This traditionally compiles into a bytecode (In the same way P-System Pascals, Java, and (I think) Python and in then interpreted on the target machine.

Can it run on tape systems? Yes - the BBC Micro had a working BCPL implementation which could let you boot the system off an internal ROM, then load the editor from tape, edit your code, then run the compiler off tape to compile then link your code.

BCPL is on-going and while it might be an interesting challenge to make it work from tape on a Beeb again it can be done.

And mentioned above; Java and Python. There are micro Python version(s) out there too.

All you need to do is write your “Basic” in your universal implementation language - or use it directly.

Or, since you’re interested in Adventure games (as am I), then you write a “portable” compiler/interpreter then port it to each platform 8, 16, 32, 64 bits, etc. as required.

For the smaller systems then cross compiling would probably be acceptable.

There are some adventure game writing kits out there which I’m sure you’ve found - I think at least one is open source, but it’s a while since I’ve looked.

-Gordon

1 Like

Hadn’t there been such a common-ground BASIC subset that would run on multiple popular machines with the help of subroutines at well known line numbers for any machine specific tasks? I try to remember what this was, but I can’t recall at the moment, while I’ve certainly seen sources for this. It must have been associated to some newsletter or magazine, I guess. Also, I don’t know what computers were actually supported.
(This would have been limited to simple, line oriented input and output, and only the simplest kind of conditions, of course. Even things like AND and OR would have been to be avoided, I suppose. But it would have been good enough for a [rather simple] text adventure.)

Anyway, this would probably be the way to do it:

  • Identify a close to universal subset (not “IF…THEN <line-number”>, or “IF … GOTO”, but “IF … THEN GOTO”; no ELSE, only simple INPUT and PRINT, FOR…NEXT, assignments using LET, etc)
  • probably single-character variable names only
  • only simple, one-dimensional arrays
  • define a library of subroutines for any complex operations and their line numbers, reserve some variable names for data exchange (clear screen, find string in another string, get a random number for a given range, etc)
  • implement the library for any target computer
  • identify a viable memory limit
  • write the control code, AKA “the program”, using the identified subset and sticking to memory limits (including the subroutine library)
  • an effective program consist of the control code and the reusable library code. Meaning, this would be still dedicated to a specific computer, but it would provide a common platform for type-in programs.

But, I’m afraid, the practical limitations are quite severe…

1 Like

Sounds like BASICODE… mentioned previously a few times
https://retrocomputingforum.com/search?q=BASICODE%20order%3Alatest

2 Likes

Is this repository useful?

1 Like

Why not use an (existing) emulator?
Text adventures (without gfx) should work on most computers when using few and simple instructions.
Like the ones from Creative Computing.
But you will always have limitations (different file formats, media, screen resolution etc).
So you would have to make adjustments for most machines, and so you are close to emulators.

You had a similar post

There also was a similar post with graphics,

1 Like

Hey there, Wysardry!

We might have a somewhat similar vision. Starting a year and a half back I developed Continuum 93, a fantasy retro computer having in mind many of the points you also expressed the difference being I wrote the CPU from scratch along with its assembly instructions architecture. It’s a versatile little machine, maybe you’d like to take a look at some of the specs.
The vision for it is indeed enabling developers to write retro-games the old-fashioned way, but with some modern twists and helpers and offcourse be able to deploy on other platforms/handhelds. This is still an ongoing process and I also plan on implementing BASIC interpreters/compilers for it. Maybe even a C compiler if time allows me. Or, anyone willing to write their own, they can also pick that up.

But, as the author, I am also biased in favor of my own project and looking at your efforts, I think it’s best for you to look around and see what others have done as well. Here’s a nice list that someone on this forum was also kind enough to show to me: GitHub - paladin-t/fantasy: A curated list of available fantasy consoles/computers.

Maybe it helps crystalize what you envision doing, whether it would be adopting one of those existing projects or writing your own. If you plan on writing your own, try to aim writing it as simple as possible, without external libraries that you might have difficulties with when trying to go cross-platform.

That being said, (and coming back to my bias) I do think Continuum is a very good platform for you to write such games, so I’d welcome you to give a critical look at this project. We also have a minuscule community that’s growing and someone even wrote the first game for it.

If you decide to write something on your own, I’d also be interested to see your project (and I’d probably not be the only one), so don’t be a stranger. :wink:

Cheers!

2 Likes

Wow. There’s a lot of potentially useful info here. I’ll try to respond to as much as I can.

@drogon Write once run anywhere is kind of what I’m aiming for, as long as “anywhere” only includes platforms with a keyboard.

Adding more platforms to FreePascal would be one way of achieving that. Another would be to add more interpreters or virtual machines to an existing text adventure system.

Yet another would be to create the 8-bit virtual machine I originally mentioned.

PLASMA does look interesting. I’ve added to my (many) bookmarks.

BCPL is helpful as an example of what can be done. The language itself would be less useful to retro enthusiasts than BASIC though.

I know about most of the more popular existing text adventure (aka interactive fiction these days) systems, but most require a disk drive.

@NoLand I would likely start off by testing a small subset of BASIC, but I would be aiming for Minimal BASIC. I believe that Vintage BASIC follows that standard reasonably closely.

Of course, before that I am hoping to set my sights a little lower and attempt a simpler system.

@davidb I have that repository bookmarked. One of the possibilities I have been considering is attempting to reverse engineer Level 9’s A-code system, as it was designed for 8-bit tape-based systems (unlike Infocom’s Z-machine).

Others are actively exploring the old games and one of the Austin brothers is trying to get all the original code together and update the tools for modern machines. Nobody seems to know how long that might take though.

The main problem is that only the opcodes they used are (mostly) known. The coding language is a mystery and the only virtual machine is for modern computers.

To complicate matters, there were 4 different versions of the virtual machine created over the years.

@mainframetom If you mean an existing virtual machine, then there aren’t any publicly available for the machines I wish to support. There are emulators of the physical machines though.

I’m only interested in creating text-based programs, so that should reduce the number of differences between machines. I might add graphics capabilities to a couple of them, but I wouldn’t attempt it for every platform.

Others with greater knowledge of such systems could potentially expand the code, if they wanted graphics badly enough.

Whatever I come up with should be able to produce code for physical machines, preferably by loading from physical tape or a digital recorder. There are existing utilities to convert program files to an audio format.

Yes, I’m still looking for a similar system to the one I mentioned in my previous thread.

@EnthusiastGuy I hadn’t considered supporting fantasy computers. It’s an interesting idea.

If I manage to get something up and running for real retro machines, I will explore doing the same for fantasy emulators, depending on what programming tools are available for them.

Rather than adding a disk drive, or tape , perhaps a wi-fi connection may be more useful
if building new hardware.

Sorry? Who mentioned building new hardware?

If you find a good way of accomplishing that for several other hardware computers, I’d be happy to offload the implementation of it for my machine and take care of that. I also designed a flavor of BASIC for Continuum, but there can be as many implementations as one wants. Keep us in the loop and good luck! :slight_smile:

I think I will most likely start with a smaller simpler project, such as rewriting the existing Level 9 interpreter/VM in a language other than C.

I can then move on to creating a suitable byte code compiler for modern platforms or attempt to recreate an 8-bit VM.

The main problem with the former is that nobody outside of the Level 9 team knows what A-code source looks like other than “a bit like BASIC”.

1 Like

I think that other than FORTRAN (and maybe Algol) BCPL ought to be the ultimate in retro languages - however in terms of popularity I suspect I can count the number of active users with 2 binary digits, and I’m one of those 3…

As for writing an adventure in it - one fairly famous MUD was written in it once upon a time… (MUD2, Essex)

But sadly, popular, it’s not, but it does run on 8 through 64 bit systems… Just write/adapt the bytecode interpreter then write a portable run-time library and off you go …

One other thing I’ve just thought of though - Lua. It’s “embeddable” in other languages and systems, but I really don’t know much about it.

-Gordon

I’ve stumbled upon this, not sure whether it can be of help, but said to mention it.

Most owners (or former owners) of 8-bit home computers are likely to be at least slightly familiar with BASIC as it was usually available as soon as the machine was switched on.

Books and magazines of the time also rarely used anything other than BASIC in program listings.

From what I remember, Pascal was probably the second most popular language of the time.

Lua might be an option for those that have used it for modern game mods, but I don’t know of a version small enough to run in 64Kb or less.

There is a language called Nelua that compiles to C though, so it might be possible to use it with an 8-bit C cross-compiler.

@EnthusiastGuy I have that and the original PC version bookmarked. There’s also a Sinclair QL port.

1 Like