src/video/ps2gs/SDL_gsevents.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 07 Feb 2006 09:29:18 +0000
changeset 1338 604d73db6802
parent 1336 3692456e7b0f
child 1358 c71e05b4dc2e
permissions -rw-r--r--
Removed uses of stdlib.h and string.h
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     1
/*
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
     2
    SDL - Simple DirectMedia Layer
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
     3
    Copyright (C) 1997-2006 Sam Lantinga
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     4
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
     5
    This library is free software; you can redistribute it and/or
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
     6
    modify it under the terms of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
     7
    License as published by the Free Software Foundation; either
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
     8
    version 2.1 of the License, or (at your option) any later version.
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
     9
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    10
    This library is distributed in the hope that it will be useful,
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    13
    Lesser General Public License for more details.
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    15
    You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    16
    License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    18
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    19
    Sam Lantinga
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    20
    slouken@libsdl.org
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 769
diff changeset
    21
*/
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    22
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    23
/* Handle the event stream, converting console events into SDL events */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    24
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    25
#include <sys/types.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    26
#include <sys/time.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    27
#include <sys/ioctl.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    28
#include <unistd.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    29
#include <fcntl.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    30
#include <errno.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    31
#include <limits.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    32
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    33
/* For parsing /proc */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    34
#include <dirent.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    35
#include <ctype.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    36
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    37
#include <linux/vt.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    38
#include <linux/kd.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    39
#include <linux/keyboard.h>
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    40
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    41
#include "SDL.h"
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
    42
