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.
slouken@305
     1
/*
slouken@305
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@305
     4
slouken@305
     5
    This library is free software; you can redistribute it and/or
slouken@305
     6
    modify it under the terms of the GNU Library General Public
slouken@305
     7
    License as published by the Free Software Foundation; either
slouken@305
     8
    version 2 of the License, or (at your option) any later version.
slouken@305
     9
slouken@305
    10
    This library is distributed in the hope that it will be useful,
slouken@305
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@305
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@305
    13
    Library General Public License for more details.
slouken@305
    14
slouken@305
    15
    You should have received a copy of the GNU Library General Public
slouken@305
    16
    License along with this library; if not, write to the Free
slouken@305
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@305
    18
slouken@305
    19
    Sam Lantinga
slouken@305
    20
    slouken@libsdl.org
slouken@305
    21
*/
slouken@305
    22
slouken@305
    23
#ifdef SAVE_RCSID
slouken@305
    24
static char rcsid =
slouken@305
    25
 "@(#) $Id$";
slouken@305
    26
#endif
slouken@305
    27
slouken@305
    28
/*
slouken@305
    29
 *	XBIOS mouse & joystick vectors
slouken@305
    30
 *
slouken@305
    31
 *	Patrice Mandin
slouken@305
    32
 */
slouken@305
    33
patmandin@820
    34
#include <stdio.h>
slouken@305
    35
#include <stdlib.h>
slouken@305
    36
#include <string.h>
patmandin@820
    37
slouken@305
    38
#include <mint/osbind.h>
slouken@305
    39
slouken@305
    40
#include "SDL_events_c.h"
slouken@305
    41
#include "SDL_xbiosevents_c.h"
slouken@305
    42
#include "SDL_xbiosinterrupt_s.h"
slouken@305
    43
slouken@305
    44
/* Variables */
slouken@305
    45
slouken@305
    46
int SDL_AtariXbios_enabled=0;
slouken@305
    47
patmandin@820
    48
/* Local variables */
patmandin@820
    49
patmandin@820
    50
static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
slouken@305
    51
static Uint16 atari_prevmouseb;	/* buttons */
slouken@305
    52
patmandin@820
    53
/* Functions */
patmandin@820
    54
slouken@305
    55
void SDL_AtariXbios_InstallVectors(int vectors_mask)
slouken@305
    56
{
slouken@305
    57
	void *oldpile;
slouken@305
    58
slouken@305
    59
	/* Clear variables */
slouken@305
    60
	SDL_AtariXbios_mouseb =
slouken@305
    61
		SDL_AtariXbios_mousex =
slouken@305
    62
		SDL_AtariXbios_mousey =
slouken@305
    63
		SDL_AtariXbios_joystick =
slouken@305
    64
		atari_prevmouseb = 0;
slouken@305
    65
patmandin@1237
    66
	if (vectors_mask==0) {
patmandin@1237
    67
		SDL_AtariXbios_enabled=0;
patmandin@1237
    68
		return;
patmandin@1237
    69
	}
patmandin@1237
    70
slouken@305
    71
	/* Read IKBD vectors base */
slouken@305
    72
	kbdvecs=Kbdvbase();
slouken@305
    73
slouken@305
    74
	/* Go to supervisor mode */
slouken@305
    75
	oldpile=(void *)Super(0);
slouken@305
    76
patmandin@820
    77
	/* Install our vectors */
slouken@305
    78
	SDL_AtariXbios_Install(
slouken@305
    79
		kbdvecs,
slouken@305
    80
		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
slouken@305
    81
		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
slouken@305
    82
	);
slouken@305
    83
slouken@305
    84
	/* Back to user mode */
slouken@305
    85
	Super(oldpile);
slouken@305
    86
slouken@305
    87
	SDL_AtariXbios_enabled=1;
slouken@305
    88
}
slouken@305
    89
slouken@305
    90
void SDL_AtariXbios_RestoreVectors(void)
slouken@305
    91
{
slouken@305
    92
	void *oldpile;
slouken@305
    93
patmandin@1237
    94
	if (SDL_AtariXbios_enabled==0) {
patmandin@1237
    95
		return;
patmandin@1237
    96
	}
patmandin@1237
    97
patmandin@820
    98
	/* Read IKBD vectors base */
patmandin@820
    99
	kbdvecs=Kbdvbase();
patmandin@820
   100
slouken@305
   101
	/* Go to supervisor mode */
slouken@305
   102
	oldpile=(void *)Super(NULL);
slouken@305
   103
slouken@305
   104
	/* Reinstall system vector */
patmandin@820
   105
	SDL_AtariXbios_Restore(kbdvecs);
slouken@305
   106
slouken@305
   107
	/* Back to user mode */
slouken@305
   108
	Super(oldpile);
slouken@305
   109
}
slouken@305
   110
slouken@305
   111
static int atari_GetButton(int button)
slouken@305
   112
{
slouken@305
   113
	switch(button)
slouken@305
   114
	{
slouken@305
   115
		case 0:
slouken@305
   116
			return SDL_BUTTON_RIGHT;
slouken@305
   117
			break;
slouken@305
   118
		case 1:
slouken@305
   119
		default:
slouken@305
   120
			return SDL_BUTTON_LEFT;
slouken@305
   121
			break;
slouken@305
   122
	}
slouken@305
   123
}
slouken@305
   124
slouken@305
   125
void SDL_AtariXbios_PostMouseEvents(_THIS)
slouken@305
   126
{
patmandin@1237
   127
	if (SDL_AtariXbios_enabled==0) {
patmandin@1237
   128
		return;
patmandin@1237
   129
	}
patmandin@1237
   130
slouken@305
   131
	/* Mouse motion ? */
slouken@305
   132
	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
slouken@305
   133
		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
slouken@305
   134
		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
slouken@305
   135
	}
slouken@305
   136
	
slouken@305
   137
	/* Mouse button ? */
slouken@305
   138
	if (SDL_AtariXbios_mouseb != atari_prevmouseb) {
slouken@305
   139
		int i;
slouken@305
   140
slouken@305
   141
		for (i=0;i<2;i++) {
slouken@305
   142
			int curbutton, prevbutton;
slouken@305
   143
slouken@305
   144
			curbutton = SDL_AtariXbios_mouseb & (1<<i);
slouken@305
   145
			prevbutton = atari_prevmouseb & (1<<i);
slouken@305
   146
slouken@331
   147
			if (curbutton && !prevbutton) {
slouken@305
   148
				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
slouken@305
   149
			}
slouken@331
   150
			if (!curbutton && prevbutton) {
slouken@305
   151
				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
slouken@305
   152
			}
slouken@305
   153
		}
slouken@305
   154
		atari_prevmouseb = SDL_AtariXbios_mouseb;
slouken@305
   155
	}
slouken@305
   156
}