Actions

SCHG How-to

Difference between revisions of "S1 Split Guides/Basic ASM Editing (Spin Dash)"

From Sonic Retro

(links and images need fixing)
 
m (repaired asm code)
Line 1: Line 1:
 +
''(Original guide written by [[Qjimbo]])''
 +
 
You might not think the words "basic" and "assembly" could belong in the same sentence, however what we plan to do in this tutorial takes a more ''modular'' approach to our disassembly than you might have thought was possible.
 
You might not think the words "basic" and "assembly" could belong in the same sentence, however what we plan to do in this tutorial takes a more ''modular'' approach to our disassembly than you might have thought was possible.
  
Line 19: Line 21:
 
1. First things first, we need to extract the disassembly out of the rar file. Extract it into the same folder as our Sonic 1 project (C:\SonED2-1\s1h\).
 
1. First things first, we need to extract the disassembly out of the rar file. Extract it into the same folder as our Sonic 1 project (C:\SonED2-1\s1h\).
  
2. Now, we can open all the files we are going to use in ConTEXT. Open C:\SonED2-1\s1h\sonic1.asm and C:\SonED2-1\s1h\Sonic 2 (Early prototype).asm . ConTEXT uses tabs so it's easy to switch between which file we are editing. <br />
+
2. Now, we can open all the files we are going to use in ConTEXT. Open C:\SonED2-1\s1h\sonic1.asm and C:\SonED2-1\s1h\Sonic 2 (Early prototype).asm . ConTEXT uses tabs so it's easy to switch between which file we are editing.  
  
 
<center>http://www.glowingbridge.org/splitfiles/asmtut01.png</center>
 
<center>http://www.glowingbridge.org/splitfiles/asmtut01.png</center>
  
3. Now to find the Spindash routine in Beta-E. Select the Sonic 2 (Early prototype).asm tab and do a search for '''sonic_spindash'''<br />
+
3. Now to find the Spindash routine in Beta-E. Select the Sonic 2 (Early prototype).asm tab and do a search for '''sonic_spindash'''
  
 
<center>http://www.glowingbridge.org/splitfiles/asmtut02.png</center>
 
<center>http://www.glowingbridge.org/splitfiles/asmtut02.png</center>
  
<br />The set of data we reach is this:
+
The set of data we reach is this:
  
<div class="code_header">Code:<br /></div><div class="code_body"><div dir="ltr"><code> Obj01_MdNormal: ; DATA XREF: ROM:Obj01_Modes�o<br /> bsr.w Sonic_Spindash<br /> bsr.w Sonic_Jump<br /> bsr.w Sonic_SlopeResist<br /> bsr.w Sonic_Move<br /> bsr.w Sonic_Roll<br /> bsr.w Sonic_LevelBoundaries<br /> jsr SpeedToPos<br /> bsr.w Sonic_AnglePos<br /> bsr.w Sonic_SlopeRepel<br /> rts<br /></code></div></div>
+
<asm>Obj01_MdNormal: ; DATA XREF: ROM:Obj01_Modes�o
 +
bsr.w Sonic_Spindash
 +
bsr.w Sonic_Jump
 +
bsr.w Sonic_SlopeResist
 +
bsr.w Sonic_Move
 +
bsr.w Sonic_Roll
 +
bsr.w Sonic_LevelBoundaries
 +
jsr SpeedToPos
 +
bsr.w Sonic_AnglePos
 +
bsr.w Sonic_SlopeRepel
 +
rts</asm>
  
 
'''Obj01''' is the most important object, it's the Sonic object! This table contains all of Sonic's routines. We'll need to remember this for use in a bit.
 
'''Obj01''' is the most important object, it's the Sonic object! This table contains all of Sonic's routines. We'll need to remember this for use in a bit.
  
4. Hit F3 on ConTEXT to find the next occurance and we're taken to the Spindash subroutine itself! <br />
+
4. Hit F3 on ConTEXT to find the next occurance and we're taken to the Spindash subroutine itself!  
  
 
<center>http://www.glowingbridge.org/splitfiles/asmtut03.png</center>
 
<center>http://www.glowingbridge.org/splitfiles/asmtut03.png</center>
  
<br />The next step is to select from '''Sonic_Spindash:''' all the way down to '''<nowiki>; End of function Sonic_Spindash</nowiki>'''. Copy this into the clipboard.
+
The next step is to select from '''Sonic_Spindash:''' all the way down to '''<nowiki>; End of function Sonic_Spindash</nowiki>'''. Copy this into the clipboard.
  
5. Now click the sonic1.asm tab. What we have to do now is place the spindash routine in it's equivalent place in Sonic 1. If you look back at the Beta-E disassembly, you can see '''<nowiki>; End of function Sonic_JumpHeight</nowiki>''' above the Sonic_Spindash routine. So, it's logical to place this routine in them same place in sonic1.asm. Search for '''<nowiki>; End of function Sonic_JumpHeight</nowiki>''' in sonic1.asm. <br />
+
5. Now click the sonic1.asm tab. What we have to do now is place the spindash routine in it's equivalent place in Sonic 1. If you look back at the Beta-E disassembly, you can see '''<nowiki>; End of function Sonic_JumpHeight</nowiki>''' above the Sonic_Spindash routine. So, it's logical to place this routine in them same place in sonic1.asm. Search for '''<nowiki>; End of function Sonic_JumpHeight</nowiki>''' in sonic1.asm.  
  
 
<center>http://www.glowingbridge.org/splitfiles/asmtut04.png</center>
 
<center>http://www.glowingbridge.org/splitfiles/asmtut04.png</center>
Line 45: Line 57:
 
6. Like I say in the above image, paste the code there!
 
6. Like I say in the above image, paste the code there!
  
<div class="code_header">Code:<br /></div><div class="code_body"><div dir="ltr"><code> ; End of function Sonic_JumpHeight<br /><br /> [CODE]<br /><br /> ; ---------------------------------------------------------------------------<br /> ; Subroutine to slow Sonic walking up a slope<br /></code></div></div>
+
<asm>; End of function Sonic_JumpHeight
  
7. Now we've pasted the code in, we have to edit the table of Sonic's routines in Sonic 1. Remember the table we saw earlier in Beta-E? It's exactly the same! Search for '''Obj01_MdNormal:''' (with the colon, also make sure you tell context to search from the top rather than from the cursor). <br />
+
[CODE]
 +
 
 +
; ---------------------------------------------------------------------------
 +
; Subroutine to slow Sonic walking up a slope</asm>
 +
 
 +
7. Now we've pasted the code in, we have to edit the table of Sonic's routines in Sonic 1. Remember the table we saw earlier in Beta-E? It's exactly the same! Search for '''Obj01_MdNormal:''' (with the colon, also make sure you tell context to search from the top rather than from the cursor).  
  
 
<center>http://www.glowingbridge.org/splitfiles/asmtut05.png</center>
 
<center>http://www.glowingbridge.org/splitfiles/asmtut05.png</center>
  
8. All we do now is insert the code from Beta-E again, this time, it's just one line: '''bsr.w Sonic_Spindash'''. <br />
+
8. All we do now is insert the code from Beta-E again, this time, it's just one line: '''bsr.w Sonic_Spindash'''.  
  
 
<center>http://www.glowingbridge.org/splitfiles/asmtut06.png</center>
 
<center>http://www.glowingbridge.org/splitfiles/asmtut06.png</center>
  
9. Now is a good time to save sonic1.asm, stop and take a look at what we've done. Run build.bat and lets take a look at our s1built.bin. <br />
+
9. Now is a good time to save sonic1.asm, stop and take a look at what we've done. Run build.bat and lets take a look at our s1built.bin.  
  
 
<center>http://www.glowingbridge.org/splitfiles/S1BUILT_016.gif http://www.glowingbridge.org/splitfiles/S1BUILT_017.gif http://www.glowingbridge.org/splitfiles/S1BUILT_018.gif http://www.glowingbridge.org/splitfiles/S1BUILT_019.gif</center>
 
<center>http://www.glowingbridge.org/splitfiles/S1BUILT_016.gif http://www.glowingbridge.org/splitfiles/S1BUILT_017.gif http://www.glowingbridge.org/splitfiles/S1BUILT_018.gif http://www.glowingbridge.org/splitfiles/S1BUILT_019.gif</center>
  
<br />The code works, but the spindash animation is not present in the ROM. This can be added, but requires slightly more advanced editing. So for now we are going to simply create a Sonic CD style spindash using the jumping animation.
+
The code works, but the spindash animation is not present in the ROM. This can be added, but requires slightly more advanced editing. So for now we are going to simply create a Sonic CD style spindash using the jumping animation.
  
 
10. Look for the '''Sonic_Jump:''' routine above the Spindash routine we placed. Towards the bottom is the key to our goal: '''move.b #2,$1C(a0) ; use "jumping" animation'''. $1C(a0) is the animation control for the sonic object, so we need to find the part of Sonic_Spindash which uses this to choose the animation.
 
10. Look for the '''Sonic_Jump:''' routine above the Spindash routine we placed. Towards the bottom is the key to our goal: '''move.b #2,$1C(a0) ; use "jumping" animation'''. $1C(a0) is the animation control for the sonic object, so we need to find the part of Sonic_Spindash which uses this to choose the animation.
  
<div class="code_header">Code:<br /></div><div class="code_body"><div dir="ltr"><code> Sonic_Spindash: ; CODE XREF: ROM:Obj01_MdNormal�p<br /> tst.b $39(a0)<br /> bne.s loc_10396<br /> cmpi.b #8,$1C(a0)<br /> bne.s locret_10394<br /> move.b ($FFFFF603).w,d0<br /> andi.b #$70,d0 ; 'p'<br /> beq.w locret_10394<br />'''move.b #9,$1C(a0); This is the animation we're interested in!'''<br /> move.w #$BE,d0 ; ''<br /> jsr (PlaySound_Special).l<br /> addq.l #4,sp<br /> move.b #1,$39(a0)<br /></code></div></div>
+
<asm>Sonic_Spindash: ; CODE XREF: ROM:Obj01_MdNormal�p
 +
tst.b $39(a0)
 +
bne.s loc_10396
 +
cmpi.b #8,$1C(a0)
 +
bne.s locret_10394
 +
move.b ($FFFFF603).w,d0
 +
andi.b #$70,d0 ; 'p'
 +
beq.w locret_10394
 +
 
 +
move.b #9,$1C(a0); This is the animation we're interested in!
 +
 
 +
move.w #$BE,d0 ; '¾'
 +
jsr (PlaySound_Special).l
 +
addq.l #4,sp
 +
move.b #1,$39(a0)</asm>
  
 
11. Now all we have to do is edit that line. It's a little complicated to explain how to work out how that is the animation (as you can see there is another one further up). But in any case, we can take the animation from the jumping code and put it here easily.
 
11. Now all we have to do is edit that line. It's a little complicated to explain how to work out how that is the animation (as you can see there is another one further up). But in any case, we can take the animation from the jumping code and put it here easily.
  
<div class="code_header">Code:<br /></div><div class="code_body"><div dir="ltr"><code> Sonic_Spindash: ; CODE XREF: ROM:Obj01_MdNormal�p<br /> tst.b $39(a0)<br /> bne.s loc_10396<br /> cmpi.b #8,$1C(a0)<br /> bne.s locret_10394<br /> move.b ($FFFFF603).w,d0<br /> andi.b #$70,d0 ; 'p'<br /> beq.w locret_10394<br />'''move.b #2,$1C(a0); Changed #9 to #2'''<br /> move.w #$BE,d0 ; ''<br /> jsr (PlaySound_Special).l<br /> addq.l #4,sp<br /> move.b #1,$39(a0)<br /></code></div></div>
+
<asm>Sonic_Spindash: ; CODE XREF: ROM:Obj01_MdNormal�p
 +
tst.b $39(a0)
 +
