[REQUEST] Joystick patch for Ys games

Page 2/2
1 |

By donluca

Expert (75)

donluca's picture

18-04-2021, 15:50

You're an absolute legend, thank you so much!

I wonder, if it's not much to ask, if in the future you'd be willing to share a sort of guide or insight in how you manage to produce these patches? I'm really interested.

By pgimeno

Champion (285)

pgimeno's picture

19-04-2021, 00:10

Well, there's no magic to it. I use OpenMSX. Launch the debugger and break into the program while it's waiting for a key. Then trace a bit, to see if it's easy to find the routine that checks for a key. In this case, it was right there after the interrupt, so it was easy. If not, set a breakpoint on the ROM routines used to read keyboard, 0x141 and 0xD8. Possibly 0x9F too. Failing that, set a breakpoint on read of port 0xA9.

Once the method for reading the key is located, you have to figure out how to modify the code so that instead of reading the keyboard, it calls GTTRIG with A=1 to read the joystick, and ensure that it processes the result correctly. In a few cases, the code was calling GTTRIG with A=0. I also found a case where the game did not support joystick because of wrong port directions on PSG register 7, so there's that to watch out for too (in that case you have to fix the port directions as well).

Worst case is that you also need to optimize some neighbouring code, in order to make room for some extra code that you need to add. In practice that's not frequent.

In this case, the code was calling ROM routine 0x141 through an interslot call. I just changed it to 0xD8. It was setting A=8 on call, to read the column with the space bar, so I changed it to A=1. I also had to reverse the test because the keyboard matrix routine (0x141) returns 0 if pressed, and the joystick button read routine (0xD8) returns 0xFF if pressed. That's about it. ISTR that Knight Lore was a bit more complex, but I can't remember the details.

By santiontanon

Paragon (1351)

santiontanon's picture

19-04-2021, 04:18

pgimeno wrote:

Well, there's no magic to it

Pgimeno, you are being too modest here hehe. Patching a game/rom indeed has no secret. But in order to do it, you need to know how to code in assembler, and know/understand the relevant MSX BIOS calls or I/O ports, etc. So, basically, even if at the end of the day is just changing a few bytes in the ROM here and there, it takes quite a lot of knowledge to do it Smile

By pgimeno

Champion (285)

pgimeno's picture

19-04-2021, 10:44

Sorry, I conveyed the wrong idea. What I meant is that there's no magic method or shortcut to do it, that it requires analysing the program.

By donluca

Expert (75)

donluca's picture

19-04-2021, 16:13

Thanks for the insight, it was really interesting and motivating!

Next time I'm confronted with a game that needs a keyboard press to start I'll definitely try myself.
I'm already familiar with the openMSX debugger, so that helps, and your detailed description of what to look for and how to patch it will tell me what to look for and how to change it.

Page 2/2
1 |