Next Previous Contents

2. The Overworld

2.1 The Overworld Map Format

Description             Offset          Num. Entries    Entry Size
------------------------------------------------------------------
Overworld Map           87064           128             16
Column Directory       105743           16              2
Column Table 0          89048           16              varies
Column Table 1          89101           16              varies
Column Table 2          89150           16              varies
Column Table 3          89216           16              varies
Column Table 4          89284           16              varies
Column Table 5          89334           16              varies
Column Table 6          89394           16              varies
Column Table 7          89453           16              varies
Column Table 8          89512           16              varies
Column Table 9          89574           16              varies
Column Table 10         89639           16              varies
Column Table 11         89708           16              varies
Column Table 12         89769           16              varies
Column Table 13         89823           16              varies
Column Table 14         89889           16              varies
Column Table 15         89941           16              varies
Primary Square Table    92540           64              1
Secondary Square Table  92596           16              4
Secrets Table           92534           6               1

2.2 The Overworld Map

The overworld is 16 screens wide by 8 screens high. Screens are numbered 0..127 starting at the upper left corner, moving left to right, then top to bottom. Therefore the screen number is calculated by 16*R + C where R is the map row and C is the map column.

However, not all 128 overworld locations are entirely different. Some have the same graphic as another location. Each unique screen is stored once. Screens that have the same picture, but different colors, can still share the same memory for their graphic (the colors are stored elsewhere).

The overworld screen table stores 124 unique screens of 16 bytes each (see the next section for a description for individual screens). These in no particular order. The overworld map contains 128 bytes, one for each 2-D map location. Each byte in the overworld map refers to one screen in the overworld screen table.

2.3 Overworld Screens

One screen in the overworld is 16 columns wide. Each column is 11 squares high. Each screen takes 16 bytes, one byte for each column of squares on that screen.

Before we learn how to find the data for a column, we need to discuss the format of the data for a column.

2.4 Columns

Column Data Format

The data for column is 11 bytes, one byte for each square in the column, stored in order from top to bottom. A square is made of 4 tiles arranged in a 2x2 square on the screen.

It takes 11 bytes to draw a column, but these aren't always stored as 11 consecutive bytes in memory. Instead, if two squares (one above the other) are the same graphic (use the same tiles), they can be stored in one byte instead of two. The number of bytes it takes to store a column depends on how many squares are stored doubly. The minimum number is 6 bytes (if there are 5 duplicated squares and one left over), and the maximum is 11 (if no squares are duplicated). There is no way to duplicate more than 2 squares at a time, so even if all the squares in a column are the same, you still need 6 bytes to store that column.

There are 64 possible squares (although not all of the 64 possible may be actually used). This means that only 6 bits are needed to store the square number. Since each square uses one byte, there are 2 extra bits in the byte for each square. The meaning of a square byte is described in section 4, "Squares."

The 6 bits for the square number are stored in bits 0-5 of each byte in the column data. If bit 6 is set, this square is a duplicated square and will take up two rows, one above the other, in this column.

Column Tables

The column data for 16 different columns is stored together in what we will call a "column table." A column table contains the 6-11 bytes for each of the 16 columns in that column table, stored all in one contiguous area of memory (which, if you do the arithmetic, could be as small as 96 bytes, or as large as 176 bytes, depending on how many total squares are doubled in the columns inside the column table).

The first byte of the 6-11 bytes for an individual column always has bit 7 set. This is how to locate columns within a column table. We have now accounted for all 8 bits of every byte inside the column data.

The Column Directory

There are 16 column tables, for a total of 256 different columns in the overworld. The addresses of the beginning of each column table are stored in a table of column tables, which we will call the "column directory." I have copied these addresses and converted them to offsets in the ROM in the above table in the rows "Column Table XX", for your convenience.

(The naming for this two-tiered table structure is taken from Intel's description of its tiered structure for addressing memory pages in the 386 processor's virtual memory model. This model uses a "page directory" which contains pointers to "page tables", which in turn point at individual pages, which are 4K blocks of memory that are the unit of memory allocation.)

Indexing a Column

Now we can understand the meaning of the 16 bytes in each overworld screen. There are 256 columns, so each column byte in an overworld screen refers to one column. The high nibble of the byte selects which column table to use from the column directory. The low nibble selects a column from that column table.

2.5 Squares

The Primary Square Table

The primary square table is an array of 64 (or 56?) bytes, one for each square number used in the column data. The values in the primary square table are used to determine the tiles to draw for a particular square number. If the value is greater than or equal to 16 (hex $10), then it refers to the first of four consecutive tiles in NES Pattern Table 1 (Pattern Table 0 is not used for map background tiles). The 4 chosen tiles are the upper left, lower left, upper right, and lower right tiles for that square, in that order. If the value in the primary square table is less than 16, the four tiles in this square are taken from the secondary square table (using the value that is less than 16 as the index).

The Secondary Square Table

The secondary square table contains tile numbers for squares in the overworld that have one or more tiles repeated. To save space in the pattern tables, pattern tables only store tiles for squares for which all the tiles are unique.

Each entry in the secondary square table is 4 bytes long, and there are 16 entries (indexed by values in the primary square table that are less than 16). The bytes specify the tile numbers (again in Pattern Table 1) for a square in the same order used by the primary square table.

2.6 Secrets

Secret squares are marked by a special value in the primary square table. When the map is drawn, the primary square table value for a secret is translated into the value for the graphic that should be shown where the secret is. This includes checking whether you have gotten the secret on that screen, if applicable. There are 6 possible secrets: a pushable rock ($E5), a tree in the forest with a door under it ($E6), a round bush with stairs under it ($E7), a well ($E8), a statue ($E9), and a statue with stairs under it ($EA).

There can be only one secret per screen. If you were to put more than one secret on a screen, only the last one (the bottommost square of the rightmost column that contains a secret) would be marked as the row and column that a secret is at (and therefore would be the only secret you could use by walking into it), and all the secrets on the screen would share the same state of whether they were found or not, since there is only one bit per overworld screen devoted to storing that state.


Next Previous Contents