src/video/ataricommon/SDL_xbiosevents.c
author Patrice Mandin
Fri, 06 Jan 2006 22:24:09 +0000
changeset 1237 a8068adf156b
parent 820 0b9b4bf3c1e7
child 1310 a201a8c62522
permissions -rw-r--r--
Disable XBIOS driver for mouse and joystick under MiNT. Will write a driver for /dev/mouse later.
     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 	if (vectors_mask==0) {
    67 		SDL_AtariXbios_enabled=0;
    68 		return;
    69 	}
    70 
    71 	/* Read IKBD vectors base */
    72 	kbdvecs=Kbdvbase();
    73 
    74 	/* Go to supervisor mode */
    75 	oldpile=(void *)Super(0);
    76 
    77 	/* Install our vectors */
    78 	SDL_AtariXbios_Install(
    79 		kbdvecs,
    80 		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
    81 		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
    82 	);
    83 
    84 	/* Back to user mode */
    85 	Super(oldpile);
    86 
    87 	SDL_AtariXbios_enabled=1;
    88 }
    89 
    90 void SDL_AtariXbios_RestoreVectors(void)
    91 {
    92 	void *oldpile;
    93 
    94 	if (SDL_AtariXbios_enabled==0) {
    95 		return;
    96 	}
    97 
    98 	/* Read IKBD vectors base */
    99 	kbdvecs=Kbdvbase();
   100 
   101 	/* Go to supervisor mode */
   102 	oldpile=(void *)Super(NULL);
   103 
   104 	/* Reinstall system vector */
   105 	SDL_AtariXbios_Restore(kbdvecs);
   106 
   107 	/* Back to user mode */
   108 	Super(oldpile);
   109 }
   110 
   111 static int atari_GetButton(int button)
   112 {
   113 	switch(button)
   114 	{
   115 		case 0:
   116 			return SDL_BUTTON_RIGHT;
   117 			break;
   118 		case 1:
   119 		default:
   120 			return SDL_BUTTON_LEFT;
   121 			break;
   122 	}
   123 }
   124 
   125 void SDL_AtariXbios_PostMouseEvents(_THIS)
   126 {
   127 	if (SDL_AtariXbios_enabled==0) {
   128 		return;
   129 	}
   130 
   131 	/* Mouse motion ? */
   132 	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
   133 		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   134 		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   135 	}
   136 	
   137 	/* Mouse button ? */
   138 	if (SDL_AtariXbios_mouseb != atari_prevmouseb) {
   139 		int i;
   140 
   141 		for (i=0;i<2;i++) {
   142 			int curbutton, prevbutton;
   143 
   144 			curbutton = SDL_AtariXbios_mouseb & (1<<i);
   145 			prevbutton = atari_prevmouseb & (1<<i);
   146 
   147 			if (curbutton && !prevbutton) {
   148 				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   149 			}
   150 			if (!curbutton && prevbutton) {
   151 				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   152 			}
   153 		}
   154 		atari_prevmouseb = SDL_AtariXbios_mouseb;
   155 	}
   156 }