; HGFX chunky - video settings for a classic bitmap manipulation ; ; Before video-buffers access and paging, ; once and for all initialize videosystem settings ; ; set HGFX graphics ; ld bc,0x7C3B ; ZXi general port0 ld a,1 ; g_zxi_001 - Extra graphics modes out (c),a inc b ; ZXi general port1 ld a,3 ; 512*384 resolution, 16 colours out (c),a ; dec b ; ZXi general port0 ld a,2 ; g_zxi_002 - Advanced video out (c),a inc b ; ZXi general port1 xor a ; bit 1 = 0 BigBorder off out (c),a ; dec b ; ZXi general port0 ld a,0x20 ; g_zxi_020 - HGFX general settings out (c),a inc b ; ZXi general port1 ld a,7 ; 10000111 ; ; bit0 = 1 linear memory ; bit1 = 1 indexed (index 0-7) border colour ; bit2 = 1 ZX screen transparency disable ; bit7 = 0 enable write to HGFX (incl. registers & colour table) ; out (c),a ; ; ; videoRAM address at 0xC000 ; that is a "window" of a zx-screen size (6144 bytes), ; not used with chunky BRAM, just for planar operations only ; a change of one bit affects the whole pixel stored in the video-buffer ; ; dec b ; ZXi general port0 ld a,1 ; g_zxi_021 - high byte of VideoRAM out (c),a inc b ; ZXi general port1 ld a,0xC0 out (c),a ; beginning at 0xC000 ; ; address of the HGFX colour table RAM at 0xD800 ; dec b ; ZXi general port0 ld a,1 ; g_zxi_023 - high byte of colour table out (c),a inc b ; ZXi general port1 ld a,0xD8 out (c),a ; at the place after above VideoRAM ; ; indexed colours are defined in TrueColour BGR ; HGFX mode 3 provides 16 colours only, ; this takes a colour table of 3*16 bytes ; ; ; start address of the HGFX registers at 0xD900 ; dec b ; ZXi general port0 ld a,1 ; g_zxi_022 - high byte of Registers Area out (c),a inc b ; ZXi general port1 ld a,0xD9 out (c),a ; ; ; Now is the videosystem configured. ; ; ; The HGFX RAM uses its own memory, 1 or 2 video-buffers. ; Two ways exist how to access the buffer(s): ; - planar: changing a bit in the HGFX videoRAM ; affects a whole (coloured) HGFX pixel ; - chunky: 8K or 16K part of the buffer is paged to one ; of eight Areas /four Zones ; ; Because we are starting to use a direct access to chunky BRAM ; (HGFX buffers) at first, we should disable a write-enable ; to HGFX (planar) bitmap, regs and col.table ; dec b ; ZXi general port0 ld a,0x20 ; g_zxi_020 - HGFX general settings out (c),a inc b ; ZXi general port1 ld a,135 ; access to VideoRAM disabled - bit 7 is on out (c),a ; ; ; Parts of the video-buffer are accessible per X&Y coordinates, ; with OFFSETs. Having HGFX registers at 0x5B00, there is: ; ; 0x5B07 (2 bytes) OffsetY 0 ... 383 ; ; Note: With chunky graphics, only OffsetY is used. ; In planar we work with both X&Y offsets (quick and easy way, ; to print a text, point an arrow, etc. with a coordinates) ; ; Next HGFX register usable for chunky operations ; is PLANARMASK, basically filled with a value 255 ; ; 0x5B04 (1 byte) PlanarMask ; ; -------------------------------------------------------------------------- ; ; HGFX (chunky) video-buffer access ; ; choose 16K segment - Memory Zone ld a,3 ; Zone 2 0xC000 - 0xFFFF out (0x73),a ; set Zone ; choose 16K HGFX chunky - both Areas are HGFX, ; so set Zone memory layout for this ; ld a,131 ; 10000011 ; bit0 = enable write Area0 ; bit1 = enable write Area1 ; bit4-7 = memory type, value 8 = HGFX Area0 & HGFX Area1 out (0x53),a ; Please note the HGFX video-buffers are not addressed in a classical way, ; but through a start-of-line (OffsetY) value. ; Example: ; ; Having a HGFX chunky Areas from 0xC000, ; willing to get an access from the first third of the 512*384 screen, ; so the first byte of the line no. 128 starts at 0xC000 ; ld hl,128 ld (0x5B05),hl ; set OffsetY to 128 ; 512*384 is a 16colour-mode, one byte holds two pixels. ; One line takes 256 bytes, the whole video-buffer has 98304 bytes. ; With OffsetY = 128 you will get an access to 64 screen lines from ; 128 to 191 (from video-buffer part, addr. 32768 to 49151) in 16KB Zone. ; ; -------------------------------------------------------------------------- ; ; Chunky vs. Planar comparison: example of 'software' pointer ; ; Decide, what type of screen data manipulation is good for. ; Example: mouse pointer, size 8x16 px, 4 colors ; ; In general, we need to pick up data, make a test for transparency, ; write, then shift to a new pixel... in the classical (HGFX chunky) ; bitmap all this covers 128 bytes and one byte manipulation takes ; approx. 24 tacts, 3000 tacts in total? ; ; A faster method is writing 48 bytes through Planar (32B data, 16B mask) ; such a painting of a pointer takes about 100 clock cycles at 3.5 MHz ; However, when saving background bytes (behind the pointer), it is better ; to deal with a chunky area, in combination with the FastDMA ; ; -------------------------------------------------------------------------- ; ; Notes on the Direct Memory Access using the FDMA ; ; The Z80-CPU is stopped when the FastDMA is doing jobs. ; At a speed of 3.5 MHz, the transmission of 1 byte takes about 0.48 tact. ;