For game maps, see my Legend of Zelda page.
[ Introduction | General Information | PPU Transfers | Patterns | Layouts | Scrolling | Sound | References ]
The game cartridge used standard N.E.S. technology. It contained battery-backed RAM for saving up to 3 games between sessions. The code and data resided in ROM.
Nintendo no longer makes the N.E.S. and Legend of Zelda. However, emulators have been written for the N.E.S., and unauthorized ROM dumps of N.E.S. cartridges are available on the World-Wide Web. The Legend of Zelda is commonly found in "iNES" format: 16 bytes of header information; 512 bytes of trainer if present; a dump of ROM, byte by byte; a dump of VROM, byte by byte, and an optional 128-byte trailer with the name of the cartridge, null-filled.
In this moonmap, a five-digit address denotes RAM or ROM. A four-digit address denotes CPU or PPU memory, with the prefix "P" denoting PPU.
Saved games take up little space in the battery RAM. Most of the space is used for utility routines and data. When the game starts, it calls a subroutine at $04d00 to copy ROM $06500-$0776f to battery RAM $6c90-$7eff.
A computed go-to subroutine resides at $1e5e2. When you call it, it uses A as an index into a table of addresses following the call, and jumps to the address indicated.
If bit 7 of byte 2 is set, the bytes are to be loaded vertically; that is, at every 32nd byte of PPU memory. Otherwise they are to be loaded contiguously.
If bit 6 of byte 2 is set, the header is followed by a single byte. It is to be replicated into the specified number of PPU locations.
A count of 0 denotes 64 locations.
PPU load blocks are often constructed as needed, usually starting at $0302.
Tagged load blocks are not used for the pattern spaces, which are loaded expressly from large blocks of memory.
The character set is stored contiguously at $0877f, and the extended miscellaneous graphics are at $08e7f.
Sprites are double; it takes two to make a 16x16 monster. The pattern space at P$0000 is used for sprites as follows:
The fixed sprites are stored contiguously at $0807f.
Segment $0c000 contains the variable patterns for the overworld and underworld, with the code for loading them.
For the overworld, the variable tile patterns are loaded from $0c93b and the sprites from $0d15b.
For the underworld, the variable tile patterns are loaded from $0c11b. The variable sprite space is divided into three sections:
The complete image of sprite memory is maintained at $0200. It is always loaded by DMA transfer using the register at $4014.
The pointers for the dungeons' 3 monster and 3 boss groups reside in two arrays from 0 to 9 at the beginning of segment $0c000. The groups are mutually exclusive except that zols belong to two groups. Thus a dungeon cannot have both goriyas and gibdoes, because they belong to different monster groups. The monsters common to all dungeons are bubble, gel, trap, keese (bat), and the old man who gives hints.
At $04d00 reside the code and pointers for the title-screen patterns. Locations $04d3b and $04d3d point to the variable sprite patterns (at $04db4) and the variable tile patterns (at $056b4). The tile layout for the title screen begins at $1a869. The 28 decorative sprites for the title screen begin at $090ee.
In the table at $18580, bits 6-0 identify the layout number for the screen. Layout numbers run from $00 to $78 and index a block of 121 sixteen-byte arrays starting at $15418. Each of the 16 bytes defines one column of the layout.
The high nybble of each byte specifies a group of column sequences. The low nybble defines a sequence within the group. There are 16 groups; their addresses are stored starting at $19d0f. The group data begin at $15bd8.
A group consists of a sequence of bytes. The first byte and 8 or 9 others have bit 7 set to denote the start of a sequence. Sequences are designed to overlap to save space, so a sequence seldom begins where the previous sequence ends. Bits 5-0 specify a cluster of four tile codes. Bit 6 is a repeat flag; it means use the cluster twice.
If a cluster code is less than $10, it specifies an explicit set of four tile codes in the array starting at $169b4. If it is $10 or greater, it specifies the starting pattern code for the cluster, in an array based (from $00) at $1697c; the other three pattern codes are the three that follow it in the pattern space.
Serial pattern codes from $e5 to $ea are special and represent mutable quads like bombable caves and burnable trees.
The room descriptions are compacted to save space. Dungeons 1 to 6 fit together neatly into a 16-by-8 block; so do dungeons 7 to 9.
Quest 1, Dungeons 1-6 +-------+ +---+ +-------+---+ |4 4 4 4| |5 5| |6 6 6 6|2 2| | +-+ +-+-+ +-+ +-+ |4 4 4 4|5 5 5 5|6 6 6 6 6 6|2 2| | +---+ | +---+ | | |4 4|1 1|5 5 5 5|6 6|3 3|6 6|2 2| | +-+ | +---+ | +-+ | +-+ | |4 4 4|1|5|1 1|5|6 6 6|3|6|3|2 2| | +---+ +-+ +-+ | +---+ +-+ | | |4|1 1 1 1 1|5 5|6|3 3 3 3 3|2 2| | +-+ +-+ | | | | |4 4|1 1 1|5 5 5|6|3 3 3 3 3|2 2| +-+ +-+ +-+ | | +-+ +---+ | |4 4|1|5 5 5 5|6|3|6|3|2 2 2 2| +-+ +-+ +-+-+ | +-+ | +-+ +-+ |4 4|1 1 1| |5 5|6 6 6|3 3|2 2| +---+-----+ +---+-----+---+---+ Quest 1, Dungeons 7-9 +-------------+-----------+-+ |9 9 9 9 9 9 9|7 7 7 7 7 7|8| +-+ | +-+ +-+ |9 9 9 9 9 9 9 9|7 7 7 7 7|8 8 8| | | +-+ +-+ |9 9 9 9 9 9 9 9|7 7 7 7|8 8 8| | | +-+ +-+ |9 9 9 9 9 9 9 9|7 7 7|8 8 8 8 8| | | +-+ +-+ |9 9 9 9 9 9 9 9|7 7| |8 8 8 8| | | +-+-+ +-+ |9 9 9 9 9 9 9 9|7 7 7 7|8 8 8 8| +-+ +-+ +---+ +-+ |9 9 9 9 9 9| |7 7 7 7 7 7|8| | +-+ +-+ | | +-+---+ +-| |9| |9 9| |9| |7 7 7| |8 8 8 8| +-+ +---+ +-+ +-----+ +-------+ Quest 2, Dungeons 1-6 +-----+ +-----+---+ +-+ +-----+ |5 5 5| |6 6 6|1 1| |2| |4 4 4| | +-+ +-+ | +-+ +-+ +-+ |5 5 5|6 6|3|6|1 1|2 2 2|4 4 4 4| +-+-+ | | | | +-+ | | |3| |5|6 6|3|6|1| |2 2 2|4 4 4 4| | +-+ | | | | +-+ | | |3|5 5|6 6|3|6|1 1|2 2 2|4 4 4 4| +-+ +-+ | +-+ | | | |5 5|6 6 6|3| |1 1|2 2 2|4 4 4 4| | +-+ | | | +-+ | | |5|6 6 6 6|3| |1| |2 2 2|4 4 4 4| | +---+ | +-+ +-+ +-+ | | |5 5 5|6 6|3 3|1 1|2| |2|4 4 4 4| | +-+ | | | | | | +-+ |5 5 5| |6|3 3|1 1|2| |2|4 4 4| +-----+ +-+---+---+-+ +-+-----+ Quest 2, Dungeons 7-9 +---+ +---+---------------+ |9 9| |9 9|8 8 8 8 8 8 8 8| | +-------+ | +---------+ | |9 9 9 9 9 9 9 9|8 8|7 7 7 7 7|8| +---+ +---+ | +---+-+ | | |9 9 9 9| |8 8|7| |8|7|8| +-+ +-+ | | +---+ | | | |9 9 9 9 9 9| |8 8|7 7 7|8|7|8| +-+ +-+ | | | | | |9 9 9 9 9 9 9 9|8 8|7 7 7|8|7|8| | | | | | | | |9 9 9 9 9 9 9 9|8 8|7 7 7|8|7|8| +-+ +-+ +-----+ | | | |9 9 9 9 9 9| |8 8 8 8 8 8|7|8| +---+ +---+ +-----------+ | | |9 9| |7 7 7 7 7 7 7|8| +---+ +-------------+-+
The unused spots are used to specify subterranean passages. There are six $80-byte descriptor blocks for each matrix.
The layout of a dungeon room is specified in 32 vertical rasters of 22 tiles. The common layout of the outer walls is defined beginning at $15fa0. The 12-by-7 interior is defined by the fourth $80-byte block. Each byte is an index into a block of 12-byte groups at $160de. As with the overworld, a column specifier uses the high nybble to identify a sequence of quad-tile specifiers, and the low nybble to identify the start of a column within the sequence. Addresses of the ten sequences begin at $16704. Bit 7 is the tab flag, indicating the start of a column. Bits 6 to 4 are the repetition count: 0 means 1 copy of the quadtile, 6 means 7 copies. Bits 2 to 0 identify the quad-tile. The eight underworld quad-tiles are defined in an array of starting pattern numbers at $16718: 0=block, 1=floor, 2=goblin, 3=dragon, 4=stair, 5=sand, 6=water, 7=hole.
The doors are defined in the first two $80-byte blocks. In block 0, bits 7-5 define the north wall and bits 4-2 define the south wall. Bits 1-0 are not used. In block 1, bits 7-5 define the west wall and bits 4-2 define the east wall. Bits 1-0 specify one of the dungeon's four tile palettes. The wall encoding is: 0=open, 1=wall, 2=phantom, 4=bombable, 5=locked, 7=magic.
Blocks 4 and 5 specify and locate preset items, and characterize what happens (if anything) when you kill all the monsters.
For passages, block 0 defines the map coordinates of the room at the left end, and block 1 the right end if any. Block 2 defines the quad coordinates at which Link emerges into a room from the passage. Block 3 contains $3f for a single-ended passage or $3e for a double-ended passage.
The program achieves this by modifying the scroll register or the PPU address register while the PPU is redrawing the screen. Sprite 0, which triggers the hit flag in PPU status register $2002, is a bomb symbol drawn under the bomb tile in the header. At the end of the Vblank interval, the scrolling registers contain zeroes. For special scrolling, the program waits till the bomb sprite triggers the hit flag, delays with a loop while the PPU completes the status header, then sets the registers to scroll the scene as needed.
This method is hard to emulate, because it relies on the hit flag and CPU timing. It is used in many games, including Zelda II.
The pitch table for musical tones begins at $01f00. It contains 57 wave lengths, stored as two-byte values with the high byte first. The highest is 33, or the third A-flat above middle C. The lowest is 1357, or the third E below middle C. They are not stored in order of pitch. The oscillator frequency is 3579545 hz for N.T.S.C. or 3546895 hz for P.A.L.; divide by 32 to get the unit of time.
Five 8-byte duration tables for musical tones are stored contiguously beginning at $01fd1. The units are video scan cycles, 1/60th of a second for N.T.S.C., 1/50th for P.A.L.
The decay envelopes for musical notes are stored in reverse order beginning at $01f92. The high nybbles are for soft music and the low nybbles are for loud music.
At $00d60 resides a block of 36 byte offsets, not all distinct, from $00d60 to 28 music descriptors. The lowest is $24 ($00d84) and the highest is $f5 ($00e55). The structure is:
Some descriptors have fewer than 8 bytes.
For channels 1-3, the music is coded as a series of durations and pitches. If a byte's high bit is set, the low 3 bits identify the duration in the selected 8-byte duration table. If the high bit is clear, the value is a byte offset into the pitch table. The music for channel 2 ends with a null byte. The music for the other channels ends implicitly when the music for channel 2 ends. The music for channel 3 may contain repeat signs. A byte of $fX indicates X iterations; a byte of $f0 marks the end of the iterated sequence.
Channel 4 is used for percussion. The music encoding is: bits 5 and 4 encode the noise parameters (duration and intensity), and bits 0, 7, 6 encode the length of the interval, using the duration array for the segment. A noise code of 0 denotes silence. A zero byte denotes the end of the rhythmic unit.
Channel 2 is also used for incidental music. The offset table is at $01a55 and has eight entries, including the famous 8-note sting. Metabytes are controls; the low nybble denotes duration.
Fayzullin's description of how double sprites are processed is wrong. J.D.C. gives a correct algorithm:
Fayzullin gives few details of sound processing. The channels are:
J.D.C. gives the basic usage for channel 5. Its registers can be used in two ways:
Zeldit is a ROM editor for Legend of Zelda. Much specific information about locations and code numbers is available at the Zeldit Hacking Page in Zophar's Domain.