Advertisement
slydogstudios

Palette Fade Out

Apr 3rd, 2014
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Palette fading routine in 6502. CA65 syntax.
  2.  
  3. ; Constants
  4. pal_address =   $100
  5.  
  6. ; Zeropage
  7. temp_8bit_1:    .res 1
  8.  
  9. loop_palette_fade:
  10.     dec temp_8bit_1                 ; This is the variable used to delay time between
  11.     beq :+                      ;  frames. After it reaches zero, we go about
  12.         jmp @loop_end               ;  our business and do some palette stuff.
  13. :   lda #$08                    ;  Also, reset it when it reaches zero.
  14.     sta temp_8bit_1                 ;
  15.  
  16.     ldx #$00                    ; Check every palette entry to test if it's
  17. :   lda pal_address, x              ;  at x0f black or not. If it's not, we have
  18.     cmp #$0f                    ;  more fading to do.
  19.     bne :+                      ;
  20.         inx                 ;
  21.         cpx #$20                ;
  22.         bne :-                  ;
  23.  
  24.                             ; This is the end of the palette fade loop. From
  25.                             ;  here we would set up our addresses for NMI and
  26.                             ;  loop, or jump to another place in ROM. Or just
  27.                             ;  say "Game Over" and give the player a blank
  28.                             ;  screen : )
  29. :
  30.     ldx #$00                    ; Set up register X
  31. @redo:                          ;
  32.     lda pal_address, x              ; Check each byte in the palette. If it is
  33.     cmp #$0f                    ;  already x0f black, then branch and increment
  34.     beq @next                   ;  X so we can check the next byte.
  35.         sec                 ; If it's not x0f, subtract 16 from it to get
  36.         sbc #$10                ;  to the next darker off-shoot of the color
  37.         beq :+                  ;  we are dealing with. If it's x00, branch to
  38.         cmp #$0f                ;  store the dark gray. If it's < x0f branch
  39.         bcc :++                 ;  to test if it's at color x02.
  40.             cmp #$40            ; If the color wrapped around during our subtraction
  41.             bcc :+              ;  and is > x40, then just go ahead and put it at
  42.                 lda #$0f        ;  x0f black. If it's < x40, branch and store the
  43.                 sta pal_address, x  ;  value.
  44.                 bne @next       ; Always branch
  45. :           sta pal_address, x      ;
  46.             bne @next           ; Always branch
  47. :       cmp #$02                ; If we're at color x02 or less, we want to make it
  48.         beq :+                  ;  x03 purple before black. If it's greater than
  49.         bcc :+                  ;  x02, we will go ahead and stick x0f black in it.
  50.             lda #$0f            ;
  51.             sta pal_address, x      ;
  52.             bne @next           ; Always branch
  53. :       lda #$03                ; x03 is the base color we want to hit in the fade
  54.         sta pal_address, x          ;
  55. @next:                          ;
  56.     inx                     ; Increment X and branch back into the routine if
  57.     cpx #$20                    ;  it's not at decimal 32 yet.
  58.     bne @redo                   ;
  59. @loop_end:                      ;
  60.     jmp end_loop                    ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement