Demos included with MiniBASIC

joestrout

JoeStrout

Posted on March 1, 2023

Demos included with MiniBASIC

The recent announcement of MiniBASIC has been met with surprising (and gratifying) enthusiasm! So I thought today I would go over the demos included with it.

You can find these by doing cd demo to change to the demo directory, and then dir to list the files. (Note that in MiniBASIC, unlike in MiniScript, quotes are not require around file names that contain no punctuation; but they're always accepted. So cd "demo" would also work.)

Screen shot of demo directory

Here you find almost a dozen demos of various sizes (plus GAME.TXT, which is a Silver Mountain save file โ€” more on that later). Let's take a quick look at each one.

Alien Letters

To launch the first demo, enter load alienLetters followed by run.

Screen shot of Alien Letters game

This is a game I wrote when I was in middle school, on an Apple ][. I found it somehow still hanging around my hard drive, made minor changes to convert the old sound routine (which relied on poking a small machine-language program into memory) to MiniBASIC's SOUND command, and threw it into the demo directory.

The game is a typing tutor: as letters fall from the top of the screen, you must press the corresponding letter to shoot them before they reach the ground. The game gets harder over time by starting the letters closer to the ground.

The set of letters, and how many fall at once, are both set by line 30 (use list -100 to list up to line 100):

30 LT$ = "ASDFJKL;":NL = 3: REM  LETTERS USED, NO. OF LETTERS FALLING AT ONCE
Enter fullscreen mode Exit fullscreen mode

Currently it's set to the QWERTY home row keys, three at a time. You can retype this line (or use edit 30 to edit it) if you want to change this.

ASCII Table

Screen shot of ASCII table

Despite the name, the asciiTable program displays not only ASCII characters (code points 0-127) but also code points 128-255. This is a handy reference for values you can use with CHR$(n). For example, if you want to print the ยต (mu) symbol, you'll find this in the chart as 181, so PRINT CHR$(181) will do it.

(Keep in mind that MiniBASIC is not case-sensitive, and ? is a shortcut for PRINT, so ? chr$(181) would work just as well.)

This program also demonstrates combining graphics and text โ€” the vertical lines are graphics, done with the PLOT and LINE commands. When the text scrolls, the graphics do not, which may be surprising when you first see it. Use CLS to clear the screen.

Blackjack

This is another program from my youth. It required no changes to get running in MiniBASIC. However, as I was inspecting the code, I did notice a bug: line 360 read

360  PRINT "Shuffling...": FOR A = 1 TO 13: FOR B = 1 TO 4:CU(A,C) = 0: NEXT : NEXT 
Enter fullscreen mode Exit fullscreen mode

This references CU(A,C), when it should have been CU(A,B). So, I finally fixed this bug... 38 years later!

Colors

The colors demo simply draws a color chart, showing the built-in 16-color palette (which is the same as the Commodore 64).

Screen shot of color table

You can use these numeric values with the COLOR command. For example, COLOR 8 will change both the text and the graphics-drawing color to orange. You can also use strings with arbitrary HTML colors, whether they're part of the standard palette or not. For example, COLOR "#FFCCCC" will get you a light pink. Use COLOR 5 to go back to the default green.

Drawing

The drawing program demonstrates the six drawing commands in MiniBASIC: PLOT, LINE, RECT, ELLIPSE, POLY, and IMAGE.

Screen shot of drawing demo

You just press the number of the one you want to see, and then watch as it both shows the code and the result of using that command.

One thing this demo does not currently demonstrate is the PEN command, which changes the line thickness of subsequent drawing. Try adding 59 PEN 4 to see what that looks like.

Lemonade

This one is an in-progress port of the original Lemonade Stand game from Apple, circa 1979. This classic game was perhaps the first economic simulation game to reach the general public, and was hugely popular.

It's still in-progress because of two things:

  1. It uses the Apple's "low-resolution graphics" mode, which doesn't port easily to MiniBASIC. And it does it via some funky tricks, like printing characters to the text screen which, when lores graphics are turned on, happen to form blocks of color. Yikes.

  2. It also uses a machine-language routine to make music. I have attempted to convert the parameters to this routine into the corresponding notes four our SOUND command, but it's not quite right, so the music is a bit out of tune.

So I will keep working on it. Unless some kind and ambitious reader out there wants to help โ€” pull requests are gratefully accepted!

Silver Mountain

silverMountain is the complete code from the Usborne book Mystery of Silver Mountain. To get this code into MiniBASIC, I first tried OCR (optical character recognition), but it didn't do very well. So I ended up just typing it in, line by line, just like we would have done in the old days.

Then I spent a couple days debugging it... also like we would have done in the old days!

Screen shot of Silver Mountain game

But now I believe it to be complete and correct. But I must warn you: this is a hard game! You will need to actually read the book and study the pictures for clues. For example, just because nothing on the screen says there is a pot, doesn't mean you don't have to "EXAMINE POT" to find some critical item. The pictures in the book are the only way you would know to do this.

I did make some minor enhancements to the original program: I made it accept both lowercase and uppercase text, and I added a few synonyms, like "LOOK" for "EXAMINE", as well as a "QUIT" command. You'll find my changes on lines 270 and 351-359.

Sounds

The sounds program demonstrates usage of MiniBASIC's SOUND command.

Screen shot of sounds demo

Again, you just press the key of the demo you want to run; but in this case, it just plays the sound. The code for each demo is already on the screen.

The SOUND command takes four parameters:

  1. frequency (if > 0) or note (if <= 0), or array of same
  2. duration (in seconds)
  3. volume (0-1, or an array of values 0-1)
  4. waveform (0-4)

By varying these parameters, you can make a variety of interesting sounds, all very much in character for the first wave of home computers.

Spirograph

This is a very simple drawing demo, using a little bit of SIN and COS to draw a many-pointed star. This demo (and its code) were featured in the original announcement.

Star

star is a neat little program I found over on a forum called Basic4All. It draws an 8-pointed star on the text screen.

Screen shot of star demo

It does this with surprisingly little code, using TAB to position the cursor.

5 CLS
10 FOR m = 5 TO 9
20 FOR n = m - 4 TO 22 - m
30 PRINT TAB(27 + m, 3 + n); "*"
40 PRINT TAB(27 + n, 3 + m); "*"
50 PRINT TAB(27 + 18 - m, 3 + n); "*"
60 PRINT TAB(27 + n, 3 + 18 - m); "*"
70 NEXT n
80 NEXT m
90 VTAB 24 : END
Enter fullscreen mode Exit fullscreen mode

10 Print

Finally, the tenPrint program is our version of the classic 10 PRINT demo:

Screen shot of tenPrint demo

The core of this program is the 1-line infinite loop:

10 PRINT CHR$(47 + 45 *(RND(1) > 0.5)); : GOTO 10
Enter fullscreen mode Exit fullscreen mode

This is slightly different from the famous Commodore 64 version, because that uses the PETSCII character set which has diagonal lines at code points 205 and 206. We have to use slash and backslash, which are at code points 47 and 92. But otherwise, it's basically the same.

To break out of this infinite loop, just press Control-C.

Wrap-up

And that's it for the contents of the demo directory, at least at the time of this writing. I will probably add a few more as time goes on.

Do you have some cool BASIC code lying around, or an idea for a new MiniBASIC program? Let me know! Maybe I'll include it as a demo (with attribution, of course) in a future update to MiniBASIC!

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
joestrout
JoeStrout

Posted on March 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Demos included with MiniBASIC
programming Demos included with MiniBASIC

March 1, 2023

ยฉ TheLazy.dev

About