A manual for superBASIC
Because I like printed manuals, I’ve written a short manual for superBASIC. It’s available in print on Amazon.com•, currently, for $5.99. It makes a useful reference if you use superBASIC; I use it all the time. It’s also available as a free ebook on most of the usual sites.1
I’ve also made some changes to how code generation works. I have changed the format of the DATASET
macro, or dynamic constant. I’ve renamed %DATASETS! to !DATASETS%. I did this because I can envision having string constants as well, and I wanted to use the same format I use for variables, that is, ending in a dollar sign. So now a variable always begins with a percent, and a constant always begins with an exclamation.
The only visible change to the generated code is that I’ve standardized how blank lines get added around blocks and remarks. This greatly improves the readability of the resulting old-school BASIC.
Also, remarks no longer break on forward slashes, as these are common in URLs, which are common in the top comments I put in any program I write.
Internally, I’ve completely rewritten block generation. It generates the same code as before, but it is much easier to manage and view block types. This means that SWITCH/CASE is now the same kind of block as LOOP and IF/ELSE. LOOPs and IF/ELSE can be embedded in CASEs. Even SWITCHes can be embedded in CASEs.
This should make it easier to add an ELSEIF to IF/ELSE when needed, and to add a SWITCH ON to generate ON x GOTO statements. I probably won’t be adding any sort of FOR/NEXT loop because this turns out to be unnecessary on the Color Computer. All of the FOR loops that I’ve been wanting to BREAK out of are in subroutines, and the BREAK would have returned immediately from the subroutine. It turns out that returning from a subroutine clears out the FOR stack.
I always felt weird about jumping out of a FOR loop, leaving the poor stack perpetually waiting for a NEXT that will never come. Now that I know how Microsoft’s BASIC implemented its stack, I feel a lot better about it.
There’s also a --version
command-line switch if you want to check the version on your system. The current version as I write this is 1.0.0. The third number is for bug fixes or minor internal changes. The second number is for feature additions, such as ELSEIF, or if I decide to add a SWITCH INDEX to create ON X GOTOs.
I’ve added a new feature to data sets. You can now provide a counter name to data sets, which will become a dynamic constant that contains the number of elements you provide to the data set.
[toggle code]
- border/foreground names
-
data !foregrounds%
- black
- green
- orange
- enddata
- %borderCount% = !foregrounds%
Note that !foreground%
does not contain the number of data items, but the number of elements provided to the DATA macro. I’ve found this useful because I often provide multiple data items per line to, for example, create a menu item. The line might contain the name of the item, the program to run, and whether or not the program is a BASIC program or a binary program. What matters to me later is not that there are, say, 15 elements in the resulting DATA
statements but that I entered 5 menu items.
Over on Facebook, Jay Searle asked,
Why did you use overly complicated variable types? It seems that %variable% could just be variable or %variable, and %variable$ could just be variable$ or $variable? I'm interested in your thinking and how you came to this conclusion. I'm not bashing you, just genuinely interested.
This is a really good question. Now that I’ve converted to recursive block generation and merged SWITCH/CASE into it, the weakest part of superBASIC is the variable conversion. I use the current format because providing both a start and an end character vastly reduces the chances of a non-variable getting munged up. The entire code for detecting variables is:
- $labelFormat = '[A-Za-z][A-Za-z0-9_]+';
- $variableFormat = '%' . $labelFormat . '[%\$]';
- s/($variableFormat)/&variables($1)/ge;
If you’re familiar with regular expressions, you will notice that nowhere in that code does it make any attempt to parse BASIC to determine what is and is not a variable. If you have %code%
or %code$
inside of a string, it will get converted to something like CO
or CO$
. Anywhere something that looks like a long variable—a percent sign, a letter, some text, numbers, and/or underscore, and then a percent sign or a dollar sign—appears, it will get converted, regardless of whether it truly is a variable.
I have yet to have this be a problem, but that doesn’t mean I like it.
Even worse is that this harms the readability of the code. While %code$
is more readable than CO$
, code$
would be even more readable. I would very much prefer to use a variable format of if location$ = "utility" then drive%=1 else drive%=0
instead of if %location$ = "utility" then %drive%=1 else %drive%=0
. But the BASIC of these old computers is a very freeform language, and the former runs the risk of collisions with non-variable text unless I have the script actually parse the old-school BASIC. That would vastly increase the complexity of the script, and thus the number of bugs hidden within it.
On the plus side, the current variable name format is such that if you have a working program that uses the current variable naming system, and I ever devise a better system, the Perl script to convert existing programs will be trivial. This is a rare case where waiting longer to implement a real solution does not make it more difficult to convert from the quick-and-dirty solution.
If you’re interested in how I generated tables for the ebook version of the manual, I wrote about the text-to-image conversion script at Text to image filter for Smashwords conversions.
In response to TRS-80 Color Computer Programming Tools: The TRS-80 Color Computer was a fascinating implementation of the 6809 computer chip, and was, from the Color Computer 1 through 3, possibly the longest-running of the old-school personal computers.
I used Smashwords to publish it.
↑
- Reversi in SuperBASIC on the Color Computer
- One of the ubiquitous games of the early computer era was reversi. Very simple rules, very simple board, very complex play. It’s easy to see why it was so popular.
- SuperBASIC (Zip file, 18.9 KB)
- A preprocessor for writing BASIC code with loops, subroutines, and switch blocks. Mainly for the TRS-80 Color Computer.
- SuperBASIC for the TRS-80 Color Computer
- Make BASIC Fun Again. Use loops, switches, and subroutines while writing Extended Color BASIC code for the Radio Shack Color Computer.
- SuperBASIC: The Manual: Jerry Stratton at Smashwords (ebook)
- “Do you want to write BASIC programs for your Color Computer, but don’t want to deal with two-character variables and invisible (or non-existent) structure? Consider superBASIC. Use loops, multi-line if/else/endifs, include files, and more. You can even use command-line switches to target the same BASIC program for computers with different hardware.”
- SuperBASIC: The Manual•: Jerry Stratton at Amazon.com (paperback)
- “Do you want to write BASIC programs for your Color Computer, but don’t want to deal with two-character variables and the complete lack of structure in old-school BASIC? Consider superBASIC. Use loops, multi-line if/else/endifs, include files, and more. You can even use the same code base to target computers with different hardware.”
- Text to image filter for Smashwords conversions
- Smashwords has very strange requirements for ebooks. This script is what I use to convert books to .doc format for Smashwords, including converting tables to images.
- What effect does exiting a FOR/NEXT loop early have on the TRS-80 Color Computer? at StackExchange
- “What are the effects of exiting a For/Next loop early in Extended Color BASIC? How can I see these effects in a program? And, what, if any, are the side effects of returning from a subroutine from inside an unfinished For/Next loop?”
More superBASIC
- Simple game menu for the Color Computer 2 with CoCoSDC
- This simple menu provides one screen for cartridges saved in the CoCoSDC’s flash ROM, and any number of screens for your favorite games for your friends to play.
- Hunt the Wumpus: Conditional code and include files in SuperBASIC
- Hunt the Wumpus can talk to you if you have a speech synthesizer.
- Reversi in SuperBASIC on the Color Computer
- One of the ubiquitous games of the early computer era was reversi. Very simple rules, very simple board, very complex play. It’s easy to see why it was so popular.
- SuperBASIC for the TRS-80 Color Computer
- Make BASIC Fun Again. Use loops, switches, and subroutines while writing Extended Color BASIC code for the Radio Shack Color Computer.