Giving the ZX Spectrum a Fair Shake

wicket2 pts0 comments

Giving the ZX Spectrum a Fair Shake | Bumbershoot Software

Last month (just a couple days before my Exidy Sorcerer article) the ZX Spectrum celebrated its 44th birthday. I have written shockingly little about the system given that it still remains the first system I go to when prototyping Z80 code. I wrote up a platform guide for it last year and mentioned it in passing while I was trying out various Z80 development tools, but beyond that it’s been almost ten years since it’s gotten any dedicated articles. Even those were pretty perfunctory; I was mostly interested in the challenge of writing a machine code program that could run unchanged on the Spectrum 16K and the wildly incompatible TS2068.

So let’s have some fun, with a belated birthday bash. Today I’ll do a tour, in BASIC, through the capabilities of the core 16K and 48K Spectrums, and then take a quick look at what the 128 offers us as a casual user. Then, over the next couple weeks, I’ll dig down into how to take advantage of these capabilities in machine code as well. This will be in the vein of the tour I did back in the day for its predecessor, the ZX81, and more recently my exploration of the TI-99/4A and MSX.

Hello, World

The first-generation Spectrum computers basically presented themselves as the ZX81 but more, and a veteran of the earlier Sinclair computers will be at home immediately:

The K prompt means the same thing it did on the ZX81; it means we are in "keyword" mode and a single keypress will give us one of BASIC’s commands. P will give us PRINT , J will give us LOAD , and many others. Here, too, we are the ZX81 but More. Here is Fuse’s keyboard reference, which replicates what was printed on the system’s own keys:

We have more options per key than we did on the ZX81, too, though some old friends return:

K eyword mode, which will deliver the white word on the bottom of the key. Numbers are entered normally so we can enter line numbers in this mode if we wish.

L etter mode is the mode we’re usually in when typing, and when we’re in it the keys represent the letter or number that is the printed boldly upon it. CAPS SHIFT gives us upper-case on letters, and on the top row it gets us the thing described by the white text above the key. (CAPS SHIFT 5-8 are the cursor-movement keys.) SYMBOL SHIFT gives us the red text character on the right side of the key. This means that CAPS SHIFT works like normal SHIFT on other systems, except for the top row. Exclamation point is SYMBOL SHIFT 1, for instance, while CAPS SHIFT 1 ("Edit") erases the line you’ve typed so far and calls up the most recently accessed BASIC line in your program to edit it. This certainly didn’t trip me up a thousand times while I was preparing this article.

C aps mode is toggled with CAPS SHIFT 2, and it leaves all the letters in uppercase for free when we’re in letter mode.

E xtended mode replaces the "Function" mode on the ZX81. We enter it by pressing CAPS and SYMBOL shift together, then releasing them. This gives us the green keyword printed above the key. If we hold either shift key while so doing, we get the red-text keyword underneath it instead. The top row, again, is different; it has only the red-text keyword and will provide it even when unshifted.

G raphics mode is toggled with CAPS SHIFT 9. When in this mode the numbers 1-8 become the semigraphics characters depicted on their keys. Inverse text mode (CAPS SHIFT 3) will give the other 8 required to have the full set of 2×2 semigraphics. While in this mode, the letters A through U look like they’re always capital letters, and V-Z don’t work at all. There is more going on here than it seems; we’ll get to that in a bit.

When doing ordinary BASIC things, Spectrum BASIC is very similar to ZX81 BASIC. Here’s a Spectrum version of the temperature conversion program I wrote for the ZX81 nine years ago:

10 PRINT "TEMPERATURE CONVERTER"<br>20 PRINT ,,"Press ""F"" to convert from","Fahrenheit or ""C"" to convert","from Celsius"<br>30 IF INKEY$="f" THEN GO TO 90<br>40 IF INKEY$<>"c" THEN GO TO 30<br>50 PRINT ,,"Enter Celsius degrees"<br>60 INPUT c<br>70 LET f=(c9/5)+32<br>80 GO TO 120<br>90 PRINT ,,"Enter Fahrenheit degrees"<br>100 INPUT f<br>110 LET c=(f-32)5/9<br>120 PRINT ,,"RESULTS"<br>130 PRINT ,,f;" degrees Fahrenheit"<br>140 PRINT ,,c;" degrees Celsius"

This just barely fits onto the Spectrum’s 32×24 screen.

The little caret by the last line works the same way as on the ZX81; it represents the "current line" that will be called up if we hit EDIT. I left the variables in lowercase this time too, but I often find that distracting and will keep everything in all-caps in the text. Identifiers are case-insensitive anyway.

One sort of unusual thing about Sinclair machines that I didn’t mention in my older articles is that there’s a sharp split between output in the upper portion of the screen and text entry in the lower two lines (the "status window"). We see that even with INPUT commands:

The Invisible Upgrade

The Spectrum and ZX81 both run a...

mode shift zx81 spectrum caps print

Related Articles