Discussion in 'Engineering & Reverse Engineering' started by Tweaker, May 29, 2008.

1. ### shobiz

Tech Member
The Mega Drive's processor doesn't support floating point operations as far as I'm aware, so the Sonic games use 16.8 fixed point to represent non-integral values. What this means in simple terms is that Sonic's speed and acceleration aren't in pixels/second or pixels/second², respectively, but in 1/256 pixels per second or 1/256 pixels per second², respectively, instead. So when you see the line

Code (ASM):
1.         move.w  #\$C,(\$FFFFF762).w ; Sonic's acceleration
\$C in hex is the same thing as 12 in decimal, so this sets Sonic's acceleration to 12/256 = 0.046875 pixels per second² (which is where the number in the physics guide comes from).

2. ### Lapper

Lappering Tech Member
1,738
813
93
England
Sonic Studio, Sonic Physics Guide, Kyle & Lucy, Freedom Planet 2
How would I set Sonic's yspeed to -7? I can't find another peice of code to edit.
Also, where is the Jump height set?

Thanks people

3. ### Selbi

The Euphonic Mess Member
1,492
40
28
Northern Germany
Sonic ERaZor
His Y speed? I'm not sure what you mean, but the vertical velocity for an object is \$12(a0) (negative value for going upwards, positive for going downwards).

As for the jump height, at the routine Sonic_Jump you have this code (added the comments myself):
Code (ASM):
1.         move.w  #\$680,d2    ; set normal jump height
2.         btst    #6,\$22(a0)  ; is Sonic underwater?
3.         beq.s   loc_1341C   ; if not, branch
4.         move.w  #\$380,d2    ; if he is underwater, set smaller jump height
At Sonic_JumpHeight (which is just a few lines below) you have a code which sets a minimum jump height (a height you will pass, even if you release the jump button before reaching that height):
Code (ASM):
1.         move.w  #-\$400,d1   ; set normal minimum jump height
2.         btst    #6,\$22(a0)  ; is Sonic underwater?
3.         beq.s   loc_134AE   ; if not, branch
4.         move.w  #-\$200,d1   ; if he is underwater, set smaller minimum jump height

4. ### Lapper

Lappering Tech Member
1,738
813
93
England
Sonic Studio, Sonic Physics Guide, Kyle & Lucy, Freedom Planet 2
Ok, how do I set Sonic's y velocity?

5. ### Selbi

The Euphonic Mess Member
1,492
40
28
Northern Germany
Sonic ERaZor
Code (ASM):
1.         move.w  #\$100,\$12(a0)
Note that the \$100 is just an example. Replace it with the number you want. And also, if you want to move Sonic upwards, make it look like this:
Code (ASM):
1.         move.w  #-\$100,\$12(a0)
(In other words, make sure where you place the - char.)

6. ### Lapper

Lappering Tech Member
1,738
813
93
England
Sonic Studio, Sonic Physics Guide, Kyle & Lucy, Freedom Planet 2
Thanks =P

I've made an invincibility cheat. How nice.

7. ### Irixion

Member
So, I have some palettes that are in ASM form, is there any way to convert them into .bin files? Reason I need this is so I can load them in SonED2, etc.

8. ### Selbi

The Euphonic Mess Member
1,492
40
28
Northern Germany
Sonic ERaZor
Open the mappings file in SonMapEd and save as .bin again. You could also use a hex editor and CP the stuff, but that feature isn't supported for every hex editor.

9. ### Irixion

Member
I said palette not mappings. I can't open the .asm palette in anything—SonED, sonmaped, they all load it incorrectly, in game though, It loads fine.

10. ### Hodgy

Member
797
0
16
UK
Games programming :)
I seem to have created quite an odd bug....

I attempted to implement a Heathsystem so that pikachu has 3 hits before he does reguardless of wether he has rings or not, I havent implemented it into the HUD yet.The problems are that when pikachu dies, the object that kills him dissappears for some reason, and when pikachu is killed through crushing or on spikes something strange happens. I have included a link to the current build so you can have a look.

http://www.box.net/shared/5k5j6k8hlp

