src/video/ataricommon/SDL_ikbdinterrupt.S
author Ryan C. Gordon <icculus@icculus.org>
Fri, 06 Jan 2006 13:20:10 +0000
changeset 1234 73676c1f56ee
parent 1110 b6fdf299a2f3
child 1312 c9b51268668f
permissions -rw-r--r--
For sanity's sake, removed the '&' when passing copy_row array to asm.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 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     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef SAVE_RCSID
    24 static char rcsid =
    25  "@(#) $Id$";
    26 #endif
    27 
    28 /*
    29  *	IKBD 6301 interrupt routine
    30  *
    31  *	Patrice Mandin
    32  */
    33 
    34 	.text
    35 
    36 	.globl	_SDL_AtariIkbdInstall
    37 	.globl	_SDL_AtariIkbdUninstall
    38 
    39 	.globl	_SDL_AtariIkbd_keyboard
    40 	.globl	_SDL_AtariIkbd_mouseb
    41 	.globl	_SDL_AtariIkbd_mousex
    42 	.globl	_SDL_AtariIkbd_mousey
    43 	.globl	_SDL_AtariIkbd_joystick
    44 
    45 	.globl	_SDL_AtariIkbd_enabled
    46 
    47 /*--- Install our IKBD vector ---*/
    48 
    49 _SDL_AtariIkbdInstall:
    50 	moveml	d0-d1/a0-a1,sp@-
    51 
    52 	| Disable interrupts
    53 
    54 	movew	#0x2700,sr
    55 
    56 	| Save MFP registers used for keyboard
    57 
    58 	lea	0xfffffa00:w,a0
    59 	btst	#6,a0@(0x09)
    60 	sne		ikbd_ierb
    61 	btst	#6,a0@(0x15)
    62 	sne		ikbd_imrb
    63 
    64 	| Set our routine
    65 
    66 	movel	0x118:w,old_ikbd
    67 	movel	#ikbd,0x118:w
    68 	bset	#6,0xfffffa09:w	| IERB
    69 	bset	#6,0xfffffa15:w	| IMRB
    70 
    71 	| Set mouse relative mode
    72 
    73 	moveb	#8,0xfffffc02:w
    74 
    75 	| Reenable interrupts
    76 
    77 	movew	#0x2300,sr
    78 
    79 	| Interrupts done
    80 
    81 	movew	#0xffff,_SDL_AtariIkbd_enabled
    82 
    83 	moveml	sp@+,d0-d1/a0-a1
    84 	rts
    85 
    86 /*--- Uninstall our IKBD vector ---*/
    87 
    88 _SDL_AtariIkbdUninstall:
    89 	movel	a0,sp@-
    90 
    91 	| Disable interrupts
    92 
    93 	movew	#0x2700,sr
    94 
    95 	| Restore previous MFP registers
    96 
    97 	lea	0xfffffa00:w,a0
    98 
    99 	bclr	#6,a0@(0x09)
   100 	tstb	ikbd_ierb
   101 	beqs	ikbd_restoreierb
   102 	bset	#6,a0@(0x09)
   103 ikbd_restoreierb:
   104 
   105 	bclr	#6,a0@(0x15)
   106 	tstb	ikbd_imrb
   107 	beqs	ikbd_restoreimrb
   108 	bset	#6,a0@(0x15)
   109 ikbd_restoreimrb:
   110 
   111 	movel	old_ikbd,0x118:w
   112 
   113 	| Clear keyboard buffer
   114 
   115 	lea	0xfffffc00:w,a0
   116 ikbd_videbuffer:
   117 	btst	#0,a0@
   118 	beqs	ikbd_finbuffer
   119 	tstb	a0@(0x02)
   120 	bras	ikbd_videbuffer
   121 ikbd_finbuffer:
   122 
   123 	| Reenable interrupts
   124 
   125 	movew	#0x2300,sr
   126 
   127 	movel	sp@+,a0
   128 	rts
   129 
   130 	.bss
   131 
   132 	.even
   133 	.comm	ikbd_ierb,1
   134 	.comm	ikbd_imrb,1
   135 
   136 /*--- Our custom IKBD vector ---*/
   137 
   138 	.text
   139 	.even
   140 	.ascii	"XBRA"
   141 	.ascii	"LSDL"
   142 	.comm	old_ikbd,4*1
   143 ikbd:
   144 	| Check if source is IKBD or MIDI
   145 	btst	#0,0xfffffc00.w
   146 	beqs	ikbd_oldmidi
   147 
   148 	moveml	d0-d1/a0,sp@-
   149 	moveb	0xfffffc02:w,d0
   150 
   151 	| Joystick packet ?
   152 	
   153 	cmpb	#0xff,d0
   154 	beqs	ikbd_yes_joystick
   155 
   156 	| Mouse packet ?
   157 
   158 	cmpb	#0xf8,d0
   159 	bmis	ikbd_no_mouse
   160 	cmpb	#0xfc,d0
   161 	bpls	ikbd_no_mouse
   162 
   163 	| Mouse packet, byte #1
   164 
   165 ikbd_yes_mouse:
   166 	andw	#3,d0
   167 	movew	d0,_SDL_AtariIkbd_mouseb
   168 
   169 	movel	#ikbd_mousex,0x118:w
   170 	bras	ikbd_endit_stack
   171 
   172 	| Joystick packet, byte #1
   173 
   174 ikbd_yes_joystick:
   175 	movel	#ikbd_joystick,0x118:w
   176 	bras	ikbd_endit_stack
   177 
   178 	| Keyboard press/release
   179 
   180 ikbd_no_mouse:
   181 	moveb	d0,d1
   182 	lea		_SDL_AtariIkbd_keyboard,a0
   183 	andw	#0x7f,d1
   184 	tas		d0
   185 	spl		a0@(0,d1:w)
   186 
   187 	| End of interrupt
   188 
   189 ikbd_endit_stack:
   190 	moveml	sp@+,d0-d1/a0
   191 ikbd_endit:
   192 	bclr	#6,0xfffffa11:w
   193 	rte
   194 
   195 	| Call old MIDI interrupt
   196 
   197 ikbd_oldmidi:
   198 	movel	old_ikbd,sp@-
   199 	rts
   200 
   201 	| Mouse packet, byte #2
   202 
   203 ikbd_mousex:
   204 
   205 	| Check if source is IKBD or MIDI
   206 	btst	#0,0xfffffc00.w
   207 	beqs	ikbd_oldmidi
   208 
   209 	movew	d0,sp@-
   210 
   211 	moveb	0xfffffc02:w,d0
   212 	extw	d0
   213 	addw	d0,_SDL_AtariIkbd_mousex
   214 
   215 	movew	sp@+,d0
   216 
   217 	movel	#ikbd_mousey,0x118:w
   218 	bras	ikbd_endit
   219 
   220 	| Mouse packet, byte #3
   221 
   222 ikbd_mousey:
   223 
   224 	| Check if source is IKBD or MIDI
   225 	btst	#0,0xfffffc00.w
   226 	beqs	ikbd_oldmidi
   227 
   228 	movew	d0,sp@-
   229 
   230 	moveb	0xfffffc02:w,d0
   231 	extw	d0
   232 	addw	d0,_SDL_AtariIkbd_mousey
   233 
   234 	movew	sp@+,d0
   235 
   236 	movel	#ikbd,0x118:w
   237 	bras	ikbd_endit
   238 
   239 	| Joystick packet, byte #2
   240 
   241 ikbd_joystick:
   242 
   243 	| Check if source is IKBD or MIDI
   244 	btst	#0,0xfffffc00.w
   245 	beqs	ikbd_oldmidi
   246 
   247 	moveb	0xfffffc02:w,_SDL_AtariIkbd_joystick+1
   248 
   249 	movel	#ikbd,0x118:w
   250 	bras	ikbd_endit
   251 
   252 	.data
   253 	
   254 	.even
   255 _SDL_AtariIkbd_enabled:
   256 	.word	0
   257 
   258 	.bss
   259 
   260 	.even
   261 	.comm	_SDL_AtariIkbd_keyboard,128
   262 	.comm	_SDL_AtariIkbd_mousex,2
   263 	.comm	_SDL_AtariIkbd_mousey,2
   264 	.comm	_SDL_AtariIkbd_mouseb,2
   265 	.comm	_SDL_AtariIkbd_joystick,2