Relaxing Z88DK To system

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

Relaxing Z88DK To system

Post by FishGuy876 »

Hi,

Is there any way to nicely relax the code created by z88dk to the system thread? Im using a replayer by starkos ( http://www.grimware.org/doku.php/docume ... tion.guide ) to play a piece of music and when my compiled code runs at the same time, it plays about 50% of the speed (presumably because its sharing the system). Is there any code in the CPC side, or z88dk specifically, that I can sleep/wait for VBL to make background system tasks run a bit better? My code doesn't need a very fast fps at all in order to run, and if possible I would like to relax the thread code as much as possible to give resources to the background player.

Ive tried the assembly method on the above page, but cant seem to get it to work properly. Any suggestions?
User avatar
dom
Well known member
Posts: 1195
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

z88dk has both an im2 manager - so you can call code from the interrupt and also a naive preemptive scheduler which will swap between tasks.

Generally music code should be fine when called from the interrupt - so I'd look at im2lib first of all.
FishGuy876
New member
Posts: 7
Joined: Tue Sep 07, 2010 3:27 pm

Post by FishGuy876 »

Hi,

Thanks for your info. I have read up on the interrupts and I am trying to set something up that should call something. However, the Amstrad crashes (resets). All I really want to do at this point is call a function at least once per vbl (some tracks may need to call as much as 2 or 3 times per vbl, but I worry about that later) so I can keep the assembler player going for this music player. Here is some code I used, based on the examples in the wiki:

M_BEGIN_ISR(isr)
{
PlayTrack();
}
M_END_ISR

...

In setup portion of main() :

// Disable Interrupts
#asm
di
#endasm

im2_Init(0xd300); // place z80 in im2 mode with interrupt vector table located at 0xd300
wpoke(0xd300, im2_EmptyISR); // place the default im2_EmptyISR()on vector 0
memcpy(0xd302, 0xd300, 255); // initialize the entire 257-byte im2 table with im2_EmptyISR on all even vectors

bpoke(0xd4d4, 195); // POKE jump instruction at address 0xd4d4 (interrupt service routine entry)
wpoke(0xd4d5, isr); // POKE isr address following the jump instruction

// Re-Enable Interrupts
#asm
ei
#endasm

...

void PlayTrack(void)
{
// Call the starkos asm player for a cycle
#asm
call $4003
#endasm
}

I dont know much about interrupts on Z80, and like I said, all I need to do is set something to call every vbl. Any help I can get is appreciated. Thanks :)
arnoldemu
New member
Posts: 8
Joined: Wed Sep 08, 2010 1:07 pm

Post by arnoldemu »

The problem is that the player may be corrupting the alternative register set, and this is not good when BASIC/Firmare is active.
Did you want the music to play in the background while BASIC was still active?

If so then you need to use the firmware to install a "frame flyback" interrupt.

I don't have this code in C ready.

I can help if you want to disable basic.
Post Reply