
Colour Clash: The Engineering Miracle of the Sinclair ZX Spectrum - empressplay
https://paleotronic.com/2018/09/29/loading-ready-run-sinclair-edition-the-zx-spectrum/
======
flohofwoe
What's not mentioned in the article is that the pixel memory also had an
interesting layout. It's organized as 32x192 bytes, with each byte holding 8
1-bit pixels. But the memory wasn't organized in a linear fashion. To get to
the next pixel line you don't add 32 bytes, but 256 bytes (adding 32 bytes
gets you to the next character line, 8 pixel lines below).

My guess is that this was done to simplify and speed up character rendering.
The Z80 has 8-bit registers, but 2 consecutive registers form a 16-bit
register pair. E.g. you have the 8-bit registers H and L, which form the
16-bit register HL.

To get to the next horizontal character, you simply increment L, continue
incrementing past 31, and you get to the start of the next character line.

To copy a font character, just increment H and write a font glyph byte to the
address pointed to by HL 8 times.

The East German KC85/4 (which borrows many ideas from the Spectrum) took this
idea one step further, it had a 320x256 display, also organized as separate
pixel and color banks (40x256 bytes each). But the video memory was 90 degree
rotated. Put a video memory address into HL, incrementing L gets you to the
next vertical pixel line, and incrementing H to the next horizontal 8-pixel
byte.

Each 8-bit home computer had it's own signature video memory layout, basically
early attempts at hardware image compression (a bit similar to today's GPU
texture compression formats).

~~~
flohofwoe
Bonus BASIC program demonstrating this :)

