home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / src / baseline / jove-4.14.6.lha / jove-4.14.6 / getch.c < prev    next >
C/C++ Source or Header  |  1992-01-10  |  2KB  |  137 lines

  1. /***************************************************************************
  2.  * This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne.  JOVE *
  3.  * is provided to you without charge, and with no warranty.  You may give  *
  4.  * away copies of JOVE, including sources, provided that this notice is    *
  5.  * included in all the files.                                              *
  6.  ***************************************************************************/
  7.  
  8. #include "tune.h"
  9.  
  10. #ifdef    MSDOS
  11.  
  12. #include <bios.h>
  13. #include <dos.h>
  14.  
  15. #include "jove.h"
  16. #include "disp.h"
  17.  
  18. private void waitfun proto((void));
  19.  
  20. #ifdef    IBMPC
  21. private char last = '\0';
  22. extern int specialkey;
  23. #endif
  24.  
  25. int
  26. getrawinchar()
  27. {
  28. #ifdef    IBMPC
  29.     unsigned scan;
  30.  
  31.     if (specialkey = last) {
  32.         scan = last;
  33.         last = '\0';
  34.         return scan;
  35.     }
  36.  
  37.     while (!rawkey_ready())
  38.         waitfun();
  39.  
  40.     scan = _bios_keybrd(_KEYBRD_READ);
  41.     if ((scan&0xff) == 0) {
  42.         last = (char) (scan >> 8);
  43.         return 0xff;
  44.     }
  45.     return scan&0xff;
  46.  
  47. #else    /* !IBMPC */
  48. #ifdef    RAINBOW
  49.  
  50.     union REGS regs;
  51.  
  52.     while (!rawkey_ready())
  53.         waitfun();
  54.  
  55.     for (;;) {
  56.         regs.x.di = 2;
  57.         int86(0x18, ®s, ®s);
  58.         if (regs.h.al != 0)    /* should never happen, but who knows */
  59.             return regs.h.al;
  60.     }
  61. #else    /* !RAINBOW */
  62.  
  63.     while (!rawkey_ready())
  64.         waitfun();
  65.     return bdos(0x06, 0x00ff, 0xff) & 0xff;
  66. #endif    /* !RAINBOW */
  67. #endif    /* !IBMPC */
  68. }
  69.  
  70. private bool waiting = NO;
  71.  
  72. bool
  73. rawkey_ready()
  74. {
  75. #ifdef    IBMPC
  76.     if (waiting)
  77.         return NO;
  78.     if (last)
  79.         return YES;
  80.  
  81.     return _bios_keybrd(_KEYBRD_READY) != 0;
  82. #else    /* !IBMPC */
  83.     union REGS regs;
  84.  
  85.     if (waiting)
  86.         return NO;
  87. #ifdef    RAINBOW
  88.     regs.x.di = 4;
  89.     int86(0x18, ®s, ®s);
  90.     return regs.h.cl != 0;
  91. #else    /* !RAINBOW */
  92.     regs.h.ah = 0x44;        /* ioctl call */
  93.     regs.x.bx = 0;            /* stdin file handle */
  94.     regs.h.al = 0x06;        /* get input status */
  95.     intdos(®s, ®s);
  96.     return regs.h.al & 1;
  97. #endif    /* !RAINBOW */
  98. #endif    /* !IBMPC */
  99. }
  100.  
  101. #ifdef    IBMPC
  102. private long timecount, lastcount = 0;
  103. #else
  104. private char lastmin = 0;
  105. #endif
  106.  
  107.  
  108. private void
  109. waitfun()
  110. {
  111.     if (UpdModLine) {
  112.         waiting = YES;
  113.         redisplay();
  114.         waiting = NO;
  115.         return;
  116.     }
  117. #ifdef    IBMPC
  118.     if (_bios_timeofday(_TIME_GETCLOCK, &timecount) ||  /* after midnight */
  119.         (timecount > lastcount + 0x444) ) {
  120.         lastcount = timecount;
  121.         UpdModLine = YES;
  122.     }
  123. #else
  124.     {
  125.         struct dostime_t tc;
  126.  
  127.         _dos_gettime(&tc);
  128.         if (tc.minute != lastmin) {
  129.             UpdModLine = YES;
  130.             lastmin = tc.minute;
  131.         }
  132.     }
  133. #endif
  134. }
  135.  
  136. #endif    /* MSDOS */
  137.