Home | History | Annotate | Download | only in ataricommon
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2006 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     This library is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13     Lesser General Public License for more details.
     14 
     15     You should have received a copy of the GNU Lesser General Public
     16     License along with this library; if not, write to the Free Software
     17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     18 
     19     Sam Lantinga
     20     slouken (at) libsdl.org
     21 */
     22 
     23 /*
     24  *	IKBD 6301 interrupt routine
     25  *
     26  *	Patrice Mandin
     27  */
     28 
     29 	.text
     30 
     31 	.globl	_SDL_AtariIkbdInstall
     32 	.globl	_SDL_AtariIkbdUninstall
     33 
     34 	.globl	_SDL_AtariIkbd_keyboard
     35 	.globl	_SDL_AtariIkbd_mouseb
     36 	.globl	_SDL_AtariIkbd_mousex
     37 	.globl	_SDL_AtariIkbd_mousey
     38 	.globl	_SDL_AtariIkbd_joystick
     39 
     40 	.globl	_SDL_AtariIkbd_enabled
     41 
     42 /*--- Install our IKBD vector ---*/
     43 
     44 _SDL_AtariIkbdInstall:
     45 	moveml	d0-d1/a0-a1,sp@-
     46 
     47 	| Disable interrupts
     48 
     49 	movew	#0x2700,sr
     50 
     51 	| Save MFP registers used for keyboard
     52 
     53 	lea	0xfffffa00:w,a0
     54 	btst	#6,a0@(0x09)
     55 	sne		ikbd_ierb
     56 	btst	#6,a0@(0x15)
     57 	sne		ikbd_imrb
     58 
     59 	| Set our routine
     60 
     61 	movel	0x118:w,old_ikbd
     62 	movel	#ikbd,0x118:w
     63 	bset	#6,0xfffffa09:w	| IERB
     64 	bset	#6,0xfffffa15:w	| IMRB
     65 
     66 	| Set mouse relative mode
     67 
     68 	moveb	#8,0xfffffc02:w
     69 
     70 	| Reenable interrupts
     71 
     72 	movew	#0x2300,sr
     73 
     74 	| Interrupts done
     75 
     76 	movew	#0xffff,_SDL_AtariIkbd_enabled
     77 
     78 	moveml	sp@+,d0-d1/a0-a1
     79 	rts
     80 
     81 /*--- Uninstall our IKBD vector ---*/
     82 
     83 _SDL_AtariIkbdUninstall:
     84 	movel	a0,sp@-
     85 
     86 	| Disable interrupts
     87 
     88 	movew	#0x2700,sr
     89 
     90 	| Restore previous MFP registers
     91 
     92 	lea	0xfffffa00:w,a0
     93 
     94 	bclr	#6,a0@(0x09)
     95 	tstb	ikbd_ierb
     96 	beqs	ikbd_restoreierb
     97 	bset	#6,a0@(0x09)
     98 ikbd_restoreierb:
     99 
    100 	bclr	#6,a0@(0x15)
    101 	tstb	ikbd_imrb
    102 	beqs	ikbd_restoreimrb
    103 	bset	#6,a0@(0x15)
    104 ikbd_restoreimrb:
    105 
    106 	movel	old_ikbd,0x118:w
    107 
    108 	| Clear keyboard buffer
    109 
    110 	lea	0xfffffc00:w,a0
    111 ikbd_videbuffer:
    112 	btst	#0,a0@
    113 	beqs	ikbd_finbuffer
    114 	tstb	a0@(0x02)
    115 	bras	ikbd_videbuffer
    116 ikbd_finbuffer:
    117 
    118 	| Reenable interrupts
    119 
    120 	movew	#0x2300,sr
    121 
    122 	movel	sp@+,a0
    123 	rts
    124 
    125 	.bss
    126 
    127 	.even
    128 	.comm	ikbd_ierb,1
    129 	.comm	ikbd_imrb,1
    130 
    131 /*--- Our custom IKBD vector ---*/
    132 
    133 	.text
    134 	.even
    135 	.ascii	"XBRA"
    136 	.ascii	"LSDL"
    137 	.comm	old_ikbd,4*1
    138 ikbd:
    139 	| Check if source is IKBD or MIDI
    140 	btst	#0,0xfffffc00.w
    141 	beqs	ikbd_oldmidi
    142 
    143 	moveml	d0-d1/a0,sp@-
    144 	moveb	0xfffffc02:w,d0
    145 
    146 	| Joystick packet ?
    147 
    148 	cmpb	#0xff,d0
    149 	beqs	ikbd_yes_joystick
    150 
    151 	| Mouse packet ?
    152 
    153 	cmpb	#0xf8,d0
    154 	bmis	ikbd_no_mouse
    155 	cmpb	#0xfc,d0
    156 	bpls	ikbd_no_mouse
    157 
    158 	| Mouse packet, byte #1
    159 
    160 ikbd_yes_mouse:
    161 	andw	#3,d0
    162 	movew	d0,_SDL_AtariIkbd_mouseb
    163 
    164 	movel	#ikbd_mousex,0x118:w
    165 	bras	ikbd_endit_stack
    166 
    167 	| Joystick packet, byte #1
    168 
    169 ikbd_yes_joystick:
    170 	movel	#ikbd_joystick,0x118:w
    171 	bras	ikbd_endit_stack
    172 
    173 	| Keyboard press/release
    174 
    175 ikbd_no_mouse:
    176 	moveb	d0,d1
    177 	lea		_SDL_AtariIkbd_keyboard,a0
    178 	andw	#0x7f,d1
    179 	tas		d0
    180 	spl		a0@(0,d1:w)
    181 
    182 	| End of interrupt
    183 
    184 ikbd_endit_stack:
    185 	moveml	sp@+,d0-d1/a0
    186 ikbd_endit:
    187 	bclr	#6,0xfffffa11:w
    188 	rte
    189 
    190 	| Call old MIDI interrupt
    191 
    192 ikbd_oldmidi:
    193 	movel	old_ikbd,sp@-
    194 	rts
    195 
    196 	| Mouse packet, byte #2
    197 
    198 ikbd_mousex:
    199 
    200 	| Check if source is IKBD or MIDI
    201 	btst	#0,0xfffffc00.w
    202 	beqs	ikbd_oldmidi
    203 
    204 	movew	d0,sp@-
    205 
    206 	moveb	0xfffffc02:w,d0
    207 	extw	d0
    208 	addw	d0,_SDL_AtariIkbd_mousex
    209 
    210 	movew	sp@+,d0
    211 
    212 	movel	#ikbd_mousey,0x118:w
    213 	bras	ikbd_endit
    214 
    215 	| Mouse packet, byte #3
    216 
    217 ikbd_mousey:
    218 
    219 	| Check if source is IKBD or MIDI
    220 	btst	#0,0xfffffc00.w
    221 	beqs	ikbd_oldmidi
    222 
    223 	movew	d0,sp@-
    224 
    225 	moveb	0xfffffc02:w,d0
    226 	extw	d0
    227 	addw	d0,_SDL_AtariIkbd_mousey
    228 
    229 	movew	sp@+,d0
    230 
    231 	movel	#ikbd,0x118:w
    232 	bras	ikbd_endit
    233 
    234 	| Joystick packet, byte #2
    235 
    236 ikbd_joystick:
    237 
    238 	| Check if source is IKBD or MIDI
    239 	btst	#0,0xfffffc00.w
    240 	beqs	ikbd_oldmidi
    241 
    242 	moveb	0xfffffc02:w,_SDL_AtariIkbd_joystick+1
    243 
    244 	movel	#ikbd,0x118:w
    245 	bras	ikbd_endit
    246 
    247 	.data
    248 
    249 	.even
    250 _SDL_AtariIkbd_enabled:
    251 	.word	0
    252 
    253 	.bss
    254 
    255 	.even
    256 	.comm	_SDL_AtariIkbd_keyboard,128
    257 	.comm	_SDL_AtariIkbd_mousex,2
    258 	.comm	_SDL_AtariIkbd_mousey,2
    259 	.comm	_SDL_AtariIkbd_mouseb,2
    260 	.comm	_SDL_AtariIkbd_joystick,2
    261