2 ** Minimalistic GEOSLib overlay demo program
4 ** 2012-01-01, Oliver Schmidt (ol.sc@web.de)
11 #include "overlay-demores.h"
14 /* Functions resident in an overlay can call back functions resident in the
15 ** main program at any time without any precautions. The function show() is
16 ** an example for such a function resident in the main program.
22 sprintf(line1, CBOLDON "Overlay Demo - Overlay %s" CPLAINTEXT, name);
23 DlgBoxOk(line1, "Click OK to return to Main.");
26 /* In a real-world overlay program one would probably not use a #pragma but
27 ** rather place the all the code of certain source files into the overlay by
28 ** compiling them with --code-name OVERLAY1.
30 #pragma code-name(push, "OVERLAY1");
34 /* Functions resident in an overlay can access all program variables and
35 ** constants at any time without any precautions because those are never
36 ** placed in overlays. The string constant "One" is an example for such
37 ** a constant resident in the main program.
42 #pragma code-name(pop);
45 #pragma code-name(push, "OVERLAY2");
52 #pragma code-name(pop);
55 #pragma code-name(push, "OVERLAY3");
62 #pragma code-name(pop);
65 void main(int /*argc*/, char *argv[])
67 if (OpenRecordFile(argv[0])) {
68 _poserror("OpenRecordFile");
72 DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT,
73 "Click OK to call Overlay One.");
76 _poserror("PointRecord.1");
80 /* The macro definitions OVERLAY_ADDR and OVERLAY_SIZE were generated in
81 ** overlay-demores.h by grc65. They contain the overlay area address and
82 ** size specific to a certain program.
84 if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) {
85 _poserror("ReadRecord.1");
89 /* The linker makes sure that the call to foo() ends up at the right mem
90 ** addr. However, it's up to user to make sure that the -- right -- overlay
91 ** actually is loaded before making the call.
95 DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT,
96 "Click OK to call Overlay Two.");
99 _poserror("PointRecord.2");
103 /* Replacing one overlay with another one can only happen from the main
104 ** program. This implies that an overlay can never load another overlay.
106 if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) {
107 _poserror("ReadRecord.2");
113 DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT,
114 "Click OK to call Overlay Three.");
116 if (PointRecord(3)) {
117 _poserror("PointRecord.3");
121 if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) {
122 _poserror("ReadRecord.3");
128 if (CloseRecordFile()) {
129 _poserror("CloseRecordFile");