BerandaComputers and TechnologyPalo Alto Tiny Basic in the Browser

Palo Alto Tiny Basic in the Browser

Martin Malý has adapted Version 2 of Li Chen Wang’s Palo Alto Tiny BASIC to run on his ASM80 browser-based assembler and emulator. I’ve uploaded the source code, with his permission, to GitHub.

Background

Palo Alto Tiny BASIC emerged out of the Tiny BASIC movement started by People’s Computer Company and taken up by the Homebrew Computer Club. Fellow members Steve Wozniak and Tom Pittman would develop their own BASICs (Integer BASIC and 6800 Tiny BASIC respectively). Wang analyzed the Altair BASIC code and contributed edits to Tiny BASIC Extended. Wang published in the newsletter a loader for the 8080, commenting on the Open Letter to Hobbyists:

Altair Basic has a bootstrap loader of twenty or twenty one bytes long. In principle, you can use this bootstrap to load in your own loader which will then load in your program. However, since Mr. Bill Gates claims that he did not yet payed [sic] enough and is in the mood of calling people thieves. (See HBCC newsletter ’12-1.) I decided to code one myself. What comes out is a bootstrap of sixteen bytes long. This is still too long, maybe our professional experts can make it shorter. For the time being you are welcome to copy mine and I will not call you a thief (this includes Mr. Gates).

No surprise then that Li Chen Wang made his BASIC implementation available for free. (I found this quote reading old Homebrew newsletter articles in my research for the BASIC interpreter article.)

The only smaller implementation of Tiny BASIC was MINOL, which used unsigned bytes instead of signed integers and which used nonstandard commands. Also weighing in under 2kB, when a common method of shipping interpreters was 4kB ROMs, Palo Alto Tiny BASIC supported a more typical version of the language while leaving extensive room for customization for specific hardware, something which was taken advantage of multiple times, for the TRS-80, the Bally Astrocade, the Sharp PC-1211, and the Cromemco.

The Code

It’s been fun to play with the source code that was behind three of the computers I used as a kid. Some things I learnt:

  • The code is very well structured and extensible. I added a few commands in under an hour (PEEK, FRE()). All you need to do is insert new commands in the keyword table, then adapt code elsewhere.
  • I was very excited to find a few small bugs in the code:
    • The system famously had only three error messages (“WHAT?” for syntax errors, “HOW?” for functional errors, and “SORRY” for capacity issues). If you execute a RETURN with no corresponding GOSUB you get a  “WHAT?” instead of a “HOW?”
    • 10 INPUT “HELLO WORLD” acts like a valid PRINT statement when it should cause a syntax error, since no variable is specified to receive the input.
    • The language only supports integers, but decimals aren’t ignored as they should be. PRINT 1.1, 1.2 outputs 1 and 0.
  • There’s an Easter egg! “W”, “AN”, “G”

RST 1 Routine

The RST 1 routine is a work of art, using the call stack to determine where its parameters are, with the byte after RST 1 specifying the character to match and the byte after that specifying the offset to jump to. Wang’s ability to write such memory-efficient code is why he didn’t need to implement the IL virtual machine.

I encourage you to check out the source code for yourself.

Read More

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments