2 ** Minimalistic overlay demo program.
4 ** Shows how to load overlay files from disk.
6 ** 2009-10-02, Oliver Schmidt (ol.sc@web.de)
22 extern void _OVERLAY1_LOAD__[], _OVERLAY1_SIZE__[];
23 extern void _OVERLAY2_LOAD__[], _OVERLAY2_SIZE__[];
24 extern void _OVERLAY3_LOAD__[], _OVERLAY3_SIZE__[];
27 /* Functions resident in an overlay can call back functions resident in the
28 ** main program at any time without any precautions. The function log() is
29 ** an example for such a function resident in the main program.
33 printf ("Log: %s\n", msg);
37 /* In a real-world overlay program one would probably not use a #pragma but
38 ** rather place all the code of certain source files into the overlay by
39 ** compiling them with --code-name OVERLAY1.
41 #pragma code-name (push, "OVERLAY1");
45 /* Functions resident in an overlay can access all program variables and
46 ** constants at any time without any precautions because those are never
47 ** placed in overlays. The string constant below is an example for such
48 ** a constant resident in the main program.
50 log ("Calling main from overlay 1");
53 #pragma code-name (pop);
56 #pragma code-name (push, "OVERLAY2");
60 log ("Calling main from overlay 2");
63 #pragma code-name (pop);
66 #pragma code-name (push, "OVERLAY3");
70 log ("Calling main from overlay 3");
73 #pragma code-name(pop);
76 unsigned char loadfile (char *name, void *addr, void *size)
80 int file = open (name, O_RDONLY);
82 log ("Opening overlay file failed");
85 read (file, addr, (unsigned) size);
90 /* Avoid compiler warnings about unused parameters. */
91 (void) addr; (void) size;
92 if (cbm_load (name, getcurrentdevice (), NULL) == 0) {
93 log ("Loading overlay file failed");
104 log ("Calling overlay 1 from main");
106 /* The symbols _OVERLAY1_LOAD__ and _OVERLAY1_SIZE__ were generated by the
107 ** linker. They contain the overlay area address and size specific to a
110 if (loadfile ("ovrldemo.1", _OVERLAY1_LOAD__, _OVERLAY1_SIZE__)) {
112 /* The linker makes sure that the call to foo() ends up at the right mem
113 ** addr. However it's up to user to make sure that the - right - overlay
114 ** is actually loaded before making the the call.
119 log ("Calling overlay 2 from main");
121 /* Replacing one overlay with another one can only happen from the main
122 ** program. This implies that an overlay can never load another overlay.
124 if (loadfile ("ovrldemo.2", _OVERLAY2_LOAD__, _OVERLAY2_SIZE__)) {
128 log ("Calling overlay 3 from main");
129 if (loadfile ("ovrldemo.3", _OVERLAY3_LOAD__, _OVERLAY3_SIZE__)) {