Back to the start... Back to the index

text box divider

Simon N. Goodwin reviews Linux-friendly tributes to Sinclair's ZX Spectrum

Sinclair logo

Spectrum Emulators

Sinclair's Spectrum is the best-selling British computer of all time. It introduced millions of people around the world to home computing in the 1980s. Compatible systems continued to be made and sold a decade after its 1982 introduction.

There are more than a dozen Linux-compatible Spectrum emulators. This article compares them, after reviewing the features that make the Spectrum both a worthwhile and challenging system to emulate.

text box divider

PART 1 - Spectrum features

By modern standards the ZX Spectrum is a toy, yet it was uncommonly powerful compared with rival home computers in the early eighties. It came complete with leads, two good manuals and sample programs, needing only a normal TV and portable cassette recorder to make it useful.

An original Spectrum is roughly A4 in size, smaller than most PC keyboards, though with the same key pitch. The first models were expandible from 16K to 48K RAM, which filled the eight bit Z80A processor's address space alongside the 16K ROM firmware. The ROM, from Cambridge mathematicians Nine Tiles, was based on that for the earlier ZX-80 and ZX-81, doubling in size for each update.

Dan Dare

The conductive rubber keys had a 'dead flesh' feel, typically packing half a dozen functions on each button. It inherited the bizarre keyword-entry system which protected earlier Sinclairs against rip-off clones, but this was a mixed blessing when expanded to squeeze more than two hundred keywords and symbols on a 40 key grid. You'd hesitate to program a Spectrum in C, using four key presses to type each curly bracket!

Most programming was done in ZX BASIC, a slow interpreter yet a surprisingly fast way to hack together unplanned programs. Unlike the DEC-inspired Microsoft BASIC common at the time, you can stop and change ZX BASIC programs at any time and continue with variable values, loops and subroutine scope intact. Along with syntax checking as lines are entered, this proved ideal for ad hoc program development, and an easy start for thousands of now-professional programmers.

Despite the hardware limitations there are good implementations of Pascal and Prolog, and even C, Fortran and Cobol compilers for the Spectrum. Most rely on code overlays from disk or tape, so you need an emulator that can mimic add-on drives as well as basic snapshot loading to use these efficiently on your Linux box.

Alien8 on XZX

Z80 chip

Most professional Spectrum programs were hand-crafted in Zilog Z80A assembly language, a Byzantine elaboration of crusty Intel machine code. The name was a pun on Intel, which stood for INTEgrated Logic - Zilog stands for 'Z' (as 'in the last of') Integrated LOGic. Zilog trounced Intel's eight bit range, but not in bigger or embedded chips. Zilog's complications pose an extra challenge to emulator writers, though perversely attractive one to anyone who absorbed the intricacies of the Z80 at an early age.

Unlike modern chips, the Z80 was built-in random logic, without the benefit of microcode or simulations to structure its design. Extra circuits were literally taped onto the edge of the mask used to make the chip, piling on hidden states and interactions, as well as arguably useful features. Chip-makers Zilog documented 600-odd official instructions, some of them very esoteric, but in fact the chip responds to more than 800 op-codes and any decent emulator has so recognise the unofficial ones as well as the standard set. Spectrum programmers used knowledge of these secret features to show off their expertise and to make their code harder for others to steal.

ZX Graphics

Alongside the Z80A, Sinclair encapsulated Spectrum-specific interfaces into a similar-sized custom chip, a Ferranti logic array. This leapfrogged rivals like the Apple, TRS-80, Pet and BBC micro, which were built from scores of standard TTL building-block parts. Sinclair's ULA cut costs and made life difficult for clone-makers - and poses more challenges for programmers and emulators.

Cybernoid

Programs exploit undocumented ports in the ZX82 ULA to circumvent the limitations on colour positioning. Officially the Spectrum supports a wide border in one of eight colours, around a grid of 24 lines of 32 character positions, allowing just two colours chosen from 15 in each grid square of 64 pixels. This arrangement allowed high-resolution colour graphics - 256 by 192 pixels really /was/ HiRes in those days - but the restrictions of the grid led to 'attribute clash' when moving images don't exactly fit the eight by eight pixel two-colour areas. Ugly as it sometimes is, emulators have to mimic this precisely, catering for precise timing that allows real Spectrum programs to tweak the ULA's data as the TV screen is scanned.

The key advantage of Richard Altwasser's hardware design for Sinclair was that the whole screen consumed less than a third as much memory as it would have needed without colour restrictions, leaving more space for programs and dramatically reducing the CPU burden of display animation. Emulators work harder - one eight bit write to Spectrum video memory can change the colour of 64 pixels. True-colour screen emulation has to update a couple of hundred of bytes to get the same effect as a single byte poked to Sinclair's screen RAM.

