I'm trying to write a program where I use interrupts using z88dk.
The idea would be to inject my interrupt callback, do whatever process I want to do (typically changing palette, switching mode, synchronizing things...) and then call the normal interrupt handler.
Reason: this is a very convenient way to handle multiple things, like playing some music while drawing something on the screen, having split screens with different modes/palettes, ...
In a "naked" environment, this would look something like that:
Code: Select all
di
// Save original interrupt callback
ld hl, (0x39)
ld original_interrupt_callback, hl
// Replace by my own interrupt callback
ld hl, interrupt_callback
ld (0x39), hl
ei
However this doesn't work with z88dk because it's using exactly the same trick.
Looking at how it's done, I couldn't find a good way to inject my callback. There doesn't seem to be a hook planned for that.
I managed to get something that seem to work fine by exporting __fw_int_address__ in lib/target/cpc/classic/cpc_crt0.asm
I then setup my interrupts with code like this:
Code: Select all
void setup_interrupt()
{
#asm
di
// Save original interrupt handler address
ld hl, (__fw_int_address__)
ld (_original_int_address), hl
// Add our own handler
ld hl, _interrupt_callback
ld (__fw_int_address__), hl
ei
#endasm
}
What do you think? Is there a way to do it? If not, would it make sense to introduce one?