This is everyone's favourite graphics mode. It's extremely easy to use. Takes a couple of seconds to learn how it all works. Right here goes
The screen resolution is 320 pixels by 200 pixels. Therefore there are 64000 pixels visible on the screen. Each one of these pixels is capable of showing one of 262144 different colours. However, you may only ever have 256 different colours visible on screen at once. I shall explain all in a sec.
Every pixel on the screen is represented by one byte in the PC's memory. If you change the value of that byte, the colour of the corresponding pixel will change immediately. Writing a pixel to the screen, therefore, is simply a matter of working out which byte you need to change, and changing it.
The bytes are arranged in memory in order. They are arranged in the same order that you read letters from a page. The top-left pixel comes first, followed by the one to its right . . . and the next few . . . then the top-right pixel, then the one below the top-left one. . . and finally the bottom-right pixel.
So the pixels on the first line of the screen are numbered 0 to 319. The pixels on the next line are numbered 320 to 639. etc.
Understand that? Yer it's simple isn't it? OK, so here's a little bit of maths to convert a
pair of (x, y) co-ordinates to a byte location:
For each of the 256 colour values, you choose how much red, green, and blue light you want the
screen to give out. By mixing these colours in various amounts, you can create almost all the
colours the eye can see.
send a byte to port 968. This is the pixel value you want to assign red, green and blue values to. Next send 3 bytes to port 969. First the red, then the green then the blue value. The range of colour you are allowed is 0 to 63.
send 15 to port 968
send 63 to port 969
send 40 to port 969
send 0 to port 969
This will assign orange to colour number 15. So every time you plot a pixel with value 15 to the screen it will be orange.
now, if you do this:
And there you have it. Nothing could be simpler.