Hacking the SNES ROM

Discuss PoP1 for SNES here.
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Hacking the SNES ROM

Post by David »

Shauing wrote: February 29th, 2020, 10:07 am Is it possible to play the demo after the last training level?
For what I experimented, if in the Hacks tab Training 5 is not the last training level, the game softlocks after beating it.
That's because in that case the game tries to load the level after Training 5, which does not exist.

To load the demo level after the player completes Training 5:
At 0xEF5E write: 20 00 FE EA
At 0xFE00 write: C9 1B D0 05 A9 15 8D 44 05 60

The assembly source corresponding to the written bytes:

Code: Select all

At 0xEF5E write:
20 00 FE  JSR $FE00
EA        NOP

At 0xFE00 write:
C9 1B     CMP #$1B ; after Training 5
D0 05     BNE :1
A9 15     LDA #$15 ; demo level
8D 44 05  STA $0544 ; next level
          :1
60        RTS
You could for example change 15 to 00 if you wanted to load level 1 instead.

Do you also want to disable automatic moves on the demo level?
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David wrote: February 29th, 2020, 9:58 pm
Spoiler: show
That's because in that case the game tries to load the level after Training 5, which does not exist.

To load the demo level after the player completes Training 5:
At 0xEF5E write: 20 00 FE EA
At 0xFE00 write: C9 1B D0 05 A9 15 8D 44 05 60

The assembly source corresponding to the written bytes:

Code: Select all

At 0xEF5E write:
20 00 FE  JSR $FE00
EA        NOP

At 0xFE00 write:
C9 1B     CMP #$1B ; after Training 5
D0 05     BNE :1
A9 15     LDA #$15 ; demo level
8D 44 05  STA $0544 ; next level
          :1
60        RTS
You could for example change 15 to 00 if you wanted to load level 1 instead.
For some reason, the demo level can only be played once; if you die, you're booted out to the menu.

This leads me to a question where if it is possible to have all 27 levels available to play continuously? And also, if more levels could technically be added? (the remaining free space might be an issue on that though).
David wrote: February 29th, 2020, 9:58 pm Do you also want to disable automatic moves on the demo level?
Yes.

Also, after finishing the demo can either send you back to the menu or that the next Level should be Level 1? Or the game is forced to follow an order in the level table?
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Hacking the SNES ROM

Post by David »

Shauing wrote: February 29th, 2020, 10:16 pm For some reason, the demo level can only be played once; if you die, you're booted out to the menu.
It seems the game has special code to return to the menu if the prince dies on the demo level.
(Even though that can't happen in the original game. Unlike in the DOS version, the Prince always beats the guard in the SNES demo level.)
In the Pr1SnesLevEd hacks window, on the "training" tab, there is an option labeled "?", whose default value is "demo".
Set it to "(disable)".

Yes, I know that label is meaningless and the option is even on the wrong tab.
When I found this hack some years ago, I only knew that this part of the code checks if the current level is the demo level, but I didn't know the purpose. And it was near some code which checks if the current level is a training level, that's why I put it onto the training tab.
I figured out its purpose only now, when I was specifically looking for code which does what you wrote, and I realized that the offset I found is already in the hacks list of the editor.

Shauing wrote: February 29th, 2020, 10:16 pm This leads me to a question where if it is possible to have all 27 levels available to play continuously?
Yes, you just need to disable all special events on Jaffar's level.
Then set "show ending when next level would be" to the (nonexistent) level after training 5. (It appears as an empty item in the dropdown list.)

Shauing wrote: February 29th, 2020, 10:16 pm And also, if more levels could technically be added? (the remaining free space might be an issue on that though).
Probably yes, but then the resources following the levels in the first resource table have to be rearranged.
Or alternatively, the level loading code could be changed to load the extra levels from some other place instead of looking at resource 41+levelnumber.

And additionally, all the arrays related to levels (level types, level music, etc.) have to be enlarged, and moved to elsewhere where a longer array can fit.

And of course, the SNES level editor(s) have to be modified to know about all these changes.

Shauing wrote: February 29th, 2020, 10:16 pm
David wrote: February 29th, 2020, 9:58 pm Do you also want to disable automatic moves on the demo level?
Yes.
You can do so in the hacks window: on the "demo level" tab, set the first two options to disabled.
(But you probably already knew that?)

Shauing wrote: February 29th, 2020, 10:16 pm Also, after finishing the demo can either send you back to the menu or that the next Level should be Level 1? Or the game is forced to follow an order in the level table?
By default the levels appear in sequential order.
But it's possible to override this using a hack similar to the one in my previous post, just with different level numbers.
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David wrote: March 7th, 2020, 10:06 pm It seems the game has special code to return to the menu if the prince dies on the demo level.
(Even though that can't happen in the original game. Unlike in the DOS version, the Prince always beats the guard in the SNES demo level.)
In the Pr1SnesLevEd hacks window, on the "training" tab, there is an option labeled "?", whose default value is "demo".
Set it to "(disable)".

Yes, I know that label is meaningless and the option is even on the wrong tab.
When I found this hack some years ago, I only knew that this part of the code checks if the current level is the demo level, but I didn't know the purpose. And it was near some code which checks if the current level is a training level, that's why I put it onto the training tab.
I figured out its purpose only now, when I was specifically looking for code which does what you wrote, and I realized that the offset I found is already in the hacks list of the editor.
Interesting. So that's why many of the options on the hacks tab have a ''?'' labeled. I thought it was sort of a continuation of whatever hack was labeled before it (e.g., ''training ends when next level would be (Option) ? (Option)'' ).
David wrote: March 7th, 2020, 10:06 pm Yes, you just need to disable all special events on Jaffar's level.
Then set "show ending when next level would be" to the (nonexistent) level after training 5. (It appears as an empty item in the dropdown list.)
Ah, that's why there's some blank options on those. Good to know it is possible to expand the game further, though the ''Training 1-5'' labeling and pause menu might need to display Levels as 'Level 23-27', and that on those levels the time is still running and can be displayed, as well as save and display the best time.
Spoiler: show
Shauing wrote: February 29th, 2020, 10:16 pm And also, if more levels could technically be added? (the remaining free space might be an issue on that though).
David wrote: March 7th, 2020, 10:06 pm Probably yes, but then the resources following the levels in the first resource table have to be rearranged.
Or alternatively, the level loading code could be changed to load the extra levels from some other place instead of looking at resource 41+levelnumber.

And additionally, all the arrays related to levels (level types, level music, etc.) have to be enlarged, and moved to elsewhere where a longer array can fit.

And of course, the SNES level editor(s) have to be modified to know about all these changes.
So it is more likely that the ROM would need to expanded if more levels were to be implemented in order to have enough space.
David wrote: February 29th, 2020, 9:58 pm
Spoiler: show
Shauing wrote: February 29th, 2020, 10:16 pm
David wrote: February 29th, 2020, 9:58 pm Do you also want to disable automatic moves on the demo level?
Yes.
You can do so in the hacks window: on the "demo level" tab, set the first two options to disabled.
(But you probably already knew that?)
Due to the demo booting you out if killed, wasn't sure if there was anything extra to do that involved the 'disable automatic moves and autoplay'.
David wrote: February 29th, 2020, 9:58 pm
Shauing wrote: February 29th, 2020, 10:16 pm Also, after finishing the demo can either send you back to the menu or that the next Level should be Level 1? Or the game is forced to follow an order in the level table?
By default the levels appear in sequential order.
But it's possible to override this using a hack similar to the one in my previous post, just with different level numbers.
Hmm, but where do you write the ''20 xx xx EA'' code?

This leads me to a couple of ideas I've had for some time and would like to know if they're possible.
Knowing that the level warping to different (non-consecutive) levels is possible due to seeing it in glitches (e.g., jump to Level 4 to Level 12),
1. Can levels have multiple exits that lead to different levels via a level end door? (e.g., on Level 1 one exit lead to Level 2, and another on the same level to Level 4).
2. If the exit door can only lead to one exit, can a special exit in the same level take you to a different level? (EDIT: Did an attempt of this and though I got the intended result, I would love to be pretty much like if you were finishing a level via a level end door, that is: avoid seeing the next room so that the graphical effects take place in the same room you're exiting, plus hear the exit jingle music and display the best time).
3. Can the game have more than 6 special exits and in all four directions (I think there's no exits going up and right)?
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

Found a bug on Level 12 of my 30th anniversary port (I'm working on implementing the music). If the Prince reaches the level and the jingle still continues, this glitch occurs:

Any solution to this?
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Hacking the SNES ROM

Post by David »

Shauing wrote: March 21st, 2020, 6:32 pm Found a bug on Level 12 of my 30th anniversary port (I'm working on implementing the music). If the Prince reaches the level and the jingle still continues, this glitch occurs:
Any solution to this?
The music should stop when the prince completes the level through the special exit.
The DOS version does exactly the same.
(In fact SDLPoP used to have a bug exactly because I forgot to do so. See here.)

Earlier, I made a hack which disables the level end music on certain levels.
(And later I added a hack which changes the music for level 4.)
This should be changed so that if there is no level end music then the currently playing music should be stopped. (By playing the music with ID 0xFF.)

The solution I found is to simply repurpose the array at 0xFFA0 to store which music should be played, instead of just storing a 0/1 flag.

At 0xFF90 write: AE 79 05 BD A0 FF A2 05 20 4D EA 60
At 0xFFA0 write: 1C 1C 1C 1A 1C FF 1C 1C 1C 1C 1C FF FF FF 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
If you used different music IDs then: replace 1C with the ID of the default level end music, and 1A with the ID of the level 4 end music.

Code: Select all

At 0xFF90 write:
AE 79 05  LDX $0579
BD A0 FF  LDA $FFA0,X
A2 05     LDX #$05
20 4D EA  JSR $ea4d ; play music A ; cuesong
60        RTS

I played through the game again (mainly to test the hack above), and here are some more observations:

* I see you didn't add room links between adjacent rooms if there is no way to move between them.
For example on level 2 between room 10 and 13.
While this doesn't change gameplay, it affects the top of the screen, where you can see the bottom of the room above.

* In the starting room of level 1, the top row has two pillars which are not in the DOS version.

* Level 8, room 9: The two buttons are linked to the same event.
If you kill the guard on the closer button, the opener button won't appear pressed if you step on it (but it will still work).
snes_Shauing_button_level_8.png
snes_Shauing_button_level_8.png (15.52 KiB) Viewed 57347 times
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David wrote: March 22nd, 2020, 11:38 am
The music should stop when the prince completes the level through the special exit.
The DOS version does exactly the same.
(In fact SDLPoP used to have a bug exactly because I forgot to do so. See here.)

Earlier, I made a hack which disables the level end music on certain levels.
(And later I added a hack which changes the music for level 4.)
This should be changed so that if there is no level end music then the currently playing music should be stopped. (By playing the music with ID 0xFF.)

The solution I found is to simply repurpose the array at 0xFFA0 to store which music should be played, instead of just storing a 0/1 flag.

At 0xFF90 write: AE 79 05 BD A0 FF A2 05 20 4D EA 60
At 0xFFA0 write: 1C 1C 1C 1A 1C FF 1C 1C 1C 1C 1C FF FF FF 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C 1C
If you used different music IDs then: replace 1C with the ID of the default level end music, and 1A with the ID of the level 4 end music.

Code: Select all

At 0xFF90 write:
AE 79 05  LDX $0579
BD A0 FF  LDA $FFA0,X
A2 05     LDX #$05
20 4D EA  JSR $ea4d ; play music A ; cuesong
60        RTS
Awesome. I actually liked the music fade-out effect instead of the abrupt cut, but the latter is faithful to the DOS, so I'll take it. I did change the music ID as the DOS 'Level End' is longer than the SNES one, so I had to use the SNES 'Jaffar's Intro Theme' music ID which had enough length so I could replace it with the new 'Level End' music.

David wrote: March 22nd, 2020, 11:38 am I played through the game again (mainly to test the hack above), and here are some more observations:

* I see you didn't add room links between adjacent rooms if there is no way to move between them.
For example on level 2 between room 10 and 13.
While this doesn't change gameplay, it affects the top of the screen, where you can see the bottom of the room above.

* In the starting room of level 1, the top row has two pillars which are not in the DOS version.

* Level 8, room 9: The two buttons are linked to the same event.
If you kill the guard on the closer button, the opener button won't appear pressed if you step on it (but it will still work).
snes_Shauing_button_level_8.png
I'm happy you play tested it again and found more oddities/deviations I didn't catch, as well as more trigger oddities even when last time I thought I revisited all the open/close triggers. Thank you so much, I'll re-revisit the triggers one more time. I know there's some room aesthetic differences (like Level 1's sword room where there's some extra skeletons) and I might change those tiles to reflect the DOS rooms more accurately.

Any findings on the ideas I have for a possible third hack (the multiple exits per door or per any four directions and more than just six to choose)?
I'll just add that if it is possible for the Prince to take some of these special directional exits, and then on that new level return back to the room of the previous level.
There's more I have in mind, but the multiple exits for now is the main gimmick I want to test first.
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David, can a single music track play across the embrace, epilogue and end credits sequences? (recap is being omitted)
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

If the above it's not possible, how can I manipulate the length of the Princess cutscenes so that some of these last a bit longer before it fades-out? Because, unless I speed the music cues, said cues fade-out a bit too soon.

Also, can the sound test menu have the empty tracks omitted/inaccessible just like we did with the level select menu? As I'm pretty much removing/muting every other song that is not being used. I'm removing tracks 2-15 and track 20. I imagine I have to change the pointers so that it plays in order only tracks 1-19 or 15-34, instead of 1, 16-19 and 21-34.
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Hacking the SNES ROM

Post by David »

Shauing wrote: April 4th, 2020, 11:17 pm David, can a single music track play across the embrace, epilogue and end credits sequences? (recap is being omitted)
Disable epilogue music:
At 0x1AC5C write: EA EA EA EA

Disable credits music:
At 0x1B45D write: EA EA EA EA

Don't fade out the music at the end of the good ending cutscene:
At 0x1484A write: 20 90 FF EA
At 0x17F90 write: AD 84 0A C9 07 F0 04 22 DF F8 00 60
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Hacking the SNES ROM

Post by David »

Shauing wrote: April 11th, 2020, 1:55 am Also, can the sound test menu have the empty tracks omitted/inaccessible just like we did with the level select menu?
Let N be the last music ID you want to appear.
N = 19 = 0x13 in your case. (default: N=34=0x22)
At 0x1691E write: N-9 = 0x0A (default: 0x19)
At 0x16941 write: N-9 = 0x0A (default: 0x19)
At 0x1694D write: N-10 = 0x09 (default: 0x18)
Shauing wrote: April 11th, 2020, 1:55 am As I'm pretty much removing/muting every other song that is not being used. I'm removing tracks 2-15 and track 20.
I imagine I have to change the pointers so that it plays in order only tracks 1-19 or 15-34, instead of 1, 16-19 and 21-34.
Don't forget that if you change the pointers, it will change the IDs, so you have to change all references to these IDs.
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David wrote: April 11th, 2020, 4:46 pm
Disable epilogue music:
At 0x1AC5C write: EA EA EA EA

Disable credits music:
At 0x1B45D write: EA EA EA EA

Don't fade out the music at the end of the good ending cutscene:
At 0x1484A write: 20 90 FF EA
At 0x17F90 write: AD 84 0A C9 07 F0 04 22 DF F8 00 60
Nice, though now I have to move the 'Epilogue/Credits' music data to the 'Embrace' music data, as I originally wrote the 'Embrace' and 'Epilogue' as separate tracks. It's all right.
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David wrote: April 11th, 2020, 5:11 pm Let N be the last music ID you want to appear.
N = 19 = 0x13 in your case. (default: N=34=0x22)
At 0x1691E write: N-9 = 0x0A (default: 0x19)
At 0x16941 write: N-9 = 0x0A (default: 0x19)
At 0x1694D write: N-10 = 0x09 (default: 0x18)
Awesome, thanks!
David wrote: April 11th, 2020, 5:11 pm Don't forget that if you change the pointers, it will change the IDs, so you have to change all references to these IDs.
Yeah, I might move the minimum amount of pointers to avoid changing as many IDs as possible.

David, can the training option be removed and deactivated from the menu screen, so that there's only ''Game Start'', ''Continue'', ''Best Time'' and ''Option''?
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
David
The Prince of Persia
The Prince of Persia
Posts: 2877
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Hacking the SNES ROM

Post by David »

Shauing wrote: April 12th, 2020, 9:33 am David, can the training option be removed and deactivated from the menu screen, so that there's only ''Game Start'', ''Continue'', ''Best Time'' and ''Option''?
* Remove the TRAINING menu item and move the following items up one row.
At 0x128E write: 03
At 0x129B write: 04

* Change the interpretation of menu item indices accordingly.
At 0x11A8 write: EA

* Disable moving past the fourth menu item.
At 0x1236 write: 04
At 0x1247 write: 04

* Make the frame around the menu one row smaller.
At 0x116D write: 07
User avatar
Shauing
Calif
Calif
Posts: 435
Joined: April 5th, 2018, 10:38 pm
Contact:

Re: Hacking the SNES ROM

Post by Shauing »

David wrote: April 12th, 2020, 5:38 pm
* Remove the TRAINING menu item and move the following items up one row.
At 0x128E write: 03
At 0x129B write: 04

* Change the interpretation of menu item indices accordingly.
At 0x11A8 write: EA

* Disable moving past the fourth menu item.
At 0x1236 write: 04
At 0x1247 write: 04

* Make the frame around the menu one row smaller.
At 0x116D write: 07
Nice.

Is it possible to change the Intro cutscenes, Princess cutscenes and epilogue length? The timing is still a bit off in some cases if the music cues's speed matches as close as possible to the DOS ones.

Another thing; while making attempts on adding a new sample, for some reason new sequence I added to the area at ECDE6-ECE96, so that the list of sound effects expand from 45 to 46 doesn't register/play. It only plays if I replace an existing sequence. Why this happens?

Any findings on the multiple exits idea?
NEW UPDATE! Prince Of Persia: 30th Anniversary Port v1.1.5. Download it today!: viewtopic.php?p=29053#p29053
NEW UPDATE! Prince Of Persia: The Queen Of Light v2.6. Download it today! viewtopic.php?p=33174#p33174
Post Reply