ZX BASIC:ScrAddress

From BorielWiki
Jump to: navigation, search

This function returns the address in screen memory of the TOP line of the character in print position X-Y. Remember that the next line will be 256 bytes further on, and the 3rd line 256 further again and so forth, for 7 more lines.

 
FUNCTION scrAddress(x AS UBYTE, y AS UBYTE) AS UINTEGER
ASM 
; This FUNCTION returns the address into HL of the screen address
; x,y in character grid notation. 
; Original CODE was extracted by BloodBaz
 
         ; x Arrives in A, y is in stack.
         AND     31
         ld      l,a
         ld      a,(IX+7) ; Y value
         ld      d,a
         AND     24
         add     a,64
         ld      h,a
         ld      a,d
         AND     7
         rrca
         rrca
         rrca
         OR      l
         ld      l,a
               
END ASM
END FUNCTION
 
 
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.
 
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

Examples of use (though more likely to be used as parameters to other screen handling functions):

 
PRINT scrAddress(8,15)
PRINT attrAddress(8,15)
 
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox
Translate
Google AdSense