Language…
8 users online: Abstract, amie5057,  AmperSam, Burst Man, Dyojenes, monkey03297, twicepipes, UTF - Guests: 146 - Bots: 115
Users: 70,133 (2,545 active)
Latest user: Rmax56

How to set Freespace

This Tutorial covers all the steps needed to successfully set freespace and avert getting blank screen of death
Yes, we already have another tutorial about this. It is however horribly outdated(expects you to use a hex editor even >_<)
And as I was tired of having to retype all of it each and every time someone wondered why their rom crashed after having inserted a patch, I decided to just make a damn tutorial that I could simply link to. <_<


1: introduction to the term 'Freespace'
The below is a small wall of tex that in simple terms explains just what freespace is, and why you need to set it.
If you happen to not give a damn about the explanation, and just want to learn how to set it, jump directly to section 2: How to set Freespace.

Freespace is a row of bytes in the rom file that are not used by game itself(i.e. hey are free for anyone else to use)
You will generally need freespace when you want to create an xkas patch that adds aditional effects to the rom(often not needed if it is just a simple modification or removal of an already existing effect)
freespace is therefore generally used in patches, and it often occurs that several patches use the same freespace. This will crash your rom because once the freespace is used by a patch, it isn't free anymore, and should not be used as freespace in another patch.

Here is a very basic(although somewhat inaccurate) example to show you why several patches can't use the same freespace:

imagine the rom has these freespaces:
A
B
C

And you want to insert the following two patches:
Patch 1[freespace: A]
Patch 2[freespace: A]

First you insert "Patch 1[freespace: A]"
A is now used up and is no longer a freespace
You have now the following freespaces:
B
C

You then insert "Patch 2[freespace: A]". This will make the rom crash because A is not a freespace.

What you have to do is to change "Patch 2[freespace: A]" into "Patch 2[freespace: B]", so the rom won't crash when you insert it.

In reality the freespaces are not slots(like A, B and C), but amounts of bytes.
And patches only use a certain amount of bytes, which differs from patch to patch(one patch might use 40 bytes of freespace, while a second 400)
And if you have a patch hat needs 200 bytes of freespace, and set to a freespace which is 800 bytes large, you will still have 600 bytes of freespace left(which you then can use on another patch)

However, keping track of which freespace you have used, and how many bytes are left in each is a very anoying task to do by hand. Luckily we have the handy tool "Free Space Logger" which does this for us =D

With all that said, lets get over to the important part!


2: How to set Freespace:


Step 1. Download smkdan's "free space logger"(also known as "Slogger") here, and exract the zip to an empty folder.

Step 2. Put the rom you want to patch to in the same folder. It must be a rom that has been edited by Lunar Magic(and preferably expanded to at least 2MB using Lunar expand or a newer version of LM)

