comparison src/video/dc/SDL_dcevents.c @ 509:dad72daf44b3

Added initial support for Dreamcast (thanks HERO!)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Oct 2002 16:50:56 +0000
parents
children b8d311d90021
comparison
equal deleted inserted replaced
508:9ff7e90aaa94 509:dad72daf44b3
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 BERO
20 bero@geocities.co.jp
21
22 based on SDL_nullevents.c by
23
24 Sam Lantinga
25 slouken@libsdl.org
26 */
27
28 #ifdef SAVE_RCSID
29 static char rcsid =
30 "@(#) $Id$";
31 #endif
32
33 /* Being a null driver, there's no event stream. We just define stubs for
34 most of the API. */
35
36 #include "SDL.h"
37 #include "SDL_sysevents.h"
38 #include "SDL_events_c.h"
39 #include "SDL_dcvideo.h"
40 #include "SDL_dcevents_c.h"
41
42 #include <dc/maple.h>
43 #include <dc/maple/mouse.h>
44 #include <dc/maple/keyboard.h>
45
46 const static unsigned short sdl_key[]= {
47 /*0*/ 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
48 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
49 'u', 'v', 'w', 'x', 'y', 'z',
50 /*1e*/ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
51 /*28*/ SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, SDLK_MINUS, SDLK_PLUS, SDLK_LEFTBRACKET,
52 SDLK_RIGHTBRACKET, SDLK_BACKSLASH , 0, SDLK_SEMICOLON, SDLK_QUOTE,
53 /*35*/ '~', SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_CAPSLOCK,
54 SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12,
55 /*46*/ SDLK_PRINT, SDLK_SCROLLOCK, SDLK_PAUSE, SDLK_INSERT, SDLK_HOME, SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, SDLK_LEFT, SDLK_DOWN, SDLK_UP,
56 /*53*/ SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, SDLK_KP_PLUS, SDLK_KP_ENTER,
57 SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6,
58 /*5f*/ SDLK_KP7, SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 0 /* S3 */
59 };
60
61 const static unsigned short sdl_shift[] = {
62 SDLK_LCTRL,SDLK_LSHIFT,SDLK_LALT,0 /* S1 */,
63 SDLK_RCTRL,SDLK_RSHIFT,SDLK_RALT,0 /* S2 */,
64 };
65
66 #define MOUSE_WHEELUP (1<<4)
67 #define MOUSE_WHEELDOWN (1<<5)
68
69 static void mouse_update(void)
70 {
71 const static char sdl_mousebtn[] = {
72 MOUSE_LEFTBUTTON,
73 MOUSE_RIGHTBUTTON,
74 MOUSE_SIDEBUTTON,
75 MOUSE_WHEELUP,
76 MOUSE_WHEELDOWN
77 };
78
79 uint8 addr;
80 mouse_cond_t cond;
81
82 static int prev_buttons;
83 int buttons,changed;
84 int i;
85
86 if ((addr = maple_first_mouse())==0 || mouse_get_cond(addr, &cond)<0) return;
87
88 buttons = cond.buttons^0xff;
89 if (cond.dz<0) buttons|=MOUSE_WHEELUP;
90 if (cond.dz>0) buttons|=MOUSE_WHEELDOWN;
91
92 if (cond.dx||cond.dy) SDL_PrivateMouseMotion(0,1,cond.dx,cond.dy);
93
94 changed = buttons^prev_buttons;
95 for(i=0;i<sizeof(sdl_mousebtn);i++) {
96 if (changed & sdl_mousebtn[i]) {
97 SDL_PrivateMouseButton((buttons & sdl_mousebtn[i])?SDL_PRESSED:SDL_RELEASED,i,0,0);
98 }
99 }
100 prev_buttons = buttons;
101 }
102
103 static void keyboard_update(void)
104 {
105 static kbd_state_t old_state;
106 static uint8 old_addr;
107
108 kbd_state_t *state;
109 uint8 addr;
110 int port,unit;
111
112 int shiftkeys;
113 SDL_keysym keysym;
114
115 int i;
116
117 addr = maple_first_kb();
118
119 if (addr==0) return;
120
121 if (addr!=old_addr) {
122 old_addr = addr;
123 memset(&old_state,0,sizeof(old_state));
124 }
125
126 maple_raddr(addr,&port,&unit);
127
128 state = kbd_get_state(port,unit);
129 if (!state) return;
130
131 shiftkeys = state->shift_keys ^ old_state.shift_keys;
132 for(i=0;i<sizeof(sdl_shift);i++) {
133 if ((shiftkeys>>i)&1) {
134 keysym.sym = sdl_shift[i];
135 SDL_PrivateKeyboard(((state->shift_keys>>i)&1)?SDL_PRESSED:SDL_RELEASED,&keysym);
136 }
137 }
138
139 for(i=0;i<sizeof(sdl_key);i++) {
140 if (state->matrix[i]!=old_state.matrix[i]) {
141 int key = sdl_key[i];
142 if (key) {
143 keysym.sym = key;
144 SDL_PrivateKeyboard(state->matrix[i]?SDL_PRESSED:SDL_RELEASED,&keysym);
145 }
146 }
147 }
148
149 old_state = *state;
150 }
151
152 void DC_PumpEvents(_THIS)
153 {
154 keyboard_update();
155 mouse_update();
156 }
157
158 void DC_InitOSKeymap(_THIS)
159 {
160 /* do nothing. */
161 }
162
163 /* end of SDL_dcevents.c ... */
164