5.6 Overlays

An overlay is a partial program containing code and data that another program, called the main program, loads and uses as needed. Overlays are useful for large, complex programs that must run in limited memory.

Overlays can be either .COM or .EXE programs and need not have the same format as the main program. To load an overlay, the main program allocates memory for it (MS-DOS does not) and then calls Load Overlay (Interrupt 21h Function 4B03h), specifying a parameter block whose form corresponds to that of the LOADOVERLAY structure:

LOADOVERLAY STRUC

loStartSegment dw ? ;segment address of overlay's memory

loRelocationFactor dw ? ;relocation factor

LOADOVERLAY ENDS

For a full description of the LOADOVERLAY structure, see Section 5.8, “Structures.”

After loading the overlay, the main program transfers control to it by using a far call. The entry point for the overlay depends on the convention the main program uses. Typically, the entry point is at offset 0000h in the overlay. In any case, the overlay should return control to the main program by using a far return. entry point>

The system does not construct a PSP for the overlay; it considers the overlay part of the main program. Any memory the overlay allocates and any files it opens belong to the main program.