Sonic and Sega Retro Message Board: Question about Ring Loss - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Question about Ring Loss

#1 User is offline Mercury 

Posted 14 June 2009 - 12:52 AM

  • His Name Is Sonic
  • Posts: 1711
  • Joined: 13-November 08
  • Gender:Not Telling
  • Location:Location Location
  • Project:AeStHete
  • Wiki edits:130
Hi. This is my first time posting a question here.

My current project involves creating a complete Sonic Engine in Game Maker from scratch, and making it as accurate as possible to the Genesis games.

I'm pretty far along, and it's not terribly hard to research Sonic's physics - he's always the first object in RAM, so it's easy to watch his variables with debuggers, etc - but I'm having a little trouble with Ring Loss.

I have the basics down, like the maximum of 20 Rings and the way they bounce; but I'd like to be as accurate as possible, so I need to know the initial speed, angle, and distribution of the Rings, as well as exactly how long it takes for them to be ragatherable. Also, when there is only one Ring, what determines which direction it flies out, and so on.

I guess then what I'm asking is if anyone has any knowledge of the actual Ring Loss routine, or can give me tips on how I might be able to look at it myself. I don't know any ASM, but all I really need is the complete list of variables so that I can plug them into my engine.

Thanks.

#2 User is offline nineko 

Posted 14 June 2009 - 02:27 AM

  • I am the Holy Cat
  • Posts: 5341
  • Joined: 17-August 06
  • Gender:Male
  • Location:italy
  • Project:I... don't even know anymore :U
  • Wiki edits:5,251
The relevant routine in the disassembly is this:
CODE
; ---------------------------------------------------------------------------
; Object 37 - rings flying out of Sonic    when he's hit
; ---------------------------------------------------------------------------

Obj37:                ; XREF: Obj_Index
        moveq    #0,d0
        move.b    $24(a0),d0
        move.w    Obj37_Index(pc,d0.w),d1
        jmp    Obj37_Index(pc,d1.w)
; ===========================================================================
Obj37_Index:    dc.w Obj37_CountRings-Obj37_Index
        dc.w Obj37_Bounce-Obj37_Index
        dc.w Obj37_Collect-Obj37_Index
        dc.w Obj37_Sparkle-Obj37_Index
        dc.w Obj37_Delete-Obj37_Index
; ===========================================================================

Obj37_CountRings:        ; XREF: Obj37_Index
        movea.l    a0,a1
        moveq    #0,d5
        move.w    ($FFFFFE20).w,d5; check number    of rings you have
        moveq    #32,d0
        cmp.w    d0,d5    ; do you have 32 or more?
        bcs.s    loc_9CDE; if not, branch
        move.w    d0,d5    ; if yes, set d5 to 32

loc_9CDE:
        subq.w    #1,d5
        move.w    #$288,d4
        bra.s    Obj37_MakeRings
; ===========================================================================

Obj37_Loop:
        bsr.w    SingleObjLoad
        bne.w    Obj37_ResetCounter

Obj37_MakeRings:        ; XREF: Obj37_CountRings
        move.b    #$37,0(a1); load bouncing    ring object
        addq.b    #2,$24(a1)
        move.b    #8,$16(a1)
        move.b    #8,$17(a1)
        move.w    8(a0),8(a1)
        move.w    $C(a0),$C(a1)
        move.l    #Map_obj25,4(a1)
        move.w    #$27B2,2(a1)
        move.b    #4,1(a1)
        move.b    #3,$18(a1)
        move.b    #$47,$20(a1)
        move.b    #8,$19(a1)
        move.b    #-1,($FFFFFEC6).w
        tst.w    d4
        bmi.s    loc_9D62
        move.w    d4,d0
        bsr.w    CalcSine
        move.w    d4,d2
        lsr.w    #8,d2
        asl.w    d2,d0
        asl.w    d2,d1
        move.w    d0,d2
        move.w    d1,d3
        addi.b    #$10,d4
        bcc.s    loc_9D62
        subi.w    #$80,d4
        bcc.s    loc_9D62
        move.w    #$288,d4

loc_9D62:
        move.w    d2,$10(a1)
        move.w    d3,$12(a1)
        neg.w    d2
        neg.w    d4
        dbf    d5,Obj37_Loop; repeat for number of rings (max 31)

Obj37_ResetCounter:        ; XREF: Obj37_Loop
        move.w    #0,($FFFFFE20).w; reset number    of rings to zero
        move.b    #$80,($FFFFFE1D).w; update ring counter
        move.b    #0,($FFFFFE1B).w
        move.w    #$C6,d0
        jsr    (PlaySound_Special).l;    play ring loss sound

