Take your skills to the next level with these bite-sized tutorials!

Processing Resets

Posted August 24, 2020

Remember when consoles had reset buttons? Those were the days. No menus, no closing applications… just slam that button and the game resets. Simple and effective. But is it actually that simple? It turns out that when it comes to the Mega Drive, there’s a little feature that could turn into a trap if you’re not aware of it.,

I’m talking about the fact that there are two types of reset: A soft reset and a hard reset. A soft reset is the reset type you’re probably thinking about: It occurs when you press the reset button on your console. A hard reset is basically the same as turning the console off and on again. But why should we care about the difference?

Well, create a new SGDK project and let me show you!

Let’s demonstrate with a very simple program that simply displays an increasing number on screen. Define two variables outside of main():

int ticker = 0;
char tickerString[4] = "0000";

And then draw the value of ticker on the screen by adding this code to the while(1) game loop inside main():


Compile and run the game and you’ll see a number that increases every frame. Alright, now reset your emulator (in BlastEm you do that by pressing Tab, in Gens you need to go to CPU -> Reset 68000).

Notice anything? Even though you reset the console, the number doesn’t reset back to zero! Seems a bit strange, doesn’t it?

Well, that’s actually intentional. SGDK doesn’t clear the entire RAM on a soft reset, so that you can keep certain data like high scores and settings alive even after a reset. It would be a bit overkill to use SRAM (saving using a battery in the cartridge) just for that. Plus, you could do even more interesting things with it… Have you ever played the original X-Men game on the Mega Drive? That game had you reset your console to gain access to the final level. That obviously wouldn’t work if a soft reset deleted everything! And it also meant that you couldn’t do it when playing on the Sega Nomad, because that handheld didn’t have a reset button. Whoops.

Anyway, that’s why our number just keeps going up even after a soft reset. Obviously this can cause issues if we’re not careful. If we don’t clear the high score on a soft reset, players could rack up an infinite score by replaying the first level over and over, for example. Or our game could just outright break down because of memory issues. So how do we manage our data when it comes to resets? There are actually two ways.

1. Initializing

The simplest way is to initialize everything we need reset in main() before our game loop starts. The main() function is called every time we reset the console (using a soft or hard reset), so in our case, adding a ticker = 0; before while(1) would solve our problem and set the ticker back to 0 after each reset of the emulator.

2. Checking the Reset Type

But if you want more control over what gets reset and when, there’s actually a trick that lets you check for resets. If you add a parameter to main(), you can see whether the console has been reset and how:

int main(int resetType){

When the console has just been turned on, resetType will equal 1, indicating a hard reset. But if the reset button has just been pressed, resetType will equal 0! (You can call the parameter anything you want, by the way).

Let’s check if it works. Add the following chunk of code at the beginning of main(int resetType):

char typeString[14] = "";
sprintf(typeString,"Reset Type: %d",resetType);

If you compile and run the game now, you should see that the reset type is 1. Press tab (or whatever you do to soft-reset) and you’ll see that now it’s 0! So using an if-statement like if(resetType == 0){ ... } you can now control how your game should behave on a soft reset!

If you've got problems or questions, join the official SGDK Discord! It's full of people a lot smarter and skilled than me. Of course you're also welcome to just hang out and have fun!

Download the Project Files!

All patrons on Patreon get the complete source code for this tutorial, as well as other perks such as early access! And Patreon support also ensures that I can keep working on tutorials like this one. Become a Patron!
Just Want to Buy Me a Coffee?

Check out the rest of this tutorial series!

  • Creating Graphics for the Mega Drive
  • How to Quickly Generate C Prototype Functions in VSCode
  • Color Swapping
  • 4 Programs For Creating Mega Drive Graphics
  • Editing the Rom Header
  • Simple Game States
  • Creating a Simple Menu
  • Changing The Text Color in SGDK
  • Playing Music in SGDK
  • Converting VGZ to VGM
  • Processing Resets
  • Drawing Tiles From Code
  • Get Words in Your Inbox!

    Be oldschool and sign up for my newsletter to get updates! Just enter your email address, prove you're not part of Skynet and you're good to go!

    Powered by CleverReach. I will not send you spam or sell/give your email address to someone else.  You can of course unsubscribe at any time. By clicking the subscribe button above, you confirm that you have read and agreed to our privacy policy.

    By using the Disqus service you confirm that you have read and agreed to the privacy policy.

    comments powered by Disqus

    Related Posts

    HaxeFlixel Tutorials!

    If you’ve popped over to the tutorial section recently you might have noticed that I’ve added my very first HaxeFlixel tutorial! It shows how to implement a simple, pixel-perfect 2D water shader which I used for Go! Go! PogoGirl. But a few of you might be wondering what a HaxeFlixel is. Well, it’s a 2D game framework that is as powerful as it is underrated! It runs on the (also underrated) Haxe language, is extremely well documented, open source, and has built-in functions for almost anything you’d need.
    Read More

    Streets of Was

    As I’m sure many of you will remember, the original Streets of Rage for the Mega Drive had multiple endings. The real canonical ending has you beat the crap out of Mr. X, thereby ending his reign of terror forever (yeah, right). However, if you confronted Mr. X with a buddy in tow, a new possible path unlocked. A quick refresher is in order. When you confront Mr. X he will ask you to join his organization.
    Read More

    Streets of Rage 2 Design Docs

    A few years ago, Yuzo Koshiro posted a pile of old game design documents for Bare Knuckle 2 aka Streets of Rage 2 on the Ancient blog to commemorate the release of Streets of Rage 2 3D on the Nintendo 3DS. These documents gave a deep insight into the game’s inner workings, technical aspects, designs and even some cut content. They were an awesome resource for one of the most awesome games ever created.

    Read More