Sonic and Sega Retro Message Board: Adding a CD-style level restart to Sonic 1 - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Page 1 of 1
    Locked
    Locked Forum

Adding a CD-style level restart to Sonic 1

#1 User is offline luluco 

Posted 11 August 2017 - 12:49 AM

  • Posts: 17
  • Joined: 09-August 17
  • Gender:Male
  • Location:Brazil
I have been learning m68k assembly recently with some help from the nice guides in the wiki. I'm starting with Sonic 1, generally implementing the bug fixes and learning as I go.

I thought of a relatively simple feature I'd like to add, the ability to restart a level by pressing a button when paused, like in CD. I managed to track down the specific code that handles the button inputs in the pause loop and moved instructions around so that the A button can be pressed even with debug mode off. Having done that I started to dig deep into the disassembly looking for how the game restarts a level when you die. After a while of trying out different labels like 'KillSonic', 'Sonic_Death' and other similar-sounding instructions I realized it wasn't going to be as easy as "calling a function".

So TL;DR: where and how does Sonic 1 restart levels? How can I replicate it in my own label? (by 'label' I mean where you begin 'functions', like "Pause_Reset:", with the colon at the end, but no '@' sign to the left)

Here's the code I have right now, please excuse the mess, I like to comment out things before I'm certain they're working:

Spoiler


As you can see all I have done for now was separate the game restart functionality, so I could work on it more clearly.



Also I'm new to these forums, so please tell me if I did anything wrong.

#2 User is offline MarkeyJester 

Posted 11 August 2017 - 06:56 AM

  • The architect of the universe, didn't build a stairway, leading nowhere.
  • Posts: 1842
  • Joined: 22-July 08
  • Gender:Male
  • Location:Japan
  • Wiki edits:16
Actually, you were very close. Calling "KillSonic" would have done the trick. The thing is, the subroutine "KillSonic" expects Sonic's object RAM address to be inside address register "a0".

So simply do the following:

		lea	($FFFFD000).w,a0
		jsr	KillSonic


This will trigger Sonic's routines to perform the series of death based functions. But of course, the game is still paused, so you'll have force the game to unpause and return out of the pause loop:

		move.b	#$80,($FFFFF003).w
		move.w	#0,($FFFFF63A).w
		rts


#3 User is offline luluco 

Posted 11 August 2017 - 08:40 AM

  • Posts: 17
  • Joined: 09-August 17
  • Gender:Male
  • Location:Brazil
Okay, I'll try that, thanks a lot.

By the way, I love your hack "Next Level", Sonic's rotating sprite and more animation frames are amazing.

#4 User is offline luluco 

Posted 11 August 2017 - 11:25 AM

  • Posts: 17
  • Joined: 09-August 17
  • Gender:Male
  • Location:Brazil
Great, now Sonic has a self-destruct button :D

This is the final code I ended up with:

Spoiler


I've copied part of the original game-reset functionality to fix the music (it wouldn't play again after killing sonic).
Without 'nop' the emulator (Kega) crashed upon loading the rom for some reason, but I didn't test twice before adding it, seems to be harmless though.

Now what I'm gonna do is see if I can manually replicate only parts of the kill function, so that it doesn't look as if it's actually killing Sonic, just restarting the level.
Also I'm going to make it so restarting doesn't take away a life, because I believe that's unfair, but to keep the game balanced I'll have to see some way to keep track of the last score when the level started or when Sonic really died, that way I can reset to said score and prevent players from restarting over and over to accumulate more points.
This post has been edited by luluco: 11 August 2017 - 12:14 PM

Page 1 of 1
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users