Actions

SCHG How-to

Add new moves in Sonic 1

From Sonic Retro

(Original guide by Ravenfreak)

So you want to add a new move to your Sonic 1 hack but you don't know where to start? That's what this guide is for! This guide will cover the SVN disassembly. As an example for this guide, I'll give Sonic the ability to be invincible without having to destroy the monitor that contains the power-up. Okay, to start, you want to open sonic.asm in your favorite text editor. (I recommend using ConTEXT, but you don't have to.) Next you want to find the word "Modes". This is what the code should look like:

; ---------------------------------------------------------------------------
; Modes	for controlling	Sonic
; ----------------------------------------------------------------------------------

Sonic_MdNormal:                      ; XREF: Sonic_Modes

		bsr.w	Sonic_Jump
		bsr.w	Sonic_SlopeResist
		bsr.w	Sonic_Move
		bsr.w	Sonic_Roll
		bsr.w	Sonic_LevelBound
		jsr	SpeedToPos
		bsr.w	Sonic_AnglePos
		bsr.w	Sonic_SlopeRepel
		rts

As you can see, these are Sonic's moves, and each are stored in subroutines. So now, we are going to add the code to make Sonic invincible from the start! So right after Sonic_MdNormal add bsr.w Sonic_Invinc. (Remember, this is an example. You can name the label whatever you want and give Sonic any ability you want if you know how, but you must always have the correct operation, in this case bsr.w which stands for "branch to subroutine", otherwise you'll get build errors.) This is what the new code should look like:

; ---------------------------------------------------------------------------
; Modes	for controlling	Sonic
; ----------------------------------------------------------------------------------

Sonic_MdNormal:                      ; XREF: Sonic_Modes
                
                bsr.w   Sonic_Invinc
		bsr.w	Sonic_Jump
		bsr.w	Sonic_SlopeResist
		bsr.w	Sonic_Move
		bsr.w	Sonic_Roll
		bsr.w	Sonic_LevelBound
		jsr	SpeedToPos
		bsr.w	Sonic_AnglePos
		bsr.w	Sonic_SlopeRepel
		rts

So that's a start, now you have to create the subroutine to give Sonic the new move. This is a very simple thing to do, first locate the _incObj folder. This is where each subroutine is located at. Scroll down until you see SonicJump.asm. Open it in a text editor, select the whole file and paste it to a blank template. This is what Sonic Jump.asm looks like:

; ---------------------------------------------------------------------------
; Subroutine allowing Sonic to jump
; ----------------------------------------------------------------------------------

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


Sonic_Jump:				; XREF: Obj01_MdNormal; Obj01_MdRoll
		move.b	(v_jpadpress2).w,d0
		andi.b	#btnABC,d0	; is A, B or C pressed?
		beq.w	locret_1348E	; if not, branch
		moveq	#0,d0
		move.b	obAngle(a0),d0
		addi.b	#$80,d0
		bsr.w	sub_14D48
		cmpi.w	#6,d1
		blt.w	locret_1348E
		move.w	#$680,d2
		btst	#6,obStatus(a0)
		beq.s	loc_1341C
		move.w	#$380,d2

loc_1341C:
		moveq	#0,d0
		move.b	obAngle(a0),d0
		subi.b	#$40,d0
		jsr	(CalcSine).l
		muls.w	d2,d1
		asr.l	#8,d1
		add.w	d1,obVelX(a0)	; make Sonic jump
		muls.w	d2,d0
		asr.l	#8,d0
		add.w	d0,obVelY(a0)	; make Sonic jump
		bset	#1,obStatus(a0)
		bclr	#5,obStatus(a0)
		addq.l	#4,sp
		move.b	#1,$3C(a0)
		clr.b	$38(a0)
		sfx	sfx_Jump	; play jumping sound
		move.b	#$13,obWidth(a0)
		move.b	#9,obHeight(a0)
		btst	#2,obStatus(a0)
		bne.s	loc_13490
		move.b	#$E,obWidth(a0)
		move.b	#7,obHeight(a0)
		move.b	#id_Roll,obAnim(a0) ; use "jumping" animation
		bset	#2,obStatus(a0)
		addq.w	#5,obY(a0)

locret_1348E:
		rts	
; ===========================================================================

loc_13490:
		bset	#4,obStatus(a0)
		rts	
; End of function Sonic_Jump

Next, you want to change that to this:

; ---------------------------------------------------------------------------
; Subroutine to make Sonic Invincible from the start of the game
; ----------------------------------------------------------------------------------

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

Sonic_Invinc:
		
                move.b	#1,(v_invinc).w	; make Sonic invincible
                 rts	

; End of subroutine Sonic_Invinc

Name the file Sonic Invincible.asm, and save it to the _incObj folder. So the subroutine is there, but you're not done yet. Open sonic.asm again if it's not already opened. Make a search for "Sonic Jump." You should see this:

locret_13302:
		rts	

		include	"_incObj\Sonic LevelBound.asm"
		include	"_incObj\Sonic Roll.asm"
		include	"_incObj\Sonic Jump.asm"
		include	"_incObj\Sonic JumpHeight.asm"
		include	"_incObj\Sonic SlopeResist.asm"
		include	"_incObj\Sonic RollRepel.asm"
		include	"_incObj\Sonic SlopeRepel.asm"
		include	"_incObj\Sonic JumpAngle.asm"
		include	"_incObj\Sonic Floor.asm"
		include	"_incObj\Sonic ResetOnFloor.asm"
		include	"_incObj\Sonic (part 2).asm"
		include	"_incObj\Sonic Loops.asm"
		include	"_incObj\Sonic Animate.asm"
		include	"_anim\Sonic.asm"
		include	"_incObj\Sonic LoadGfx.asm"

This tells the compiler to also include the files located in the folder. You must change this in order for it to build, otherwise it'll never find the move you added. xP After include "_incObj\Sonic Roll.asm", add this:

include	"_incObj\Sonic Invincible.asm"

Next, build your ROM and your new ability should work! Keep in mind that if you want to add an object with Sonic's new move, you should look at this guide to set things up. Also this code does work, but it doesn't load the stars object because I didn't add the code that loads the objects since after all, it's an example. xP

SCHG How-To Guide: Sonic the Hedgehog (16-bit)
Fixing Bugs
Fix Demo Playback | Fix a Race Condition with Pattern Load Cues | Fix the SEGA Sound | Display the Press Start Button Text | Fix the Level Select Menu | Fix the Hidden Points Bug | Fix Accidental Deletion of Scattered Rings | Fix Ring Timers | Fix the Walk-Jump Bug | Correct Drowning Bugs | Fix the Death Boundary Bug | Fix the Camera Follow Bug | Fix Song Restoration Bugs | Fix the HUD Blinking | Fix the Level Select Graphics Bug | Fix a remember sprite related bug
Changing Design Choices
Change Spike Behavior | Collide with Water After Being Hurt | Fix Special Stage Jumping Physics | Improve the Fade In\Fade Out Progression Routines | Fix Scattered Rings' Underwater Physics | Remove the Speed Cap | Port the REV01 Background Effects | Port Sonic 2's Level Art Loader | Retain Rings Between Acts | Add Sonic 2 (Simon Wai Prototype) Level Select | Improve ObjectMove Subroutines | Add Sonic 2 Level Select | Collide with Water After Being Hurt | Smooth Out Rotation in Special Stages
Adding Features
Add Spin Dash ( Part 1 (GitHub)/(Hivebrain) / Part 2 / Part 3 / Part 4 ) | Add Eggman Monitor | Add Super Sonic | Add Extended Camera | Add the Air Roll | Add 6-Button Support
Sound Features
Expand the Sound Index | Play Different Songs Per Act | Port Sonic 2 Final Sound Driver | Port Sonic 3's Sound Driver | Change The SEGA Sound | Correct PAL Music Tempo
Extending the Game
Load Chunks From ROM | Add Extra Characters | Make an Alternative Title Screen | Use Dynamic Tilesets | Make GHZ Load Alternate Art | Make Ending Load Alternate Art | Add a New Zone | Set Up the Goggle Monitor | Add New Moves | Add a Dynamic Collision System | Dynamic Special Stage Walls System | Extend Sprite Mappings and Art Limit | Enigma Credits | Use Dynamic Palettes
Miscellaneous
Convert the Hivebrain 2005 Disassembly to ASM68K
Split Disassembly Guides
Set Up a Split Disassembly | Basic Level Editing | Basic Art Editing | Basic ASM Editing (Spin Dash)

|Add new moves in Sonic 1]]