src/video/ataricommon/SDL_xbiosevents.c
author Sam Lantinga
Wed, 17 May 2006 08:18:28 +0000
branchSDL-1.3
changeset 1659 14717b52abc0
parent 1402 d910939febfa
child 1662 782fd950bd46
child 1895 c121d94672cb
child 3857 be01e0b82dca
permissions -rw-r--r--
Merge trunk-1.3-3
     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 #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_xbiosevents_c.h"
    34 #include "SDL_xbiosinterrupt_s.h"
    35 
    36 /* Variables */
    37 
    38 int SDL_AtariXbios_enabled=0;
    39 
    40 /* Local variables */
    41 
    42 static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
    43 static Uint16 atari_prevmouseb;	/* buttons */
    44 
    45 /* Functions */
    46 
    47 void SDL_AtariXbios_InstallVectors(int vectors_mask)
    48 {
    49 	void *oldpile;
    50 
    51 	/* Clear variables */
    52 	SDL_AtariXbios_mouseb =
    53 		SDL_AtariXbios_mousex =
    54 		SDL_AtariXbios_mousey =
    55 		SDL_AtariXbios_joystick =
    56 		atari_prevmouseb = 0;
    57 
    58 	if (vectors_mask==0) {
    59 		SDL_AtariXbios_enabled=0;
    60 		return;
    61 	}
    62 
    63 	/* Read IKBD vectors base */
    64 	kbdvecs=Kbdvbase();
    65 
    66 	/* Go to supervisor mode */
    67 	oldpile=(void *)Super(0);
    68 
    69 	/* Install our vectors */
    70 	SDL_AtariXbios_Install(
    71 		kbdvecs,
    72 		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
    73 		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
    74 	);
    75 
    76 	/* Back to user mode */
    77 	Super(oldpile);
    78 
    79 	SDL_AtariXbios_enabled=1;
    80 }
    81 
    82 void SDL_AtariXbios_RestoreVectors(void)
    83 {
    84 	void *oldpile;
    85 
    86 	if (SDL_AtariXbios_enabled==0) {
    87 		return;
    88 	}
    89 
    90 	/* Read IKBD vectors base */
    91 	kbdvecs=Kbdvbase();
    92 
    93 	/* Go to supervisor mode */
    94 	oldpile=(void *)Super(NULL);
    95 
    96 	/* Reinstall system vector */
    97 	SDL_AtariXbios_Restore(kbdvecs);
    98 
    99 	/* Back to user mode */
   100 	Super(oldpile);
   101 }
   102 
   103 static int atari_GetButton(int button)
   104 {
   105 	switch(button)
   106 	{
   107 		case 0:
   108 			return SDL_BUTTON_RIGHT;
   109 			break;
   110 		case 1:
   111 		default:
   112 			return SDL_BUTTON_LEFT;
   113 			break;
   114 	}
   115 }
   116 
   117 void SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
   118 {
   119 	if (SDL_AtariXbios_enabled==0) {
   120 		return;
   121 	}
   122 
   123 	/* Mouse motion ? */
   124 	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
   125 		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   126 		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   127 	}
   128 	
   129 	/* Mouse button ? */
   130 	if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
   131 		int i;
   132 
   133 		for (i=0;i<2;i++) {
   134 			int curbutton, prevbutton;
   135 
   136 			curbutton = SDL_AtariXbios_mouseb & (1<<i);
   137 			prevbutton = atari_prevmouseb & (1<<i);
   138 
   139 			if (curbutton && !prevbutton) {
   140 				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   141 			}
   142 			if (!curbutton && prevbutton) {
   143 				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   144 			}
   145 		}
   146 		atari_prevmouseb = SDL_AtariXbios_mouseb;
   147 	}
   148 }