Mercurial > sdl-ios-xcode
comparison src/video/wscons/SDL_wsconsevents.c @ 1187:19d8949b4584
To: sdl@libsdl.org
From: Staffan Ulfberg <staffan@ulfberg.se>
Date: 19 Nov 2005 01:00:48 +0100
Subject: [SDL] New driver for OpenBSD/wscons
Hello,
I've written an SDL driver for OpenBSD/wscons (console mode, somewhat
resembling the functionality of the svga driver for Linux). I use it
for playing MAME on my Sharp Zaurus. The alternative is to play under
X, which is slower.
I asked how to submit the driver a few days ago, and posted a link to
the patch in a follow-up, so maybe it was missed?
Anyway, the patch is on the web at:
http://multivac.fatburen.org/SDL-wscons.patch
Comments?
Staffan
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 22 Nov 2005 15:19:50 +0000 |
parents | |
children | c9b51268668f |
comparison
equal
deleted
inserted
replaced
1186:0276947bee66 | 1187:19d8949b4584 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2004 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <sys/types.h> | |
29 #include <dev/wscons/wsdisplay_usl_io.h> | |
30 #include <sys/ioctl.h> | |
31 #include <fcntl.h> | |
32 #include <unistd.h> | |
33 #include <termios.h> | |
34 #include <errno.h> | |
35 #include <string.h> | |
36 | |
37 #include "SDL.h" | |
38 #include "SDL_sysevents.h" | |
39 #include "SDL_events_c.h" | |
40 #include "SDL_wsconsvideo.h" | |
41 #include "SDL_wsconsevents_c.h" | |
42 | |
43 static int posted = 0; | |
44 | |
45 int WSCONS_InitKeyboard(_THIS) | |
46 { | |
47 struct termios tty; | |
48 | |
49 if (ioctl(private->fd, WSKBDIO_GTYPE, &private->kbdType) == -1) { | |
50 WSCONS_ReportError("cannot get keyboard type: %s", strerror(errno)); | |
51 return -1; | |
52 } | |
53 | |
54 if (tcgetattr(private->fd, &private->saved_tty) == -1) { | |
55 WSCONS_ReportError("cannot get terminal attributes: %s", strerror(errno)); | |
56 return -1; | |
57 } | |
58 private->did_save_tty = 1; | |
59 tty = private->saved_tty; | |
60 tty.c_iflag = IGNPAR | IGNBRK; | |
61 tty.c_oflag = 0; | |
62 tty.c_cflag = CREAD | CS8; | |
63 tty.c_lflag = 0; | |
64 tty.c_cc[VTIME] = 0; | |
65 tty.c_cc[VMIN] = 1; | |
66 cfsetispeed(&tty, 9600); | |
67 cfsetospeed(&tty, 9600); | |
68 if (tcsetattr(private->fd, TCSANOW, &tty) < 0) { | |
69 WSCONS_ReportError("cannot set terminal attributes: %s", strerror(errno)); | |
70 return -1; | |
71 } | |
72 if (ioctl(private->fd, KDSKBMODE, K_RAW) == -1) { | |
73 WSCONS_ReportError("cannot set raw keyboard mode: %s", strerror(errno)); | |
74 return -1; | |
75 } | |
76 | |
77 return 0; | |
78 } | |
79 | |
80 void WSCONS_ReleaseKeyboard(_THIS) | |
81 { | |
82 if (private->fd != -1) { | |
83 if (ioctl(private->fd, KDSKBMODE, K_XLATE) == -1) { | |
84 WSCONS_ReportError("cannot restore keyboard to translated mode: %s", | |
85 strerror(errno)); | |
86 } | |
87 if (private->did_save_tty) { | |
88 if (tcsetattr(private->fd, TCSANOW, &private->saved_tty) < 0) { | |
89 WSCONS_ReportError("cannot restore keynoard attributes: %s", | |
90 strerror(errno)); | |
91 } | |
92 } | |
93 } | |
94 } | |
95 | |
96 static void updateMouse() | |
97 { | |
98 } | |
99 | |
100 static SDLKey keymap[128]; | |
101 | |
102 static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) | |
103 { | |
104 keysym->scancode = scancode; | |
105 keysym->sym = SDLK_UNKNOWN; | |
106 keysym->mod = KMOD_NONE; | |
107 | |
108 if (scancode < SDL_TABLESIZE(keymap)) | |
109 keysym->sym = keymap[scancode]; | |
110 | |
111 if (keysym->sym == SDLK_UNKNOWN) | |
112 printf("Unknown mapping for scancode %d\n", scancode); | |
113 | |
114 return keysym; | |
115 } | |
116 | |
117 static void updateKeyboard(_THIS) | |
118 { | |
119 unsigned char buf[100]; | |
120 SDL_keysym keysym; | |
121 int n, i; | |
122 | |
123 if ((n = read(private->fd, buf, sizeof(buf))) > 0) { | |
124 for (i = 0; i < n; i++) { | |
125 char c = buf[i] & 0x7f; | |
126 if (c == 224) // special key prefix -- what should we do with it? | |
127 continue; | |
128 int release = (buf[i] & 0x80) != 0; | |
129 posted += SDL_PrivateKeyboard(release ? SDL_RELEASED : SDL_PRESSED, | |
130 TranslateKey(c, &keysym)); | |
131 } | |
132 } | |
133 } | |
134 | |
135 void WSCONS_PumpEvents(_THIS) | |
136 { | |
137 do { | |
138 posted = 0; | |
139 updateMouse(); | |
140 updateKeyboard(this); | |
141 } while (posted); | |
142 } | |
143 | |
144 void WSCONS_InitOSKeymap(_THIS) | |
145 { | |
146 int i; | |
147 | |
148 /* Make sure unknown keys are mapped correctly */ | |
149 for (i=0; i < SDL_TABLESIZE(keymap); i++) { | |
150 keymap[i] = SDLK_UNKNOWN; | |
151 } | |
152 | |
153 switch (private->kbdType) { | |
154 case WSKBD_TYPE_ZAURUS: | |
155 /* top row */ | |
156 keymap[2] = SDLK_1; | |
157 keymap[3] = SDLK_2; | |
158 keymap[4] = SDLK_3; | |
159 keymap[5] = SDLK_4; | |
160 keymap[6] = SDLK_5; | |
161 keymap[7] = SDLK_6; | |
162 keymap[8] = SDLK_7; | |
163 keymap[9] = SDLK_8; | |
164 keymap[10] = SDLK_9; | |
165 keymap[11] = SDLK_0; | |
166 keymap[14] = SDLK_BACKSPACE; | |
167 | |
168 /* second row */ | |
169 keymap[16] = SDLK_q; | |
170 keymap[17] = SDLK_w; | |
171 keymap[18] = SDLK_e; | |
172 keymap[19] = SDLK_r; | |
173 keymap[20] = SDLK_t; | |
174 keymap[21] = SDLK_y; | |
175 keymap[22] = SDLK_u; | |
176 keymap[23] = SDLK_i; | |
177 keymap[24] = SDLK_o; | |
178 keymap[25] = SDLK_p; | |
179 | |
180 /* third row */ | |
181 keymap[15] = SDLK_TAB; | |
182 keymap[30] = SDLK_a; | |
183 keymap[31] = SDLK_s; | |
184 keymap[32] = SDLK_d; | |
185 keymap[33] = SDLK_f; | |
186 keymap[34] = SDLK_g; | |
187 keymap[35] = SDLK_h; | |
188 keymap[36] = SDLK_j; | |
189 keymap[37] = SDLK_k; | |
190 keymap[38] = SDLK_l; | |
191 | |
192 /* fourth row */ | |
193 keymap[42] = SDLK_LSHIFT; | |
194 keymap[44] = SDLK_z; | |
195 keymap[45] = SDLK_x; | |
196 keymap[46] = SDLK_c; | |
197 keymap[47] = SDLK_v; | |
198 keymap[48] = SDLK_b; | |
199 keymap[49] = SDLK_n; | |
200 keymap[50] = SDLK_m; | |
201 keymap[54] = SDLK_RSHIFT; | |
202 keymap[28] = SDLK_RETURN; | |
203 | |
204 /* fifth row */ | |
205 keymap[56] = SDLK_LALT; | |
206 keymap[29] = SDLK_LCTRL; | |
207 /* keymap[56] = ; */ | |
208 keymap[0] = SDLK_LSUPER; | |
209 keymap[12] = SDLK_MINUS; | |
210 keymap[57] = SDLK_SPACE; | |
211 keymap[51] = SDLK_COMMA; | |
212 keymap[52] = SDLK_PERIOD; | |
213 | |
214 /* misc */ | |
215 keymap[59] = SDLK_F1; | |
216 keymap[60] = SDLK_F2; | |
217 keymap[61] = SDLK_F3; | |
218 keymap[62] = SDLK_F4; | |
219 keymap[63] = SDLK_F5; | |
220 keymap[1] = SDLK_ESCAPE; | |
221 /* keymap[28] = SDLK_KP_ENTER; */ | |
222 keymap[72] = SDLK_UP; | |
223 keymap[75] = SDLK_LEFT; | |
224 keymap[77] = SDLK_RIGHT; | |
225 keymap[80] = SDLK_DOWN; | |
226 break; | |
227 | |
228 default: | |
229 WSCONS_ReportError("Unable to map keys for keyboard type %u", | |
230 private->kbdType); | |
231 break; | |
232 } | |
233 } | |
234 | |
235 /* end of SDL_wsconsevents.c ... */ | |
236 |