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):
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:
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
or
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
so I copied "138000"
Now change the desired freespace in the patch into the copied one.
For example:
becomes
or
becomes
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
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