2 * Minimalistic overlay demo program.
4 * 2009-10-02, Oliver Schmidt (ol.sc@web.de)
20 extern void _OVERLAY1_LOAD__[], _OVERLAY1_SIZE__[];
21 extern void _OVERLAY2_LOAD__[], _OVERLAY2_SIZE__[];
22 extern void _OVERLAY3_LOAD__[], _OVERLAY3_SIZE__[];
25 /* Functions resident in an overlay can call back functions resident in the
26 * main program at any time without any precautions. The function log() is
27 * an example for such a function resident in the main program.
31 printf ("Log: %s\n", msg);
35 /* In a real-world overlay program one would probably not use a #pragma but
36 * rather place all the code of certain source files into the overlay by
37 * compiling them with --code-name OVERLAY1.
39 #pragma code-name (push, "OVERLAY1");
43 /* Functions resident in an overlay can access all program variables and
44 * constants at any time without any precautions because those are never
45 * placed in overlays. The string constant below is an example for such
46 * a constant resident in the main program.
48 log ("Calling main from overlay 1");
51 #pragma code-name (pop);
54 #pragma code-name (push, "OVERLAY2");
58 log ("Calling main from overlay 2");
61 #pragma code-name (pop);
64 #pragma code-name (push, "OVERLAY3");
68 log ("Calling main from overlay 3");
71 #pragma code-name(pop);
74 unsigned char loadfile (char *name, void *addr, void *size)
78 int file = open (name, O_RDONLY);
80 log ("Opening overlay file failed");
83 read (file, addr, (unsigned) size);
88 /* Avoid compiler warnings about unused parameters. */
89 (void) addr; (void) size;
90 if (cbm_load (name, getcurrentdevice (), NULL) == 0) {
91 log ("Loading overlay file failed");
102 log ("Calling overlay 1 from main");
104 /* The symbols _OVERLAY1_LOAD__ and _OVERLAY1_SIZE__ were generated by the
105 * linker. They contain the overlay area address and size specific to a
108 if (loadfile ("ovrldemo.1", _OVERLAY1_LOAD__, _OVERLAY1_SIZE__)) {
110 /* The linker makes sure that the call to foo() ends up at the right mem
111 * addr. However it's up to user to make sure that the - right - overlay
112 * is actually loaded before making the the call.
117 log ("Calling overlay 2 from main");
119 /* Replacing one overlay with another one can only happen from the main
120 * program. This implies that an overlay can never load another overlay.
122 if (loadfile ("ovrldemo.2", _OVERLAY2_LOAD__, _OVERLAY2_SIZE__)) {
126 log ("Calling overlay 3 from main");
127 if (loadfile ("ovrldemo.3", _OVERLAY3_LOAD__, _OVERLAY3_SIZE__)) {