Bubble Shield Bounce in Sonic 1

Discussion in 'Discussion and Q&A Archive' started by KingofHarts, Jun 11, 2015.

  1. KingofHarts

    KingofHarts Well-Known Member Member

    Joined:
    Sep 30, 2012
    Messages:
    53
    Location:
    Chi-Town
    Here is my code. Basically, this damn thing seems to work properly on objects but not on tiles. Any ideas why that might be?

    Sonic_ResetOnFloor: (aka Player_TouchFloor: in S3K)

    ; ---------------------------------------------------------------------------
    ; Subroutine to reset Sonic's mode when he lands on the floor
    ; ---------------------------------------------------------------------------

    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||


    Sonic_ResetOnFloor: ; XREF: PlatformObject; et al
    btst #4,status(a0)
    beq.s loc_137AE
    nop
    nop
    nop

    loc_137AE:
    bclr #5,status(a0)
    bclr #1,status(a0)
    bclr #4,status(a0)
    clr.b jumping(a0)
    clr.w (v_itembonus).w
    btst #2,status(a0)
    beq.s loc_137E4
    bclr #2,status(a0)
    move.b #$13,y_radius(a0)
    move.b #9,x_radius(a0)
    move.b #id_Walk,anim(a0) ; use running/walking animation
    ;subq.w #5,y_pos(a0)
    tst.b double_jump_flag(a0)
    beq.s loc_137E4
    btst #6,(v_status_secondary).w ; does Sonic have a Bubble Shield?
    beq.s @nobubble
    bsr.s BubbleShield_Bounce
    @nobubble:
    clr.b double_jump_flag(a0)

    loc_137E4:
    rts
    ; End of function Sonic_ResetOnFloor
    BubbleShield_Bounce: (Immediately after this subroutine)

    Code:
    ; ---------------------------------------------------------------------------
    ; Subroutine to	bounce Sonic in the air when he has a bubble shield
    ; ---------------------------------------------------------------------------
    
    ; =============== S U B R O U T I N E =======================================
    
    
    BubbleShield_Bounce:
    		movem.l	d1-d2,-(sp)
    		move.w	#$780,d2
    		btst	#6,status(a0)
    		beq.s	@nowater
    		move.w	#$400,d2
    
    	@nowater:
    		moveq	#0,d0
    		move.b	angle(a0),d0
    		subi.b	#$40,d0
    		jsr	CalcSine
    		muls.w	d2,d1
    		asr.l	#8,d1
    		add.w	d1,x_vel(a0)
    		muls.w	d2,d0
    		asr.l	#8,d0
    		add.w	d0,y_vel(a0)
    		movem.l	(sp)+,d1-d2
    		bset	#1,status(a0)
    		bclr	#5,status(a0)
    		move.b	#1,jumping(a0)
    		clr.b	stick_to_convex(a0)
    		move.b	#$E,y_radius(a0)
    		move.b	#7,x_radius(a0)
    		move.b	#id_Roll,anim(a0)
    		bset	#2,status(a0)
    		move.b	y_radius(a0),d0
    		sub.b	#$13,d0
    		ext.w	d0
    		sub.w	d0,y_pos(a0)
    		move.b	#9,(v_shieldspace+anim).w
    		rts
     ; TEMP RTS until I port the sound effect...
    ;		move.w	#$44,d0
    ;		jmp	(Play_Sound_2).l
    ; End of function BubbleShield_Bounce
     
  2. TheStoneBanana

    TheStoneBanana banana Member

    Joined:
    Nov 27, 2013
    Messages:
    602
    Location:
    The Milky Way Galaxy
    It probably has nothing to do with it, and is a minor nitpick, but I wouldn't just slap a random rts at the end. Considering it isn't after the sound effect in the original code, it's going to make it go back and do things that weren't intended.
     
  3. KingofHarts

    KingofHarts Well-Known Member Member

    Joined:
    Sep 30, 2012
    Messages:
    53
    Location:
    Chi-Town
    I put the rts in because the jmp that goes to play the sound is commented out. It's temporary.
     
  4. Niko

    Niko All's well that ends well, right? Member

    Joined:
    Mar 1, 2014
    Messages:
    245
    Location:
    $C800
    But, still, don't just throw in an rts command. That just tells it "stop reading code from here," and that would be pretty bad if your next code was something seriously needed, like Sonic's other actions that are in the game, or other collision details. 

    Don't add an rts, but when there is one, moving it is not exactly realistic if you already comment out the other commands. 
     
  5. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,016
    He knows what he's doing, guys. It's just a jump to PlaySound, geez.

    I don't have a disassembly at hand, right now, but I had this problem before. I remember the problem not having anything to do with the code you've listed, but what branches to it. Check what branches to ResetOnFloor, and compare it to the S3K object. They're structured slightly different. Remember the S2 Rexon bug? It's kinda like that.
     
    Last edited by a moderator: Jun 12, 2015
  6. KingofHarts

    KingofHarts Well-Known Member Member

    Joined:
    Sep 30, 2012
    Messages:
    53
    Location:
    Chi-Town
    ​THANK YOU...

    I'll give you guys a hint: You know how when you see these:
     

    // Branch Example
    bsr.w CodeBlock
    rts

    // Jump Example
    jsr CodeBlock
    rtsYou are taught to change them to THESE? (respectively)

    // Branch Example
    bra.w CodeBlock ; Change to bra.w and remove the rts

    // Jump Example
    jmp CodeBlock ; Change to jmp and remove the rtsMaybe then you can figure out why I felt I wanted to put an rts in... and we can drop it and get back to the original question.

    Anyway, thanks Clownacy, when I get home I'll look into the code that branches to it and see what I can figure out.
     
  7. Niko

    Niko All's well that ends well, right? Member

    Joined:
    Mar 1, 2014
    Messages:
    245
    Location:
    $C800
    Technically, those would be accurate if you were to "do this part of this action, then jump" because once you jump, it doesn't come back.
    But, an rts placeholder if you don't need what's after it, that's only going to ensure that if that part is bybassed from starting at that subroutine, it doesn't move on.

    Like, say this:

    Sonic_MdJump:                ; XREF: Sonic_Modes
    bsr.w Sonic_JumpHeight
    bsr.w Sonic_Drop
    bsr.w Sonic_DoubleJump
    bsr.w Sonic_Hover
    bsr.w Sonic_JumpDirection
    bsr.w Sonic_LevelBound
    jsr ObjectFall
    bsr.w Sonic_JumpAngle
    bsr.w Sonic_Floor
    rts
    ; ===========================================================================

    Sonic_MdRoll: ; XREF: Sonic_Modes
    You got rts there because you don't want Sonic to jump, then start doing the roll subroutine. 
     

    But, if it was more like this:
     

    Your_code:
    bsr.w Sonic_JumpAngle
    rts
    Gravity_for_whatever: ; for example
    or

    Your_other_code:
    jmp Sonic_JumpDash
    rts
    Gravity_for_whatever: ; for exampleThis would pretty much disable that gravity, or whatever it is that's after it, unless called again by another code.

    You understand what I'm trying to explain?
     
     
  8. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,016
    Alright, found it. The 'bsr's to ResetOnFloor in Sonic_Floor need to be relocated.

    Compared to S3K's sub_11EEC, the bsr in loc_1361E needs to be moved to before the rts of loc_1364E. A copy also needs to be added at the start of loc_11FC2. loc_136B4's bsr needs to be moved to just above the locret's label, and so does loc_13772's. loc_13726's can be left where it is.
     
  9. Pokepunch

    Pokepunch That guy who posts on occasion Member

    Joined:
    Aug 7, 2009
    Messages:
    270
    Location:
    UK
    ​You see this text here

    ; End of function BubbleShield_BounceThat means that it's the end of this subroutine, If the code was a jump to a Play Sound type routine it would jump to something that looks kinda like this:

    PlaySound:
    stopZ80
    cmp.b (Z80_RAM+zSFXNumber0).l,d0
    beq.s ++
    tst.b (Z80_RAM+zSFXNumber0).l
    bne.s +
    move.b d0,(Z80_RAM+zSFXNumber0).l
    startZ80
    rts
    +
    move.b d0,(Z80_RAM+zSFXNumber1).l
    +
    startZ80
    +
    rts <--See that at the end? Putting an rts instead of a jmp to PlaySound is fine as it just skips playing a sound. Also you know what's after Sonic_ResetOnFloor (Or in this case BubbleShield_Bounce)?

    ; ===========================================================================
    ; ---------------------------------------------------------------------------
    ; Sonic when he gets hurt
    ; ---------------------------------------------------------------------------
    ; loc_1B120: Obj_01_Sub_4:
    Obj01_Hurt:
    We don't want that to run after bouncing. 
     
    Last edited by a moderator: Jun 12, 2015
  10. JoenickROS

    JoenickROS ROS (bug fixing in progress) Member

    Joined:
    Feb 5, 2012
    Messages:
    929
    Alright Clownacy, since you know how to fix it in s1, how about S2? Except in my hack it doesn't work on objects or tiles. I looked at S3s Hit floor and my hit floor is set up just like it, but the bounce code is set in Sonic_resetonfloor_part3 instead. Not sure if that effects anything.

    Edit: Ive had this bug for a long time and when ever I try to fix it I get nowhere. Been bugging the crap out of me. Ok looked back and it being in part3 shouldn't effect anything.
     
    Last edited by a moderator: Jun 12, 2015
  11. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,016
    Sorry, I never had a tiles problem in S2. Objects were a problem, but I never figured out how to fix it. Wound up finding a fix on Retro, but just where has fallen from memory.
     
    Last edited by a moderator: Jun 12, 2015
  12. JoenickROS

    JoenickROS ROS (bug fixing in progress) Member

    Joined:
    Feb 5, 2012
    Messages:
    929
    ​After you ported the bounce, bouncing on tiles worked? grrr

    Edit: not trying to make it seem that grr is for you. This bug has just really been pissing me off.

    Edit2: Another thought I had is the double jump flag is clearing to quickly, because I tested to see if it was the code itself, until I commented out the flag and I could bounce, it was a continuous bounce of course. I don't see how that could be the problem though since I set it up like S3Ks.
     
    Last edited by a moderator: Jun 12, 2015
  13. KingofHarts

    KingofHarts Well-Known Member Member

    Joined:
    Sep 30, 2012
    Messages:
    53
    Location:
    Chi-Town
    Much thanks Clownacy! It works!

    Also thank you PokePunch for helping to clarify
     
    Last edited by a moderator: Jun 12, 2015