Calling Memory Resident Code On Amstrad

Amstrad CPC and NC systems
Post Reply
FishGuy876
New member
Posts: 7
Joined: Tue Sep 07, 2010 3:27 pm

Calling Memory Resident Code On Amstrad

Post by FishGuy876 »

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.
User avatar
dom
Well known member
Posts: 1195
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

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();
FishGuy876
New member
Posts: 7
Joined: Tue Sep 07, 2010 3:27 pm

Post by FishGuy876 »

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
arnoldemu
New member
Posts: 8
Joined: Wed Sep 08, 2010 1:07 pm

Post by arnoldemu »

I see in another thread that you want to play starkos music.

I have created a library for z88dk which you could use to play starkos music.
You need to including it in your build, and then you can have the player and music data in memory how you wish without needing to call direct like this.
FishGuy876
New member
Posts: 7
Joined: Tue Sep 07, 2010 3:27 pm

Post by FishGuy876 »

Hi,

YES! Please send me the info for replaying starkos music directly in z88dk. I have several tracks that are loaded into memory that get switched at different points. You can link here, or email me at andy@f1-software.com thanks!
FishGuy876
New member
Posts: 7
Joined: Tue Sep 07, 2010 3:27 pm

Post by FishGuy876 »

Hi, certainly let me know when you are able to send that, I looked on the z88dk pages and can find no mention of it, so I am assuming its not included with the compiler as default. Thanks again :)
arnoldemu
New member
Posts: 8
Joined: Wed Sep 08, 2010 1:07 pm

Post by arnoldemu »

FishGuy876 wrote:Hi, certainly let me know when you are able to send that, I looked on the z88dk pages and can find no mention of it, so I am assuming its not included with the compiler as default. Thanks again :)
You have mail.
Post Reply