Actions

SCHG How-to

Difference between revisions of "Add a Second Digit To the Lifecounter in Sonic 2 SMS"

From Sonic Retro

(Created page with "{{GuideBy|Ravenfreak}} How to add a second digit to the life counter in Sonic 2 SMS Alright I always hated that you couldn't have more than 9 lives in Sonic 2, so I decided to ch...")
 
m (Whoops, that didn't need to be there. :V)
Line 1: Line 1:
 
{{GuideBy|Ravenfreak}}
 
{{GuideBy|Ravenfreak}}
How to add a second digit to the life counter in Sonic 2 SMS
 
 
Alright I always hated that you couldn't have more than 9 lives in Sonic 2, so I decided to change that. I didn't use the updated version on
 
Alright I always hated that you couldn't have more than 9 lives in Sonic 2, so I decided to change that. I didn't use the updated version on
 
the SVN, this is from the wiki version of the disassembly. First look for CapLifeCounterValue in S2.asm. It should look like this:
 
the SVN, this is from the wiki version of the disassembly. First look for CapLifeCounterValue in S2.asm. It should look like this:

Revision as of 05:30, 24 October 2011

(Original guide by Ravenfreak) Alright I always hated that you couldn't have more than 9 lives in Sonic 2, so I decided to change that. I didn't use the updated version on the SVN, this is from the wiki version of the disassembly. First look for CapLifeCounterValue in S2.asm. It should look like this:

<asm> LABEL_25AC: ld a, ($D292) or a ret nz ld a, (LifeCounter) cp $09 ;cap the life display at 9 jr c, + ld a, $09 +: rlca and $1E add a, $10 ld ($DBA9), a ret</asm> Now, delete every line after ret nz and add this: <asm> ld a, (LifeCounter)

       and $0F
       rlca

and $1E add a, $10 ld ($DBA9), a

       ret</asm>

This sets up the last nibble of the life counter. This is what your code should look like at this: <asm> ld a, ($D292) or a ret nz ld a, ($D292) or a ret nz

       ld   a, (LifeCounter)
       and $0F
       rlca

and $1E add a, $10 ld ($DBA9), a</asm> Alright time for a brief explination, the rlca operand allows the display to be updated, while the other parts of the code updates the display. We need to change it to where it can set another nibble for the counter. Right after "ld ($DBA9), a" add this: <asm>

  ld   a, (LifeCounter)
       and  $F0
       rrca

rrca rrca and $1E add a, $10 ld ($DBAF), a

       ret</asm>

This will allow the "x" on the counter to become the other nibble. That does allow the counter to display the proper numbers, but when Sonic gains a life after 9, it still displays the wrong value in the wrong nibble. So we need to change that. Find Collision_Monitor_Life in the source code, it should look like this: <asm> res 1, (hl) ld a, ($D298) inc a ld (LifeCounter), a ld a, SFX_ExtraLife ld ($DD04), a jp LABEL_25AC</asm> First, bellow res 1,(hl) add these lines: <asm> ld a, (LifeCounter)

       cp      $99
       ret     z</asm>

This will allow the game to cap the life counter after 99 lives. Next we need to change these lines: <asm> ld a, ($D298) inc a ld (LifeCounter), a</asm> To this: <asm> ld a, (LifeCounter)

       add     a, $01
       daa     (LifeCounter),a</asm>

The "daa" operand is used for counters, which is why the "inc" operand wouldn't work here. After that, save build and enjoy. This is what the routine looks like after everything is added: <asm> CapLifeCounterValue: LABEL_25AC:

       ld   a, ($D292)

or a ret nz

       ld   a, (LifeCounter)
       and $0F
       rlca

and $1E add a, $10 ld ($DBA9), a

       ld   a, (LifeCounter)
       and  $F0
       rrca

rrca rrca and $1E add a, $10 ld ($DBAF), a ret Collision_Monitor_Life: res 1, (hl)

       ld      a, (LifeCounter)
       cp      $99
       ret     z

add a, $01 daa

       ld      (LifeCounter), a
       ld      a, SFX_ExtraLife

ld ($DD04), a jp LABEL_25AC</asm>