2012-01-03 21:55:34 +00:00
|
|
|
/*
|
2014-06-30 09:10:35 +00:00
|
|
|
** Minimalistic GEOSLib overlay demo program
|
|
|
|
**
|
|
|
|
** 2012-01-01, Oliver Schmidt (ol.sc@web.de)
|
|
|
|
**
|
|
|
|
*/
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <geos.h>
|
|
|
|
#include "overlay-demores.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Functions resident in an overlay can call back functions resident in the
|
2014-06-30 09:10:35 +00:00
|
|
|
** main program at any time without any precautions. The function show() is
|
|
|
|
** an example for such a function resident in the main program.
|
|
|
|
*/
|
2012-01-03 21:55:34 +00:00
|
|
|
void show(char *name)
|
|
|
|
{
|
|
|
|
char line1[40];
|
|
|
|
|
|
|
|
sprintf(line1, CBOLDON "Overlay Demo - Overlay %s" CPLAINTEXT, name);
|
2012-06-10 12:20:50 +00:00
|
|
|
DlgBoxOk(line1, "Click OK to return to Main.");
|
2012-01-03 21:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* In a real-world overlay program one would probably not use a #pragma but
|
2014-06-30 09:10:35 +00:00
|
|
|
** rather place the all the code of certain source files into the overlay by
|
|
|
|
** compiling them with --code-name OVERLAY1.
|
|
|
|
*/
|
2012-01-03 21:55:34 +00:00
|
|
|
#pragma code-name(push, "OVERLAY1");
|
|
|
|
|
|
|
|
void foo(void)
|
|
|
|
{
|
|
|
|
/* Functions resident in an overlay can access all program variables and
|
2014-06-30 09:10:35 +00:00
|
|
|
** constants at any time without any precautions because those are never
|
2022-04-17 14:06:45 +00:00
|
|
|
** placed in overlays. The string constant "One" is an example for such
|
2014-06-30 09:10:35 +00:00
|
|
|
** a constant resident in the main program.
|
|
|
|
*/
|
2012-01-03 21:55:34 +00:00
|
|
|
show("One");
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma code-name(pop);
|
|
|
|
|
|
|
|
|
|
|
|
#pragma code-name(push, "OVERLAY2");
|
|
|
|
|
|
|
|
void bar(void)
|
|
|
|
{
|
|
|
|
show("Two");
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma code-name(pop);
|
|
|
|
|
|
|
|
|
|
|
|
#pragma code-name(push, "OVERLAY3");
|
|
|
|
|
|
|
|
void foobar (void)
|
|
|
|
{
|
|
|
|
show("Three");
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma code-name(pop);
|
|
|
|
|
|
|
|
|
|
|
|
void main(int /*argc*/, char *argv[])
|
|
|
|
{
|
2012-02-22 23:29:52 +00:00
|
|
|
if (OpenRecordFile(argv[0])) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("OpenRecordFile");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT,
|
|
|
|
"Click OK to call Overlay One.");
|
|
|
|
|
2012-02-22 23:29:52 +00:00
|
|
|
if (PointRecord(1)) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("PointRecord.1");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
/* The macro definitions OVERLAY_ADDR and OVERLAY_SIZE were generated in
|
2014-06-30 09:10:35 +00:00
|
|
|
** overlay-demores.h by grc65. They contain the overlay area address and
|
|
|
|
** size specific to a certain program.
|
|
|
|
*/
|
2012-02-22 23:29:52 +00:00
|
|
|
if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("ReadRecord.1");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
/* The linker makes sure that the call to foo() ends up at the right mem
|
2014-06-30 09:10:35 +00:00
|
|
|
** addr. However, it's up to user to make sure that the -- right -- overlay
|
|
|
|
** actually is loaded before making the call.
|
|
|
|
*/
|
2012-01-03 21:55:34 +00:00
|
|
|
foo();
|
|
|
|
|
|
|
|
DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT,
|
|
|
|
"Click OK to call Overlay Two.");
|
|
|
|
|
2012-02-22 23:29:52 +00:00
|
|
|
if (PointRecord(2)) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("PointRecord.2");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
/* Replacing one overlay with another one can only happen from the main
|
2014-06-30 09:10:35 +00:00
|
|
|
** program. This implies that an overlay can never load another overlay.
|
|
|
|
*/
|
2012-02-22 23:29:52 +00:00
|
|
|
if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("ReadRecord.2");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
bar();
|
|
|
|
|
|
|
|
DlgBoxOk(CBOLDON "Overlay Demo - Main" CPLAINTEXT,
|
|
|
|
"Click OK to call Overlay Three.");
|
|
|
|
|
2012-02-22 23:29:52 +00:00
|
|
|
if (PointRecord(3)) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("PointRecord.3");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
2012-02-22 23:29:52 +00:00
|
|
|
if (ReadRecord(OVERLAY_ADDR, OVERLAY_SIZE)) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("ReadRecord.3");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
|
|
|
|
foobar();
|
|
|
|
|
2012-02-22 23:29:52 +00:00
|
|
|
if (CloseRecordFile()) {
|
2022-07-24 16:14:21 +00:00
|
|
|
_poserror("CloseRecordFile");
|
2012-02-22 23:29:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-01-03 21:55:34 +00:00
|
|
|
}
|