The ZX81 uses /INT and /NMI to generate the display. Thus you cannot use any other interrupt during SLOW mode.
Maybe your code will run during FAST mode of ZX81. But restore all registers AND the original int-mode before switching back to SLOW mode to show a result ...
If you check the schema of the ZX81, you will notice that the /NMI line is driven by the ULA and /INT is driven by the Z80. Thus it's not easy to drive the /INT line by an external device ...
What other options could I explore to have some sort of ISR on the ZX81 with z88dk ? I've seen assembly code programs that implement a routine that is called 50 or 60 times a second, after the display is done refreshing, is that possible in C ?
/* zcc +zx81 -create-app disp_isr.c */
/* Inspired by RELOGIO By K. Murta http://zx81.eu5.org/toddysofte.html,
and the z88dk source of gmtime().
Also based on olofsen post https://www.sinclairzxworld.com/viewtopic.php?p=17265#p17265
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <input.h>
#include <zx81.h>
extern int d_file @16396;
unsigned char i, isrText[32], *Display;
void DisplayISR(void)
{
for(i = 0; i < 32; ++i)
isrText[i] = rand()%64;
memcpy(Display,isrText,32);
#asm
jp 0x02a4 ; return to the main program
#endasm
}
void hook()
{
#asm
ld hl,_DisplayISR
ld (0x41b4),hl ; 0x41b4 I guess this address has changed in z88dk ?
ld a,0xc9
ld (0x412e),a ; same here ?
#endasm
}
void main(void)
{
Display = (unsigned char *) d_file + 1;
hook();
while(1);
}