Blog Info: These blog posts are supposed to take you about an hour to do, and me about three hours to write. That proved to be a gross underestimation –the prototype ROM for this post alone took at least three hours, and writing up step-by-step instructions has taken a few hours too. But I think we really accomplish something in this post.
Back-story: We decided in the last post to modify Zelda3 to make the bow-and-arrow the primary weapon for the first part of the game. But how do we actually go about doing this? And, how can we make the first part of the castle more challenging for advanced players? An arrow-related puzzle is in order! But this means we’ll have to start learning how to use (shudder) the Dungeon Editor. (There is no Dragon Editor).
Goal: Become proficient in using the Dungeon Editor, remove the sword, add the bow, and modify the first dungeon room you fall into to require the clever use of arrows to exit.
Step 1: Understanding Backups
Open a clean copy of Zelda3 in Hyrule Magic. Make SURE this is a copy, because I’m going to show you how simple it is to permanently muck it up. Expand “Dungeons” and click “Starting Location 03”, then click on the “More” button at the bottom of the dungeon screen (near “Starting Location”). See the radio button for “Upper Left”, next to “Horizontal Scroll”? Click that:
…and then click “Ok” and save. Start the ROM…. and notice that it crashes after the name select screen. Ok, go back to the “More” button and change the setting back to “Upper Right”. Save, start the ROM…. it’s still failing to work.
With one simple click, we have irreversibly corrupted our ROM. Sure, you can try to HEX it back to the status quo, but that could take hours. A better solution is to keep regular backups, and to do your most dangerous fiddling directly after you backup. Really, I’m not kidding when I say that you need to back up your working ROM far more often than usual.
Step 2: Understanding the Dungeon Editor
Open a clean copy of the Zelda3 ROM in Hyrule Magic. It’s time to play around with the dungeon editor. Open an MP3 player, too, for your sanity.
Expand the “Dungeons” tab and browse down to “Starting Location 04”. Double-click, and you should see a familiar room: the entrance to the sewers. In the top-left corner of the window it says “Room 81”. Next to this are some arrows to switch to the next room in each of the four directions. Finally, there is a “Jump” button which allows you to go immediately to a room by number. Click on the arrows a few times to see where it takes you, and then click on “Jump”, type in “81” and hit “Ok”. You’re now back at the throne room.
Close the dungeon view and scroll down to “Entrance 32” & open it. This is the room you fall into after pulling up that bush outside the castle. Actually, that’s somewhat inaccurate. This entrance only takes effect when you walk out of and then back into this room. It is the same room as the one you fall into (and the one you start from after saving) but depending on how you enter the room determines a number of minor things like where the camera starts. It’s important to remember this when you edit certain properties of this entrance. Make sure you always access it by double-clicking “Entrance 32”, unless I tell you to click “Starting Location 03”.
Look at the box in the lower-right corner of the Dungeon Window. There are several options:
- “1” – Layer 1 is where we do most of our editing. Doors can go here, too. Treasure chests often are placed here.
- “2” – Layer 2 is required for some editing tricks (like bridges) –I won’t be using it here. Doors can also be placed here.
- “3” – Pretty much only doors can go here. We’ll use this layer to make an entrance leading outside –that door has to go on this layer.
- “Sprite” – Things like enemies, crystal switches, and NPCs go here.
- “Item” – Items that can be placed on the ground or in pots go here.
- “Block” – This setting lets you organize your pushable blocks. We won’t be using this.
- “Torch” – This setting is for torches. We won’t use this, except to delete one torch.
Click on “1”, and then look for the corner jutting out on the left side of the watery place where you land. When you click on it, you will see the following information displayed in the lower-right:
Right-click on this object, and choose “Remove”. You’ve successfully deleted the corner.
Now click on the piece directly south of the one you deleted. Click & drag it left until its X co-ordinate reads “2A”. Now move the mouse over the top edge of the same piece and click+drag to “extend” it until its “Size” reads “03”.
Unfortunately, the piece we moved is now under another piece. So, left-click on it, and then press “Ctrl+V” to bring it to the front. (Ctrl+B brings it to the back).
Right-click anywhere and choose “Insert an Object”. Scroll up to object 108, click it, and choose “Ok”.
It will appear roughly where you right-clicked; drag it to 2A,0B. Makes a nice corner, doesn’t it?
Congratulations, we’ve made our first real change to the room! Save.
We can describe what you just did using a simple table:
|wall||x:2D y:15||x:2A y:0F size:3 front|
|wall||—||obj:108 x:2A y:0B front|
That means “Delete object at location 2D,11”, then “Take object at 2D,15, move it to 2A,0F, resize it to 3 units, and bring it to the front”, then “Add a new object of type 108 at 2A,0B and bring it to the front”. It’s important that you understand this syntax; we’ll be modifying a lot of objects, and it would be horribly cruel to describe each one with a paragraph.
The “Comment” column is an informal addition to help you keep your place.
A note about resizing is in order. Sometimes, when you place a piece down (particularly one that stretches vertically) the piece will stretch to fill up all available vertical space. Please note that you can still resize it, you just have to grab the handle at the bottom and drag it all the way to the top. This is annoying, but not insurmountable.
Step3: Enabling The Bow
Back in Entrance 32, click on the “Sprites” radio button, then click on “Priest/Uncle”. Then, right-click on him, and choose “Remove”. Our Uncle will now no longer be there to give us the sword.
Close Entrance 32 and open Entrance 00. Click once on the chest with the lantern. You’ll see the word “Lamp” under the “Obj” section of the window. Press “+” (or “\”) to scroll through the list of possible treasure chests until you reach “Bow” (do not choose “Bow&Arrow” –it won’t display a message when you take it.) Then change the editing mode to “Item” and click on each heart, then using “N”, “M”, “J”, and “K” to switch the item to “Arrows”. Save.
Link now has access to the bow, 15 arrows, and not much else. Play through your game a bit, and you’ll notice that arrows are a bit hard to come by. Also, we’re stuck in the basement, due to that wall we placed in the last section. We’ll change that next.
Step 4: A Complete Roomlet
Modify the following in Entrance 32. Note that the “size” I specify might require you to stretch the component horizontally, vertically, or both.
|lights||x:1A y:09||size: 00|
|lights||x:1A y:15||size: 00|
|lights||x:2F y:25||x:30 y:09|
|lights||—||obj:80 x:3B y:11 front|
|wall||x:2A y:14||x:27 y:14|
|wall||x:18 y:09||x:25 y:14 size:01|
|wall||x:2A y:18||x:27 y:18|
|cement||x:28 y:18||x:26 y:18 back|
|wall||x:2A y:1A||x:27 y:1A|
|wall||x:2D y:17||x:2A y:16 front|
|wall||x:31 y:17||x:31 y:16 size:00|
|stairs||—||obj:F9D x:2E y:16 front|
|wall||—||obj:113 x:33 y:16 back|
|wall||—||obj:004 x:33 y:17 size:01 back|
|water||x:30 y:0F||x:2E y:0F|
|water||—||obj:0C8 x:36 y:0F size:01 back|
|edge||x:30 y:0F||x:2D y:0F size:06 front|
|edge||x:30 y:0E||x:2D y:0E size:08 front|
|edge||—||obj:044 x:2D y:16 size:06 front|
|edge||x:30 y:17||x:35 y:17 size:00|
Here’s what it looks like after you’re finished:
You’ve learned a lot about from this, I hope. For example, you’ve learned that tiles can overlay like crazy, and the movement rules are determined in a very sensible, visible fashion. (This becomes less intuitive once you start using two layers). You may have also learned that if you left click on an object, then right-click and choose “Add Object”, the default object will be the type of the first object you clicked on. This makes it really easy to insert a new tile if you can see a similar one on-screen. It’s a real time-saver.
Step 5: Doors and Staircases
We now move on to one of the most difficult parts of dugeon editing: doors and staircases. Actually, that’s a lie: everything’s amazingly difficult. But doors (and staircases) require actual explaining, not just hex mangling, to really understand the concept. And then there’s that mind-numbing number pad “feature”, which I consider to be pure evil.
Backup your ROM and open the working copy in Hyrule Magic. (We can switch to Windows for a while, yes?) Now, click on layer 3 in “Edit”, and then right-click and choose “insert a door”. Scroll up to door 000, click on it, and click “Ok”.
Now, left-click on the door you just placed. This is where Hyrule Magic gets evil. You need to press the arrow keys on the number keypad in order to move the door around. The regular arrow keys won’t work. (On a laptop, you’ll have to use the function key, probably). In my opinion, this is a pure sin of interface design —why would you ever assign different functionality to these two sets of keys. Even Ctrl+Arrow is a better solution.
Press the right arrow until the “Pos” of your new door reads “8”. This may look a bit odd for now, but we’ll fix that later.
You can also add this door on layer 1. However, if you do that, the door on the left might disappear; you can manually add it back (it’s door type 001, but we’ll change that later.) A bigger problem is what happens if the entrance door disappears. If that is the case, you have to re-add it —and it can only be added to layer 3. Also, there are two doors which must be stacked to enforce the entrance. Do the following:
- First put down door type 02A and align it over where the exit was.
- Then, put down door type 033 and move it directly over the door you just placed.
- Now save. Your entrance functionality should have been restored. If not, make sure that you placed both doors on layer 3.
Now that you’ve fixed the entrance (or maybe you were lucky and didn’t have to) you should add another door, of type 016, and move it to position 7. Finally, click on the left-most door (the one that was already there) and move it to position 6. Right-click on it, select “choose an object”, and change it to object 000.
I recommend keeping all doors in layer 3, but it’s up to you. Either way, save your game.
Our staircase, by the way, already works. If you look at the very southern part of the room, you can see that we have to climb a staircase before exiting the “Dungeon”. This implies that you enter the dungeon on the “ground level”. In reality, though, staircases usually work so long as you place the start and end bits on valid walkable ground. (In case you haven’t figured it out yet, the “depth” in Zelda3 is just an illusion.) I don’t know enough about Zelda3 to know if you can just keep chaining staircases onto each other, but I’m going to try to stay consistent with the game until I feel adventurous. So, when I put that staircase in our small confined room, I knew that meant I was going to delete the other one.
Do that now: edit plane 1 and right-click on the staircase at 0E,34. Choose “Remove”. Save. We’ll fix the layout later.
Step 6: An Arrow Puzzle
We want to spice up our first Entrance with an arrow-only puzzle. My idea is to have a crystal switch the player sees as he falls in from the garden, and then have him walk around to the far door, then shoot an arrow over the gap at the crystal switch. The middle door is a red herring; there’s no way to get the big key yet. Maybe we can put a treasure chest there to reward the player later when he actually gets the big key.
Perform the following actions:
|wall||x:14 y:14||x:22 y:14 front|
|wall||x:14 y:18||x:22 y:18|
|wall||x:14 y:1A||x:22 y:1A|
|wall||x:15 y:11||x:18 y:18 size:00|
|wall||x:11 y:17||x:19 y:18|
|wall||x:0B y:17||x:14 y:18|
|light||x:1A y:15||x:17 y:1B|
|wall||x:11 y:15||x:19 y:0E size:04|
|wall||x:0B y:0F||x:14 y:0E size:04|
|wall||x:0B y:0B||x:14 y:0B front|
|wall||x:0F y:0B||x:18 y:0B size:00 front|
|wall||x:2F y:0B||x:2D y:0B size:04|
|wall||—||obj:10A x:19 y:0B front|
|light||x:1A y:09||x:17 y:09|
|barrier||—||obj:069 x:13 y:0B size:0C|
|barrier||—||obj:069 x:1D y:0B size:0C|
|barrier||—||obj:069 x:29 y:0B size:00|
|barrier||—||obj:069 x:29 y:11 size:00|
|edge||—||obj:79 x:17 y:0F size:08 front|
|edge||—||obj:7A x:19 y:0F size:08 front|
|edge||—||obj:3F x:17 y:0E size:00 front|
|edge||—||obj:40 x:17 y:18 size:00 front|
|water||—||obj:0C8 x:17 y:0E size:02 back|
|treasure||x:30 y:2C||obj:F99 x:22 y:0C Item: 73:sword 1 front|
Switch to “Sprite” mode, right-click and choose “Insert an enemy”. Choose “PegSwitch” and click Ok. Put this one at x:24 y:0C. Repeat, and place the second one at x:20 y:0C. Then, right-click on each of the “Knight” sprites below and choose “Remove”. Now Save.
We’re beginning to get a feel for this dungeon: the player drops in, sees a switch, learns there’s no way he’s getting the big key, and then decides to hit the switch from the other side. Whew, what a lot of work! However, if you load the ROM in zsnes, you’ll notice a problem immediately:
The problem is, all the enemies on one “level” use the same palette. The crystal switch is considered an enemy, so right now it is using a palette with nulled-out colors. Looking at the Perfect Guide, you can see that several palettes use PegSwitch: 15, 27, 26 and 10, to name a few. Open your ROM and change the “EnemyBlk” to “10”. Sometimes you’ll have to pair a palette up with a “blockset”. Eventually, you should be able to create custom groupings of blocks and colors for use in your dungeons.
By the way, change the “Blockset” from “16” to “1”. It’s not necessary, but it makes things look a lot more regal:
Step 7: Finishing Up the Arrow Puzzle
We need to edit the lower half of Entrance 32. We could simply render it as a big square, with some blue crystal blocks impeding our exit. But that’s boring, and will make our audience groan for its lack of creativity. Let’s think: what kind of building did we fall into?
- The original garden entrance was… some weird, useless storage shed.
- Now, we’ve got a locked door and a chest. (There’s a sword inside, but it could be changed to something more interesting… like flippers).
- So we’re in a… control shack for Hyrule River?
- Then the lower room should have lots of flowing water, and be a “public space” (no fancy jumping needed to get around).
Hmm…. maybe we can also be more creative with the crystal blocks. Let’s use them as bridges. Perhaps the big key door is locked because it’s a control room for the “bridges”. We’ll have to think of a better explanation later (water purification? Ph testing?) but at least that’s more interesting than a big rectangle.
Ok, make the necessary changes.
- Switch to level 3, click on the door at position 6 (the exit) and press right (on the numpad) twice. Now, click on the other door at position 6 and press numpad-right twice. We’ve now moved the exit doors.
- Switch to “Item” level, right-click on each “Magic” circle, and choose “Remove”.
- Switch to “torch” level, right-click on our only torch, and choose “Remove”. Switch back to level 1.
|wall||x:35 y:27||x:37 y:27|
|wall||x:35 y:2B||x:37 y:29|
|wall||—||obj:106 x:3A y:2C back|
|wall||—||obj:001 x:3E y:2C|
|wall||x:16 y:30||x:3A y:36|
|wall||x:1A y:30||x:3E y:36 size:01|
|wall||x:0D y:27||x:17 y:27 size:00|
|wall||x:09 y:27||x:13 y:27|
|wall||x:09 y:2B||x:13 y:2B size:03|
|wall||x:0D y:34||x:15 y:33 size:04|
|wall||x:09 y:34||x:13 y:33 front|
|wall||—||obj:10A x:18 y:27 front|
|wall||—||obj:10E x:18 y:2F|
|wall||—||obj:003 x:1C y:2F|
|water||—||obj:0C8 x:15 y:2D front|
|water||—||obj:0C8 x:15 y:31 size:04 front|
|edge||—||obj:079 x:15 y:2B size:08 front|
|edge||—||obj:07A x:19 y:2B size:05 front|
|grate||—||obj:FEF x:1B y:31 front|
|edge||—||obj:045 x:19 y:31 front|
|edge||—||obj:040 x:15 y:34 size:04 front|
|grate||—||obj:FEC x:16 y:28|
|barrier||x:09 y:38||x:13 y:2A size:06 front|
|barrier||x:12 y:38||x:13 y:2F size:08 front|
|barrier||—||obj:022 x:13 y:36 size:08 front|
|barrier||—||obj:069 x:13 y:27 size:00 front|
|barrier||—||obj:069 x:1C y:27 size:00 front|
|barrier||—||obj:069 x:13 y:2F size:04 front|
|barrier||—||obj:069 x:1E y:2F size:04 front|
|wall||x:22 y:30||x:20 y:3A|
|wall||x:22 y:34||x:20 y:3E size:01|
|wall||x:25 y:31||x:33 y:29 size:02|
|wall||—||obj:108 x:33 y:27 front|
|water||—||obj:0C8 x:35 y:27 size:01 front|
|grate||—||obj:FEC x:35 y:27 front|
|barrier||—||obj:022 x:32 y:2E size:0A front|
|barrier||—||obj:022 x:32 y:37 size:0A front|
|barrier||—||obj:069 x:32 y:27 size:04 front|
Looks incomplete, no? At this point, I was going to add another minor waterway, but looking at the top screen, I noticed that it wouldn’t line up right. Originally, I was just going to say that some sewer line carried away the middle waterway –it looked pretty cool after all. But I think it’s actually better to leave this out.
Naturally, I create all of my tutorial ROMs twice: once to make sure the concept works and once to write out instructions for the blog post. But I want to stress the importance of reflecting on your design decisions: I had the third water-way in place on my first ROM, and decided not to add it on the second one.
Ok, let’s add the final pieces to our room:
|bridge||—||obj:0B9 x:13 y:2B size:05 front|
|bridge||—||obj:0B9 x:13 y:2D size:05 front|
|water||—||obj:0C9 x:30 y:2F size:0D front|
|water||—||obj:0C9 x:1F y:2F size:0D front|
|water||—||obj:0C9 x:23 y:34 size:06 front|
|wall||—||obj:107 x:2A y:3A back|
|wall||—||obj:062 x:2A y:3E size:01 back|
|bridge||—||obj:092 x:1F y:2F size:04 front|
|bridge||—||obj:092 x:21 y:2F size:04 front|
|bridge||—||obj:092 x:2D y:2F size:04 front|
|bridge||—||obj:092 x:2F y:2F size:04 front|
And we’re done! (You guys didn’t notice that I forgot that corner, did you?)
Our puzzle is complete. Back up your ROM, please, since we’re going to be hacking the header next. When you run your ROM, you can solve the puzzle easily and exit the room. (There is a weird glitch where sometimes the screen won’t scroll properly after walking up the stairs for the first time. I’ve designed this room so that it won’t hinder your progress, but I’m not sure exactly how to fix that bug if it occurs again.) However, something’s amiss if you then re-enter the room. You’re in the wrong starting location!
Open Hyrule Magic (make sure you’ve backed up your ROM) and look in the “Starting Location” tab. You’ll see “Room”, which we won’t change, and then “X” and “Y” which we will. You can do the math to set these properly (each tile is 16 pixels wide and high) but I prefer to just switch to a room with a similar entrance and copy the values from there. We’ll also need to adjust the x-scroll value to start our camera further over to the right. And, we should fix the CX and CY values as described in the Perfect Guide. Change the following:
X = 376
xScroll = 256
CX = xScroll + 128 = 256+128 = 384
CY = yScroll + 112 = 272 + 112 = 384
Please click on the “More” button in the top part of the Dungeon editor, then click “Ok”. Then Save. Sometimes Hyrule Magic won’t persist room values if you don’t click the “more” button; I have no idea why.
Open your ROM, and re-test… whoah! You’re colliding with obstacles that aren’t there, and you’re jumping into ground that’s really water:
It’s almost like Hyrule Magic is ignoring the value we entered for xScroll. And… if you open your ROM and double-check, it is ignoring it! This is another frustrating feature of Hyrule Magic; sometimes it doesn’t really save your data. You’ll understand why after we cover the ridiculously complex way that Zelda3 saves the xScroll parameter. For now, it’s sandwich time. I recommend a BLT.
Step 8: Fixing the xScroll Wonkiness
You’ll need a hex editor. We’ll cover Windows first. I recommend using XVI32. Open the program, then open your Zelda3.smc ROM. We are now presented with the first few bytes of the file. They’re all header space, so they’re not too interesting. On the left is the hexadecimal view, and on the right is the ASCII view. Scroll down a bit and you’ll see what I mean:
In this example, we are in position 0xEB589, which has the value 4B. In ASCII, that would be the letter “K”, but probably this is actually just used as a number for something, not as a letter. A lot of the data in Zelda3 is compressed, so you won’t be able to find it even if you know what you’re looking for.
At the bottom of the screen, you can see that 0x4B is actually the number 75. Also, you can see that “Overwrite” is on. As you may recall from the early days of Microsoft Word, this means that typing a letter will erase the next letter, so that you never expand the length of the document. Unlike Word, you almost always want this on when hex editing. Otherwise, you’ll offset the entire ROM, and data won’t load where it’s supposed to. Don’t worry, you’ll notice if you do this when you open the ROM; it’s almost guaranteed not to load at all.
From the Perfect Guide, we know that xScroll for the dungeons starts at 0x14F45 and each value is 2 bytes in length. Since we want the data for Entrance 0×32, we do some simple math in Windows Calculator (hex mode) and get:
14F45 + 32*2 = 14FA9
Hitting “Ctrl+G” in XVI32, we click “hexadecimal” under “Go to”, ensure that our “Go mode” is “absolute”, and type in 14FA9. Click “Ok”, and our cursor jumps to address 0x14FA9.
The highlighted box reads 00, and the next box to the right reads 0A. Since Zelda3 stores bytes backwards, we read this as 0x0A00, or 2560 …which is not zero, as we might expect. Enter 2560 in Windows Calculator and click “Bin” to convert this to binary. Now, we have:
Note the green bits. Zelda3 uses these for… something, and it prevents Hyrule Magic from saving the xscroll value properly. The red bits are the actual bits used for saving xscroll. So, if we want an x-scroll of 256, then we need:
…since 100000000 in binary is 256 in decimal notation. (Generally, you won’t want to mess with the green bits).
If you enter 101100000000 into your calculator and then switch to hexadecimal, you get 0x0B00. Breaking apart and flipping the bytes, we get:
So, in XVI 32, click once on the 0A next to the cursor to move it there, type 0B and then Save. Load the ROM in Hyrule Magic and you’ll see that our xScroll has, in fact, been updated. Load it in zsnes and you’ll notice that our scrolling problem is gone.
Step 8.2: Fixing the Wonkiness on Linux
I’m still looking for a good hex editor on Ubuntu, so if you have any suggestions, please let me know. For now, you should use tweak, a console editor with a slight Emacs inclination.
sudo apt-get install tweak
Please read the previous section on Windows to understand how we do the math. Basically, we just want to replace the 0A at offset 14FAA with an 0B. To do this:
Then, press Ctrl+X then g
Then type 0x14FAA and hit Enter.
Then type 0B and press Ctrl+X then Ctrl+S
Then press Ctrl+X then Ctrl+C
Okay, we’ve edited our file, saved it, and exited. Re-run our game, and you’ll see that Link is back where he should be when entering the room.
Here’s a summary of some things I’d like to modify, but had no time to. You can play around with them, if you’d like:
- Change the opening message from Link’s uncle to make more sense.
- Re-arrange Entrance 00 (Link’s house, pre-Intro) to have a more intelligent layout. The chest should go in front of his bed, for example, or maybe he should have two chests; one with the bow and one with arrows.
- Change the messages from Zelda, and the message when you pick up your bow so that they make more sense.
- Advanced. You actually can’t save; it will drop you back off at the introduction. This is (I think) because the “Castle” save flag is set when your Uncle gives you your sword. Read through the Perfect Guide and MON’s Pinups until you know what has to be changed, and write a small hack which fixes this. (Maybe you can set the “Castle” save flag when Link falls into the hole?)
- If you play through the intro a bit, you’ll notice that arrows are in short supply, and that the ball-and-chain trooper goes down with a mere four arrows. Also, the lamp should be harder to get (maybe in that chest we put between the crystal switches?) and the boomerang should be acquired later. Fiddle around and fix these. Also, consider making more arrow-related puzzles in Hyrule Castle. Just remember that it is a castle, after all, so maintain a believable architecture.
- For the hardcore players, devise a way for them to get into the basement without even the bow. (Make it very tricky to figure out.) This means they have to beat the entire castle by throwing pots. Trust me, hardcore players will love you for this.
- Add a telepathic tile to the water control room which helps to clarify its purpose. (Hint: click on the “more” button on the top of the dungeon window).
In addition to the Perfect Guide, I relied heavily on MathOnNapkins’s “Zelda 3 ROM Map”, adding 0×200 to the offsets since I’m using a headered ROM. I generally refer to these as MON’s Pinups in this guide.