Obj37_Bounce:            ; XREF: Obj37_Index
        move.b    ($FFFFFEC7).w,$1A(a0)
        bsr.w    SpeedToPos
        addi.w    #$18,$12(a0)
        bmi.s    Obj37_ChkDel
        move.b    ($FFFFFE0F).w,d0
        add.b    d7,d0
        andi.b    #3,d0
        bne.s    Obj37_ChkDel
        jsr    ObjHitFloor
        tst.w    d1
        bpl.s    Obj37_ChkDel
        add.w    d1,$C(a0)
        move.w    $12(a0),d0
        asr.w    #2,d0
        sub.w    d0,$12(a0)
        neg.w    $12(a0)

Obj37_ChkDel:            ; XREF: Obj37_Bounce
        tst.b    ($FFFFFEC6).w
        beq.s    Obj37_Delete
        move.w    ($FFFFF72E).w,d0
        addi.w    #$E0,d0
        cmp.w    $C(a0),d0; has object moved below level boundary?
        bcs.s    Obj37_Delete; if yes, branch
        bra.w    DisplaySprite
; ===========================================================================

Obj37_Collect:            ; XREF: Obj37_Index
        addq.b    #2,$24(a0)
        move.b    #0,$20(a0)
        move.b    #1,$18(a0)
        bsr.w    CollectRing

Obj37_Sparkle:            ; XREF: Obj37_Index
        lea    (Ani_obj25).l,a1
        bsr.w    AnimateSprite
        bra.w    DisplaySprite
; ===========================================================================

Obj37_Delete:            ; XREF: Obj37_Index
        bra.w    DeleteObject


#3 User is offline Galaxia 

Posted 14 June 2009 - 11:43 AM

  • Posts: 718
  • Joined: 06-September 08
  • Gender:Male
  • Location:Manchester, England
  • Project:degloving infants
  • Wiki edits:48
If Sonic only has one ring, I'd guess that the direction in which it's flung out is determined by what way he's facing. IIRC, I've never seen a ring fly out from behind Sonic, it's usually flung out from in front of him.

#4 User is offline SMTP 

Posted 14 June 2009 - 12:27 PM

  • Posts: 2145
  • Joined: 27-April 04
  • Gender:Male
  • Location:Ohio
  • Wiki edits:59
QUOTE (Galaxia @ Jun 14 2009, 12:43 PM)
If Sonic only has one ring, I'd guess that the direction in which it's flung out is determined by what way he's facing. IIRC, I've never seen a ring fly out from behind Sonic, it's usually flung out from in front of him.


A ring is sent out at the same angle, direction and speed no matter what direction he is facing.
This post has been edited by SMTP: 14 June 2009 - 12:27 PM

#5 User is offline Sonic Warrior TJ 

Posted 14 June 2009 - 12:39 PM

  • Is a ghost.
  • Posts: 2744
  • Joined: 16-March 08
  • Gender:Male
  • Location:Augusta, GA
  • Wiki edits:21
Isn't that one ring always sent flying to his left, not arching much higher than his own height?

#6 User is offline SMTP 

Posted 14 June 2009 - 01:00 PM

  • Posts: 2145
  • Joined: 27-April 04
  • Gender:Male
  • Location:Ohio
  • Wiki edits:59
Here is the single ring when getting hurt from the left:



Archs much higher than his own height as you can see.

Here it is from the right:




And I'm sure most of you know this by now, but 32 of them all fall out in certain angles and speed to create:



With the single ring circled in red.

#7 User is offline Sonic Warrior TJ 

Posted 14 June 2009 - 10:04 PM

  • Is a ghost.
  • Posts: 2744
  • Joined: 16-March 08
  • Gender:Male
  • Location:Augusta, GA
  • Wiki edits:21
It must've just been the Advanced games then. My bad.

#8 User is offline Rika Chou 

Posted 14 June 2009 - 10:55 PM

  • Adopt
  • Posts: 5093
  • Joined: 11-January 03
  • Gender:Not Telling
  • Location:CA US
  • Wiki edits:4
I know that in Sonic 2 that if you have one ring, it will always fly left...

#9 User is offline Sik 

Posted 15 June 2009 - 12:49 AM

  • Sik is pronounced as "seek", not as "sick".
  • Posts: 6719
  • Joined: 17-March 06
  • Gender:Male
  • Project:being an asshole =P
  • Wiki edits:11
