Ti Constructor
 
Loading...
Searching...
No Matches
interupt_loader.c
1#pragma once
2
3
4// Location of line 45 at:
5// https://github.com/z88dk/z88dk/blob/master/lib/target/ti83p/classic/intwrap83p.asm
6//
7
8#define interrupt_rst38 24 + 0x8A8A
9
10#define basepage 0x8AFF
11// Only have 69 bytes to work with
12#define loader_point 48 + 0x8A8A
13
14#define interrupt_mask 0b00001011
15#define interrupt_acknowledge 0b00001000
16
17
18// Effectivly "ret" but to +3 of normal value, and acknowledges that interupt ran
19#define CI_RET pop de \ ld hl, 7 \ add hl, de \\
20 ld a, interrupt_mask \ out (3), a \
21 \ jp (hl)
22
23
24// Restore old opcodes to the interupt ram
25void unpatch_ram() __naked{
26 #asm
27 di
28#ifdef FLASH_APP
29 ld hl, interrupt_rst38-2
30#else
31 ld hl, 0x8A8A+1
32 ld e, (hl)
33 inc hl
34 ld d, (hl)
35 ld hl, 24-2 // Calculate where location based on the jp instruction
36 add hl, de // created by the interupt loader
37#endif
38 ld (hl), $D9 // Exx
39 inc hl
40 ld (hl), $08 // ex af, af
41 inc hl
42 ld (hl), $FF // rst 38h
43 inc hl
44 ld (hl), $F3 // di
45 inc hl
46 ld (hl), $F3 // di
47 inc hl
48 ld (hl), $08 // ex af, af
49 inc hl
50 ld (hl), $D9 // Exx
51
52
53 ret
54
55
56 #endasm
57}
58
59void patch_ram() __naked{
60 #asm
61 di
62
63#ifdef FLASH_APP
64 in a,(6)
65 ld (basepage), a
66
67 ld hl, interrupt_rst38-2
68
69#else
70 ld hl, 0x8A8A+1
71 ld e, (hl)
72 inc hl
73 ld d, (hl)
74 ld hl, 24-2 // Calculate where location based on the jp instruction
75 add hl, de // created by the interupt loader
76
77#endif
78 ld a, 0xF3
79 ld (hl), a // Replace "exx" with "di"
80 inc hl
81 xor a, a
82 ld (hl), a // Replace "ex af,af" with "nop"
83 inc hl
84
85
86
87 // replace calling the default system interupts with calling the interupt loader
88 ld (hl), 0xCd // "Call" opcode
89 inc hl
90 #ifdef FLASH_APP
91 ld (hl), (loader_point) &0xFF
92 inc hl
93 ld (hl), (loader_point) >> 8
94 #else
95 ld (hl), (USER_INTERUPT_LOADER) &0xFF
96 inc hl
97 ld (hl), (USER_INTERUPT_LOADER) >> 8
98 #endif
99 xor a, a
100 inc hl
101 ld (hl), a // Replace "ex af,af" with "nop"
102 inc hl
103 ld (hl), a // Replace "exx" with "nop"
104
105 #ifdef FLASH_APP
106 ld hl, USER_INTERUPT_LOADER
107 ld de, loader_point
108 ld bc, END_OF_USER_INTERUPT_LOADER-USER_INTERUPT_LOADER
109
110 ldir
111 #endif
112 ei
113 ret
114 #endasm
115
116
117
118
119 #asm
120USER_INTERUPT_LOADER:
121#ifdef FLASH_APP
122
123 in a,(6)
124 push af
125 ld a,(basepage)
126 out (6),a
127#endif
128 call USER_INTERUPT
129
130 exx
131 ex af, af
132
133 rst $38 ;
134 di ; 'BIG' HOLE HERE... (TIOS does ei...)
135 di
136 exx
137 ex af, af
138
139 // Effectivly rets here on CI_RET by adding to the return value
140
141#ifdef FLASH_APP
142 pop af
143 out (6),a
144#endif
145 ret
146END_OF_USER_INTERUPT_LOADER:
147 #endasm
148
149
150
151
152}