src/video/ataricommon/SDL_xbiosevents.c
author Sam Lantinga
Thu, 16 Feb 2006 10:11:48 +0000
changeset 1361 19418e4422cb
parent 1338 604d73db6802
child 1402 d910939febfa
permissions -rw-r--r--
New configure-based build system. Still work in progress, but much improved
     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@libsdl.org
    21 */
    22 
    23 /*
    24  *	XBIOS mouse & joystick vectors
    25  *
    26  *	Patrice Mandin
    27  */
    28 
    29 #include <mint/osbind.h>
    30 
    31 #include "../../events/SDL_events_c.h"
    32 #include "SDL_xbiosevents_c.h"
    33 #include "SDL_xbiosinterrupt_s.h"
    34 
    35 /* Variables */
    36 
    37 int SDL_AtariXbios_enabled=0;
    38 
    39 /* Local variables */
    40 
    41 static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
    42 static Uint16 atari_prevmouseb;	/* buttons */
    43 
    44 /* Functions */
    45 
    46 void SDL_AtariXbios_InstallVectors(int vectors_mask)
    47 {
    48 	void *oldpile;
    49 
    50 	/* Clear variables */
    51 	SDL_AtariXbios_mouseb =
    52 		SDL_AtariXbios_mousex =
    53 		SDL_AtariXbios_mousey =
    54 		SDL_AtariXbios_joystick =
    55 		atari_prevmouseb = 0;
    56 
    57 	if (vectors_mask==0) {
    58 		SDL_AtariXbios_enabled=0;
    59 		return;
    60 	}
    61 
    62 	/* Read IKBD vectors base */
    63 	kbdvecs=Kbdvbase();
    64 
    65 	/* Go to supervisor mode */
    66 	oldpile=(void *)Super(0);
    67 
    68 	/* Install our vectors */
    69 	SDL_AtariXbios_Install(
    70 		kbdvecs,
    71 		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
    72 		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
    73 	);
    74 
    75 	/* Back to user mode */
    76 	Super(oldpile);
    77 
    78 	SDL_AtariXbios_enabled=1;
    79 }
    80 
    81 void SDL_AtariXbios_RestoreVectors(void)
    82 {
    83 	void *oldpile;
    84 
    85 	if (SDL_AtariXbios_enabled==0) {
    86 		return;
    87 	}
    88 
    89 	/* Read IKBD vectors base */
    90 	kbdvecs=Kbdvbase();
    91 
    92 	/* Go to supervisor mode */
    93 	oldpile=(void *)Super(NULL);
    94 
    95 	/* Reinstall system vector */
    96 	SDL_AtariXbios_Restore(kbdvecs);
    97 
    98 	/* Back to user mode */
    99 	Super(oldpile);
   100 }
   101 
   102 static int atari_GetButton(int button)
   103 {
   104 	switch(button)
   105 	{
   106 		case 0:
   107 			return SDL_BUTTON_RIGHT;
   108 			break;
   109 		case 1:
   110 		default:
   111 			return SDL_BUTTON_LEFT;
   112 			break;
   113 	}
   114 }
   115 
   116 void SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
   117 {
   118 	if (SDL_AtariXbios_enabled==0) {
   119 		return;
   120 	}
   121 
   122 	/* Mouse motion ? */
   123 	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
   124 		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   125 		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   126 	}
   127 	
   128 	/* Mouse button ? */
   129 	if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
   130 		int i;
   131 
   132 		for (i=0;i<2;i++) {
   133 			int curbutton, prevbutton;
   134 
   135 			curbutton = SDL_AtariXbios_mouseb & (1<<i);
   136 			prevbutton = atari_prevmouseb & (1<<i);
   137 
   138 			if (curbutton && !prevbutton) {
   139 				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   140 			}
   141 			if (!curbutton && prevbutton) {
   142 				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   143 			}
   144 		}
   145 		atari_prevmouseb = SDL_AtariXbios_mouseb;
   146 	}
   147 }