Forum
Dynamic Interrupt Routine - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: How-To & Tutorials (https://www.boriel.com/forum/forumdisplay.php?fid=13)
+---- Thread: Dynamic Interrupt Routine (/showthread.php?tid=971)



Dynamic Interrupt Routine - emook - 08-17-2020

A simple dynamic IM routine, it will automatically find the nearest suitable IM jump from, ie you can compile at any address. Best to keep below $C000 if you have any paging plans. 

Code:
dim bx as ubyte

Sub SetUpIM()
asm
    di
    ld hl,IMvect
    ld de,IMvect+1
    ld bc,257
    ld a,h
    ld i,a
    ld (hl),a
    ldir
    ld h,a : ld l, a : ld a,$c3 : ld (hl),a : inc hl
    ld de,._ISR : ld (hl),e : inc hl : ld (hl),d
    IM 2
    ei
end asm
end sub


Sub fastcall ISR()

    asm
    push af : push bc : push hl : push de : push ix : push iy
    ex af,af'
    push af : exx
    
    end asm
    
    MyCustomIM()
    
    asm
    
    exx : pop af
    ex af,af'
    pop iy : pop ix : pop de : pop hl : pop bc : pop af
    ei
    'jp 56 uncomment for running with basic
    end asm

end sub

sub MyCustomIM()

    bx = bx + 1 BAND 7 : border bx

end sub

SetUpIM()
'stop uncomment for running in basic

Do
    For y  = 0 to 20
        print at y,0; "testing .... ";bx 
    next y
Loop

ISR()     ' call to ensure ISR doesn't get optimized!

Imtable:
ASM
    ALIGN 256
    IMvect:
    defs 257,0
end asm



RE: Dynamic Interrupt Routine - boriel - 08-18-2020

Some questions:

1) Why the JP 56?
2) You do exx but do not push /pop the EXXed registers?

Ah, one more thing: after discussing with other "hardware geeks", all agreed that the value should be always $FF in the table so, as you suggested, only the last value is taken into account. The thing is that only "bugged" (i.e. very old Kempston interfaces) places random (non $FF) values in the Bus, but well designed ones don't. So...


RE: Dynamic Interrupt Routine - emook - 08-18-2020

JP 56 is for it you want to use while basic is still running, so you could have your interrupt running in the back ground while NORMAL basic is running. So you can set up an inerrupt using zxb then exit back to basic and have it running.

Didn't push the exx regs as I didn't need them in this instance.


RE: Dynamic Interrupt Routine - boriel - 08-18-2020

Ah, I understand, thanks!!!


RE: Dynamic Interrupt Routine - Duefectu - 08-18-2020

In my implementation, in every interrupt I read the $c000 page, switch to the music page (for example), run music, and then switch to the original page before return.

I thing it's important for Next developments where $c000 memory area are used for several resources, at leat in my implementation.


RE: Dynamic Interrupt Routine - boriel - 08-19-2020

(08-18-2020, 10:38 PM)Duefectu Wrote: In my implementation, in every interrupt I read the $c000 page, switch to the music page (for example), run music, and then switch to the original page before return.

I thing it's important for Next developments where $c000 memory area are used for several resources, at leat in my implementation.

I'm working on a more generic implementation now that ZX Basic 2.x is on the way! Stay tuned! Cool


RE: Dynamic Interrupt Routine - worcestersource - 12-27-2020

Woo! Version 2? I just joined today to make the game I always wanted to. Thank you for making your compiler. Smile