Problems loading a tails under water pallet...

Discussion in 'Discussion and Q&A Archive' started by Dark Lips, Nov 20, 2011.

Thread Status:
Not open for further replies.
  1. Dark Lips

    Dark Lips Well-Known Member Member

    Joined:
    Nov 14, 2008
    Messages:
    293
    Location:
    Wolverhampton UK
    Hi there, I have recently added Tails to my Sonic 1 hack but I seem to be having difficulty getting a tails underwater pallet to work...



    Level_LoadPal:
    move.w #$1E,($FFFFFE14).w


    move #$2300,sr


    moveq #3,d0


    bsr.w PalLoad2 ; load Sonic's pallet line


    cmpi.w #1,(Current_Character).W ; Is Character Tails?


    bne.s UnderWater_Normal ; If not, branch


    moveq #$16,d0 ; Tails pallet


    jsr Palload2 ; load pallet


    UnderWater_Normal:


    cmpi.w #1,(Current_Character).W ; Is Character Tails


    beq.s UnderWater_Tails ; If yes goto Underwater_tails


    cmpi.b #1,($FFFFFE10).w ; is level LZ?


    bne.s Level_GetBgm ; if not, branch


    moveq #$F,d0 ; pallet number $0F LZ


    cmpi.b #3,($FFFFFE11).w ; is act number 3?


    bne.s Level_WaterPal ; if not, branch


    moveq #$10,d0 ; pallet number $10 SBZ3


    Level_WaterPal:


    bsr.w PalLoad3_Water ; load underwater pallet (d0)


    tst.b ($FFFFFE30).w


    beq.s Level_GetBgm


    move.b ($FFFFFE53).w,($FFFFF64E).w


    Underwater_tails:


    cmpi.b #1,($FFFFFE10).w ; is level LZ?


    bne.s Level_GetBgm ; if not, branch


    moveq #$17,d0 ; pallet number $0F LZ


    cmpi.b #3,($FFFFFE11).w ; is act number 3?


    bne.s Level_WaterPal ; if not, branch


    moveq #$17,d0 ; pallet number $10 SBZ3


    bsr.w PalLoad3_Water



    Any Ideas guys and girls? ...I think it may have something to do with the fact I havent slept for about 3 nights and I am missing something silly :/


    P.S sorry the tabbing and the colours in the code box have all gone to shit lol.... just wouldnt work right !!!
     
    Last edited by a moderator: Nov 21, 2011
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Try this instead:



    Level_LoadPal:
    move.w #$1E,($FFFFFE14).w ; reset air counter


    move #$2300,sr ; enable blanking interrupts


    moveq #$03,d0 ; set ID to Sonic's palette


    moveq #$0F,d1 ; prepare LZ underwater ID (Sonic)


    moveq #$10,d2 ; prepare SBZ3 underwater ID (Sonic)


    tst.w (Current_Character).w ; is the character Tails?


    beq LLP_Sonic ; if not, branch


    moveq #$16,d0 ; set ID to Tails' palette


    moveq #$17,d1 ; prepare LZ underwater ID (Tails)


    moveq #$17,d2 ; prepare SBZ3 underwater ID (Tails)


    LLP_Sonic:


    bsr PalLoad2 ; load palette


    cmpi.b #$01,($FFFFFE10).w ; is the zone ID LZ?


    bne Level_GetBgm ; if not, branch (ignore underwater load)


    move.w d1,d0 ; load LZ ID to d0


    cmpi.b #$03,($FFFFFE11).w ; is the act ID Act 4?


    bne Level_WaterPal ; if not, branch


    move.w d2,d0 ; load SBZ3 ID to d0


    Level_WaterPal:


    bsr PalLoad3_Water ; load underwater palette



    I will say though, you seem to have some real trouble with understanding very basic program flow, perhaps you should look into understanding that more, reading through that code confused the hell out of me personally =$


    Also, I'm unaware of what "Current_Character" is and what size it is, are you sure it's word sized? If so, is it at an even address?


    Also, I would really love to punch whoever's idea it was to convert tab spaces to regular multiple spaces.
     
  3. Dark Lips

    Dark Lips Well-Known Member Member

    Joined:
    Nov 14, 2008
    Messages:
    293
    Location:
    Wolverhampton UK
    Thanks for the help I will try it... also could you explain to me a little more about this?

    I do sometimes find it difficult to figure out where certain routines come in the order of things... I do a lot of try, build, change, try build change, try build change until I get it :s


    Edit - Just tried it and now both charecters have a all white pallet and bright purple water :s
     
    Last edited by a moderator: Nov 20, 2011
  4. SpirituInsanum

    SpirituInsanum Well-Known Member Member

    Joined:
    Feb 11, 2010
    Messages:
    642
    Actually the order is extremely simple: next line, next line, next line. Unless there's a branch of any kind (or an interrupt but don't bother with those for now), what's processed is the next line. (what I call "branches": all the Bcc, the JSR/JMP, BRA, RTS, DBcc, etc.)


    For example, in the code you posted above, move.b ($FFFFFE53).w,($FFFFF64E).w is processed, Underwater_tails: is only an address and it doesn't appear in the compiled rom so it's "skipped", then cmpi.b #1,($FFFFFE10).w is processed and so on.


    A consequence of this in your code: PalLoad2 is being ran twice when the character is Tails: first it loads Sonic's palette, then it checks the player and loads Tails' palette.
     
  5. Dark Lips

    Dark Lips Well-Known Member Member

    Joined:
    Nov 14, 2008
    Messages:
    293
    Location:
    Wolverhampton UK
    Thanks for the info... so anything that is branched to will return to where it branched whit hits an RTS? From what I can tell from my own experiance it then carrys on in line order - so my question is this how does it work when threre is a brach within a branch within a branch? I have seen a few code segments that seem to this and that is where i get a bit muddled.
     
  6. SpirituInsanum

    SpirituInsanum Well-Known Member Member

    Joined:
    Feb 11, 2010
    Messages:
    642
    If you use BSR or JSR to branch, the RTS will make the program come back to the line after that BSR/JSR. If it's another branch type, it won't.


    To make it simple, the address of the following instruction is stacked when you have a BSR/JSR, and the last one entering the stack is the first one to be used when there's an RTS.


    With other branches (BRA, DBcc, Bcc, JMP), the address of the following instruction isn't pushed in the stack, so an RTS will ignore it and use the last address stacked by a BSR/JSR instead.
     
Thread Status:
Not open for further replies.