How do I swap pallets using a variable

ezr0913

New member
I'm trying to figure out how to cycle between pallets by pressing select. I am able to swap the pallets, but not how I want it to. I declared "dcolors" a variable in the "user variables" tab and set it to 6. My idea was to set it to 6 and every time you pressed select it would subtract 1 from the variable and when the variable reaches 1 it goes back up to 6. I made some progress, the colors do swap, but I just cant seem to figure it out how to make it work properly. It only cycles through them 2 times, and it doesn't seem to go to the green pallet at all. The only reason it is green is because that is the starting pallet I chose in the program.

Here is my code so far:
Code:
LDA dcolors
DEC dcolors


LDA dcolors
    CMP #$01
    BEQ +
    
ADC dcolors
ADC dcolors 
ADC dcolors 
ADC dcolors    
ADC dcolors


++
  
    LDA dcolors
    CMP #$04
    BEQ +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$16 ; Light Red
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$06 ; Dark Red
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+
    LDA dcolors
    CMP #$06
    BEQ +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$14 ; Light Purple
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$04 ; Dark Purple
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+

    LDA dcolors
    CMP #$02
    BEQ +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$2A ; Light Green
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$1A ; Dark Green
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+

I have a basic understanding of coding C++ from my Arduino projects, so I know what I want to do, but I just don't know how to tell it to do it. ASM seems so much more complicated than I originally thought :D
 

Attachments

  • pal swap.gif
    pal swap.gif
    13.6 KB · Views: 615

dale_coop

Moderator
Staff member
Hmmmm I think there are some errors...
To check if dcolor is equal to something (for example « 2 »), you need to write:

Code:
  LDA dcolors
    CMP #$02
    BNE +  ;; if not equal, branch out to the + label
      ;; it is equal to 2
      ;; do the things 
    +
     ;; else...

Also to (re)set a value to your variable:
Code:
   LDA #$06
   STA dcolors
 

ezr0913

New member
Thank you Dale! I figured there was a lot of errors :D I learned a lot from you and a couple other members on here in the past week. I'm just learning as I go. You guys are life savers <3

Here's the code that works:
Code:
LDA dcolors
DEC dcolors


    LDA dcolors
    CMP #$01
    BNE +    
    LDA #$07
    STA dcolors

+
  
    LDA dcolors
    CMP #$07
    BNE +
    
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$16 ; Light Red
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$06 ; Dark Red
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+
    LDA dcolors
    CMP #$06
    BNE +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$14 ; Light Purple
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$04 ; Dark Purple
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+

    LDA dcolors
    CMP #$02
    BNE +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$2A ; Light Green
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$1A ; Dark Green
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+

    LDA dcolors
    CMP #$05
    BNE +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$10 ; Light Grey
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$00 ; Dark Grey
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+

    LDA dcolors
    CMP #$04
    BNE +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$27 ; Light Orange
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$17 ; Dark Orange
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

+


    LDA dcolors
    CMP #$03
    BNE +
    
LDA #$0F ; black
STA spritePalFade+0 ; 1st sprite palette, 1st color
LDA #$12 ; Light Blue
STA spritePalFade+1 ; 1st sprite palette, 2nd color
LDA #$38 ; Tan
STA spritePalFade+2 ; 1st sprite palette, 3rd color
LDA #$02 ; Dark Blue
STA spritePalFade+3 ; 1st sprite palette, 4th color

LDA #$01
STA updatePalettes
RTS

I eventually would like to make different attributes for each color, but that's too advanced for me right now. I need to learn how to walk before I can run :p
 

Attachments

  • pal swap working.gif
    pal swap working.gif
    19.8 KB · Views: 607

Kajika

Member
hi , dale, hi all.

I'm working with the scripts that you sentme yesterday, and it work but my final target, is to press a button and swap again and again (max 3 diffenrents colors) ,un peu like the EZR0913's request.

So ,in order to do some things by myself i will try to modify the script by grafting pieces of it and doing it on my own. even if I can't, it will allow me to get my hands dirty and improve myself.

if I block ... I would signal to you :)
 
Top Bottom