event.c 7.8 KB

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