A Bit About the Sinclair ZX Spectrum

It’s probably a good idea to go into some of the details of the Sinclair ZX Spectrum. This will help you understand what the machine was about and how that can affect some of the work we will be doing during this series of blogs. We don’t need to know the ins and outs of all the hardware or anything like that, but if we want to try and faithfully reproduce a game, we need some information about how the original hardware was put together. So, I’m going to try and explain that a little. I’ll try to explain in as much detail as I can, but feel free to comment with any questions or if I’ve made any errors.

Graphics Mode: Resolution

The ZX Spectrum has an image resolution of 256 x 192 pixels. It has considerable colour limitations and in it’s time, was mocked for these limitations, which became commonly known as “colour clash”.  But why does this happen, and what is going on with the colours?

Well, to understand that, we first need to know how the ZX Spectrum holds it’s graphics data. Simply put, it’s a switch – on or off. Each byte of data holds 8 bits, with each bit representing a single pixel on the screen. When a bit is set to on, that means the foreground colour will be shown, and when the bit is 0 it means there is no foreground colour and so the background colour is shown. Easy init?

So, we know that we need a screen resolution of 256 x 192. This is nice and easy to achieve because the Atari ST has a low resolution of 320 x 200. So, we have more pixels to play with: 64 on the horizontal axis and just 8 on the vertical axis. Therefore, if we want to make sure our game is centred, we would just need to offset by half of those differences. However, we know that the ST works best on 16-pixel boundaries, so we don’t offset the vertical. We will use 32,0 on the ST to represent the 0,0 of the ZX Spectrum, and that way we can take advantage of the 16-pixel boundaries. We will be centred horizontally, but at the top of the screen vertically. In truth, an 8-pixel difference on the vertical axis will be barely noticeable.

Graphics Mode: Colours

But what about the colours? Well, to conserve memory, colour is stored separately from the pixel bitmap in a low resolution, 32×24 grid overlay, corresponding to text character cells. This means that all pixels of an 8×8 character block share one foreground colour and one background colour. Hence, when objects move between the 8×8 character blocks, their colours change and cause clashes with other objects close to them. Clever coders learnt to work with these limitations, and games such as Trap Door and Popeye by Don Priestly used tricks to move the colour grids along with the sprites to great effect.

The ZX Spectrum has a colour palette of just 16 colours. Well, the truth is that it’s actually only 8 colours, but with a dark and bright setting for each, so technically 15 colours (as you cannot have a bright black).

Each 8×8 character block has it’s colours represented by a single byte of information. Therefore, the palette information for the Spectrum takes 768 bytes. Each byte of information holds the foreground colour, background colour, brightness setting, and finally a flash setting that switches the foreground and background colour data through interupt.

The palette is as follows, showing the Atari ST & STE equivalent values:

90011Bright Blue$007$00F
100101Bright Red$700$F00
110111Bright Magenta$707$F0F
121001Bright Green$070$0F0
131011Bright Cyan$077$0FF
141101Bright Yellow$770$FF0
151111Bright White$777$FFF

Note: The Spectrum holds it’s RGB values in a different order to allow black and white television sets to show appropriate grey scales – very clever!

You can read more about the ZX Spectrum graphics modes here.

For our purposes, we are going to use just the standard ST palette, and we are going to store the normal and bright colour next to one another. Therefore, we can use the following command within STOS to achieve this:

PALETTE $000,$777,$005,$007,$500,$700,$504,$707,$050,$070,$055,$077,$550,$770,$555,$777

Note: We have used colour 1 to be white as there is no “bright black”.

Hopefully that has given you a bit of an insight into how the ZX Spectrum graphics systems work, and what we need to do to get our games looking right and proper.