Sonic the Hedgehog/Subroutines
From Sonic Retro
SCHG: Sonic 1's Subroutines
At some point, you, the user on Sonic Retro has made an attempt at creating a rom hack of a Mega Drive (or Sega Genesis for you American users) Sonic game. We'll be focusing on Sonic 1's subroutines and exactly what they do.
This guide is actually focused on the GitHub disassembly. If you are using a hivebrain disassembly or something else, try to find the corresponding subroutine in question since the Hivebrain versions won't be here.
What are subroutines?
I can try to make this as simple as possible for people beginning the Sonic ROM Hacking scene. Let's say, you want to add back in the unused Robotnik monitor into Sonic 1. To do this, we would need to use subroutines to make the player get damaged and lose their rings when they break the monitor. Here's a tutorial if you actually want to do this. As stated there, when you replace that line of code that forces the monitor to do nothing with the "Spik_Hurt" routine, you are actually directing it to a subroutine. The "Spik_Hurt" routine is the routine that goes into play when Sonic makes contact with spikes. Knocking him back and causing him to get damaged (or nothing if invincible). When you branch the monitor to be broken to trigger the spikes routine, you're making the monitor be forced to hurt Sonic when it was originally going to do nothing! I tried to sum it up as best as possible.
Import routines into code
The exact same way they imported the spikes routine into the unused Robotnik montior can apply to any other monitor. Like the ring monitor. Change the line of code that tells the game to give Sonic 10 rings to hurting Sonic. Simple as that! Though, it doesn't apply to anything. Especially in places where Sonic isn't loaded in. You can't just put the code to hurt Sonic after the player presses the start button on the title screen. That also doesn't mean that the game will wait for Sonic to spawn in and then hurt the player.
If you would like to hack Sonic 1, view the tutorials below!
Written by XPointZPoint