Home | History | Annotate | Download | only in ataricommon
      1 /*
      2     SDL - Simple DirectMedia Layer
      3     Copyright (C) 1997-2012 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 #include "SDL_config.h"
     23 
     24 /*
     25  *	XBIOS mouse & joystick vectors
     26  *
     27  *	Patrice Mandin
     28  */
     29 
     30 #include <mint/osbind.h>
     31 
     32 #include "../../events/SDL_events_c.h"
     33 #include "SDL_atarisuper.h"
     34 #include "SDL_xbiosevents_c.h"
     35 #include "SDL_xbiosinterrupt_s.h"
     36 
     37 /* Variables */
     38 
     39 int SDL_AtariXbios_enabled=0;
     40 
     41 /* Local variables */
     42 
     43 static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
     44 static Uint16 atari_prevmouseb;	/* buttons */
     45 
     46 /* Functions */
     47 
     48 void SDL_AtariXbios_InstallVectors(int vectors_mask)
     49 {
     50 	void *oldpile;
     51 
     52 	/* Clear variables */
     53 	SDL_AtariXbios_mouselock =
     54 		SDL_AtariXbios_mouseb =
     55 		SDL_AtariXbios_mousex =
     56 		SDL_AtariXbios_mousey =
     57 		SDL_AtariXbios_joystick =
     58 		atari_prevmouseb = 0;
     59 
     60 	if (vectors_mask==0) {
     61 		SDL_AtariXbios_enabled=0;
     62 		return;
     63 	}
     64 
     65 	/* Read IKBD vectors base */
     66 	kbdvecs=Kbdvbase();
     67 
     68 	/* Go to supervisor mode */
     69 	oldpile=(void *)Super(0);
     70 
     71 	/* Install our vectors */
     72 	SDL_AtariXbios_Install(
     73 		kbdvecs,
     74 		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
     75 		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
     76 	);
     77 
     78 	/* Back to user mode */
     79 	SuperToUser(oldpile);
     80 
     81 	SDL_AtariXbios_enabled=1;
     82 }
     83 
     84 void SDL_AtariXbios_RestoreVectors(void)
     85 {
     86 	void *oldpile;
     87 
     88 	if (SDL_AtariXbios_enabled==0) {
     89 		return;
     90 	}
     91 
     92 	/* Read IKBD vectors base */
     93 	kbdvecs=Kbdvbase();
     94 
     95 	/* Go to supervisor mode */
     96 	oldpile=(void *)Super(NULL);
     97 
     98 	/* Reinstall system vector */
     99 	SDL_AtariXbios_Restore(kbdvecs);
    100 
    101 	/* Back to user mode */
    102 	SuperToUser(oldpile);
    103 }
    104 
    105 static int atari_GetButton(int button)
    106 {
    107 	switch(button)
    108 	{
    109 		case 0:
    110 			return SDL_BUTTON_RIGHT;
    111 			break;
    112 		case 1:
    113 		default:
    114 			return SDL_BUTTON_LEFT;
    115 			break;
    116 	}
    117 }
    118 
    119 void SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
    120 {
    121 	if (SDL_AtariXbios_enabled==0) {
    122 		return;
    123 	}
    124 
    125 	/* Mouse motion ? */
    126 	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
    127 		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
    128 		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
    129 	}
    130 
    131 	/* Mouse button ? */
    132 	if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
    133 		int i;
    134 
    135 		for (i=0;i<2;i++) {
    136 			int curbutton, prevbutton;
    137 
    138 			curbutton = SDL_AtariXbios_mouseb & (1<<i);
    139 			prevbutton = atari_prevmouseb & (1<<i);
    140 
    141 			if (curbutton && !prevbutton) {
    142 				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
    143 			}
    144 			if (!curbutton && prevbutton) {
    145 				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
    146 			}
    147 		}
    148 		atari_prevmouseb = SDL_AtariXbios_mouseb;
    149 	}
    150 }
    151 
    152 void SDL_AtariXbios_LockMousePosition(SDL_bool lockPosition)
    153 {
    154 	SDL_AtariXbios_mouselock = lockPosition;
    155 }
    156