From z64 wiki
Jump to: navigation, search

Overlays are code files which can be loaded dynamically into ram.


The overlay structure is similar to the elf file structure, in the sense that there are the following parts:

Text block mips r4000 machine code
Data block Read/Write data (variables) This can also include inline model data, as seen in element arrows and Ganon to name a few.
Rodata block Read-Only Data Usually contains text used with the n64 debugging print function (0x80002130) and thus contains empty format strings.
BSS block Uninitialized values? BSS data is rarely used in actor overlays.
Relocation block Remaps virtual ram to ram

The last word in an overlay file contains a seek up value that points to the header for the overlay, which in turn points to the start of these blocks.

For example, in ovl_En_Test (Stalfos) the last word in the overlay file is 0x00000640, the file length is 0x58B0 bytes, and the file end in rom is at address 0xC33CD0. Therefore the header is located at...

 0x58B0     0xC33CD0
-0x0640    -0x000640
=0x5270    =0xC33690

...within the actor file and rom respectively.

Block Table

Overlays contain a table that map out the location of all 5 blocks within the file. At offset 0x5270 within ovl_En_Test, you'll find the following 5 words which correspond to the overlay's five blocks.

(Offset 0x5270)
Text block 00004EC0 ( .text) Size in bytes of the text block. Block located at the start of the file.
Data block 000001F0 (.data) Size in bytes of read/write data block following the text block.
Rodata block 000001C0 (.rodata) Size in bytes of the read-only block following the data block.
BSS block 00000000 Size in bytes of the BSS block?
Relocation block 00000187 Count of one-word long entries of relocation data. Relocation block immediately follows this table.

Relocation Entry Format

s = section

0 = .text
1 = .data
2 = .rodata
3 = .bss

t = type

0 = unused?
1 = unused?
2 = 32 bit pointer
3 = unused?
4 = jump target
5 = lui/ori pt. 1
6 = lui/ori pt. 2
7+ = unused?

o = offset relative to start of section s

Custom Actors

ZZT32 decided to get off his ass one day and write nOVL ([1]), a tool which converts MIPS (http://en.wikipedia.org/wiki/MIPS_architecture) elf binaries to Zelda 64 http://en.wikipedia.org/wiki/Overlay_(programming) Overlays, also known as actors. Few actors have been (re)written using mips-gcc + nOVL, but there are a few:

zovldis http://64.vg/dr/node/75 is the opposite of nOVL - it takes an overlay and disassembles it to an assembly file, which, combined with a proper makefile, produces an identical actor as the one which was disassembled. This makes hacking existing actors much more convenient. An example of actor modification using this approach is http://spinout182.com/dodongo here (http://www.youtube.com/watch?v=EcbhG8wGF10 video)