Personal Computer News


Addressing Graphics On The Spectrum

 
Published in Personal Computer News #091

Addressing Graphics On The Spectrum

Q. I have a 48K Spectrum. I know how to program it, but I don't know how to define graphics. I looked in the manual and found the three line program and BIN numbers, but now what? It doesn't tell you where to put the BIN numbers.

Jonathan Todd
Tyne and Wear

A. Spectrum UDGs can be confusing to stat with, but it's fairly easy to get them to fall into place.

Start with this:

  10 FOR N=0 TO 7
  20 READ B
  30 POKE USR "A"+N,B
  40 DATA BIN 10101010,BIN 01010101,BIN 10101010,BIN 01010101,
     BIN 10101010,BIN 01010101,BIN 10101010,BIN 01010101

This sets up a loop to poke the data in line 40 into the eight addresses that make up USR "A", which is where the Spectrum stores its definition of the graphics character A.

Now put the binary numbers in line 40 into an 8x8 grid, one on top of the other, and you'll see a patchwork pattern made up by the 1s and 0s. This is essentially what UDGs do, and if you go into graphics mode and press A you'll get the UDG representation of this.

You'll notice that hardly any listing you see in a magazine ses this method. The numbers in the data statements there are decimal, but you're actually doing the same thing. In the DATA statements above, we're saying BIN because the Spectrum is expecting decimal numbers.

But what's meant by USR "A"? On the Spectrum, a machine code routine is called by pointing at a memory location with RANDOMIZE USR or LET A=USR, so by saying USR "A", you're specifying a memory location, which in this case is the first of the eight addresses that make up graphic A. So you could equally well poke the eight addresses directly.

Try PRINT USR "A" and you'll get this address, then try POKEing the data into it and the seven following it, and you'll get the same result.

Jonathan Todd