bne.s loc_10396
 +
cmpi.b #8,$1C(a0)
 +
bne.s locret_10394
 +
move.b ($FFFFF603).w,d0
 +
andi.b #$70,d0 ; 'p'
 +
beq.w locret_10394
 +
 
 +
move.b #2,$1C(a0); Changed #9 to #2
 +
 
 +
move.w #$BE,d0 ; '¾'
 +
jsr (PlaySound_Special).l
 +
addq.l #4,sp
 +
move.b #1,$39(a0)</asm>
  
 
12. Now save the assembly file and compile it again! Lets take a look...
 
12. Now save the assembly file and compile it again! Lets take a look...
Line 73: Line 118:
 
==What you should see==
 
==What you should see==
  
http://www.glowingbridge.org/splitfiles/spinanim.gif<br />We have working spindash, however it is a little too slow. In part 2 I will explain how to speed this up, as well as share more ASM goodies!
+
http://www.glowingbridge.org/splitfiles/spinanim.gifWe have working spindash, however it is a little too slow. In part 2 I will explain how to speed this up, as well as share more ASM goodies!
 
 
==Questions about the tutorial?==
 
 
 
Get help at [/mybb/ the forum] or in [?p=irc the irc]<nowiki>!</nowiki>
 
  
<br /><br />'''Thanks go to Quickman for coming up with the concept and for directing me in porting the spindash!'''
+
'''Thanks go to Quickman for coming up with the concept and for directing me in porting the spindash!'''

Revision as of 11:23, 2 January 2008

(Original guide written by Qjimbo)

You might not think the words "basic" and "assembly" could belong in the same sentence, however what we plan to do in this tutorial takes a more modular approach to our disassembly than you might have thought was possible.

Porting spindash from the Early Prototype

And that is today's project! We are going to use the Early Prototype disassembly that drx made, reason being that he took care over to ensure it used all the same label names as Hivebrain's Sonic 1 disassembly. This means porting data from it is a lot more straightforward than from the existing Sonic 2 disassembly.

Recommended Tools and Files

You can use any text editor to edit the disassembly, however I recommend using ConTEXT and Ambil's M68K Highlighter.

http://www.glowingbridge.org/splitfiles/icon-context.png ConTEXT v0.98.5
Text editor for editing the disassembly.

http://www.glowingbridge.org/splitfiles/icon-textfile.png Assembler.chl Ambil's M68K highlighter for ConTEXT
Highlighter that allows clearer code editing. After installing ConTEXT, place this in your C:\Program Files\ConTEXT\Highlighters folder.

http://www.glowingbridge.org/splitfiles/icon-winzip.gif drx's Beta-E disassembly
The disassembly of the Beta-E ROM

http://www.glowingbridge.org/splitfiles/icon-textfile.png http://68k.hax.com/
Useful resource for understanding assembly instructions.

1. First things first, we need to extract the disassembly out of the rar file. Extract it into the same folder as our Sonic 1 project (C:\SonED2-1\s1h\).

2. Now, we can open all the files we are going to use in ConTEXT. Open C:\SonED2-1\s1h\sonic1.asm and C:\SonED2-1\s1h\Sonic 2 (Early prototype).asm . ConTEXT uses tabs so it's easy to switch between which file we are editing.

http://www.glowingbridge.org/splitfiles/asmtut01.png

3. Now to find the Spindash routine in Beta-E. Select the Sonic 2 (Early prototype).asm tab and do a search for sonic_spindash

http://www.glowingbridge.org/splitfiles/asmtut02.png

The set of data we reach is this:

<asm>Obj01_MdNormal: ; DATA XREF: ROM:Obj01_Modes�o bsr.w Sonic_Spindash bsr.w Sonic_Jump bsr.w Sonic_SlopeResist bsr.w Sonic_Move bsr.w Sonic_Roll bsr.w Sonic_LevelBoundaries jsr SpeedToPos bsr.w Sonic_AnglePos bsr.w Sonic_SlopeRepel rts</asm>

