Trying out BASIC

Trying out BASIC

A little while ago, Usborne released some of their classic 80s programming books for free[1]. While it may not a have been a complete collection, it's still pretty cool to be able to experience such an elegant piece of computer science history.

The books were aimed at teaching kids to program in the Beginner's All-purpose Symbolic Instruction Code (BASIC) programming language. It's a high level general purpose language that aimed to lower the barrier to entry to other languages at the time like FORTRAN.

Since quite a number of readers were so fond of these books[2], I wanted to get a sense of what they experienced exploring the material. This motivated me to completely ignore the disclaimer on Usborne's website -

Please note
These books were written for 1980s computers such as the ZX Spectrum and BBC Micro. The programs will not run on modern computers...

and give BASIC a try by reading and entering some of the examples given in the books.

Getting Basic

The first step was getting a basic interpreter or compiler. This was not as straight forward as one would assume because there are many flavors/dialects[3] of Basic. Some of the books even had to provide short basic conversion charts to help readers write BASIC code compliant with their platform.

Example BASIC conversion chart

Although there are a lot of perfectly good emulators and interpreters online, such as jsbeeb a javascript bbmicro emulator and Applesoft BASIC in Javascript, I wanted something offline. With a bit of Googling, my options came down to mostly[4],

  1. Chipmunk Basic
  2. Free Basic - I ended up going with this
  3. Brandy Basic

I ended up going forward with FreeBasic not for any reason in particular other than it just seemed like the best one to go with. Installing the tools was simple enough.

By referencing instructions in their installation guide, I wrote a small vagrant script which provisions a VM, installs the needed dependencies as well as downloads and Installs the compiler

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/trusty64"
  config.vm.provision "shell", inline: <<-SHELL
      
      sudo apt-get update
      sudo apt-get --assume-yes install gcc libncurses5-dev libffi-dev libgl1-mesa-dev libx11-dev libxext-dev libxrender-dev libxrandr-dev libxpm-dev
      wget "http://downloads.sourceforge.net/project/fbc/Binaries%20-%20Linux/FreeBASIC-1.05.0-linux-x86_64.tar.gz"
      tar zxf FreeBASIC-1.05.0-linux-x86_64.tar.gz
      cd FreeBASIC-1.05.0-linux-x86_64
      sudo ./install.sh -i

    SHELL
  end

Programming in BASIC

It's pretty simple enough getting started.

You write your code in a *.bas file, compile by invoking fbc on said file, then run the generated executable to see the output.

Interestingly, unlike most modern programming languages, BASIC is not case sensitive meaning that the print commands used in the following lines of code are functionally equivalent.

PRINT "B: Do you feel in charge?"
print "D: ... I paid you a small fortune!"
Print "B: And this give you...power over me?"

As expected, there were issues running examples used in the book straight out of the box. Using the default settings, some commands like LET and $ suffixes didn't work.

Using the default settings, some commands like LET and $ suffixes didn't work.

This meant that this examples such as this wouldn't compile

LET B = 365
LET D$ = "DAYS IN THE YEAR"
LET L$ = "EXCEPT LEAP YEAR"

PRINT B
PRINT D$
PRINT L$

END

but instead return an error message similar to the following

HelloWorld.bas(1) error 145: Only valid in -lang deprecated or fblite or qb, found 'LET' in 'LET B = 365'

To resolve this we will have to compile using the fblite language dialect[5] using the -lang flag

$ fbc -lang fblite HELLO.bas

Once compiled, you can run the program using the generated executable.

$ ./HELLO

 365
DAYS IN THE YEAR
EXCEPT LEAP YEAR

Conclusion

After playing with it for a while, a good chunk of the code works. However, there are still a couple of compatibility issues. For example,

PRINT TAB(15, 9)

doesn't compile since there is no tab function that allows a row offset to be specified.

PRINT TAB(15); "Hello World"

>               Hello World

In conclusion, I guess part of the appeal is figuring out ways of porting over and adapting ideas learned from the text over to your own platform- Guaranteed to be hours of fun :)

Basically, RTFM!

Footnotes and References

  1. See this Reddit thread for instructions on how to download them all at once ↩︎

  2. Discussion on HackerNews and r/programming ↩︎

  3. These links worked as of the time of this writing, The previous direct download links were removed and replaced with Google Drive links. ↩︎

  4. This is not nor does it pretend to be a complete list. ↩︎

  5. https://en.wikipedia.org/wiki/List_of_BASIC_dialects ↩︎

Subscribe to Another Dev's Two Cents

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe