Difference between revisions of "PS2 Code Overlay"

From GTAMods Wiki
Jump to navigation Jump to search
m (Overlay load callbacks)
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
 
   4b - size of data segment
 
   4b - size of data segment
 
   4b - size of bss segment
 
   4b - size of bss segment
   4b - end of data/start of bss segment?
+
   4b - start address of overlay load callbacks
   4b - end of data/start of bss segment?
+
   4b - end address of overlay load callbacks
 
   32b - file name
 
   32b - file name
  
After that follow the text and data segment
+
After that follow the text and data segment.
 +
 
 +
== Overlay load callbacks ==
 +
 
 +
The start and end address of overlay load callbacks forms an array of 32bit pointers. The addresses have to be aligned to 4 byte boundaries and have to either point inside the game executable or the code overlay. The addresses are absolute memory offsets, not relative to the code overlay base address. The end address delimits the array and thus it does not point to a valid routine address.
 +
 
 +
  numfuncs = ( end-addr - start-addr ) / 4

Latest revision as of 14:32, 18 December 2020

The PS2 version of San Andreas uses code overlays to save memory and swap code in only when it is actually needed. The files have the extension 'nm' for NTSC and 'pm' for PAL respectively.

The following code overlays are used: clothes, credits, cutscene, fileload, init, jpeg, mc, mpeg

In the SLES version the files are loaded by the function at 0x3C6A80 which takes as its first argument the name of the file containing the code and as second argument the address where it is to be loaded (0x88D980 typically).

The files have a 64 byte long header:

 4b - fourcc (MWo3)
 4b - unknown (number of segments?)
 4b - load address/entry point?
 4b - size of text segment
 4b - size of data segment
 4b - size of bss segment
 4b - start address of overlay load callbacks
 4b - end address of overlay load callbacks
 32b - file name

After that follow the text and data segment.

Overlay load callbacks

The start and end address of overlay load callbacks forms an array of 32bit pointers. The addresses have to be aligned to 4 byte boundaries and have to either point inside the game executable or the code overlay. The addresses are absolute memory offsets, not relative to the code overlay base address. The end address delimits the array and thus it does not point to a valid routine address.

 numfuncs = ( end-addr - start-addr ) / 4