News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: How (roughly) would I call a subroutine with a button press?  (Read 1001 times)

SPennLUE

  • Jr. Member
  • **
  • Posts: 63
    • View Profile
    • SPennLUE Projects
How (roughly) would I call a subroutine with a button press?
« on: March 12, 2016, 02:22:36 pm »
Arcana is an SNES role-playing game in which just about everything is done through a menu, accessed via the A button.  You know Dragon Warrior/Quest?  Like that.

I think it would be convenient to map the unused controller buttons to a few of the more commonly used functions, such as the map.  So instead of pressing A -> Down -> Down -> A, I could press maybe the X button and call it up immediately.

I am not expecting any specific help (you would first have to familiarize yourself with the ROM's layout, and at that point I may as well ask you to do all the work).  But where would I start?  Would I have to look through the ROM itself, or the memory?  Are there any emulators that can step through processor instructions one at a time?  Has any game been given similar hacks I can use for reference?
English translation - Rockman 2 Neta (PC); Document - Creating PC patchers with NSIS
Available here on RHDN or at my site: http://sites.google.com/site/spennlue/

zonk47

  • Sr. Member
  • ****
  • Posts: 343
    • View Profile
Re: How (roughly) would I call a subroutine with a button press?
« Reply #1 on: March 12, 2016, 02:52:12 pm »
This is simple. Locate the routine you want to call. Then in the game loop insert the button test in question. To find this loop, enter a dungeon and keep stepping until you loop back to where you started. You can put the test/call at any point in this loop that you like (you probably want to put it before the JSR calls).

To make the test/call, just LDA the controller's RAM address and do an AND operation between it and the button mask on the next line. BNZ on the following line to the JSR call in question.
A good slave does not realize he is one; the best slave will not accept that he has become one.

dougeff

  • Sr. Member
  • ****
  • Posts: 359
    • View Profile
Re: How (roughly) would I call a subroutine with a button press?
« Reply #2 on: March 12, 2016, 02:58:17 pm »
I use geiger's tools for snes9x...

http://geigercount.net/crypt/

I recommend staring at the RAM and try to locate where button presses are stored. Then do a trace while you press tge buttons that calls the MAP. Try to see in the trace where it read the button RAM, and where it jumped to.

Now, you'll have to write some new code that reads the RAM where it stored buttons, decide if the X (or whatever) button was pressed, and call the MAP function. And, then hack in a JSR to your code, somewhere in the main game loop.

BTW, the trace function is poorly documented... here's a discussion about how it works...

http://gamehacking.org/vb/threads/5170-Geiger-s-Snes9x-1-43-Trace-Feature-Problems
« Last Edit: March 12, 2016, 03:23:47 pm by dougeff »
nesdoug.com -- blog/tutorial on programming for the NES