Storage stories

Sinclair made four models of ZX Spectrum - the original 16K and 48K models, priced from £125, then the reboxed Spectrum Plus with a much inferior manual, followed by the Spectrum 128 with extra RAM and three channel sound, which was funded by Sinclair's Spanish distributor Indescomp. This had a serial port, a compatible 48K mode and new 128 mode with an editor, RAM disk and no keyword entry, but few other changes.

The Spectrum cassette interface loaded programs uncommonly fast and reliably by home computer standards, but it was still tortuous, taking five minutes to load 48K at three per cent of the speed of a modern modem. Sinclair teased those unwilling to wait with quirky microdrives - tiny disk-substitutes that churned loops of video tape. They could rival the speed of floppies once data was located, but initial access time averaged 3.5 seconds on a good day, and half an hour or never on a bad one...

Tasword2 help

Microdrive tapes were expensive and held only around 90K, so a thriving market grew for add-on interfaces for conventional 5.25 and 3.5 inch floppy drives, even though the expansion cost more than the computer.

Later Spectrums were inflated to 128K RAM and 32K then 64K ROM by bank-switching - a bodge which shuffles four 16K chunks of memory in the Z80's 16 bit address space. This hampers emulation of Spectrums with more than 48K RAM; either each emulated memory access must look up the current location of the target byte in a separate table, or writes to control ports must be trapped, copying 16K areas in and out.

The design of a bank-switching emulator limits its speed, even on modern systems. Processor emulation is typically CPU-intensive, as dozens of new instructions must be performed for each old one interpreted. When a Spectrum writes a byte to a bank-switching port, as often happens in the 128 BASIC editor, any emulator that has to copy 32K will need a very fast host to keep up.

The thousandfold increase in CPU speed in the last two decades means that any 32 bit Linux host should manage full-speed 48K Spectrum emulation, but memory advances have lagged behind those in processor cores. If you want to emulate a Spectrum 128 or other machine with bank-switched memory you're better off with an emulator written from scratch for that job, rather than a 48K one with extra code to waft 16K chunks around.

Amstrad Spectrum Plus 2

Enter Amstrad

Overstock problems after the home micro market peaked led to a 1986 buy-out by arch-rival Amstrad. Alan Sugar's company made millions more Spectrum 128s than Sinclair, scrapping their CPC range to focus on Spectrums with nicer keyboards and en-suite floppies. The built-in drive on their Spectrum +3 was a three inch Hitachi format. This flopped in a battle with Sony's 3.5" standard, even though the narrower format gave it cheap passage through Japan's postal service, exploiting a concession designed for posting cassettes. A normal 3.5" drive could be added externally, and most PC, Mac and Amiga drives can read that format directly via Linux.

Ian Andrew's Driller

These were cosmetic improvements. Most classic Spectrum software runs in 48K, and Linux loads it in milliseconds. The ZX legacy was taken much further by MGT's SAM, and Eastern block Hobbit, Pentagon and Scorpion clones. Software for these is more capable but less common, and runs on several Linux emulators.

Amstrad's most generous legacy is to allow free non-commercial distribution of the ROM firmware from their 1980s home computers, legalising dozens of Spectrum, QL and CPC emulators. They even allow electronic distribution of the original manuals, making the emulators complete and easy to use.

text box divider

PART 2 - Emulators compared

There are at least a dozen Spectrum emulators that will run on Linux, plus a couple more for MGT's SAM which has a Spectrum-compatible mode. Those two, XCoupé and SimCoupé, do a reasonable job of 48K Spectrum emulation but their real strengths lie elsewhere. Java emulators are discussed at the end of this section.

Ultimate's debut JetPac

That leaves eight emulators specifically written to run Spectrum programs under X. The best of these are XSpectEmu, X128 and XZX, though it's worth trying others as they're all free and system requirements vary. You may need to fiddle with makefiles to get them to compile from source, as they've been developed over many years and not specifically for current Linux builds.

I found XSpectEmu much the easiest to install. The Debian package needed no extra files beyond the basic 2.2 release, and added a direct desktop link to launch the emulator. It's a lot faster than the emulators that run 128K software, but not as fast as the French emulator which has a hand-coded CPU emulation core specifically for X86 systems.

SpectEmu

SpectEmu lacks menus. Snapshot files are selected for loading and saving by pressing a function key and typing the file name and path in a crude terminal window, lacking input history or even editing with cursor arrows.

Don Priestley's Maziacs

You can play, pause and stop the emulated tape drive, and trade accuracy of emulation against speed in loading. The emulator can run at standard Spectrum speed - with impressively accurate display and sound synchronisation - or flat out, using all the CPU time it can get. This makes input tricky, but is sometimes handy and often impressive. With SpectEmu an AMD K6-2/500 Linux box runs ZX BASIC about twenty times faster than a Spectrum, roughly equivalent to a 70 MHz Z80.

