HGFX Intro, part 4 4. HGFX video memory location The video memory of the HGFX system consists of 3 areas: The HGFX VideoRAM of 6144 bytes. Configuration memory registers. Colour registers (index of 256 colours) with a size of 768 bytes. HGFX VideoRAM, ConfigRAM and colourRAM can be located in the ZX Spectrum memory space from address 0 anywhere, at multiples of 256 bytes. It is configured using three HGFX ports. g_zxi_021 high byte of VideoRAM area g_zxi_022 high byte of Registers area g_zxi_023 high byte of Indexed colour table area When the HGFX is turned on, the beginning of a videoRAM is set to the original ZX-bitmap, at 16384 (40h * 100h = 4000h = 16384 dec). You can also page it into the ROM area (writes to HGFX memories work here as well). Comments: EleMeNt ZX/MB hardware installs new extensions on reserved ZXi ports. None of the HGFX ports will ever collide with existing, correctly designed ZX-peripherals. HGFX ports and registers are listed in the Programmer's Reference Guide on 128land.com, in the Documents section. The current version of HGFX has a total of 7 control ports and 7 memory registers, of which four registers are 16-bit. OUT instructions (to the HGFX ports) are usually used only once, to turn system settings on (where is the VideoRAM, where are colours, and where are registers). Then you don't have to touch them anymore. Further control takes place by writing to the HGFX registers, which are stored in standard memory and can be handled, e.g. incremented, faster than ports. Check the ProgRef manual how the HGFX memory registers work with two video buffers. When dealing with the planar you won't find any buffer in videoram, as buffers are an internal part of the HGFX system. Two internal, working screen buffers always store data of all bitplanes. They can be controlled through HGFX's registers perfectly, much better than we are used when switching between two classic ZX-screens. 5. HiRes - "fine" resolution of 512*192 pixels Haven't I told you yet that the HGFX can do a high resolution graphics? With full colours and, unlike HRC (HiResColour) graphics modes, without any attribute compromises. Even in HiRes, just like in 256*192 resolution, each pixel is a different colour. HGFX is the first system which can display on the ZX Spectrum (with a little trick) in 6144 bytes all 256 colours in hires graphics, with 512 pixels per line. One line (point 0 to 511) occupies 64 bytes in HiRes (in the original ZX Spectra resolution of 256*192 points, which now we can name "LowRes", whether it was non-linear or linear, it is always 32 bytes). HGFX HiRes linear video memory 1st line ... byte 0 to 63 2nd line ... byte 64 to 127 3rd line ... byte 128 to 191 ... Double resolution means the VideoRAM space of 6144 bytes is enough for half of the HiRes screen only. In order to controll the entire space at once, and always with the same simple way, we will help ourselves with an offset. --------------------------------------------------------------- | X,Y: 0,0 X,Y: 511,0 | | adr. 16384 512 pixels, 64 bytes adr. 16447 | | Offset Y=0 per line | | | ... ... | 96 lines | | X,Y: 0,95 96*64 = 6144 bytes X,Y: 511,95| | adr. 22464 adr. 22527 | | Offset Y=0 | --------------------------------------------------------------- | X,Y: 0,96 X,Y: 511,96| | adr. 16384 512 pixels, 64 bytes adr. 16447 | | Offset Y=96 per line | | | ... ... | 96 lines | | X,Y: 0,191 96*64 = 6144 bytes X,Y:511,191| | adr. 22464 adr. 22527 | | Offset Y=96 | --------------------------------------------------------------- HiRes can also be combined with ZX screen and so on, for example. enrich the attribute graphics with a fine font... 6. Index colour format, border A HGFX colour is made from a 24-bit (3 bytes) RGB value stored in memory so that the lowest byte, colour, is stored first folder (B)lue (similar to what the Z80 CPU does when it saves 16-bit numbers, eg number #4000 will be stored in the order #00, #40. Example: addr - blue value adr+1 - green value addr+2 - red value We can also define it as the system BGR(0-255,0-255,0-255). The original ZX Spectrum palette we could define in HGFX as follows: Colour Binary B-G-R Colour number value storage name ---------------------------------------------------- 0 0000 #000000 black 1 0001 #B60000 blue (BRIGHT 0) 2 0010 #0000B6 red 3 0011 #B600B6 magenta 4 0100 #00B600 green 5 0101 #B6B600 cyan 6 0110 #00B6B6 yellow 7 0111 #B6B6B6 white 8 1000 #000000 black 9 1001 #FF0000 blue (BRIGHT 1) 10 1010 #0000FF red 11 1011 #FF00FF magenta 12 1100 #00FF00 green 13 1101 #FFFF00 cyan 14 1110 #00FFFF yellow 15 1111 #FFFFFF white This is how it is "poked" to the memory: DATA 0,0,0 ; black DATA 182,0,0 ; blue (no bright) DATA 0,0,182 ; red (no bright) DATA 182... ; magenta (no bright) By default, port 254 is used to select the screen border colour from basic 8 colours (i.e. no bright). If a border-index-colour is turned on in the the HGFX, the port 254 specifies which colour stored in one of the first eight colour indexes will be the border colour.