Converting 100 Classic BASIC Games to MiniScript
Tags: miniscript, basic, programming, minimicro
Published: 2023-08-25 21:20:44

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](https://blog.codinghorror.com/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](https://miniscript.org).

## Finding and Running the Code

The official github repo is at [github.com/coding-horror/basic-computer-games](https://github.com/coding-horror/basic-computer-games), though I also have [my own fork](https://github.com/JoeStrout/basic-computer-games/tree/miniscript-batch-6) 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](https://github.com/JoeStrout/basic-computer-games/tree/ebefe8a16cc0f2ee03374adfe59b3fba2ff7b673/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](https://miniscript.org/cmdline/), or [Mini Micro](https://miniscript.org/MiniMicro/index.html); a few of them are even small enough to run in the [Try-It! page](https://miniscript.org/tryit/).  But I would recommend using just Mini Micro; it's easiest and provides the best, most consistent experience.  To do that:

0. Clone the repo to your local machine.  Or, download it as a zip file and unpack.  Put it wherever you keep such things.

1. Download Mini Micro for your platform from [here](https://miniscript.org/MiniMicro/index.html) or [here](https://joestrout.itch.io/mini-micro).

2. 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.)

3. Click the upper disk slot below the screen, and pick "Mount Folder..." from the popup menu.
![Screen shot showing "Mount Folder..." menu command on top disk slot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bqocpv7ajh72bknwzovx.png)  Select the 00_Alternate_Languages subfolder of the repo you downloaded.

4. Now you can do everything within Mini Micro.  Use the `cd` and `dir` commands to navigate to any folder, `view` to read a README file, and `load`/`run` to run a MiniScript program.  For example:
![Screen shot showing navigation and running the "animal" program](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6sui2nvw9degoz9vmdc.png)

## 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](https://miniscript.org/wiki/Break) and [continue](https://miniscript.org/wiki/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](https://troypress.com/wp-content/uploads/user/js-basic/index.html)), 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](https://github.com/JoeStrout/basic-computer-games), or just reach out to me via [Discord](https://discord.gg/7s6zajx).  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.