Coding style cleanup
[platform/kernel/u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / photon / event.c
1 /****************************************************************************
2 *
3 *                   SciTech Multi-platform Graphics Library
4 *
5 *  ========================================================================
6 *
7 *    The contents of this file are subject to the SciTech MGL Public
8 *    License Version 1.0 (the "License"); you may not use this file
9 *    except in compliance with the License. You may obtain a copy of
10 *    the License at http://www.scitechsoft.com/mgl-license.txt
11 *
12 *    Software distributed under the License is distributed on an
13 *    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 *    implied. See the License for the specific language governing
15 *    rights and limitations under the License.
16 *
17 *    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
18 *
19 *    The Initial Developer of the Original Code is SciTech Software, Inc.
20 *    All Rights Reserved.
21 *
22 *  ========================================================================
23 *
24 * Language:     ANSI C
25 * Environment:  QNX Photon GUI
26 *
27 * Description:  QNX fullscreen console implementation for the SciTech
28 *               cross platform event library.
29 *
30 ****************************************************************************/
31
32 /*--------------------------- Global variables ----------------------------*/
33
34 static ushort       keyUpMsg[256] = {0};/* Table of key up messages     */
35
36 /*---------------------------- Implementation -----------------------------*/
37
38 /* These are not used under Linux */
39 #define _EVT_disableInt()       1
40 #define _EVT_restoreInt(flags)
41
42 /****************************************************************************
43 PARAMETERS:
44 scanCode    - Scan code to test
45
46 REMARKS:
47 This macro determines if a specified key is currently down at the
48 time that the call is made.
49 ****************************************************************************/
50 static ibool _EVT_isKeyDown(
51     uchar scancode)
52 {
53     return (KeyState[(scancode & 0xf8) >> 3] & (1 << (scancode & 0x7)) ?
54         true : false);
55 }
56
57 /****************************************************************************
58 REMARKS:
59 Retrieves all events from the mouse/keyboard event queue and stuffs them
60 into the MGL event queue for further processing.
61 ****************************************************************************/
62 static void _EVT_pumpMessages(void)
63 {
64     int         pid;
65     uint            msg, but_stat, message;
66     uchar           evt[sizeof (PhEvent_t) + 1024];
67     PhEvent_t       *event = (void *)evt;
68     PhKeyEvent_t        *key;
69     PhPointerEvent_t    *mouse;
70     static int      extended;
71     event_t         _evt;
72
73     while (count < EVENTQSIZE) {
74         uint    mods = 0, keyp = 0;
75
76         pid = Creceive(0, &msg, sizeof (msg));
77
78         if (pid == -1)
79             return;
80
81         if (PhEventRead(pid, event, sizeof (evt)) == Ph_EVENT_MSG) {
82             memset(&evt, 0, sizeof (evt));
83             if (event->type == Ph_EV_KEY) {
84                 key = PhGetData(event);
85
86                 if (key->key_flags & KEY_SCAN_VALID) {
87                     keyp = key->key_scan;
88                     if (key->key_flags & KEY_DOWN)
89                         KeyState[(keyp & 0xf800) >> 11]
90                             |= 1 << ((keyp & 0x700) >> 8);
91                     else
92                         KeyState[(keyp & 0xf800) >> 11]
93                             &= ~(1 << ((keyp & 0x700) >> 8));
94                 }
95                 if ((key->key_flags & KEY_SYM_VALID) || extended)
96                     keyp |= key->key_sym;
97
98                 /* No way to tell left from right... */
99                 if (key->key_mods & KEYMOD_SHIFT)
100                     mods = (EVT_LEFTSHIFT | EVT_RIGHTSHIFT);
101                 if (key->key_mods & KEYMOD_CTRL)
102                     mods |= (EVT_CTRLSTATE | EVT_LEFTCTRL);
103                 if (key->key_mods & KEYMOD_ALT)
104                     mods |= (EVT_ALTSTATE | EVT_LEFTALT);
105
106                 _evt.when = evt->timestamp;
107                 if (key->key_flags & KEY_REPEAT) {
108                     _evt.what = EVT_KEYREPEAT;
109                     _evt.message = 0x10000;
110                     }
111                 else if (key->key_flags & KEY_DOWN)
112                     _evt.what = EVT_KEYDOWN;
113                 else
114                     _evt.what = EVT_KEYUP;
115                 _evt.modifiers = mods;
116                 _evt.message |= keyp;
117
118                 addEvent(&_evt);
119
120                 switch(key->key_scan & 0xff00) {
121                     case 0xe000:
122                         extended = 1;
123                         break;
124                     case 0xe001:
125                         extended = 2;
126                         break;
127                     default:
128                         if (extended)
129                             extended--;
130                     }
131                 }
132             else if (event->type & Ph_EV_PTR_ALL) {
133                 but_stat = message = 0;
134                 mouse = PhGetData(event);
135
136                 if (mouse->button_state & Ph_BUTTON_3)
137                     but_stat = EVT_LEFTBUT;
138                 if (mouse->buttons & Ph_BUTTON_3)
139                     message = EVT_LEFTBMASK;
140
141                 if (mouse->button_state & Ph_BUTTON_1)
142                     but_stat |= EVT_RIGHTBUT;
143                 if (mouse->buttons & Ph_BUTTON_1)
144                     message |= EVT_RIGHTBMASK;
145
146                 _evt.when = evt->timestamp;
147                 if (event->type & Ph_EV_PTR_MOTION) {
148                     _evt.what = EVT_MOUSEMOVE;
149                     _evt.where_x = mouse->pos.x;
150                     _evt.where_y = mouse->pos.y;
151                     _evt.modifiers = but_stat;
152                     addEvent(&_evt);
153                     }
154                 if (event->type & Ph_EV_BUT_PRESS)
155                     _evt.what = EVT_MOUSEDOWN;
156                 else
157                     _evt.what = EVT_MOUSEUP;
158                 _evt.where_x = mouse->pos.x;
159                 _evt.where_y = mouse->pos.y;
160                 _evt.modifiers = but_stat;
161                 _evt.message = message;
162                 addEvent(&_evt);
163                 }
164             }
165         else
166             return;
167         }
168 }
169
170 /****************************************************************************
171 REMARKS:
172 This macro/function is used to converts the scan codes reported by the
173 keyboard to our event libraries normalised format. We only have one scan
174 code for the 'A' key, and use shift modifiers to determine if it is a
175 Ctrl-F1, Alt-F1 etc. The raw scan codes from the keyboard work this way,
176 but the OS gives us 'cooked' scan codes, we have to translate them back
177 to the raw format.
178 ****************************************************************************/
179 #define _EVT_maskKeyCode(evt)
180
181 /****************************************************************************
182 REMARKS:
183 Safely abort the event module upon catching a fatal error.
184 ****************************************************************************/
185 void _EVT_abort(
186     int signo)
187 {
188     char    buf[80];
189
190     EVT_exit();
191     sprintf(buf,"Terminating on signal %d",signo);
192     PM_fatalError(buf);
193 }
194
195 /****************************************************************************
196 PARAMETERS:
197 mouseMove   - Callback function to call wheneve the mouse needs to be moved
198
199 REMARKS:
200 Initiliase the event handling module. Here we install our mouse handling ISR
201 to be called whenever any button's are pressed or released. We also build
202 the free list of events in the event queue.
203
204 We use handler number 2 of the mouse libraries interrupt handlers for our
205 event handling routines.
206 ****************************************************************************/
207 void EVTAPI EVT_init(
208     _EVT_mouseMoveHandler mouseMove)
209 {
210     int         i;
211
212     /* Initialise the event queue */
213     _mouseMove = mouseMove;
214     initEventQueue();
215     memset((void *)KeyState, 0, sizeof (KeyState));
216
217     /* Catch program termination signals so we can clean up properly */
218     signal(SIGABRT, _EVT_abort);
219     signal(SIGFPE, _EVT_abort);
220     signal(SIGINT, _EVT_abort);
221 }
222
223 /****************************************************************************
224 REMARKS
225 Changes the range of coordinates returned by the mouse functions to the
226 specified range of values. This is used when changing between graphics
227 modes set the range of mouse coordinates for the new display mode.
228 ****************************************************************************/
229 void EVTAPI EVT_setMouseRange(
230     int xRes,
231     int yRes)
232 {
233     /* TODO: Need to call Input to change the coordinates that it returns */
234     /*       for mouse events!! */
235 }
236
237 /****************************************************************************
238 REMARKS:
239 Initiailises the internal event handling modules. The EVT_suspend function
240 can be called to suspend event handling (such as when shelling out to DOS),
241 and this function can be used to resume it again later.
242 ****************************************************************************/
243 void EVT_resume(void)
244 {
245     /* Do nothing for Photon */
246 }
247
248 /****************************************************************************
249 REMARKS
250 Suspends all of our event handling operations. This is also used to
251 de-install the event handling code.
252 ****************************************************************************/
253 void EVT_suspend(void)
254 {
255     /* Do nothing for Photon */
256 }
257
258 /****************************************************************************
259 REMARKS
260 Exits the event module for program terminatation.
261 ****************************************************************************/
262 void EVT_exit(void)
263 {
264     /* Restore signal handlers */
265     signal(SIGABRT, SIG_DFL);
266     signal(SIGFPE, SIG_DFL);
267     signal(SIGINT, SIG_DFL);
268 }