BASIC: Cross-Platform Software Hacking Then And Now

Surely BASIC is properly obsolete by now, right? Perhaps not. In addition to inspiring a large part of home computing today, BASIC is still very much alive today, even outside of retro computing.

There was a time, not even that long ago, when the lingua franca of the home computer world was BASIC. This wasn’t necessarily always the exact same BASIC; the commands and syntax differed between whatever BASIC dialect came with any given model of home computer (Commodore, Atari, Texas Instruments, Sinclair or any of the countless others). Fortunately most of these licensed or were derived from the most popular microcomputer implementation of BASIC: Microsoft BASIC.

BASIC has its roots in academics, where it was intended to be an easy to use programming language for every student, even those outside the traditional STEM fields. Taking its cues from popular 1960s languages like FORTRAN and ALGOL, it saw widespread use on time-sharing systems at schools, with even IBM joining the party in 1973 with VS-BASIC. When the 1970s saw the arrival of microcomputers, small and cheap enough to be bought by anyone and used at home, it seemed only natural that they too would run BASIC.

The advantage of having BASIC  integrated into these systems was obvious: not only were most people who bought such a home computer already familiar with BASIC, it allows programs to be run without first being compiled. This was good, because compiling a program takes a lot of RAM and storage, neither of which were plentiful in microcomputers. Instead of compiling BASIC source code, BASIC interpreters would interpret and run the code one line at a time, trading execution speed for flexibility and low resource use.

After turning on one’s microcomputer, the BASIC interpreter would usually be loaded straight from an onboard ROM in lieu of a full-blown operating system. In this interpreter shell, one could use the hardware, write and load BASIC programs and save them to tape or disk. Running existing BASIC code as well as compiled programs on one’s computer, or even typing them in from a listing in a magazine all belonged to the options. As BASIC implementations between different home computers were relatively consistent, this provided for a lot of portability.

That was then, and this is now. Are people actually still using the Basic language?

BASIC Joystick Fun

To start off with, let’s see a bit of what BASIC is about. For an extremely simple but fun example of how BASIC can be used, let’s take a look at an application for the Commodore 64 (courtesy of C64-Wiki) that moves an arrow around the screen while printing its screen coordinates using a joystick connected to the second joystick port. The C64 runs Commodore BASIC 2.0, which is based on Microsoft BASIC.

 10 S=2: X=150: Y=150: V=53248: GOTO 100
 15 J=PEEK(56320): IF J=127 THEN 15
 20 IF J=111 THEN POKE 56322,255:END
 25 IF J=123 THEN X=X-S
 30 IF J=119 THEN X=X+S
 35 IF J=125 THEN Y=Y+S
 40 IF J=126 THEN Y=Y-S
 45 IF J=122 THEN Y=Y-S
 50 IF J=118 THEN Y=Y-S
 55 IF J=117 THEN Y=Y-S
 60 IF J=121 THEN Y=Y-S
 65 IF X=>252 THEN X=10
 70 IF X=<10 THEN X=252 75 IF Y>254 THEN Y=44
 80 IF Y<44 THEN Y=254
 85 PRINT CHR$(147);CHR$(158);CHR$(17);"X-POS:";X;" Y-POS";Y
 90 POKE V,X:POKE V+1,Y: GOTO 15
100 FOR Z=832 TO 853 : POKE Z,0: NEXT Z
105 FOR Z=832 TO 853 STEP 3: READ J: POKE Z,J: NEXT Z
110 POKE V+21,1: POKE  V+39,7: POKE V+33,0: POKE V+29,1
115 POKE 56322,224: POKE 2040,13: GOTO 85
120 DATA 240, 224, 224, 144, 8, 4, 2, 1

Each of the lines above are entered as-is, including the line number. On the next line after the code we enter RUN and hit ‘Return’ (or ‘Enter’, depending on one’s keyboard). Assuming we didn’t mistype anything, the code will now execute to show the following screen:

In this exciting game, we move the arrow around the screen using the joystick.

So what does this code do? As with any BASIC program, it starts at the first line which here is 10. It defines a few variables here, before jumping to line 100 (using GOTO). In a FOR loop, we POKE (i.e. write a hardware register) and repeat this in a few more addresses, which updates the display to its initial configuration. Here the READ command is used to read constants which are defined by DATA.

Many of these memory addresses directly address the video adapter (VIC-II in the C64). When we use PEEK at line 15, it reads the contents of the memory address 56322, which corresponds to the current input values on the second joystick port. After that we can check the state of each input using the bit values and adjust our on-screen arrow accordingly (line 90), along with the coordinates (line 85).

The C64 Wiki page for this program includes a bitwise comparison version. That should run marginally faster, as it has fewer lines of code. For moving an arrow around the screen, the difference would be unlikely to be noticed, however.

Important to note here is that BASIC implementations on different microcomputers would have to POKE and PEEK different memory addresses to get the same effect due to the different system layout of each computer. Some implementations would also provide commands tailored specifically to that microcomputer system, which became more relevant as graphics and audio capabilities grew.

Interpreted Versus Compiled

A familiar sight for some people: the QuickBasic IDE.

The interpreted nature of BASIC on most microcomputers was both a benefit and a disadvantage. On one hand, it’s very flexible, and you can simply run your latest program and quickly modify it without having to deal with lengthy compile cycles (on a <10 MHz Z80 or 6502 MPU, no less). On the other hand, because any errors in the code will not become apparent until the program is run by the interpreter, this leads to the same joyful experience as with modern-day JavaScript and Python scripts, where the code will run fine until the interpreter suddenly keels over with an error message (if one is lucky).

With BASIC this usually comes in the form of a ‘Syntax error on line <line>’ error. Running the same code through a compiler would however have found those errors. This feature of interpreted code means that the easy distribution method of code as listings in computer magazines and reference books would only be as good as the quality of the printed code and one’s own typing skills. Fortunately, on the C64 and similar systems, fixing a mistyped line would be as easy as retyping it, hitting ‘Return’ and the interpreter shell would update the line in question.

BASIC Today

The PureBasic Visual Designer.

All good and well, you may say at this point, but nobody is dragging out that C64 to do some BASIC programming today. Aside from folks who like to play with old computers, of course. Here it should be noted that BASIC didn’t live and die with Commodore and Atari. Over at Microsoft, BASIC spawned Visual Basic, Visual Basic for Applications (VBA) and VB .NET. The latter allows writing VB code for the .NET runtime.

Microsoft also released Small Basic in 2008, which it says targets novice programmers, for example students who used a visual programming language like Scratch previously. This is not to be confused with SmallBASIC, which is an open source (GPL) BASIC dialect with accompanying interpreters for modern platforms.

BASIC dialects can also be found in many graphing and programmable calculators from Ti, HP, Casio and others, although many of these dialects are not directly compatible with the original BASIC standard (ISO/IEC 10279:1991). Since the 1980s, BASIC evolved to no longer require line numbers, instead using labels which it can jump to, along with adopting new programming paradigms. This was introduced with QuickBasic in 1985 and is a common sight today.

Also on the commercial side of the fence is PureBasic by Fantaisie Software, which provides an IDE and compiler for a number of target platforms. True BASIC is a modern BASIC toolchain and IDE which moves closer to FORTRAN in its syntax, and is developed by the original developers of BASIC (Darthmouth BASIC).

In terms of today’s open source BASIC interpreters and compilers, there is Chipmunk Basic, which dates back to the Apple MacIntosh, Microsoft recently open-sourced its GW-BASIC, and you’ll even find a healthy OSS ecosystem around BASIC. If none of that tickles your fancy, you can implement Tiny BASIC, straight from the BNF grammar as listed in the first issue of Dr. Dobb’s Journal from 1976. A few years ago our own Tom Nardi wrote about his experiences bringing a 1990s QuickBasic project into the modern world with QB64.

Making the case for BASIC

Clearly, BASIC is not dead then. It sees daily use in its commercial forms, the myriad of open source projects and in the vibrant retrocomputing community. Aside from still being a (arguably) good language to teach programming with, it’s also a nice option for embedded applications, especially where many use MicroPython or kin today, as the system requirements are much lower. We reported on an ARM MCU which came with a BASIC interpreter a number of years ago, for example.

There are also projects like UBASIC PLUS on GitHub, targeting STM32F0 MCUs and requiring as little as 8 kB of RAM and 64 kB of Flash. Another project for ARM and PIC32 (as well as DOS and Windows) is MMBasic, which lists its requirements as 94 kB of Flash and at least 16 kB of RAM.

With BASIC having evolved in an era when home computers had less memory and storage than a $5 microcontroller has today, it makes for an excellent, low-resource language for situations which call for the use of interpreted scripts rather than precompiled binaries, without having to shell out for MCUs with more Flash and RAM.

Are any of our readers regular users of BASIC in some form today? If so, be sure to leave a comment with your experiences and tips for those who might be interested in giving BASIC a shot, whether on desktop, retro systems or embedded :)

[Header Image: The HP 2000 system, mainly used for running time-shared BASIC, CC-BY 3.0]

115 thoughts on “BASIC: Cross-Platform Software Hacking Then And Now

  1. There are still many programmable calculators that use BASIC, like TI-83, TI-89 and many others.
    I particularly like the ones which have QWERTY keyboard, like TI-92 and TI-74 (I have both and they are very cool and fun devices).

  2. I used to program in BASIC on an HP 3000, which now feels like about a billion years ago. I was 14 at the time. Our school rented a dial-up terminal from the University… ran at 75 baud initially, and then we got an upgrade to 110…

    I also used MBASIC on my Altairs. I had two 8800b’s. Then on the IBM PC when it came out. I had a TI-99 at some point but never really liked programming it. My C64 on the other hand was a lot more fun. I bought it originally when my Perkin-Elmer Owl terminal died… got a C64 and a TV to replace it with. 80 chars would have been nice, but the C64 offered *color* for a nice price.

    At some point I switched to C, but enjoyed writing code in BASIC for a long time.

  3. Is anyone else here familiar with Rocket UniVerse? Part of my job at work is maintaining an aging ERP system written using UVBASIC. We are currently working on replacing it, but it’s still running as a daily workhorse. Some of the comments in the code date back to the mid 80’s

    1. Check out OpenQM or jBASE. Both are multi-value systems compatible with UniVerse, but are much more economical to run. If you’re replacing it with something SQL based, know that you’re going backwards. ;)

  4. Computers are so fast now that it’s possible to write emulators in BASIC. Years ago someone write a really slow NES emulator in QBASIC (or was it QuickBASIC?) and back then I commented that it’d probably take a computer running at 2Ghz to make it full speed. Yup, some years later someone did that.

    I just now searched for NES qbasic emulator and saw an IBM PC emulator in BASIC.

  5. Load basic from ROM?, yeah, if you had one of the newer computers. I had a SOL20, and it loaded basic from cassette tape. MBasic… Later upgraded to Shugart 8″ drive S-100 bus, and then basic loaded quickly. Great memories… de WB7OND

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.