I have gotten the X coordinate to work, doing two writes to $2006, but I cannot figure out the Y cordinate/base address part. I have looked around online regarding how to do this, but no luck since most of it is not 6502 specific. So far my routine looks like this:tokumaru wrote:Then, once you have the X and Y coordinates of the player converted to tile units, you have to combine them using the following formula: NTADDRESS = BASE + Y * 32 + X. BASE is the base address of the name table... for example, $2000 is the first name table. You multiply Y by 32 because each row has 32 tiles, and you add X because that's how far into the row the tile is.
Code: Select all
Illuminate:
;
; I have tried putting various things here, which affects the location of the Y coordinate, but not based off of player position.
; Instead, it seems to be based off of the first two digits, with the options being at 20, 21, 22, and 23, which is consistent
; with the previous way that I was writing to the background by writing two hex numbers and storing them each at $2006.
;
STA $2006
LDA SpriteXPos
CLC
ADC #$03 ; Changing this, as you said, changes the relationship of the tile to the player
STA $2006
LDA Tile ; A light tile
STA $2007
IlluminateDone:
RTS