Zelda Hacking: Editing Caves

Warp Caves

In The Legend of Zelda, there are four “warp caves” that connect to each other, allowing the player to quickly traverse the overworld. If you try to move these warp caves with Zelda Tech, you’ll discover that either the player will still be warped to one of the original warp cave locations, or, more likely, the game will freeze.

To fix this, open the ROM in a hex editor and go to the offset $19344. There will be four “screen IDs” listed there. These are the locations the warp caves will bring you to. The values specify a map location, where the first digit is the Y coordinate and the second digit is the X coordinate (0, 0 being the top-left corner of the map). For example, $49 would be the fifth screen down, tenth to the right.

If a warp cave is not in the list and you try to warp through it, the game will freeze.

Cave Contents

Zelda Tech allows editing which items appear in each of the four shops, but it is actually pretty easy to more extensively modify what’s inside any cave type. There are four relevant data tables in the ROM, each of which has 20 entries, one for each cave type.

In typical Zelda fashion, each data table has extra information crammed in the unused bits. There are some bits whose purpose hasn’t been completely deciphered. Even though every bit contains data, some bits may not actually be used (this could be determined with a debugger). It may be that these bits were originally used, but they ended up hardcoding behavior for certain cave types.

$045b2 - String ID    (1 byte per cave)
$1861C - Item list    (3 bytes per cave)
$18658 - Item prices  (3 bytes per cave)
$06E7F - Cave dweller (1 byte per cave)

String ID

The string ID table contains one byte for each cave type. The bits of each byte have the following meaning (high bit first).

MGSS SSSS

M ($80) is a mystery. It is set for shops, potion shops, and pay-for-info caves. G ($40) appears to specify whether the player can get items. If G is set, the player can get items in the cave, even if they aren’t shown. SSSSSS ($3F) is an even number between 0 and 62 that specifies which string is shown in the cave. ‘0’ shows the text “IT’S DANGEROUS TO GO ALONE! TAKE THIS!”, ‘2’ shows “MASTER USING IT AND YOU CAN HAVE THIS”, and so on.

Item List

The item list contains three bytes per screen, whose bits have the following meaning (high bit first).

byte 1:  NMaa aaaa
byte 2:  HTbb bbbb
byte 2:  PIcc cccc

aaaaaa, bbbbbb, and cccccc specify the items in the cave and have a value from 0 to 63 (0 = bombs, 1 = sword, etc.). For certain cave types such as secret-money caves, a rupee is shown, but this is for display only. Any item can be placed in these caves and the player will still receive rupees when he touches the item.

N ($80) specifies that prices, if shown, will be negative, such as in pay-for-info caves. M ($40) is set for the white sword and the magic sword. When M is set, the player must have enough heart containers to get the item. The number of hearts needed appears to be 12 for all cave types except cave type 2 (white sword), which requires five hearts.

H ($80) is set for the gambling game and secret money. Clearing it in the secret-money caves causes the player to get and hold up the item instead of receiving free rupees. T ($40) is set for pay-for-info caves.

P ($80) specifies whether prices are shown, and I ($40) specifies whether items are shown.

Item Prices

This one is easy. There are three bytes per screen, each specifying the price for the item.

Cave Dweller

This one is also pretty easy. One byte for each screen that identifies which sprite to show for the person that inhabits the cave. $58 is for the old man, $59 the old woman, $5A the merchant, and $5B the moblin.

Leave a comment

2 Comments.

  1. I’m a bit noob when it comes to rom addresses because they are in different formats in different contexts. I use a regular hex editor (HxD) and in that one my zelda rom goes from 0-20010, (or is it $0-@20010?) When I search for the addresses mentioned above, the correct values seem to be 27 bytes ahead in my hex editor. Why is this?

  2. Nevermind, I got it now ^^

Leave a Reply

Your email address will not be published. Required fields are marked *