]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/MAI/bios_emulator/scitech/src/pm/os2pm/event.c
* Patch by Thomas Frieden, 13 Nov 2002:
[karo-tx-uboot.git] / board / MAI / bios_emulator / scitech / src / pm / os2pm / 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:  IBM PC (OS/2)
26 *
27 * Description:  OS/2 implementation for the SciTech cross platform
28 *               event library.
29 *
30 ****************************************************************************/
31
32 /*---------------------------- Global Variables ---------------------------*/
33
34 static int          oldMouseState;      /* Old mouse state              */
35 static ulong        oldKeyMessage;      /* Old keyboard state           */
36 static ushort       keyUpMsg[256] = {0};/* Table of key up messages     */
37 static int          rangeX,rangeY;      /* Range of mouse coordinates   */
38 HMOU                _EVT_hMouse;        /* Handle to the mouse driver   */
39
40 /*---------------------------- Implementation -----------------------------*/
41
42 /* These are not used under OS/2 */
43 #define _EVT_disableInt()       1
44 #define _EVT_restoreInt(flags)
45
46 /****************************************************************************
47 PARAMETERS:
48 scanCode    - Scan code to test
49
50 REMARKS:
51 This macro determines if a specified key is currently down at the
52 time that the call is made.
53 ****************************************************************************/
54 #define _EVT_isKeyDown(scanCode)    (keyUpMsg[scanCode] != 0)
55
56 /****************************************************************************
57 REMARKS:
58 Pumps all messages in the message queue from OS/2 into our event queue.
59 ****************************************************************************/
60 static void _EVT_pumpMessages(void)
61 {
62     // TODO: Implement this for OS/2 Presentation Manager apps!
63 }
64
65 /****************************************************************************
66 REMARKS:
67 This macro/function is used to converts the scan codes reported by the
68 keyboard to our event libraries normalised format. We only have one scan
69 code for the 'A' key, and use shift modifiers to determine if it is a
70 Ctrl-F1, Alt-F1 etc. The raw scan codes from the keyboard work this way,
71 but the OS gives us 'cooked' scan codes, we have to translate them back
72 to the raw format.
73 ****************************************************************************/
74 #define _EVT_maskKeyCode(evt)
75
76 /****************************************************************************
77 REMARKS:
78 Safely abort the event module upon catching a fatal error.
79 ****************************************************************************/
80 void _EVT_abort()
81 {
82     EVT_exit();
83     PM_fatalError("Unhandled exception!");
84 }
85
86 /****************************************************************************
87 PARAMETERS:
88 mouseMove   - Callback function to call wheneve the mouse needs to be moved
89
90 REMARKS:
91 Initiliase the event handling module. Here we install our mouse handling ISR
92 to be called whenever any button's are pressed or released. We also build
93 the free list of events in the event queue.
94
95 We use handler number 2 of the mouse libraries interrupt handlers for our
96 event handling routines.
97 ****************************************************************************/
98 void EVTAPI EVT_init(
99     _EVT_mouseMoveHandler mouseMove)
100 {
101     /* Initialise the event queue */
102     EVT.mouseMove = mouseMove;
103     initEventQueue();
104     oldMouseState = 0;
105     oldKeyMessage = 0;
106     memset(keyUpMsg,0,sizeof(keyUpMsg));
107
108     // TODO: OS/2 PM specific initialisation code!
109
110     /* Catch program termination signals so we can clean up properly */
111     signal(SIGABRT, _EVT_abort);
112     signal(SIGFPE, _EVT_abort);
113     signal(SIGINT, _EVT_abort);
114 }
115
116 /****************************************************************************
117 REMARKS
118 Changes the range of coordinates returned by the mouse functions to the
119 specified range of values. This is used when changing between graphics
120 modes set the range of mouse coordinates for the new display mode.
121 ****************************************************************************/
122 void EVTAPI EVT_setMouseRange(
123     int xRes,
124     int yRes)
125 {
126     rangeX = xRes;
127     rangeY = yRes;
128 }
129
130 /****************************************************************************
131 REMARKS:
132 Initiailises the internal event handling modules. The EVT_suspend function
133 can be called to suspend event handling (such as when shelling out to DOS),
134 and this function can be used to resume it again later.
135 ****************************************************************************/
136 void EVT_resume(void)
137 {
138     // Do nothing for OS/2
139 }
140
141 /****************************************************************************
142 REMARKS
143 Suspends all of our event handling operations. This is also used to
144 de-install the event handling code.
145 ****************************************************************************/
146 void EVT_suspend(void)
147 {
148     // Do nothing for OS/2
149 }
150
151 /****************************************************************************
152 REMARKS
153 Exits the event module for program terminatation.
154 ****************************************************************************/
155 void EVT_exit(void)
156 {
157     /* Restore signal handlers */
158     signal(SIGABRT, SIG_DFL);
159     signal(SIGFPE, SIG_DFL);
160     signal(SIGINT, SIG_DFL);
161
162     // TODO: OS/2 PM specific exit code
163 }
164
165 /****************************************************************************
166 REMARKS
167 Modifes the mouse coordinates as necessary if scaling to OS coordinates,
168 and sets the OS mouse cursor position.
169 ****************************************************************************/
170 #define _EVT_setMousePos(x,y)