Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Palette fading routine in 6502. CA65 syntax.
- ; Constants
- pal_address = $100
- ; Zeropage
- temp_8bit_1: .res 1
- loop_palette_fade:
- dec temp_8bit_1 ; This is the variable used to delay time between
- beq :+ ; frames. After it reaches zero, we go about
- jmp @loop_end ; our business and do some palette stuff.
- : lda #$08 ; Also, reset it when it reaches zero.
- sta temp_8bit_1 ;
- ldx #$00 ; Check every palette entry to test if it's
- : lda pal_address, x ; at x0f black or not. If it's not, we have
- cmp #$0f ; more fading to do.
- bne :+ ;
- inx ;
- cpx #$20 ;
- bne :- ;
- ; This is the end of the palette fade loop. From
- ; here we would set up our addresses for NMI and
- ; loop, or jump to another place in ROM. Or just
- ; say "Game Over" and give the player a blank
- ; screen : )
- :
- ldx #$00 ; Set up register X
- @redo: ;
- lda pal_address, x ; Check each byte in the palette. If it is
- cmp #$0f ; already x0f black, then branch and increment
- beq @next ; X so we can check the next byte.
- sec ; If it's not x0f, subtract 16 from it to get
- sbc #$10 ; to the next darker off-shoot of the color
- beq :+ ; we are dealing with. If it's x00, branch to
- cmp #$0f ; store the dark gray. If it's < x0f branch
- bcc :++ ; to test if it's at color x02.
- cmp #$40 ; If the color wrapped around during our subtraction
- bcc :+ ; and is > x40, then just go ahead and put it at
- lda #$0f ; x0f black. If it's < x40, branch and store the
- sta pal_address, x ; value.
- bne @next ; Always branch
- : sta pal_address, x ;
- bne @next ; Always branch
- : cmp #$02 ; If we're at color x02 or less, we want to make it
- beq :+ ; x03 purple before black. If it's greater than
- bcc :+ ; x02, we will go ahead and stick x0f black in it.
- lda #$0f ;
- sta pal_address, x ;
- bne @next ; Always branch
- : lda #$03 ; x03 is the base color we want to hit in the fade
- sta pal_address, x ;
- @next: ;
- inx ; Increment X and branch back into the routine if
- cpx #$20 ; it's not at decimal 32 yet.
- bne @redo ;
- @loop_end: ;
- jmp end_loop ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement