Hi,
Working on a C port of a program for one of my friends, using z88dk and the Amstrad CPC. Something I wanted to be able to do was load a file from disk into ram and execute it (to run a replayer for a piece of music he has written). In BASIC, its currently done something like:
MEMORY &1FFF
LOAD"REPLAY.BIN",&4000
LOAD"TRACK.BIN",&4C00
CALL &4000,&4C00
The replayer handles system calls etc. so it doesn?t have to be called every vbl. I was wandering if there is a way to load a block into a memory address of my choice and call/execute it like the above basic example. Thanks.
Calling Memory Resident Code On Amstrad
-
- New member
- Posts: 7
- Joined: Tue Sep 07, 2010 3:27 pm
Yeah, you should be able to use open/read/close to load the block.
For calling you can either cheat: asm("call 0x4000"); or setup an function prototype and call it in a C way, here's one way to do that:
static void func();
#asm
defc _func = 0x4000
#endasm
int main()
{
func();
}
There's several other ways to do it - use a function pointer:
void (*func)();
func = 0x4000;
func();
You can even do it directly though it generates a warning that I can't remember what it means (suppress with -Wn48):
0x4000();
For calling you can either cheat: asm("call 0x4000"); or setup an function prototype and call it in a C way, here's one way to do that:
static void func();
#asm
defc _func = 0x4000
#endasm
int main()
{
func();
}
There's several other ways to do it - use a function pointer:
void (*func)();
func = 0x4000;
func();
You can even do it directly though it generates a warning that I can't remember what it means (suppress with -Wn48):
0x4000();
-
- New member
- Posts: 7
- Joined: Tue Sep 07, 2010 3:27 pm
Hi,
Thanks for the tip. Will this same method work in passing a second parameter to CALL (which is used to tell the replayer where the music data is stored) ?
I got an email from someone suggesting an ASM call function, and again I need to see if I can pass a second parameter to it. My asm skills are not strong hehe. Thanks.
Andy
Thanks for the tip. Will this same method work in passing a second parameter to CALL (which is used to tell the replayer where the music data is stored) ?
I got an email from someone suggesting an ASM call function, and again I need to see if I can pass a second parameter to it. My asm skills are not strong hehe. Thanks.
Andy
-
- New member
- Posts: 7
- Joined: Tue Sep 07, 2010 3:27 pm
-
- New member
- Posts: 7
- Joined: Tue Sep 07, 2010 3:27 pm