1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
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
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.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
25 * Environment: *** TODO: ADD YOUR OS ENVIRONMENT NAME HERE ***
27 * Description: **** implementation for the SciTech cross platform
30 ****************************************************************************/
32 /*---------------------------- Global Variables ---------------------------*/
34 static ushort keyUpMsg[256] = {0};/* Table of key up messages */
35 static int rangeX,rangeY; /* Range of mouse coordinates */
37 /*---------------------------- Implementation -----------------------------*/
39 /* These are not used under non-DOS systems */
40 #define _EVT_disableInt() 1
41 #define _EVT_restoreInt(flags)
43 /****************************************************************************
45 scanCode - Scan code to test
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)
53 /****************************************************************************
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
59 ****************************************************************************/
60 ulong _EVT_getTicks(void)
62 /* TODO: Implement this for your OS! */
65 /****************************************************************************
67 Pumps all messages in the application message queue into our event queue.
68 ****************************************************************************/
69 static void _EVT_pumpMessages(void)
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. */
75 /* NOTE: There are a couple of important things that this function must */
78 /* 1. Support for KEYDOWN, KEYREPEAT and KEYUP is required. */
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. */
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'. */
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 */
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. */
103 /****************************************************************************
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
111 ****************************************************************************/
112 #define _EVT_maskKeyCode(evt)
114 /****************************************************************************
116 Safely abort the event module upon catching a fatal error.
117 ****************************************************************************/
121 PM_fatalError("Unhandled exception!");
124 /****************************************************************************
126 mouseMove - Callback function to call wheneve the mouse needs to be moved
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.
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)
139 /* Initialise the event queue */
140 _mouseMove = mouseMove;
142 memset(keyUpMsg,0,sizeof(keyUpMsg));
144 /* TODO: Do any OS specific initialisation here */
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);
152 /****************************************************************************
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(
166 /****************************************************************************
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)
174 /* Do nothing for non DOS systems */
177 /****************************************************************************
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)
184 /* Do nothing for non DOS systems */
187 /****************************************************************************
189 Exits the event module for program terminatation.
190 ****************************************************************************/
193 /* Restore signal handlers */
194 signal(SIGABRT, SIG_DFL);
195 signal(SIGFPE, SIG_DFL);
196 signal(SIGINT, SIG_DFL);
198 /* TODO: Do any OS specific cleanup in here */