Mercurial > sdl-ios-xcode
annotate src/video/ps2gs/SDL_gsevents.c @ 4157:baf615f9f2a0 SDL-1.2
Date: Thu, 16 Oct 2008 20:27:34 +0400
From: "Ilya Kasnacheev" <ilya.kasnacheev@gmail.com>
To: sdl@lists.libsdl.org
Subject: [SDL] SDL for Windows CE: a few GAPI patches
Hi *!
I've just ported a POWDER roguelike ( http://www.zincland.com/powder/ ) to
Windows CE (PDAs, Windows Mobile/Pocket PC). To do that, I had to get libsdl
working. Thanks for the awesome project files, it built without a hitch.
Nevertheless, I've found quite a few bugs in Windows CE (GAPI) SDL
implementation, which I've solved and now present as a serie of patches.
I'll try carefully annotate them. Please annotate them so I can work
toward accepting
them into the main source tree since without them SDL isn't really working on
Windows CE (I wonder why nobody fixed them before, btw: why isn't SDL popular as
a way to develop Windows CE games? Where are no ports?)
These changes can't be considered flawless, but they can be considered working
because I've yet to hear complains about things I fixed and POWDER build for
Windows CE is now considered stable.
Note: my comments start with !!, delete them before applying.
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.c
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.c 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.c 2008-10-16
20:02:11.000000000 +0400
@@ -643,6 +643,7 @@
}
gapi->userOrientation = SDL_ORIENTATION_UP;
+ gapi->systemOrientation = SDL_ORIENTATION_UP;
video->flags = SDL_FULLSCREEN; /* Clear flags, GAPI supports
fullscreen only */
/* GAPI or VGA? */
@@ -661,18 +662,21 @@
}
/* detect user landscape mode */
- if( (width > height) && (GetSystemMetrics(SM_CXSCREEN) <
GetSystemMetrics(SM_CYSCREEN)))
+ if( (width > height) && (gapi->gxProperties.cxWidth <
gapi->gxProperties.cyHeight))
gapi->userOrientation = SDL_ORIENTATION_RIGHT;
+ if(GetSystemMetrics(SM_CYSCREEN) < GetSystemMetrics(SM_CXSCREEN))
+ gapi->systemOrientation = SDL_ORIENTATION_RIGHT;
+
/* shall we apply hires fix? for example when we do not use
hires resource */
gapi->hiresFix = 0;
- if( gapi->userOrientation == SDL_ORIENTATION_RIGHT )
+ if( gapi->systemOrientation == gapi->userOrientation )
{
- if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+ if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
gapi->hiresFix = 1;
} else
- if( (width > GetSystemMetrics(SM_CXSCREEN)) || (height
> GetSystemMetrics(SM_CYSCREEN)))
- if( !((width == GetSystemMetrics(SM_CYSCREEN))
&& (height == GetSystemMetrics(SM_CXSCREEN)))) // user portrait,
device landscape
+ if( (width > GetSystemMetrics(SM_CYSCREEN)) || (height
> GetSystemMetrics(SM_CXSCREEN)))
+// if( !((width == gapi->gxProperties.cyHeight)
&& (height == gapi->gxProperties.cxWidth))) // user portrait, device
landscape
gapi->hiresFix = 1;
switch( gapi->userOrientation )
!! It used to query system metrics which return dimensions according to screen
!! orientation, which can really be portrait, left landscape or right landscape.
!! This is presumably incorrect because we couldn't care less about user mode
!! dimensions - all we want are the GAPI framebuffer dimensions, which
only match
!! user dimensions in one of possible orientations.
!! There's a fair dose of cargo cult programming involved in this fix, but it
!! used to work only in one orientation (portrait for PDAs, where frame-buffer
!! have same orientation as user screen), and now it works on all orientations.
@@ -742,21 +746,30 @@
WIN_FlushMessageQueue();
/* Open GAPI display */
- if( !gapi->useVga && this->hidden->useGXOpenDisplay )
+ if( !gapi->useVga && this->hidden->useGXOpenDisplay &&
!this->hidden->alreadyGXOpened )
+ {
+ this->hidden->alreadyGXOpened = 1;
if( !gapi->gxFunc.GXOpenDisplay(SDL_Window, GX_FULLSCREEN) )
{
SDL_SetError("Couldn't initialize GAPI");
return(NULL);
}
+ }
#if REPORT_VIDEO_INFO
printf("Video properties:\n");
printf("display bpp: %d\n", gapi->gxProperties.cBPP);
printf("display width: %d\n", gapi->gxProperties.cxWidth);
printf("display height: %d\n", gapi->gxProperties.cyHeight);
+ printf("system display width: %d\n", GetSystemMetrics(SM_CXSCREEN));
+ printf("system display height: %d\n", GetSystemMetrics(SM_CYSCREEN));
printf("x pitch: %d\n", gapi->gxProperties.cbxPitch);
printf("y pitch: %d\n", gapi->gxProperties.cbyPitch);
printf("gapi flags: 0x%x\n", gapi->gxProperties.ffFormat);
+ printf("user orientation: %d\n", gapi->userOrientation);
+ printf("system orientation: %d\n", gapi->userOrientation);
+ printf("gapi orientation: %d\n", gapi->gapiOrientation);
+
if( !gapi->useVga && this->hidden->useGXOpenDisplay && gapi->needUpdate)
{
!! Previous version used to call gapi->gxFunc.GXOpenDisplay each time the video
!! mode would be changed. You shouldn't, because this call has a
meaning "Lock the
!! GAPI framebuffer, designate it as busy", so the second call will fail (it is
!! already locked/busy).
!! Testing might not find that because most programs set up the video mode only
!! once, but POWDER does this once in a while, so it crashed when in
320x240 mode
!! (640x480 mode doesn't use that code, it worked fine).
diff -bru SDL-1.2.13/src/video/gapi/SDL_gapivideo.h
SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h
--- SDL-1.2.13/src/video/gapi/SDL_gapivideo.h 2007-12-31
07:48:00.000000000 +0300
+++ SDL-1.2.13-new/src/video/gapi/SDL_gapivideo.h 2008-10-16
20:02:11.000000000 +0400
@@ -132,12 +132,17 @@
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
+ // The orientation of the video mode user wants to get
+ // Probably restricted to UP and RIGHT
enum SDL_ScreenOrientation userOrientation;
int invert;
char hiresFix; // using hires mode without defining hires resource
// --------------
int useGXOpenDisplay; /* use GXOpenDispplay */
+ int alreadyGXOpened;
int w, h;
+ // The orientation of GAPI framebuffer.
+ // Never changes on the same device.
enum SDL_ScreenOrientation gapiOrientation;
void *buffer; // may be 8, 16, 24, 32 bpp
@@ -153,6 +158,10 @@
int startOffset; // in bytes
int useVga;
int suspended; // do not pu anything into video memory
+ // The orientation of the system, as defined by SM_CXSCREEN
and SM_CYSCREEN
+ // User can change it by using 'screen layout' in system options
+ // Restricted to UP or RIGHT
+ enum SDL_ScreenOrientation systemOrientation;
};
!! This is a flag variable, see the previous comment
!! And yet another orientation: now we have to keep three of them in mind.
diff -bru SDL-1.2.13/src/video/wincommon/SDL_sysevents.c
SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c
--- SDL-1.2.13/src/video/wincommon/SDL_sysevents.c 2007-12-31
07:48:02.000000000 +0300
+++ SDL-1.2.13-new/src/video/wincommon/SDL_sysevents.c 2008-10-16
20:02:12.000000000 +0400
@@ -160,10 +160,22 @@
#endif */
}
break;
+ // FIXME: Older version used just SDL_VideoSurface->(w, h)
+ // w and h are "clipped" while x and y are "raw", which caused
+ // x in former and y in latter case to be clipped in a
wrong direction,
+ // thus offsetting the coordinate on 2 x clip pixels
+ // (like, 128 for 640 -> 512 clipping).
+ // We will now try to extract and use raw values.
+ // The way to do that RIGHT is do
(orientation-dependent) clipping before
+ // doing this transform, but it's hardly possible.
+
+ // SEE SDL_mouse.c /ClipOffset to understand these calculations.
case SDL_ORIENTATION_RIGHT:
if (!SDL_VideoSurface)
break;
- rotatedX = SDL_VideoSurface->w - *y;
+ rotatedX = (2 *
((SDL_VideoSurface->offset%SDL_VideoSurface->pitch)/
+ SDL_VideoSurface->format->BytesPerPixel))
+ + SDL_VideoSurface->w - *y;
rotatedY = *x;
*x = rotatedX;
*y = rotatedY;
@@ -172,7 +184,8 @@
if (!SDL_VideoSurface)
break;
rotatedX = *y;
- rotatedY = SDL_VideoSurface->h - *x;
+ rotatedY = (2 *
(SDL_VideoSurface->offset/SDL_VideoSurface->pitch))
+ + SDL_VideoSurface->h - *x;
*x = rotatedX;
*y = rotatedY;
break;
!! That's the trickest part, hence the long comment.
!! GAPI would really support only 320x240 or 640x480 mode, if application
!! requested the different screen size (as POWDER did, wishing
256x192), then SDL
!! is going to grab the first mode that fits the requested, and pad the screen
!! with black bars (as they do with wide-screen films).
!! It would also get, say, 240x320 mode, and to turn it into 256x192 it would
!! need to rotate mouse clicks.
!! It worked, but one bug slipped through: it would receive mouse clicks
!! unpadded, then rotate them, and then pad the black bars. The
problem is: rotate
!! is done by GAPI driver while padding is done by SDL core. SDL core
doesn't know
!! anything about rotating, so it would pad one of dimensions incorrectly.
I understand that some of my claims (or code) might seem unbacked, but you can
always grab the POWDER binary, compile your own libsdl with one or more of
those fixes turned off, and see how weird it would misbehave. I can even supply
you with those custom builds of libsdl if you don't want to set up the build
environment for windows ce, you'll just need a PDA or a smartphone with it.
I plan to take care of SDL on Windows CE as long as I maintain the POWDER port.
POWDER is good for that because it:
Employs both padded (with centered image, black bars) and unpadded
(image occupies full screen) graphics; initializes video more than
once; uses both 320x240 and 640x480 video; uses both stylus and
buttons.
There's still a list of unresolved issues which I'm planning to fix:
1) Arrow buttons on PDA return weird scancodes compared to PC, this
caused the game to misbehave before I've fixed that. You can see it on
those diagrams:
http://wrar.name/upload/powder-htc.png
http://wrar.name/upload/powder-pda.png
2) SDL (or underlying windows) doesn't care to rotate arrow presses
when we're in a low-res GAPI mode, but it will rotate them in VGA mode
(because of different screen orientations, the same arrow buttons can
suddently mean different directions). Solution: we should stick to
GAPI user orientation (the orientation the program supposedly wants)
and rotate the keys on our own.
_______________________________________________
SDL mailing list
SDL@lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 07 Nov 2008 04:15:36 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb a1b03ba2fcd0 |
rev | line source |
---|---|
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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1379
diff
changeset
|
22 #include "SDL_config.h" |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
23 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
24 /* 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
|
25 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
26 #include <sys/types.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
27 #include <sys/time.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
28 #include <sys/ioctl.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
29 #include <unistd.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
30 #include <fcntl.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
31 #include <errno.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
32 #include <limits.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
33 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
34 /* For parsing /proc */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
35 #include <dirent.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
36 #include <ctype.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
37 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
38 #include <linux/vt.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
39 #include <linux/kd.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
40 #include <linux/keyboard.h> |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
41 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
42 #include "SDL_mutex.h" |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
43 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
44 #include "../../events/SDL_sysevents.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
45 #include "../../events/SDL_events_c.h" |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
46 #include "SDL_gsvideo.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
47 #include "SDL_gsevents_c.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
48 #include "SDL_gskeys.h" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
49 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
50 #ifndef GPM_NODE_FIFO |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
51 #define GPM_NODE_FIFO "/dev/gpmdata" |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
52 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
53 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
54 /* 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
|
55 #define NUM_VGAKEYMAPS (1<<KG_CAPSSHIFT) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
56 static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
57 static SDLKey keymap[128]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
58 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
|
59 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
|
60 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
61 /* 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
|
62 Oh, it's not so bad. :-) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
63 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
64 FIXME: Add keyboard LED handling code |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
65 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
66 static void GS_vgainitkeymaps(int fd) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
67 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
68 struct kbentry entry; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
69 int map, i; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
70 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
71 /* 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
|
72 if ( fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
73 return; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
74 } |
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 /* Load all the keysym mappings */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
77 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
|
78 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
|
79 for ( i=0; i<NR_KEYS; ++i ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
80 entry.kb_table = map; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
81 entry.kb_index = i; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
82 if ( ioctl(fd, KDGKBENT, &entry) == 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
83 /* fill keytemp. This replaces SDL_fbkeys.h */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
84 if ( (map == 0) && (i<128) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
85 keymap_temp[i] = entry.kb_value; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
86 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
87 /* The "Enter" key is a special case */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
88 if ( entry.kb_value == K_ENTER ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
89 entry.kb_value = K(KT_ASCII,13); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
90 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
91 /* Handle numpad specially as well */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
92 if ( KTYP(entry.kb_value) == KT_PAD ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
93 switch ( entry.kb_value ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
94 case K_P0: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
95 case K_P1: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
96 case K_P2: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
97 case K_P3: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
98 case K_P4: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
99 case K_P5: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
100 case K_P6: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
101 case K_P7: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
102 case K_P8: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
103 case K_P9: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
104 vga_keymap[map][i]=entry.kb_value; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
105 vga_keymap[map][i]+= '0'; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
106 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
107 case K_PPLUS: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
108 vga_keymap[map][i]=K(KT_ASCII,'+'); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
109 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
110 case K_PMINUS: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
111 vga_keymap[map][i]=K(KT_ASCII,'-'); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
112 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
113 case K_PSTAR: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
114 vga_keymap[map][i]=K(KT_ASCII,'*'); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
115 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
116 case K_PSLASH: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
117 vga_keymap[map][i]=K(KT_ASCII,'/'); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
118 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
119 case K_PENTER: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
120 vga_keymap[map][i]=K(KT_ASCII,'\r'); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
121 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
122 case K_PCOMMA: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
123 vga_keymap[map][i]=K(KT_ASCII,','); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
124 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
125 case K_PDOT: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
126 vga_keymap[map][i]=K(KT_ASCII,'.'); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
127 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
128 default: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
129 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
130 } |
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 /* Do the normal key translation */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
133 if ( (KTYP(entry.kb_value) == KT_LATIN) || |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
134 (KTYP(entry.kb_value) == KT_ASCII) || |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
135 (KTYP(entry.kb_value) == KT_LETTER) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
136 vga_keymap[map][i] = entry.kb_value; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
137 } |
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 int GS_InGraphicsMode(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
144 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
145 return((keyboard_fd >= 0) && (saved_kbd_mode >= 0)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
146 } |
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 int GS_EnterGraphicsMode(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
149 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
150 struct termios keyboard_termios; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
151 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
152 /* Set medium-raw keyboard mode */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
153 if ( (keyboard_fd >= 0) && !GS_InGraphicsMode(this) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
154 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
155 /* Switch to the correct virtual terminal */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
156 if ( current_vt > 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
157 struct vt_stat vtstate; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
158 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
159 if ( ioctl(keyboard_fd, VT_GETSTATE, &vtstate) == 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
160 saved_vt = vtstate.v_active; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
161 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
162 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
|
163 ioctl(keyboard_fd, VT_WAITACTIVE, current_vt); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
164 } |
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 /* Set the terminal input mode */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
168 if ( tcgetattr(keyboard_fd, &saved_kbd_termios) < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
169 SDL_SetError("Unable to get terminal attributes"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
170 if ( keyboard_fd > 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
171 close(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
172 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
173 keyboard_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
174 return(-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
175 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
176 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
|
177 SDL_SetError("Unable to get current keyboard mode"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
178 if ( keyboard_fd > 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
179 close(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
180 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
181 keyboard_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
182 return(-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
183 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
184 keyboard_termios = saved_kbd_termios; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
185 keyboard_termios.c_lflag &= ~(ICANON | ECHO | ISIG); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
186 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
|
187 keyboard_termios.c_cc[VMIN] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
188 keyboard_termios.c_cc[VTIME] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
189 if (tcsetattr(keyboard_fd, TCSAFLUSH, &keyboard_termios) < 0) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
190 GS_CloseKeyboard(this); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
191 SDL_SetError("Unable to set terminal attributes"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
192 return(-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
193 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
194 /* 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
|
195 if ( ioctl(keyboard_fd, KDSKBMODE, K_MEDIUMRAW) < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
196 GS_CloseKeyboard(this); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
197 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
|
198 return(-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
199 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
200 if ( ioctl(keyboard_fd, KDSETMODE, KD_GRAPHICS) < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
201 GS_CloseKeyboard(this); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
202 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
|
203 return(-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
204 } |
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 return(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
207 } |
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 void GS_LeaveGraphicsMode(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
210 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
211 if ( GS_InGraphicsMode(this) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
212 ioctl(keyboard_fd, KDSETMODE, KD_TEXT); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
213 ioctl(keyboard_fd, KDSKBMODE, saved_kbd_mode); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
214 tcsetattr(keyboard_fd, TCSAFLUSH, &saved_kbd_termios); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
215 saved_kbd_mode = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
216 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
217 /* Head back over to the original virtual terminal */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
218 if ( saved_vt > 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
219 ioctl(keyboard_fd, VT_ACTIVATE, saved_vt); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
220 } |
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 void GS_CloseKeyboard(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
225 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
226 if ( keyboard_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
227 GS_LeaveGraphicsMode(this); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
228 if ( keyboard_fd > 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
229 close(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
230 } |
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 keyboard_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
233 } |
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 int GS_OpenKeyboard(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
236 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
237 /* Open only if not already opened */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
238 if ( keyboard_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
239 char *tty0[] = { "/dev/tty0", "/dev/vc/0", NULL }; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
240 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
|
241 int i, tty0_fd; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
242 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
243 /* Try to query for a free virtual terminal */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
244 tty0_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
245 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
|
246 tty0_fd = open(tty0[i], O_WRONLY, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
247 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
248 if ( tty0_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
249 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
|
250 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
251 ioctl(tty0_fd, VT_OPENQRY, ¤t_vt); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
252 close(tty0_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
253 if ( (geteuid() == 0) && (current_vt > 0) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
254 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
|
255 char vtpath[12]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
256 |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
257 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
|
258 keyboard_fd = open(vtpath, O_RDWR, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
259 #ifdef DEBUG_KEYBOARD |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
260 fprintf(stderr, "vtpath = %s, fd = %d\n", |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
261 vtpath, keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
262 #endif /* DEBUG_KEYBOARD */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
263 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
264 /* This needs to be our controlling tty |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
265 so that the kernel ioctl() calls work |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
266 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
267 if ( keyboard_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
268 tty0_fd = open("/dev/tty", O_RDWR, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
269 if ( tty0_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
270 ioctl(tty0_fd, TIOCNOTTY, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
271 close(tty0_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
272 } |
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 if ( keyboard_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
277 /* 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
|
278 current_vt = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
279 keyboard_fd = open("/dev/tty", O_RDWR); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
280 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
281 #ifdef DEBUG_KEYBOARD |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
282 fprintf(stderr, "Current VT: %d\n", current_vt); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
283 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
284 saved_kbd_mode = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
285 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
286 /* 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
|
287 { int dummy; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
288 if ( ioctl(keyboard_fd, KDGKBMODE, &dummy) < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
289 close(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
290 keyboard_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
291 SDL_SetError("Unable to open a console terminal"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
292 } |
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 /* Set up keymap */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
296 GS_vgainitkeymaps(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
297 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
298 return(keyboard_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
299 } |
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 static enum { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
302 MOUSE_NONE = -1, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
303 MOUSE_GPM, /* Note: GPM uses the MSC protocol */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
304 MOUSE_PS2, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
305 MOUSE_IMPS2, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
306 MOUSE_MS, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
307 MOUSE_BM, |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
308 NUM_MOUSE_DRVS |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
309 } mouse_drv = MOUSE_NONE; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
310 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
311 void GS_CloseMouse(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
312 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
313 if ( mouse_fd > 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
314 close(mouse_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
315 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
316 mouse_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
317 } |
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 /* 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
|
320 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
|
321 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
322 struct dirent *entry; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
323 int pid; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
324 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
325 /* First scan proc for the gpm process */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
326 pid = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
327 while ( (pid == 0) && ((entry=readdir(proc)) != NULL) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
328 if ( isdigit(entry->d_name[0]) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
329 FILE *status; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
330 char path[PATH_MAX]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
331 char name[PATH_MAX]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
332 |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
333 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
|
334 status=fopen(path, "r"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
335 if ( status ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
336 name[0] = '\0'; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
337 fscanf(status, "Name: %s", name); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
338 if ( SDL_strcmp(name, wanted_name) == 0 ) { |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
339 pid = atoi(entry->d_name); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
340 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
341 fclose(status); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
342 } |
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 return pid; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
346 } |
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 /* 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
|
349 static int gpm_available(void) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
350 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
351 int available; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
352 DIR *proc; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
353 int pid; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
354 int cmdline, len, arglen; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
355 char path[PATH_MAX]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
356 char args[PATH_MAX], *arg; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
357 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
358 /* 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
|
359 if ( access(GPM_NODE_FIFO, F_OK) < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
360 return(0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
361 } |
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 available = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
364 proc = opendir("/proc"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
365 if ( proc ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
366 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
|
367 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
|
368 cmdline = open(path, O_RDONLY, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
369 if ( cmdline >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
370 len = read(cmdline, args, sizeof(args)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
371 arg = args; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
372 while ( len > 0 ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
373 if ( SDL_strcmp(arg, "-R") == 0 ) { |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
374 available = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
375 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
376 arglen = SDL_strlen(arg)+1; |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
377 len -= arglen; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
378 arg += arglen; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
379 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
380 close(cmdline); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
381 } |
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 closedir(proc); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
384 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
385 return available; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
386 } |
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 /* 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
|
390 * 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
|
391 * 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
|
392 * 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
|
393 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
394 static int set_imps2_mode(int fd) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
395 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
396 /* 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
|
397 Set IMPS/2 protocol: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
398 {0xf3,200,0xf3,100,0xf3,80} |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
399 Reset mouse device: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
400 {0xFF} |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
401 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
402 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
|
403 Uint8 reset = 0xff; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
404 fd_set fdset; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
405 struct timeval tv; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
406 int retval = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
407 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
408 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
|
409 if (write(fd, &reset, sizeof (reset)) == sizeof (reset) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
410 retval = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
411 } |
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 /* Get rid of any chatter from the above */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
415 FD_ZERO(&fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
416 FD_SET(fd, &fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
417 tv.tv_sec = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
418 tv.tv_usec = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
419 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
|
420 char temp[32]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
421 read(fd, temp, sizeof(temp)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
422 } |
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 return retval; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
425 } |
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 /* 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
|
429 static int detect_imps2(int fd) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
430 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
431 int imps2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
432 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
433 imps2 = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
434 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
435 if ( SDL_getenv("SDL_MOUSEDEV_IMPS2") ) { |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
436 imps2 = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
437 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
438 if ( ! imps2 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
439 Uint8 query_ps2 = 0xF2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
440 fd_set fdset; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
441 struct timeval tv; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
442 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
443 /* Get rid of any mouse motion noise */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
444 FD_ZERO(&fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
445 FD_SET(fd, &fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
446 tv.tv_sec = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
447 tv.tv_usec = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
448 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
|
449 char temp[32]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
450 read(fd, temp, sizeof(temp)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
451 } |
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 /* Query for the type of mouse protocol */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
454 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
|
455 Uint8 ch = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
456 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
457 /* Get the mouse protocol response */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
458 do { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
459 FD_ZERO(&fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
460 FD_SET(fd, &fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
461 tv.tv_sec = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
462 tv.tv_usec = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
463 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
|
464 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
465 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
466 } while ( (read(fd, &ch, sizeof (ch)) == sizeof (ch)) && |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
467 ((ch == 0xFA) || (ch == 0xAA)) ); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
468 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
469 /* Experimental values (Logitech wheelmouse) */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
470 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
471 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
|
472 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
473 if ( ch == 3 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
474 imps2 = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
475 } |
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 return imps2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
479 } |
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 int GS_OpenMouse(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
482 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
483 int i; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
484 const char *mousedev; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
485 const char *mousedrv; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
486 |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
487 mousedrv = SDL_getenv("SDL_MOUSEDRV"); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
488 mousedev = SDL_getenv("SDL_MOUSEDEV"); |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
489 mouse_fd = -1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
490 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
491 /* STD MICE */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
492 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
493 if ( mousedev == NULL ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
494 /* FIXME someday... allow multiple mice in this driver */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
495 char *ps2mice[] = { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
496 "/dev/input/mice", "/dev/usbmouse", "/dev/psaux", NULL |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
497 }; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
498 /* First try to use GPM in repeater mode */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
499 if ( mouse_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
500 if ( gpm_available() ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
501 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
|
502 if ( mouse_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
503 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
504 fprintf(stderr, "Using GPM mouse\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
505 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
506 mouse_drv = MOUSE_GPM; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
507 } |
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 /* 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
|
511 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
|
512 mouse_fd = open(ps2mice[i], O_RDWR, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
513 if (mouse_fd < 0) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
514 mouse_fd = open(ps2mice[i], O_RDONLY, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
515 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
516 if (mouse_fd >= 0) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
517 /* rcg06112001 Attempt to set IMPS/2 mode */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
518 if ( i == 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
519 set_imps2_mode(mouse_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
520 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
521 if (detect_imps2(mouse_fd)) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
522 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
523 fprintf(stderr, "Using IMPS2 mouse\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
524 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
525 mouse_drv = MOUSE_IMPS2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
526 } else { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
527 mouse_drv = MOUSE_PS2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
528 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
529 fprintf(stderr, "Using PS2 mouse\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
530 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
531 } |
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 /* 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
|
535 if ( mouse_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
536 mouse_fd = open("/dev/adbmouse", O_RDONLY, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
537 if ( mouse_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
538 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
539 fprintf(stderr, "Using ADB mouse\n"); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
540 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
541 mouse_drv = MOUSE_BM; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
542 } |
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 /* Default to a serial Microsoft mouse */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
546 if ( mouse_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
547 if ( mousedev == NULL ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
548 mousedev = "/dev/mouse"; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
549 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
550 mouse_fd = open(mousedev, O_RDONLY, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
551 if ( mouse_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
552 struct termios mouse_termios; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
553 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
554 /* Set the sampling speed to 1200 baud */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
555 tcgetattr(mouse_fd, &mouse_termios); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
556 mouse_termios.c_iflag = IGNBRK | IGNPAR; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
557 mouse_termios.c_oflag = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
558 mouse_termios.c_lflag = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
559 mouse_termios.c_line = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
560 mouse_termios.c_cc[VTIME] = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
561 mouse_termios.c_cc[VMIN] = 1; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
562 mouse_termios.c_cflag = CREAD | CLOCAL | HUPCL; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
563 mouse_termios.c_cflag |= CS8; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
564 mouse_termios.c_cflag |= B1200; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
565 tcsetattr(mouse_fd, TCSAFLUSH, &mouse_termios); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
566 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
567 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
|
568 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
569 mouse_drv = MOUSE_MS; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
570 } |
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 if ( mouse_fd < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
573 mouse_drv = MOUSE_NONE; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
574 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
575 return(mouse_fd); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
576 } |
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 static int posted = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
579 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
580 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
|
581 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
582 int button_1, button_3; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
583 int button_state; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
584 int state_changed; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
585 int i; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
586 Uint8 state; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
587 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
588 if ( dx || dy ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
589 posted += SDL_PrivateMouseMotion(0, 1, dx, dy); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
590 } |
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 /* Swap button 1 and 3 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
593 button_1 = (button & 0x04) >> 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
594 button_3 = (button & 0x01) << 2; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
595 button &= ~0x05; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
596 button |= (button_1|button_3); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
597 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
598 /* See what changed */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
599 button_state = SDL_GetMouseState(NULL, NULL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
600 state_changed = button_state ^ button; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
601 for ( i=0; i<8; ++i ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
602 if ( state_changed & (1<<i) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
603 if ( button & (1<<i) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
604 state = SDL_PRESSED; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
605 } else { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
606 state = SDL_RELEASED; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
607 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
608 posted += SDL_PrivateMouseButton(state, i+1, 0, 0); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
609 } |
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 /* 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
|
614 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
|
615 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
616 static void handle_mouse(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
617 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
618 static int start = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
619 static unsigned char mousebuf[BUFSIZ]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
620 int i, nread; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
621 int button = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
622 int dx = 0, dy = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
623 int packetsize = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
624 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
625 /* Figure out the mouse packet size */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
626 switch (mouse_drv) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
627 case MOUSE_NONE: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
628 /* Ack! */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
629 read(mouse_fd, mousebuf, BUFSIZ); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
630 return; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
631 case MOUSE_GPM: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
632 packetsize = 5; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
633 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
634 case MOUSE_IMPS2: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
635 packetsize = 4; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
636 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
637 case MOUSE_PS2: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
638 case MOUSE_MS: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
639 case MOUSE_BM: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
640 packetsize = 3; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
641 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
642 case NUM_MOUSE_DRVS: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
643 /* Uh oh.. */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
644 packetsize = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
645 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
646 } |
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 /* Read as many packets as possible */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
649 nread = read(mouse_fd, &mousebuf[start], BUFSIZ-start); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
650 if ( nread < 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
651 return; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
652 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
653 nread += start; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
654 #ifdef DEBUG_MOUSE |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
655 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
|
656 #endif |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
657 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
|
658 switch (mouse_drv) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
659 case MOUSE_NONE: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
660 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
661 case MOUSE_GPM: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
662 /* GPM protocol has 0x80 in high byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
663 if ( (mousebuf[i] & 0xF8) != 0x80 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
664 /* Go to next byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
665 i -= (packetsize-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
666 continue; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
667 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
668 /* Get current mouse state */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
669 button = (~mousebuf[i]) & 0x07; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
670 dx = (signed char)(mousebuf[i+1]) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
671 (signed char)(mousebuf[i+3]); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
672 dy = -((signed char)(mousebuf[i+2]) + |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
673 (signed char)(mousebuf[i+4])); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
674 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
675 case MOUSE_PS2: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
676 /* PS/2 protocol has nothing in high byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
677 if ( (mousebuf[i] & 0xC0) != 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
678 /* Go to next byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
679 i -= (packetsize-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
680 continue; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
681 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
682 /* Get current mouse state */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
683 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
684 (mousebuf[i] & 0x02) >> 1 | /*Right*/ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
685 (mousebuf[i] & 0x01) << 2; /*Left*/ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
686 dx = (mousebuf[i] & 0x10) ? |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
687 mousebuf[i+1] - 256 : mousebuf[i+1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
688 dy = (mousebuf[i] & 0x20) ? |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
689 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
690 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
691 case MOUSE_IMPS2: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
692 /* Get current mouse state */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
693 button = (mousebuf[i] & 0x04) >> 1 | /*Middle*/ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
694 (mousebuf[i] & 0x02) >> 1 | /*Right*/ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
695 (mousebuf[i] & 0x01) << 2 | /*Left*/ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
696 (mousebuf[i] & 0x40) >> 3 | /* 4 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
697 (mousebuf[i] & 0x80) >> 3; /* 5 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
698 dx = (mousebuf[i] & 0x10) ? |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
699 mousebuf[i+1] - 256 : mousebuf[i+1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
700 dy = (mousebuf[i] & 0x20) ? |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
701 -(mousebuf[i+2] - 256) : -mousebuf[i+2]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
702 switch (mousebuf[i+3]&0x0F) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
703 case 0x0E: /* DX = +1 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
704 case 0x02: /* DX = -1 */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
705 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
706 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
|
707 FB_vgamousecallback(button | (1<<3), |
2604a7be65af
Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
70
diff
changeset
|
708 1, 0, 0); |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
709 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
710 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
|
711 FB_vgamousecallback(button | (1<<4), |
2604a7be65af
Added button-up with mouse-wheel on framebuffer console
Sam Lantinga <slouken@libsdl.org>
parents:
70
diff
changeset
|
712 1, 0, 0); |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
713 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
714 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
715 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
716 case MOUSE_MS: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
717 /* Microsoft protocol has 0x40 in high byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
718 if ( (mousebuf[i] & 0x40) != 0x40 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
719 /* Go to next byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
720 i -= (packetsize-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
721 continue; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
722 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
723 /* Get current mouse state */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
724 button = ((mousebuf[i] & 0x20) >> 3) | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
725 ((mousebuf[i] & 0x10) >> 4); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
726 dx = (signed char)(((mousebuf[i] & 0x03) << 6) | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
727 (mousebuf[i + 1] & 0x3F)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
728 dy = (signed char)(((mousebuf[i] & 0x0C) << 4) | |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
729 (mousebuf[i + 2] & 0x3F)); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
730 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
731 case MOUSE_BM: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
732 /* BusMouse protocol has 0xF8 in high byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
733 if ( (mousebuf[i] & 0xF8) != 0x80 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
734 /* Go to next byte */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
735 i -= (packetsize-1); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
736 continue; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
737 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
738 /* Get current mouse state */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
739 button = (~mousebuf[i]) & 0x07; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
740 dx = (signed char)mousebuf[i+1]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
741 dy = -(signed char)mousebuf[i+2]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
742 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
743 case NUM_MOUSE_DRVS: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
744 /* Uh oh.. */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
745 dx = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
746 dy = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
747 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
748 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
749 GS_vgamousecallback(button, dx, dy); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
750 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
751 if ( i < nread ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
752 SDL_memcpy(mousebuf, &mousebuf[i], (nread-i)); |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
753 start = (nread-i); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
754 } else { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
755 start = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
756 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
757 return; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
758 } |
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 static void handle_keyboard(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
761 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
762 unsigned char keybuf[BUFSIZ]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
763 int i, nread; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
764 int pressed; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
765 int scancode; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
766 SDL_keysym keysym; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
767 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
768 nread = read(keyboard_fd, keybuf, BUFSIZ); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
769 for ( i=0; i<nread; ++i ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
770 scancode = keybuf[i] & 0x7F; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
771 if ( keybuf[i] & 0x80 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
772 pressed = SDL_RELEASED; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
773 } else { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
774 pressed = SDL_PRESSED; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
775 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
776 TranslateKey(scancode, &keysym); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
777 posted += SDL_PrivateKeyboard(pressed, &keysym); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
778 } |
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 void GS_PumpEvents(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
782 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
783 fd_set fdset; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
784 int max_fd; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
785 static struct timeval zero; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
786 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
787 do { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
788 posted = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
789 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
790 FD_ZERO(&fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
791 max_fd = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
792 if ( keyboard_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
793 FD_SET(keyboard_fd, &fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
794 if ( max_fd < keyboard_fd ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
795 max_fd = keyboard_fd; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
796 } |
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 if ( mouse_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
799 FD_SET(mouse_fd, &fdset); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
800 if ( max_fd < mouse_fd ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
801 max_fd = mouse_fd; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
802 } |
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 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
|
805 if ( keyboard_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
806 if ( FD_ISSET(keyboard_fd, &fdset) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
807 handle_keyboard(this); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
808 } |
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 if ( mouse_fd >= 0 ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
811 if ( FD_ISSET(mouse_fd, &fdset) ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
812 handle_mouse(this); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
813 } |
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 } while ( posted ); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
817 } |
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 void GS_InitOSKeymap(_THIS) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
820 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
821 int i; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
822 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
823 /* Initialize the Linux key translation table */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
824 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
825 /* First get the ascii keys and others not well handled */ |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
826 for (i=0; i<SDL_arraysize(keymap); ++i) { |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
827 switch(i) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
828 /* 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
|
829 case SCANCODE_PRINTSCREEN: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
830 keymap[i] = SDLK_PRINT; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
831 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
832 case SCANCODE_BREAK: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
833 keymap[i] = SDLK_BREAK; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
834 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
835 case SCANCODE_BREAK_ALTERNATIVE: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
836 keymap[i] = SDLK_PAUSE; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
837 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
838 case SCANCODE_LEFTSHIFT: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
839 keymap[i] = SDLK_LSHIFT; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
840 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
841 case SCANCODE_RIGHTSHIFT: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
842 keymap[i] = SDLK_RSHIFT; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
843 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
844 case SCANCODE_LEFTCONTROL: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
845 keymap[i] = SDLK_LCTRL; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
846 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
847 case SCANCODE_RIGHTCONTROL: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
848 keymap[i] = SDLK_RCTRL; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
849 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
850 case SCANCODE_RIGHTWIN: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
851 keymap[i] = SDLK_RSUPER; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
852 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
853 case SCANCODE_LEFTWIN: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
854 keymap[i] = SDLK_LSUPER; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
855 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
856 case 127: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
857 keymap[i] = SDLK_MENU; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
858 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
859 /* 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
|
860 default: |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
861 keymap[i] = KVAL(vga_keymap[0][i]); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
862 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
863 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
864 } |
1379
c0a74f199ecf
Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
865 for (i=0; i<SDL_arraysize(keymap); ++i) { |
70
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
866 switch(keymap_temp[i]) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
867 case K_F1: keymap[i] = SDLK_F1; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
868 case K_F2: keymap[i] = SDLK_F2; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
869 case K_F3: keymap[i] = SDLK_F3; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
870 case K_F4: keymap[i] = SDLK_F4; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
871 case K_F5: keymap[i] = SDLK_F5; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
872 case K_F6: keymap[i] = SDLK_F6; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
873 case K_F7: keymap[i] = SDLK_F7; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
874 case K_F8: keymap[i] = SDLK_F8; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
875 case K_F9: keymap[i] = SDLK_F9; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
876 case K_F10: keymap[i] = SDLK_F10; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
877 case K_F11: keymap[i] = SDLK_F11; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
878 case K_F12: keymap[i] = SDLK_F12; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
879 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
880 case K_DOWN: keymap[i] = SDLK_DOWN; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
881 case K_LEFT: keymap[i] = SDLK_LEFT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
882 case K_RIGHT: keymap[i] = SDLK_RIGHT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
883 case K_UP: keymap[i] = SDLK_UP; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
884 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
885 case K_P0: keymap[i] = SDLK_KP0; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
886 case K_P1: keymap[i] = SDLK_KP1; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
887 case K_P2: keymap[i] = SDLK_KP2; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
888 case K_P3: keymap[i] = SDLK_KP3; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
889 case K_P4: keymap[i] = SDLK_KP4; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
890 case K_P5: keymap[i] = SDLK_KP5; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
891 case K_P6: keymap[i] = SDLK_KP6; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
892 case K_P7: keymap[i] = SDLK_KP7; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
893 case K_P8: keymap[i] = SDLK_KP8; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
894 case K_P9: keymap[i] = SDLK_KP9; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 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
|
899 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
|
900 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
|
901 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
902 case K_SHIFT: if ( keymap[i] != SDLK_RSHIFT ) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
903 keymap[i] = SDLK_LSHIFT; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
904 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
905 case K_SHIFTL: keymap[i] = SDLK_LSHIFT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
906 case K_SHIFTR: keymap[i] = SDLK_RSHIFT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
907 case K_CTRL: if ( keymap[i] != SDLK_RCTRL ) |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
908 keymap[i] = SDLK_LCTRL; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
909 break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
910 case K_CTRLL: keymap[i] = SDLK_LCTRL; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
911 case K_CTRLR: keymap[i] = SDLK_RCTRL; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
912 case K_ALT: keymap[i] = SDLK_LALT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
913 case K_ALTGR: keymap[i] = SDLK_RALT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
914 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
915 case K_INSERT: keymap[i] = SDLK_INSERT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
916 case K_REMOVE: keymap[i] = SDLK_DELETE; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
917 case K_PGUP: keymap[i] = SDLK_PAGEUP; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
918 case K_PGDN: keymap[i] = SDLK_PAGEDOWN; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
919 case K_FIND: keymap[i] = SDLK_HOME; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
920 case K_SELECT: keymap[i] = SDLK_END; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
921 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
922 case K_NUM: keymap[i] = SDLK_NUMLOCK; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
923 case K_CAPS: keymap[i] = SDLK_CAPSLOCK; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
924 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
925 case K_F13: keymap[i] = SDLK_PRINT; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
926 case K_HOLD: keymap[i] = SDLK_SCROLLOCK; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
927 case K_PAUSE: keymap[i] = SDLK_PAUSE; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
928 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
929 case 127: keymap[i] = SDLK_BACKSPACE; break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
930 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
931 default: break; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
932 } |
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 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
|
937 { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
938 /* Set the keysym information */ |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
939 keysym->scancode = scancode; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
940 keysym->sym = keymap[scancode]; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
941 keysym->mod = KMOD_NONE; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
942 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
943 /* 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
|
944 keysym->unicode = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
945 if ( SDL_TranslateUNICODE ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
946 int map; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
947 SDLMod modstate; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
948 |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
949 modstate = SDL_GetModState(); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
950 map = 0; |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
951 if ( modstate & KMOD_SHIFT ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
952 map |= (1<<KG_SHIFT); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
953 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
954 if ( modstate & KMOD_CTRL ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
955 map |= (1<<KG_CTRL); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
956 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
957 if ( modstate & KMOD_ALT ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
958 map |= (1<<KG_ALT); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
959 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
960 if ( modstate & KMOD_MODE ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
961 map |= (1<<KG_ALTGR); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
962 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
963 if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
964 if ( modstate & KMOD_CAPS ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
965 map ^= (1<<KG_SHIFT); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
966 } |
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 if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
969 if ( modstate & KMOD_NUM ) { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
970 keysym->unicode=KVAL(vga_keymap[map][scancode]); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
971 } |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
972 } else { |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
973 keysym->unicode = KVAL(vga_keymap[map][scancode]); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
974 } |
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 return(keysym); |
f590dd383b5d
Added Linux PlayStation 2 Graphics Synthesizer support
Sam Lantinga <slouken@lokigames.com>
parents:
diff
changeset
|
977 } |