Development
Raiting:
36

BASIC. Cross-platform software then and now


image

Would it surprise you if I said that BASIC is still relevant? In addition to being the progenitor of modern home computing, the language is still viable even outside the retro-enthusiast circles. We propose to plunge into a brief overview of the history of its formation, starting from the basics and ending with modern implementations.
The origins of the language
Not too long ago BASIC was the common language of home computer systems. Moreover, it was not always the same BASIC. His commands and syntax differed depending on the PC model he was equipped with, be it Commodore, Atari, Texas Instruments, Sinclair, or others. Fortunately, most of the dialects stemmed from the most popular implementation, namely Microsoft BASIC

BASIC is rooted in the academic field, where it was originally created as a language that would be convenient for both specialized students and for those who studied outside the traditional areas of STEM (Science, Technology, Engineering and Mathematics). Inheriting a number of properties from popular languages of the 60s such as FORTRAN and ALGOL , it became widespread in school time sharing systems ... Even IBM took part in its development, releasing an improved version of VS-BASIC in 1973. When in the 70s microcomputers began to appear, which were small and at the same time affordable, it was quite natural for them to use BASIC.

The advantage of integrating this language into such systems was obvious and consisted not only in the fact that it was already familiar to many potential computer buyers, but also in its ability to execute programs without preliminary compilation. This was a big plus, because compilation requires a decent amount of RAM and storage, and microcomputers of those years clearly could not boast of these characteristics. Instead of compiling source code BASIC interpreters transform and execute code line by line, thus losing speed for the sake of flexibility and reduced resource consumption.

When the microcomputer was turned on, as a rule, it was the interpreter that was loaded directly from the built-in ROM, and not a full-fledged operating system. From its shell it was possible to use hardware, write and load BASIC programs, and write them to tape or disk. In addition, the user could execute both existing code and compiled programs, and even enter them directly from the listings that were printed in the magazines. At the same time, the relative consistency between BASIC implementations for different home PCs provided excellent portability.

But that was then, and what now? Is this language used today?
BASIC + joystick = fun
To begin with, I propose to take a closer look at how this language works. For a very simple, but at the same time funny, example of its use, we will analyze an application for the Commodore 64 that moves an arrow around the screen, displaying its coordinates on the display. The input device is joystick connected to the second port. The software is Commodore BASIC 2.0, which is a dialect of 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 line is entered as is, including its number. Having finished writing the code, go to the next line, enter RUN and press “Return” (or “Enter”, depending on the keyboard). Provided that everything was entered correctly, the code will be executed, and on the screen we will see:

image
In this awesome game, we move the arrow around the screen with the joystick

So what does the code actually do? As in any BASIC program, it starts execution from the first line, in this case 10. Several variables are defined here, and then using the GOTO command goes to line 100. In the FOR loop, we execute POKE (that is, we write to the hardware register ) and repeat this in several more addresses, thereby updating the display to its original configuration. Here, the READ command is used to read the constants defined by DATA ...

Many of these memory addresses refer directly to the video adapter (in the C64, this is VIC-II). When do we use PEEK on line 15, the contents of memory address 56322 are read, which corresponds to the current input values on the second joystick port. We then check the state of each input using these bit values and adjust the arrow (line 90) along with its coordinates (line 85) as needed.

The C64 Wiki page dedicated to this program includes a bitwise version of the comparison. It should run slightly faster due to fewer lines of code. However, it will be difficult to notice by moving the arrow on the screen.

