Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / bios_emulator / scitech / src / pm / stub / event.c
1 /****************************************************************************
2 *
3 *                   SciTech OS Portability Manager 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:  *** TODO: ADD YOUR OS ENVIRONMENT NAME HERE ***
26 *
27 * Description:  **** implementation for the SciTech cross platform
28 *               event library.
29 *
30 ****************************************************************************/
31
32 /*---------------------------- Global Variables ---------------------------*/
33
34 static ushort       keyUpMsg[256] = {0};/* Table of key up messages     */
35 static int          rangeX,rangeY;      /* Range of mouse coordinates   */
36
37 /*---------------------------- Implementation -----------------------------*/
38
39 /* These are not used under non-DOS systems */
40 #define _EVT_disableInt()       1
41 #define _EVT_restoreInt(flags)
42
43 /****************************************************************************
44 PARAMETERS:
45 scanCode    - Scan code to test
46
47 REMARKS:
48 This macro determines if a specified key is currently down at the
49 time that the call is made.
50 ****************************************************************************/
51 #define _EVT_isKeyDown(scanCode)    (keyUpMsg[scanCode] != 0)
52
53 /****************************************************************************
54 REMARKS:
55 This function is used to return the number of ticks since system
56 startup in milliseconds. This should be the same value that is placed into
57 the time stamp fields of events, and is used to implement auto mouse down
58 events.
59 ****************************************************************************/
60 ulong _EVT_getTicks(void)
61 {
62     /* TODO: Implement this for your OS! */
63 }
64
65 /****************************************************************************
66 REMARKS:
67 Pumps all messages in the application message queue into our event queue.
68 ****************************************************************************/
69 static void _EVT_pumpMessages(void)
70 {
71     /* TODO: The purpose of this function is to read all keyboard and mouse */
72     /*       events from the OS specific event queue, translate them and post */
73     /*       them into the SciTech event queue. */
74     /* */
75     /* NOTE: There are a couple of important things that this function must */
76     /*       take care of: */
77     /* */
78     /*  1. Support for KEYDOWN, KEYREPEAT and KEYUP is required. */
79     /* */
80     /*  2. Support for reading hardware scan code as well as ASCII */
81     /*     translated values is required. Games use the scan codes rather */
82     /*     than ASCII values. Scan codes go into the high order byte of the */
83     /*     keyboard message field. */
84     /* */
85     /*  3. Support for at least reading mouse motion data (mickeys) from the */
86     /*     mouse is required. Using the mickey values, we can then translate */
87     /*     to mouse cursor coordinates scaled to the range of the current */
88     /*     graphics display mode. Mouse values are scaled based on the */
89     /*     global 'rangeX' and 'rangeY'. */
90     /* */
91     /*  4. Support for a timestamp for the events is required, which is */
92     /*     defined as the number of milliseconds since some event (usually */
93     /*     system startup). This is the timestamp when the event occurred */
94     /*     (ie: at interrupt time) not when it was stuff into the SciTech */
95     /*     event queue. */
96     /* */
97     /*  5. Support for mouse double click events. If the OS has a native */
98     /*     mechanism to determine this, it should be used. Otherwise the */
99     /*     time stamp information will be used by the generic event code */
100     /*     to generate double click events. */
101 }
102
103 /****************************************************************************
104 REMARKS:
105 This macro/function is used to converts the scan codes reported by the
106 keyboard to our event libraries normalised format. We only have one scan
107 code for the 'A' key, and use shift modifiers to determine if it is a
108 Ctrl-F1, Alt-F1 etc. The raw scan codes from the keyboard work this way,
109 but the OS gives us 'cooked' scan codes, we have to translate them back
110 to the raw format.
111 ****************************************************************************/
112 #define _EVT_maskKeyCode(evt)
113
114 /****************************************************************************
115 REMARKS:
116 Safely abort the event module upon catching a fatal error.
117 ****************************************************************************/
118 void _EVT_abort()
119 {
120     EVT_exit();
121     PM_fatalError("Unhandled exception!");
122 }
123
124 /****************************************************************************
125 PARAMETERS:
126 mouseMove   - Callback function to call wheneve the mouse needs to be moved
127
128 REMARKS:
129 Initiliase the event handling module. Here we install our mouse handling ISR
130 to be called whenever any button's are pressed or released. We also build
131 the free list of events in the event queue.
132
133 We use handler number 2 of the mouse libraries interrupt handlers for our
134 event handling routines.
135 ****************************************************************************/
136 void EVTAPI EVT_init(
137     _EVT_mouseMoveHandler mouseMove)
138 {
139     /* Initialise the event queue */
140     _mouseMove = mouseMove;
141     initEventQueue();
142     memset(keyUpMsg,0,sizeof(keyUpMsg));
143
144     /* TODO: Do any OS specific initialisation here */
145
146     /* Catch program termination signals so we can clean up properly */
147     signal(SIGABRT, _EVT_abort);
148     signal(SIGFPE, _EVT_abort);
149     signal(SIGINT, _EVT_abort);
150 }
151
152 /****************************************************************************
153 REMARKS
154 Changes the range of coordinates returned by the mouse functions to the
155 specified range of values. This is used when changing between graphics
156 modes set the range of mouse coordinates for the new display mode.
157 ****************************************************************************/
158 void EVTAPI EVT_setMouseRange(
159     int xRes,
160     int yRes)
161 {
162     rangeX = xRes;
163     rangeY = yRes;
164 }
165
166 /****************************************************************************
167 REMARKS:
168 Initiailises the internal event handling modules. The EVT_suspend function
169 can be called to suspend event handling (such as when shelling out to DOS),
170 and this function can be used to resume it again later.
171 ****************************************************************************/
172 void EVT_resume(void)
173 {
174     /* Do nothing for non DOS systems */
175 }
176
177 /****************************************************************************
178 REMARKS
179 Suspends all of our event handling operations. This is also used to
180 de-install the event handling code.
181 ****************************************************************************/
182 void EVT_suspend(void)
183 {
184     /* Do nothing for non DOS systems */
185 }
186
187 /****************************************************************************
188 REMARKS
189 Exits the event module for program terminatation.
190 ****************************************************************************/
191 void EVT_exit(void)
192 {
193     /* Restore signal handlers */
194     signal(SIGABRT, SIG_DFL);
195     signal(SIGFPE, SIG_DFL);
196     signal(SIGINT, SIG_DFL);
197
198     /* TODO: Do any OS specific cleanup in here */
199 }