Re: Another map tutorial: How to edit warps

Discuss anything related to hacking ROMs of the Telefang games here.
Post Reply
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Another map tutorial: How to edit warps

Post by Blaziken257 »

I've been meaning to do this for a while, but I forgot to do it until now. If you ever go to Data Crystal, you'll see that I added some information on this already, but I will try to make it easier to understand here.

Warps include any location that takes you from one place to another. This can include staircases, doors, cave entrances, cave exits, teleporters (like the kind in that blue-colored maze), or antenna trees.

This tutorial will show you how to edit these.

First, warp data is always right after the map data (this is a concept I mentioned a while ago) of the map that it's for. That means you can take the offsets of where the map data begins and add hex 40 to them all. And the warp data always ends right before the next map data. Basically, here are offsets for all the warps:

19C0DF-19C0E6 = ???
19C127-19C151 = ???
19C192-19C32F = Overworld Map - Upper left quadrant
19C370-19C50D = Overworld Map - Upper right quadrant
19C54E-19C6F2 = Overworld Map - Lower left quadrant
19C733-19C875 = Overworld Map - Lower right quadrant
19C8B6-19C8FC = Toronko Village Water Station
19C93D-19CBD6 = Marts & Houses
19CC17-19CC79 = Kurinon Village Cave - Floor 1
19CCBA-19CCF9 = Kurinon Village Cave - Floor 2
19CD3A-19CDD4 = Paparuna Lake Laboratory
19CE15-19D00D = Panses Village Cave
19D04E-19D078 = Toripa Antenna Tree Cave - Floor 1
19D0B9-19D0DC = Toripa Antenna Tree Cave - Floor 2
19D11D-19D140 = Toripa Antenna Tree Cave - Floor 3
19D181-19D1A4 = Toripa Antenna Tree Cave - Floor 4
19D1E5-19D1EC = Toripa Antenna Tree Cave - Floor 5
19D22D-19D250 = Peperi Mountain - Floor 1
19D291-19D2DE = Peperi Mountain - Floor 2
19D31F-19D350 = Peperi Mountain - Floor 3
19D391-19D3B4 = Peperi Mountain - Floor 4
19D3F5-19D403 = Peperi Mountain - Floor 5
19D444-19D46E = Kakotos Relic - Floor 1
19D4AF-19D550 = Kakotos Relic - Floor 2
19D591-19D68D = Kakotos Relic - Floor 3
19D6CE-19D7A0 = Kakotos Relic - Floor 4
19D7E1-19D969 = Kakotos Relic - Floor 5
19D9AA-19DA83 = Kakotos Relic - Floor 6
19DAC4-19DB65 = Kakotos Relic - Floor 7
19DBA6-19DC39 = Kakotos Relic - Floor 8
19DC7A-19DC8F = Burion Relic - Floor 1
19DCD0-19DD55 = Burion Relic - Floor 2
19DD96-19DED8 = Burion Relic - Floor 3
19DF19-19DFF2 = Burion Relic - Floor 4
19E033-19E0F0 = Burion Relic - Floor 5
19E131-19E22D = Burion Relic - Floor 6
19E26E-19E301 = Burion Relic - Floor 7
19E342-19E422 = Burion Relic - Floor 8
19E463-19E4E8 = Burion Relic - Floor 9
19E529-19E553 = Human World - Main Area
19E594-19E5A2 = Human World - Antenna Tree
19E5E3-19E5FF = Human World - Unused Buildings
19E640-19E64E = ???
19E68F-19E69D = ???
19E6DE-19E6EC = ???
19E72D-19E73B = ???
19E77C-19E7D0 = Ion Island Cave - Floor 1
19E811-19E86C = Ion Island Cave - Basement 1
19E8AD-19E8EC = Ion Island Cave - Basement 2

Yeah, that's a long list. You'll notice that they are all different lengths. This is because some maps have more warps than others (really long maps have tons of them, especially mazes like the blue maze with all the different symbol teleportation tiles). This also means that they're controlled by pointers -- the pointer table is from 19C000-19C09E. Be careful, this pointer table is for map data, not warp data. Keep that in mind. (Also keep in mind that the warp data is always right after the map data). Also, for some reason, each pointer is three bytes long -- I'm not sure what the first byte of the three is supposed to do, but the next two are just like any other Game Boy pointers.

But what do these bytes mean? Each byte has a different purpose, and follows a specific format. First, each warp is seven bytes long, and follows this format:

aa bb cc dd ee ff gg

Now for the bytes themselves:

