Palette line fading help

Discussion in 'Discussion and Q&A Archive' started by redhotsonic, Mar 27, 2012.

Thread Status:
Not open for further replies.
  1. Crash

    Crash Well-Known Member Member

    Joined:
    Jul 15, 2010
    Messages:
    302
    Location:
    Australia
    No, d7 is fine to use. a7 is the stack pointer though, and shouldn't be used as a normal address register ;)
     
  2. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Yes, D7 is fine, until you're programming objects.


    It's used as a counter in 'ObjectsLoad' routine, which run all objects codes. So if you touch D7 in object's code, wrong number of objects will be loaded. Due to counter corruption, loading objects may continue when objects RAM ends, so 'ObjectsLoad' will load wrong data, jumping to wrong locations for it. This will eventually crash the game.
     
  3. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    That explains why d7 doesn't work half the time!


    Okay:



    lea ($FFFFF5C0).w,a4
    lea ($FFFFF5C0).w,a4


    move.l (a3)+,(a4)+


    move.l (a3)+,(a4)+


    move.l (a3)+,(a4)+


    move.l (a3)+,(a4)+



    This works! The palette line is copied! So, $FFFFF5C0 is ready.


    [​IMG]


    Here is the background. When you die, it does this code:



    movem.l d7/a0,-(sp)
    move.w #$5601,($FFFFF626).w


    jsr Pal_FadeFrom2


    move.w #$003F,($FFFFF626).w


    movem.l (sp)+,d7/a0



    This fades it to black and it works.


    [​IMG]


    Now, as you are aware, the shield coding here didn't work. So, I tried this:



    shield_monitor:
    moveq #$4D,d0


    jsr (LoadPLC).l


    bclr #3,status_secondary(a1)


    addq.w #1,(a2)


    bset #0,status_secondary(a1)


    move.w #$AF,d0


    jsr (PlayMusic).l


    move.b #$38,(Object_RAM+$2180).w ; load Obj38 (shield) at $FFFFD180


    move.w a1,(Object_RAM+$2180+parent).w


    movem.l d7/a0-a2,-(sp)


    moveq #0,d0


    lea ($FFFFF5C0).w,a0


    move.w #$0601,($FFFFF626).w


    jsr Pal_FadeTo3


    move.w #$003F,($FFFFF626).w


    movem.l (sp)+,d7/a0-a2


    rts



    I did "#$0601,($FFFFF626).w" because then, it still uses the same line but moves over by 6. like as $FFFFF5C6. And added an extra label "Pal_FadeTo3", here:



    Pal_FadeTo:
    move.w #$3F,($FFFFF626).w


    Pal_FadeTo2:


    moveq #0,d0


    lea (Normal_palette).w,a0


    Pal_FadeTo3:


    move.b ($FFFFF626).w,d0


    adda.w d0,a0


    moveq #0,d1


    move.b ($FFFFF627).w,d0


    ; loc_23DE:


    Pal_ToBlack:


    move.w d1,(a0)+


    dbf d0,Pal_ToBlack ; fill palette with $000 (black)


    moveq #$0E,d4 ; MJ: prepare maximum colour check


    moveq #$00,d6 ; MJ: clear d6


    - bsr.w RunPLC_RAM


    move.b #$12,(Delay_Time).w


    bsr.w DelayProgram


    bchg #$00,d6 ; MJ: change delay counter


    beq - ; MJ: if null, delay a frame


    bsr.s Pal_FadeIn


    subq.b #$02,d4 ; MJ: decrease colour check


    bne - ; MJ: if it has not reached null, branch


    move.b #$12,(Delay_Time).w ; MJ: wait for V-blank again (so colours transfer)


    bra DelayProgram ; MJ: ''


    ; End of function Pal_FadeTo



    I did this because then "lea (Normal_palette).w,a0" doesn't interrupt with "lea ($FFFFF5C0).w,a0", but alas, still not working.


    [​IMG]


    I then tried making it jump to "Pal_FadeTo2" anyway, and same thing happens. Also tried "move.w #$5601,($FFFFF626).w" again but still fails.
     
    Last edited by a moderator: Mar 29, 2012
  4. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    Hello, I'm still having troubles with making the palette fade in. It's really bugging me now, and I just can't see why it's failing.


    Now, I can get the palette line to fade out perfectly fine (thanks for the help, MJ):


    [​IMG]


    I then make it fade out:



    super_shoes:
    addq.w #1,(a2)


    bset #2,status_secondary(a1)


    move.b #$96,speedshoes_time(a1)


    movem.l d7/a0,-(sp)


    move.w #$600F,($FFFFF626).w


    jsr Pal_FadeFrom2


    movem.l (sp)+,d7/a0


    cmpa.w #MainCharacter,a1


    bne.s loc_12A10


    cmpi.w #2,(Player_mode).w ; Maybe set if the char is Tails?


    beq.s loc_12A10


    move.b #$2, (sonicsbursting).w ; when speed boots are active, make sonic in burst mode


    move.w #$C00,(Sonic_top_speed).w


    move.w #$18,(Sonic_acceleration).w


    move.w #$80,(Sonic_deceleration).w


    bra.s loc_12A22



    [​IMG]


    (The blue is from a different palette line so ignore that for now)


    But no matter what I do, I cannot fade it back in.



    Pal_FadeTo:
    move.w #$3F,($FFFFF626).w


    Pal_FadeTo2:


    moveq #0,d0


    lea (Normal_palette).w,a0


    Pal_FadeTo3:


    move.b ($FFFFF626).w,d0


    adda.w d0,a0


    moveq #0,d1


    move.b ($FFFFF627).w,d0


    ; loc_23DE:


    Pal_ToBlack:


    move.w d1,(a0)+


    dbf d0,Pal_ToBlack ; fill palette with $000 (black)


    moveq #$0E,d4 ; MJ: prepare maximum colour check


    moveq #$00,d6 ; MJ: clear d6


    - bsr.w RunPLC_RAM


    move.b #$12,(Delay_Time).w


    bsr.w DelayProgram


    bchg #$00,d6 ; MJ: change delay counter


    beq.s - ; MJ: if null, delay a frame


    bsr.s Pal_FadeIn


    subq.b #$02,d4 ; MJ: decrease colour check


    bne.s - ; MJ: if it has not reached null, branch


    move.b #$12,(Delay_Time).w ; MJ: wait for V-blank again (so colours transfer)


    bra.w DelayProgram ; MJ: ''


    ; End of function Pal_FadeTo



    I've put Pal_fadeto3, so in my objects code, I can move my own data to a0 and the RAM address.



    shield_monitor:
    movem.l d7/a0,-(sp)


    move.w #$600F,($FFFFF626).w


    moveq #0,d0


    lea (Normal_palette_line4).w,a0


    jsr Pal_FadeTo3


    movem.l (sp)+,d7/a0


    moveq #$4D,d0


    jsr (LoadPLC2).l


    bclr #3,status_secondary(a1)


    addq.w #1,(a2)


    bset #0,status_secondary(a1)


    move.w #$AF,d0


    jsr (PlayMusic).l


    move.b #$38,(Object_RAM+$2180).w ; load Obj38 (shield) at $FFFFD180


    move.w a1,(Object_RAM+$2180+parent).w


    rts



    Now, it doesn't matter what I "Lea" to a0, Normal_palette_line, 2, 3 or 4, or even put my own data in a new RAM address and move it to a0 (lea (Myownpalette).w,a0). Whatever I do, I ALWAYS get this:


    [​IMG]


    I'm obviously doing something wrong. Anyone with any ideas? Thanks for the help!


    redhotsonic


    EDIT: I tried making it jump to different places rather than Pal_FadeTo3 and I either get the samething, or it styas black, or it freezes.
     
    Last edited by a moderator: May 1, 2012
Thread Status:
Not open for further replies.