Obj01 is the most important object, it's the Sonic object! This table contains all of Sonic's routines. We'll need to remember this for use in a bit.

4. Hit F3 on ConTEXT to find the next occurance and we're taken to the Spindash subroutine itself!

http://www.glowingbridge.org/splitfiles/asmtut03.png

The next step is to select from Sonic_Spindash: all the way down to ; End of function Sonic_Spindash. Copy this into the clipboard.

5. Now click the sonic1.asm tab. What we have to do now is place the spindash routine in it's equivalent place in Sonic 1. If you look back at the Beta-E disassembly, you can see ; End of function Sonic_JumpHeight above the Sonic_Spindash routine. So, it's logical to place this routine in them same place in sonic1.asm. Search for ; End of function Sonic_JumpHeight in sonic1.asm.

http://www.glowingbridge.org/splitfiles/asmtut04.png

6. Like I say in the above image, paste the code there!

<asm>; End of function Sonic_JumpHeight

[CODE]

---------------------------------------------------------------------------
Subroutine to slow Sonic walking up a slope</asm>

7. Now we've pasted the code in, we have to edit the table of Sonic's routines in Sonic 1. Remember the table we saw earlier in Beta-E? It's exactly the same! Search for Obj01_MdNormal: (with the colon, also make sure you tell context to search from the top rather than from the cursor).

http://www.glowingbridge.org/splitfiles/asmtut05.png

8. All we do now is insert the code from Beta-E again, this time, it's just one line: bsr.w Sonic_Spindash.

http://www.glowingbridge.org/splitfiles/asmtut06.png

9. Now is a good time to save sonic1.asm, stop and take a look at what we've done. Run build.bat and lets take a look at our s1built.bin.

http://www.glowingbridge.org/splitfiles/S1BUILT_016.gif http://www.glowingbridge.org/splitfiles/S1BUILT_017.gif http://www.glowingbridge.org/splitfiles/S1BUILT_018.gif http://www.glowingbridge.org/splitfiles/S1BUILT_019.gif

The code works, but the spindash animation is not present in the ROM. This can be added, but requires slightly more advanced editing. So for now we are going to simply create a Sonic CD style spindash using the jumping animation.

10. Look for the Sonic_Jump: routine above the Spindash routine we placed. Towards the bottom is the key to our goal: move.b #2,$1C(a0) ; use "jumping" animation. $1C(a0) is the animation control for the sonic object, so we need to find the part of Sonic_Spindash which uses this to choose the animation.

<asm>Sonic_Spindash: ; CODE XREF: ROM:Obj01_MdNormal�p tst.b $39(a0) bne.s loc_10396 cmpi.b #8,$1C(a0) bne.s locret_10394 move.b ($FFFFF603).w,d0 andi.b #$70,d0 ; 'p' beq.w locret_10394

move.b #9,$1C(a0); This is the animation we're interested in!

move.w #$BE,d0 ; '¾' jsr (PlaySound_Special).l addq.l #4,sp move.b #1,$39(a0)</asm>

11. Now all we have to do is edit that line. It's a little complicated to explain how to work out how that is the animation (as you can see there is another one further up). But in any case, we can take the animation from the jumping code and put it here easily.

<asm>Sonic_Spindash: ; CODE XREF: ROM:Obj01_MdNormal�p tst.b $39(a0) bne.s loc_10396 cmpi.b #8,$1C(a0) bne.s locret_10394 move.b ($FFFFF603).w,d0 andi.b #$70,d0 ; 'p' beq.w locret_10394

move.b #2,$1C(a0); Changed #9 to #2

move.w #$BE,d0 ; '¾' jsr (PlaySound_Special).l addq.l #4,sp move.b #1,$39(a0)</asm>

12. Now save the assembly file and compile it again! Lets take a look...

What you should see

http://www.glowingbridge.org/splitfiles/spinanim.gifWe have working spindash, however it is a little too slow. In part 2 I will explain how to speed this up, as well as share more ASM goodies!

Thanks go to Quickman for coming up with the concept and for directing me in porting the spindash!