ZX BASIC:AttrAddress

From BorielWiki
Jump to: navigation, search

attrAdress(x,y)

This function will return the address of the byte that controls the Attributes of a given X-Y print position co-ordinate.

 
FUNCTION attrAddress (x AS UBYTE, y AS UBYTE) AS UINTEGER 
'This function returns the memory address of the Character Position 
'x,y in the attribute screen memory. 
'Adapted from code by Jonathan Cauldwell. 
'Rebuilt for ZX BASIC by Britlion from NA_TH_AN's fourspriter, with permission. 
 
ASM 
 
         ld      a,(IX+7)  ;ypos
         rrca
         rrca
         rrca              ; Multiply by 32
         ld      l,a       ; Pass TO L
         AND     3         ; Mask with 00000011
         add     a,88      ; 88 * 256 = 22528 - start of attributes.
         ld      h,a       ; Put it in the High BYTE
         ld      a,l       ; We get y value *32
         AND     224       ; Mask with 11100000
         ld      l,a       ; Put it in L
         ld      a,(IX+5)  ; xpos 
         add     a,l       ; Add it TO the Low BYTE
         ld      l,a       ; Put it back in L, AND we're done. HL=Address.
END ASM 
 
END FUNCTION

Usage

Example:

 
POKE attrAddress(10,10),43

Will change the attributes of print position 10,10 to 43 - (magenta ink on cyan paper)

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Translate
Google AdSense