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.
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.
|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
ZZT32 decided to get off his ass one day and write nOVL (), 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:
- En_Anim http://spinout182.com/ovl_En_Anim/ - An actor written to load any animation.
- En_AnimVar http://spinout182.com/ovl_En_AnimVar/ - A fork of the above actor, uses variables.
- en_vase http://vg64tools.googlecode.com/svn/n64/z_snippets/ovl_en_vase/ - The simplest actor in OoT, re-written in C to test nOVL and to document functions.
- En_Bird http://vg64tools.googlecode.com/svn/n64/z64-actors/En_Bird/trunk/ - The simplest animated actor in OoT, re-written for the same reason as En_Vase.
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)