aa = The acre that the warp is located in. The position of the acre has no effect on this, just the acre itself. That means if you move this acre to a different part of the map (remember, it's above the warp data), or use the same acre multiple times, it'll still be the same warp. If you do not know this value, there are two ways you can figure it out. The first way is to go to the acre in the game, use VisualBoyAdvance's memory editor, and take the value in address 0xC903 in the game's RAM. The second way is to look at the map data (again, above the warp data) and find it that way. The first way is easier, but the second way is faster if you know what you're doing.

bb = This value is where the warp is on the screen. Basically, this byte tells which 16x16 square on the screen to stand for the warp to take place. It uses this format:
http://img508.imageshack.us/img508/2/tfmapgridto0.png

cc = The location that the warp will take you to. This one is simple, just use this list to find where you want to go:

Code: Select all

00 - ???
01 - ???
02 - Overworld Map - Upper left quadrant
03 - Overworld Map - Upper right quadrant
04 - Overworld Map - Lower left quadrant
05 - Overworld Map - Lower right quadrant
06 - Antenna Tree - Upper left quadrant
07 - Antenna Tree - Upper right quadrant
08 - Antenna Tree - Lower left quadrant
09 - Antenna Tree - Lower right quadrant
0A - Toronko Village Water Station
0B - Mart/House
0C - Kurinon Village Cave - Floor 1
0D - Kurinon Village Cave - Floor 2
0E - Paparuna Lake Laboratory
0F - Panses Village Cave
10 - Toripa Antenna Tree Cave - Floor 1
11 - Toripa Antenna Tree Cave - Floor 2
12 - Toripa Antenna Tree Cave - Floor 3
13 - Toripa Antenna Tree Cave - Floor 4
14 - Toripa Antenna Tree Cave - Floor 5
15 - Peperi Mountain - Floor 1
16 - Peperi Mountain - Floor 2
17 - Peperi Mountain - Floor 3
18 - Peperi Mountain - Floor 4
19 - Peperi Mountain - Floor 5
1A - Kakotos Relic - Floor 1
1B - Kakotos Relic - Floor 2
1C - Kakotos Relic - Floor 3
1D - Kakotos Relic - Floor 4
1E - Kakotos Relic - Floor 5
1F - Kakotos Relic - Floor 6
20 - Kakotos Relic - Floor 7
21 - Kakotos Relic - Floor 8
22 - Burion Relic - Floor 1
23 - Burion Relic - Floor 2
24 - Burion Relic - Floor 3
25 - Burion Relic - Floor 4
26 - Burion Relic - Floor 5
27 - Burion Relic - Floor 6
28 - Burion Relic - Floor 7
29 - Burion Relic - Floor 8
2A - Burion Relic - Floor 9
2B - Human World - Main Area
2C - Human World - Antenna Tree
2D - Human World - Unused Buildings
2E - ???
2F - ???
30 - Room with Second D-Shoot
31 - Room with switch which activates Palm Sea Antenna Tree
32 - Ion Island Cave - Floor 1
33 - Ion Island Cave - Basement 1
34 - Ion Island Cave - Basement 2
You'll also notice that these values happen to be the index numbers for every location. Convenient. Also, you can find this value within the game if you happen to be in the area you want to be and looking up memory address 0xC904 in the game's RAM.

dd = This determines the position (coordinate) on the map that you want to warp to. It follows this format regardless of the map (remember that in the case of the overworld map, it is actually four smaller maps joined together):
http://img214.imageshack.us/img214/9956/tfmapgridqt2.png
This can also be determined by memory address 0xC906 in the game's RAM.

ee = This is the position on the screen that you'll end up on when you warp. This works similar to the second byte, except the difference is this determines where you'll be taken. It uses the same format:
http://img508.imageshack.us/img508/2/tfmapgridto0.png

ff gg = This is the flag. Basically, it has to do with locking some doors. I haven't fully figured this one out. Normal entrances (such as ones in caves, or staircases) seem to almost always use FF FF. Going indoors (such as in marts, or houses of other people or Denjuu) almost always has the flag value 00 0C. Antenna trees are even more confusing; these flags are different with nearly every antenna tree. I guess this is because they all unlock with different events in the game. The weirdest thing is that doors that go to an antenna tree going one way have different flags from doors going the other way. For example, the offsets 19C5BE-19C5CB are gates to the antenna trees going from Toronko to Kurinon. You'll see that these flags are CB 01. However, the gates to the antenna tree going the other way (Kurinon to Toronko) (offsets 19C56A-19C577) have flags CC 01. Weird. Further complicating things is that if you set a flag for a gate to an antenna tree to FF FF, it's always locked, even though this flag is used for other warps that are always unlocked.

-----

Finally, a couple of notes:

- After the last warp in a given map, there is always a byte with value FF at the end. This tells that game that the map has no more warps.
- Only certain tiles are warpable. These include staircases, cave entrances, doorways, gates, antenna trees, teleportation tiles, and I think that's it. Further confusing things is that in some dungeons, the exit tiles look identical to regular tiles, which can be confusing. You cannot use an ordinary floor or wall tile to warp. It won't work. (Keep in mind I didn't make this game.) You can, however, edit contents of an acre so can make warpable tiles wherever you want, which I also mentioned how to do on Data Crystal, and I'll mention how to do THAT soon.

-----

Since you all are probably confused now, let's do a few examples.

First, let's start with one of the exits in Toronko Village Water Station. The first two warps happen to be the exit. Let's just look at one of them since they're almost the same.

This warp is from 19C8B6 to 19C8BC.

The bytes are like this:

4D 47 02 24 43 FF FF

Now let's look at them.

4D = This is the acre where the warp is located. If you look at the map data directly above, you'll see that this is the beginning of the cave, on the very bottom. It'll make a bit more sense if you look at this image:
Image
47 = This is the position on the screen that you have to stand on to warp. As you can see, it's at the bottom of the screen:
Image
02 = This simply tells the game that this warp will take you to the upper-left quadrant of the overworld map.
24 = The warp will take you to the fifth row, fifth column, as shown here:
Image
43 = You'll end up around the center of the screen, right outside the cave:
Image
FF FF = This is the flag used. Since it's a cave exit, it's FF FF.

I was going to do some more examples, but I hope that was enough to make at least a little understandable. But I will do some more later, I promise. This post took me almost two hours to make, so please appreciate it!

P.S. You'll notice that after the warp I just mentioned above, there is another warp right afterwards that is very similar -- the only difference is the second byte (the location of the warp). Since the exit is two tiles long, you need two warps!
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Another map tutorial: How to edit warps

Post by Blaziken257 »

OK, so I figured out how the seemingly random flags work. Basically, unless the flag value is FF FF, this flag is a two-byte little endian bit-wise pointer to a flag in RAM. Confused? Well, starting with RAM address $C500, there are numerous flags for various things in the game, such as treasure chests, antenna trees/other locked doors, Shigeki's abilities, sprites, and so on. Each flag is one bit long. This warp-based flag basically tells the game to look x number of bits after the least significant bit in $C500. For example, if this value was 8, then it would go the bit that is 8 bits after $C500 (which would be the least significant bit in $C501). Of course, it's little endian, so the bytes are reversed first.

Let's look at a couple of examples.

First let's look at the warps for the Antenna Tree from Toronko to Kurinon. These are in bytes 19C5BE-19C5CB:

94 40 08 0C 46 CB 01
94 50 08 0C 56 CB 01


(There are two warps because the gate is two blocks long.) The bolded part is what we're looking at for now. Both of these flags are CB 01. What does this mean? This specifies how many bits after RAM address $C500 that the game will access to check the flag. First, the flag is little endian, so you switch the CB and 01 to get 01 CB. This means that the flag for these warps is $01CB bits after $C500. Basically, the way I find this is to divide this by 8 to find the address, and then take the remainder to find the bit in the byte. $01CB divided by 8 is $39, and $C500 + $39 = $C539. This is the address where the RAM flag is. Now to find the bit, take the remainder of this, which is 3. So the flag is at bit 3 (the least significant bit is considered to be bit 0 here, and to find the correct bit work your way left -- so in this case, the flag we're looking for is the 4th least significant bit, indicated with an x below):

....x...

That means that if the antenna tree from Toronko to Kurinon is unlocked, the 4th least significant bit will be a 1, and you can pass through it. Hooray! (Note that this flag doesn't make it 1 -- another event does that, probably the sprite data when beating Tabasco. This flag only finds the bit and checks it it's 1 or 0.)

Now let's look at the antenna trees from Kurinon to Toronko, located at 19C56A-19C577:


90 40 08 08 46 CC 01
90 50 08 08 56 CC 01


Now the flags are CC 01. So basically:

- Convert these to little endian (so CC 01 will become 01 CC)
- Divide $01CC by 8 to get $39
- Add $39 to $C500 to get $C539. This is the address that the flag is located. (This is the same as the other one!)
- Now take the remainder, which is 4. Count from the right, starting with 0, until you get to 4. The flag is set at the 5th least significant bit, as indicated with an x below:

...x....

If this is 1 in RAM, this gate is unlocked and you can get to Toronko from Kurinon. If this is 0, it will be locked!

Again, this flag doesn't SET the bit -- it just accesses it and checks it. It's other events (again, most likely sprites) that make it 1.

Hope this wasn't too confusing...

Now one thing I still don't get... if FF FF is always unlocked in cave/staircase/etc. entrances, why is it always LOCKED for antenna trees and houses?

And I also still don't understand why they need two separate flags, seeing that as soon as you can go from Toronko to Kurinon, you can go the other way as well...

EDIT: Fixed typo.
User avatar
andwhyisit
Site Admin
Posts: 1197
Joined: Fri Dec 14, 2007 9:24 pm

Re: Another map tutorial: How to edit warps

Post by andwhyisit »

Blaziken257 wrote: And I also still don't understand why they need two separate flags, seeing that as soon as you can go from Toronko to Kurinon, you can go the other way as well...
Efficiency flies out the door with flags. No-one will care too much about someone wasting a few bits of data. :lol:

What does FF FF do?
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Another map tutorial: How to edit warps

Post by Blaziken257 »

FF FF is used for cave entrances, staircases, teleportation tiles, and exits from places inside. They're used in places that don't involve locks. But if you use FF FF for a gate to an antenna tree (and I think for indoor buildings as well), it'll always be locked.
Post Reply