gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/z80/msxdos/msx_int.s
1 .include "global.s"
2
3 .title "INT Handler"
4 .module INTHandler
5
6 .globl .sys_time, .vbl_done
7 .globl .OUTI128, __shadow_OAM_base
8
9 .area _GSINIT
10
11 ld a, #0xc3
12 di
13 ld (.LS_INT_VECTOR), a
14 ld hl, #_INT_ISR
15 ei
16 ld (.LS_INT_VECTOR + 1), hl
17
18 .area _HOME
19
20 _INT_ISR::
21 push af
22 push bc
23 push de
24 push hl
25 push iy
26 push ix
27
28 in a, (.VDP_STAT)
29 and #.STATF_INT_VBL
30 jp z, 2$
31 ;; handle VBlank
32
33 ld hl, (.sys_time)
34 inc hl
35 ld (.sys_time), hl
36
37 ld a, #1
38 ld (.vbl_done), a
39
40 ;; transfer shadow OAM
41 ld a, (__shadow_OAM_OFF) ; check transfer is OFF
42 or a
43 jp nz, 1$
44 ld hl, #__shadow_OAM_base
45 ld h, (hl)
46 ld l, a ; a == 0 here
47 or h
48 jp z, 1$
49
50 ld c, #.VDP_CMD
51 ld a, #<.VDP_SAT
52 out (c), a
53 ld a, #>.VDP_SAT
54 out (c), a
55 dec c ; c == .VDP_DATA
56 call .OUTI128
57 1$:
58
59 ;; call user-defined VBlank handlers
60 ld hl, (.VBLANK_HANDLER0)
61 ld a, h
62 or l
63 jp z, 2$
64 CALL_HL
65
66 ld hl, (.VBLANK_HANDLER1)
67 ld a, h
68 or l
69 jp z, 2$
70 CALL_HL
71
72 ld hl, (.VBLANK_HANDLER2)
73 ld a, h
74 or l
75 jp z, 2$
76 CALL_HL
77
78 2$:
79 pop ix
80 pop iy
81 pop hl
82 pop de
83 pop bc
84 pop af
85 ei
86 reti
87
88 ; void add_VBL(int_handler h) __z88dk_fastcall __preserves_regs(d, e, iyh, iyl);
89 _add_VBL::
90 ld b, h
91 ld c, l
92
93 .add_VBL::
94 ld hl, #.VBLANK_HANDLER0
95
96 ;; Add interrupt routine in BC to the interrupt list in HL
97 .add_int::
98 1$:
99 ld a, (hl)
100 inc hl
101 or (hl)
102 jr z, 2$
103 inc hl
104 jr 1$
105 2$:
106 ld (hl), b
107 dec hl
108 ld (hl), c
109 ret
110
111 ; void remove_VBL(int_handler h) __z88dk_fastcall __preserves_regs(iyh, iyl);
112 _remove_VBL::
113 ld b, h
114 ld c, l
115
116 ;; Remove interrupt routine in BC from the VBL interrupt list
117 ;; falldown to .remove_int
118 .remove_VBL::
119 ld hl, #.VBLANK_HANDLER0
120
121 ;; Remove interrupt BC from interrupt list HL if it exists
122 ;; Abort if a 0000 is found (end of list)
123 .remove_int::
124 1$:
125 ld e, (hl)
126 inc hl
127 ld d, (hl)
128 inc hl
129 ld a, e
130 or d
131 ret z ; No interrupt found
132
133 ld a, e
134 cp c
135 jr nz, 1$
136
137 ld a, d
138 cp b
139 jr nz, 1$
140
141 ld d, h
142 ld e, l
143 dec de
144 dec de
145
146 ;; Now do a memcpy from here until the end of the list
147 2$:
148 ld a, (hl)
149 ldi
150 or (hl)
151 ldi
152 jr nz, 2$
153
154 _remove_LCD::
155 .remove_LCD::
156 _add_LCD::
157 .add_LCD::
158 _remove_TIM::
159 _remove_SIO::
160 _remove_JOY::
161 _add_TIM::
162 _add_SIO::
163 _add_JOY::
164 .empty_function:
165 ret
166
167 .area _INITIALIZED
168
169 .VBLANK_HANDLER0:
170 .ds 0x02
171 .VBLANK_HANDLER1:
172 .ds 0x02
173 .VBLANK_HANDLER2:
174 .ds 0x02
175 .ds 0x02
176
177 .area _INITIALIZER
178
179 .dw 0x0000
180 .dw 0x0000
181 .dw 0x0000
182 .dw 0x0000
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.