STA temp2 ; We're storing the palette value for use later
LDA tileX ; We need to convert our X and Y coordinates to the corresponding
LSR ; value for the lo byte of the attribute address. Columns have ending
LSR ; value of 0-7 on odd rows, even have 8-F. Every 2 rows share the hi nibble
LSR ; going from C to F. So for example the lo byte of the attribute address of
LSR ; the 3rd row, 5th column would $D4. Because row 1 is C, row 2 is C, and
LSR ; row 3 is D. This is an odd row, so the column value would be 0-7, so the
CLC ; 5th column would give you a value of 4. To get these values we just do
ADC #$C0 ; some bit shifting and some math.
STA temp
LDA tileY ; Now we get the Y component of the coordinate
AND #$E0
LSR
LSR
CLC
ADC temp ; Now the X and Y components get merged to get us the final lo byte value
STA updateNT_fire_att_lo
LDA #$23 ; The hi byte depends on which nametable you are targeting. The upper
STA updateNT_fire_att_hi ; left is #$23, upper right is #$27, lower left is #$2B, and lower right is #$2F
; This next section of code is for determining which of the 4 metatiles available at this attribute address we
; are updating. It goes by the following pattern:
; 7654 3210
; |||| ||++- Color bits 3-2 for top left quadrant of this byte
; |||| ++--- Color bits 3-2 for top right quadrant of this byte
; ||++------ Color bits 3-2 for bottom left quadrant of this byte
; ++-------- Color bits 3-2 for bottom right quadrant of this byte
LDA tileX
AND #%00010000
BEQ setLeftAttributes
LDA tileY
AND #%00010000
BEQ setTopRightAttribute
setBottomRightAttribute:
LDA temp2
AND #%11000000
STA updateNT_att
LDA #%00111111
STA updateNT_attMask
JMP doneWithTileAttChange
setTopRightAttribute:
LDA temp2
AND #%00001100
STA updateNT_att
LDA #%11110011
STA updateNT_attMask
JMP doneWithTileAttChange
setLeftAttributes:
LDA tileY
AND #%00010000
BEQ setBottonLeftAttribute
setTopLeftAttribute:
LDA temp2
AND #%00110000
STA updateNT_att
LDA #%11001111
STA updateNT_attMask
JMP doneWithTileAttChange
setBottonLeftAttribute:
LDA temp2
AND #%00000011
STA updateNT_att
LDA #%11111100
STA updateNT_attMask
JMP doneWithTileAttChange
doneWithTileAttChange:
LDA #$01 ; We're done getting and setting the values we needed, now we just need to
STA UpdateAtt ; set this flag so an attribute update will occur during the next NMI