This is the code I modified for the hit's system, the only other entries are at the start of a level and when starting from a signpost to set the hits back to 3.
Code (Text):
1. HurtSonic:
2.                 tst.b   (\$FFFFFE2C).w ; does Sonic have a shield?
3.                 bne.s   Hurt_Shield; if yes, branch
4.                 tst.w   (\$FFFFFE20).w ; does Sonic have any rings?
5.                 beq.w   Hurt_NoRings  ; if not, branch
6.                 tst.w   (\$FFFFFEAA).w ; does Pikachu have any hits?
7.                 beq.w   Killsonic     ; if not, branch
8.                 subq.b  #1,(\$FFFFFEAA).w;-1 from hits
10.                 bne.s   Hurt_Shield
11.                 move.b  #\$37,0(a1)    ; load bouncing multi rings object
12.                 move.w  8(a0),8(a1)
13.                 move.w  \$C(a0),\$C(a1)
14.
15.
16. Hurt_Shield:
17.
18.                 move.b  #0,(\$FFFFFE2C).w; remove shield
19.                 move.b  #4,\$24(a0)
20.                 bsr.w   Sonic_ResetOnFloor
21.                 bset    #1,\$22(a0)
22.                 move.w  #-\$400,\$12(a0); make Sonic bounce away from the object
23.                 move.w  #-\$200,\$10(a0)
24.                 btst    #6,\$22(a0)
25.                 beq.s   Hurt_Reverse
26.                 move.w  #-\$200,\$12(a0)
27.                 move.w  #-\$100,\$10(a0)
28.
29. Hurt_Reverse:
30.                 move.w  8(a0),d0
31.                 cmp.w   8(a2),d0
32.                 bcs.s   Hurt_ChkSpikes; if Sonic is left of the object, branch
33.                 neg.w   \$10(a0)    ; if Sonic is right of the object, reverse
34.
35. Hurt_ChkSpikes:
36.                 move.b  #0,\$39(a0)
37.                 move.w  #0,\$14(a0)
38.                 move.b  #\$1A,\$1C(a0)
39.                 move.w  #\$78,\$30(a0)
40.                 move.w  #\$A3,d0    ; load normal damage sound
41.                 cmpi.b  #\$36,(a2)     ; was damage caused by spikes?
42.                 bne.s   Hurt_Sound    ; if not, branch
43.                 cmpi.b  #\$16,(a2)     ; was damage caused by LZ harpoon?
44.                 bne.s   Hurt_Sound    ; if not, branch
45.                 move.w  #\$A6,d0    ; load spikes damage sound
46.
47. Hurt_Sound:
48.                 jsr     (PlaySound_Special).l
49.                 moveq   #-1,d0
50.                 rts
51. ; ===========================================================================
52.
53. Hurt_NoRings:   tst.w   (\$FFFFFEAA).w ; does Pikachu have any hits?
54.                 beq.w   Killsonic     ; if not, branch
55.                 subq.b  #1,(\$FFFFFEAA).w;-1 from hits
56.                 bra     Hurt_Shield; else,branch
I really have no idea what is causing the bugs

11. ### Selbi

The Euphonic Mess Member
1,492
40
28
Northern Germany
Sonic ERaZor
@Irixion: You can also load stuff as uncompressed tiles, seems like anything can be opened using this way (and also saved of course).

@Hodgy: Byte and word issue, the usual thing. To fix up your code as well, do this:
Go to a point that is only being loaded once (like Level_WaterPal) and put this line there:
Code (ASM):
1.         move.b  #3,(\$FFFFFEAA).w    ; reset number of hits
Then just go to HurtSonic and put those lines there:
Code (ASM):
1.         subq.b  #1,(\$FFFFFEAA).w    ; -1 from hits
2.         beq.w   Hurt_NoRings        ; if not, branch
We don't need to do a test and then substract it, because HurtSonic only takes place when you actually got hurt.

12. ### Sik

Sik is pronounced as "seek", not as "sick". Tech Member
6,719
1
0
being an asshole =P
If the asm file only contains the palette, you could as well just build it using the assembler so it outputs a binary...

13. ### E-122-Psi

Member
2,457
593
93
Does anyone know where the mappings are for Sonic and Tails animations in the Sonic 2 title screen? I can't find them listed in the ASM.

14. ### Irixion

Member
They're in the mappings folder—iirc in the misc folder

I'm confused >_>

I basically want to turn this:
dc.w 0, 0, \$206, \$20C, \$80, \$64E, \$EEE, \$AAA, \$888, \$444, \$8AE, \$46A, \$E, 8, \$AE, \$8E; 0 ; ...
dc.w \$C20, 0, \$E62, \$A86, \$E86, \$44, \$EEE, \$AAA, \$888, \$444, \$666, \$E86, \$EE, \$88, \$EA8, \$ECA; 16

Into a binary file that I can open with SonED, SonMapEd, etc. If I force it to load, it doesn't load correctly, if I use 'include blah.asm' then it doesn't load in rom. If I say have it:

palptr Palette:

<What I just pasted>

Then it looks fine.

15. ### stormislandgal

It's not a phase! Tech Member
4,533
10
18
Married life <3
That's... pretty easy. Just open a new file in a hex editor and write down in the file what you see, but adding 0s too the data where needed. Example: \$EEE = 0EEE, \$80 = 0080, etc.

If that doesn't work, reconstructing the palette in SonEd shouldn't be that hard either.

16. ### Sik

Sik is pronounced as "seek", not as "sick". Tech Member
6,719
1
0
being an asshole =P
Code (Text):
1. asm68k /p palette.asm, palette.bin
Or whatever applies to your assembler. Basically I just told you to assemble that file like any other ASM file =P

17. ### Irixion

Member
That worked! Thanks, just thought there were a simpler quicker way to do it.

I'm using S2, so how would that command look like for S2's assembler? iirc it doesn't use ASM86K. Problem's solved though, thanks!

18. ### Ravenfreak

I dunno what I should put here. Tech Member
3,027
149
43
O'Fallon Mo
Hacking Sonic Drift, Writer at Sonic Cage Dome
I'm having trouble figuring out which animation is Sonic's running animation in Sonic 3K. And I've been trying many different values, but obviously no luck. (But I managed to figure out that \$A is the unused whistling animation. :v

19. ### Irixion

Member
Which animation? You mean which number? Iirc it's animation #2, \$01.

20. ### Selbi

The Euphonic Mess Member
1,492
40
28
Northern Germany
Sonic ERaZor
Is there a simple way to disable channels on SMPS music (and I mean like just not making the channel play if reason XY is true)?