/
SDL_ikbdinterrupt.S
404 lines (317 loc) · 6.44 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Sam Lantinga
slouken@libsdl.org
*/
/*
* IKBD 6301 interrupt routine
*
* Patrice Mandin
*/
.text
.globl _SDL_AtariIkbdInstall
.globl _SDL_AtariIkbdUninstall
.globl _SDL_AtariIkbd_keyboard
.globl _SDL_AtariIkbd_mouseb
.globl _SDL_AtariIkbd_mousex
.globl _SDL_AtariIkbd_mousey
.globl _SDL_AtariIkbd_joystick
40
41
.globl _SDL_AtariIkbd_enabled
42
43
44
/*--- Install our IKBD vector ---*/
_SDL_AtariIkbdInstall:
45
46
47
48
#if defined(__mcoldfire__)
lea sp@(-16),sp
moveml d0-d1/a0-a1,sp@
#else
49
moveml d0-d1/a0-a1,sp@-
50
#endif
51
52
| Disable interrupts
53
54
55
56
57
58
59
movew #0x2700,sr
| Save MFP registers used for keyboard
lea 0xfffffa00:w,a0
btst #6,a0@(0x09)
60
61
62
63
64
65
#if defined(__mcoldfire__)
sne d0
move.b d0,ikbd_ierb
#else
sne ikbd_ierb
#endif
66
btst #6,a0@(0x15)
67
68
69
70
71
72
#if defined(__mcoldfire__)
sne d0
move.b d0,ikbd_imrb
#else
sne ikbd_imrb
#endif
73
74
75
| Set our routine
76
77
78
79
80
#if defined(__mcoldfire__)
movel 0x118:w,d0
movel d0,old_ikbd
lea ikbd,a0
movel a0,0x118:w
81
82
83
moveql #6,d0
bset d0,0xfffffa09:w | IERB
bset d0,0xfffffa15:w | IMRB
84
#else
85
86
87
88
movel 0x118:w,old_ikbd
movel #ikbd,0x118:w
bset #6,0xfffffa09:w | IERB
bset #6,0xfffffa15:w | IMRB
89
#endif
90
91
92
| Set mouse relative mode
93
94
95
96
#if defined(__mcoldfire__)
moveql #8,d0
moveb d0,0xfffffc02:w
#else
97
moveb #8,0xfffffc02:w
98
#endif
99
100
101
| Reenable interrupts
102
103
104
105
movew #0x2300,sr
| Interrupts done
106
107
108
109
#if defined(__mcoldfire__)
movel #0xffff,d0
movew d0,_SDL_AtariIkbd_enabled
110
111
moveml sp@,d0-d1/a0-a1
lea sp@(16),sp
112
#else
113
114
movew #0xffff,_SDL_AtariIkbd_enabled
115
moveml sp@+,d0-d1/a0-a1
116
#endif
117
118
119
120
121
122
123
rts
/*--- Uninstall our IKBD vector ---*/
_SDL_AtariIkbdUninstall:
movel a0,sp@-
124
| Disable interrupts
125
126
127
128
129
130
131
132
133
movew #0x2700,sr
| Restore previous MFP registers
lea 0xfffffa00:w,a0
bclr #6,a0@(0x09)
tstb ikbd_ierb
134
beqs ikbd_restoreierb
135
136
137
138
139
bset #6,a0@(0x09)
ikbd_restoreierb:
bclr #6,a0@(0x15)
tstb ikbd_imrb
140
beqs ikbd_restoreimrb
141
142
143
bset #6,a0@(0x15)
ikbd_restoreimrb:
144
145
146
147
#if defined(__mcoldfire__)
movel old_ikbd,a0
movel a0,0x118:w
#else
148
movel old_ikbd,0x118:w
149
#endif
150
151
152
153
154
155
| Clear keyboard buffer
lea 0xfffffc00:w,a0
ikbd_videbuffer:
btst #0,a0@
156
beqs ikbd_finbuffer
157
tstb a0@(0x02)
158
bras ikbd_videbuffer
159
160
ikbd_finbuffer:
161
162
| Reenable interrupts
163
164
165
166
167
movew #0x2300,sr
movel sp@+,a0
rts
168
169
.bss
170
.even
171
172
.comm ikbd_ierb,1
.comm ikbd_imrb,1
173
174
175
176
177
178
/*--- Our custom IKBD vector ---*/
.text
.even
.ascii "XBRA"
179
180
.ascii "LSDL"
.comm old_ikbd,4*1
181
ikbd:
182
183
#if defined(__mcoldfire__)
lea sp@(-12),sp
184
moveml d0-d1/a0,sp@
185
186
187
188
#else
moveml d0-d1/a0,sp@-
#endif
189
| Check if source is IKBD or MIDI
190
191
192
193
#if defined(__mcoldfire__)
moveql #0,d0
btst d0,0xfffffc00.w
#else
194
btst #0,0xfffffc00.w
195
#endif
196
beqs ikbd_oldmidi
197
198
199
moveb 0xfffffc02:w,d0
200
| Joystick packet ?
201
202
cmpb #0xff,d0
203
beqs ikbd_yes_joystick
204
205
| Mouse packet ?
206
207
cmpb #0xf8,d0
208
bmis ikbd_no_mouse
209
cmpb #0xfc,d0
210
bpls ikbd_no_mouse
211
212
213
| Mouse packet, byte #1
214
ikbd_yes_mouse:
215
216
217
#if defined(__mcoldfire__)
andl #3,d0
#else
218
andw #3,d0
219
#endif
220
221
movew d0,_SDL_AtariIkbd_mouseb
222
223
224
225
#if defined(__mcoldfire__)
movel #ikbd_mousex,d0
movel d0,0x118:w
#else
226
movel #ikbd_mousex,0x118:w
227
#endif
228
bras ikbd_endit_stack
229
230
231
| Joystick packet, byte #1
232
ikbd_yes_joystick:
233
234
235
236
#if defined(__mcoldfire__)
movel #ikbd_joystick,d0
movel d0,0x118:w
#else
237
movel #ikbd_joystick,0x118:w
238
#endif
239
bras ikbd_endit_stack
240
241
242
| Keyboard press/release
243
244
ikbd_no_mouse:
moveb d0,d1
245
lea _SDL_AtariIkbd_keyboard,a0
246
247
248
#if defined(__mcoldfire__)
andl #0x7f,d1
btst #7,d0
249
seq d0
250
251
moveb d0,a0@(0,d1:l)
#else
252
andw #0x7f,d1
253
254
btst #7,d0
seq a0@(0,d1:w)
255
#endif
256
257
| End of interrupt
258
259
ikbd_endit_stack:
260
261
262
263
264
265
266
#if defined(__mcoldfire__)
moveql #6,d0
bclr d0,0xfffffa11:w
moveml sp@,d0-d1/a0
lea sp@(12),sp
#else
267
moveml sp@+,d0-d1/a0
268
269
bclr #6,0xfffffa11:w
270
#endif
271
272
rte
273
274
275
| Call old MIDI interrupt
ikbd_oldmidi:
276
277
278
279
280
281
282
#if defined(__mcoldfire__)
moveml sp@,d0-d1/a0
lea sp@(12),sp
#else
moveml sp@+,d0-d1/a0
#endif
283
284
285
movel old_ikbd,sp@-
rts
286
287
| Mouse packet, byte #2
288
ikbd_mousex:
289
290
#if defined(__mcoldfire__)
lea sp@(-12),sp
291
moveml d0-d1/a0,sp@
292
293
294
#else
moveml d0-d1/a0,sp@-
#endif
295
296
| Check if source is IKBD or MIDI
297
298
299
300
#if defined(__mcoldfire__)
moveql #0,d0
btst d0,0xfffffc00.w
#else
301
btst #0,0xfffffc00.w
302
#endif
303
beqs ikbd_oldmidi
304
305
306
moveb 0xfffffc02:w,d0
extw d0
307
308
309
310
311
312
313
314
#if defined(__mcoldfire__)
movew _SDL_AtariIkbd_mousex,d1
addl d1,d0
movew d0,_SDL_AtariIkbd_mousex
movel #ikbd_mousey,d0
movel d0,0x118:w
#else
315
316
317
addw d0,_SDL_AtariIkbd_mousex
movel #ikbd_mousey,0x118:w
318
319
#endif
bras ikbd_endit_stack
320
321
322
| Mouse packet, byte #3
323
ikbd_mousey:
324
325
#if defined(__mcoldfire__)
lea sp@(-12),sp
326
moveml d0-d1/a0,sp@
327
328
329
#else
moveml d0-d1/a0,sp@-
#endif
330
331
| Check if source is IKBD or MIDI
332
333
334
335
#if defined(__mcoldfire__)
moveql #0,d0
btst d0,0xfffffc00.w
#else
336
btst #0,0xfffffc00.w
337
#endif
338
beqs ikbd_oldmidi
339
340
341
moveb 0xfffffc02:w,d0
extw d0
342
343
344
345
346
347
348
349
#if defined(__mcoldfire__)
movew _SDL_AtariIkbd_mousey,d1
addl d1,d0
movew d0,_SDL_AtariIkbd_mousey
movel #ikbd,d0
movel d0,0x118:w
#else
350
351
352
addw d0,_SDL_AtariIkbd_mousey
movel #ikbd,0x118:w
353
354
#endif
bras ikbd_endit_stack
355
356
357
| Joystick packet, byte #2
358
ikbd_joystick:
359
360
#if defined(__mcoldfire__)
lea sp@(-12),sp
361
moveml d0-d1/a0,sp@
362
363
364
#else
moveml d0-d1/a0,sp@-
#endif
365
366
| Check if source is IKBD or MIDI
367
368
369
370
#if defined(__mcoldfire__)
moveql #0,d0
btst d0,0xfffffc00.w
#else
371
btst #0,0xfffffc00.w
372
#endif
373
beqs ikbd_oldmidi
374
375
376
377
378
379
380
381
382
383
#if defined(__mcoldfire__)
moveb 0xfffffc02:w,d0
moveb d0,_SDL_AtariIkbd_joystick+1
movel #ikbd,d0
movel d0,0x118:w
bra ikbd_endit_stack
#else
384
385
386
moveb 0xfffffc02:w,_SDL_AtariIkbd_joystick+1
movel #ikbd,0x118:w
387
388
389
bras ikbd_endit_stack
#endif
390
391
392
393
.data
.even
394
395
_SDL_AtariIkbd_enabled:
.word 0
396
397
398
.bss
399
.even
400
.comm _SDL_AtariIkbd_keyboard,128
401
402
403
404
.comm _SDL_AtariIkbd_mousex,2
.comm _SDL_AtariIkbd_mousey,2
.comm _SDL_AtariIkbd_mouseb,2
.comm _SDL_AtariIkbd_joystick,2