Converting 100 Classic BASIC Games to MiniScript
JoeStrout
Posted on August 25, 2023
On New Year's Eve, 2021, Jeff Atwood (of "Coding Horror" fame) wrote a post called Updating the Single Most Influential Book of the BASIC Era. The book was BASIC Computer Games (Microcomputer Edition), and it contained 101 short programs in the BASIC computer language. This book from the late 70s influenced an entire generation, showing the world what could be done with a few pages of program code.
In his post, Jeff proposed an audacious idea: let's convert these old BASIC games to modern computer languages. I think it's a great idea. So, naturally, I and some helpers are converting them to MiniScript.
Finding and Running the Code
The official github repo is at github.com/coding-horror/basic-computer-games, though I also have my own fork with the very latest ports. In either case, you'll find the MiniScript ports down under the 00_Alternate_Languages part of the tree. For example, if you navigate into 00_Alternate_Languages/03_Animal/MiniScript, you'll find animal.ms
, the MiniScript port of the animal.bas
BASIC game.
Each port folder contains a README file that explains how to load and run that particular program. But they're all pretty much the same. These programs can be run using command-line MiniScript, or Mini Micro; a few of them are even small enough to run in the Try-It! page. But I would recommend using just Mini Micro; it's easiest and provides the best, most consistent experience. To do that:
Clone the repo to your local machine. Or, download it as a zip file and unpack. Put it wherever you keep such things.
Unpack and launch Mini Micro. (If your OS gives you a security warning, right-click it and select "Open"; this happens because the app is not yet code-signed.)
Click the upper disk slot below the screen, and pick "Mount Folder..." from the popup menu.
Select the 00_Alternate_Languages subfolder of the repo you downloaded.Now you can do everything within Mini Micro. Use the
cd
anddir
commands to navigate to any folder,view
to read a README file, andload
/run
to run a MiniScript program. For example:
Porting Challenges
In some ways, MiniScript is very similar to BASIC. The syntax for an if
/then
/else
block, or even a print
statement, looks almost the same. But there is one big difference:
BASIC makes extensive use of the GOTO
statement.
The GOTO
(pronounced "go to") statement makes the program "jump" directly from wherever it is encountered, to some other part of the code, identified by line number. And that could be anywhere in the code. It can jump out of a loop; it can jump into a loop. It can jump into the middle of what we'd think of as an if
block. It can literally go anywhere. (And the BASIC IF
statement can do the same thing, even if it doesn't explicitly say GOTO
.
Now, use of GOTO
doesn't have to result in spaghetti code. BASIC also supports subroutines, which are like simple methods; with subroutines and a little discipline about how you jump around with GOTO
and IF
, one can write very clean, maintainable code in BASIC. But... most of these programs are not written that way. We have to remember that not only was BASIC brand new, programming itself was fairly new, at least in any high-level language. Good practices hadn't been established yet.
As a result, many of the programs in here are hopeless piles of tangled-up spaghetti, jumping around willy-nilly in ways that are literally impossible in any modern language.
Our mandate in this project is to rewrite the programs using clean, modern code. But it's also to reproduce the behavior of the original program as closely as possible. That can be very hard to do when you're staring at four pages of messy, interwoven code, as it's not even clear what all it all does. So in some cases, we end up porting almost line for line, turning GOTOs into deeply nested while loops (which, thanks to break and continue, can jump in a more limited way that covers some uses of GOTO
).
Current Progress
At the time of this writing, the first 52 programs have been ported to MiniScript, along with another 8 of the last 50 (because I started by porting the shortest programs first, before going back and tackling the rest in numerical order).
For many of the programs, MiniScript is the only "alternate language" implemented. When we finish the rest of the programs, we will certainly be the only alternate language to do so.
How to Help
Want to try your hand at the challenge? There are still 40 programs that need to be translated! Pick any one that doesn't yet have a MiniScript folder. Perhaps start with one where the BASIC code isn't too long and seems fairly clear. Run the BASIC code (which you can do on the web here), so you're sure you understand what it does, and then write nice clean MiniScript code that does the same thing.
You can submit a PR to my github repo, or just reach out to me via Discord. We'll get your code into the next batch of updates to go to Jeff!
Together, we'll build a library of programs that preserve these classic games from the very dawn of home computing, and provide fun sample code for anyone curious about MiniScript or looking to improve their MiniScript skills.
Posted on August 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.