Actions

SCHG How-to

Difference between revisions of "Add a New Monitor in Sonic 2 SMS"

From Sonic Retro

m (Text replacement - "</asm>" to "</syntaxhighlight>")
m (Text replacement - "<asm>" to "<syntaxhighlight lang="asm">")
Line 4: Line 4:
 
First, open s2.asm in your editor of choice and search for "Collision_Monitor". It should look like this:  
 
First, open s2.asm in your editor of choice and search for "Collision_Monitor". It should look like this:  
  
<asm>Collision_Monitor:
+
<syntaxhighlight lang="asm">Collision_Monitor:
 
LABEL_47F6: ;collision with monitor
 
LABEL_47F6: ;collision with monitor
 
ld      hl, $D39D
 
ld      hl, $D39D
Line 24: Line 24:
 
ret</syntaxhighlight>
 
ret</syntaxhighlight>
 
These are the types of monitors used in the game. Now scroll down until you see this:
 
These are the types of monitors used in the game. Now scroll down until you see this:
<asm>LABEL_4845:
+
<syntaxhighlight lang="asm">LABEL_4845:
 
res    5, (hl)
 
res    5, (hl)
 
ret</syntaxhighlight>
 
ret</syntaxhighlight>
Line 30: Line 30:
 
Now at this point you might think to add your new monitor code after the res operand, but if you do this the game freezes.  
 
Now at this point you might think to add your new monitor code after the res operand, but if you do this the game freezes.  
 
To get past this, you need to page in the bank that contains the monitors, bank 07. So after the res operand add this:
 
To get past this, you need to page in the bank that contains the monitors, bank 07. So after the res operand add this:
<asm> ld a, :Bank07
+
<syntaxhighlight lang="asm"> ld a, :Bank07
 
       ld ($FFFF),a
 
       ld ($FFFF),a
 
       Call New_Monitor
 
       Call New_Monitor
Line 36: Line 36:
 
You can change the "New_Monitor" label to whatever you want of course. xP Now to add the monitor code. Before adding your code, if you wanted to
 
You can change the "New_Monitor" label to whatever you want of course. xP Now to add the monitor code. Before adding your code, if you wanted to
 
use the Question Mark monitor add this:
 
use the Question Mark monitor add this:
<asm>New_Monitor:
+
<syntaxhighlight lang="asm">New_Monitor:
 
       ld a, ($D39D)
 
       ld a, ($D39D)
 
       cp $07
 
       cp $07

Revision as of 21:45, 20 December 2015

(Original guide by Ravenfreak)

So you want to add a new monitor in Sonic 2 and wanted to use one of the few unused monitors but don't know how? Well, here's how! First, open s2.asm in your editor of choice and search for "Collision_Monitor". It should look like this:

Collision_Monitor:
LABEL_47F6:		;collision with monitor
	ld      hl, $D39D
	ld      a, (hl)
	bit     0, a
	jr      nz, Collision_Monitor_Rings
	bit     1, a
	jr      nz, Collision_Monitor_Life
	bit     4, a
	jr      nz, Collision_Monitor_Continue
	bit     5, a
	jr      nz, LABEL_4845
	bit     2, a
	jr      nz, Collision_Monitor_Sneakers
	bit     3, a
	jr      nz, Collision_Monitor_Invincibility
	bit     6, a
	jr      nz, LABEL_4884
	ret

These are the types of monitors used in the game. Now scroll down until you see this:

LABEL_4845:
	res     5, (hl)
	ret

This is one of two blank monitors that are available to use, the other one is located after the invincibility monitor routine. Now at this point you might think to add your new monitor code after the res operand, but if you do this the game freezes. To get past this, you need to page in the bank that contains the monitors, bank 07. So after the res operand add this:

 ld a, :Bank07
      ld ($FFFF),a
      Call New_Monitor
      ret

You can change the "New_Monitor" label to whatever you want of course. xP Now to add the monitor code. Before adding your code, if you wanted to use the Question Mark monitor add this:

New_Monitor:
      ld a, ($D39D)
      cp $07
      ret z
      ;your code goes here

And that's it! But of course don't forget to edit each level's object layout, otherwise you'll never be able to test your code. xP