Inserting Routines into your ROM
This is not exactly the same as my normal ASM resources. Instead of a routine I have a mini-tutorial. This has been covered in a lot of other ASM tutorials, but I'm just going to go over inserting routines into your ROM in general (and hopefully in detail). I've just been getting a large amount of PMs and VMs regarding this, so I thought it was about time I write a small guide.
This guide may seem like a large amount of work, but all the steps take me about 10 seconds to do. Literally 10 seconds.
Before we start you will need the following tools:
- This thumb compiler (
http://www.mediafire.com/download/bxzzfe543qq7697/Compiler.rar)
- Hex editor (I use
ftp://wa651f4:[email protected]/HxDSetupEN.zip)
- Some knowledge of how to use the command line/a computer in general
Setting up your routine for compilation
1) Make a separate folder somewhere and put the thumb compiler you downloaded in the first post. into this folder. In this example I make a folder on my Desktop called ASM, and inside that folder I have my thumb compiler.
2) Now open your routine inside a word processor. I use notepad (thought you should use notepad ++ or something similar). Save the file as Name.asm and move it into the folder containing the compiler. I'm going to be using my "Average Level" routine because I have to test it still, and this is a good opportunity to do that!
You've now set up the files in a needed matter to assemble your routine!
Compiling the routine:
Before I begin, if you're running a windows machine (Windows 7, Vista, XP (maybe 8 works, I'm not sure)), you don't need to read this part of the tutorial. Skip to the
Windows-compile section of this tutorial.
1) Open the start menu and open your command line. In Windows this is cmd, most other operating systems call it the Terminal. Whatever you call it, open it! It should be a black or dark purple box depending on the OS you're using.
2) We need to navigate to our folder containing the compiler and our ASM Routine! To do we use the cd command (short for change directory). You can find the directory of the file you're using if you navigate to it and click the directory browser.
Here's a picture of what I'm talking about
:
3) We will insert into the command line "cd \file\path" where these words file path are the names of the folders we have to go through to reach our routine. In my case the filepath to the folder containing the routine and compiler was C:\Users\Guest\Desktop\ASM. My command line is currently on:
So I will type in:
Hit Enter/return when you're done.
It looks like this:
4) Run the compiler on the Routine. The line to do this is simply:
Code:
thumb filename.asm outputFileName.bin
The only thing here that will remain the same for you is the word "thumb" as that is the name as the.bat file. The following file names after the word "thumb" are not case sensitive and the outputFileName.asm is actually optional. If you don't specify an output file, the compiler is smart enough to make one with the same name as the input file, but with a .bin extension.
So all you really need to type in the end is:
In my case I named my file AverageLevel.asm. So I would type, obviously:
5)If the routine you compiled, is error free, it will say "Assembled Successfully"
Windows Compile:
If you're not running a Windows machine, this doesn't apply to you (maybe it does, I haven't confirmed :P). Feel free to skip to the next section.
1)Drag your .ASM file into your thumb.bat file. It will look like this:
2) If your .ASM file doesn't have any errors a new File with the same name but with a .bin extension will be created. If a .bin file isn't created than the file you're trying to compile has an error. Go back to the "Compiling your Routine" section and do it manually to find the error.
Inserting the compile Routine into the ROM!
1) Open both the ROM and the .bin File inside a hex editor. Remember, you want the .bin file which was created in the compilation process, not the .asm file.
2) Copy the contents the hex editor gives for your .bin file
3) Find some free space in the ROM (denoted by 0xFF) and insert there the .bin file's hex form. In HxD you simply ctrl+c the bin file's hex, then at the free space in the ROM do ctrl +B.
4) You need to make sure the address you insert the routine in is divisible by 4. The simple way to ensure this is to make sure that the address ends in 0, 4, 8 or C. In my case I will insert the routine in 00720000.
Running the Rountine from your ROM.
In your script have "callasm 0xRoutineAddress +1".
So if I had inserted my routine at 0x720000, I would have the command "callasm 0x720001". That's all there is to compiling and using ASM routines.
If you still don't understand, I would advise you to go and play outside instead :)