Language…
10 users online: Apple Boy, Hot Sauce, MellowYouth, River347, SubliminalSiren, Teaser, Terra Branford,  TheJavabrew,  Thomas, Xulon - Guests: 112 - Bots: 118
Users: 68,942 (2,359 active)
Latest user: Shreya219

Inserting .asm Patches with Asar

FundamentalASM PatchesTool-Specific

  • Pages:
  • 1
  • 2
Inserting .asm Patches with Asar
This tutorial aims to teach you how to insert .asm patches. These aren't the same as .bps patches like the ones you use to share and play whole hacks, but rather additions and changes you can make to your game using the ASM programming language, the language the Super Nintendo Entertainment System (SNES) understands.
Of course, that doesn't mean you have to program anything yourself or learn anything complicated just to apply a patch, it's all in the file you downloaded already!

Your job is simply to use a program called Asar to apply the patch to your Super Mario World ROM. It doesn't matter if the ROM is "clean" or not, .asm patches will generally work on any ROM.

What you will need
  • Asar, the program that inserts the patch into our ROM for us
  • An .asm patch -- in this tutorial I will use the Overworld Counters patch as an example, but all patches follow the same principle
  • Your Super Mario World ROM

Extract asar.exe and the patch you downloaded, owcount.asm in this example, to the same folder (say, a "patches" folder in your main hack folder) and place your ROM into the same folder.
You can ignore everything other than asar.exe in Asar's .zip file.

Table of Contents



Step 1) Setting up .asm patches
Before we start, a few explanations about what .asm files are. They're plain text files, they're simply .txt files renamed to .asm.
That being the case, try opening them in your text editor. Do not use a rich text editor like Word or an Office program, any plain text editor like Notepad will work.
To do so, simply double-click it or right-click it and select "Open with...", then select your text editor from the list that shows up and make sure it is set to always open the file with this program.

Open it up and you should see what you can see in the image on the right. A lot of code. It might look cryptic to you if you don't know ASM, but you won't need to mess with any of the vital bits.
The only two things you have to keep in mind are what comments and defines are:
  • A "comment" is that comes after a semi-colon (the ; character), it's not actual code and is just there for you to read. A lot of patches will come with instructions near the top about their usage or what to change if you want to customize it.
    The Overworld Counters patch does not come with any instructions near the top, but instead has a few comments if you look down just a little:

    As you can see, the text after the semi-colons is plain english, it's just commentary.
    This means that if you don't want a specific counter on the overworld you simply delete that entire line, like "JSR OWScore" in the case of the score counter or "JSR OWYICoin" if you don't want any Yoshi Coin counters on your overworld.
  • A "define" is anything that starts with an exclamation mark (the ! character). All these do is create names we can read for addresses or numbers. You will usually see at least a handful of defines near the top of any patch, including this one:

    These will usually be explained further with comments, but as you might be able to guess from just the names here, changing the hexadecimal number after the equals sign (the = character) changes the position of the counter on the overworld screen.
    Leave these values as they are for this patch, since the default positions are already really well placed.
    Other patches will usually have a lot simpler defines, like yes/no options and specific commands to use.


Every patch has its own options and settings, you should always at least open up any patch you download and read the instructions near the top before applying it to your ROM.
If it comes with a readme file, make sure to take a look at those too, else you might run into unforeseen issues. This patch came with one as well, it explains what you can change and gives you some tips should you want to customize it further.

On top of that, there is one very important thing to keep track of in patches: Free RAM. This example patch doesn't use any, but a lot of patches do.
If you open a patch and see a define called "!FreeRAM", "!freeram" or anything like that, make sure it is not the same value as any other patch you have applied to your ROM.
If it IS the same value, open up the SMW RAM Map and search for addresses labelled "Empty" using the CTRL-F keyboard shortcut, one like this:

Look at the box marked in red on the left and replace the "!FreeRAM" value with that. In this case, that would be "!FreeRAM = $0D9C". The last 4 ciphers are enough if the value starts with "$7E", but you will copy the whole thing if it starts with "$7F", for example "!FreeRAM = $7FA000".



All this sounds like a lot at first, but you will see that patches generally work perfectly fine out of the box, without requiring any further changes. Patching will become second nature eventually.



Step 2) The patching process
There are two quick ways to patch individual patches: by double-clicking Asar and through the Command Prompt (cmd).
Generally, using Asar itself is easier and faster and I will explain a method to speed up patching multiple patches at once further below, but knowing how to use Asar in the Command Prompt is good either way.

