home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / d / ddx-mips.zip / MIPSIO.C < prev    next >
C/C++ Source or Header  |  1992-07-31  |  3KB  |  127 lines

  1. /*
  2.  * $XConsortium$
  3.  *
  4.  * Copyright 1991 MIPS Computer Systems, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of MIPS not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  MIPS makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * MIPS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL MIPS
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  */
  23. #ident    "$Header: mipsIo.c,v 1.6 91/07/11 12:10:23 dd Exp $"
  24.  
  25. /*
  26.  * mipsIo.c - input device routines.
  27.  */
  28. #ifdef SYSV
  29. #include <sys/param.h>
  30. #else /* SYSV */
  31. #define HZ    100        /* 100 ticks/second of the clock */
  32. #endif /* SYSV */
  33. #include "X.h"
  34. #define  NEED_EVENTS
  35. #include "Xproto.h"
  36. #include "scrnintstr.h"
  37. #include "inputstr.h"
  38. #include "mips.h"
  39. #include "mipsIo.h"
  40. #include "mipsMouse.h"
  41.  
  42. int        lastEventTime;
  43. static int    ts_calibrate = 1;
  44.  
  45. extern void handleKeybd();
  46. extern void handleMouse();
  47.  
  48. /* SIGIO handler */
  49. #ifdef X11R4
  50. volatile int mipsIOReady;
  51.  
  52. sigIOfunc()
  53. {
  54.     mipsIOReady = 1;
  55.     isItTimeToYield++;
  56. }
  57. #else /* X11R4 */
  58. sigIOfunc()
  59. {
  60.     extern DevicePtr pKeyboard, pPointer;
  61.  
  62.     handleKeybd(pKeyboard);
  63.     handleMouse(pPointer);
  64. }
  65. #endif /* X11R4 */
  66.  
  67. void
  68. ProcessInputEvents()
  69. {
  70. #ifdef X11R4
  71.     DevicePtr    pMouse;
  72.     DevicePtr    pKeybd;
  73.  
  74.     pMouse = LookupPointerDevice();
  75.     pKeybd = LookupKeyboardDevice();
  76.     mipsIOReady = 0;
  77.     handleKeybd(pKeybd);
  78.     handleMouse(pMouse);
  79.  
  80.     if (screenIsSaved == SCREEN_SAVER_ON)
  81.     SaveScreens(SCREEN_SAVER_OFF, ScreenSaverReset);
  82. #else /* X11R4 */
  83.     mieqProcessInputEvents();
  84.     miPointerUpdate();
  85. #endif /* X11R4 */
  86. }
  87.  
  88. TimeSinceLastInputEvent()
  89. {
  90.     int    elapsed;
  91.  
  92.     if (lastEventTime == 0) {
  93.     lastEventTime = GetTimeInMillis();
  94.     elapsed = 0;
  95.     ts_calibrate = 1;    /* No events yet, then calibrate */
  96.     }
  97.     else if ((elapsed = GetTimeInMillis() - lastEventTime) < 0) {
  98.     lastEventTime += elapsed;
  99.     elapsed = 0;
  100.     ts_calibrate = 1;    /* Event timestamp is in the future, then calibrate */
  101.     }
  102.     else if (elapsed > 60000) {
  103.     ts_calibrate = 1;    /* Event timestamp is far in the past, then calibrate */
  104.     }
  105.  
  106.     return(elapsed);
  107. }
  108.  
  109. int
  110. offsetTime(time)
  111. int    time;
  112. {
  113.     static int    offset;
  114.     int        mtime;
  115.     int        rtime;
  116.  
  117.     mtime = time * (1000 / HZ);
  118.  
  119.     if (ts_calibrate) {
  120.     ts_calibrate = 0;
  121.     rtime = GetTimeInMillis();
  122.     offset = rtime - mtime;
  123.     }
  124.  
  125.     return(mtime + offset);
  126. }
  127.