src/video/ataricommon/SDL_xbiosevents.c
author Sam Lantinga
Tue, 21 Feb 2006 08:46:50 +0000
changeset 1402 d910939febfa
parent 1361 19418e4422cb
child 1662 782fd950bd46
child 1895 c121d94672cb
child 3857 be01e0b82dca
permissions -rw-r--r--
Use consistent identifiers for the various platforms we support.
Make sure every source file includes SDL_config.h, so the proper system
headers are chosen.
slouken@305
     1
/*
slouken@305
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@305
     4
slouken@305
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@305
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 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@1312
    13
    Lesser General Public License for more details.
slouken@305
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@305
    18
slouken@305
    19
    Sam Lantinga
slouken@305
    20
    slouken@libsdl.org
slouken@305
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@305
    23
slouken@305
    24
/*
slouken@305
    25
 *	XBIOS mouse & joystick vectors
slouken@305
    26
 *
slouken@305
    27
 *	Patrice Mandin
slouken@305
    28
 */
slouken@305
    29
slouken@305
    30
#include <mint/osbind.h>
slouken@305
    31
slouken@1361
    32
#include "../../events/SDL_events_c.h"
slouken@305
    33
#include "SDL_xbiosevents_c.h"
slouken@305
    34
#include "SDL_xbiosinterrupt_s.h"
slouken@305
    35
slouken@305
    36
/* Variables */
slouken@305
    37
slouken@305
    38
int SDL_AtariXbios_enabled=0;
slouken@305
    39
patmandin@820
    40
/* Local variables */
patmandin@820
    41
patmandin@820
    42
static _KBDVECS *kbdvecs;		/* Pointer to access system vectors */
slouken@305
    43
static Uint16 atari_prevmouseb;	/* buttons */
slouken@305
    44
patmandin@820
    45
/* Functions */
patmandin@820
    46
slouken@305
    47
void SDL_AtariXbios_InstallVectors(int vectors_mask)
slouken@305
    48
{
slouken@305
    49
	void *oldpile;
slouken@305
    50
slouken@305
    51
	/* Clear variables */
slouken@305
    52
	SDL_AtariXbios_mouseb =
slouken@305
    53
		SDL_AtariXbios_mousex =
slouken@305
    54
		SDL_AtariXbios_mousey =
slouken@305
    55
		SDL_AtariXbios_joystick =
slouken@305
    56
		atari_prevmouseb = 0;
slouken@305
    57
patmandin@1237
    58
	if (vectors_mask==0) {
patmandin@1237
    59
		SDL_AtariXbios_enabled=0;
patmandin@1237
    60
		return;
patmandin@1237
    61
	}
patmandin@1237
    62
slouken@305
    63
	/* Read IKBD vectors base */
slouken@305
    64
	kbdvecs=Kbdvbase();
slouken@305
    65
slouken@305
    66
	/* Go to supervisor mode */
slouken@305
    67
	oldpile=(void *)Super(0);
slouken@305
    68
patmandin@820
    69
	/* Install our vectors */
slouken@305
    70
	SDL_AtariXbios_Install(
slouken@305
    71
		kbdvecs,
slouken@305
    72
		(vectors_mask & ATARI_XBIOS_MOUSEEVENTS) ? SDL_AtariXbios_MouseVector : NULL,
slouken@305
    73
		(vectors_mask & ATARI_XBIOS_JOYSTICKEVENTS) ? SDL_AtariXbios_JoystickVector : NULL
slouken@305
    74
	);
slouken@305
    75
slouken@305
    76
	/* Back to user mode */
slouken@305
    77
	Super(oldpile);
slouken@305
    78
slouken@305
    79
	SDL_AtariXbios_enabled=1;
slouken@305
    80
}
slouken@305
    81
slouken@305
    82
void SDL_AtariXbios_RestoreVectors(void)
slouken@305
    83
{
slouken@305
    84
	void *oldpile;
slouken@305
    85
patmandin@1237
    86
	if (SDL_AtariXbios_enabled==0) {
patmandin@1237
    87
		return;
patmandin@1237
    88
	}
patmandin@1237
    89
patmandin@820
    90
	/* Read IKBD vectors base */
patmandin@820
    91
	kbdvecs=Kbdvbase();
patmandin@820
    92
slouken@305
    93
	/* Go to supervisor mode */
slouken@305
    94
	oldpile=(void *)Super(NULL);
slouken@305
    95
slouken@305
    96
	/* Reinstall system vector */
patmandin@820
    97
	SDL_AtariXbios_Restore(kbdvecs);
slouken@305
    98
slouken@305
    99
	/* Back to user mode */
slouken@305
   100
	Super(oldpile);
slouken@305
   101
}
slouken@305
   102
slouken@305
   103
static int atari_GetButton(int button)
slouken@305
   104
{
slouken@305
   105
	switch(button)
slouken@305
   106
	{
slouken@305
   107
		case 0:
slouken@305
   108
			return SDL_BUTTON_RIGHT;
slouken@305
   109
			break;
slouken@305
   110
		case 1:
slouken@305
   111
		default:
slouken@305
   112
			return SDL_BUTTON_LEFT;
slouken@305
   113
			break;
slouken@305
   114
	}
slouken@305
   115
}
slouken@305
   116
patmandin@1310
   117
void SDL_AtariXbios_PostMouseEvents(_THIS, SDL_bool buttonEvents)
slouken@305
   118
{
patmandin@1237
   119
	if (SDL_AtariXbios_enabled==0) {
patmandin@1237
   120
		return;
patmandin@1237
   121
	}
patmandin@1237
   122
slouken@305
   123
	/* Mouse motion ? */
slouken@305
   124
	if (SDL_AtariXbios_mousex || SDL_AtariXbios_mousey) {
slouken@305
   125
		SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
slouken@305
   126
		SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
slouken@305
   127
	}
slouken@305
   128
	
slouken@305
   129
	/* Mouse button ? */
patmandin@1310
   130
	if (buttonEvents && (SDL_AtariXbios_mouseb != atari_prevmouseb)) {
slouken@305
   131
		int i;
slouken@305
   132
slouken@305
   133
		for (i=0;i<2;i++) {
slouken@305
   134
			int curbutton, prevbutton;
slouken@305
   135
slouken@305
   136
			curbutton = SDL_AtariXbios_mouseb & (1<<i);
slouken@305
   137
			prevbutton = atari_prevmouseb & (1<<i);
slouken@305
   138
slouken@331
   139
			if (curbutton && !prevbutton) {
slouken@305
   140
				SDL_PrivateMouseButton(SDL_PRESSED, atari_GetButton(i), 0, 0);
slouken@305
   141
			}
slouken@331
   142
			if (!curbutton && prevbutton) {
slouken@305
   143
				SDL_PrivateMouseButton(SDL_RELEASED, atari_GetButton(i), 0, 0);
slouken@305
   144
			}
slouken@305
   145
		}
slouken@305
   146
		atari_prevmouseb = SDL_AtariXbios_mouseb;
slouken@305
   147
	}
slouken@305
   148
}