It is important to emphasize here that implementations of BASIC on different microcomputers would imply the execution of POKE and PEEK for different memory addresses, due to the differences in the system configuration of each computer. Some implementations also provided commands tied to a specific PC system, which became more relevant as their graphics and audio capabilities grew.
Interpretation versus compilation
image
Familiar picture to many: QuickBasic IDE
The interpreted nature of BASIC on most computers was both an advantage and a disadvantage at the same time. On the one hand, it was very flexible and made it possible to simply run programs, as well as quickly change them, without requiring long compilation cycles (at least on a Z80 or 6502 processor with a frequency of <10 MHz). On the other hand, errors in the code remained unnoticed until the moment the program was executed by the interpreter. And this led to the same fun in development as modern JS and Python scripts, where the code will run fine until the interpreter suddenly throws an error message (if you're lucky).

In the case of BASIC, this incident usually manifested itself in the form "Syntax error on line <....>" ... At the same time, running the same code through the compiler would reveal all these errors. This feature of interpreted programs meant that the effectiveness of easily distributing code in the form of listings in computer magazines and reference manuals was determined by the quality of the print and the skills of the programmer who entered the code. Fortunately, on C64 and similar systems, correcting erroneous strings was very easy. It was enough to re-enter it, press “Return”, and the interpreter would update it.
BASIC today
I would like to say that everything is fine, but today no one gets that old C64 from the storerooms to write a BASIC program at their leisure. Except, of course, for the keen lovers of vintage systems. Still, it's worth noting that BASIC's life did not end with the era of Commodore and Atari, and later Microsoft developed its updated versions of Visual Basic, Visual Basic for Applications (VBA) and VB.NET. The latter can be used to write VB code for the .NET runtime.

image
PureBasic Visual Designer

In addition, in 2008 Microsoft released Small Basic aimed at aspiring programmers, such as students who have previously used a visual programming language like Scratch ... Moreover, it should not be confused with SmallBasic which is an open (under the general public license) dialect of BASIC with accompanying interpreters for modern platforms.

Dialects BASIC can also be found in many graphing and programmable calculators from Yi, HP, Casio and other manufacturers, although many of these dialects are not directly compatible with the original BASIC standard (ISO / IEC 10279: 1991). In the course of its development, this language has moved from the obligatory line numbering to moving through the code using labels, and also acquired new programming techniques. These changes were introduced in its updated version. QuickBasic in 1985 and remain relevant to this day.

Other implementations include commercial PureBasic from Fantaisie Software, which provides an IDE and compiler for a number of target platforms. TrueBasic , in turn, is a modern toolkit that includes an IDE whose syntax is closer to FORTRAN. It was developed by the creators of the original language themselves - Darthmouth BASIC ...

As for modern open interpreters and BASIC compilers, they include Chipmunk Basic dating back to the time of the Apple Macintosh, and GW-BASIC from Microsoft, whose code was disclosed not so long ago. In addition, around this language is formed healthy OSS ecosystem. If none of this touches you, then there is still Tiny BASIC using the syntax in Backus-Naur form as described in the first issue of “Dr. Dobb's journal "1976 ... A few years ago, one of the authors of Hackaday, Tom Nardi, described my experience migrating your old 90s QuickBasic project to a modern format with QB64 ...
Suitable application
It becomes obvious that BASIC is not only alive, but also used on a daily basis in commercial forms, countless open source projects and an active community of people who are fond of retro computers. This is certainly a controversial statement, but it is still suitable as a language for learning programming. In addition, due to the lower system requirements, BASIC is excellent for building embedded applications, which is usually done in MicroPython and similar languages. For example, a few years ago we wrote about the ARM microcontroller which came with a BASIC interpreter on board.

On GitHub you can also find projects like UBASIC PLUS which is designed for STM32F0 and requires only 8KB of RAM and 64KB of flash memory. Another project for ARM and PIC32 (as well as DOS and Windows) is MMBasic requiring 94KB of Flash and a minimum of 16KB of RAM.

BASIC evolved in an era when home PCs had less memory and storage than today's $ 5 microcontrollers. As such, it turns out to be an excellent lightweight language for when you need to use interpreted scripts rather than compiled binaries, and eliminates the need to purchase a microcontroller with a lot of RAM and flash memory.

Do you, dear reader, use any form of BASIC today?

If so, share your experiences and tips in the comments for those who might be interested in the language, whether on desktop, vintage systems, or embedded.
xially 12 march 2021, 16:50
Vote for this post
Bring it to the Main Page
 

Comments

Leave a Reply

B
I
U
S
Help
Avaible tags
  • <b>...</b>highlighting important text on the page in bold
  • <i>..</i>highlighting important text on the page in italic
  • <u>...</u>allocated with tag <u> text shownas underlined
  • <s>...</s>allocated with tag <s> text shown as strikethrough
  • <sup>...</sup>, <sub>...</sub>text in the tag <sup> appears as a superscript, <sub> - subscript
  • <blockquote>...</blockquote>For  highlight citation, use the tag <blockquote>
  • <code lang="lang">...</code>highlighting the program code (supported by bash, cpp, cs, css, xml, html, java, javascript, lisp, lua, php, perl, python, ruby, sql, scala, text)
  • <a href="http://...">...</a>link, specify the desired Internet address in the href attribute
  • <img src="http://..." alt="text" />specify the full path of image in the src attribute