19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *	IKBD 6301 interrupt routine
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall *	Patrice Mandin
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall */
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.text
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbdInstall
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbdUninstall
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbd_keyboard
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbd_mouseb
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbd_mousex
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbd_mousey
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbd_joystick
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.globl	_SDL_AtariIkbd_enabled
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*--- Install our IKBD vector ---*/
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_SDL_AtariIkbdInstall:
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(-16),sp
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0-a1,sp@
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0-a1,sp@-
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Disable interrupts
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	#0x2700,sr
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Save MFP registers used for keyboard
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	0xfffffa00:w,a0
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#6,a0@(0x09)
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sne	d0
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	move.b	d0,ikbd_ierb
639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sne	ikbd_ierb
659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#6,a0@(0x15)
679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sne	d0
699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	move.b	d0,ikbd_imrb
709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	sne	ikbd_imrb
729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Set our routine
759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	0x118:w,d0
789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	d0,old_ikbd
799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	ikbd,a0
809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	a0,0x118:w
819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#6,d0
829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bset	d0,0xfffffa09:w	| IERB
839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bset	d0,0xfffffa15:w	| IMRB
849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	0x118:w,old_ikbd
869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd,0x118:w
879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bset	#6,0xfffffa09:w	| IERB
889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bset	#6,0xfffffa15:w	| IMRB
899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Set mouse relative mode
929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#8,d0
959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	d0,0xfffffc02:w
969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	#8,0xfffffc02:w
989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Reenable interrupts
1019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	#0x2300,sr
1039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Interrupts done
1059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
1079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#0xffff,d0
1089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	d0,_SDL_AtariIkbd_enabled
1099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	sp@,d0-d1/a0-a1
1119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(16),sp
1129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
1139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	#0xffff,_SDL_AtariIkbd_enabled
1149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	sp@+,d0-d1/a0-a1
1169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	rts
1189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*--- Uninstall our IKBD vector ---*/
1209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_SDL_AtariIkbdUninstall:
1229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	a0,sp@-
1239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Disable interrupts
1259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	#0x2700,sr
1279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Restore previous MFP registers
1299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	0xfffffa00:w,a0
1319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bclr	#6,a0@(0x09)
1339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	tstb	ikbd_ierb
1349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_restoreierb
1359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bset	#6,a0@(0x09)
1369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_restoreierb:
1379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bclr	#6,a0@(0x15)
1399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	tstb	ikbd_imrb
1409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_restoreimrb
1419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bset	#6,a0@(0x15)
1429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_restoreimrb:
1439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
1459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	old_ikbd,a0
1469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	a0,0x118:w
1479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
1489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	old_ikbd,0x118:w
1499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Clear keyboard buffer
1529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	0xfffffc00:w,a0
1549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_videbuffer:
1559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#0,a0@
1569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_finbuffer
1579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	tstb	a0@(0x02)
1589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bras	ikbd_videbuffer
1599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_finbuffer:
1609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Reenable interrupts
1629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	#0x2300,sr
1649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	sp@+,a0
1669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	rts
1679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.bss
1699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.even
1719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	ikbd_ierb,1
1729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	ikbd_imrb,1
1739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*--- Our custom IKBD vector ---*/
1759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.text
1779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.even
1789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.ascii	"XBRA"
1799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.ascii	"LSDL"
1809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	old_ikbd,4*1
1819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd:
1829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
1839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(-12),sp
1849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@
1859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
1869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@-
1879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Check if source is IKBD or MIDI
1909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
1919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#0,d0
1929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	d0,0xfffffc00.w
1939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
1949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#0,0xfffffc00.w
1959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
1969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_oldmidi
1979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
1989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	0xfffffc02:w,d0
1999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Joystick packet ?
2019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmpb	#0xff,d0
2039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_yes_joystick
2049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Mouse packet ?
2069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmpb	#0xf8,d0
2089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bmis	ikbd_no_mouse
2099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	cmpb	#0xfc,d0
2109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bpls	ikbd_no_mouse
2119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Mouse packet, byte #1
2139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_yes_mouse:
2159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	andl	#3,d0
2179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	andw	#3,d0
2199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	d0,_SDL_AtariIkbd_mouseb
2219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd_mousex,d0
2249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	d0,0x118:w
2259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd_mousex,0x118:w
2279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bras	ikbd_endit_stack
2299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Joystick packet, byte #1
2319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_yes_joystick:
2339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd_joystick,d0
2359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	d0,0x118:w
2369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd_joystick,0x118:w
2389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bras	ikbd_endit_stack
2409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Keyboard press/release
2429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_no_mouse:
2449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	d0,d1
2459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea		_SDL_AtariIkbd_keyboard,a0
2469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	andl	#0x7f,d1
2489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#7,d0
2499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	spl	d0
2509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	d0,a0@(0,d1:l)
2519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	andw	#0x7f,d1
2539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	tas	d0
2549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	spl	a0@(0,d1:w)
2559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| End of interrupt
2589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_endit_stack:
2609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#6,d0
2629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bclr	d0,0xfffffa11:w
2639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	sp@,d0-d1/a0
2659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(12),sp
2669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	sp@+,d0-d1/a0
2689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bclr	#6,0xfffffa11:w
2709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	rte
2729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Call old MIDI interrupt
2749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_oldmidi:
2769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	sp@,d0-d1/a0
2789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(12),sp
2799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	sp@+,d0-d1/a0
2819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	old_ikbd,sp@-
2849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	rts
2859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Mouse packet, byte #2
2879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_mousex:
2899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(-12),sp
2919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@
2929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
2939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@-
2949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
2959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
2969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Check if source is IKBD or MIDI
2979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
2989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#0,d0
2999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	d0,0xfffffc00.w
3009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#0,0xfffffc00.w
3029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_oldmidi
3049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3059682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	0xfffffc02:w,d0
3069682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	extw	d0
3079682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3089682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	_SDL_AtariIkbd_mousex,d1
3099682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	addl	d1,d0
3109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	d0,_SDL_AtariIkbd_mousex
3119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd_mousey,d0
3139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	d0,0x118:w
3149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	addw	d0,_SDL_AtariIkbd_mousex
3169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd_mousey,0x118:w
3189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bras	ikbd_endit_stack
3209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Mouse packet, byte #3
3229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_mousey:
3249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(-12),sp
3269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@
3279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@-
3299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Check if source is IKBD or MIDI
3329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#0,d0
3349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	d0,0xfffffc00.w
3359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#0,0xfffffc00.w
3379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_oldmidi
3399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	0xfffffc02:w,d0
3419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	extw	d0
3429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	_SDL_AtariIkbd_mousey,d1
3449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	addl	d1,d0
3459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movew	d0,_SDL_AtariIkbd_mousey
3469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd,d0
3489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	d0,0x118:w
3499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	addw	d0,_SDL_AtariIkbd_mousey
3519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd,0x118:w
3539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bras	ikbd_endit_stack
3559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Joystick packet, byte #2
3579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallikbd_joystick:
3599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	lea	sp@(-12),sp
3619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@
3629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveml	d0-d1/a0,sp@-
3649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	| Check if source is IKBD or MIDI
3679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveql	#0,d0
3699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	d0,0xfffffc00.w
3709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	btst	#0,0xfffffc00.w
3729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	beqs	ikbd_oldmidi
3749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#if defined(__mcoldfire__)
3769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	0xfffffc02:w,d0
3779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	d0,_SDL_AtariIkbd_joystick+1
3789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd,d0
3809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	d0,0x118:w
3819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bra	ikbd_endit_stack
3839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#else
3849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	moveb	0xfffffc02:w,_SDL_AtariIkbd_joystick+1
3859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	movel	#ikbd,0x118:w
3879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	bras	ikbd_endit_stack
3899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#endif
3909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.data
3929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.even
3949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall_SDL_AtariIkbd_enabled:
3959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.word	0
3969682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3979682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.bss
3989682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
3999682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.even
4009682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	_SDL_AtariIkbd_keyboard,128
4019682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	_SDL_AtariIkbd_mousex,2
4029682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	_SDL_AtariIkbd_mousey,2
4039682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	_SDL_AtariIkbd_mouseb,2
4049682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	.comm	_SDL_AtariIkbd_joystick,2
405