Romhacking.net

Romhacking => Programming => Topic started by: Yakibomb on November 05, 2017, 06:25:37 PM

Title: ASM Compiler? Help with spaghetti code problem
Post by: Yakibomb on November 05, 2017, 06:25:37 PM
Hello! I'm working on a hack for a Super NES game (Super Mario RPG). I've documented and added a lot of different things to one area in the ROM, but now it's become a huge JSR/JMP spaghetti-code fiesta and it's hard to figure out what each thing does and where.

Is there any program or tool to help organize the code? I've looked around but have had no luck.
Title: Re: ASM Compiler? Help with spaghetti code problem
Post by: jonk on November 05, 2017, 09:10:30 PM
Quote from: Yakibomb on November 05, 2017, 06:25:37 PM
Hello! I'm working on a hack for a Super NES game (Super Mario RPG). I've documented and added a lot of different things to one area in the ROM, but now it's become a huge JSR/JMP spaghetti-code fiesta and it's hard to figure out what each thing does and where.

Is there any program or tool to help organize the code? I've looked around but have had no luck.
I've written a few modest tools to help out with exactly this kind of thing. My son is making lots of code hacks to some SNES games and, of course, some prior subroutines need substantial expansion and more room which wasn't present there. So he either had to hack in a JMP/JSR into the existing routine, which transferred to his own code placed in some "blank areas" or else just completely replace all the call addresses to his new address and just write the code there (which meant that the old code location was now a "hole" that might be used for something else.)

So part of what I did was to modify an existing assembler and linker tool so that it supported creating and naming regions within the ROM (and it supports overlapped memory just fine in cases where memory is banked.) Now, he just writes assembly code in text files. The assembler generates the output, examines the mapping information, and then automatically locates the code as appropriate and patches the ROM (the tool will first copy the earlier ROM so that he doesn't lose the original.) All he does is "run the assembler" and the new ROM file is ready to go without any other tool use. It's directly patched. Just load and go, to test.

Don't know if that's what you are looking for, or if perhaps I misunderstood. But something like that? Or what did I miss?
Title: Re: ASM Compiler? Help with spaghetti code problem
Post by: pianohombre on November 09, 2017, 02:52:18 PM
Just put all the new assembly in an ASM file and link it using an assembler like Asar. You can use labels in the program next to the jumps (which the linker replaces with memory addresses). Then, you can comment the code using semi-colons so it will be nice and tidy.