LoadPalettes problem

Having trouble compiling code? Getting an unexpected error? Player not appearing on screen? Seeking answers on how to do a particular thing? This is the forum you're looking for, to ask other NESmaker users for assistance.
Post Reply
smithee
Posts: 6
Joined: Wed Dec 05, 2018 8:00 pm

LoadPalettes problem

Post by smithee » Wed Dec 05, 2018 8:11 pm

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
User avatar
jorotroid
Posts: 152
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: LoadPalettes problem

Post by jorotroid » Wed Dec 05, 2018 9:08 pm

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: Select all

	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
Posts: 6
Joined: Wed Dec 05, 2018 8:00 pm

Re: LoadPalettes problem

Post by smithee » Fri Dec 07, 2018 4:26 pm

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!
User avatar
jorotroid
Posts: 152
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: LoadPalettes problem

Post by jorotroid » Fri Dec 07, 2018 6:05 pm

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.
smithee
Posts: 6
Joined: Wed Dec 05, 2018 8:00 pm

Re: LoadPalettes problem

Post by smithee » Sat Dec 08, 2018 10:54 am

Exactly, when I tried everything got stuck :lol:
I'll have a lot at your suggestions

thanks again
Post Reply