#include "SDL_string.h"
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    43
#include "SDL_mutex.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    44
#include "SDL_sysevents.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    45
#include "SDL_sysvideo.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    46
#include "SDL_events_c.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    47
#include "SDL_gsvideo.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    48
#include "SDL_gsevents_c.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    49
#include "SDL_gskeys.h"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    50
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    51
#ifndef GPM_NODE_FIFO
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    52
#define GPM_NODE_FIFO	"/dev/gpmdata"
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    53
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    54
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    55
/* The translation tables from a console scancode to a SDL keysym */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    56
#define NUM_VGAKEYMAPS	(1<<KG_CAPSSHIFT)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    57
static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    58
static SDLKey keymap[128];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    59
static Uint16 keymap_temp[128]; /* only used at startup */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    60
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    61
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    62
/* Ugh, we have to duplicate the kernel's keysym mapping code...
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    63
   Oh, it's not so bad. :-)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    64
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    65
   FIXME: Add keyboard LED handling code
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    66
 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    67
static void GS_vgainitkeymaps(int fd)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    68
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    69
	struct kbentry entry;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    70
	int map, i;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    71
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    72
	/* Don't do anything if we are passed a closed keyboard */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    73
	if ( fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    74
		return;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    75
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    76
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    77
	/* Load all the keysym mappings */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    78
	for ( map=0; map<NUM_VGAKEYMAPS; ++map ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
    79
		SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    80
		for ( i=0; i<NR_KEYS; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    81
			entry.kb_table = map;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    82
			entry.kb_index = i;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    83
			if ( ioctl(fd, KDGKBENT, &entry) == 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    84
				/* fill keytemp. This replaces SDL_fbkeys.h */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    85
				if ( (map == 0) && (i<128) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    86
					keymap_temp[i] = entry.kb_value;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    87
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    88
				/* The "Enter" key is a special case */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    89
				if ( entry.kb_value == K_ENTER ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    90
					entry.kb_value = K(KT_ASCII,13);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    91
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    92
				/* Handle numpad specially as well */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    93
				if ( KTYP(entry.kb_value) == KT_PAD ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    94
					switch ( entry.kb_value ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    95
					case K_P0:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    96
					case K_P1:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    97
					case K_P2:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    98
					case K_P3:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
    99
					case K_P4:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   100
					case K_P5:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   101
					case K_P6:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   102
					case K_P7:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   103
					case K_P8:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   104
					case K_P9:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   105
						vga_keymap[map][i]=entry.kb_value;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   106
						vga_keymap[map][i]+= '0';
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   107
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   108
										case K_PPLUS:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   109
						vga_keymap[map][i]=K(KT_ASCII,'+');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   110
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   111
										case K_PMINUS:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   112
						vga_keymap[map][i]=K(KT_ASCII,'-');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   113
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   114
										case K_PSTAR:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   115
						vga_keymap[map][i]=K(KT_ASCII,'*');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   116
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   117
										case K_PSLASH:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   118
						vga_keymap[map][i]=K(KT_ASCII,'/');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   119
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   120
										case K_PENTER:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   121
						vga_keymap[map][i]=K(KT_ASCII,'\r');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   122
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   123
										case K_PCOMMA:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   124
						vga_keymap[map][i]=K(KT_ASCII,',');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   125
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   126
										case K_PDOT:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   127
						vga_keymap[map][i]=K(KT_ASCII,'.');
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   128
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   129
					default:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   130
						break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   131
					}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   132
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   133
				/* Do the normal key translation */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   134
				if ( (KTYP(entry.kb_value) == KT_LATIN) ||
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   135
					 (KTYP(entry.kb_value) == KT_ASCII) ||
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   136
					 (KTYP(entry.kb_value) == KT_LETTER) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   137
					vga_keymap[map][i] = entry.kb_value;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   138
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   139
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   140
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   141
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   142
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   143
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   144
int GS_InGraphicsMode(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   145
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   146
	return((keyboard_fd >= 0) && (saved_kbd_mode >= 0));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   147
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   148
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   149
int GS_EnterGraphicsMode(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   150
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   151
	struct termios keyboard_termios;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   152
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   153
	/* Set medium-raw keyboard mode */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   154
	if ( (keyboard_fd >= 0) && !GS_InGraphicsMode(this) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   155
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   156
		/* Switch to the correct virtual terminal */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   157
		if ( current_vt > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   158
			struct vt_stat vtstate;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   159
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   160
			if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   161
				saved_vt = vtstate.v_active;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   162
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   163
			if ( ioctl(keyboard_fd, VT_ACTIVATE, current_vt) == 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   164
				ioctl(keyboard_fd, VT_WAITACTIVE, current_vt);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   165
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   166
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   167
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   168
		/* Set the terminal input mode */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   169
		if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   170
			SDL_SetError("Unable to get terminal attributes");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   171
			if ( keyboard_fd > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   172
				close(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   173
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   174
			keyboard_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   175
			return(-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   176
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   177
		if ( ioctl(keyboard_fd, KDGKBMODE, &saved_kbd_mode) < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   178
			SDL_SetError("Unable to get current keyboard mode");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   179
			if ( keyboard_fd > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   180
				close(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   181
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   182
			keyboard_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   183
			return(-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   184
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   185
		keyboard_termios = saved_kbd_termios;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   186
		keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   187
		keyboard_termios.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   188
		keyboard_termios.c_cc[VMIN] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   189
		keyboard_termios.c_cc[VTIME] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   190
		if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   191
			GS_CloseKeyboard(this);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   192
			SDL_SetError("Unable to set terminal attributes");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   193
			return(-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   194
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   195
		/* This will fail if we aren't root or this isn't our tty */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   196
		if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   197
			GS_CloseKeyboard(this);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   198
			SDL_SetError("Unable to set keyboard in raw mode");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   199
			return(-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   200
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   201
		if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   202
			GS_CloseKeyboard(this);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   203
			SDL_SetError("Unable to set keyboard in graphics mode");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   204
			return(-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   205
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   206
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   207
	return(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   208
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   209
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   210
void GS_LeaveGraphicsMode(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   211
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   212
	if ( GS_InGraphicsMode(this) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   213
		ioctl(keyboard_fd, KDSETMODE, KD_TEXT);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   214
		ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   215
		tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   216
		saved_kbd_mode = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   217
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   218
		/* Head back over to the original virtual terminal */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   219
		if ( saved_vt > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   220
			ioctl(keyboard_fd, VT_ACTIVATE, saved_vt);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   221
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   222
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   223
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   224
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   225
void GS_CloseKeyboard(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   226
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   227
	if ( keyboard_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   228
		GS_LeaveGraphicsMode(this);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   229
		if ( keyboard_fd > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   230
			close(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   231
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   232
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   233
	keyboard_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   234
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   235
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   236
int GS_OpenKeyboard(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   237
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   238
	/* Open only if not already opened */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   239
 	if ( keyboard_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   240
		char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL };
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   241
		char *vcs[] = { "/dev/vc/%d", "/dev/tty%d", NULL };
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   242
		int i, tty0_fd;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   243
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   244
		/* Try to query for a free virtual terminal */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   245
		tty0_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   246
		for ( i=0; tty0[i] && (tty0_fd < 0); ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   247
			tty0_fd = open(tty0[i], O_WRONLY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   248
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   249
		if ( tty0_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   250
			tty0_fd = dup(0); /* Maybe stdin is a VT? */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   251
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   252
		ioctl(tty0_fd, VT_OPENQRY, &current_vt);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   253
		close(tty0_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   254
		if ( (geteuid() == 0) && (current_vt > 0) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   255
			for ( i=0; vcs[i] && (keyboard_fd < 0); ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   256
				char vtpath[12];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   257
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
   258
				SDL_snprintf(vtpath, SDL_arraysize(vtpath), vcs[i], current_vt);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   259
				keyboard_fd = open(vtpath, O_RDWR, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   260
#ifdef DEBUG_KEYBOARD
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   261
				fprintf(stderr, "vtpath = %s, fd = %d\n",
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   262
					vtpath, keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   263
#endif /* DEBUG_KEYBOARD */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   264
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   265
				/* This needs to be our controlling tty
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   266
				   so that the kernel ioctl() calls work
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   267
				*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   268
				if ( keyboard_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   269
					tty0_fd = open("/dev/tty", O_RDWR, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   270
					if ( tty0_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   271
						ioctl(tty0_fd, TIOCNOTTY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   272
						close(tty0_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   273
					}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   274
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   275
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   276
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   277
 		if ( keyboard_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   278
			/* Last resort, maybe our tty is a usable VT */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   279
			current_vt = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   280
			keyboard_fd = open("/dev/tty", O_RDWR);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   281
 		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   282
#ifdef DEBUG_KEYBOARD
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   283
		fprintf(stderr, "Current VT: %d\n", current_vt);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   284
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   285
 		saved_kbd_mode = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   286
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   287
		/* Make sure that our input is a console terminal */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   288
		{ int dummy;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   289
		  if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   290
			close(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   291
			keyboard_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   292
			SDL_SetError("Unable to open a console terminal");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   293
		  }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   294
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   295
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   296
		/* Set up keymap */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   297
		GS_vgainitkeymaps(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   298
 	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   299
 	return(keyboard_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   300
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   301
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   302
static enum {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   303
	MOUSE_NONE = -1,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   304
	MOUSE_GPM,	/* Note: GPM uses the MSC protocol */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   305
	MOUSE_PS2,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   306
	MOUSE_IMPS2,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   307
	MOUSE_MS,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   308
	MOUSE_BM,
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   309
	NUM_MOUSE_DRVS
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   310
} mouse_drv = MOUSE_NONE;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   311
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   312
void GS_CloseMouse(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   313
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   314
	if ( mouse_fd > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   315
		close(mouse_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   316
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   317
	mouse_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   318
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   319
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   320
/* Returns processes listed in /proc with the desired name */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   321
static int find_pid(DIR *proc, const char *wanted_name)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   322
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   323
	struct dirent *entry;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   324
	int pid;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   325
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   326
	/* First scan proc for the gpm process */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   327
	pid = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   328
	while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   329
		if ( isdigit(entry->d_name[0]) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   330
			FILE *status;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   331
			char path[PATH_MAX];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   332
			char name[PATH_MAX];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   333
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
   334
			SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   335
			status=fopen(path, "r");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   336
			if ( status ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   337
				name[0] = '\0';
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   338
				fscanf(status, "Name: %s", name);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   339
				if ( SDL_strcmp(name, wanted_name) == 0 ) {
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   340
					pid = atoi(entry->d_name);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   341
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   342
				fclose(status);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   343
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   344
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   345
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   346
	return pid;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   347
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   348
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   349
/* Returns true if /dev/gpmdata is being written to by gpm */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   350
static int gpm_available(void)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   351
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   352
	int available;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   353
	DIR *proc;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   354
	int pid;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   355
	int cmdline, len, arglen;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   356
	char path[PATH_MAX];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   357
	char args[PATH_MAX], *arg;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   358
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   359
	/* Don't bother looking if the fifo isn't there */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   360
	if ( access(GPM_NODE_FIFO, F_OK) < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   361
		return(0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   362
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   363
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   364
	available = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   365
	proc = opendir("/proc");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   366
	if ( proc ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   367
		while ( (pid=find_pid(proc, "gpm")) > 0 ) {
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
   368
			SDL_snprintf(path, SDL_arraysize(path), "/proc/%d/cmdline", pid);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   369
			cmdline = open(path, O_RDONLY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   370
			if ( cmdline >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   371
				len = read(cmdline, args, sizeof(args));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   372
				arg = args;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   373
				while ( len > 0 ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   374
					if ( SDL_strcmp(arg, "-R") == 0 ) {
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   375
						available = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   376
					}
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   377
					arglen = SDL_strlen(arg)+1;
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   378
					len -= arglen;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   379
					arg += arglen;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   380
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   381
				close(cmdline);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   382
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   383
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   384
		closedir(proc);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   385
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   386
	return available;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   387
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   388
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   389
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   390
/* rcg06112001 Set up IMPS/2 mode, if possible. This gives
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   391
 *  us access to the mousewheel, etc. Returns zero if
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   392
 *  writes to device failed, but you still need to query the
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   393
 *  device to see which mode it's actually in.
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   394
 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   395
static int set_imps2_mode(int fd)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   396
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   397
	/* If you wanted to control the mouse mode (and we do :)  ) ...
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   398
		Set IMPS/2 protocol:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   399
			{0xf3,200,0xf3,100,0xf3,80}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   400
		Reset mouse device:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   401
			{0xFF}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   402
	*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   403
	Uint8 set_imps2[] = {0xf3, 200, 0xf3, 100, 0xf3, 80};
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   404
	Uint8 reset = 0xff;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   405
	fd_set fdset;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   406
	struct timeval tv;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   407
	int retval = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   408
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   409
	if ( write(fd, &set_imps2, sizeof(set_imps2)) == sizeof(set_imps2) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   410
		if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   411
			retval = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   412
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   413
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   414
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   415
	/* Get rid of any chatter from the above */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   416
	FD_ZERO(&fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   417
	FD_SET(fd, &fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   418
	tv.tv_sec = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   419
	tv.tv_usec = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   420
	while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   421
		char temp[32];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   422
		read(fd, temp, sizeof(temp));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   423
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   424
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   425
	return retval;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   426
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   427
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   428
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   429
/* Returns true if the mouse uses the IMPS/2 protocol */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   430
static int detect_imps2(int fd)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   431
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   432
	int imps2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   433
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   434
	imps2 = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   435
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   436
	if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) {
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   437
		imps2 = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   438
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   439
	if ( ! imps2 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   440
		Uint8 query_ps2 = 0xF2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   441
		fd_set fdset;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   442
		struct timeval tv;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   443
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   444
		/* Get rid of any mouse motion noise */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   445
		FD_ZERO(&fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   446
		FD_SET(fd, &fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   447
		tv.tv_sec = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   448
		tv.tv_usec = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   449
		while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   450
			char temp[32];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   451
			read(fd, temp, sizeof(temp));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   452
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   453
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   454
   		/* Query for the type of mouse protocol */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   455
   		if ( write(fd, &query_ps2, sizeof (query_ps2)) == sizeof (query_ps2)) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   456
   			Uint8 ch = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   457
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   458
			/* Get the mouse protocol response */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   459
			do {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   460
				FD_ZERO(&fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   461
				FD_SET(fd, &fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   462
				tv.tv_sec = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   463
				tv.tv_usec = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   464
				if ( select(fd+1, &fdset, 0, 0, &tv) < 1 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   465
					break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   466
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   467
			} while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) &&
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   468
			          ((ch == 0xFA) || (ch == 0xAA)) );
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   469
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   470
			/* Experimental values (Logitech wheelmouse) */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   471
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   472
fprintf(stderr, "Last mouse mode: 0x%x\n", ch);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   473
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   474
			if ( ch == 3 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   475
				imps2 = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   476
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   477
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   478
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   479
	return imps2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   480
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   481
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   482
int GS_OpenMouse(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   483
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   484
	int i;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   485
	const char *mousedev;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   486
	const char *mousedrv;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   487
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   488
	mousedrv = SDL_getenv("SDL_MOUSEDRV");
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   489
	mousedev = SDL_getenv("SDL_MOUSEDEV");
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   490
	mouse_fd = -1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   491
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   492
	/* STD MICE */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   493
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   494
	if ( mousedev == NULL ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   495
		/* FIXME someday... allow multiple mice in this driver */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   496
		char *ps2mice[] = {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   497
		    "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   498
		};
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   499
		/* First try to use GPM in repeater mode */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   500
		if ( mouse_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   501
			if ( gpm_available() ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   502
				mouse_fd = open(GPM_NODE_FIFO, O_RDONLY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   503
				if ( mouse_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   504
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   505
fprintf(stderr, "Using GPM mouse\n");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   506
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   507
					mouse_drv = MOUSE_GPM;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   508
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   509
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   510
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   511
		/* Now try to use a modern PS/2 mouse */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   512
		for ( i=0; (mouse_fd < 0) && ps2mice[i]; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   513
			mouse_fd = open(ps2mice[i], O_RDWR, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   514
			if (mouse_fd < 0) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   515
				mouse_fd = open(ps2mice[i], O_RDONLY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   516
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   517
			if (mouse_fd >= 0) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   518
				/* rcg06112001 Attempt to set IMPS/2 mode */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   519
				if ( i == 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   520
					set_imps2_mode(mouse_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   521
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   522
				if (detect_imps2(mouse_fd)) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   523
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   524
fprintf(stderr, "Using IMPS2 mouse\n");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   525
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   526
					mouse_drv = MOUSE_IMPS2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   527
				} else {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   528
					mouse_drv = MOUSE_PS2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   529
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   530
fprintf(stderr, "Using PS2 mouse\n");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   531
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   532
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   533
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   534
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   535
		/* Next try to use a PPC ADB port mouse */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   536
		if ( mouse_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   537
			mouse_fd = open("/dev/adbmouse", O_RDONLY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   538
			if ( mouse_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   539
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   540
fprintf(stderr, "Using ADB mouse\n");
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   541
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   542
				mouse_drv = MOUSE_BM;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   543
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   544
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   545
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   546
	/* Default to a serial Microsoft mouse */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   547
	if ( mouse_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   548
		if ( mousedev == NULL ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   549
			mousedev = "/dev/mouse";
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   550
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   551
		mouse_fd = open(mousedev, O_RDONLY, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   552
		if ( mouse_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   553
			struct termios mouse_termios;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   554
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   555
			/* Set the sampling speed to 1200 baud */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   556
			tcgetattr(mouse_fd, &mouse_termios);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   557
			mouse_termios.c_iflag = IGNBRK | IGNPAR;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   558
			mouse_termios.c_oflag = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   559
			mouse_termios.c_lflag = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   560
			mouse_termios.c_line = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   561
			mouse_termios.c_cc[VTIME] = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   562
			mouse_termios.c_cc[VMIN] = 1;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   563
			mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   564
			mouse_termios.c_cflag |= CS8;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   565
			mouse_termios.c_cflag |= B1200;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   566
			tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   567
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   568
fprintf(stderr, "Using Microsoft mouse on %s\n", mousedev);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   569
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   570
			mouse_drv = MOUSE_MS;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   571
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   572
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   573
	if ( mouse_fd < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   574
		mouse_drv = MOUSE_NONE;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   575
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   576
	return(mouse_fd);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   577
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   578
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   579
static int posted = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   580
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   581
void GS_vgamousecallback(int button, int dx, int dy)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   582
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   583
	int button_1, button_3;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   584
	int button_state;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   585
	int state_changed;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   586
	int i;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   587
	Uint8 state;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   588
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   589
	if ( dx || dy ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   590
		posted += SDL_PrivateMouseMotion(0, 1, dx, dy);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   591
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   592
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   593
	/* Swap button 1 and 3 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   594
	button_1 = (button & 0x04) >> 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   595
	button_3 = (button & 0x01) << 2;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   596
	button &= ~0x05;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   597
	button |= (button_1|button_3);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   598
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   599
	/* See what changed */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   600
	button_state = SDL_GetMouseState(NULL, NULL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   601
	state_changed = button_state ^ button;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   602
	for ( i=0; i<8; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   603
		if ( state_changed & (1<<i) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   604
			if ( button & (1<<i) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   605
				state = SDL_PRESSED;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   606
			} else {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   607
				state = SDL_RELEASED;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   608
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   609
			posted += SDL_PrivateMouseButton(state, i+1, 0, 0);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   610
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   611
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   612
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   613
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   614
/* For now, use GPM, PS/2, and MS protocols
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   615
   Driver adapted from the SVGAlib mouse driver code (taken from gpm, etc.)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   616
 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   617
static void handle_mouse(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   618
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   619
	static int start = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   620
	static unsigned char mousebuf[BUFSIZ];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   621
	int i, nread;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   622
	int button = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   623
	int dx = 0, dy = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   624
	int packetsize = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   625
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   626
	/* Figure out the mouse packet size */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   627
	switch (mouse_drv) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   628
		case MOUSE_NONE:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   629
			/* Ack! */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   630
			read(mouse_fd, mousebuf, BUFSIZ);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   631
			return;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   632
		case MOUSE_GPM:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   633
			packetsize = 5;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   634
			break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   635
		case MOUSE_IMPS2:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   636
			packetsize = 4;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   637
			break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   638
		case MOUSE_PS2:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   639
		case MOUSE_MS:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   640
		case MOUSE_BM:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   641
			packetsize = 3;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   642
			break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   643
		case NUM_MOUSE_DRVS:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   644
			/* Uh oh.. */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   645
			packetsize = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   646
			break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   647
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   648
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   649
	/* Read as many packets as possible */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   650
	nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   651
	if ( nread < 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   652
		return;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   653
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   654
	nread += start;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   655
#ifdef DEBUG_MOUSE
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   656
	fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   657
#endif
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   658
	for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   659
		switch (mouse_drv) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   660
			case MOUSE_NONE:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   661
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   662
			case MOUSE_GPM:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   663
				/* GPM protocol has 0x80 in high byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   664
				if ( (mousebuf[i] & 0xF8) != 0x80 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   665
					/* Go to next byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   666
					i -= (packetsize-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   667
					continue;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   668
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   669
				/* Get current mouse state */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   670
				button = (~mousebuf[i]) & 0x07;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   671
				dx =   (signed char)(mousebuf[i+1]) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   672
				       (signed char)(mousebuf[i+3]);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   673
				dy = -((signed char)(mousebuf[i+2]) +
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   674
				       (signed char)(mousebuf[i+4]));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   675
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   676
			case MOUSE_PS2:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   677
				/* PS/2 protocol has nothing in high byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   678
				if ( (mousebuf[i] & 0xC0) != 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   679
					/* Go to next byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   680
					i -= (packetsize-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   681
					continue;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   682
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   683
				/* Get current mouse state */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   684
				button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   685
		  			 (mousebuf[i] & 0x02) >> 1 | /*Right*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   686
		  			 (mousebuf[i] & 0x01) << 2;  /*Left*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   687
		  		dx = (mousebuf[i] & 0x10) ?
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   688
		  		      mousebuf[i+1] - 256 : mousebuf[i+1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   689
		  		dy = (mousebuf[i] & 0x20) ?
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   690
		  		      -(mousebuf[i+2] - 256) : -mousebuf[i+2];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   691
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   692
			case MOUSE_IMPS2:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   693
				/* Get current mouse state */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   694
				button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   695
		  			 (mousebuf[i] & 0x02) >> 1 | /*Right*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   696
		  			 (mousebuf[i] & 0x01) << 2 | /*Left*/
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   697
		  			 (mousebuf[i] & 0x40) >> 3 | /* 4 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   698
		  			 (mousebuf[i] & 0x80) >> 3;  /* 5 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   699
		  		dx = (mousebuf[i] & 0x10) ?
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   700
		  		      mousebuf[i+1] - 256 : mousebuf[i+1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   701
		  		dy = (mousebuf[i] & 0x20) ?
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   702
		  		      -(mousebuf[i+2] - 256) : -mousebuf[i+2];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   703
				switch (mousebuf[i+3]&0x0F) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   704
				    case 0x0E: /* DX = +1 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   705
				    case 0x02: /* DX = -1 */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   706
					break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   707
				    case 0x0F: /* DY = +1 (map button 4) */
132
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 70
diff changeset
   708
                                       FB_vgamousecallback(button | (1<<3),
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 70
diff changeset
   709
                                                           1, 0, 0);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   710
					break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   711
				    case 0x01: /* DY = -1 (map button 5) */
132
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 70
diff changeset
   712
                                       FB_vgamousecallback(button | (1<<4),
2604a7be65af Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents: 70
diff changeset
   713
                                                           1, 0, 0);
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   714
					break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   715
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   716
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   717
			case MOUSE_MS:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   718
				/* Microsoft protocol has 0x40 in high byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   719
				if ( (mousebuf[i] & 0x40) != 0x40 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   720
					/* Go to next byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   721
					i -= (packetsize-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   722
					continue;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   723
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   724
				/* Get current mouse state */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   725
				button = ((mousebuf[i] & 0x20) >> 3) |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   726
				         ((mousebuf[i] & 0x10) >> 4);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   727
				dx = (signed char)(((mousebuf[i] & 0x03) << 6) |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   728
				                   (mousebuf[i + 1] & 0x3F));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   729
				dy = (signed char)(((mousebuf[i] & 0x0C) << 4) |
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   730
				                    (mousebuf[i + 2] & 0x3F));
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   731
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   732
			case MOUSE_BM:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   733
				/* BusMouse protocol has 0xF8 in high byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   734
				if ( (mousebuf[i] & 0xF8) != 0x80 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   735
					/* Go to next byte */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   736
					i -= (packetsize-1);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   737
					continue;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   738
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   739
				/* Get current mouse state */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   740
				button = (~mousebuf[i]) & 0x07;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   741
				dx =  (signed char)mousebuf[i+1];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   742
				dy = -(signed char)mousebuf[i+2];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   743
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   744
			case NUM_MOUSE_DRVS:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   745
				/* Uh oh.. */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   746
				dx = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   747
				dy = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   748
				break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   749
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   750
		GS_vgamousecallback(button, dx, dy);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   751
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   752
	if ( i < nread ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
   753
		SDL_memcpy(mousebuf, &mousebuf[i], (nread-i));
70
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   754
		start = (nread-i);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   755
	} else {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   756
		start = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   757
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   758
	return;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   759
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   760
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   761
static void handle_keyboard(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   762
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   763
	unsigned char keybuf[BUFSIZ];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   764
	int i, nread;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   765
	int pressed;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   766
	int scancode;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   767
	SDL_keysym keysym;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   768
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   769
	nread = read(keyboard_fd, keybuf, BUFSIZ);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   770
	for ( i=0; i<nread; ++i ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   771
		scancode = keybuf[i] & 0x7F;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   772
		if ( keybuf[i] & 0x80 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   773
			pressed = SDL_RELEASED;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   774
		} else {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   775
			pressed = SDL_PRESSED;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   776
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   777
		TranslateKey(scancode, &keysym);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   778
		posted += SDL_PrivateKeyboard(pressed, &keysym);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   779
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   780
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   781
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   782
void GS_PumpEvents(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   783
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   784
	fd_set fdset;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   785
	int max_fd;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   786
	static struct timeval zero;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   787
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   788
	do {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   789
		posted = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   790
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   791
		FD_ZERO(&fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   792
		max_fd = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   793
		if ( keyboard_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   794
			FD_SET(keyboard_fd, &fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   795
			if ( max_fd < keyboard_fd ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   796
				max_fd = keyboard_fd;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   797
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   798
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   799
		if ( mouse_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   800
			FD_SET(mouse_fd, &fdset);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   801
			if ( max_fd < mouse_fd ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   802
				max_fd = mouse_fd;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   803
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   804
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   805
		if ( select(max_fd+1, &fdset, NULL, NULL, &zero) > 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   806
			if ( keyboard_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   807
				if ( FD_ISSET(keyboard_fd, &fdset) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   808
					handle_keyboard(this);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   809
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   810
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   811
			if ( mouse_fd >= 0 ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   812
				if ( FD_ISSET(mouse_fd, &fdset) ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   813
					handle_mouse(this);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   814
				}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   815
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   816
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   817
	} while ( posted );
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   818
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   819
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   820
void GS_InitOSKeymap(_THIS)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   821
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   822
	int i;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   823
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   824
	/* Initialize the Linux key translation table */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   825
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   826
	/* First get the ascii keys and others not well handled */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   827
	for (i=0; i<SDL_TABLESIZE(keymap); ++i) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   828
	  switch(i) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   829
	  /* These aren't handled by the x86 kernel keymapping (?) */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   830
	  case SCANCODE_PRINTSCREEN:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   831
	    keymap[i] = SDLK_PRINT;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   832
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   833
	  case SCANCODE_BREAK:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   834
	    keymap[i] = SDLK_BREAK;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   835
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   836
	  case SCANCODE_BREAK_ALTERNATIVE:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   837
	    keymap[i] = SDLK_PAUSE;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   838
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   839
	  case SCANCODE_LEFTSHIFT:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   840
	    keymap[i] = SDLK_LSHIFT;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   841
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   842
	  case SCANCODE_RIGHTSHIFT:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   843
	    keymap[i] = SDLK_RSHIFT;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   844
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   845
	  case SCANCODE_LEFTCONTROL:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   846
	    keymap[i] = SDLK_LCTRL;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   847
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   848
	  case SCANCODE_RIGHTCONTROL:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   849
	    keymap[i] = SDLK_RCTRL;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   850
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   851
	  case SCANCODE_RIGHTWIN:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   852
	    keymap[i] = SDLK_RSUPER;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   853
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   854
	  case SCANCODE_LEFTWIN:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   855
	    keymap[i] = SDLK_LSUPER;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   856
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   857
	  case 127:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   858
	    keymap[i] = SDLK_MENU;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   859
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   860
	  /* this should take care of all standard ascii keys */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   861
	  default:
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   862
	    keymap[i] = KVAL(vga_keymap[0][i]);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   863
	    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   864
          }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   865
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   866
	for (i=0; i<SDL_TABLESIZE(keymap); ++i) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   867
	  switch(keymap_temp[i]) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   868
	    case K_F1:  keymap[i] = SDLK_F1;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   869
	    case K_F2:  keymap[i] = SDLK_F2;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   870
	    case K_F3:  keymap[i] = SDLK_F3;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   871
	    case K_F4:  keymap[i] = SDLK_F4;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   872
	    case K_F5:  keymap[i] = SDLK_F5;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   873
	    case K_F6:  keymap[i] = SDLK_F6;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   874
	    case K_F7:  keymap[i] = SDLK_F7;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   875
	    case K_F8:  keymap[i] = SDLK_F8;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   876
	    case K_F9:  keymap[i] = SDLK_F9;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   877
	    case K_F10: keymap[i] = SDLK_F10; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   878
	    case K_F11: keymap[i] = SDLK_F11; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   879
	    case K_F12: keymap[i] = SDLK_F12; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   880
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   881
	    case K_DOWN:  keymap[i] = SDLK_DOWN;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   882
	    case K_LEFT:  keymap[i] = SDLK_LEFT;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   883
	    case K_RIGHT: keymap[i] = SDLK_RIGHT; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   884
	    case K_UP:    keymap[i] = SDLK_UP;    break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   885
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   886
	    case K_P0:     keymap[i] = SDLK_KP0; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   887
	    case K_P1:     keymap[i] = SDLK_KP1; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   888
	    case K_P2:     keymap[i] = SDLK_KP2; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   889
	    case K_P3:     keymap[i] = SDLK_KP3; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   890
	    case K_P4:     keymap[i] = SDLK_KP4; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   891
	    case K_P5:     keymap[i] = SDLK_KP5; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   892
	    case K_P6:     keymap[i] = SDLK_KP6; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   893
	    case K_P7:     keymap[i] = SDLK_KP7; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   894
	    case K_P8:     keymap[i] = SDLK_KP8; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   895
	    case K_P9:     keymap[i] = SDLK_KP9; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   896
	    case K_PPLUS:  keymap[i] = SDLK_KP_PLUS; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   897
	    case K_PMINUS: keymap[i] = SDLK_KP_MINUS; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   898
	    case K_PSTAR:  keymap[i] = SDLK_KP_MULTIPLY; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   899
	    case K_PSLASH: keymap[i] = SDLK_KP_DIVIDE; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   900
	    case K_PENTER: keymap[i] = SDLK_KP_ENTER; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   901
	    case K_PDOT:   keymap[i] = SDLK_KP_PERIOD; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   902
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   903
	    case K_SHIFT:  if ( keymap[i] != SDLK_RSHIFT )
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   904
	                     keymap[i] = SDLK_LSHIFT;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   905
	                   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   906
	    case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   907
	    case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   908
	    case K_CTRL:  if ( keymap[i] != SDLK_RCTRL )
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   909
	                     keymap[i] = SDLK_LCTRL;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   910
	                   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   911
	    case K_CTRLL:  keymap[i] = SDLK_LCTRL;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   912
	    case K_CTRLR:  keymap[i] = SDLK_RCTRL;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   913
	    case K_ALT:    keymap[i] = SDLK_LALT;   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   914
	    case K_ALTGR:  keymap[i] = SDLK_RALT;   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   915
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   916
	    case K_INSERT: keymap[i] = SDLK_INSERT;   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   917
	    case K_REMOVE: keymap[i] = SDLK_DELETE;   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   918
	    case K_PGUP:   keymap[i] = SDLK_PAGEUP;   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   919
	    case K_PGDN:   keymap[i] = SDLK_PAGEDOWN; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   920
	    case K_FIND:   keymap[i] = SDLK_HOME;     break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   921
	    case K_SELECT: keymap[i] = SDLK_END;      break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   922
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   923
	    case K_NUM:  keymap[i] = SDLK_NUMLOCK;   break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   924
	    case K_CAPS: keymap[i] = SDLK_CAPSLOCK;  break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   925
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   926
	    case K_F13:   keymap[i] = SDLK_PRINT;     break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   927
	    case K_HOLD:  keymap[i] = SDLK_SCROLLOCK; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   928
	    case K_PAUSE: keymap[i] = SDLK_PAUSE;     break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   929
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   930
	    case 127: keymap[i] = SDLK_BACKSPACE; break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   931
	     
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   932
	    default: break;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   933
	  }
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   934
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   935
}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   936
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   937
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   938
{
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   939
	/* Set the keysym information */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   940
	keysym->scancode = scancode;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   941
	keysym->sym = keymap[scancode];
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   942
	keysym->mod = KMOD_NONE;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   943
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   944
	/* If UNICODE is on, get the UNICODE value for the key */
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   945
	keysym->unicode = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   946
	if ( SDL_TranslateUNICODE ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   947
		int map;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   948
		SDLMod modstate;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   949
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   950
		modstate = SDL_GetModState();
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   951
		map = 0;
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   952
		if ( modstate & KMOD_SHIFT ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   953
			map |= (1<<KG_SHIFT);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   954
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   955
		if ( modstate & KMOD_CTRL ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   956
			map |= (1<<KG_CTRL);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   957
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   958
		if ( modstate & KMOD_ALT ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   959
			map |= (1<<KG_ALT);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   960
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   961
		if ( modstate & KMOD_MODE ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   962
			map |= (1<<KG_ALTGR);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   963
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   964
		if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   965
			if ( modstate & KMOD_CAPS ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   966
				map ^= (1<<KG_SHIFT);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   967
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   968
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   969
		if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   970
			if ( modstate & KMOD_NUM ) {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   971
				keysym->unicode=KVAL(vga_keymap[map][scancode]);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   972
			}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   973
		} else {
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   974
			keysym->unicode = KVAL(vga_keymap[map][scancode]);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   975
		}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   976
	}
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   977
	return(keysym);
f590dd383b5d Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
   978
}