"... It will load all programs which were specially written for the Spectrum 128, as well as many programs which were written for the Spectrum +, Spectrum 48K and 16K ..." - extract from Sinclair ZX Spectrum 128 Introduction manual.
This article is all about Uncle Clive's new computer, the Spectrum 128. What it is, how it works, and what makes it tick. This article will be of use and interest to both Basic and machine code users.
The Spectrum 128 is, as its manual states, two computers in one. It can run as a 128 (which is almost as different from the old Spectrum as was the QL), or it can pretend to be an old Speccy, in which case it behaves exactly as though it were an ordinary Spectrum with 48K of RAM. When running as a 128 there are a couple of extra commands, and a few other extra features such as calculator and a renumbering facility - these extra features are menu driven and cannot be initiated by a BASIC program.
But what exactly does this mean in terms of compatibility? The manual claims that the machine can run in 48K mode, and that it will then run exactly like an old Speccy. However, the following line:
IF PEEK 75 = 191 THEN PRINT "THIS IS NOT A SPECTRUM 128"
will give different results on an old Speccy to the new Speccy in 48K mode. This is a minor detail and you shouldn't worry too much about it - in general Sinclair's claim that a 128 in 48 mode behaves exactly like a 48 should be considered truthful.
128 mode, however, has quite a few differences - some of which could well produce incompatibility with programs written for the ordinary Spectrum. I'd like to examine these differences now, and discuss their consequences.
The first change is the character set. There are two differences in the character set which could affect the visual display of some graphics games. CHR$ 163 on the old Spectrum produced the user defined Graphic-T, and CHR$ 164 gave Graphic-U. On the new Spectrum they don't! CHR$ 163 gives the new keyword "SPECTRUM", and CHR$ 164 give the new keyword "PLAY". This means that on the new Spectrum 128 there are only nineteen user defined graphics, compared with twenty-one on the 48.
The second change concerns the ZX Printer. The printer will not work on the Spectrum 128. This is of course quite a serious difference for anyone who owns a ZX Printer and not one of those expensive things you have to plug into the RS232. It means that unless you buy a 'real' printer you can't list programs. Fortunately you don't have to buy an Interface One because the 128 already contains an RS232 Interface, although you still have to buy a lead.
The reason that the ZX printer doesn't work is that the printer buffer (the area of memory between hex 5B00 and 5BFF) is used by the 128 for paging-in new regions of memory and for storing a few tables and system variables. This has consequences for the machine code programmer. Any machine code program designed to utilise the memory in the printer buffer is likely to cause a crash!
The 128 contains at least two ROMs. The visible ROM is almost identical to the ROM of the old Spectrum, and contains the program for running BASIC. There is also an invisible ROM (invisible because you cannot read it using PEEK) which is paged in on power-up, and may be paged in using the code in the printer buffer. So far, I have not yet worked out how to utilise this ROM from machine code but I can make a guess as to what it contains. It must contain the program to operate the menus, the renumber facility, the calculator, and the new commands SPECTRUM and PLAY.
The ordinary ROM is, as I said earlier, almost identical to the old Spectrum ROM. This means that machine code programs which make use of subroutines in the ROM will still run perfectly well. No subroutine addresses have been changed, but the ROM is still slightly different. The space at the end of the ROM (addresses 386E to 3CFF) which used to be unused now contains some new code. There are also minor changes to the main bulk of the ROM.
The first change is to the interrupt routine at 0038. Two bytes have been changed at 004B and 004C, changing what used to be CALL 02BF to CALL 386E. Note that the keyboard routine at 02BF still exists, but it is not called by the interrupt routine directly. Instead, a new routine at the end of the ROM is called. You see, the Spectrum 128 has provision for an add-on keypad which will contain a few extra keys. These changes to the interrupt routine ensure that the new keypad keys are also scanned and registered.
The next change is to the printing of graphics and tokens. Four bytes at 0B52 have been changed, from SUB A5/JR NC, to JP 3B9F/NOP. The purpose of this change is to ensure that characters 163 and 164 are correctly expanded to give the two new keywords "SPECTRUM" and "PLAY".
At 2646 there is a change to the INKEY$ routine. What used to be CALL 028E is now JP 3B6C. Again, the purpose of this change is to ensure that the new keypad can be registered - this time so that INKEY$ is capable of reading the keypad keys.
Finally, there are three rather more fundamental changes. Four bytes at 1349, four bytes at 1B7D, and three bytes at 1BF4 have been changed, making alterations to the main execution loop, the statement-return routine, and the next-statement routine respectively. These changes cause control to enter the new (and so far invisible) ROM, and hence to carry out the new BASIC commands, operate the full screen editor, and so on and so forth. These are the important ones, and any machine code program which relied upon the main execution loop will probably crash on the new machine. Such programs are few and far between (although one of mine now suffers from this disadvantage).
If the Spectrum 128 is operating in 48K mode then none of the above listed changes will make any difference. Both BASIC and machine code programs will run exactly as they did before. The only possible exceptions to this rule are programs which directly PEEK the ROM at one of the changed locations (such as the BASIC line listed earlier) - but these are programs deliberately constructed to be different, and are therefore not a major worry.
The Spectrum can easily tell which mode it is in (128 or 48) by looking at bit 4 of the system variable FLAGS. In the old Spectrum this bit was unused, but in the new Spectrum it is used even when operating as a 48K. The flag is invariably RESET for 48K mode, or SET for 128K mode. It is not, however, possible to enter 128K mode simply by changing the value of FLAGS, since the information which 128-mode needs in the printer buffer will not be there. But one important consequence of this is that it is possible for a machine code program to tell what kind of Spectrum it is running on. Such a program must first read address 004B - if it contains BF then this is an old Spectrum; if it contains 6E then this is a Spectrum 128. (If it contains anything else then you've probably got the Interface One Shadow ROM paged in). Then - if you're sure this is a Spectrum 128 - you can read bit four of FLAGS, and if it's set it means that the machine is currently in 128 mode.
The same can be done in BASIC, as the program below will demonstrate:
10 IF PEEK 75 = 110 THEN GOTO 40
20 PRINT "THIS IS NOT A SPECTRUM 128"
40 LET x = INT(PEEK 23611 / 16)
50 LET z = 128
60 IF x/2 = INT(x/2) THEN LET z = 48
70 PRINT "THIS IS A SPECTRUM 128"'"IN";z;"K MODE"
Nextly, I want to talk about the Spectrum 128's extra memory. On a 48K Spectrum DIM A$(40000) will not work. (Error 4 Out of memory). One would assume that a machine with 128K should be able to store much larger strings. Unfortunately this is not the case! Even in 128K mode, DIM a$(40000) will work, but DIM A$(42000) will fail (Error 4 Out of memory). So where is all this extra memory?
The answer is that the new memory is used as what Sinclair refers to as "RAM disk". The only way to use it (without complicated machine code paging which I don't understand yet) is to transfer blocks of memory to and forth between the conventional memory and the new memory (RAM disk). You can do this from BASIC using the new commands LOAD! and SAVE! (the exclamation mark is crucial). You can use the new memory to store either data or programs (BASIC or machine code). This system doesn't cause any real problems and it is really quite simple to use the extra memory, making it at last possible to write really long machine code programs, or a BASIC program with really large amounts of data (or extra program lines which may be recalled using MERGE!). Unfortunately, I still haven't managed to locate 128K yet. I have found that I can store up to 71K in the RAM disk area - after that I get Error 4 Out of memory. Now 71K plus 48K equals 119K, not 128K. If anyone finds out where this missing 9K of memory is would they please let me know.
To conclude, I believe that the Spectrum 128 is brilliant. It is completely compatible with the old Spectrum (with the exceptions I've listed above), and is superior in every way. The extra memory is only one of its superior features. It has better sound, better editing, and an RS232 interface built in (as well as a monitor port). Its well worth buying and I recommend it to anyone who can afford the £180.00 ($280) price tag.