BASIC: Cross-Platform Software Hacking Then And Now – Hackaday

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 wasnt 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 ones 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 ones 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?

To start off with, lets see a bit of what BASIC is about. For an extremely simple but fun example of how BASIC can be used, lets 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.

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 ones keyboard). Assuming we didnt mistype anything, the code will now execute to show the following screen:

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.

The interpreted nature of BASIC on most microcomputers was both a benefit and a disadvantage. On one hand, its 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 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 ones 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.

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 didnt 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 todays 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 youll 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. Dobbs 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.

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, its 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]

Read the original here:
BASIC: Cross-Platform Software Hacking Then And Now - Hackaday

Related Posts
This entry was posted in $1$s. Bookmark the permalink.