2022-04-01 update: Iāve added a link to my full code for a player + computer opponent version of the PIG dice game to the end.
2022-04-06: added a link to a repo with code for my Tiny BASIC games. I have a better opponent AI now, though still quite primitive.
Lately Iāve been getting into BASIC. I was a kid in the 80s and 90s and I remember those computers that would boot into a BASIC interpreter. I didnāt have one of those but came in contact with one every year or two and played a handful of text games on them. I was aware of some of the commands and syntax, GOTO and the like, and I have looked through the classic BASIC Video Games book a number of times. The ecosystem of BASIC interested me but I hadnāt delved too deeply. Recently I read about Tiny BASIC:
Tiny BASIC is a family of dialects of the BASIC programming language that can fit into 4 or fewer KBs of memory. Tiny BASIC was designed in response to the open letter published by Bill Gates complaining about users pirating Altair BASIC, which sold for $150. Tiny BASIC was intended to be a completely free version of BASIC that would run on the same early microcomputers. āWikipedia [1]
So originally, Tiny BASIC was a specification, not an implementation. The Peopleās Computer Company published a newsletter, almost like a photocopied zine to my eyes, with articles, tutorials, comix, all aimed at the nascent hobbyist computer community. They invited Dennis Allison from Stanford Universityās Computer Science faculty to write the spec.
The magic of a good language is the ease with which a particular idea may be expressed. The assembly language of most microcomputers is very complex, very powerful, and very hard to learn. The Tiny BASIC project at PCC represents our attempt to give the hobbyist a more human-oriented language or notation with which to encode his programs. [2]
The newsletter goes on to describe the motivation for the project, a free implementation of the BASIC language, and the community working on it currently. It specifies what the language could entail, how to solve various problems, a discussion on creating a compiler versus an interpreter, what it will take to build oneās own Tiny BASIC, and a request for feedback and ideas. It also contained some simple BASIC games.
All Rights Wronged
One of the earlier implementations was Dr. Li-Chen Wangās Palo Alto Tiny BASIC, where he may have devised the term copyleft to describe this process of source code being openly shared and modified and re-published. He affixed the notice āCOPYLEFT ALL RIGHTS WRONGEDā when he published it in 1976.
BASIC flourished as a language throughout the 80s and into the 90s. Many versions of BASIC proliferated, and many versions of Tiny BASIC as well, including some that grew into more extended versions, sometimes including the ability to create graphics or sound, rather than just ASCII text.
In fact, the inital Tiny BASIC implementations allowed printing text output but couldnāt receive text string inputs. These were very simple implementations of BASIC as it had to work with low memory usage. They allowed for (integer) variables, subroutines via gosub/return, if-statements (though not if-then or if-then-else), numerical though not char/string input, and not much else!
The allowed statements were:
IF - THEN statement
GOTO #
INPUT var
LET var=expression
GOSUB #
RETURN
CLEAR
LIST
RUN
END
Strings werenāt defined in the notes, nor were āremarksā aka comments. Missing also were for-loops, random number generation, arrays, though some of the Tiny BASIC dialects did add these.
I decided to try my hand at making a simple dice gambling game. Where I grew up Threelo was a popular dice game, and my friends had our own house rules. But to warm up, I first implemented Pig, a good first game to program due to its minimal actions and easiness of programming. Essentially, each turn you roll a die and add the total to your points. You can stop at any time and keep that total, or keep rolling. If you ever roll a 1 you lose all the points you accrued. Thatās it! Pretty ā¦.(wait for it)ā¦. basic.
I downloaded Damian Gareth Walkerās Tiny BASIC Interpreter and Compiler project written in C. [3]
It packages a man page and some example games (Hunt the Wumpus, Tic Tac Toe, and some others).
Without a built-in random number generator, how was I going to create a random die roll?
Luckily, Gareth published some instructions to construct a minimal not-very-sophisticated random number generator. [4] We donāt have the privilege of referencing the clock of the computer for example, so we follow early BASIC tradition and ask the user for a seed number, then perform a simple calculation. Some other implementations of Tiny BASIC came with a random number generator. Garethās doesnāt by default but does add in the ability to use REM (remark) for commenting.
lemonade.bas running on Tiny BASIC in CoolRetroTerm
PIG
So hereās my small and not terribly fun or sophisticated game of Pig. No doubt many improvements can be made.
REM --- PIG Dice game test
REM --- Created: 2022-03-30
REM --- Created for cyningstan's Tiny BASIC
REM --- No one will want to use this code, but consider it public domain CC0.
REM --- Variable List
REM
REM R - A random number returned by the Random Number Generator
REM D - Current die roll
REM T - TOTAL SAVED
LET T=0
REM --- Initialise the random number seed
10 PRINT "Enter a number:"
INPUT R
REM --- MAIN GAME LOOP
20 PRINT "YOUR CURRENT TOTAL IS ",T
PRINT "Would you like to roll? (0 no, 1 yes)"
INPUT Q
30 IF Q=0 THEN GOTO 300
REM --- CHECK IF BUSTED
GOSUB 200
LET D=1+R-R/6*6
PRINT "YOU ROLLED ",D
IF D=1 THEN GOTO 50
LET T=T+D
GOTO 20
REM --- BUSTED!
50 PRINT "BUSTED!"
LET T=0
GOTO 20
200 LET R=5*R+35
LET R=R-R/6547*6547
RETURN
300 PRINT "YOUR SCORE IS ",T
PRINT "GOODBYE"
UPDATE: Iāve added a link to a 2 player version (player + computer opponent) I made of Pig dice to the links at the end. Source code license: COPYLEFT ALL RIGHTS WRONGED, natch. There are likely errors as this is the first time Iām programming in any BASIC, and I made this in less than an hour, and sure enough, I was making spaghetti GOTO code! But you are welcome to improve or build upon this in any way you like.
From here, it would be relatively easy to create some version of Blackjack with a little bit more effort. Of course, it would also be fun to make text adventures, pizza-ordering calculators, the classic text game Lemonade Stand, or a version of my favorite BASIC game TI-83 calculator version of Drug Wars/Dope Wars (thatās a story for a different time). To play the game youāll need to download Tiny BASIC. Save the program with a .bas extension. The computer opponent sorely needs better AI than what Iāve implemented.
Thereās a procedurally-generated maze / dungeon adventure game, like a simplified text RPG, called Kingdom of the Lyre that was made for and entered into PROCJAM in 2019. [5] I played it. Itās challenging and I thought it was fun. Iād love to have a Tiny BASIC game jam one day.
To wrap up, Iāll leave you with this WANTED ad from Volume 1, Number 1 of Dr. Dobbās in the section on My, How Tiny BASIC Growed,
WANTED: Entirely new, never before seen, Tiny Languages, imported from another planet or invented here on Earth. Especially languages for kids using home computers that talk to tvs or play music or run model trains orā¦
Links
Wikipedia article on TinyBASIC
Dr. Dobbās Journal of Computer Calisthenics and Orthodontia, January, 1976 - PDF
Tiny BASIC Interpreter and Compiler Portal
Minimal random number generator for Tiny BASIC
Kingdom of the Lyre game
Tom Pittmanās Tiny BASIC User Manual
my Tiny BASIC games repo with a better computer opponent for PIG dice game