1; Ti83 interrupt 'wrapper' - by Henk Poley 2;----------------------------------------------------------------------------- 3; The z88dk makes extensively use of the shadow registers (EXX and EX AF,AF) 4; The Ti83 system interrupt doesn't preserve (any of) these regs and 5; could thus crash your program. The workaround is to use this interrupt 6; all the time, it saves and restores the (shadow-)registers for the 7; system interrupt. 8; We need the system interrupt when scanning keys (in an easy way), also 9; some (other) ROM calls make use of the system interrupt. if the interrupt 10; is then not running, the calculator would crash. 11;----------------------------------------------------------------------------- 12; Do work: 13; ticalc\smile.c 14; ticalc\dstar.c 15; ticalc\spritest.c 16; ticalc\world.c 17; ticalc2\fib.c 18; 19; Don't work: 20; ticalc\smallgfx.c (83 lib uses dcircle.asm instead of dcircle2.asm) 21; - Displays circles, but doesn't return to prompt... 22; (Runs correctly now we safe IY and restore it at the end of the program) 23; ticalc2\enigma.c 24; - Just crashes... 25; ticalc2\rpn.c 26; - Displays text, but crashes before you can press a key, doesn't respond 27; to anything 28;----------------------------------------------------------------------------- 29 30defc intcount = $878A ; 1 byte needed 31 32 INCLUDE "target/ti83/classic/int83.asm" ; Put interrupt loader here 33 ; HL = $8789 34 inc hl ; We need to intialize variables 35 ld (hl),0 ; by ourself. 36 ; 37 jr jump_over ; Jump over the interrupt code 38 39;----------------- 40; Actual interrupt 41;----------------- 42IntProcStart: 43 push af ; 44 ld a,(intcount) ; Check if own interrupt has quited 45 bit 7,a ; correctly, then bit 7 is zero 46 jr nz,int_fix ; If not zero, fix stack... 47 push hl ; 48 push de ; 49 push bc ; 50 push iy ; 51 ld iy,_IY_TABLE ; 52 ld hl,intcount ; If a 'direct interrupt' occures 53 set 7,(hl) ; right after the TIOS-int, then 54 ; we want bit 7 to be set... 55exit_interrupt: 56 exx ; Swap to shadow registers. 57 ex af,af ; So the TIOS swaps back to the 58 ; normal ones... (the ones we saved 59 ; with push/pops) 60 rst $38 ; 61 di ; 'BIG' HOLE HERE... (TIOS does ei...) 62 di ; 63 ex af,af ; 64 exx ; 65 ; 66 ld hl,intcount ; Interrupt returned correctly, so 67 res 7,(hl) ; we reset our error-condition... 68 ; 69 pop iy ; 70 pop bc ; 71 pop de ; 72 pop hl ; 73 pop af ; 74 ei ; 75 ret ; 76int_fix: 77 pop af ; Pop AF back 78 ex af,af ; Fix shadowregs back 79 exx ; 80 pop bc ; Pop the returnpoint of RST $38 81 ; from the stack 82 jr exit_interrupt ; Continue with interrupt 83IntProcEnd: 84jump_over: 85 86; Memory usage in statvars: 87; ------------------------------------------- 88; $858F / $85FF - 113 bytes - free 89; $8600 / $8700 - 256 bytes - IV table 90; $8701 / $8786 - 134 bytes - free 91; $8787 / $8789 - 3 bytes - JP IntProcStart 92; $878A - 1 byte - intcount <-- 93; $878B / $87A2 - 24 bytes - free 94; ------------------------------------------- 95