src/video/ataricommon/SDL_xbiosevents.c
author Sam Lantinga
Wed, 01 Feb 2006 06:32:25 +0000
changeset 1312 c9b51268668f
parent 1310 a201a8c62522
child 1338 604d73db6802
permissions -rw-r--r--
Updated copyright information and removed rcs id lines (problematic in branch merges)
I batch edited these files, so please let me know if I've accidentally removed anybody's
credit here.
     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 
    23 /*
    24  *	XBIOS mouse & joystick vectors
    25  *
    26  *	Patrice Mandin
    27  */
    28 
    29 #include <stdio.h>
    30 #include <stdlib.h>
    31 #include <string.h>
    32 
    33 #include <mint/osbind.h>
    34 
    35 #include "SDL_events_c.h"
    36 #include "SDL_xbiosevents_c.h"
    37 #include "SDL_xbiosinterrupt_s.h"
    38 
    39 /* Variables */
    40 
    41 int SDL_AtariXbios_enabled=0;
    42 
    43 /* Local variables */
    44 
    45 static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
    46 static Uint16 atari_prevmouseb;	/* buttons */
    47 
    48 /* Functions */
    49 
    50 void SDL_AtariXbios_InstallVectors(int vectors_mask)
    51 {
    52 	void *oldpile;
    53 
    54 	/* Clear variables */
    55 	SDL_AtariXbios_mouseb =
    56 		SDL_AtariXbios_mousex =
    57 		SDL_AtariXbios_mousey =
    58 		SDL_AtariXbios_joystick =
    59 		atari_prevmouseb = 0;
    60 
    61 	if (vectors_mask==0) {
    62 		SDL_AtariXbios_enabled=0;
    63 		return;
    64 	}
    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 	if (SDL_AtariXbios_enabled==0) {
    90 		return;
    91 	}
    92 
    93 	/* Read IKBD vectors base */
    94 	kbdvecs=Kbdvbase();
    95 
    96 	/* Go to supervisor mode */
    97 	oldpile=(void *)Super(NULL);
    98 
    99 	/* Reinstall system vector */
   100 	SDL_AtariXbios_Restore(kbdvecs);
   101 
   102 	/* Back to user mode */
   103 	Super(oldpile);
   104 }
   105 
   106 static int atari_GetButton(int button)
   107 {
   108 	switch(button)
   109 	{
   110 		case 0:
   111 			return SDL_BUTTON_RIGHT;
   112 			break;
   113 		case 1:
   114 		default:
   115 			return SDL_BUTTON_LEFT;
   116 			break;
   117 	}
   118 }
   119 
   120 void SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
   121 {
   122 	if (SDL_AtariXbios_enabled==0) {
   123 		return;
   124 	}
   125 
   126 	/* Mouse motion ? */
   127 	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
   128 		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   129 		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   130 	}
   131 	
   132 	/* Mouse button ? */
   133 	if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
   134 		int i;
   135 
   136 		for (i=0;i<2;i++) {
   137 			int curbutton, prevbutton;
   138 
   139 			curbutton = SDL_AtariXbios_mouseb & (1<<i);
   140 			prevbutton = atari_prevmouseb & (1<<i);
   141 
   142 			if (curbutton && !prevbutton) {
   143 				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
   144 			}
   145 			if (!curbutton && prevbutton) {
   146 				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
   147 			}
   148 		}
   149 		atari_prevmouseb = SDL_AtariXbios_mouseb;
   150 	}
   151 }