pierski
New member
This is definitely not an ideal solution, but it does work for the few fade ins that I needed for my 8x8 screens.
First thing, set up your screen bytes: https://www.nesmakers.com/index.php?threads/making-userscreenbyte0-7-work-plus-bonus.5842/
Next, add the following code to doSpritePreDraw.asm. This is the macro function I am using the define all the colors of the palette.
Then, add the following code to doSpritePostDraw.asm. This is the function itself. I tried to comment the code. If you don't use all the background palettes, then just remove ChangePaletteColors from those steps.
On the screen you want to use this, set userScreenByte4 = 1 and create a color palette where all the colors are the same as the default background color (i.e. black) so that it will be the default background when the page loads. Whatever colors you define in each ChangePaletteColors, will decide what the fade looks like for that frame.
I know this code can be improved by referencing tables, instead of passing the values directly in the macro. I also would love to have a more programmatic solution, like suggested by @Jonny here: https://www.nesmakers.com/index.php?threads/4-5-9-fade-in-fade-out.7140/#post-38396
This just does the job I needed it to do in [4.9.x], so I decided to share.
First thing, set up your screen bytes: https://www.nesmakers.com/index.php?threads/making-userscreenbyte0-7-work-plus-bonus.5842/
Next, add the following code to doSpritePreDraw.asm. This is the macro function I am using the define all the colors of the palette.
Code:
MACRO ChangePaletteColors arg0, arg2, arg3, arg4
;; arg0 =palette number
;; arg2 =color 2
;; arg3 =color 3
;; arg4 =color 4
LDA arg0
ASL
ASL
TAX
LDA arg2
STA bckPal+1,x
LDA arg3
STA bckPal+2,x
LDA arg4
STA bckPal+3,x
ENDM
Then, add the following code to doSpritePostDraw.asm. This is the function itself. I tried to comment the code. If you don't use all the background palettes, then just remove ChangePaletteColors from those steps.
Code:
LDA userScreenByte4
BEQ noCompanyLogo
LDA companyLoadTimer ;; LOAD TIMER BEFORE STARTING FADE IN ;;
CMP #$30 ;; TIMER LENGTH ;;
BCS companyPaletterTimer
INC companyLoadTimer
JMP noCompanyLogo
companyPaletterTimer:
LDA companyTimer ;; LOAD PALETTE TIMER ;;
BNE companyPaletteCountdown ;; IF NOT 0 JUMP DOWN ;;
JSR companyPaletteChange
LDA #$04 ;; FRAMES BETWEEN FADES ;;
STA companyTimer
companyPaletteCountdown:
DEC companyTimer ;; DECREASE TIMER ;;
JMP noCompanyLogo
companyPaletteChange:
LDA companyStepNum
CMP #$05
BCC companyStep0
noCompanyLogo:
RTS
fadeCompanyLogo:
LDA #%00000111
STA updateScreenData
RTS
companyStep0:
INC companyStepNum ;; INCREMENT STEP ;;
LDA companyStepNum
CMP #$02
BCS companyStep1
;; FIRST STEP IN PROCESS ;;
ChangePaletteColors #$00, #$01, #$01, #$01 ;; BACKGROUND PALETTE 1 ;;
ChangePaletteColors #$01, #$01, #$01, #$01 ;; BACKGROUND PALETTE 2 ;;
ChangePaletteColors #$02, #$01, #$01, #$01 ;; BACKGROUND PALETTE 3 ;;
ChangePaletteColors #$03, #$01, #$01, #$01 ;; BACKGROUND PALETTE 4 ;;
JMP fadeCompanyLogo
companyStep1:
LDA companyStepNum
CMP #$03
BCS companyStep2
;; SECOND STEP IN PROCESS ;;
ChangePaletteColors #$00, #$11, #$11, #$11 ;; BACKGROUND PALETTE 1 ;;
ChangePaletteColors #$01, #$11, #$11, #$11 ;; BACKGROUND PALETTE 2 ;;
ChangePaletteColors #$02, #$11, #$11, #$11 ;; BACKGROUND PALETTE 3 ;;
ChangePaletteColors #$03, #$11, #$11, #$11 ;; BACKGROUND PALETTE 4 ;;
JMP fadeCompanyLogo
companyStep2:
LDA companyStepNum
CMP #$04
BCS companyStep3
;; THIRD STEP IN PROCESS ;;
ChangePaletteColors #$00, #$21, #$21, #$21 ;; BACKGROUND PALETTE 1 ;;
ChangePaletteColors #$01, #$21, #$21, #$21 ;; BACKGROUND PALETTE 2 ;;
ChangePaletteColors #$02, #$21, #$21, #$21 ;; BACKGROUND PALETTE 3 ;;
ChangePaletteColors #$03, #$21, #$21, #$21 ;; BACKGROUND PALETTE 4 ;;
JMP fadeCompanyLogo
companyStep3:
;; FINAL STEP IN PROCESS ;;
ChangePaletteColors #$00, #$31, #$31, #$31 ;; BACKGROUND PALETTE 1 ;;
ChangePaletteColors #$01, #$31, #$31, #$31 ;; BACKGROUND PALETTE 2 ;;
ChangePaletteColors #$02, #$31, #$31, #$31 ;; BACKGROUND PALETTE 3 ;;
ChangePaletteColors #$03, #$31, #$31, #$31 ;; BACKGROUND PALETTE 4 ;;
JMP fadeCompanyLogo
On the screen you want to use this, set userScreenByte4 = 1 and create a color palette where all the colors are the same as the default background color (i.e. black) so that it will be the default background when the page loads. Whatever colors you define in each ChangePaletteColors, will decide what the fade looks like for that frame.
I know this code can be improved by referencing tables, instead of passing the values directly in the macro. I also would love to have a more programmatic solution, like suggested by @Jonny here: https://www.nesmakers.com/index.php?threads/4-5-9-fade-in-fade-out.7140/#post-38396
This just does the job I needed it to do in [4.9.x], so I decided to share.