Go here:
[https://floooh.github.io/tiny8bit/zx.html](https://floooh.github.io/tiny8bit/zx.html),
select "128 BASIC", enter the following program, then start it with "run":

    
    
        10 for i=0 to 7
        20 poke 16384+i*256,255
        30 next i

~~~
emilfihlman
The emulator sucks btw, it can't handle alt+tab or ctrl+pageup/down for
navigating away.

~~~
flohofwoe
Huh? Weird, it works on Windows and Mac for me (Alt-Tab on both, and Ctrl
PageUp/Down on Windows, no such keys on my Mac keyboard to test though). I had
to consume the browser key events in order to catch the function keys for the
emulator (e.g. Chrome uses F1 on Windows for showing the help, but F1 is also
needed in the emulators), maybe you're seeing a side-effect of this.

Feel free to write a ticket here with reproduction steps:

[https://github.com/floooh/chips-test/issues](https://github.com/floooh/chips-
test/issues)

------
chx
I learned programming on a ZX Spectrum 48K my parents smuggled into Hungary in
1985 summer at ten years old. I have since become a senior software architect
and the Speccy will always have a special place in my heart. it's been quite
the journey.

~~~
shodan666
Worth to mention that it was NOT the communist "regime" who forbade citizens
of Eastern Block to own personal computers but... USA under the Coordinating
Committee for Multilateral Export Controls (COCOM) who banned import of
personal computers or transistors to eastern block...

~~~
forapurpose
That may have been true, but IIRC the Soviet totalitarian dictatorships also
tightly controlled access to communication and content creation devices. Fax
and copy machines were tightly controlled to prevent unwanted communication
and underground newsletters, for example.

In fact, I read that one reason for the opening up of the USSR under Gorbachev
was that the Soviets realized that they couldn't both maintain a totalitarian
dictatorship and keep up in information technology.

(I read this stuff awhile ago and my memory of the details is vague. For
example, I don't know if those policies existed in Hungary specifically.)

~~~
flohofwoe
This is definitely true, at least for Eastern Germany where I grew up. The
best you could get as a 'citizen' was a typewriter. Any sort of printing or
copying machine was off-limits (edit: at least until the mid-80's, you could
definitely buy a 9-needle-printer, but those things were scarce and
_expensive_ , I remember that I sent cassette tapes with source code via
snail-mail halfway through the country to a guy who had access to a printer,
and a few weeks later I got the printed listings sent back) :D

East Germany put a lot of effort into tech-education though. The "glorious
leadership" realized that they were quickly falling behind in high-technology
during the 70's, and they actually tried to fix this.

Most of the 8-bit computers that Eastern Germany started to manufacture in '84
were former 'grass-roots' designs done by hardware engineers as side projects.

When the government desperately needed cheap hardware for education, those
side projects got green-lit and were developed into official projects. This is
where reality kicked in again unfortunately, the limited resources of the
"real-socialist economy" didn't allow for the mass production necessary to
fulfill private demand, so everything that was built went to schools and
universities (at least!), but also military academies.

------
TuringTest
It was actually 15 different colors. The "bright black" could have been shown
as dark grey, but it didn't; it was the same as "black".

That allowed showing bright colors against a uniform black background, which
otherwise wouldn't have been possible, as the "bright" flag was set for the
whole colour cell and shared for both figure and background pixels.

~~~
jeffwass
Reminds me of the monitor we got for my Tandy 1000 back in the 80’s.

$50 for a CGA monitor at Trenton Computer Festival. A total bargain! But the
case was made of styrofoam. And out of the box it only supported 8 colours, we
had to build the logic board to apply the intensity bit to go to 16 colours.

But it turned out to be actually 15 colours, unlike normal CGA or Tandy
graphics, the ‘bright’ black came out as black and not dark gray, so
occasionally had issues with software that depended on the contrast between
color 8 and color 0.

~~~
jacobush
Reminds _me_ of the ABC 800 (Swedish Z80 computer) color monitor. Heavy
bastard, built like a tank in sheet metal and painted in some kind of brown
shade suitable both for the tax office and the military radar station. Great
high quality RGB monitor for your Amiga, Atari, or what not - except it had a
logic board which "truncated" any analog signal into 16 (or thereabouts,
possibly 8) colors. It could be rebuilt by your local geek for a case of beer
or equivalent value.

I was a little late to the party and without the electronics chops myself, I
had to let my Amiga be bereft of 4080 of its 4096 colors.

------
Marazan
Then there's the amazing BiFrost and Nirvana engine which beat the colour
clash limitations to produce huge full colour sprites on the Speccy. Amazing.

~~~
jacquesm
You could do pretty high res full color images by displaying three single
color images in a row with the palette reprogrammed between the images. By
using a long exposure camera in front of the screen and a hood to get rid of
ambient light some pretty impressive results were possible. Only for the
patient though, and once true color monitors and video cards became affordable
(or even just R5G5B5) this sort of trickery was no longer needed.

~~~
vidarh
So basically the reverse of some of the first digitizers/frame grabbers for
the Amiga, which came with a colour wheel. To capture an image, you used a
video camera and the colour wheel and did three passes with red/green/blue
filters in front of the camera:

[http://www.bigbookofamigahardware.com/bboah/product.aspx?id=...](http://www.bigbookofamigahardware.com/bboah/product.aspx?id=1920)

------
dang
Also [https://paleotronic.com/2018/10/01/an-interview-with-zx-
spec...](https://paleotronic.com/2018/10/01/an-interview-with-zx-spectrum-
designer-richard-altwasser/) (via
[https://news.ycombinator.com/item?id=18106246](https://news.ycombinator.com/item?id=18106246)).

------
AndrewStephens
There is a good book on the creation of the ZX Spectrum version of R-Type,
which was considered a minor miracle of graphics programming back in 1989[0].

It's Behind You by Bob Pape - available as a free ebook in various formats at
from [1].

It doesn't go into extreme technical detail but is an interesting view of how
the industry worked back then.

[0]
[https://www.youtube.com/watch?time_continue=18&v=jiQxq98OYfA](https://www.youtube.com/watch?time_continue=18&v=jiQxq98OYfA)

[1] [http://www.bizzley.com](http://www.bizzley.com)

------
megablast
A great video explaining the situation:
[https://www.youtube.com/watch?v=1PI6GwKVAeY](https://www.youtube.com/watch?v=1PI6GwKVAeY)

------
pkaye
Back in the 80s I think the BBC did a short run educational series to get kids
familiar with computers. I think they converted this over to the US computers
on the PBS channels. That is where I got my initial interest in computers as I
started experimenting with the program they provided on my Atari 800.

------
mikorym
No pics of its screen?

~~~
zeristor
I can still see the screen of a ZX Spectrum when I close my eyes

~~~
stevekemp
And hear the sound of a game loading...

------
Theodores
In the 1980's there were no fancy scanline tricks to get more colours out of
the Spectrum. Game developers just did an extremely good job of working around
the limitations of having two colours in an 8x8 block of pixels. Play anything
by 'Ultimate Play The Game' to see how gameplay worked, unimpeded by attribute
clashes.

I am amazed that decades after the Spectrum was current that clever code has
been written to get more colours than previously thought possible in an 8x8
area.

However, none of this was available in the 1980's, when people actually
used/played games on these home micros.

The situation was different with the ZX81. Originally this had the lamest
display ever, black and white, 40 x 25 characters. Some characters were
graphics, i.e. a bit like very blocky unicode. Notionally that was the best
you could get. However, you could re-map the characters to RAM and in RAM you
could put your own character definitions, e.g. the letter 'A' could be made to
be your own 8x8 pixel black and white character. If you re-mapped every
character then you could create a rudimentary 'high resolution' game
environment. This technique actually required 'shadow RAM' in the 8-16K part
of memory. You then had to enter characters the hard way, working out from
graph paper what the binary was to be. At the time this was mind blowing. The
iphone launch was nothing compared to the excitement of getting high res black
and white graphics on the ZX81.

But, it was on the BBC Micro where real mind blowing stuff happened. The game
Elite did something utterly crazy with graphics on the BBC B. The top part of
the screen was in high res black and white and the lower dashboard/console was
in chunkier four colour graphics. The Braben/Bell team had managed to not only
think of switching modes mid screen, they implemented it and they did it all
with genuine 3D.

This only worked on the BBC Micro, other variants of Elite were not as good as
there wasn't the hardware on other systems to do truly cool stuff.

Imagine if you went to a web page and the top part had 4K monochrome video
even if you didn't think your computer did 4K with the part below the video at
720p with HDR colours, with there being both modes on screen at once. You
would be in awe of that, and this is the best analogy I can think of to think
of what Elite did.

Elite was a 1980's game and this hardcore hacking of the display modes was
available at the time and not something developed demo-scene style decades
later.

Elite defied so many things that should not have been possible. As well as the
funky screen modes there were things like the thousands of planets, far too
many and far too detailed to fit into RAM. This was tantamount to magic.

I never felt that any of the hacks on the Spectrum had that jaw-dropping awe
factor, it is a shame that the subsequent video hacks were not available at
the time, in the 1980's.

~~~
vidarh
> However, none of this was available in the 1980's, when people actually
> used/played games on these home micros.

I don't know whether or not it was used on the Spectrum in the 1980's, but
here is one from 1990:

[https://www.youtube.com/watch?v=zBOPdiGC5EY](https://www.youtube.com/watch?v=zBOPdiGC5EY)

Though these kind of raster effects were absolutely staple of both demos and
games in the early 80's on the C64, so it'd surprise me if there aren't
earlier examples on the Spectrum as well. I'm not sure when exactly it became
common, but e.g. pretty much all pseudo-3d racing games for the C64 used
raster effects, as you can see in this video of Pole Position (1984) for
example:

[https://archive.org/details/C64Gamevideoarchive104-PolePosit...](https://archive.org/details/C64Gamevideoarchive104-PolePosition)

There's is brief flickering of the stripes on the road at the beginning (most
visible from around 15-30 seconds; when the game starts it shifts too fast to
be very noticeable) - this is due to poorly timed colour changes; an interrupt
handler was used to switch the background colour for the stripes, but you want
to do so in the horizontal blank, and you'd regularly see them miss-time this.

I can't tell if the ZX Spectrum version of Pole Position used the same trick,
or if it just flipped colour per character block:

[https://www.youtube.com/watch?v=76omr-7FDXo](https://www.youtube.com/watch?v=76omr-7FDXo)

> But, it was on the BBC Micro where real mind blowing stuff happened. The
> game Elite did something utterly crazy with graphics on the BBC B. The top
> part of the screen was in high res black and white and the lower
> dashboard/console was in chunkier four colour graphics. The Braben/Bell team
> had managed to not only think of switching modes mid screen, they
> implemented it and they did it all with genuine 3D.

Are you sure? I don't see any signs of this here:

[https://www.mobygames.com/game/bbc-
micro_/elite/screenshots/...](https://www.mobygames.com/game/bbc-
micro_/elite/screenshots/gameShotId,439590/)
[https://www.mobygames.com/game/c64/elite/screenshots/gameSho...](https://www.mobygames.com/game/c64/elite/screenshots/gameShotId,131048/)

They both seem to have identical resolution.

The C64 version would have been capable of that level of colour in both it's
bitmap modes (320x200 and 160x200), as it could do a minimum of two colour per
8x8 cell in the 320x200 mode as well.

[EDIT: Actually, there are things in the image that would require the "lores"
160x200 mode on the C64; so it might be that both of them do the mode
switching; it'd be able to use multiple colours but some of them seem to use
two foreground colours per 8x8 block and that wouldn't work in hires - though
it'd be possible to achieve the effects shown with a couple of sprites and
some raster colour changes, it'd probably be more trouble than it'd be worth
vs. a mode change]

Though the bitmap modes were overall very rarely used on the C64 (Elite was a
very notable exception) as it was more common to use tiles with custom
character sets combined with sprites, even for pseudo-3d games like Skyfox as
it was much faster (at the cost of jerkier movement and more memory for
multiple scaled copies of graphics):

[https://www.youtube.com/watch?v=lNkFD_jMzto](https://www.youtube.com/watch?v=lNkFD_jMzto)

> This only worked on the BBC Micro, other variants of Elite were not as good
> as there wasn't the hardware on other systems to do truly cool stuff.

There were 16/32 bit version of Elite that did much better, but of course that
was a few years later. Here's the Amiga version:

[https://www.mobygames.com/game/amiga/elite/screenshots](https://www.mobygames.com/game/amiga/elite/screenshots)

~~~
flohofwoe
> Are you sure? I don't see any signs of this here:

> [https://www.mobygames.com/game/bbc-
> micro_/elite/screenshots/...](https://www.mobygames.com/game/bbc-
> micro_/elite/screenshots/gameShotId,439590/)

If you look closely than you can see on this screenshot that the pixels in the
lower colored section are twice as wide (horizontally) as the pixels in the
upper black and white section.

~~~
annywhey
Although I'm not intimate with the BBC hardware this kind of thing doesn't
necessarily indicate a hardware mode switch - the renderer could use double
width pixels in the HUD simply to lower draw times(simpler rasterization loop)
and conserve memory.

AFAIK really complex scanline tricks mostly appeared on the Atari and Amiga
platforms first because they exposed explicit programmability that made it
simple to define exactly what you wanted the memory layout to map to. Other
hardware could do similar things, but needed to code a cycle-exact loop - a
feat that was certainly known in the 80's, but also relied on a good
understanding of the timings of all the hardware.

~~~
tom_
It definitely switches. There's four 1MHz timers and a vsync interrupt, so
this stuff is very easy to arrange and the timing doesn't have to be very
precise. (Ideally you'd leave more of a gap than Elite did, though, because it
takes basically an entire scanline to do the mode switch and reprogram the
palette.)

Try it on an emulator: [https://bbc.godbolt.org/](https://bbc.godbolt.org/) \-
Elite is the default disc. To load: hold Shift, tap F12, release shift. Once
the game is loaded and you see the animating ship, hold F12. The mode-
switching interrupt stops running while it's held down (that key is wired to
the reset pin on the real hardware), and you'll see the entire display
incorrectly scanned out in just one of the modes.

------
ddingus
Another option is to use the attributes directly.

Routines have been made to deliver 64 x scanline "pixels", essentially
creating an Apple 2 like lowres display.

~~~
ddingus
Ask Jim Bagley about doing that. :D

