News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: [SOLVED][Genesis][Technical] SoR2 Custom Code Proofread/Guidance Request  (Read 640 times)

eskayelle

  • Full Member
  • ***
  • Posts: 171
  • NBA Jam 2KTE / TMNT of Rage / Pong de las TMNT Dev
    • View Profile
While I'm finishing off a current SoR2 project, I wanted to go back to my TMNT of Kaizo hack and see if I could get a little guidance settling up on a puzzle I was never quite able to solve.

Full background is here.

tl;dr version:
I'm trying to set up the game so that only the very first life for both players is set to one life point.  When player 1 dies, their next life is set to the standard total.  Same for player 2.  I was able to get the code to work for player 1 but not for player 2.  Debugging hasn't gotten me anywhere to date.  Wondering if a 68000 guru could take a look at my code and let me know what I've missed.

Code: [Select]
;=========================================
;Streets of Rage 2
;Initial Health Code Modifications v7
;=========================================

;-----------------------------------------
;Purpose: Hijack the code before the 1st
;stage starts and send it to another area
;in ROM to add functionality to two more
;RAM bytes.
;-----------------------------------------
org $00005CBE ;offset to hijack
; lea ($00005D74),A6 ;4D F9 00 00 5D 74 ;original (hijacked) $5CBE code
jsr $00024E00 ;4E B9 00 02 4E 00 ;jump to new code location

;-----------------------------------------
;Purpose: Set two unused RAM bytes to zero
;before a game (stage 1) starts.
;These bytes will be changed so the health
;value increases to 0x68 whenever a player
;dies, but the very first life should have
;a health value much less than the default
;0x68.
;-----------------------------------------
org $00024E00 ;offset to hijack
move.b #$00,$F0BE ;11 FC 00 00 F0 BE ;create a player 1 parameter (1 byte)
move.b #$00,$F0BF ;11 FC 00 00 F0 BF ;create a player 2 parameter (1 byte)
lea ($00005D74),A6 ;4D F9 00 00 5D 74 ;original (hijacked) $5CBE code
rts ;4E 75 ;return to hijacked location and continue code

;-----------------------------------------
;Purpose: The byte with the initial health
;value is at offset $7EC8.
;Need to modify this code to split the
;commands such that the initial value is
;reduced, but all lives after receive a
;larger health value (the old 0x68).
;-----------------------------------------
org $00007EC8 ;offset to hijack
; move.w #$0068,$0080(A2) ;35 7C 00 68 00 80 ;this is the original code at $7EC8
jsr $00024E50 ;4E B9 00 02 4E 50 ;jump to new code location

org $00024E50 ;new code to split out 0x68 health per player after death
addq.b,#1,$F0BE ;52 38 F0 BE ;increment new player 1 byte
addq.b,#1,$F0BF ;52 38 F0 BF ;increment new player 2 byte
cmpi.b #$01,$F0BE ;0C 38 00 01 F0 BE ;P1 RAM byte should be #$01 the first stage, first life
beq.s splithealth ;67 10 ;if equals #$01, give #$01 in health; else, give health of #$68
cmpi.b #$01,$F0BF ;0C 38 00 01 F0 BF ;P2 RAM byte should be #$01 the first stage, first life
beq.s splithealth ;67 08 ;if equals #$01, give #$01 in health; else, give health of #$68
move.w #$0068,$0080(A2) ;35 7C 00 68 00 80 ;this is the original code at $7EC8
rts ;4E 75 ;looking to jump back to $7ECE -- clr.w $00A8(A2)