The ZX BASIC command POKE 23561,0 limits the keyboard repeat rate. Press the letter "O" at the start of a line to enter the POKE keyword. Run the emulator at normal speed and save a snapshot with this command, then reload it into a fast emulator to have a chance of typing on an amphetamine Spectrum.

Keyboard handling in SpectEmu is close to that of the original, with some additions for keys not on the original system. Like Sinclair's original, left and right shift keys have different interpretations. You can use modern keyboard cursor arrows, in place of Sinclair's shifted digit combinations, and a combination of control and function keys call up new options.

Other buttons reset, quit or give basic help, and one resynchronises the video and keyboard if they get out of step. I did not find that a problem, though SpectEmu did reject some snapshots I tried, showing garbled graphics and resetting the emulator. Most emulators have similar problems, although the extent varies and files that one accepts might clobber others. Snapshot formats vary and many are saved with errors, caused by bugs or misinterpretations of the standard. Clever loaders try to fix these, as noted in the accompanying panel.

X128 and XZX

X128 is controlled with function keys that pop up menus in the original ZX font. This fits in well with the original system and allows changes on the fly. I've enjoyed using X128 since I found Paul Hill's Amiga port of James McKay's original code; it benefits from the extra speed of modern CPUs, but the Linux version needs updating to match the features of X128 on other platforms.

X128 hardware emulations

The shareware XZX favours X menus and windowing, but requires the Motif GUI toolkit, rather than GTK++ or KDE extensions customary on Linux. The 'open' version of Motif rarely features in common Linux distributions. I got XZX 3 working with Lesstif, a Motif clone which is a less painful download than the full version, but not all the sub-menus worked and those that did were messily rendered.

XZX is silent unless you indicate '-audio 1' for output to /dev/dsp. By default emulation is normally limited to 100 per cent of original Spectrum speed, but 12 to 14 times faster with the command line parameter '-fastmode 1' to remove the brakes.

Manic Miner

XZX and X128 offer more to former Spectrum programmers than XSpectEmu, but demand Unix as well as Spectrum expertise. Both benefit from MIT-SHM extensions, standard in XFree86, to boost X redraw speed.

The rest

XZ80 was written by Ian Collier, a guru of the comp.sys.sinclair newsgroup, but stalled at version 0.1. The core is well programmed, including clever ROM patches, but XZ80 has rather slow sound and ZX printer emulation, but lacks support for later hardware like disk drives or memory expansion.

Fuse is written by Philip Kendall, maintainer of the Spectrum FAQ, but he's not generous to it. The current version 0.3 is better than , gaining sound and losing dependence on Allegro toolkit, but it's still rather crude and a CPU hog. Fuse emulates 48K and 128K Spectrums but has a minimal user-interface - just half a dozen function keys to access preset tape and snapshot file names.

Also-rans include the officially-titled 'unnamed' Sinclair Spectrum emulator by Thomas Harte, which is as minimalist as its name suggests, Jean-Francois Lozevis's hard-coded X86 Spectrum 48K emulator, and zxsp-x, a Mac port by Günter Woikg which benefits from Qt, the toolkit popularised by KDE.

Java options

Spectrum emulators written in Java are neat hacks as they run on any Java-enabled machine, not just Unix systems, but the extra overhead makes them relatively slow, even though they only attempt 48K Spectrum emulation.

Hob and Jasper are both written and actively supported in the UK. Hob may be the one to watch, but is so far only available to run on-line, and lacks sound. For the time being Jasper is more complete but only manages two thirds of the speed of a real Spectrum on an 500 MHz AMD K6 running Netscape 4.72. You'll need a fast processor, or a compiling virtual machine, and preferably both, to make good use of this, but it does run nicely on the Linux-hosted Amiga SDK.

Chukkie Egg on Jasper on Elate on LinuxElate ZX emulation; click for Jasper on Netscape

The programmer of /Java Spectrum/ admits it is 'not very good yet' - it runs some programs but not all, and is a Java application not an applet so it needs a full Java Development Kit, not just a browser. The author calls it a 'neat toy' and you can get the source if you want to take it further. I've also found links to a Java Spectrum emulator called JZ80, apparently related to Hob, but my Czech is inadequate to check this out.

text box divider

File formats

You need to understand emulator file formats to use the thousand of ZX files on the net. The original snapshot standard was .SNA format, popularised by Arnt Gulbrandsen's JPP emulator, named after the Sinclair tape-loading key sequence: J for SAVE and Shift P for a pair of quotes.

SNA format is based on the files generated by a Mirage Microdriver, a real Spectrum add-on with a 'magic button' that saved uncompressed 48K memory images and processor registers in a 49179 byte file. More common nowadays is .Z80 format, from the eponymous MSDOS emulator by Gerton Lunter. This supports data compression and 128K images with sound chip data, but the extensions mean that there are several variants of '.Z80' format and compatibility is not assured. SPCONV converts between Z80 and SNA formats, and sometimes fixes snapshot bugs in the process.

'TAP' is another emulation file format, designed for programs that load blocks from tape in several parts, merged into one host file. TZX is a lower-level tape format, essentially a sample of the original audio. TZX is more verbose but more flexible than snapshots or TAPs; it can encode 'protected' data which would require a non-standard loader, though these are a severe test of emulator compatibility. VOC is an alternative raw sample format.

Tau Ceti

Fixed-sized 'image' files can correspond to the contents of an add-on drive for the original Spectrum. Like TAP files these allow multi-part loading, and contain hidden directory data that Linux cannot easily store, making them more compatible with special files and programs that perform random access. Common formats include Opus Discovery, MGT Disciple and Plus D, TRDOS, Amstrad Spectrum +3 and microdrive images.

You can move files to and from these images with emulators or standalone utilities. Linux device-independence means that as long as the disk and sector sizes are appropriate you can directly transfer image files between Spectrum floppy disks and Linux devices. Don't expect this to work with microdrives, though! If all else fails, use a 9600 baud serial link to a Spectrum 128 or an older model with Interface 1 or similar serial expansion.

Next month

The Spectrum's arch-rival was Commodore's 64. Again it was a refinement of earlier hit systems, from the PET through the VIC-20, and sold millions worldwide. But Commodore's eight bit boxes were based on the 6502 chip, a RISC design by comparison with the Z80, augmented by not one but two custom chips that squeezed extraordinary results out of a domestic TV and cassette drive. There's no shortage of C64 emulators for Linux, and next month's column will compare them.

text box divider

Emulator fuel

Spectrum emulators are widely available on line and come complete with the vital ROM files, thanks to the generosity of Amstrad. We've put enough to get you going and ZX-related utilities for Linux on the cover CD, but could have filled the whole disk and more besides with Spectrum files if we'd been willing to push everything else aside.

Instead we've listed links, most notably Planet Sinclair and World of Spectrum, and checked out CD compilations which address the popularity of ZX emulation on many platforms. If you don't fancy trawling through thousands of snapshot files on line, Weird Science have a couple of budget CDs which could save you time - and money too at £4.99, unless your Internet connection is uncommonly quick and cheap.

Retro Gold is a combination Spectrum and C64 emulation compilation - it does not include any emulators specifically for Linux, but does contain thousands of well-known Spectrum game snapshots, and some ZX applications too, for programming, graphics, education, business, utilities and adventure-writing.

Smuggler's Cove

Speccy 99 is a Sinclair-specific compilation CD with many of the same snapshot files, hundreds of related documents, and some Linux utilities. Updates of this compilation were an annual event for much of the 1990s, and previous discs have featured similar ZX files and older emulators like XZ80.

The 1999 remix has a directory of emulators for Linux and Unix in general, containing SpectEmu, X128 and dynamic and statically linked versions of XZX for Linux. Other Sinclair-related emulators on this disc include Z81 which runs programs for Spectrum precursors ZX-80 and ZX-81, the QL emulator QLAY for Linux, and SimCoupe, which emulates MGT's ultimate extension of the Spectrum line - the attribute-free, 128-colour, double-resolution, six-channel stereo, megabyte-expandable SAM Coupé, which we'll explore in a future column.

Contact: Weird Science, (UK) 0116 2350045


text box divider

Spectrum-compatible emulators for Linux

Fuse: Spectrum 48K/128K

Hob: Java 48K Spectrum

Jasper: Java Spectrum 48K

Java Spectrum: 48K, requires JDK

SimCoupe: Spectrum and MGT SAM

SpectEmu: ZX Spectrum 48K

Spectrum: French 48K Spectrum

unnamed: Sinclair Spectrum 48/128

X128: Spectrum 128 and beyond

XCoupe: Spectrum and MGT SAM

XZ80: Sinclair Spectrum 48K

XZX: ZX Spectrum 48/128/+3

XZX2/3: Spectrum and compatibles

zxsp-x: Spectrum 16/48/128K


STOP PRESS!


Since this article was published we've found another!
Glukalka is a Spectrum 128 emulator from Russia, with Beta disk and tape emulation and a Motif user interface.


SincLinks

Main sites (updated November 2006)

Planet Sinclair

World of Spectrum

Magazines

Crash

Sinclair User

Your Sinclair 1

Your Sinclair 2

Your Spectrum

Emulator homes

SpectEmu

X128

XZ80

XZX

Java Spectrums

Hob

Jasper

JXSpeccy

Back to the start... Back to the index