Step 3. Drag and drop your rom over 'slogger.exe'. This should generate a text file titled [romname].txt
(alternatively you can use command prompt and input "slogger [romname].smc [minimumsize]", where [minimumsize] desides how large(in bytes) a freespace must be for it to be listed in the text file, but that isn't really necessary)

Step 4. open up the text file. There you should find a list that looks somewhat like this(my list is taken from a 'clean' rom expanded to 2MB):
Code
[directory]
headered
ROM is 0x200000 bytes long

PC offset		LoROM offset		Size

0x0803D8		0x1081D8		0x7E20
0x090200		0x128000		0x8000
0x098200		0x138000		0x8000
0x0A0200		0x148000		0x8000
0x0A8200		0x158000		0x8000
0x0B0200		0x168000		0x8000
0x0B8200		0x178000		0x8000
0x0C0200		0x188000		0x8000
0x0C8200		0x198000		0x8000
(...)

A total of 0x16C818 bytes of free space were found
IMPORTANT: The "LoROM Offset" is what is entered in xkas as free space


Each separate line in this list is a freespace. Each line consists of three attributes, "PC offset", "LoROM offset", and "Size"
The PC offsets are for the specially interested(aka you wont need them if you just want to insert a patch)
The LoROM offsets are, as stated in the text file itself, what we need for the xkas patches
The Size tells you how many bytes the freespace consists of(in hex). This is not really relevant, but you might want to avoid using freespace that has a size below 0x1000

Step 5. Open up the patch you want to insert into your rom, and find the spot where you have to set the freespace
To find such a spot, first search for a "!Freespace = $XXXXXX" or "!FreeROM = $XXXXXX"(note that freespace and freerom are both the same thing)
For example:
Code
!Freespace = $178000

This is usually located near the top of the asm file.
If you cannot find any !Freespace/!FreeROM/SomethingSimilar, try looking in the comments of 'org's(search behind the semicolons(;) that are behind a line that starts with 'org #XXXXXX')
For example
Code
org $2A8000 ; Freespace goes here

or
Code
ORG $XXXXXX ; FreeROM


The six-digit number after the $ is the desired freespace

NB: If the comment behind the org line does not specify that it's a desired freespace, chances are it's not supposed to be freespace, but a modification of a different code found in the rom(thus changing it might make the rom crash)
General rule of the thumb is that desired freespaces in an unedited patch usually end with '8000'

Step 6. Now that you have found the desired freespace, change it to an actual freespace
What you have to do is to look at the Slogger generated list again, and copy one of the LoROM offsets(don't copy the '0x')
In my case, I chose to use
Code
0x098200        0x138000        0x8000

so I copied "138000"
Now change the desired freespace in the patch into the copied one.
For example:
Code
!Freespace = $178000

becomes
Code
!Freespace = $138000


or

Code
org $2A8000 ; Freespace goes here

becomes
Code
org $138000 ; Freespace goes here


Step 7. Save the patch and insert it as usual via xkas(remember to backup your rom)

Step 8. Test the rom and see if the patch works as it should!
If it does, drag and drop it onto Slogger.exe again to update your freespace list(you will notice that it is changed)
If it doesn't work, it means that either:
- You changed something that wasn't a desired freespace, but some other org
- You need to change something else in the patch as well, besides the freespace(usually specified in a readme that comes with the patch)
- The patch is faulty in it self, or it is tool-specific(i.e. it doesn't work with certain versions of LM/Addmusic/etc.)
- Something else I can't think of at the moment <.<
Basically, if the patch still crashes the rom, even after setting the freespace, I suggest asking about it over at the "ASM & Related Topics" subforum

Finally, whenever you want to insert a new patch, follow steps 5-8 again. You get used to doing this very quickly ^-^


Hope this tutorial was of help to you!

~Sind
Great tutorial, but i'm stuck on step 3. How can i drop my ROM over slogger.exe? I don't get it.
Unfortunately, I'm not very active on the site anymore like I was before; I'm mainly on Discord now. Thanks for understanding.
Click & hold the ROM, go to Slogger, hover over it, release click.

Layout by algorithmshark. Additional help by mockingod.

Linkable Links: Youtube Channel - If any of you want me to do hack videos, I will. I cannot guarantee sound, however.

Shadow of A Hero Progress:


Not doing much.
If it says both 'org' and '!FREESPACE' and has values listed for both, does it need two different free space values?
Legacy custom music
A site with a non-useless dislike button
SMW hacking channel

Originally posted by Kaizokoban
If it says both 'org' and '!FREESPACE' and has values listed for both, does it need two different free space values?

I am going to refer to the NB note in my post:
Quote
If the comment behind the org line does not specify that it's a desired freespace, chances are it's not supposed to be freespace, but a modification of a different code found in the rom(thus changing it might make the rom crash)
General rule of the thumb is that desired freespaces in an unedited patch usually end with '8000'

However, I am not certain. And it would be nice if you could show me exactly what the lines say.
Here:
Code
!FREESPACE = $1082E5

org $02D214           ;\ Hijack code and JSL to custom code
JSL CodeStart         ;/


org !FREESPACE

Legacy custom music
A site with a non-useless dislike button
SMW hacking channel

Yes, the first org is indeed not a freespace. that is what I meant with the NB note; if it doesn't say it's a freespace, then it isn't supposed to be one.
just set the !FREESPACE and let the other one be ^-^
Uhh.. I am using the "No Status Bar" patch, and there is nowhere to set freespace? I can't find it anywhere lol
YouTube <-- Let's Plays and stuff.
^ Made by Tahixham
If there is nowhere to set freespace, then it doesn't need any.

I checked, and the "Disable Status Bar" by Nanoha Takamachi, which I am assuming is the one you meant, does indeed not need any freespace. Just patch it as it is.
Do you need to set freespace for HDMA gradients?
In Maxx’s “ASM for Beginners: Basic, Basic Codes in 20 minutes” tutorial here, I got this far:



It should be noted that Maxx’s tutorial is slightly outdated. He uses LevelASM1.4 made by Ersanio (an administrator of SMW Central) instead of uberASM in his tutorial. Though I don’t think the LevelASM1.4 file still exists in SMW Central’s downloads, Ersanio gave me a download link for LevelASM1.4 upon my request, so I tried it, but as I opened my rom in lunar magic, it gave me this pop-up warning message:


and everything seemed fine in lunar magic, level 105, so I closed it and tried testing my rom. And this is what happened:


Followed by a blank-black screen.

That qualifies as a “Crashed Rom”, right? That said, does this “How to set Freespace” tutorial work with uberASM?
Originally posted by 1UPdudes
Do you need to set freespace for HDMA gradients?

No, at least not in levelASM.

@MonkeyMan: It works just like any other freespace setting, except with multiple freespaces, that's all. There's a readme.txt included in the download, it should explain more detailed.
LINKS Twitter | YouTube | SoundCloud | Fortaleza Reznor
to hear birds and see none.
I recommend using asar for patching. It gets rid of the need to find freespace entirely. The only downside is that not every patch exists in Asar's format.
Originally posted by MaxodeX
Originally posted by 1UPdudes
Do you need to set freespace for HDMA gradients?

No, at least not in levelASM.

@MonkeyMan: It works just like any other freespace setting, except with multiple freespaces, that's all. There's a readme.txt included in the download, it should explain more detailed.


The readme.txt warns to not use an old rom. How old is too old? I downloaded my clean SMW rom on Febuary 11, 2011, and it's been working fine.
Just make a backup of your ROM and try it.
LINKS Twitter | YouTube | SoundCloud | Fortaleza Reznor
to hear birds and see none.
Originally posted by Iceguy
I recommend using asar for patching. It gets rid of the need to find freespace entirely. The only downside is that not every patch exists in Asar's format.


Iceguy, I'm going to sit down, and start your ASM tutorial. While I do that, I thought I'd just ask: would "Notepad++ portable" work for writing ASM code as well as just plain Notepad?
Yes. In fact, any good text editor will work.