splithealth:
; move.b #$68,$EF81 ;11 FC 00 68 EF 81 ;$EF81 appears to be where the default health value comes from; but $F081 is for player 2
; move.w #$0068,$0080(A2) ;35 7C 00 68 00 80 ;this is the original code at $7EC8; seems to do almost the same thing my code above would have
move.w #$0001,$0080(A2) ;35 7C 00 01 00 80 ;change #$68 to a lower number, so when $F0BE or $F0BF = #$01, that player starts game with less life
rts ;4E 75 ;looking to jump back to $7ECE -- clr.w $00A8(A2)
;
;------------------------------------------
;As written:
;When the ROM starts, P1 and P2 have RAM
;values of zero.
;When the first stage of the first game
;starts, the RAM values will increment to
;#$01.  The comparison will occur.
;The code will branch, and default health
;for both players will be 1 unit.
;Plus, both RAM values will increment.
;P1 and P2 will have RAM values of 2.
;So, whenever either dies, when this code
;runs again, it will not branch, and life
;points assigned will be #$68.
;
;When a game is reset (hard or soft),
;the RAM bytes should be assigned values
;of zero.
;
;Testing:
;Currently works for P1, but P2 starts
;with full life still.  This will be the
;puzzle, the test of friendship...
;
;Will the stronger player take P1?
;Will P2 let P1 take the 1up or make them
;take the suicide attempt to get to the
;chicken before Y. Signal kills them?
;------------------------------------------
;
;------------------------------------------
;-----------------NOTES--------------------
;FFEFA9 and FFF0A9 are the life counters
;FFEF80 is the total health value (max).
;$7ECB is the offset for how high health can go.
;
;Try FFFFF0BE and FFFFF0BF as unused RAM...
;
;...
;
;7EC8 move.w #$0068,$0080(A2) ;this is the original code for the default life points
;7ECE clr.w $00A8(A2) ;this is where I want the hijack to come back to
;7ED2 bra $00C6 [00:7F9A]
;
;...
;-------------------------------------------

Thanks for reading!
« Last Edit: February 27, 2021, 05:33:04 pm by eskayelle »
I once wrote a blog.  Maybe you'll find something in it useful?  https://www.romhacking.net/forum/index.php?topic=30593.0

Tony H

  • Full Member
  • ***
  • Posts: 131
    • View Profile
    • The Code Hut
Re: [Genesis][Technical] SoR2 Custom Code Proofread/Guidance Request
« Reply #1 on: February 24, 2021, 03:53:36 pm »
Have you done a bp w on FFF0BE and FFF0BF when the game is first starting?  It looks like both should be exactly the same. Does FFF0BF initially have a value of zero written to it from your custom code and then a value of $68, or does it skip your zero value and just moves the $68 value?
« Last Edit: February 24, 2021, 04:00:20 pm by Tony H »
The Code Hut: http://codehut.gshi.org/

Game Genie codes and ROM hacking guides

eskayelle

  • Full Member
  • ***
  • Posts: 171
  • NBA Jam 2KTE / TMNT of Rage / Pong de las TMNT Dev
    • View Profile
Re: [Genesis][Technical] SoR2 Custom Code Proofread/Guidance Request
« Reply #2 on: February 24, 2021, 05:10:40 pm »
Hey, Tony.  Thanks for the response.

At startup, both variables are #$00 up until the point in which my custom code assigns them to be #$00 just before the title screen displays.  They then remain #$00 until just after the players are selected.

At this point, $FFF0BE increments to #$01.  Then $FFF0BF does the same.  The process repeats, yielding a value of #$02 in both $FFF0BE and $FFF0BF. The Stage 1 Start tiles display, and the game starts.  Player 1 receives one health point.  Player 2 receives the standard full life bar.

EDIT: I think your suggestion may have done the trick.  If the increments duplicate in sequence, I might need to change the player 2 comparison to #$02 rather than #$01.  Gonna give that edit a shot and see.

EDIT 2: There's one more nuance here, where some CMP/BEQs need to be considered in situations where there's a second player versus where there isn't.  I'm cleaning up the custom code a bit, and will stick it in my blog in the Personal Projects forum for those interested.
« Last Edit: February 27, 2021, 04:30:43 pm by eskayelle »
I once wrote a blog.  Maybe you'll find something in it useful?  https://www.romhacking.net/forum/index.php?topic=30593.0