ResumeMusic Routine Not Working?

Discussion in 'Discussion and Q&A Archive' started by DarkLeach, Jan 15, 2012.

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

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I added water to my Hack in my testing level (GHZ4) and I wanted to not have it play LZ Music when you exit from drowning. However, my code isn't working. It works as expected in GHZ4 when you enter and exit Water (I can't get the air routine to work right for me) the GHZ Music plays. However in LZ and SBZ3 (Which is LZ4) whenever I touch water it plays GHZ Music. Here's my code to see what I did wrong, I can't make heads or tails of it anymore. (It does compile it doesn't give an error)



    Code:
    
    ResumeMusic:	; XREF: Obj64_Wobble; Sonic_Water; Obj0A_ReduceAir
    
    
    
      ;cmpi.w #$C,($FFFFFE14).w
    
      ;bne.s  DoNothing
    
      cmpi.b #0,($FFFFFE10) ; check if level is (GHZ)
    
      beq.s GHZAct4Chk ; If so Branch to GHZAct4Check
    
      cmpi.b #1,($FFFFFE10) ; Check if Level is a LZ Level
    
      beq.s SBZ3MusicChk ; If so Branch to SBZ3MusicCheck
    
      rts
    
    
    
    ;loc_140A6:
    
    ;  jsr (PlaySound).l
    
    
    
    ;loc_140AC:
    
    ;  move.w #$1E,($FFFFFE14).w
    
    ;  clr.b ($FFFFD372).w
    
    ;  rts
    
    
    
    GHZAct4Chk:
    
      cmpi.b #3,($FFFFFE11); Check if Level is Act 4 of GHZ
    
      bne.s DoNothing
    
      move.w #$81,d0  ; play GHZ music
    
      jsr (PlaySound).l
    
    
    
    SBZ3MusicChk:
    
      cmpi.b #3,($FFFFFE11); Check If Level is Act 4
    
      bne.s PlayLZMusic
    
      move.b #$86,d0  ; play SBZ music
    
      jsr (PlaySound).l
    
    
    
    PlayLZMusic:
    
      move.b #$81,d0  ; play LZ music
    
      jsr (PlaySound).l
    
    
    
    DoNothing:
    
      rts
    
    ; End of function ResumeMusic
    
    

    Please tell me If I was supposed to color this a specific way or not (I didn't try to) , if so I will.

    [/CODE]
     
    Last edited by a moderator: Jan 15, 2012
  2. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Your problem is most likely caused by incorrect program flow:


    [​IMG]


    Consider using the "jmp" instruction instead:


    [​IMG]


    The same would go for the one above "PlayLZMusic:", and maybe even the one above "DoNothing:" (although that one shouldn't matter much)


    jmp - JuMP (Unconditionally):


    This instruction will jump to a long-word (24-bit) address directly, regardless of the conditions.


    jsr - Jump to SubRoutine:


    This instruction will jump to a long-word (24-bit) address directly, regardless of the conditions, however, it will save the address of the location "after" the "jsr" instruction to the stack, when the instruction "rts" is encountered, the last "jsr" location is then loaded back out of the stack, and the processor will resume starting from that location.


    In other words, if using "jsr (PlaySound).l", once the routine "PlaySound" has finished, it will return to the location under the "jsr (PlaySound).l" and keep going down, "jmp (PlaySound).l" on the other hand won't, and it will return to the previous "jsr/bsr/pea" address it had encountered.


    Alternatively try this:



    ; ===========================================================================
    ; ---------------------------------------------------------------------------


    ; Subroutine to resume the music


    ; ---------------------------------------------------------------------------


    ResumeMusic:


    move.w ($FFFFFE10),d1 ; load Zone/Act ID


    lsl.b #$02,d1 ; align act with zone


    lsr.w #$02,d1 ; shift right together


    moveq #$00,d0 ; clear d0


    move.b ResumeList(pc,d0.w),d0 ; load correct music ID


    jmp PlaySound ; play the music ID


    ; ===========================================================================


    ; ---------------------------------------------------------------------------


    ; Act = 01 02 03 04


    ResumeList: dc.b $81,$81,$81,$81 ; GHZ


    dc.b $82,$82,$82,$82 ; LZ


    dc.b $83,$83,$83,$83 ; MZ


    dc.b $84,$84,$84,$84 ; SLZ


    dc.b $85,$85,$85,$85 ; SYZ


    dc.b $86,$86,$86,$86 ; SBZ


    ; ---------------------------------------------------------------------------


    ; ===========================================================================
     
    Last edited by a moderator: Jan 15, 2012
  3. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I does the exact same thing as before. I made a little modifications though (Works exactly the same with or without them.)


    I put this to make sure Sonic gets Air



    Code:
    
    move.w  #$1E,($FFFFFE14)  ; Give maximum Air
    
    move.w ($FFFFFE10),d1	; load Zone/Act ID
    
    


    I even changed this



    Code:
    
    dc.b $82,$82,$82,$82 ; LZ
    
    



    to that, because SBZ3 is LZ4

    Code:
    
    dc.b $82,$82,$82,$86 ; LZ
    
    
    [/CODE]
     
    Last edited by a moderator: Jan 15, 2012
  4. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I'm more than likely wrong here, but you've got it to "PlaySound". Shouldn't it be "PlayMusic"?
     
  5. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    PlaySound = S1


    PlayMusic = S2
     
  6. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    In S2, there's PlaySound and PlayMusic. That's why I suggested it as I wasn't sure about S1 =P
     
Thread Status:
Not open for further replies.