HGFX Intro, part 2 Drawing a coloured pixel We already know that for handling planar memory and for drawing pixels, we don't need to handle each bitplane individually. The HGFX will manage it for us, with a simple setup: 1. We set the colour of pixels. The HGFX can display 256 colours at once. We set a number of the colour in the colour index (a value from 0 to 255). The colour index is a table in the ZX Spectrum memory, the table length is 768 bytes and contains 256 positions. The colour is always given by three bytes because it is set from a range of a true-colour palette, i.e. 16777216 colours, as in the HRXC mode (HiResindeXedColour). 2. Next we set a PlanarMask value. This is a number that indicates which bitplane will be affected by a pixel rendering operation. The active (set) bits of the PlanarMask number indicate which bitplane to work with and which bitplane is for current pixel printing "off". So it is a mask and through this mask relevant bits of colour will be to "poured" into the individual bitplane. The PlanarMask actually determines a depth of the colour application. 8 bits out of 8 of bitplanes are projected into one single pixel on the screen. It is the third dimension of graphics, a sort of Z-axis. Examples: We will draw a pixel with the colour (IndexColour) number 233 by setting the value 255 (binary 11111111) in PlanarMask. The number 233 is actually binary ANDed with the number 255 in HGFX. All active bits of the mask will cause the value of the colour will be projected to all bitplanes. A more complex is an example in which we put, by changing the value of the mask, a colour value only to selected bitplanes: in the below example, we want to write the value only in the the first four bitplanes (bitplane 4 to 7) and the last (bitplane no. 7). Old colour: (bitplanes before the change) 145 dec, 10010001 bin New colour: 233 dec, 11101001 bin Mask: 143 dec, 10001111 bin New Planar Bitplanes Bitplanes Colour Mask before after b0 1 -----> 1 ------change------> 1 b1 0 -----> 1 ------change------> 0 b2 0 -----> 1 ------change------> 0 b3 1 -----> 1 ------change------> 1 b4 0 ---X-- 0 1 -----> 1 b5 1 ---X-- 0 0 -----> 0 b6 1 ---X-- 0 0 -----> 0 b7 1 -----> 1 -----change------> 1 (abbreviations b0..b7 mean both bit and bitplane) Expressed in binary form: New colour: 11101001 Mask: 10001111 ------------------------ Old colour: 10010001 ======================== Result 10011001 3. And now we are drawing a pixel. Very simple, we have already set the colour (IndexColour) and the "masking" value for bitplanes (PlanarMask), so all that's left is to tell the HGFX to "activate" the pixel. For this purpose we will use the HGFX videomemory of 6144 bytes. Its content is not different from what we already know when we programmed for the ZX Spectrum. Let's imagine it as a classic ZX-screen, a matrix of 256*192 pixels, i.e. 32*192 bytes, where each individual bit represents one pixel. By writing to the videomemory, by changing individual bits, we talk to HGFX which pixels to operate with. For the ZX-screen, the POKE command 16384,15 causes a row of 4 dots will light up in the upper left corner of the screen (in colours of ZX-attributes). If we turn the HGFX on, the same command wiil draw 4 points in full 256 colours. A compatibility with the ZX-screen is important. All entries into the classic videoram, both zx48 and zx128, every pixel drawing in the ZX-basic and in the machine code can easily be coloured with a help of the HGFX, with one from 256 unique colours (or another effect can be added]). The HGFX does that just by changing one bit in videoram. However, the HGFX can also ensure that a new graphics comes together with the ZX-screen. A HGFX videoram location address can be at any time to changed and moved to another place in a memory, for example to address 0 if you have all-ram mode enabled in the ROM location (we can also move the colour table). In this part, for simplicity, we have drawn only one coloured pixel, you will surely think the planar mask is also suitable for other, more complex operations. We'll talk about that later.