Patching through Asar
For this method, simply double-click on Asar itself and a black window will pop up, introducing itself as "Asar, by Alcaro" and asking you to enter the patch's name. Write in your patch's filename, in this example that would be "owcount.asm", and hit enter.
Next it will ask you for the name of your ROM. Again, just write in the filename of your hack, like "Super Mario World.smc", "My Hack.smc" or whatever else your own ROM might be titled. Hit enter and squadala, we done.

Make sure that Asar does not throw any errors but instead reports that "Assembling has completed without problems", close the window by pressing any key and boot your ROM up in an emulator to see if the patch did what it promised.

Voila!


Patching through the Command Prompt
This method takes a bit longer, but is good to know should you be more acquainted with the Command Prompt already or if you need to patch multiple patches, since the window will not close by itself and previous commands can be copied back by tapping the Up-Arrow key.
It's a lot more time efficient when you're testing changes in a patch over and over as well, since you can simply tap the Up-Arrow and hit enter to re-patch it each time.

To open the Command Prompt, hold shift while right-clicking on the folder Asar is in. There will be a normally hidden entry in the context menu called "Open command window here". Click it and the Command Prompt will pop up.
To apply a patch from here, type the following and hit enter:
asar.exe "owcount.asm" "My Hack.smc"
@pause

If the patch was applied correctly, there will be no confirmation, but also no errors. It should look like the image to the right.
Now, try hitting the Up-Arrow key in this window. The previous line will be copied again and you can hit enter once more to apply the patch a second time, or a third or fourth time.
You don't have to re-open the Command Prompt window after changing anything in your ROM either, it will only access the ROM the second you hit enter.



Step 3) Keeping track of patches properly
Batch (.bat) Files
Sometimes you may want to insert a lot of patches at once or have to insert multiple patches over and over to test specific settings. It would be really annoying to have to open Asar, enter the patch name and ROM name and close it every single time.
Sometimes you might have to port your hack to a new ROM because of a critical issue that can't be fixed and going through all the effort of doing this a second time is really tedious.
This is where batch files come in handy.

To use batch files, simply create a new text file in your patch folder, right next to Asar. Name it something like "asar.bat", the name is not that important as long as it ends in ".bat".
Make sure you overwrite the .txt file extension, do not name it "asar.bat.txt". Click on "Yes" when it warns you about changing the file extension since that is what we want, and now you've created a batch file successfully. It should change its icon to look like in the image to the right.
All batch files do is run a series of pre-written Command Prompt commands whenever you double-click them. You might be able to guess how this can help you keep track of which patches you have applied to your ROM already.

Right click your .bat file and pick the second option: "Edit".
This will open it up in Notepad. Copy and paste these lines into the file and save it:
asar.exe "owcount.asm" "My Hack.smc"
@pause


From now on, if you double-click your batch file, it will let Asar apply the "owcount.asm" patch to a ROM named "My Hack.smc" in the same folder.
The "@pause" line is simply a command to make the window not close immediately upon finishing the patching process, so you can see whether any errors appeared or whether the patches all applied fine.
Try running the batch file we've written, it should look just like the Command Prompt window, with the only difference being that it closes immediately after pressing any key in it.


To add more patches to this batch file later on, simply right click it, hit "Edit" again and add more lines after the first, like so:
asar.exe "owcount.asm" "My Hack.smc"
asar.exe "another patch.asm" "My Hack.smc"
asar.exe "biggie cheese.asm" "My Hack.smc"
@pause


Should you have to port your hack to a new ROM, you will now have a simple batch file you can click to apply every single patch you had applied to your ROM originally again, with absolutely no hassle involved.

Noting down FreeRAM
As I explained earlier, it is important not to have conflicting "!FreeRAM" defines in your patches, otherwise patches will interfere with each other and start to screw up your hack in often really strange and devastating ways.
To avoid this, I'd advise you to create a .txt file noting down which addresses you've used up, formatted something like this for easier CTRL-F access:
Freeroam Overworld:
$0058

100 Coin Roulette:
$005C

Custom Powerups:
$0DD9
$1926

It is a lot easier to do this as you go than to end up having to check every single patch you've applied to your ROM before every time you want to apply a new one, just to make sure there are no conflicts.

