2012-06-03 16:16:11 +00:00
|
|
|
/*
|
|
|
|
* Minimalistic overlay demo program.
|
|
|
|
*
|
|
|
|
* 2009-10-02, Oliver Schmidt (ol.sc@web.de)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2012-06-24 21:15:39 +00:00
|
|
|
#include <conio.h>
|
2012-06-03 16:16:11 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
extern void _OVERLAY1_LOAD__, _OVERLAY1_SIZE__;
|
|
|
|
extern void _OVERLAY2_LOAD__, _OVERLAY2_SIZE__;
|
|
|
|
extern void _OVERLAY3_LOAD__, _OVERLAY3_SIZE__;
|
|
|
|
|
|
|
|
|
|
|
|
void log (char *msg)
|
|
|
|
{
|
|
|
|
printf ("Log: %s\n", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma code-name (push, "OVERLAY1");
|
|
|
|
|
|
|
|
void foo (void)
|
|
|
|
{
|
|
|
|
log ("Calling main from overlay 1");
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma code-name (pop);
|
|
|
|
|
|
|
|
|
|
|
|
#pragma code-name (push, "OVERLAY2");
|
|
|
|
|
|
|
|
void bar (void)
|
|
|
|
{
|
|
|
|
log ("Calling main from overlay 2");
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma code-name (pop);
|
|
|
|
|
|
|
|
|
|
|
|
#pragma code-name (push, "OVERLAY3");
|
|
|
|
|
|
|
|
void foobar (void)
|
|
|
|
{
|
|
|
|
log ("Calling main from overlay 3");
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma code-name(pop);
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char loadfile (char *name, void *addr, void *size)
|
|
|
|
{
|
|
|
|
int file = open (name, O_RDONLY);
|
|
|
|
if (file == -1) {
|
|
|
|
log ("Opening overlay file failed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
read (file, addr, (unsigned) size);
|
|
|
|
close (file);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void main (void)
|
|
|
|
{
|
|
|
|
log ("Calling overlay 1 from main");
|
2012-06-24 21:15:39 +00:00
|
|
|
if (loadfile ("ovrldemo.1", &_OVERLAY1_LOAD__, &_OVERLAY1_SIZE__)) {
|
2012-06-03 16:16:11 +00:00
|
|
|
foo ();
|
|
|
|
}
|
|
|
|
|
|
|
|
log ("Calling overlay 2 from main");
|
2012-06-24 21:15:39 +00:00
|
|
|
if (loadfile ("ovrldemo.2", &_OVERLAY2_LOAD__, &_OVERLAY2_SIZE__)) {
|
2012-06-03 16:16:11 +00:00
|
|
|
bar ();
|
|
|
|
}
|
|
|
|
|
|
|
|
log ("Calling overlay 3 from main");
|
2012-06-24 21:15:39 +00:00
|
|
|
if (loadfile ("ovrldemo.3", &_OVERLAY3_LOAD__, &_OVERLAY3_SIZE__)) {
|
2012-06-03 16:16:11 +00:00
|
|
|
foobar ();
|
|
|
|
}
|
2012-06-24 21:15:39 +00:00
|
|
|
|
|
|
|
cgetc ();
|
2012-06-03 16:16:11 +00:00
|
|
|
}
|