Contention, snow and the floating bus

In a Sinclair Spectrum the processor and the chip that draws the picture - the ULA, or the gate array on a +2A and +3 - share part of the memory. Three effects come out of that sharing: the processor slows down in that memory, rubbish called snow appears on the screen, and ports read back what the ULA is drawing. Programs depend on the first and the third. The second is a defect that some programs show. This page explains what each effect is and how Xpeccy+ emulates it. You can switch each one per machine in Machine: Advanced Settings, group ULA (see Advanced settings). Every machine starts with the settings of the real one.

One memory, two users

The ULA reads the screen from RAM while the beam draws it, and the beam cannot wait. If the processor wants the same memory at the same time, the ULA wins, and the processor’s clock is held until the ULA’s read is over. This is contention. For every 16 pixels the ULA reads four bytes in a row - pixels, attribute, pixels, attribute - and then leaves the memory alone for a while. So how long the processor waits depends on the exact moment it asks: from 6 ticks to none. Over the border and while the beam returns, nothing waits.

  • On a 48K, the 16K at #4000-#7FFF is shared.

  • On a 128K and +2, pages 1, 3, 5 and 7 are shared, wherever they are paged in. A port whose address looks like shared memory, or whose lowest bit is 0 (the ULA’s own port), is held the same way.

  • On a +2A and +3, the gate array shares pages 4, 5, 6 and 7, with a pattern of its own, and holds no ports.

  • The Pentagon, the Scorpion and the other clones share nothing: their processor never waits.

Two batches of the same ULA start all of this one tick apart. These are the early and late timings. The 128K machines that were tested are early, and every +2 tested is late.

This matters to any program that counts ticks: a border effect, a multicolor picture, a sound played by the processor. For each memory or port access, Xpeccy+ looks up the wait at the tick where the access starts, and waits it out. This includes the accesses the Z80 makes without reading anything.

Snow

Every time the Z80 fetches an instruction, it also puts a refresh address on the bus for the memory chips: the I register and the R counter. If I points into shared memory - on a 48K at #40-#7F, on a 128K also at #C0-#FF with an odd page there - that refresh reaches the memory the ULA is reading, and spoils its read. Depending on where in the ULA’s cycle it falls, one of two things happens:

  • the ULA reads a pixel byte and its attribute from the wrong address, with the low bits taken from R. This gives a cell of rubbish - the snow;

  • or it misses its second pair of bytes and shows the first pair twice.

Snow happens mostly when a program puts its interrupt table in shared memory. A +2A, a +3 and the clones do not snow. Xpeccy+ follows the study and the tests of weiv, which PheeL and balford filmed on real machines. The snow falls on the same columns and in the same shape as on the real machine, and on a 128K it comes from the same page. A +2 running Mark Woodmass’s IR Contention 128 snows the same way as a real +2 does in a photo of its screen taken during that test.

Some 128K machines hang or reset under snow. Nobody knows exactly why, so …and it crashes only imitates the effect: after a snowy access, the next instruction the processor reads from the shared memory comes from the wrong address, and the program usually crashes. It is off on every machine.

When a game snows

Snow is on for the 48K, the 128K and the +2, as on the real machines, so that a program that snows shows it. If a game snows in ten frames within any two seconds, even lightly (Dizzy 3 on a 128K snows in one frame of four), Xpeccy+ tells you: the picture is dimmed, snow falls over it, a snowflake blinks in the top left corner, and a message explains what it is. Meanwhile the game keeps running. The message comes once for each image - a tape, a side of it, the disk in drive A, a snapshot - and again when another one is opened or the machine is reset.

  • Turn Off for Now - no snow until a reset or another image. Nothing is saved, and the machine keeps its setting.

  • Continue (or Esc) - the snow stays. The real machine shows it too, and the game’s author may want to know. The snowflake stays too. It blinks while the game snows, goes out when the snow stops (in a menu without snow, for example), and comes back with the snow.

To get no more of these messages, for any game, tick Don’t show this again before you press either button. The snow is then shown as before, without a word. To bring the message back, use Snow notice in Options > Appearance, Configure indicators (see Indicators on the picture). If you apply settings in Options while the message is up, the message closes, and a tick in it is not kept.

To get rid of the snow for good, choose a machine that does not snow, or switch ULA snow… off in Machine: Advanced Settings (see Advanced settings). Fast loading, fast forward, rewind, an RZX recording or playback and the Debugger do not raise the message.

The floating bus

If a program reads a port that nothing answers, it reads whatever is on the bus at that moment. On a Spectrum that is the byte the ULA is fetching for the screen, or #FF while it fetches nothing. A program can use this to find out where the beam is: it waits for a known attribute, then draws. That way it can move sprites without flicker. Sidewize, Short Circuit and Terra Cresta do this, and so do Arkanoid and Cobra in their first releases.

The Floating bus setting has four answers:

  • Ferranti ULA - 48K, 128K, +2: the screen byte being fetched, or #FF otherwise. On a 128K and +2, the paging latch takes even a read of port #7FFD, and the pages switch.

  • Amstrad gate array - +2A, +3: for decades people thought these machines had no floating bus, until Ast A. Moore and Hikaru worked out its rules on real machines. It can be read only on some ports and only with paging on, bit 0 is always set, and between fetches the bus holds the last byte the processor moved in shared memory.

  • Port #FF (clones) - the Pentagon, Scorpion and others: no shared bus, but a port #FF that gives the attribute of the cell being shown, or #FF over the border. On the Scorpion this is taken from its schematic.

  • None - always #FF.

The joystick port with no joystick, the mouse ports with the mouse off and the AY’s port with no AY also read the floating bus, as they do on the real machine.

One model for all three

Contention, snow and the floating bus are the same thing seen three ways: the ULA’s reads, tick by tick. Xpeccy+ counts all three from one position of the ULA in its 16-pixel cycle, so they cannot drift apart. They were checked against tests whose results on real machines are published, photographed or filmed: Richard and Tim Butler’s timing tests (37 of 37 on the 48K, and on an early 128K the same five failures a real one prints), Patrik Rak’s timing test, Mark Woodmass’s floating bus, paging and contention tests, Hikaru’s +2A/+3 floating bus test, and weiv’s snow tests. The ZX Spectrum Next is the exception: its contention and floating bus come from its own FPGA design, and it does not snow.