2 ** Minimalistic overlay demo program.
4 ** Shows how to load overlay files from disk.
6 ** 2009-10-02, Oliver Schmidt (ol.sc@web.de)
23 extern void _OVERLAY1_LOAD__[], _OVERLAY1_SIZE__[];
24 extern void _OVERLAY2_LOAD__[], _OVERLAY2_SIZE__[];
25 extern void _OVERLAY3_LOAD__[], _OVERLAY3_SIZE__[];
28 /* Functions resident in an overlay can call back functions resident in the
29 ** main program at any time without any precautions. The function log() is
30 ** an example for such a function resident in the main program.
34 printf ("Log: %s\n", msg);
38 /* In a real-world overlay program one would probably not use a #pragma but
39 ** rather place all the code of certain source files into the overlay by
40 ** compiling them with --code-name OVERLAY1.
42 #pragma code-name (push, "OVERLAY1");
46 /* Functions resident in an overlay can access all program variables and
47 ** constants at any time without any precautions because those are never
48 ** placed in overlays. The string constant below is an example for such
49 ** a constant resident in the main program.
51 log ("Calling main from overlay 1");
54 #pragma code-name (pop);
57 #pragma code-name (push, "OVERLAY2");
61 log ("Calling main from overlay 2");
64 #pragma code-name (pop);
67 #pragma code-name (push, "OVERLAY3");
71 log ("Calling main from overlay 3");
74 #pragma code-name(pop);
77 unsigned char loadfile (char *name, void *addr, void *size)
81 int file = open (name, O_RDONLY);
83 log ("Opening overlay file failed");
86 read (file, addr, (unsigned) size);
91 /* Avoid compiler warnings about unused parameters. */
92 (void) addr; (void) size;
93 if (cbm_load (name, getcurrentdevice (), NULL) == 0) {
94 log ("Loading overlay file failed");
105 log ("Calling overlay 1 from main");
107 /* The symbols _OVERLAY1_LOAD__ and _OVERLAY1_SIZE__ were generated by the
108 ** linker. They contain the overlay area address and size specific to a
111 if (loadfile ("ovrldemo.1", _OVERLAY1_LOAD__, _OVERLAY1_SIZE__)) {
113 /* The linker makes sure that the call to foo() ends up at the right mem
114 ** addr. However it's up to user to make sure that the - right - overlay
115 ** is actually loaded before making the the call.
120 log ("Calling overlay 2 from main");
122 /* Replacing one overlay with another one can only happen from the main
123 ** program. This implies that an overlay can never load another overlay.
125 if (loadfile ("ovrldemo.2", _OVERLAY2_LOAD__, _OVERLAY2_SIZE__)) {
129 log ("Calling overlay 3 from main");
130 if (loadfile ("ovrldemo.3", _OVERLAY3_LOAD__, _OVERLAY3_SIZE__)) {
134 if (doesclrscrafterexit ()) {