[4.5.9] Fade In / Fade Out

Jonny

Well-known member
I know this is already covered in other threads but there's nothing regarding FADE IN for current version (4.5.9).
Fade Out is covered well and is working in current version of NM. It's the FADE IN I'm interested in.

How would this be done in a similar way to Dales fake out code?

This is what I'd like to do specifically... (uness there's a better way)
  • Save all the current background palettes and sprite palettes.
  • Change all the palettes to black #$0F
  • Loop a fade routine to restore the saved palettes.
Has anyone done something similar to this already they might share?

Fade in is mentioned elsewhere but it's for older versions where file structure / how palettes are initially loaded is quite different.
 

pierski

New member
I have been looking for the exact same thing. I'm going to include some stuff that I have seen shared, in hope it helps come up with a solution.

I saw the fade in/out transitions video that Joe posted in June 2019, but that was using 4.1.0 (according to the header).


In the video, he had a file called MysticSearches_HandleFades.asm. I had a copy of NESMaker 4.1.5, but that file was not part of it. I did quickly type out the code from the video and this is what it included:

Code:
HandleFades:
    ;; FIRST, check to see if we're already engaged in updating palettes.
    ;; if we are we need to skip the update, so we don't accidentally update a palette value twice before finishing all values.
    LDA updatePalettes
    BEG keepFading
    JMP noFades ;; updating palettes in this frame, so skip until ready
keepFading:
    ;; NOW we are fading
    LDA gameHandler
    AND #%00000100 ;; is it fading out?
    BEQ notFadingOut
    ;;; Fading out
    DEC hudTimer ;; based on the timer.
    BEQ keepFading4
    JMP noFades
keepFading4:
    ;;; fading out uses the darken palette macro.
    DarkenPalette #%01110111, #%01110111
    LDA #$04 ;; speed of fade
    STA hudTimer
    ;;;; check to see if all the way faded out by checking to see if all values are black
    INC fadeStep
    LDA fadeStep
    CMP #$05
    BEQ finishedFadingOut
    JMP noFades ;; they were not all black, so this fade must keep going.
finishedFadingOut:
    ;;;;;;;; DO FADE OUT TYPE ACTION, whatever we want to do when the fade is out.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;; In this case, we'll change screens, and flip fade in back on.
    LDA update_screen
    ORA #%10000000 ;; turn on update on screen
    AND #%11001111 ;; turn off transition type.
    STA update_screen
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    LDA gameHandler
    AND #%11111011
    ORA #%00000010
    STA gameHandler ;  turn on fade in.
    JMP noFades
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;; FADE IN:
notFadingOut:
    LDA gameHandler
    AND #%00000010
    BNE doFadeIn
    JMP noFades ;; also not fading in.
doFadeIn:
    ;;; Do fade in around the fade timer.
    DEC hudTimer
    LDA hudTimer
    BNE noFadesLDA #$04
    STA hudTimer

    DEC fadeStep
    LDA fadeStep
    BPL +
    LDA gameHandlerAND #%11111001

    STA gameHandler
    JMP noFades
+
    ;;;; rather than use lighten palette macro, we will us update palette
    ;;;; so that we can calculate the palette values compared to the fadeStep, and
    ;;;; evaluate those values against the main palette values, stored in backPalHold.
    UpdatePalette #%01110111, #01110111
noFades:

    RTS

StorePaletteData:
    LDY #$00
StorePaletteLoop:
    LDA bckPal,y
    STA backPalHold,y
    INY

I was unable to fine the macros for DarkenPalette or UpdatePalette referenced in the video/file.

@Mugi referenced some code from Shatterhand that would require using datatables:

Code:
palettetable:
    .db #$0F, #$0F, #$0F, #$0F, #$0F, #$02, #$0F, #$0F, #$0F, #$02, #$06, #$26, #$0F, #$09, #$17, #$26
    .db #$0F, #$0C, #$00, #$37, #$0F, #$06, #$27, #$38, #$0F, #$08, #$17, #$28, #$0F, #$0C, #$1A, #$26
    .db #$0F, #$0F, #$1A, #$36, #$0F, #$0F, #$1B, #$36, #$0F, #$0F, #$1C, #$36, #$0F, #$0F, #$0C, #$1B
; Stage A Background Palette
    .db #$0F, #$0C, #$17, #$26, #$0F, #$0B, #$1C, #$10, #$0F, #$02, #$15, #$21, #$0F, #$10, #$16, #$30
; Stage A Sprite Palette
    .db #$0F, #$0F, #$29, #$36, #$0F, #$0F, #$21, #$30, #$0F, #$06, #$27, #$38, #$0F, #$08, #$27, #$37
    .db #$0F, #$08, #$1B, #$2C, #$0F, #$0C, #$1C, #$10, #$0F, #$02, #$14, #$21, #$0F, #$00, #$16, #$30



; the rest of the table is cut off because whatever, we dont need it now.