If I recall correctly, every Sonic game behaves differently. I recall people asking if Sonic 2 beta was using the same algorithm as Sonic Crackers. If all games behaved the same, then nobody would have wondered that.

EDIT: Rika, in rev00 I got single rings flying to the right =P
This post has been edited by Sik: 15 June 2009 - 12:49 AM

#10 User is offline SMTP 

Posted 15 June 2009 - 01:15 AM

  • Posts: 2145
  • Joined: 27-April 04
  • Gender:Male
  • Location:Ohio
  • Wiki edits:59
Considering the ring loss object code is basicly exact, I kinda doubt they act different in each, Nor have I ever seen a single ring go right...

#11 User is offline Sik 

Posted 15 June 2009 - 01:23 AM

  • Sik is pronounced as "seek", not as "sick".
  • Posts: 6719
  • Joined: 17-March 06
  • Gender:Male
  • Project:being an asshole =P
  • Wiki edits:11
Then maybe it was just me =S

#12 User is offline Mercury 

Posted 15 June 2009 - 02:49 AM

  • His Name Is Sonic
  • Posts: 1711
  • Joined: 13-November 08
  • Gender:Not Telling
  • Location:Location Location
  • Project:AeStHete
  • Wiki edits:130
@nineko
Which of the games is that code from? Also, is there a Genesis specific command reference anywhere that could help me translate it? Like I said, I don't know any ASM.

Don't know why I said 20, that's the maximum amount in Sonic Adventure 2, and Sonic Heroes, if I recall right.

Another thing that makes it hard to research Ring Loss is that you have to intentionally hurl Sonic into hazards to do so, which goes against years of training... although I guess you could always play as Tails instead... (kidding, of course)

To be more specific, what I'd like to know is:
The initial speed of the two circles of rings (I've figured out the angles)
The gravity that affects the rings
The effect that bouncing has on the speed of the rings
And, finally, if possible, the animation speed of the rings (it seems to decrease over time)

Apparently, the rings last for 255 frames, and Sonic can regather rings after 64 frames have passed since being hit.

#13 User is offline SMTP 

Posted 15 June 2009 - 12:10 PM

  • Posts: 2145
  • Joined: 27-April 04
  • Gender:Male
  • Location:Ohio
  • Wiki edits:59
That code is from Sonic 1. Its the same as Sonic 2 except no routines for the 2nd player.

#14 User is offline JoseTB 

Posted 16 June 2009 - 05:43 PM

  • Posts: 623
  • Joined: 01-June 04
  • Location:Spain
  • Wiki edits:4
QUOTE (Rika Chou @ Jun 15 2009, 05:55 AM)
I know that in Sonic 2 that if you have one ring, it will always fly left...


That's right. At least for Sonic 1 and 2, the initial angle is about 79ยบ converted to the 360 system, considering 0 degrees the ground at the left of sonic.

QUOTE (Mercury @ Jun 15 2009, 09:49 AM)
The initial speed of the two circles of rings (I've figured out the angles)


X Speed = iterationnumber * sine(angle)
Y Speed = iterationnumber * cosine(angle)

iterationnumber = 4 for the first 16 rings, 2 for the next 16

QUOTE (Mercury @ Jun 15 2009, 09:49 AM)
The gravity that affects the rings


The horizonal speed is increased by 0.09 pixels every frame.

QUOTE (Mercury @ Jun 15 2009, 09:49 AM)
The effect that bouncing has on the speed of the rings


Y Speed = 0 - (Y Speed - (Y Speed/4))

I don't have the details about the animation speed around, as far as I can remember that was handled by another external routine... anyway, have fun smile.png
This post has been edited by JoseTB: 16 June 2009 - 05:43 PM

#15 User is offline Mercury 

Posted 17 June 2009 - 04:08 AM

  • His Name Is Sonic
  • Posts: 1711
  • Joined: 13-November 08
  • Gender:Not Telling
  • Location:Location Location
  • Project:AeStHete
  • Wiki edits:130
Thanks for the replies everybody! My engine now has quite robust ring loss physics thanks to you guys.

I was able to use nikeko's info to home in on some lost ring objects in the RAM and verify the numbers.

I've typed up what I've learned into a Sonic Physics Guide for the future reference of anyone else. I'd definitely like to make more of them as I continue to learn, for people who want to start from scratch rather than modify ROMs or someone else's engine.

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users