Chapter 7
61
Supplementing the Spectrum’s ROM
The Spectrum’s ROM can be supplemented to extend Sinclair BASIC with new
commands by setting configuration switch 3 to the on position. Either a ROM cartridge
must be plugged in or an onboard ROM enabled via configuration switch 2 being set
to the on position. In this mode, the paging mechanism implemented by the
ZX Interface 1 is reproduced by the SPECTRA interface. This paging mechanism
extends Sinclair BASIC by detecting when the BASIC ROM is about to display an error
report on the screen and passing control over to the ZX Interface 1 ROM so that it can
attempt to handle the command causing the error. Note that the ZX Interface 1 ROM is
also known as the Shadow ROM, with the Spectrum’s BASIC ROM then referred to as
the Main ROM.
The ZX Interface 1 intercepts the error handler routine within the BASIC ROM at
address $0008. Its hardware pages in the Shadow ROM after the first byte of the
instruction is read in, and so the remaining bytes of the instruction are fetched from the
Shadow ROM (which means that the instruction in the Shadow ROM must be same
as that in the Main ROM). Execution then continues using the Shadow ROM. Normally
the error handler routine would have displayed the appropriate error report message,
but now the Shadow ROM has the opportunity to analyse the cause of the error and to
determine whether it was due to the syntax of one of its new commands. If it was then
the corresponding command handler within the Shadow ROM is executed, otherwise
a return is made to the Main ROM so that the original error report message can be
displayed. After the new command handler has completed, a switch back to the Main
ROM is made via a call to address $0700. Fetching an instruction from this address is
detected by the hardware and it pages back to the Main ROM after a byte has been
read in (this limits the size of the instruction to a single byte). There is a RET instruction
at this location within the ZX Interface 1 ROM and so the call immediately returns but
now to a location within the Main ROM. The ZX Interface 1 paging mechanism also
intercepts an instruction fetch from address $1708, which is located midway through
the CLOSE# BASIC command handler. This is done because the command handler in
the BASIC ROM does not support the enhanced channel format introduced for the
new ZX Interface 1 facilities and so an alternate routine needed be used instead. The
Shadow ROM is paged in after the first byte of the instruction is read in and so the
Shadow ROM contains the same instruction at this address as the Main ROM
(although note that the instruction at this location happens to be only a single byte in
length).
Supplementing the Spectrum’s ROM using the ZX Interface 1 paging method has a
number of advantages. It allows a ZX Interface 1 fitted with the first edition ROM to be
effectively upgraded by overriding it with a newer version held in the external ROM of
the SPECTRA interface. The newer version could simply be a copy of the second
edition ZX Interface 1 ROM or could be a customised version that has all remaining
bugs fixed. You can tell if your ZX Interface 1 has a first edition ROM by typing PRINT
PEEK 23729, which will return a value of 0 with a first edition ROM and 80 with a
second edition ROM. Even if ZX Interface 1 hardware is not connected, it is still
possible to make some use of the new commands introduced by the ZX Interface 1