Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assembly question
#26
Hmmm.
This wasn't what I was thinking.
The ZX Spectrum screen has 24 * 8 = 192 scan lines (0..to 191 couting from the top of the screen). My idea was you created an *universal* function to return the memory address of a scan line. This way:
Code:
function ScrAdd(scanline as uByte) as Uinteger
...
End Function

REM DRAW A Vertical Line
FOR i = 0 to 191
   POKE ScrAdd(i), 255
NEXT
The trick is: the screen is divided in 3 thirds. The first one PRINTs AT 0..7, X so scan lines 0 to 63. This means, that al least for lines 0 to 63, we are in the 1rst third. And each character scan top-line starts at 32 * row, where row is 0..7. Remember, as britlion stated, the trick is to take the 'scanline' parameter as binary:
Code:
Lets try for line 120 (BIN 0111 1101)
s s n n n p p p
0 1 1 1 1 1 0 1 => so [s s][n n n][p p p] = [0 1][1 1 1][1 0 1]
So the line address is 16384 + [s s] * 32 * 64 + [n n n] * 32 + [p p p] * 256
The number 32 * 64 above is 32 bytes * 64 lines = Number of bytes on each 1/3 of the screen (each 3rd has 64 lines, of a total of 64 * 3 = 192 lines).

Here is the function (in ZX BASIC):
Code:
FUNCTION ScrAddr(scanline as Ubyte) AS UInteger
    DIM result As UInteger
    LET result = (32 * 64) * (scanline >> 6) ' Only 2 higher bits [s s].
    LET result = result + 32 * ((scanline bAnd 63) >> 3) [n n n]
    LET result = result + 256 * (scanline bAnd 7) [p p p]
    RETURN 16384 + result
END FUNCTION

DIM i as Ubyte
FOR i = 0 TO 191:
   POKE ScrAddr(i), 255
NEXT
PAUSE 0
Translate the above to assembler an you are done Wink But as Britlion pointed, in Assembler there are more optimized ways to do the above operations 8)
E.g.
  • (scanline >> 6) is equivalent to (scanline / 64)
  • (scanline bAnd 63) >> 8 is equivalent to (scanline % 63) >> 3
  • (scanline bAnd 7) is equivalnet to (scanline % 8 )
But in assembler bit manipulation is much faster.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)