src/video/ataricommon/SDL_xbiosevents.c
author Patrice Mandin
Sat, 14 Feb 2004 10:12:27 +0000
changeset 820 0b9b4bf3c1e7
parent 769 b8d311d90021
child 1237 a8068adf156b
permissions -rw-r--r--
Important crash fix: system vectors for mouse/joystick were not restored
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2004 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  *	XBIOS mouse & joystick vectors
    30  *
    31  *	Patrice Mandin
    32  */
    33 
    34 #include <stdio.h>
    35 #include <stdlib.h>
    36 #include <string.h>
    37 
    38 #include <mint/osbind.h>
    39 
    40 #include "SDL_events_c.h"
    41 #include "SDL_xbiosevents_c.h"
    42 #include "SDL_xbiosinterrupt_s.h"
    43 
    44 /* Variables */
    45 
    46 int SDL_AtariXbios_enabled=0;
    47 
    48 /* Local variables */
    49 
    50 static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
    51 static Uint16 atari_prevmouseb;	/* buttons */
    52 
    53 /* Functions */
    54 
    55 void SDL_AtariXbios_InstallVectors(int vectors_mask)
    56 {
    57 	void *oldpile;
    58 
    59 	/* Clear variables */
    60 	SDL_AtariXbios_mouseb =
    61 		SDL_AtariXbios_mousex =
    62 		SDL_AtariXbios_mousey =
    63 		SDL_AtariXbios_joystick =
    64 		atari_prevmouseb = 0;
    65 
    66 	/* Read IKBD vectors base */
    67 	kbdvecs=Kbdvbase();
    68 
    69 	/* Go to supervisor mode */
    70 	oldpile=(void *)Super(0);
    71 
    72 	/* Install our vectors */
    73 	SDL_AtariXbios_Install(
    74 		kbdvecs,
    75 		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
    76 		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
    77 	);
    78 
    79 	/* Back to user mode */
    80 	Super(oldpile);
    81 
    82 	SDL_AtariXbios_enabled=1;
    83 }
    84 
    85 void SDL_AtariXbios_RestoreVectors(void)
    86 {
    87 	void *oldpile;
    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)
   117 {
   118 	/* Mouse motion ? */
   119 	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
   120 		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   121 		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   122 	}
   123 	
   124 	/* Mouse button ? */
   125 	if (SDL_AtariXbios_mouseb != atari_prevmouseb) {
   126 		int i;
   127 
   128 		for (i=0;i<2;i++) {
   129 			int curbutton, prevbutton;
   130 
   131 			curbutton = SDL_AtariXbios_mouseb & (1<<i);
   132 			prevbutton = atari_prevmouseb & (1<<i);
   133 
   134 			if (curbutton && !prevbutton) {
   135 				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   136 			}
   137 			if (!curbutton && prevbutton) {
   138 				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   139 			}
   140 		}
   141 		atari_prevmouseb = SDL_AtariXbios_mouseb;
   142 	}
   143 }