I have created "Pi Shack BASIC"

I have created a retro style version of BASIC for Linux (psBASIC). The language has been engineered to take advantage of many of the features found in the Linux environment while being as dynamically interactive as the BASICs found on the TRS-80s, PETs, C64s, IBM PCs, … I added features for working with GPIO pins, block devices and manipulating the SPI, I2C and UART ports available to us. The UART implementation was patterned after classic M$ BASIC for the IBM PC.

This dialect of vintage BASIC has been enhanced with many additional features, including:

  • It doesn’t require line numbers.
  • Pre, post and infinite loops with the DO [WHILE|UNTIL] ... LOOP [WHILE|UNTIL] syntax.
  • Multi-line IF statements.
  • Matrix (array) operations, not just for math.
  • SELECT CASE decision trees.
  • FUNCTION and SUB style subroutine blocks, with LOCAL variables.
  • Opening uni-directional pipes to other programs.
  • “~” expansion in file names to make it easy to write home.
  • A “Binary” file mode to provide pretty much unrestricted access to globs of data wherever in a data stream, while allowing both reading and writing. No more “random” with a 1 byte record length.
  • The “Binary” file mode also supports passing hardware parameters for UARTs (ttys), I2C and SPI ports.
  • Querying as well as setting the current working directory.
  • Access to command line arguments.
  • Access to environment variables as well as the ability to set / export them.
  • Classic I/O port style operations for accessing GPIO pins (INP/OUT).
  • The ability to return exit codes to calling programs.
  • Operates cleanly in a filter role.
  • You can call external programs and capture their exit codes.
  • Access to stderr.
  • Ability to open a print spooler (lpr), formatter (enscript) program or a device for printed output. On the DevTerm you can open the thermal printer interface (/tmp/DEVTERM_PRINTER_IN)
  • A complete built-in reference via the HELP command.

There are “.deb” packages available for all DevTerm / uConsole compute modules. You can read more about the features, usage and download packages from here. You can also see some sample code here. psBASIC also runs on Linux SBCs, desktops and laptop PCs.

Here’s an example of a terminal program in less than 10 lines of code, not counting blank and remark only lines:

100 PRINT "Super-Stupid-Dumb Term v1"
110 PRINT
    
    ' Open UART device
120 OPEN "b",#1,"/dev/ttyS0:115200,n,8,1"
    
    ' Copy 1 char stdin (keyboard) to UART
130 a$=inkey$
    
    ' Catch exit key and change [ENTER] back to CR
140 IF a$=chr$(0) THEN END ELSE IF a$=chr$(10) THEN a$=chr$(13)
150 IF a$<>"" THEN PUT #1,,a$
    
    ' Copy buffered UART input to stdout (monitor)
160 IF NOT eof(1) THEN PRINT input$(loc(1),1);
170 GOTO 130 : ' Do it again!

You have to change line 120 to the serial port you want to talk to. Those SBCs that support it or FTDI interfaces usually show up as /dev/ttyACM* or /dev/ttyUSB*. SBCs normally use a baud rate of 115200. But other things connected to FTDI devices, like Arduinos may need slower baud rates (usually 9600). HELP "uart" in psBASIC has more information on setting the line disciplines.

NOTE: OPTION RUN can be added at the top so that ^C, ^Q, ^S, ^Z, … can be sent to the remote device.

Since psBASIC considers line numbers as optional labels, the era-typical line based editing does not work. psBASIC makes no effort to provide a code editor, instead following the time honored tradition of UNIX, it will use whatever editor you prefer. Just set the $EDITOR environment variable to the command to run to edit programs. If the environment variable is not found it will use whatever the default Debian terminal editor is. When running under X, the editor does not have to be terminal based, it can be a GUI editor like Geany, Kate, GEdit, Leafpad, Mousepad, …

Editing with a GUI editor

NOTE: Screen colors, if any are user definable. They default to your terminals default, usually B&W or W&B.

NOTE: I added export EDITOR=... to my “~/.bashrc” just before the call to “startx”. Depending on your environment you may want to test for $DISPLAY (to detect X) and selectively change $EDITOR for terminal based and X based editing. Setting this in the BASH environment has the added benefit of setting your editor for many other tools, including GIT. Or you can set it in the “~/psbasic.bas” profile script to limit its affect.

psBASIC achieves a good level of performance for an interpreter by being native-code compiled C, tokenizing the source code and resolving jump targets before execution. It has become an indispensable tool in my tool-box. I use it for everything from animating LEDs to mining data from Apache web access logs. Its dynamic interactive nature gives it unparalleled “what if” capacity. On top of that you can play classic BASIC games like “Hunt the Wumpus” and “Super Star Trek”. Some minor changes may be required. But that was also typical for the period. :smiley: I even added sound effects to my copy of “Wumpus”.

If you have questions, feel free to ask them here or with the website support form, available from the download link I gave above.

Happy “retro” coding!

2 Likes

This is probably a crazy suggestion… but have you considered porting this over and making it available as a libretro core? I just realized it’s not open source, so maybe that would also be a problem, but since this is already portable code, and doesn’t require anything powerful in terms of CPU/GPU to run, it might be a really nice way to add a classic basic interpreter to libretro/retroarch and make it available on pretty much every platform out there, from many of the slow and older cheap gaming handhelds to more modern handhelds like Ambernic, Powkiddy and other companies churn out. Not only would it be a cool way to play classic stuff like Hunt the Wumpus and Super Star Trek, but it could be a way for folks to get into programming via old school BASIC on a whole host of readily available devices. And most stuff would probably even look alright on the tiny screens on some of these devices.

It would be a project, of course. But I imagine a libretro core would only need to make use of the graphics output, sound, and input (in the form of the retroarch virtual gamepad or keyboard mappings which could also be reassigned). All the other cool stuff (gpio, serial, etc.) for interfacing with hardware wouldn’t really be needed or used since as far as I know libretro doesn’t really have a way to access much native hardware like that, except perhaps the filesystem. Then someone could just point the psBASIC libretro core to a .bas file as the “rom” and it could run it without all the overhead of emulating hardware, as would be needed if running a TRS-80, C64, DOSBox, etc.

Anyhow, just a (probably crazy) thought. Thanks for creating this and sharing it. This is a really cool idea and a way to preserve these classic programs, as well as even make those old BASIC programming books more easily used in modern projects. :slight_smile:

Interesting thought I’ve not heard of “libretro”. I’ll have to take a look.

1 Like