So, as I said above, we have two bits per pixel (or 8 pixels per memory word) in mode 4. How does this work? Mode 4 allows 4 colours, in binary the numbers from 0 to 3 can be represented by two bits. Colours are also represented by 'digits' in that if you add two colours together you get a different colour
The word in memory looks like this :
Table 8.1. Mode 4 Screen Memory Word Format
Green byte bits (even address) | Red byte bits (odd address = green address + 1) |
---|---|
G7 G6 G5 G4 G3 G2 G1 G0 | R7 R6 R5 R4 R3 R2 R1 R0 |
In the above table, G7 refers to bit 7 of the green byte. The green byte is alwas even and lower in memory than the red byte which is always odd.
The colour codes for the allowed mode 4 colours are as follows :
So white is represented by both colours mixed together, black by the lack of both colours and red and green by themselves.
If in memory we have the green byte and the red byte in each word set up as follows, we can add the corresponding bit in each byte to represent the colour for a single pixel as follows :
Green byte = 0000 1111 | Red byte = 0101 0101 |
Which gives us the following :
Bit | Value (GR in Binary) | Colour |
---|---|---|
7 | 00 | Black |
6 | 01 | Red |
5 | 00 | Black |
4 | 01 | Red |
3 | 10 | Green |
2 | 11 | White |
1 | 10 | Red |
0 | 11 | White |
And that is how it works in mode 4. Ok so we know the screen address (or do we? Think about it) and we know how to poke values into the correct location so we can now write directly to the screen can't we? More later, keep those brain cells ticking over for now. There is something I have not yet mentioned.