Static overlay example

Suppose you have a program that contains a calculator module, a word processor module, and a spreadsheet module. Since only one of these three pieces can be used at once, you decide to overlay them, to save memory (and to allow you to add a lot more features).

This can be accomplished using a single overlay area:

AREA

OVERLAY Calc;
OVERLAY Text + Commands + Files;
OVERLAY Parse + Eval + UserInt;

Next, your boss tells you that you have to support both graphics and text modes, and that you cannot use any additional memory. You already have a set of screen handling procedures for graphics mode that are used by all three portions of the program. You did not put them in an overlay because it was called by all of the other overlays, and things would have swapped in and out of memory at an amazing rate.

But when you create the screen primitives for text mode, you can overlay them with the graphics primitives safely, since the screen is not likely to be in text and graphics mode at the same time.  Now your linker linker definition file looks like this:

AREA

OVERLAY Calc;
OVERLAY Text + Commands + Files;
OVERLAY Parse + Eval + UserInt;

 

AREA

OVERLAY GraphScreen + GraphWindows;
OVERLAY TextScreen + TextWindows;

Now text and graphics code overlay each other, and separately, the calculator code, word processor code, and spreadsheet code overlay each other. You can have one overlay from each of those separate groups in memory at any given time.

Preparing for overlaying

Compiler options Set to
Code memory model Large
Overlay Yes