/[projet1]/public/pc/emulators/caloric/src/keyb_us.c
Defence Force logotype

Contents of /public/pc/emulators/caloric/src/keyb_us.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (show annotations)
Sun Aug 23 11:20:13 2009 UTC (10 years, 7 months ago) by Jede
File MIME type: text/plain
File size: 9713 byte(s)
Changement de zoom par l'interface
1 /*
2 * keyb_us.c - keyboard input for Xeuphoric
3 * AYM 2002-01-22
4 * SDL modifications (c) 2007 Jean-Yves Lamoureux
5 */
6
7 /*
8 This file is copyright André Majorel 2002.
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of version 2 of the GNU General Public License as published by the
12 Free Software Foundation.
13
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place, Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23
24 #include <limits.h>
25 #include <stdio.h>
26 #include <stdint.h>
27
28 #include <SDL/SDL.h>
29
30 #include "caloric.h"
31 #include "keyb_us.h"
32 #include "screenshot.h"
33
34 extern short Sys_Request;
35 extern long cycles;
36 extern long initial_cycles;
37
38 char env_screen;
39 char hard_screen;
40 char exit_menu;
41 unsigned char Kbd_Matrix[65]; /* FIXME should be 8 */
42 extern uint8_t setfullScreen, fullScreen;
43
44 static signed char keycode_to_oric[512];
45 extern char atmos;
46 extern char telestrat;
47 extern int current_machine;
48 extern int zoom_changed;
49 /*
50 * keyboard_map_init - initialise keycode_to_oric;
51 */
52 void keyboard_map_init (void)
53 {
54 {
55 int n;
56
57 for (n = 0; n < sizeof keycode_to_oric / sizeof *keycode_to_oric; n++)
58 keycode_to_oric[n] = -1;
59 }
60
61 keycode_to_oric[SDLK_1] = OK1;
62 keycode_to_oric[SDLK_2] = OK2;
63 keycode_to_oric[SDLK_3] = OK3;
64 keycode_to_oric[SDLK_4] = OK4;
65 keycode_to_oric[SDLK_5] = OK5;
66 keycode_to_oric[SDLK_6] = OK6;
67 keycode_to_oric[SDLK_7] = OK7;
68 keycode_to_oric[SDLK_8] = OK8;
69 keycode_to_oric[SDLK_9] = OK9;
70 keycode_to_oric[SDLK_0] = OK0;
71 keycode_to_oric[SDLK_MINUS] = OKMI;
72 keycode_to_oric[SDLK_EQUALS] = OKEQ;
73 keycode_to_oric[SDLK_BACKSLASH] = OKBA; /* On many keyboards it's 2 rows down */
74
75 keycode_to_oric[SDLK_ESCAPE] = OKES;
76 keycode_to_oric[SDLK_TAB] = OKES;
77 keycode_to_oric[SDLK_q] = OKQ;
78 keycode_to_oric[SDLK_w] = OKW;
79 keycode_to_oric[SDLK_e] = OKE;
80 keycode_to_oric[SDLK_r] = OKR;
81 keycode_to_oric[SDLK_t] = OKT;
82 keycode_to_oric[SDLK_y] = OKY;
83 keycode_to_oric[SDLK_u] = OKU;
84 keycode_to_oric[SDLK_i] = OKI;
85 keycode_to_oric[SDLK_o] = OKO;
86 keycode_to_oric[SDLK_p] = OKP;
87 keycode_to_oric[SDLK_LEFTBRACKET] = OKBL;
88 keycode_to_oric[SDLK_RIGHTBRACKET] = OKBR;
89 keycode_to_oric[SDLK_BACKSPACE] = OKDE;
90
91 keycode_to_oric[SDLK_CAPSLOCK] = OKCT;
92 keycode_to_oric[SDLK_a] = OKA;
93 keycode_to_oric[SDLK_s] = OKS;
94 keycode_to_oric[SDLK_d] = OKD;
95 keycode_to_oric[SDLK_f] = OKF;
96 keycode_to_oric[SDLK_g] = OKG;
97 keycode_to_oric[SDLK_h] = OKH;
98 keycode_to_oric[SDLK_j] = OKJ;
99 keycode_to_oric[SDLK_k] = OKK;
100 keycode_to_oric[SDLK_l] = OKL;
101 keycode_to_oric[SDLK_SEMICOLON] = OKSE;
102 keycode_to_oric[SDLK_QUOTE] = OKAP;
103 keycode_to_oric[SDLK_RETURN] = OKRE;
104
105 keycode_to_oric[SDLK_LSHIFT] = OKLS;
106 keycode_to_oric[SDLK_LESS] = OKLS; /* Not on all keyboards */
107 keycode_to_oric[SDLK_z] = OKZ;
108 keycode_to_oric[SDLK_x] = OKX;
109 keycode_to_oric[SDLK_c] = OKC;
110 keycode_to_oric[SDLK_v] = OKV;
111 keycode_to_oric[SDLK_b] = OKB;
112 keycode_to_oric[SDLK_n] = OKN;
113 keycode_to_oric[SDLK_m] = OKM;
114 keycode_to_oric[SDLK_COMMA] = OKCO;
115 keycode_to_oric[SDLK_PERIOD] = OKFS;
116 keycode_to_oric[SDLK_SLASH] = OKSL;
117 keycode_to_oric[SDLK_RSHIFT] = OKRS;
118
119 #if 0 /* same physical position but not usable at all */
120 /* FIXME suited to 102-key keyboards (i.e. no windows keys) */
121 keycode_to_oric[SDLK_LCTRL] = OKLE;
122 keycode_to_oric[SDLK_LALT] = OKDO;
123 keycode_to_oric[SDLK_SPACE] = OKSP;
124 keycode_to_oric[SDLK_RALT] = OKUP;
125 keycode_to_oric[SDLK_RCTRL] = OKRI;
126 #endif
127 keycode_to_oric[SDLK_LCTRL] = OKCT;
128 keycode_to_oric[SDLK_LALT] = OKFU;
129 keycode_to_oric[SDLK_SPACE] = OKSP;
130 keycode_to_oric[SDLK_RALT] = OKFU;
131 keycode_to_oric[SDLK_RCTRL] = OKCR;
132
133 /* Also map the PC cursor keys */
134 keycode_to_oric[SDLK_UP] = OKUP;
135 keycode_to_oric[SDLK_LEFT] = OKLE;
136 keycode_to_oric[SDLK_DOWN] = OKDO;
137 keycode_to_oric[SDLK_RIGHT] = OKRI;
138
139 /* PC function key */
140 keycode_to_oric[SDLK_F1] = -2;
141 keycode_to_oric[SDLK_F2] = -2;
142 keycode_to_oric[SDLK_F3] = -2;
143 keycode_to_oric[SDLK_F4] = -2;
144 keycode_to_oric[SDLK_F5] = -2;
145 keycode_to_oric[SDLK_F6] = -2;
146 keycode_to_oric[SDLK_F7] = -2;
147 keycode_to_oric[SDLK_F8] = -2;
148 keycode_to_oric[SDLK_F9] = -2;
149 keycode_to_oric[SDLK_F10] = -2;
150 keycode_to_oric[SDLK_F11] = -2;
151 keycode_to_oric[SDLK_F12] = -2;
152
153 /* FIXME no PC key maps to Oric func */
154 }
155
156
157 void keyboard_dump (void)
158 {
159 int n;
160
161 for (n = 0; n < sizeof keycode_to_oric / sizeof *keycode_to_oric; n++)
162 {
163 if (keycode_to_oric[n] < 0)
164 continue;
165 printf ("0x%02x %03o\n", n, keycode_to_oric[n]);
166 }
167 }
168
169
170 void quit_handler (SDL_Event *ev)
171 {
172 Sys_Request |= 0x2000;
173 if (env_screen == 1)
174 exit_menu = 1;
175 }
176
177
178 /*
179 * keyboard_handler - convert X11 keycode to Oric scan code
180 */
181 void keyboard_handler (SDL_Event *ev)
182 {
183 signed char oric_row_column;
184 unsigned keycode = ev->key.keysym.sym;
185 fprintf(stderr, "SDL_KEY%s sym %d \n", (ev->type == SDL_KEYDOWN)?"DOWN":"UP", keycode);
186 if (ev->type == SDL_KEYDOWN && keycode == 0x125) /* F12 - screenshot */
187 {
188 fprintf(stderr, "Screenshot ...\n");
189 screenshot ();
190 return;
191 }
192 oric_row_column = keycode_to_oric[keycode];
193 if (oric_row_column == -2) /* Function key */
194 if (ev->type == SDL_KEYDOWN)
195 switch (keycode)
196 {
197 case 0x11a : /* F1 - setup screen */
198 Sys_Request |= 0x8000;
199 if (env_screen == 1)
200 {
201 if (zoom!=zoom_changed)
202 {
203 zoom=zoom_changed;
204 // initSDL_display();
205 sdl_end();
206 sdl_start();
207 }
208 if (current_machine==1 && atmos==0 && telestrat==0)
209 {
210 Init_Hard();
211 Load_ROM(Oric_Mem+0x10000);
212 Sys_Request |= 0x400;
213 }
214 if (current_machine==1 && atmos==0 && telestrat==1)
215 {
216 Init_Hard();
217 Load_Banks();
218 Load_EPROM();
219 Restart();
220 Sys_Request |= 0x400;
221 }
222 //Restart();
223 //current_machine
224 exit_menu = 1;
225 }
226 return;
227 break;
228 case 0x11b : /* F2 - sound switch */
229 /* toggle_sound (); */
230 if (hard_screen == 1)
231 exit_menu = 1;
232 return;
233 break;
234 case 0x11c : /* F3 - keyboard toggle */
235 /* toggle_keyboard (); */
236 return;
237 break;
238 case 0x11d : /* F4 - double clock */
239 if (cycles < initial_cycles)
240 cycles = initial_cycles;
241 else if (cycles < LONG_MAX / 2)
242 cycles *= 2;
243 return;
244 break;
245 case 0x11e : /* F5 - halve clock */
246 if (cycles > initial_cycles)
247 cycles = initial_cycles;
248 else if (2 * (cycles / 2) == cycles)
249 cycles /= 2;
250 return;
251 break;
252 case 0x11f : /* F6 - Jasmin boot */
253 Sys_Request |= 0x200;
254 if (env_screen == 1)
255 exit_menu = 1;
256 return;
257 break;
258 case 0x120 : /* F7 - NMI */
259 Sys_Request |= 0x400;
260 if (env_screen == 1)
261 exit_menu = 1;
262 return;
263 break;
264 case 0x121 : /* F8 - power on reset */
265 Sys_Request |= 0x800;
266 if (env_screen == 1)
267 exit_menu = 1;
268 return;
269 break;
270 case 0x122 : /* F9 - dump */
271 Sys_Request |= 0x1000;
272 if (env_screen == 1)
273 exit_menu = 1;
274 return;
275 break;
276 case 0x123 : /* F10 - quit */
277 Sys_Request |= 0x2000;
278 if (env_screen == 1)
279 exit_menu = 1;
280 return;
281 break;
282 case 0x124 : /* F11 - toggle fullscreen */
283 setfullScreen = !fullScreen;
284 return;
285 break;
286 default : /* Can't happen */
287 err ("bad fn keycode %d\n", (int) keycode);
288 }
289
290
291 if (keycode < 0 || keycode > sizeof keycode_to_oric / sizeof *keycode_to_oric)
292 {
293 fprintf(stderr, "bad keycode %02x\n", (int) keycode);
294 return;
295 }
296
297 else if (oric_row_column == -1)
298 {
299 return;
300 }
301 else
302 {
303 if (ev->type == SDL_KEYDOWN)
304 Kbd_Matrix[oric_row_column & 7] |= 1 << (oric_row_column >> 3);
305 else if (ev->type == SDL_KEYUP)
306 Kbd_Matrix[oric_row_column & 7] &= ~ (1 << (oric_row_column >> 3));
307 return;
308 }
309 }
310
311
312 void disable_keypad (void)
313 {
314 ; /* FIXME */
315 }
316
317 void enable_keypad (void)
318 {
319 ; /* FIXME */
320 }
321
322
323 void Read_Joystick_on_printer_port (void)
324 {
325 ; /* FIXME */
326 }
327
328
329 void Read_Joystick_on_VIA2 (void)
330 {
331 ; /* FIXME */
332 }
333

  ViewVC Help
Powered by ViewVC 1.1.26