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

Author Topic: Adding code to NES games  (Read 2219 times)

Vaccy

  • Jr. Member
  • **
  • Posts: 21
    • View Profile
Adding code to NES games
« on: August 18, 2016, 09:17:27 am »
NES for example, any system would work I guess.

I'm just curious how someone would add say some ASM code to a NES translation or hack. Not so much what code, but how it's done in general. The few times I messed around with hacking, I kept to hex editing.

Is there a good video or file that shows this? I remember a good one for beginners and hex editing showing how to make small changes in Final Fantasy.

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: Adding code to NES games
« Reply #1 on: August 18, 2016, 10:01:14 am »
The biggest problem (in my experience) is to find available space for your custom ASM, located in a bank currently loaded and available when you need it to be.

Even if a section of the ROM appears to be blank (unused) - there is really no other way of making sure the game functions with that space being empty - except playing through the entire game (preferably a couple of times).

There are basically two ways of creating space (if you aren't lucky enough to find some already confirmed free space):

1. Rewrite the existing ASM/data using less bytes.
2. Erase existing ASM/data and accept the loss of some (preferably unused) functionality/resource.

/dACE

STARWIN

  • Sr. Member
  • ****
  • Posts: 454
    • View Profile
Re: Adding code to NES games
« Reply #2 on: August 18, 2016, 10:06:50 am »
Code is data like any other data in the ROM. You have to change some of the bytes in the ROM (that the CPU can see at the desired point in the game), in order to add the (code) byte sequence you want.

Either you change bytes that are unused, or bytes that already contain code or data (hence breaking that part) - or you make a guess and try writing your code somewhere anyway (and perhaps see if something breaks). I usually prefer not making guesses, but it can make things difficult.

Then you typically write a jump in an existing piece of code that gets executed, that jumps to your new code sequence (and back). It may have to be executed at a specific point during the game execution, and that defines which piece of code you insert your jump to. If you have free space, you can insert your code roughly at any point in the existing execution flow because you can always move a few instructions of the original code to the new place, in order to get room for the jump itself.

You can use a hex editor and write the code (as hex values = machine code) yourself or you can use an assembler that translates your asm mnemonics into machine code. The assembler may just output a blob of hex that you insert yourself, or it can do that for you as well if you tell it where to output the values (depending on assembler).

You don't typically add anything to the hack (as a patch file) itself, but you modify the patched ROM just like you would modify any unpatched ROM. You can always make a new patch from any differences anyway.

nesrocks

  • Hero Member
  • *****
  • Posts: 691
    • View Profile
    • nesrocks.com
Re: Adding code to NES games
« Reply #3 on: August 18, 2016, 11:27:49 am »
This sounds a lot like this thread, and they may be additional to each other: http://www.romhacking.net/forum/index.php/topic,22500.0.html

Vaccy

  • Jr. Member
  • **
  • Posts: 21
    • View Profile
Re: Adding code to NES games
« Reply #4 on: August 18, 2016, 04:02:53 pm »
This sounds a lot like this thread, and they may be additional to each other: http://www.romhacking.net/forum/index.php/topic,22500.0.html

Perfect! This post here definitely got the message across.

http://www.romhacking.net/forum/index.php/topic,22500.msg315858.html#msg315858

Thanks!