Touched
Resident ASMAGICIAN
- 625
- Posts
- 10
- Years
- Age 123
- Seen Feb 1, 2018
ASM hacking can be irritating, that's why I'm publishing a build tool. It's a command line tool that makes the process of inserting ASM and writing hooks etc. less annoying and tedious.
Installation
Whatever platform you are on, download and install both devkitARM and Node.js. Windows users might want to restart after this. The devkitARM binaries MUST be in your path (try run arm-none-eabi-as --version in a console to check if it works) in order for this to work.
After doing this, you can now install the tool. Simply run the following command in a console.
NOTE: Linux users might need to use sudo to run this.
Now that your installation is complete, you can run 'asmagix' from the console.
Usage
How this works is that you create a project directory:
You then use the tool to create an empty project for you:
This creates the basic directory structure and configuration file (your asmagixfile).
To start hacking, copy ROMS in to the roms directory. Say you copy firered.gba to the ROM directory. You then would need to alter your asmagixfile.json to read something like:
In reality, these directories can be whatever you want. However the ROM keys are important. They allow you to test on multiple ROMS.
Now that's done, its time to create some source in the source directory.
This is an example stub code. It goes in the src directory. What's important about this file is the line at the top (a comment directive). It tells ASMAGIX to insert this file into free space, then write a hook at offset 0xDEADBEEF that jumps to this code. It uses r1 (that 1 after the offset) to load the address to this code. See README.md for more of these comment directives.
Now we run
As you can see, we use the key specified earlier to tell what ROM to add this code to. If you specified a default key, you can leave this out. This creates a test.gba ROM in your project root which allows you to test it. I will soon allow an emulator to be run automatically after this.
If this command gets annoying, we can do
This command watches for changes to your source files and automatically runs the 'build' task (above) when it sees a change. This saves you having to type that command repeatedly.
A few things to note are that the ROM key (BPRE above) is presented to your code as a constant. This means you can do conditional assembly using the constants.
Now if you run "asmagix build bpre", the "Code for FR" will be assembled, but if you run "asmagix build bpee", the "Code for emerald" will be assembled instead.
Additionally, the parameters to the comment directives can ALSO be ASM constants. This aid the conditional assembly stuff.
This allows you to set conditional hook locations for different ROMS. You can hide those in some include file somewhere if it gets too messy.
If you want ASMAGIX to skip an ASM file, simple add
to the top of your file and this code will be skipped (regardless of whatever other directives are there)
Installation
Whatever platform you are on, download and install both devkitARM and Node.js. Windows users might want to restart after this. The devkitARM binaries MUST be in your path (try run arm-none-eabi-as --version in a console to check if it works) in order for this to work.
After doing this, you can now install the tool. Simply run the following command in a console.
Code:
npm install -g asmagix
Now that your installation is complete, you can run 'asmagix' from the console.
Usage
How this works is that you create a project directory:
Code:
mkdir myProject && cd myProject
You then use the tool to create an empty project for you:
Code:
asmagix init
This creates the basic directory structure and configuration file (your asmagixfile).
To start hacking, copy ROMS in to the roms directory. Say you copy firered.gba to the ROM directory. You then would need to alter your asmagixfile.json to read something like:
Code:
{
"src": "./src",
"roms": {
"bpre": "./roms/firered.gba"
},
"default": "bpre",
"build": "./build"
}
In reality, these directories can be whatever you want. However the ROM keys are important. They allow you to test on multiple ROMS.
Now that's done, its time to create some source in the source directory.
Code:
@@action hook 0xDEADBEEF 1
main:
bx lr
This is an example stub code. It goes in the src directory. What's important about this file is the line at the top (a comment directive). It tells ASMAGIX to insert this file into free space, then write a hook at offset 0xDEADBEEF that jumps to this code. It uses r1 (that 1 after the offset) to load the address to this code. See README.md for more of these comment directives.
Now we run
Code:
asmagix build bpre
As you can see, we use the key specified earlier to tell what ROM to add this code to. If you specified a default key, you can leave this out. This creates a test.gba ROM in your project root which allows you to test it. I will soon allow an emulator to be run automatically after this.
If this command gets annoying, we can do
Code:
asmagix dev bpre
A few things to note are that the ROM key (BPRE above) is presented to your code as a constant. This means you can do conditional assembly using the constants.
Code:
.ifdef BPRE
@ Code for FR
.elseif BPEE
@ Code for emerald
.endif
Now if you run "asmagix build bpre", the "Code for FR" will be assembled, but if you run "asmagix build bpee", the "Code for emerald" will be assembled instead.
Additionally, the parameters to the comment directives can ALSO be ASM constants. This aid the conditional assembly stuff.
Code:
@@action hook HOOK_LOC
.ifdef BPRE
.equ HOOK_LOC 0xDEADBEEF
.elseif BPEE
.equ HOOK_LOC 0xCAFEBABE
.endif
This allows you to set conditional hook locations for different ROMS. You can hide those in some include file somewhere if it gets too messy.
If you want ASMAGIX to skip an ASM file, simple add
Code:
@@ignore