# Spectrum

Under certain conditions, a Memotech can emulate a ZX Spectrum, to a certain degree. MEMU can emulate a Memotech emulating a ZX Spectrum!

To help integrate this emulation, MEMU supports a ZX Spectrum tape file format and a ZX Spectrum snapshot file format.

## Z ZX Spectrum Emulator

Z is a ZX Spectrum Emulator which runs on the MTX.

MEMU includes a copy of `Z.COM` (and `Z.mtx`) which have the Z cassette LOAD/SAVE/VERIFY routines patched so they ask MEMU to read or write a ZX Spectrum `.tap` file. By default, this is called `memu.tap`.

MEMU includes `ZXSpectrumOriginal.tap`, which contains a dump of the original 48KB Spectrum ROM. It also includes `ZXSpectrumGoshWonderful.tap`, which contains a dump of the Gosh Wonderful Spectrum ROM. Either ROMs work fine, but the Gosh Wonderful ROM allows you to type in the keywords, rather than P for PRINT etc..

To load Z, and to allow it to read a Spectrum ROM :-

    $ cat ZXSpectrumGoshWonderful.tap > memu.tap
    $ memu -vid-win -snd-portaudio Z.COM

Every time Spectrum code tries to load something, it just reads further and further into the file. So if you want to be able to load a program :-

    $ cat ZXSpectrumGoshWonderful.tap program.tap > memu.tap
    $ memu -vid-win -snd-portaudio Z.COM
    LOAD ""

Z2 is like Z, except it has the Gosh Wonderful ROM built-in, and has various improvements made since the original. Although Z will be left unchanged as a record of how it was in 1987, Z2 will likely evolve over time. It can be used like this :-

    $ cat program.tap > memu.tap
    $ memu -vid-win -snd-portaudio -mon-win-big Z2.COM
    LOAD ""

The F9+t diagnostic keypress can be used to make the next load start at the beginning of the `.tap` file again. Think of this as rewind-before-loading.

Every time Spectrum code tries to save something, it just appends more data to the end of the file.

It often makes sense to delete the file before saving, so as to end up with just the data you want. Think of this as rewind-before-saving.

You can also use the F9+s and F9+l diagnostic keypresses to save and load Spectrum `.sna` snapshot files. But note that real Spectrum `.sna` files and Z `.sna` files are slightly incompatible, due to differences in the way interrupts are handled.

You'll need to refer to a picture of the Spectrum keyboard to work out what keys to press. Right Shift is mapped to Symbol Shift (and on Windows to press Right Shift on the MTX keyboard, you actually press the "applications" key on the PC keyboard, next to the right Ctrl key).

If you're using Z2, things are easier, as it displays a picture of the Spectrum keyboard on the 80 column screen when it starts.

## Speculator

This is a hardware and software combination, devised by Tony Brewer, which allows a Memotech to load a number of Spectrum games from Spectrum tapes, and play them.

Here is a detailed article describing it.

MEMU emulates the hardware as described by the Speculator section of the Emulation page.

The Speculator software includes an interrupt routine which copies Spectrum screen memory to the VDP. It also converts Memotech keyboard to Spectrum keyboard. It also includes loaders to load each of the supported games. It may also customise the emulation based upon each game loaded.

`SPEC1.mtx` probes all the port ranges (partially) decoded by the Speculator hardware, and as a result, won't run under MEMU. `SPEC1A.mtx` is a patched version which only probes the ports needed, and emulated by MEMU. `Speculator.mtx` is a further patched version which instead of using Memotech hardware to read Spectrum tapes, asks MEMU to read or write `.tap` files instead.

MEMU includes some of the originally supported Spectrum games in `.tap` format, and they can be loaded like this :-

    $ cp Gridrunner.tap memu.tap
    $ memu -vid-win -snd-portaudio Speculator.mtx
    LOAD ""
    press F to select Gridrunner

In certain cases (Astronut, Daley Thompsons Decathlon, Jump Challenge, Laserwarp, Percy the Potty Pigeon, Tornado Low Level), the readily available `.tap` file(s) have a different record structure to what the Speculator loader for that game expects. So these cannot be loaded. Presumably there must have been multiple issues of certain games.

The readily available Astronut and Jump Challenge `.tzx` files can be converted to `.tap` file and are then loadable by Speculator.

Astronut needs a code sheet, or use a snapshot instead.

If The readily available Tornado Low Level `.tap` file is patched and the Speculator loader is also patched, it can be loaded, and runs fine. But 3 readily available `.tzx` files can be converted to `.tap` files, and all 3 work fine. This game is the only one which Speculator runs in the "immediate NMI" mode.

In other cases (eg: Atic Atac, Jet Pac), tape images are not readily available (denied distribution), but if you can lay your hands on them, then they work :-

Where we don't have `.tap` files, or files that load, we may have `.sna` files :-

    $ cp StopTheExpress.sna memu.sna
    $ memu -vid-win -snd-portaudio Speculator.mtx
    LOAD ""
    F9+l

Some of these were made by loading `.tap` files into fuse and then saving a snapshot.

Starion is interesting. Loading it from its `.tap` is not always reliable, and if it does load, it can hang. It seems to be doing something interesting with the HALT instruction. If you restore it from its `.sna` snapshot, then it runs, but the Speculator NMI mechanism produces visible corruption. The normal Speculator loading process will have patched the loaded code to avoid this, but of course, restoring unpatched code from a snapshot taken from another emulator is still going to exhibit the problem. This article in Your Spectrum explains how Starion disables interrupts and uses POP and PUSH as a fast copy. There is no NMI on a real Spectrum, but Speculators NMI interferes with this. It also explains that the original Starion could not be completed, but we also include a Snapshot of the patched version (which Speculator could never have loaded from tape).

Knight Lore isn't one of the Speculator supported programs, but we can attempt to restore it from a snapshot. It works for a little while, with visible screen corruption (perhaps like Starion?) and then invariably crashes. Maybe it has insufficient stack space for the Speculator NMI to use.

Blobbo (ZX Spectrum version) is another program that Speculator didn't support, but again we can restore this from a snapshot. This basically works.

## REZSPEC

REMEMOrizer includes REZSPEC, which is the best of both worlds. It works like Z2 in that it embeds the Spectrum ROM and patches it, but it also exploits the Speculator style hardware now present in REMEMOrizer. So it should allow many games to be LOADed and run unmodified.