LoadPalettes problem

smithee

New member
Hi all,
I'm new to NesMaker and to this forum :)
I'm trying to change the color (palettes) of the background when pressing START button. If I go pressing start it would change palettes of the background in loop.
I've tried adding DataLoadScript/LoadPalettes.asm to Scripts/Input Scripts, and later, in Input Editor, I've added the LoadPalettes.asm script to the START-PRESS action.

When I compile I get:
\Routines\DataLoadScripts\LoadPalettes.asm (11): Label already defined.
\Routines\DataLoadScripts\LoadPalettes.asm (26): Label already defined.
\Routines\DataLoadScripts\LoadPalettes.asm (38): Label already defined.

First, what am I doing wrong?
Second, is it possible to get the behaviour I'm looking for?

Many thanks in advance!
Smithee
 

jorotroid

Member
Because LoadPaletts.asm is included elsewhere in the code you get an error because the labels within the file have already been declared elsewhere in the code. It is possible to change palettes. Try using this code to do it:
Code:
	LDA #$3E		;This is the index of the palette you want to change to. If I remember right, background palettes go from #$00 to #$3F
	STA newPal
	
	LDA currentBank
	STA prevBank
	LDY #$16
	JSR bankswitchY
	LDX newPal
	LDA GameBckPalLo,x	;\
	STA temp16		;  These lines are for main game screens. Use SpecialBackPalLo and SpecialBackPaHi for the start screen
	LDA GameBckPalHi,x	;/
	STA temp16+1
	LDY prevBank
	JSR bankswitchY
	LoadBackgroundPalette
	LDY prevBank
	JSR bankswitchY

Hope this helps!
 

smithee

New member
Hi! thanks a lot for your help.
Probably LoadPalettes is some kind of system script. Once I've removed the code compiles good.
I'm trying your code as a new input script, it compiles ok but still not getting what I want, probably I need to go deeper on how banks/palettes really work.

Regards and thanks again!
 

jorotroid

Member
Oh, sorry. I completely forgot about one challenging aspect about this. You can't directly bank switch during an input script. This is because the input scripts and the palette data are stored in different banks that get swapped in and out of the Dynamic Bank. So if you bank switch while in the middle of an input script it's like pulling the rug out from underneath the code, making the game confused about where it should be in the code and everything will break. But it's still possible to achieve what you are looking for. You just need to run the code in my previous post from the Static Bank (essentially somewhere in MainASM.asm). I can think of two ways to go about this:
-Set a bit in your input script to act as a flag to tell some code in Static Bank to run the code in my previous post when the game program gets back to the Static Bank.
-From the input script, jump to some code in the Static Bank that will run the palette swapping code that swaps in the palette bank, then swaps back in the input bank and jumps back to where you left off there.
 
Top Bottom