Advertisement
NovaYoshi

ChangeBlockColor

Apr 3rd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc ChangeBlockColor ; A-New color (0 to 3), Y-Block index
  2.                        ; http://wiki.nesdev.com/w/index.php/Attribute_table
  3.   AttrIndexTemp = 4
  4.   OnValue = 5
  5.   SaveColor = 6
  6.   SaveX = 7
  7.  
  8.   stx SaveX       ; level renderer uses X, so save it
  9.   sta SaveColor
  10.   and #3
  11.   tax         ; save the particular color being used
  12.   lda ValueMasks,x  ; start with it unshifted
  13.   sta OnValue
  14.   ; now determine how much to shift
  15.   ldx #0      ; start at no shift
  16.   tya
  17.   lsr         ; odd X? move up one
  18.   bcc :+
  19.     inx
  20. : tya
  21.   and #$10 ;odd Y? move up two
  22.   beq :+
  23.     inx
  24.     inx
  25.   :
  26.  
  27.   lda OnValue
  28.   and ShiftOnMasks,x
  29.   sta OnValue
  30.  
  31.   ; Take the level buffer index and make it into an AttribMap index
  32.   tya
  33.   alr #$e0 ; Y half (discard last bit)
  34.   lsr
  35.   sta AttrIndexTemp
  36.   tya
  37.   alr #$e     ; X half (discard last bit)
  38.   ora AttrIndexTemp
  39.   tay
  40.  
  41.   lda AttribMap,y
  42.   and ShiftOffMasks,x
  43.   ora OnValue
  44.   sta AttribMap,y
  45.   sta OnValue
  46.   ldx SaveX
  47.  
  48.   bit SaveColor
  49.   bpl :+
  50.     rts
  51.   :
  52. ; Now locate a slot to queue the actual change
  53.   ldx #0
  54. : lda TileUpdateA1,x
  55.   beq Found
  56.   inx
  57.   cpx #MaxNumTileUpdates
  58.   bne :-
  59.   clc ; failed
  60.   rts
  61. Found:
  62.  
  63.   lda OnValue
  64.   sta TileUpdateT,x
  65.   lda #$23
  66.   sta TileUpdateA1,x
  67.   tya
  68.   add #$c0
  69.   sta TileUpdateA2,x
  70.   sec
  71.   rts
  72.  
  73. ValueMasks:
  74.   .byt %00000000
  75.   .byt %01010101
  76.   .byt %10101010
  77.   .byt %11111111
  78. ShiftOnMasks:
  79.   .byt %00000011
  80.   .byt %00001100
  81.   .byt %00110000
  82.   .byt %11000000
  83. ShiftOffMasks:
  84.   .byt %11111100
  85.   .byt %11110011
  86.   .byt %11001111
  87.   .byt %00111111
  88. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement