PRISM: A library to simulate the ZX Spectrum display in LÖVE

I’ve done some refactoring and separated my display code into a simple library called PRISM. I’ll think of a funny backronym some day but it’s in reference to the Spectrum logo.

In a previous blog I talked about how I’m rendering the sprites to the screen. Since then I have added a way to dynamically rotate the sprites and to simulate the border and Attribute Clash of these old display methods.

Colour Clash

The displays of the early 8-bit machines often could only manage 2 colours per 8×8 pixel cell, so if 2 sprites overlapped the colours would change depending on which sprite was drawn last. There may be a better way to make this work but here is my method.

I have 3 canvases; paper, ink and sprite. Each are 256×192 pixels, the resolution of the original Spectrum display. When the sprite function is called it draws an 8×8 rectangle of the paper and ink colours to their respective canvas. Then the sprite itself is drawn in monochrome to the sprite canvas.

When the PRISM draw function is called it sets a custom shader I made and passes the ink and paper canvases to it before drawing the sprite canvas. The shader simply checks each sprite pixel and returns the colour of the same pixel from the ink canvas if the sprite pixel is white and the paper pixel colour if the sprite pixel is black.

It runs fine on my PC but I feel it needs a lot of optimization before it runs ok on mobile.


You can grab my current version here. Zlib licence (same as LÖVE). Inside is a main.lua which runs the demo in the video above.