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 »

Here is my next attempt:
At x7207 write: 20 00 FF EA 0A
At x7F00 write: B5 07 D0 0C A3 0B D5 0C F0 04 A9 04 80 02 A9 00 60
(I don't remember if I have already used the x7F00 area for some earlier hack I gave you. In either case you can try this by starting from the original ROM.)

The top part of the prince (topmost 16 pixels) will use the regular palette, the rest will use the blue palette.
(Or you can change F0 04 to D0 04 in the second part to swap these.)

The problem is that his blue part will be transparent when he meets the shadow.
This happens because the "green kid" palette is loaded into the second half of palette slots (see here) and thus it's made transparent together with the shadow.
Prince_palettes.png
Prince_palettes.png (10.25 KiB) Viewed 23628 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: July 17th, 2018, 4:09 pm The problem is that his blue part will be transparent when he meets the shadow.
This happens because the "green kid" palette is loaded into the second half of palette slots (see here) and thus it's made transparent together with the shadow.

At least it stays on one palette. There are still a few animations where the palette swap is loaded incorrectly or doesn't move along with the animations due to the palette swap being applied only to the top/bottom 16 pixels.

During the intro, the Prince sitting and being dragged away sprites plus Jaffar's walk sprites ONLY during the scrolling corridor scene, all have the top/bottom half loaded with the wrong palette, though if D0 04 is used, the Prince being dragged away sprites only affect the head and the guards head (as they share the same palette), and Jaffar's shoulders to head:
WrongPaletteA.png
WrongPaletteA.png (14.93 KiB) Viewed 23621 times
WrongPaletteB.png
WrongPaletteB.png (15.91 KiB) Viewed 23621 times
WrongPaletteC.png
WrongPaletteC.png (6.84 KiB) Viewed 23621 times
WrongTopPaletteA.png
WrongTopPaletteA.png (15.05 KiB) Viewed 23621 times
WrongTopPaletteB.png
WrongTopPaletteB.png (17.41 KiB) Viewed 23621 times
WrongTopPaletteC.png
WrongTopPaletteC.png (7.2 KiB) Viewed 23621 times

There is also an incorrect palette during the ending where the prince hugs and kisses the princess, as well as the elephant during the credits.

If the prince falls, crouches, gets up or climbs, the palette gets misaligned due to the palette only changing the top/bottom 16 pixels.
PaletteCrouching.png
PaletteCrouching.png (1.05 KiB) Viewed 23621 times
PaletteClimbing.png
PaletteClimbing.png (1.18 KiB) Viewed 23621 times
PaletteTopFalling.png
PaletteTopFalling.png (1.07 KiB) Viewed 23621 times
PaletteTopGettingUp.png
PaletteTopGettingUp.png (1.33 KiB) Viewed 23621 times

David wrote: July 17th, 2018, 4:09 pm Here is my next attempt:
At x7207 write: 20 00 FF EA 0A
At x7F00 write: B5 07 D0 0C A3 0B D5 0C F0 04 A9 04 80 02 A9 00 60
(I don't remember if I have already used the x7F00 area for some earlier hack I gave you. In either case you can try this by starting from the original ROM.)
On the ROM where I am doing the mod, yes, that area is being used for the modifier=30 loose floor looking like normal floor hack, but these kind of tests I do them on a copy where I test all kinds of stuff before deciding which to apply to the mod ROM.
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: July 18th, 2018, 2:12 am At least it stays on one palette. There are still a few animations where the palette swap is loaded incorrectly or doesn't move along with the animations due to the palette swap being applied only to the top/bottom 16 pixels.
Oops, I didn't think of the intro!
Shauing wrote: July 18th, 2018, 2:12 am If the prince falls, crouches, gets up or climbs, the palette gets misaligned due to the palette only changing the top/bottom 16 pixels.
I just realized that it's his *pants* and not his shoes that use the same color as his turban (and thus need to be separated). My bad.
But it seems that when the prince is crouching, his turban and his pants are in the same 16×16 pixel area.
That means that this approach is not really going to work, at least with those moves.
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: July 21st, 2018, 9:27 am I just realized that it's his *pants* and not his shoes that use the same color as his turban (and thus need to be separated). My bad.
But it seems that when the prince is crouching, his turban and his pants are in the same 16×16 pixel area.
That means that this approach is not really going to work, at least with those moves.
I did wrote that turban and pants shared the same color back in the mock-up I did; that's why I asked if the pants only could be changed by using the red palette on that area only.
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 »

Question regarding the shadow.
At the end of Level 9, the shadow walks a step (shuffle as it is called in the game's manual) to press a switch and close the final door when the kid does a running jump. Is it possible to change this running jump trigger to either a standing jump or climbing up? I want the prince to attempt to climb/reach a specific tile only for the shadow to press a switch and make the tile fall.
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: July 27th, 2018, 11:46 pm Question regarding the shadow.
At the end of Level 9, the shadow walks a step (shuffle as it is called in the game's manual) to press a switch and close the final door when the kid does a running jump. Is it possible to change this running jump trigger to either a standing jump or climbing up? I want the prince to attempt to climb/reach a specific tile only for the shadow to press a switch and make the tile fall.
To change what move of the prince will trigger the shadow's step:
Search: AD 67 04 C9 2B
Change: 2B to 43
0x43 is the first frame of jumping up and climbing up.

You can also use other frames:
You can find the full list of frames in the sequence table ZIP here: viewtopic.php?p=17498#p17498 .
In the document find "Frame tables". The number after "FRAME" is what you need.
Remember that frame numbers are decimal in the document, but you need to enter them in hex into the hex editor.

Then we need to get rid of the condition that the prince must be in the left half of the room:
Search: AD 68 04 C9 80
Change 80 to FF

I also found out how to change the shadow's moves, because on first read I misunderstood what you want...
Spoiler: show
Search: 20 B7 92 4C 7A 92
Change to:
a) If you want a standing jump: 20 8E 92 4C 7A 92
(In the original level, the shadow will jump straight into the pit! :) )
b) If you want a jump up: 20 8E 92 4C 8E 92
(It seems I can't make the shadow climb up.)

Alternatively, you can use any two moves (put them after 20 and 4C) from this list:

Code: Select all

925F = release all (nothing)
927A = forward (run)
9283 = back (turn around)
928E = up (jump up) (Use together with "forward" for a standing jump.)
9297 = down (crouch)
92A2 = up+back (jump up)
92A9 = down+back (crouch)
92B0 = down+forward (draw sword)
92B7 = shift (Used together with "forward" for a step in the original game.)
92C0 = release shift (nothing)
(Don't forget to swap the two bytes.)
The relevant part of the disassembly: (for both hacks)
Spoiler: show

Code: Select all

level 9 room 11 shadow close:
01:8C24: ad 62 04    LDA $0462 ; Char.room ; CharScrn
01:8C27: c9 0b       CMP #$0b
01:8C29: d0 14       BNE $8c3f
01:8C2B: ad 67 04    LDA $0467 ; Kid? ; Kid.frame
01:8C2E: c9 2b       CMP #$2b
01:8C30: d0 0d       BNE $8c3f
01:8C32: ad 68 04    LDA $0468 ; Kid.x
01:8C35: c9 80       CMP #$80
01:8C37: b0 06       BCS $8c3f
01:8C39: 20 b7 92    JSR $92b7 ; automove shift
01:8C3C: 4c 7a 92    JMP $927a ; automove forward
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: July 28th, 2018, 12:27 pm
To change what move of the prince will trigger the shadow's step:
Search: AD 67 04 C9 2B
Change: 2B to 43
0x43 is the first frame of jumping up and climbing up.

You can also use other frames:
You can find the full list of frames in the sequence table ZIP here: viewtopic.php?p=17498#p17498 .
In the document find "Frame tables". The number after "FRAME" is what you need.
Remember that frame numbers are decimal in the document, but you need to enter them in hex into the hex editor.
Took me a little to get the specific action and frame, but got it.
David wrote: July 28th, 2018, 12:27 pm Then we need to get rid of the condition that the prince must be in the left half of the room:
Search: AD 68 04 C9 80
Change 80 to FF
If I get rid of that condition and if he performs the action anywhere else in the room, the shadow will keep getting triggered and maybe go out of bounds which is not what I want (perhaps in another mod would be interesting to toy with this). Is there a way to specify one tile (i.e. 13) where the prince has to be in order to perform said action?
David wrote: July 28th, 2018, 12:27 pm I also found out how to change the shadow's moves, because on first read I misunderstood what you want...
Spoiler: show
Search: 20 B7 92 4C 7A 92
Change to:
a) If you want a standing jump: 20 8E 92 4C 7A 92
(In the original level, the shadow will jump straight into the pit! :) )
b) If you want a jump up: 20 8E 92 4C 8E 92
(It seems I can't make the shadow climb up.)

Alternatively, you can use any two moves (put them after 20 and 4C) from this list:

Code: Select all

925F = release all (nothing)
927A = forward (run)
9283 = back (turn around)
928E = up (jump up) (Use together with "forward" for a standing jump.)
9297 = down (crouch)
92A2 = up+back (jump up)
92A9 = down+back (crouch)
92B0 = down+forward (draw sword)
92B7 = shift (Used together with "forward" for a step in the original game.)
92C0 = release shift (nothing)
(Don't forget to swap the two bytes.)
The relevant part of the disassembly: (for both hacks)
Spoiler: show

Code: Select all

level 9 room 11 shadow close:
01:8C24: ad 62 04    LDA $0462 ; Char.room ; CharScrn
01:8C27: c9 0b       CMP #$0b
01:8C29: d0 14       BNE $8c3f
01:8C2B: ad 67 04    LDA $0467 ; Kid? ; Kid.frame
01:8C2E: c9 2b       CMP #$2b
01:8C30: d0 0d       BNE $8c3f
01:8C32: ad 68 04    LDA $0468 ; Kid.x
01:8C35: c9 80       CMP #$80
01:8C37: b0 06       BCS $8c3f
01:8C39: 20 b7 92    JSR $92b7 ; automove shift
01:8C3C: 4c 7a 92    JMP $927a ; automove forward
Though I originally didn't want the shadow to perform a different action, it made it look more interesting if he did something a little different.

Another couple of things:
Is it possible to have all the shadow sequences on one level (different rooms obviously)? If I put another sequence, the other ones do not occur.
Is it possible that the shadow entrance and battle of Level 15 can occur without a Jaffar trigger?
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: July 28th, 2018, 8:13 pm If I get rid of that condition and if he performs the action anywhere else in the room, the shadow will keep getting triggered and maybe go out of bounds which is not what I want (perhaps in another mod would be interesting to toy with this). Is there a way to specify one tile (i.e. 13) where the prince has to be in order to perform said action?
It's possible to check if the prince is in column 3:
Search: AD 68 04 C9 80 B0 06 (Remember, this is where you changed 80 to FF.)
Change: AD 6B 04 C9 03 D0 06
(You can change the 03 to change the column.)

If you need to check both the row and the column then you can do this instead:
At x8C32 write: 20 F0 FE EA EA D0 06
At xFEF0 write: AD 6B 04 C9 03 D0 05 AD 6C 04 C9 01 60
(03 and 01 are the column and the row. You can change them.)
Shauing wrote: July 28th, 2018, 8:13 pm Is it possible that the shadow entrance and battle of Level 15 can occur without a Jaffar trigger?
Yes:
Search: AD C1 04 F0 3C
Change: AD C1 04 EA EA
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: July 29th, 2018, 7:17 pm
It's possible to check if the prince is in column 3:
Search: AD 68 04 C9 80 B0 06 (Remember, this is where you changed 80 to FF.)
Change: AD 6B 04 C9 03 D0 06
(You can change the 03 to change the column.)

If you need to check both the row and the column then you can do this instead:
At x8C32 write: 20 F0 FE EA EA D0 06
At xFEF0 write: AD 6B 04 C9 03 D0 05 AD 6C 04 C9 01 60
(03 and 01 are the column and the row. You can change them.)
Thank you, just what I was looking for.
Shauing wrote: July 28th, 2018, 8:13 pm Yes:
Search: AD C1 04 F0 3C
Change: AD C1 04 EA EA
It works as long as there is no other shadow sequences on the same level.


I tested several cases of utilizing (or not) the level 15 sequence in combination with other sequences on the same level and this is what I got:

- If I add only the ''Level 7 sequence'':
The shadow doesn't appear on this sequence, and on the shadow fight room, he briefly appears in the air before disappearing.

- If I add only the ''Level 9 sequence'':
This sequence still works though the music stun doesn't. But when the prince reaches the shadow fight room, the shadow does its entrance and the prince pulls his sword out, but the shadow doesn't, thus he doesn't fight.

- If I add both ''Level 7 & 9 sequences'':
The shadow doesn't appear in neither sequence, only briefly in the shadow fight room like the first case.

- If I add the ''mirror jump'' (and with or without) the level 7 & 9 sequences:
The other sequences have the same outcomes as previous combinations, but the mirror successfully appears and can be jumped (I have the hack where every mirror can be jumped plus each one takes 1 HP of damage); after jumping several outcomes can occur depending of how far you are from the mirror, if you turn or not to see the shadow, and if you do, when as well; I will list the common ones that can happen:
1. If the prince is close to the mirror (and either you turn back to him or not), when the shadow turns to see the prince, he will change into combat but will use a transparent fat man combat sprite! He will step back, then towards you, getting across the mirror but never attack, no matter what you do (even putting your sword away; he will push you to either side of the screen and disappear when he reaches the last column on either side). After a few more times of him moving towards you, he will freeze and do nothing else even if you put the sword away.
2. If the prince is far enough from the mirror, he will turn to see him and change into combat with the fat man combat sprite, but only briefly as he puts the sword away and returns to his normal sprites and the sequence continues as normal.
ALTERNATIVE POSSIBILITIES: In both cases, you can look back and reach/get away for him and he might do what I previously wrote, or run towards you, instead of running to the opposite side, and as he gets closer, you change into combat mode and can hit him and beat him in one hit (I have disabled the ''shadow getting hurt or die, hurts you or kills you'' mechanic).

- Without the fight sequence, and only ''mirror jump'', level 7 and 9 sequences:
The mirror jump works and doesn't break off sequence, the level 7 plays the music and the stun occurs but the shadow disappears, and the level 9 sequence doesn't happen at all.

- Without the fight sequence, and only ''mirror jump'' & level 7 sequence:
The mirror jump works without breaking sequence, on the level 7 sequence the shadow appears briefly and then disappears.

- Without the fight sequence, and only ''mirror jump'' & level 9 sequence:
Only the mirror jump works and without breaking sequence.

So yeah, it seems that all shadow sequences cannot occur on the same level, unless there is a hack that can allow this. Is this possible? As I really don't want to have the shadow appear on different levels, or discard sequences undermining the threat that it is him.

There is also one more hack for the shadow I want to know if its possible as well, but it would be a spoiler if I write it here, so I will PM you, David.
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: July 30th, 2018, 5:34 am So yeah, it seems that all shadow sequences cannot occur on the same level, unless there is a hack that can allow this. Is this possible?
I think I figured out why this happens.
The game first compares the current level number with the level number of the first shadow event.
If it doesn't match then it checks the level number of the next shadow event.
However if the level number does match then it next checks the room number, and if the room number doesn't match then it doesn't check the level numbers of the other shadow events, because in the original game these level numbers are all different.
So we need to change what happens if the level number matches but the room number doesn't.

Part 1: Use the X register instead of A for level number comparisons, so they won't get overwritten with the room number.
x8BED: AD -> AE
x8BF0: C9 -> E0
x8BF4: C9 -> E0
x8BF8: C9 -> E0
x8BFC: C9 -> E0

Part 2: If the room number doesn't match then continue with the next level check.
x86BD: D0 41 -> D0 44
x8712: D0 66 -> D0 13
x8736: D0 42 -> D0 14
x8C06: F0 03 -> F0 EE
x8C29: D0 14 -> D0 D1
x8C45: D0 1F -> D0 B1
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: August 5th, 2018, 9:11 am
Part 1: Use the X register instead of A for level number comparisons, so they won't get overwritten with the room number.
x8BED: AD -> AE
x8BF0: C9 -> E0
x8BF4: C9 -> E0
x8BF8: C9 -> E0
x8BFC: C9 -> E0

Part 2: If the room number doesn't match then continue with the next level check.
x86BD: D0 41 -> D0 44
x8712: D0 66 -> D0 13
x8736: D0 42 -> D0 14
x8C06: F0 03 -> F0 EE
x8C29: D0 14 -> D0 D1
x8C45: D0 1F -> D0 B1
Maybe I missed something here, but I changed all the values to what you wrote, and the sequences still don't occur.

EDIT: They don't occur if the mirror appearing and jump sequence occur. If I remove it, then they do occur.
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: August 5th, 2018, 10:42 am Maybe I missed something here, but I changed all the values to what you wrote, and the sequences still don't occur.

EDIT: They don't occur if the mirror appearing and jump sequence occur. If I remove it, then they do occur.
Whoops, I didn't verify what happens if I move the mirror event to the same level as the others.
In my test ROM the prince simply died in any of the shadow event rooms, except for the mirror rooms.

Here is a fix: At x8C06 write F0 03 4C F4 8B.
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: August 5th, 2018, 11:28 am Whoops, I didn't verify what happens if I move the mirror event to the same level as the others.
In my test ROM the prince simply died in any of the shadow event rooms, except for the mirror rooms.

Here is a fix: At x8C06 write F0 03 4C F4 8B.
It works, though the bug where the shadow turns to the prince and changes into transparent fat man combat sprites still occur. If no fix for this is possible, my workaround is to put the mirror more to the right, so that the shadow runs and gets out of the screen before he can stop and turn back.
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: August 5th, 2018, 11:28 am Whoops, I didn't verify what happens if I move the mirror event to the same level as the others.
In my test ROM the prince simply died in any of the shadow event rooms, except for the mirror rooms.

Here is a fix: At x8C06 write F0 03 4C F4 8B.
It works, though the bug where the shadow turns to the prince and changes into transparent fat man combat sprites still occur. If no fix for this is possible, my workaround is to put the mirror more to the right, so that the shadow runs and gets out of the screen before he can stop and turn back.

EDIT: My workaround doesn't work. The shadow doesn't disappear despite being off-screen.

Also, if the prince jumps through other mirrors on the same level, the shadow reappears and the same bug occurs.
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: August 11th, 2018, 8:45 am EDIT: My workaround doesn't work. The shadow doesn't disappear despite being off-screen.
The original code around x8C06 removes the shadow if he has left the mirror room.
Unfortunately it also removes the shadow if he appeared for one of the other events.
This also means that if I just disable his disappearing (as my hack does), then he won't disappear even if he should.
I'm wondering if there is a way to detect that the current shadow came from a mirror.
Post Reply