; Assume mem 8-Bit, Index 16-Bit
; Vram = 16-Bit value to add with the finished caculation. area of the data
; XYpos= 24-Bit value. 8-Bits for X and 8-Bits for Y, 8-Bits for flag
;  X   = 0 through 31
;  y   = 0 through 31 ( viewable -> 28?? lines )
;  flag= 0 = no space between lines, 1 = a space between lines EX:
;  flag 0 = Hello,   flag 1 = Hello
;           World 
;			      World	

;###########################
; Goto Xy routine for Tmaps#
;###########################
GotoXY .macro (Vram,XYpos) ; Both are 16-bit values
 php

 rep #$20
 pha

 lda XYpos		; load X position
 and #!$00ff		; calculate Y position last
 pha			; push X position for adding
 lda XYpos+1		; load the Y position
 and #!$00ff		; 8-bit value
 asl			; multiply by $20 -> 32 ( 1 line )
 asl : asl   
 asl : asl
 pha
 lda XYpos+2		; load flag
 and #!$00ff		; if flag = 0, then we move only 1 line
 beq High32
 pla			; else, retrieve the value
 asl			; shift again to move to next line
 pha			; push it again just to be pulled safely

High32:
 pla			; retrieve the Y caculation
 clc
 adc $01,s		; add the X position
 clc
 adc Vram		; Add Vram pointer
 sta $2116		; set Vram address for Tile Maps
 sta Vram		; save it if needed. NOTE:
			; I usually save the old value before calling this routine.
 pla			; pull calculated X position
 pla			; pull all previously pushed values..
 plp
.endm
;/* End Of SUB */
