Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .proc ChangeBlockColor ; A-New color (0 to 3), Y-Block index
- ; http://wiki.nesdev.com/w/index.php/Attribute_table
- AttrIndexTemp = 4
- OnValue = 5
- SaveColor = 6
- SaveX = 7
- stx SaveX ; level renderer uses X, so save it
- sta SaveColor
- and #3
- tax ; save the particular color being used
- lda ValueMasks,x ; start with it unshifted
- sta OnValue
- ; now determine how much to shift
- ldx #0 ; start at no shift
- tya
- lsr ; odd X? move up one
- bcc :+
- inx
- : tya
- and #$10 ;odd Y? move up two
- beq :+
- inx
- inx
- :
- lda OnValue
- and ShiftOnMasks,x
- sta OnValue
- ; Take the level buffer index and make it into an AttribMap index
- tya
- alr #$e0 ; Y half (discard last bit)
- lsr
- sta AttrIndexTemp
- tya
- alr #$e ; X half (discard last bit)
- ora AttrIndexTemp
- tay
- lda AttribMap,y
- and ShiftOffMasks,x
- ora OnValue
- sta AttribMap,y
- sta OnValue
- ldx SaveX
- bit SaveColor
- bpl :+
- rts
- :
- ; Now locate a slot to queue the actual change
- ldx #0
- : lda TileUpdateA1,x
- beq Found
- inx
- cpx #MaxNumTileUpdates
- bne :-
- clc ; failed
- rts
- Found:
- lda OnValue
- sta TileUpdateT,x
- lda #$23
- sta TileUpdateA1,x
- tya
- add #$c0
- sta TileUpdateA2,x
- sec
- rts
- ValueMasks:
- .byt %00000000
- .byt %01010101
- .byt %10101010
- .byt %11111111
- ShiftOnMasks:
- .byt %00000011
- .byt %00001100
- .byt %00110000
- .byt %11000000
- ShiftOffMasks:
- .byt %11111100
- .byt %11110011
- .byt %11001111
- .byt %00111111
- .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement