any way to change controls of functions

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
kelvin donna
Posts: 70
Joined: Sat Feb 01, 2020 5:49 am

any way to change controls of functions

Post by kelvin donna »

hello,
i wanted to map the start game function for some Waixing or Nice code nes games to the select button, is there any way to do it via the hex editor?
thank you in advance.
User avatar
Ben Boldt
Posts: 1149
Joined: Tue Mar 22, 2016 8:27 pm
Location: Minnesota, USA

Re: any way to change controls of functions

Post by Ben Boldt »

Welcome back kelvin. It has been a long time since we heard from you.

You can use a debugger to find where the game reads the controller registers. The register reads 1 bit at a time from the controller. Most games shift these bits into a variable. Often times, the game will do it twice in a row due to a DMA bug in the CPU.

Once the game has built up its pressed-button variable, it checks each bit for each button. It is likely you will be able to easily swap the start bit with the select bit this way. If you have a specific game in mind, we can give you a step-by-step how to do all of this for 1 game, so that you can do it yourself for all games that you want.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: any way to change controls of functions

Post by rainwarrior »

I don't recommend trying to do it with only a hex editor... but if you want a really quick and messy way to look for it, here's an idea.

The most common way to deal with a controller input is with an immediate AND instruction to test a bit corresponding a button, and then either BEQ or BNE to do something based on whether it's pressed.

Depending on whether they read bits leftward or rightward, START would usually be $10 or $08. To replace it with SELECT, it would be $20 or $04 correspondingly.

So, you could search for these 4 hex strings, and see if any of them do the trick:

Code: Select all

29 10 F0 - AND #$10 BEQ
29 10 D0 - AND #$10 BNE
29 08 F0 - AND #$08 BEQ
29 08 D0 - AND #$08 BNE

A  B  Se St Up Dn Le Ri
-- -- -- -- -- -- -- --
80 40 20 10 08 04 02 01 - leftward
01 02 04 08 10 20 40 80 - rightward
These 4 strings are by no means the only way to detect a button, but they are the most common way. Usually games have separate code for different menus and gameplay modes, so you would typically find one of these in the ROM for each one.

Also, with a hex editor, you won't be able to tell very well if one of these is for some other purpose rather than being a START button test. It's quite possible you will corrupt some other important code by accident. Try them one at a time, and test it. If it doesn't exactly change START to SELECT for a single menu/gameplay situation, put it back before you try the next one.


If you want to do a more thorough job, use a debugger, put a breakpoint on reads to $4016, look at the code that reads it and see where it stores the result. Then put a breakpoint on reads to that resulting variable... look for those until you find one using its value with AND or BIT, try putting a breakpoint on the relevant code, eventually you should have a breakpoint that you can make hit by pressing START on your controller.
User avatar
Individualised
Posts: 310
Joined: Mon Sep 05, 2022 6:46 am

Re: any way to change controls of functions

Post by Individualised »

Seeing as it's Nice Code we're talking about I wouldn't be surprised if the control reading routine is overly obscure/way too bloated for an NES game and not done like any other non-Nice Code game.
Post Reply