Direction control

Discussions about all other tools (CusPop, SAV/HOF editors) and hex editing.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Direction control

Post by Norbert »

It might be interesting to know the hex changes required to modify direction control.
Note that this is just something that I thought of, not something I plan to actually use myself.
Two things come to mind:
- A way to force the prince to auto-run right, with left/right arrows having no impact.
- A way to make left/right arrows work while floating, to be able to change the floating direction.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Direction control

Post by David »

Norbert wrote: August 29th, 2018, 9:02 am - A way to force the prince to auto-run right, with left/right arrows having no impact.
This is the easier of the two.
search: 80 3E D7 28 00 75 07
change: 75 07 to EB 1C
This changes the keyboard handler, so it won't work in joystick mode.

An alternate hack:

search: 80 3E 25 3D 00 7C 0F
change: 7C 0F to 90 90

search: A0 12 46 F6 D8 A2 12 46 A0 A8 42 88 46 FE A0 88 40 A2 A8 42 8A 46 FE A2 88 40
change: C6 06 12 46 FF C6 06 A8 42 FF C6 06 88 40 00 90 90 90 90 90 90 90 90 90 90 90

This should work in both keyboard and joystick mode, and the prince will run in whichever direction he is facing.
Well, unless you press shift before he starts running.
So instead change to this: C6 06 12 46 FF C6 06 A8 42 FF C6 06 88 40 00 C6 06 C6 4C 00 90 90 90 90 90 90
This will disable shift as well.
Norbert wrote: August 29th, 2018, 9:02 am - A way to make left/right arrows work while floating, to be able to change the floating direction.
This is harder, it would probably be much easier to do this in SDLPoP.
In seg005.c, in the control() function, in the char_action == actions_4_in_freefall branch, you might try to add something.

By the way, the PoP2 Design Bible, on page 145, mentions something similar. Of course it didn't get into the game.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Direction control

Post by Norbert »

David wrote: September 2nd, 2018, 9:09 pmThis is the easier of the two.
Thanks, I'll give this a try.
David wrote: September 2nd, 2018, 9:09 pmThis is harder, it would probably be much easier to do this in SDLPoP.
Oh, now that you mention SDLPoP... I can see how having this as a toggle, plus a way to modify the horizontal float momentum, both in the .ini and menu, might make possible interesting spike-dodging 'float mods'. Maybe one day.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Direction control

Post by Norbert »

David wrote: September 2nd, 2018, 9:09 pm[...] the prince will run in whichever direction he is facing.
Well, unless you press shift before he starts running.
So instead change to this: C6 06 12 46 FF C6 06 A8 42 FF C6 06 88 40 00 C6 06 C6 4C 00 90 90 90 90 90 90
This will disable shift as well.
Pressing the down arrow key will initiate hopping, and also stops the running.
(Just an observation, not a request.)
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Direction control

Post by David »

Norbert wrote: August 29th, 2018, 9:02 am - A way to force the prince to auto-run right, with left/right arrows having no impact.
Funny how the new PoP:Escape mobile game does exactly this. :)
Norbert wrote: October 19th, 2018, 2:51 pm Pressing the down arrow key will initiate hopping, and also stops the running.
I guess I forgot that because you didn't say anything about the down arrow! :)
Thenasty
Sheikh
Sheikh
Posts: 34
Joined: February 27th, 2020, 10:19 pm

Re: Direction control

Post by Thenasty »

is there a way to change the controls in POP1 v1.4 (I have an EXE from CusPop made but no option for controls)

FROM == TO
===========
Up ===> a
Down ===> b
Left ===> c
right ===> d
Shift/Sword ==> enter


What I'm trying to do is to ADD this game in my custom MAME Arcade Cabinet.
Been researching for a week but coming up with nothing.

Thanks
Ed
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Direction control

Post by David »

Thenasty wrote: February 28th, 2020, 5:59 pm is there a way to change the controls in POP1 v1.4 (I have an EXE from CusPop made but no option for controls)
[...]
What I'm trying to do is to ADD this game in my custom MAME Arcade Cabinet.
Would it run PoP in an emulator? Does that emulator or (if there is no emulator) the cabinet really have no way to remap keys?


In case there is really no way to remap the keys otherwise, here is what to hex-edit in PRINCE.EXE:
(These instructions are specific to PoP1 v1.4.)

Most keys are checked this way:

Code: Select all

seg000:15BA 80 3E E9 29	00			 cmp	 key_states_48_up, 0
[...]
seg000:15DD 80 3E F1 29	00			 cmp	 key_states_50_down, 0
[...]
seg000:15E9 80 3E EC 29	00			 cmp	 key_states_4B_left, 0
[...]
seg000:15FE 80 3E EE 29	00			 cmp	 key_states_4D_right, 0
The third byte of each instruction is the scancode of the key in question, plus 0xA1.
(The addition is needed because the key_states array starts at 0x29A1, so for example the state of the up key is stored at 0x29A1+0x48 = 0x29E9.)

To change what keys are used for the four directions, you need to change those third bytes to the scancode of the new key, plus 0xA1.

Namely:

UP to A:
search: 80 3E E9 29 00
change: E9 to 1E+A1 = BF

DOWN to B:
search: 80 3E F1 29 00
change: F1 to 30+A1 = D1

LEFT to C:
search: 80 3E EC 29 00
change: EC to 2E+A1 = CF

RIGHT to D:
search: 80 3E EE 29 00
change: EE to 20+A1 = C1


This method doesn't work for the Shift key, because is checked rather differently:

Code: Select all

seg000:1611 BB 40 00				 mov	 bx, 40h ; '@'
seg000:1614 8E C3				 mov	 es, bx
seg000:1616					 assume	es:nothing
seg000:1616 BB 17 00				 mov	 bx, 17h
seg000:1619 26 80 27 0F				 and	 byte ptr es:[bx], 0Fh
seg000:161D 26 8A 07				 mov	 al, es:[bx]
seg000:1620 24 03				 and	 al, 3
seg000:1622 28 06 8A 4C				 sub	 control_shift,	al
To change what key is used for Shift:
search : BB 40 00 8E C3 BB 17 00 26 80 27 0F 26 8A 07 24 03 28 06 8A 4C
change to: A0 BD 29 F6 D8 A2 8A 4C 90 90 90 90 90 90 90 90 90 90 90 90 90
In this case the second byte in the replacement refers to the new key. Enter is 1C+A1 = BD.
Thenasty
Sheikh
Sheikh
Posts: 34
Joined: February 27th, 2020, 10:19 pm

Re: Direction control

Post by Thenasty »

WOW David, thank you very much.....

Now I can add this in my cab.

Thanks,
Ed
Thenasty
Sheikh
Sheikh
Posts: 34
Joined: February 27th, 2020, 10:19 pm

Re: Direction control

Post by Thenasty »

is it asking to much now for the POP2 also.


I don't need all the fancy keys for the game, it can be disabled.

All I wanted is

Up > a
Down > b
LEFT > c
RIGHT > d
Sword (i think its CTRL in this game) > ENTER
ESC to quit the game right away to DOS PROMPT (in my case Games Menu).

for BONUS addition
Set the MAX LIFE/POTION (instead of the default one) that way I can play it longer.
Set Timer to 360 (instead of the default).


In POP1, I change those BONUS feature here https://www.popot.org/other_useful_tool ... ool=CusPop
and made an EXE and with your CODE, I cahnge the Controls to this EXE (THANK YOU).


Thank Again
Ed
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Direction control

Post by David »

Thenasty wrote: February 29th, 2020, 10:50 pm is it asking to much now for the POP2 also.
Which version of PoP2 do you have?
Namely:
1. What does Alt+V show?
2. What is the size of PRINCE.EXE?

I'm asking this because each version needs different hacks.
Thenasty wrote: February 29th, 2020, 10:50 pm Up > a
Down > b
LEFT > c
RIGHT > d
Sword (i think its CTRL in this game) > ENTER
ESC to quit the game right away to DOS PROMPT (in my case Games Menu).
What key should replace Shift?
You're right that sword is Ctrl in PoP2, but Shift is still used for safe step, hanging, and drinking.
Thenasty
Sheikh
Sheikh
Posts: 34
Joined: February 27th, 2020, 10:19 pm

Re: Direction control

Post by Thenasty »

oh yea some more control needed separately.


SHIFT = f
Ctrl - Enter
Space - 1 (so don't have to wait for the DEMO/STORY to finish when game is started)

POP v1.1
CRC ca455428
259583 Bytes
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Direction control

Post by David »

Here are the hacks for PoP2 v1.1:
(It took me about 3.5 hours to find the hacks, test them, and write this post.)
Thenasty wrote: February 29th, 2020, 10:50 pm Up > a
Down > b
LEFT > c
RIGHT > d
Thenasty wrote: March 9th, 2020, 10:14 pm SHIFT = f
Ctrl - Enter
First we disable the existing functions of the new keys you want to use:

Disable C:
Search: 80 3E 3B 1D 00, change 3B to 0D
Disable D:
Search: 80 3E 2D 1D 00, change 2D to 0D
Disable F:
Search: 80 3E 2E 1D 00, change 2E to 0D

Then we can remap the keys which control the prince:

Up to A:
Search: 80 3E 55 1D 00, change 55 to (0x1E+0x0D=) 2B
Down to B:
Search: 80 3E 5D 1D 00, change 5D to (0x30+0x0D=) 3D
Left to C:
Search: 80 3E 58 1D 00, change 58 to (0x2E+0x0D=) 3B
Right to D:
Search: 80 3E 5A 1D 00, change 5A to (0x20+0x0D=) 2D
Shift (Delete) to F:
Search: 80 3E 60 1D 00, change 60 to (0x21+0x0D=) 2E
Ctrl (Insert) to Enter:
Search: 80 3E 5F 1D 00, change 5F to (0x1C+0x0D=) 29

Note: The last two hacks remap from Delete and Insert, which originally do the same as Shift and Ctrl.
I did this so because Shift and Ctrl are checked in a different way. (Like Shift in PoP1.)
Thenasty wrote: February 29th, 2020, 10:50 pm ESC to quit the game right away to DOS PROMPT (in my case Games Menu).
Quit with Esc:
Search: 83 FE 11 75 0B, change 11 to 1B
(This works only within the game, but not within the intro.)
Thenasty wrote: March 9th, 2020, 10:14 pm Space - 1 (so don't have to wait for the DEMO/STORY to finish when game is started)
I couldn't find how to do this, but Esc will also interrupt the story just like Space.
(Although it's arguably not the best thing to use the same key to interrupt the intro and to quit the game.)

Technical note: Apparently some parts of PoP2 are compressed, but only in v1.1.
This includes the code which checks keypresses during the story.
This means that those parts cannot be easily changed (or even disassembled).
Thenasty wrote: February 29th, 2020, 10:50 pm Set Timer to 360 (instead of the default).
Start with 360 minutes left:
Search: C7 06 D2 5C 4B 00, change 4B 00 to 68 01
Thenasty wrote: February 29th, 2020, 10:50 pm Set the MAX LIFE/POTION (instead of the default one) that way I can play it longer.
I'm not sure what you meant here.
Do you want the prince to start with 12 hit points instead of 3?

Start with 12 hitpoints:
Search: C6 06 71 6B 03, change 03 to 0C
Thenasty
Sheikh
Sheikh
Posts: 34
Joined: February 27th, 2020, 10:19 pm

Re: Direction control

Post by Thenasty »

Wow David you are totally Amazing. Wish I could do what you do. Thanks alot for your TIME and KNOWLEDGE (SMART).

With the Corona Virus Spreading quickly, I have been busy playing this in my Mame Arcade Cabinet.

Prince of Persia everything works great.

Prince of Persia 2 with the help of your patches, I can play it also in the Cabinet.
I just need on more thing disabled, the ALT key. It is causing a problem (cause the way my cabinet controls are setup).

I'm sure there is way to disable that ALT key (hope you can find it) Thanks.
Maybe while your at it, Disable the CTRL key too (just in case).


My other thing is, is there a way for me to learn what you did with this games ? (I wanna try to hack the controls of Karateka)
From the the looks of it, seems that I gonna need alot of Assembler Language ?
Could you give me some pointers ? Thanks a MILLION.

Ed
Thenasty
Sheikh
Sheikh
Posts: 34
Joined: February 27th, 2020, 10:19 pm

Re: Direction control

Post by Thenasty »

you know what David, forget about disabling the ALT & CTRL keys, I'll just re-configure or re-wire my cabinet controls to different keys.

Maybe it's better in the long run for other games conflicting with those keys.

If you can give me some pointers on how (maybe it's hard for me) to hack game just for changing the key from their default values to something else (cause the game has FIXED keys), I'll give it a try.


Thanks Again,
Ed
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: Direction control

Post by Norbert »

David wrote: March 14th, 2020, 7:39 pm(It took me about 3.5 hours to find the hacks, test them, and write this post.)
Wow... :shock:
Post Reply