Advertisement
NovaYoshi

UpdateScrollColumn

Apr 4th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .proc UpdateScrollColumn
  2.   WhichMetaColumn = 1
  3.   LevelBufIndex = 14
  4.   NewColumn = StatusRow2
  5.  
  6. ; calculate PPU address to write the 28 byte buffer to
  7. ; (repurposed from being a status bar)
  8.   lda #$20
  9.   sta Update28Address+0
  10.   lda ScrollX+1
  11.   lsr
  12.   lsr
  13.   lsr
  14.   sta 0   ; nametable column used to determine what level column to update
  15.   add #64 ; start one block down
  16.   sta Update28Address+1
  17.  
  18.   ldy #0 ; y will be Update28 index
  19.   sty WhichMetaColumn
  20.   lda 0
  21.   lsr    ; get the LevelBuf index
  22.   sta LevelBufIndex
  23.  
  24. ; we split the tasks for scrolling into different parts per frame
  25. ; partly to leave more CPU for other stuff and partly
  26. ChooseTask:
  27.   lda ScrollX+1
  28.   and #15
  29.   cmp #8
  30.   jeq RenderRight
  31.   bcc :+
  32.     rts
  33. : asl
  34.   tax
  35.   lda ScrollTasks+1,x
  36.   pha
  37.   lda ScrollTasks+0,x
  38.   pha
  39.   rts
  40.  
  41. RenderLeftGenerate:
  42. ; generate new level stuff here, if left column
  43.   ldx #15
  44.   lda #0
  45.   ldy #SCROLLCOL_MIDGROUND*16
  46. : lda ScrollColumnTemplates,y
  47.   sta NewColumn,x
  48.   iny
  49.   dex
  50.   bpl :-
  51.  
  52. ; just put a random block on here for now
  53.   jsr huge_rand
  54.   and #15
  55.   tax
  56.   lda #METATILE_GRASSM
  57.   sta NewColumn,x
  58.  
  59.   ldy #0
  60. RenderLeft:
  61.   tya
  62.   lsr
  63.   tax
  64.   lda NewColumn,x
  65.   sta TempVal
  66.  
  67.   lda LevelBufIndex ; step to next metatile
  68.   tax               ; but for this iteration, use the previous value
  69.   add #16
  70.   sta LevelBufIndex
  71.  
  72.   lda TempVal
  73.   sta LevelBuf+16,x ; find index into MetatileData
  74.   asl
  75.   asl
  76.   tax
  77.  
  78.   lda MetatileTiledata,x
  79.   sta Update28+0,y
  80.   lda MetatileTiledata+2,x
  81.   sta Update28+1,y
  82.  
  83.   iny
  84.   iny
  85.   cpy #28
  86.   bne RenderLeft
  87.   rts
  88.  
  89. RenderRight:
  90.   lda LevelBufIndex ; step to next metatile
  91.   tax               ; but for this iteration, use the previous value
  92.   add #16
  93.   sta LevelBufIndex
  94.  
  95.   lda LevelBuf+16,x ; find index into MetatileData
  96.   asl
  97.   asl
  98.   tax
  99.  
  100.   lda MetatileTiledata+1,x
  101.   sta Update28+0,y
  102.   lda MetatileTiledata+3,x
  103.   sta Update28+1,y
  104.  
  105.   iny
  106.   iny
  107.   cpy #28
  108.   bne RenderRight
  109.   rts
  110.  
  111. FixColors1:
  112.   ldx #0
  113.   ldy #FixColorSet2-FixColorSet1
  114.   bne FixColors
  115. FixColors2:
  116.   ldx #FixColorSet2-FixColorSet1
  117.   ldy #FixColorSet3-FixColorSet2
  118.   bne FixColors
  119. FixColors3:
  120.   ldx #FixColorSet3-FixColorSet1
  121.   ldy #FixColorSetEnd-FixColorSet3
  122.  
  123. FixColors:
  124.   ColorSetIndex = 12
  125.   ColorSetLoopCount = 13
  126.   stx ColorSetIndex
  127.   sty ColorSetLoopCount
  128. FixColorsLoop:
  129.   ldx ColorSetIndex
  130.   inc ColorSetIndex
  131.  
  132.   lda FixColorSet1,x   ; what block to do currently
  133.   add LevelBufIndex
  134.   tay
  135.   sty 0
  136.   lda LevelBuf,y       ; get tile we're going to be coloring
  137.   tay
  138.   lda MetatileFlags,y  ; get the flags for this tile
  139.   and #3               ; mask off just the palette number
  140.   ldy 0
  141.   jsr ChangeBlockColor ; A = new palette, Y = LevelBuf index
  142.  
  143.   dec ColorSetLoopCount
  144.   bne FixColorsLoop
  145.   rts
  146.  
  147. ; two consecutive rows are going to share the same byte
  148. ; so I spread it out so we're not rewriting the same byte twice in one NMI
  149. FixColorSet1: .byt 1*16,  3*16,  5*16,  7*16, 9*16
  150. FixColorSet2: .byt 11*16, 13*16, 2*16,  4*16
  151. FixColorSet3: .byt 6*16,  8*16,  10*16, 12*16, 14*16
  152. FixColorSetEnd:
  153.  
  154. ScrollTasks:
  155.   .raddr RenderLeftGenerate
  156.   .raddr FixColors1
  157.   .raddr FixColors2
  158.   .raddr FixColors3
  159.   .raddr EmptyObject
  160.   .raddr EmptyObject
  161.   .raddr EmptyObject
  162.   .raddr EmptyObject
  163. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement