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]

124 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

  6. I ported my C game to the PET, TRS80, Apple2, and am working on the IBM 5150 port (x86) now: http://www.destinyhunter.org if interested in download (source is also in github). What does that have to do with BASIC?

    Well, I liked how those systems booted straight to ROM BASIC. And I used PEEK/POKE in BASIC as a “practice” to get an initial understanding of those systems — how to poll the keyboard, how to POKE to the screen, how to do sound. And essentially learning how BASIC implemented their functions for that system.

    For folks who just say “in language X I just do SOUND, or PLAY, or READ JOYSTICK” it seems they take for granted HOW those features are made available. How even PRINT actually works, or what scrolls that text screen, or the whole concept of STDOUT and redirecting that to file or comm port streams instead of the screen.

    Sure, most people don’t care how the hardware works – that’s the point of high level languages and abstraction. So it’s like two tiers of developers: people who can make libraries that work for a system (embedded systems?), versus more casual application developers. Both can clearly make good money — but application developers are dependent on the systems developers. But as we’re transitioning back into more embedded systems (IoT and processors everywhere, weaved into 3D printed products, our clothing, space systems, even injected into bloodstreams as we evolve cybernetics) — those embedded systems don’t have traditional “screens” and have very severe power requirements. So that means no more of just throwing more hardware as the solution — you’re not running CPU cooling fans inside a human body or in an interstellar satellite.

    And this made me reflect on that distinction between PROGRAMMING and SOFTWARE. I remember a lot of articles in the 1980s about “what is software”, as a lot of people still hadn’t quite wrapped their head around it — as a new expression to create content. Except software is ultimately translated into OPCODEs that are set of instructions that PROGRAM a specific processor, that in turn interacts with various aspects of the system (I/O ports to receive keyboard inputs and convey results onto some output — typically a console/monitor, maybe a printer, maybe a network data stream). Before the term software even existed — say the 1930s– you had “programmers” that could instruct a machine by pulling levers and knobs (i.e. manually doing the job of sending a sequence of instructions into a processor — those instructions encoded at 0’s and 1’s, or knobs, and eventually electrical impulses). So in this sense, “programming” pre-dates and is distinct from “software.” One could PROGRAM (communicate instructions to a system) using smoke signals, gang-hand gestures, flashes of light, etc (stuff we’ve been doing for centuries). And assembly is just short-hand for opcodes (“STA” instead of “01001001”), and that’s why I think 8-bit computing kind of marked the beginning of general purpose personal computing — with 2-bits, you have 4 instructions, or 4-bit = 16 instructions. Many early instructions sets were around 50-80 instructions, so you’d need 6 to 8 bits to represent those uniquely – anyway, there was just a moment when the data-bus was wide enough to be expressive enough to do a variety of interesting things (more than just add, subtract, like the early calculators). And that’s an interesting parallel to human languages — we narrowed down to 26 symbols (the alphabet) to be expressive enough to write literature and communicate a lot of interesting ideas, whereas just a few grunt sounds wasn’t expressive enough (but it’s all we had for many many centuries).

    I think it was the late 1930s that the first use of RAM was involved in executing some instructions – the machine “remembered” some instructions and could be dynamically programmed to issue new instructions, and that thus was born the concept of software. And from there was that growing divide between embedded/systems programming (makes things work on a specific system configuration) versus application programming (sacrifice some performance to get easier portability across systems).

    BASIC served its purpose when RAM was very limited — as BASIC could fit in about a 2K – 4K ROM (depending on which BASIC features were included — like floating point or SOUND commands would require more space). And BASIC was a comfortable compromise between “human readable” and being compact enough. But even in like 1975 (Sol-20 days), BASIC was “too large” as those early systems barely even afforded 4K. You could have BASIC, then have like 100 bytes left to do your program – not interesting. Even the early PET computers, they sold a 4K model but realized you’d have less than 1K to do any “programming”, so they upgraded those orders to 8K (most of those upgraded for free; this was like 1978).

    So BASIC does represent that “next logical step” past assembler – an INKEY and PRINT commands to interact with the keyboard and monitor of the host SYSTEM (in the published GW-BASIC code from Microsoft, their comments refer to these as the “OEM” or “vendor” portions), maybe a MODE command to change text, graphics. And the ability to store data into variables (A thru Z, or some BASICs had double-letter variables). Then support the essential math operations, logical operations, and some BASIC also had trig functions. Pack that into 2K, so the remaining 30K is all yours – and that’s a useful thing even today.

    Note, the biggest pain about BASIC on the original Commodore PET is it didn’t have the RENUM command :) So you did need to pre-plan your line numbers as programs got larger (or do a lot of manual renumbering). With that experience, I could see why some people “painted themselves into a corner” and would have been frustrated with BASIC.

    Last thing to say– BASIC was a “cheap” compromise. Now-a-days we always use “big computers” to program the embedded system. For my C game on the PET, TRS80, Apple2, all my development was on the Windows PC — where I could quickly cut and paste, and use emulators to test my code, power cycle, test again, without any wear and tear on the target system. We now all have i7’s everywhere, effectively desktop supercomputers. Except by using C to target a 32K RAM machine, I did have to forego a lot of programming practices that I’d normally do (e.g. defensive programming), and such was necessary to get an acceptable performance. Even to pull of interesting sound effects, the 1 MHz processors were too slow to just do that casually – to make it seamless with the game, I had to use self-modifying code to dynamically adjust opcode instructions that influenced the timing of the sound. On a 3+ GHz system, you can take much more for granted – and that does sadden me to see so much “waste” in modern software, and you can “feel” when certain programs are very sloppy written (it’s hard to describe, but there are just clues that some software was just slapped together versus a lot of sweat and tears having done into it).

  7. Thanks for writing this article. I use BASIC, and I also the developer of Liberty BASIC which is a popular and modern BASIC for Windows, and the new version under development also runs on Mac OS, Linux and the Raspberry Pi. A lot of people still program in BASIC and there are a bunch of modern implementations (not just Microsoft’s toy Small Basic). It almost seems like a minor crime against humanity that computers do not promote programming when you boot them up (a desktop icon for an easy programming language) like they once did. What are they afraid of? If they make too many programmers they might promote competition and sow the seeds of their own demise? ;-)

    1. To put my computing experience in contact, my first efforts were on an early version of what became Fortran ( Titan Autocode). I yearned for an Altair; built a Cosmac Elf with point-to-point wiring; and went through PETs, Ataris, etc. Being a Brit I’ll speak up for the BBC BASIC and its associated computer. I’ve used many languages- Forth was a favourite for a while, and I like aspects of Python. But Carl’s Liberty BASIC has been my go-to environment for years. It has refused to bloat itself, and does 99% of what I want- and on modern hardware platforms has never let me down fofe. Djkstra. r power and speed. I’ve enjoyed reading the whole of this thread- so many mentions of things that are part of my life. Djykstra. Cambridge Numerical recipes. Superboards. Does anyone else remember the Jupiter Ace with its built in Forth?

      1. Thanks John. I also am a big fan of Forth, a powerful and elegantly simple language which deserves more attention than it gets in my humble opinion. There are so many such languages, and it is lost on my why many of these don’t come preinstalled with popular operating systems.

Leave a Reply to f15simCancel 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.