For the record, here is a complete list of all empty FreeRAM in Super Mario World. Make sure to read the comments to be sure it's not used by other common tools already.
Also note how a lot of addresses are multiply bytes in length. This means that that address and the x following addresses are all free; in the case of "$7E0DC3", which is 4 bytes long, that means that addresses "$7E0DC3", "$7E0DC4", "$7E0DC5" and "$7E0DC6" are all free for use as individual FreeRAM addresses.



Frequently Asked Questions
When I try to apply my patch, I get an error about "JMP (something,x)". What do I do?
This is a common issue brought about by an Asar update. Open the .asm file in your text editor and find the line it is complaining about using CTRL-F.
Then add a ".w" after the "JMP", so it looks like this: "JMP.w (something,x)". That should fix it!

I have another question!
If there's anything you need help with regarding this topic, feel free to post a reply about it in this thread and hopefully someone will answer you!
Successfully patched, but the rom crashes/ don't start: my emulator emulates a blackscreen
You'll have to give some more information, like what patch it is you're trying to apply, what exactly you did and whether your ROM is clean.
Your layout has been removed.
Asar gives this error:
Warning: The ROM title appears to be "??????????????????", which looks like garbage. Is this your ROM title? (Note that inproperly answering "yes" will crash your ROM.
I typed in the patch name and ROM name like this:
D:/Lunar Magic/Patches/asarspritetiles.asm
My ROM is modified and its name is not ??????????????.
If your file is an .sfc file you need to change it to .smc

.sfc are headerless. Lunar magic automatically adds a header but doesn't change the extension so asar still thinks it doesn't have a header unless you change it to .smc
If you actually just put in D:/Lunar Magic/Patches/asarspritetiles.asm, then try wrapping that in quotes (""), because the space between Lunar and Magic might mess it up.
Your layout has been removed.
Originally posted by DarkPika_404
Successfully patched, but the rom crashes/ don't start: my emulator emulates a blackscreen

Same exact thing happened to me. I'm using bsnes, and it happened after I added the wall jump patch. Using Windows 7.
I don't know what to put here.

Originally posted by NecrozmaSpin
Same exact thing happened to me. I'm using bsnes, and it happened after I added the wall jump patch. Using Windows 7.

Something is conflicting. Have you installed any other patches? they probably rely on the same freespace area. And it doesn't matter what OS you use, the ROM is nothing but compiled 65816 code.
Hi, I'm a signature!
Hack Thread
Hack Testing Status: Available.
Layout by Koopster.
Tried on a backup, worked fine.
I don't know what to put here.

mod edit: don't quote the entire tutorial

I get an error that says ¨error: Address out of bounds. What do i do?
Make sure that the ROM name is actually correct. That error usually happens when the path to the ROM file you give it doesn't exist.
Your layout has been removed.
how do i patch a xkas patch with Asar?
Just add ;@xkas to the very top of the patch before inserting. So like:
Code
;@xkas
header
lorom

org $008000
; some xkas code or something
so i dont know anything about code so (patch name);@xkas (rom name)
or what
No, you edit the patch file and add that line to the beginning.
OOOOH ok thanks
k so i edited the file and it said it patcht it but wen i went to test it the nintendo presents never popt up and the screen just stayd black heres what i did

;@xkas
header
lorom
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; this part is from Iceguy's Disable Score patch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org $028766
NOP #3

should that have workt?
416: error: A bank border was crossed somewhere prior to this point.
A fatal error was detected while assembling the patch. Assembling aborted. Your ROM has not been modified.
It says that.
Patch is 999.asm
https://www.smwcentral.net/?p=section&a=details&id=6305
I just don't know anymore
Sincerely TheMightyJay


Originally posted by TheMightyJay
416: error: A bank border was crossed somewhere prior to this point.
A fatal error was detected while assembling the patch. Assembling aborted. Your ROM has not been modified.
It says that.
Patch is 999.asm
https://www.smwcentral.net/?p=section&a=details&id=6305
I just don't know anymore


It's a xkas patch, so you have to do 2 things:

1) Put ;@xkas at the top of the patch;
2) You need to set the !Freespace. THe current address, $1FFFF7, is sure to cause bank crossing. So, you'll have to find some freespace in another area. This tool can help you.





Dream team (feed them, please):






It does not work. It always gives me this message.
Warning: The ROM title appears to be "ΦΦÑû}¥²)≡iÖⁿÑùi", which looks like garbage. Is this your ROM title? (Note that inproperly answering "yes" will crash your ROM.)
  • Pages:
  • 1
  • 2

FundamentalASM PatchesTool-Specific