LoadColorsFromTable:
    LDA palettetable,Y
    PHA

    AND #$0F
    ASL A
    ASL A
    STA RAM_91

    ASL A
    STA RAM_92

    PLA

    LSR A
    LSR A
    LSR A
    LSR A
    AND #$03
    CLC
    ADC RAM_91

    TAX
    CLC

    LDA FadeLevelIndex,X
    ADC RAM_90
    BPL doSomeThingHere

    LDA #$00
    BEQ moveahead

doSomeThingHere:
    CMP #$08
    BCC moveahead
    LDA #$07

moveahead:
    CLC
    ADC RAM_92

    TAX
    TYA
    
    AND #$03
    BNE storeColorToRAM

    LDA RAM_96
    BMI endroutine

storeColorToRAM:
    LDA colorfadetable,X
    STA colorRAM,Y

endroutine:
    RTS


colorfadetable:
    .db #$0F, #$0C, #$00, #$10, #$20, #$30, #$30, #$30, #$0F, #$01, #$02, #$11, #$21, #$31, #$30, #$30
    .db #$0F, #$01, #$02, #$12, #$22, #$32, #$30, #$30, #$0F, #$01, #$03, #$13, #$23, #$32, #$33, #$30
    .db #$0F, #$04, #$14, #$24, #$34, #$30, #$30, #$30, #$0F, #$07, #$05, #$15, #$25, #$36, #$35, #$30
    .db #$0F, #$07, #$06, #$16, #$26, #$36, #$37, #$30, #$0F, #$07, #$06, #$17, #$27, #$36, #$37, #$30
    .db #$0F, #$08, #$18, #$28, #$38, #$30, #$30, #$30, #$0F, #$09, #$0A, #$19, #$29, #$39, #$30, #$30
    .db #$0F, #$09, #$0A, #$1A, #$2A, #$3A, #$30, #$30, #$0F, #$0B, #$1B, #$2B, #$3B, #$30, #$30, #$30
    .db #$0F, #$0C, #$1C, #$2C, #$3C, #$30, #$30, #$30, #$0F, #$03, #$11, #$21, #$32, #$30, #$30, #$30
    .db #$0F, #$03, #$11, #$21, #$32, #$30, #$30, #$30, #$0F, #$03, #$11, #$21, #$32, #$30, #$30, #$30

FadeLevelIndex:
    .db #$02, #$03, #$04, #$05, #$01, #$03, #$04, #$05, #$02, #$03, #$04, #$05, #$02, #$03, #$04, #$06
    .db #$01, #$02, #$03, #$04, #$02, #$03, #$04, #$06, #$02, #$03, #$04, #$05, #$01, #$03, #$04, #$06
    .db #$01, #$02, #$03, #$04, #$01, #$03, #$04, #$05, #$02, #$03, #$04, #$05, #$01, #$02, #$03, #$04
    .db #$01, #$02, #$03, #$04, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00, #$00

someothertableprobably:
    .db #$17, #$96, #$00, #$00, #$35, #$96, #$00, #$00, #$45, #$96, #$00, #$00, #$55, #$96, #$00, #$00
    .db #$65, #$96, #$00, #$00, #$75, #$96, #$00, #$00, #$85, #$96, #$00, #$00, #$95, #$96, #$00, #$00
    .db #$A5, #$96, #$00, #$00, #$B5, #$96, #$00, #$00, #$C5, #$96, #$00, #$00, #$D3, #$96, #$00, #$00
    .db #$E5, #$96, #$0C, #$00, #$F7, #$96, #$0C, #$00, #$17, #$97, #$0C, #$00, #$37, #$97, #$0C, #$00

Lastly, I did find a BeginFade macro inside NESMaker 4.1.5 (not sure if this is helpful or not):

Code:
MACRO BeginFade arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7
    ;arg0 = FADE_DARKEN or FADE_LIGHTEN
    ;arg1 = fadeSpeed
    ;arg2 = steps to fade out of 4
    ;arg3 = loads new data 0=no, 1=yes
    ;arg4 = reverse fade at end FADE_AND_HOLD = no, FADE_AND_RETURN = yes
    ;arg5 = loop? FADE_ONCE = no, FADE_LOOP = yes
    ;arg6 = values to fade, first set of 8
    ;arg7 = values to fade, second set of 8
    

    LDA arg2
    AND #%00000011 ;; force to 4 steps, even if they accidentally put a different number
    ORA #arg0
    ORA #arg5
    ORA #%10000000
    STA fadeByte

    
    LDA arg3
    LSR
    BCC noDataLoad
    ;; yes data load
    ORA #%10000000
noDataLoad:
    STA temp
    LDA arg1
    AND #%00011111 ;; force to 5 values for speed
    ORA #arg4
    ORA temp
    STA fadeSpeed
    
    LDA fadeSpeed
    AND #%00011111
    ASL
    ASL
    STA fadeTimer
    
    LDA arg6
    STA fadeSelect_bck
    LDA arg7
    STA fadeSelect_bck+1
    
    ENDM

Hopefully some of this helps. What @Jonny suggests makes perfect sense and it is similar to how Joe describes it in the video above. Any assistance with this issue is greatly appreciated.
 
Top Bottom