Jump to content

Contended memory

From Wikipedia, the free encyclopedia

Contended memory is Sinclair's name for a portion of the ZX Spectrum's 64 KB addressable memory space. With the full 64 KB, the Z80 microprocessor is the exclusive bus master, so it reads and writes operate at its full bus speed, but contended memory space is shared between the ULA and the Z80, with the ULA having higher priority. Contended memory occupies addresses 0x4000..0x7FFF of the Z80 memory map. This is the first 16 KB of RAM in the 48 KB machine and the entire RAM of the 16 KB machine.

Contention occurs as a result of the ULA reading the display and attributes data in this RAM to produce the TV video display. Contention therefore does not occur during horizontal flyback, vertical flyback or during the screen border.

Accesses to I/O also contend if the ULA must read contended memory while the Z80 accesses a ULA I/O port. ULA I/O ports are those with an even address (address bit 0 is a 0).

The Z80 must wait whenever the ULA needs to access contended memory before proceeding with its own contended memory read or write. The effect to the user is that programs that make use of contended memory or contended I/O run slower than those that avoid it.

Snow Bug

[edit]

The ULA must wait for a Z80 read or write to complete before it can stop the Z80's clock and access the memory; it will stop the Z80's clock only during the first clock cycle of a machine cycle.

Early Spectrums make the assumption that at most one contended memory access will occur in a machine cycle: this isn't true in instruction fetch cycles if the programmer has configured the interrupt vector table to fall within the contended area. In that case the ULA will decline to load its video address and the video byte displayed will be whatever the processor was reading. The consequence of this is random noise on the display, or 'snow'.

Since this effect did not occur under normal operation — it required a programmer's deliberate intervention[1] — it was very seldom seen, being used only in some games [which ones?] as a special graphical effect.

Later versions of the Spectrum, including all 128kb versions, correct the bug.

Circuit

[edit]

The ULA does not use the Z80's bus request/grant mechanism to become bus master during its contended memory accesses. Instead, it extends the high period of the Z80 clock input to stop all microprocessor activity. While this is less elegant than performing a bus request, it does gain contended memory access to fewer Z80 clocks. This removes any need for the ULA to read display data in advance, a benefit with the crowded circuitry in the full ULA.

The ULA connects directly to the memory system ICs while the Z80 connects to them through isolating series current-limit resistors. This allows the ULA and memory to drive each other while the Z80 is also driving the memory. Using resistors instead of tristate bus driver ICs reduces the expense of the circuit but does take a higher average I/O pin current from the Z80, ULA and memory ICs.

References

[edit]
  1. ^ "ZX Spectrum ULA – SinclairFAQ – The Snow Effect". faqwiki.zxnet.co.uk. Retrieved 2018-09-13.
[edit]