05-15-2013, 06:48 PM
slenkar Wrote:thanks
Ive read a few tutorials on spectrum screen memory but still dont understand it
the first 3 bits are always 010 so a lot of screen manipulation starts off with binary rotations,
aside from that I dont get it :?: :?:
It's a bit hard to get your head around - though if you call it a binary number it becomes clearer.
There are two ways of thinking of this.
If T = third of screen, R = Character row inside a third (row 0 to row 7), and L = line of that character row, and X = X value along the screen, then the 16 bit value you want in binary is:
010TTLLLRRRXXXXX
So you can think of it as chaining together numbers T (a two bit number 0-2 ["3" here is in the attributes - there isn't a "fourth third"]), followed by L (a three bit number 0-7), R (a three bit number 0-7), and the X value (a 5 bit number 0-31)
As you can imagine, this requires some bit shuffling to glue the parts together. The L before R seems strange - but inside a character, you can actually go down one line with an 8 bit command INC H, which is very fast. (It sets bit 8 of the above, or the last bit of the high byte).
Alternatively, you can think of it in pixels alone - and you have an X value along the screen, and a Y value down the screen. In this case you have:
0 1 0 Y7 Y6 Y2 Y1 Y0 Y5 Y4 Y3 XXXXX
So it's 010 YYYYYYYY XXXXX Yay! Except the 8 Y value bits are in the wrong order

e.g. if we have a Y value with bits 76543210 - we can rotate it left twice to get 54321076, then use AND to map the first three bits off into another register. (e.g. AND 11100000) then AND the X value with the result to make the lower byte.
So yes. It's complex. But read this post over and over while looking at some screen routines ( <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library#Graphics_Library">http://www.boriel.com/wiki/en/index.php ... cs_Library</a><!-- m --> ) and hopefully you'll work out how it was all done.
Here's an example from the high res print routine:
Code:
;HRPAT is a subroutine TO convert pixel values into an absolute screen address
;On Entry - B = Y Value C = X Value On EXIT - DE = Screen Address
HRPat:
ld a,b
srl a
srl a
srl a
ld e,a
AND 24
OR 64
ld d,a
ld a,b
AND 7
add a,d
ld d,a
ld a,e
AND 7
rrca
rrca
rrca
ld e,a
ld a,c
srl a
srl a
srl a
add a,e
ld e,a
ret