Your Spectrum
Issue 8, October 1984 - Paging On Your Spectrum
Home Contents KwikPik
Three things have been on my mind of late. First, that an oft-heard complaint about the ZX Spectrum is that its memory map is all accounted for ... nothing else can be added as it's all taken up by the 16K Basic ROM. Second, that any programs which require allocation always seem to choose the same place at the top of memory. Finally, there's the disparate thought that an upgrade to the QL was supposed to be able to allow multi-tasking - that is, two or more programs running at one time - certainly an advantage over the Speccy, but one that now appears impossible without a change in the QL software.


With these things in mind, I sat down to consider ways I might expand my 48K Spectrum. Of course I wasn't the first. Other people, for instance, have tried to solve the problem using different pages of RAM. This allows the user to have more than one set of RAM at a particular memory address. As only one set at a time can be addressed by the computer they are rotated into the memory map in turn, like the pages of a book. Information stored in the pages not addressed by the computer are unaffected by any PEEKing or POKEing of the memory addressed.
The problem has always been one of no software existing to run these new

Hearing that the QL could multi-task was the straw that broke Stephen Adams' creative back. Find out how he's able to offer users the potential of a 4096K Spectrum.
pages, and inevitably the user has been left floundering about trying to incorporate them into programs or having to write brand new ones. The other major disadvantage is that ordinary programs can't be run once the system is fitted.
Being a hardware man, I decided there was no particular difficulty in switching between the pages of RAM themselves ... it was how to make it all compatible with existing software that was the real problem. Basic and machine code programs had obviously to be extendable to the new system and, of course, the hardware shouldn't stop you using it as a straight- forward 48K Spectrum for normal programs.
To make the hardware compatible I first made the, perhaps rash, assumption that Sinclair Research was going to steer clear of any further drastic hardware
modifications on the Spectrum. By keeping well clear of anything Sinclair Research had allocated, this should ensure that any new hardware will remain compatible. In fact, the address used for the system was one numbered 253 in the Input/Output map. I took the same way of addressing it as Sinclair Research had done, using just one address line (A1) to turn on the page switching device.


Having sorted out the hardware in a rough sort of way, I then concentrated on the task of finding the software I needed. No easy task this, so I turned to frequent YS contributor and acknowledged machine code expert of this realm, Andrew Pennell. I asked him to write a special Basic extension which would allow me to use the top 32K of the Spectrum's
Circuit Diagram
The diagram above shows the circuit I used to test out the page switching facility with a 16K ZX8I RAM Pack. The inputs to the 74LS74 (3 and 11) come from the decoder that determines whether the I/O address 253 is being used. The chip then stores the value of D7. The second decoder operates A14 (to turn on the RAM Pack) when the top 32K of memory is addressed and a '1' has been stored in the 74LS74 latch. To prevent it being turned on along with the internal RAM on power-up, the latch is initially sat to zero by the reset line. Don't forget that before using the extra pages, use CLEAR 32767 to stop Basic crashing. By the way, the lines not shown on the diagram must be converted from the Spectrum's edge connector to a PCB of a ZX81-type edge connector.


