Fade to Black [4.5.6]

AllDarnDavey

Active member
Fade in from black is a trickier, but fade to black is pretty easy. So I ported over dale_coop's fade to black code to 4.5.6
Split it into background and sprite fade versions.

Fade background palettes to black
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; do fading to black for background pals - code by dale_coop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	LDX #$00 
doFadeCurrentBckPal:
	LDA bckPal,x ;; loads joes pallete for background (0-3) (4-7) (8-11) (12-15) 4,8,and 12 is not needed since its the same bgcolor as 0
	CMP #$10 ;; compares 10
	BCC + ;; if less than 10 skip to p1, if not continue below
	SEC ;; needs for subtraction
	SBC #$10 ;; subtract #$10
	STA bckPal,x ;; store it back into pallete
	JMP goNextBckPal;; jump to the next pal2
	+ 
	LDA #$0F ;; set accumalator to 0F which is (black)
	STA bckPal,x ;; store it into pallete
goNextBckPal:
	INX	
	CPX #4
	BEQ goNextBckPal
	CPX #8
	BEQ goNextBckPal
	CPX #12
	BEQ goNextBckPal
	CPX #16
	BCC doFadeCurrentBckPal
	LDA #$01
	STA updateScreenData	
RTS

Fade Sprites to black
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; do fading to black for sprite pals - code by dale_coop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	LDX #$00 
doFadeCurrentSpritePal:
	LDA spritePalFade,x ;; loads joes pallete for background (0-3) (4-7) (8-11) (12-15) 4,8,and 12 is not needed since its the same color as 0
	CMP #$10 ;; compares 10
	BCC + ;; if less than 10 skip to p1, if not continue below
	SEC ;; needs for subtraction
	SBC #$10 ;; subtract #$10
	STA spritePalFade,x ;; store it back into pallete
	JMP goNextSpritePal;; jump to the next pal2
	+ 
	LDA #$0F ;; set accumalator to 0F which is (black)
	STA spritePalFade,x ;; store it into pallete
goNextSpritePal:
	INX	
	CPX #4
	BEQ goNextSpritePal
	CPX #8
	BEQ goNextSpritePal
	CPX #12
	BEQ goNextSpritePal
	CPX #16
	BCC doFadeCurrentSpritePal
	LDA #$01
	STA updateScreenData	
RTS
 

5kids2feed

Well-known member
4.6.9 problem with first code...

This worked for me when I did 4.5.6 but not on the update..

Says label already defined for 5 & 16..

5 is... doFadeCurrentBckPal:
16 is.. goNextBckPal:

Anybody know how to work around this?
 
Last edited:

Jonny

Well-known member
4.6.9 problem with first code...

This worked for me when I did 4.5.6 but not on the update..

Says label already defined for 5 & 16..

5 is... doFadeCurrentBckPal:
16 is.. goNextBckPal:

Anybody know how to work around this?

You could try doing a search of all scripts to see where they're first defined. Maybe a different routine is messing things up.

Question: Where would this code by used? As a monster action or somewhere else?
 

5kids2feed

Well-known member
Ah I see.. Weird.. I didn't have it anywhere else..

I changed all the doFadeCurrentBckPal & goNextBckPal to have an extra L at the end.. then it worked.. kinda.. it doesn't fade.. just turns black for a second then goes to the next screen. hmm.

Do I need to setup a pallete somehow? Think that's what i'm missing.
 

Jonny

Well-known member
Fade in from black is a trickier, but fade to black is pretty easy. So I ported over dale_coop's fade to black code to 4.5.6
Split it into background and sprite fade versions.

For the sprite fade, where is "spritePalFade" from? Is that a variable that need to be set up in user variables? I can't find it in a search both for 4.5.6 and 4.5.9
 

Jonny

Well-known member
The variable name should be sprPal for 4.5.X.
Cheers, I actually tried sprPal shortly afterwards. It looked like the nearest thing. Still can't get anything to change. Maybe there's something I'm not understanding, do the colours of palettes being used have to be set up a certain way. The only way I can get any change at all is using 'spriteSubPal2'. Sounds like its super easy from the comments so I must be missing something. Background fade seems to work fine.
 

9Panzer

Well-known member
Did you get it working @Jonny ? I ran into the same issue. Background is no issue at all but nothing happens with the sprites.
 

Jonny

Well-known member
Did you get it working @Jonny ? I ran into the same issue. Background is no issue at all but nothing happens with the sprites.
Sorry, I know this is from a while ago but I finally got it to work. Are you still having issues or did you get it to work?
 

Logana

Well-known member
Based on what panzers shown me on his game recently, he is still struggling to fade sprites
 

chains

Member
@dale_coop what does it mean?

Code:
LDA bckPal,x ;; loads joes pallete for background (0-3) (4-7) (8-11) (12-15) 4,8,and 12 is not needed since its the same bgcolor as 0
    CMP #$10 ;; compares 10

Why are we comparing to #$10 here? I thought the idea behind this effect is to simply darken the color of the current pal. I'm not seeing anything changing in the PPU viewer, the pal for the current sprite remains unchanged.

Could someone shed a light here? I'm including this code in Bank_1C and calling it via `JSR` in the Monster Action. The code is getting called, but this code is doing anything. Do I have to use a specific set of palettes?

@Jonny do you mind sharing what you did?
 

AllDarnDavey

Active member
Why are we comparing to #$10 here? I thought the idea behind this effect is to simply darken the color of the current pal.
It's because we have to subtract #$10 from the color to get the darker version of the same color, but if the color is less than #$10 subtracting will go too far and wrap around, so we branch and just set it to #$0F (black) instead. I think I have the older variable name by mistake (should be "sprPal" not "spritePalFade").

You can find @Jonny working version, along with how he linked the fade to an action in the link he posted...

 

chains

Member
It's because we have to subtract #$10 from the color to get the darker version of the same color, but if the color is less than #$10 subtracting will go too far and wrap around, so we branch and just set it to #$0F (black) instead. I think I have the older variable name by mistake (should be "sprPal" not "spritePalFade").

Thanks for the reply! Yeah, the code seems to be right. I was tired last night when I posted, but it's not working. The pal is not changing in the PPU.

Do you mind sharing how are you using it? Maybe I'm doing something wrong.
 

chains

Member
You can find @Jonny working version, along with how he linked the fade to an action in the link he posted...

This script alone doesn't make much sense to me. The fade-out must occur in-between frames to have the sensation of fading, not in the same loop. So I would expect a timer associated with it. I'm only finding half, outdated tutorials and sparsing information about this. As soon as I make this work, I'll write a full, detailed tutorial.
 
Top Bottom