# Signetics 2650 & 2636 programming/Programming colours
## Tutorial — Programming colours

This family of consoles have a very limited palette of colors to work with. The PVI has three digital (i.e. either on or off) colour signals that are connected to the red, green and blue inputs of the PAL encoder. This limits the system to a palette of eight colours: black, red, green, blue, cyan, magenta, yellow and white.
This seems simple at first sight, but is complicated by two other signals that can affect the colour on the display:
* the OBJ/SCR output of the PVI which goes low whenever an object or a score digit is being displayed. Remember: SCR is score, not screen!
* bit 5 of the 74LS138 'effects' register.
A further complication is that some consoles such as the Interton VC4000 use these signals to alter the brightness of the colour, while others use it to invert the colour. The rest of this page is applicable to the colour inversion method, specifically as implemented on the Voltmace Database.

### Hardware description

The three active-high colour inputs to the PAL encoder are connected directly to the active-low colour outputs of the PVI: R, G, B.
The active-high INV input to the PAL encoder is derived from a wire-AND circuit comprising an open-collector transistor, the open-drain OBJ/SCR and a pull-up resistor. Either one of those devices can pull the invert input to a low logic level.
The INVERT signal is set by writing to bit 5 of the hex D-type flip-flop, 74LS378, at memory address $1E80. Writing a 1 to that bit causes the transistor to turn on, and pull the INV input to the PAL encoder to a logic 0 irrespective of the state of OBJ/SCR.

### Registers

All the colour information is controlled by four registers, three in the PVI and one logic chip. Note that these registers are all write-only. It is up to the programmer to keep track of what is in them.

#### $1E80 'Effects' register

| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| - | - | INVERT | - | - | - | - | - |
The other bits in this register are used by the audio circuitry.

#### $1FC1 Colour objects 1 & 2

| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| X | X | R$_1$ | G$_1$ | B$_1$ | R$_2$ | G$_2$ | B$_2$ |

#### $1FC2 Colour objects 3 & 4

| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| X | X | R$_3$ | G$_3$ | B$_3$ | R$_4$ | G$_4$ | B$_4$ |

#### $1FC6 Background and screen — enable and colours

| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| X | R | G | B | Background Enable | R | G | B |
| X | Background colour | Background colour | Background colour | Background Enable | Screen colour | Screen colour | Screen colour |
If Background Enable is set to zero, both the screen and background grid are output from the PVI as '111'.
If the background grid is not used for graphics, the registers that define it, $1F80 - $1FAC, may be used for variable storage. They are hidden on the display by setting background and screen to the same colour.

### Colours

If you find the hardware description hard to follow with the multiple inversions, you aren't alone. All you really need to do is use the table below when programming colours.
| COLOUR | OBJECTS | BACKGROUND or SCREEN | BACKGROUND or SCREEN |
| COLOUR | OBJECTS | INVERT = 0 | INVERT = 1 |
| BLACK | 111 | 000 | 111 |
| BLUE | 110 | 001 | 110 |
| GREEN | 101 | 010 | 101 |
| CYAN | 100 | 011 | 100 |
| RED | 011 | 100 | 011 |
| MAGENTA | 010 | 101 | 010 |
| YELLOW | 001 | 110 | 001 |
| WHITE | 000 | 111 | 000 |
The score colour cannot be programmed independently; it is always the inverse of the colour programmed for the background.
Neither the object colours or the score colour are affected by the state of bit 5 of the 74LS138 'effects' register since the OBJ/SCR will be low while they are being displayed.
The INVERT bit is used in some games such as Interton's Super Space as a screen-saver. While it is tempting to normally set the INVERT bit to 0, it might be better to have it normally set to 1. In this way the colour codes are the same for objects, score, background and screen, and will be in negative logic, i.e. a 0 turns the colour on.

### Code snippets

All the colours are set by these four registers:
It is a good idea to clear the effects register early on in your program. This will not only turn off the colour inversion, but will also turn off the audio.
Alternatively, as discussed above, the audio can be turned off and the colour inversion turned on so that all colours can be programmed with the same codes.
Remember that the objects colours are always active low, so the RGB sequence 101 would appear as green, etc:
The background and screen colours depend on the state of the invert bit. When the invert bit is 0, their colours are always active high, so the RGB sequence 010 would appear as green, etc:
Conversely, when the invert bit is 1, their colours are active low, so the RGB sequence 101 would appear as green, etc:

### Tutorial program

The code for this tutorial can be found at Signetics 2650 & 2636 programming/Tutorial code - programming colours. When this program is run, you should see a static screen that looks like this:
The fours objects are programmed in different colours. When the first row of objects have been displayed, the INVERT bit in the effects register is set to one. This inverts the colour of the screen (yellow 110 becomes blue 001) and the background switches from black to white.
Notice that the objects and the score digits are the same above and below this transition. Also note that the score is the inverse of the colour programmed for the background.

#### Exercises

* Change the colours of the four objects to red, cyan, yellow and blue.
* Change the initial colour of the background grid to cyan.
* Change the colour of the score to magenta.