memory in pages. Different programs could then be switched in and out under software control. The bottom 16K of RAM, containing the screen display, could not be used. It was vital the new operating system went somewhere that was unaffected by any switching of the RAM pages.
Two other specifications were that it could be operated either through Basic or machine code, and that it would have the ability to swop variables between pages. Andrew decided to add a further nice touch, allowing windows to be defined, and thus giving each program a section of the screen to itself.
The hardware for the XK system is available in the form of a kit, or you can have it fitted to your Spectrum by TV Services of Cambridge. The company guarantees its work - if for no other reason than that fitting the mod will [invalidate the] Sinclair Research guarantee. This should go quite some way towards calming those who get nervous at the idea of burning their guarantee bridges.
The modification takes the form of an extra board that fits inside any ZX Spectrum model, switching out the internal RAM above 32K when using an external RAM pack. The board allocates pages 127 and below to the two internal RAM pages, by using line D7 to choose
between internal and external pages.
At least two pages of RAM need to be allocated to the internal memory, as the 32K RAM is actually composed of eight 64K chips. These chips have one side faulty - and permanently switched off (see Suddenly, it's the 64K Spectrum! last issue) - giving 32K. However, it's possible (when the XK system is fitted) to examine this other half of the chip by switching to the second internal page and PEEKing what's there.
The working 32K page is selected by the Spectrum on power-up. The chosen side is normally linked by a wire strapped inside the Speccy and this has to be removed so that both sides can be selected under software control. It's possible, therefore, to effectively replace the 32K chips with ones of 64K potential, and to have two pages of RAM inside the machine, as well as the external pages.


The board makes sure that on power-up the internal 32K RAM is selected, and thus the Spectrum behaves normally. It does this by use of an integrated circuit latch which is controlled by two data lines, one to decide the internal/external RAM selection (D7) and the other to control which page is selected (D0).
Using the command OUT 253,255 both of these will be switched out of the memory map. On a modified Spectrum without the modified RAM pack, this would result in the machine resetting
itself back to the copyright message; in effect, it would behave like a 16K Spectrum (because there are no extra pages fitted). This happens because the Spectrum's stack is located in the topmost part of the paged memory. It's therefore important that you don't use this address in your normal programs (software companies also, please take note!). Unfortunately, for reasons best known to itself, Ultimate write to this part of memory often in games such as Sabre Wulf; a special loader will be available that removes all offending instructions.
The rest of the pages are allocated by the other seven bits in the number sent to I/O address 253. By fully decoding these bits, pages totalling over 4096K can be allocated to ROM or RAM. This is greater than any other personal computer in existence - even the mighty IBM!
One limiting factor in all this expansion (over 128 pages in all) is that the power supply will need beefing up and/ or that the address lines and so on will require buffering. However, facilities like these are included on a number of motherboards for using one or two extra RAM packs ... they can be stuck straight into the edge connector at the back of the Spectrum.
I've had a 16K ZX81 RAM pack performing (through an adaptor board) as page 255. It contains a simple Basic program

to remind me of the time (on the top line) for my appointments, while I've been using the disassembler in the internal RAM page 126. The clock runs at about half normal speed when the extra Basic software is multi-tasking. Mine is no great example, but running two games at once, as well as printing out the results of a database, might be well worth considering. It's also possible to buffer print output via one of the pages from Basic. And just think how interesting many adventure games could be with four million bytes to play with!


The final software works on any machine (with or without Microdrives) using a tape-based extension to Basic. It's loaded from tape or Microdrive cartridge into the bottom 16K of memory using LOAD "" CODE immediately after
power-up. This allows you to use keywords for switching in and out the pages and for turning the multi-tasking on and off. Stopping the program also stops the multi-tasking; thus any errors will not effect the other program.
The area between 29K and 31K in the operating system can be used to swop data between the pages. In a simple method, you can POKE the data bytes into here from one page, and then PEEK at them from another. The software will also allow you to use the various channels to swop data between pages.
Software can be written to recognise the new system as OUT 253,0; at any time PRINT IN 253 will print a number less than 127 ... if it's not fitted the number returned will be 255. Software houses should therefore have no trouble at all building in facilities that allow their programs to use the extra RAM provided.


By the time you read this, the XK system will have made its first appearance at the ZX Microfair (8th September) and the price to punters is £14 for the DIY Spectrum modification kit - £19 to have it fitted (both prices are inclusive of VAT and postage). The Basic extension to control the extra memory is included in the package. Using the same system, 16K Spectrums will be upgradeable to a full 64K of internal memory for just £74 (also inclusive of VAT and postage).
The XK system hardware is copyright of Stephen Adams. He'd like to hear from hardware and software manufacturers interested in using it - and he'd also like to hear from users (via Your Spectrum) with some idea of the sort of things they'd do with such a system, and how they would expand it.
Home Contents KwikPik