src/video/ataricommon/SDL_xbiosevents.c
changeset 305 9c6613983e85
child 331 e9278438fb3b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/ataricommon/SDL_xbiosevents.c	Sun Mar 10 03:33:59 2002 +0000
     1.3 @@ -0,0 +1,138 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +#ifdef SAVE_RCSID
    1.27 +static char rcsid =
    1.28 + "@(#) $Id$";
    1.29 +#endif
    1.30 +
    1.31 +/*
    1.32 + *	XBIOS mouse & joystick vectors
    1.33 + *
    1.34 + *	Patrice Mandin
    1.35 + */
    1.36 +
    1.37 +#include <stdlib.h>
    1.38 +#include <string.h>
    1.39 +#include <mint/osbind.h>
    1.40 +
    1.41 +#include "SDL_events_c.h"
    1.42 +#include "SDL_xbiosevents_c.h"
    1.43 +#include "SDL_xbiosinterrupt_s.h"
    1.44 +
    1.45 +/* Variables */
    1.46 +
    1.47 +int SDL_AtariXbios_enabled=0;
    1.48 +
    1.49 +static _KBDVECS *kbdvecs;		/* Pointer to access vectors */
    1.50 +static _KBDVECS sys_kbdvecs;	/* Backup of system vectors */
    1.51 +static Uint16 atari_prevmouseb;	/* buttons */
    1.52 +
    1.53 +void SDL_AtariXbios_InstallVectors(int vectors_mask)
    1.54 +{
    1.55 +	void *oldpile;
    1.56 +
    1.57 +	/* Clear variables */
    1.58 +	SDL_AtariXbios_mouseb =
    1.59 +		SDL_AtariXbios_mousex =
    1.60 +		SDL_AtariXbios_mousey =
    1.61 +		SDL_AtariXbios_joystick =
    1.62 +		atari_prevmouseb = 0;
    1.63 +
    1.64 +	/* Read IKBD vectors base */
    1.65 +	kbdvecs=Kbdvbase();
    1.66 +
    1.67 +	/* Go to supervisor mode */
    1.68 +	oldpile=(void *)Super(0);
    1.69 +
    1.70 +	/* Backup system vectors */
    1.71 +	memcpy(&sys_kbdvecs, kbdvecs, sizeof(_KBDVECS));
    1.72 +
    1.73 +	/* Install our vector */
    1.74 +	SDL_AtariXbios_Install(
    1.75 +		kbdvecs,
    1.76 +		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
    1.77 +		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
    1.78 +	);
    1.79 +
    1.80 +	/* Back to user mode */
    1.81 +	Super(oldpile);
    1.82 +
    1.83 +	SDL_AtariXbios_enabled=1;
    1.84 +}
    1.85 +
    1.86 +void SDL_AtariXbios_RestoreVectors(void)
    1.87 +{
    1.88 +	void *oldpile;
    1.89 +
    1.90 +	/* Go to supervisor mode */
    1.91 +	oldpile=(void *)Super(NULL);
    1.92 +
    1.93 +	/* Reinstall system vector */
    1.94 +	SDL_AtariXbios_Install(kbdvecs,sys_kbdvecs.mousevec,sys_kbdvecs.joyvec);
    1.95 +
    1.96 +	/* Back to user mode */
    1.97 +	Super(oldpile);
    1.98 +}
    1.99 +
   1.100 +static int atari_GetButton(int button)
   1.101 +{
   1.102 +	switch(button)
   1.103 +	{
   1.104 +		case 0:
   1.105 +			return SDL_BUTTON_RIGHT;
   1.106 +			break;
   1.107 +		case 1:
   1.108 +		default:
   1.109 +			return SDL_BUTTON_LEFT;
   1.110 +			break;
   1.111 +	}
   1.112 +}
   1.113 +
   1.114 +void SDL_AtariXbios_PostMouseEvents(_THIS)
   1.115 +{
   1.116 +	/* Mouse motion ? */
   1.117 +	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
   1.118 +		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   1.119 +		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   1.120 +	}
   1.121 +	
   1.122 +	/* Mouse button ? */
   1.123 +	if (SDL_AtariXbios_mouseb != atari_prevmouseb) {
   1.124 +		int i;
   1.125 +
   1.126 +		for (i=0;i<2;i++) {
   1.127 +			int curbutton, prevbutton;
   1.128 +
   1.129 +			curbutton = SDL_AtariXbios_mouseb & (1<<i);
   1.130 +			prevbutton = atari_prevmouseb & (1<<i);
   1.131 +
   1.132 +			if (curbutton & !prevbutton) {
   1.133 +				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   1.134 +			}
   1.135 +			if (!curbutton & prevbutton) {
   1.136 +				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   1.137 +			}
   1.138 +		}
   1.139 +		atari_prevmouseb = SDL_AtariXbios_mouseb;
   1.140 +	}
   1.141 +}