home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / POVHELP.ZIP / source / input.c < prev    next >
C/C++ Source or Header  |  1994-08-09  |  6KB  |  191 lines

  1.  
  2.  
  3. /****************************************************************************
  4. *                   INPUT.C - Version 1.0
  5. *
  6. *  This module implements some keyboard input code
  7. *
  8. *  from Persistence of Vision Raytracer
  9. *  Copyright 1994 Persistence of Vision Team
  10. *  Copyright 1994 Christopher J. Cason.
  11. *---------------------------------------------------------------------------
  12. *  NOTICE: This source code file is provided so that users may experiment
  13. *  with enhancements to POV-Ray and to port the software to platforms other
  14. *  than those supported by the POV-Ray Team.  There are strict rules under
  15. *  which you are permitted to use this file.  The rules are in the file
  16. *  named POVLEGAL.DOC which should be distributed with this file. If
  17. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  18. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  19. *  Forum.  The latest version of POV-Ray may be found there as well.
  20. *
  21. *  POV-Ray files may also be obtained from ftp.uwa.edu.au in pub/povray.
  22. *
  23. *  This program was written in its entirety by Christopher J. Cason.
  24. *  Its use is freely and permanently granted to the POV-Team and POV users
  25. *  under the conditions specified in POVLEGAL.DOC.
  26. *
  27. *  Author : C. J. Cason (cjcason@yarrow.wt.uwa.edu.au, CIS 100032,1644)
  28. *
  29. *****************************************************************************/
  30.  
  31. #include <mem.h>
  32. #include <dos.h>
  33. #include <string.h>
  34. #include "help.h"
  35.  
  36. unsigned                in_0x09 = 0 ;
  37. unsigned                in_0x15 = 0 ;
  38. unsigned                in_0x16 = 0 ;
  39. unsigned                running = 0 ;
  40. unsigned                popped_up = 0 ;
  41. unsigned                popdown = 0 ;
  42. unsigned                scancode ;
  43. unsigned                scanflag ;
  44. unsigned                counter ;
  45. unsigned                home ;
  46. void interrupt          (*old0x09) (void) ;
  47. void interrupt          (*old0x1c) (void) ;
  48. void interrupt          (*old0x15) (void) ;
  49. void interrupt          (*old0x16) (void) ;
  50.  
  51. extern char             *paste_ptr ;
  52. extern unsigned         paste ;
  53. extern unsigned         home_wanted ;
  54.  
  55. /* codes for CR (0x32) and LF (0x24) replaced with code for RETURN key */
  56. char scancodes [128] =
  57. {
  58.   0x03, 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, /* 000 through 007 */
  59.   0x23, 0x17, 0x1C, 0x25, 0x26, 0x1C, 0x31, 0x18, /* 008 through 015 */
  60.   0x19, 0x10, 0x13, 0x1F, 0x14, 0x16, 0x2F, 0x11, /* 016 through 023 */
  61.   0x2D, 0x15, 0x2C, 0x01, 0x2B, 0x1B, 0x07, 0x0C, /* 024 through 031 */
  62.   0x39, 0x02, 0x28, 0x04, 0x05, 0x06, 0x08, 0x28, /* 032 through 039 */
  63.   0x0A, 0x0B, 0x09, 0x0D, 0x33, 0x0C, 0x34, 0x35, /* 040 through 047 */
  64.   0x0B, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, /* 048 through 055 */
  65.   0x09, 0x0A, 0x27, 0x28, 0x33, 0x0D, 0x34, 0x35, /* 056 through 063 */
  66.   0x03, 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, /* 064 through 071 */
  67.   0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, /* 072 through 079 */
  68.   0x19, 0x10, 0x13, 0x1F, 0x14, 0x16, 0x2F, 0x11, /* 080 through 087 */
  69.   0x2D, 0x15, 0x2C, 0x1A, 0x2B, 0x1B, 0x07, 0x0C, /* 088 through 095 */
  70.   0x29, 0x1E, 0x30, 0x2E, 0x20, 0x12, 0x21, 0x22, /* 096 through 103 */
  71.   0x23, 0x17, 0x24, 0x25, 0x26, 0x32, 0x31, 0x18, /* 104 through 111 */
  72.   0x19, 0x10, 0x13, 0x1F, 0x14, 0x16, 0x2F, 0x11, /* 112 through 119 */
  73.   0x2D, 0x15, 0x2C, 0x1A, 0x2B, 0x1B, 0x29, 0x00  /* 120 through 127 */
  74. } ;
  75.  
  76. void popup (void) ;
  77. void new0x16 (void) ;
  78. void CS_old0x16 (void) ;
  79.  
  80. /* hardware keyboard interrupt handler */
  81.  
  82. void interrupt new0x09 (void)
  83. {
  84.   char                  kb_ch ;
  85. /*char                  s [9] ;*/
  86.   static char far       *kb_flag = (char far *) MK_FP (0x40, 0x17) ;
  87.   union REGS  regs ;
  88.  
  89.   if (in_0x09++ == 0)
  90.   {
  91.     enable () ;
  92.     if (running == 0 || popdown == 0)
  93.     {
  94.       kb_ch = inportb (0x60) ;
  95. /*    sprintf (s, "%02x", kb_ch) ;
  96.       *(char *) MK_FP (0xb800, 0) = s [0] ;
  97.       *(char *) MK_FP (0xb800, 2) = s [1] ;*/
  98.       if ((*kb_flag & scanflag) == scanflag && kb_ch == scancode)
  99.       {
  100.         paste = home = 0 ;
  101.         if (running != 0 && popdown == 0)
  102.         {
  103.           /* this IS needed due to some el-wierdo bug in the BIOS ??? */
  104.           /* symptom : system will wait until next keystroke pressed */
  105.           /* it won't happen if we use bioskey (0x01) instead of (0x11) */
  106.           /* but if we don't use (0x11) we don't get extended characters */
  107.           /* the problem may be machine-specific */
  108.           regs.h.ah = 0x05 ;
  109.           regs.x.cx = 0 ;
  110.           int86 (0x16, ®s, ®s) ;
  111.         }
  112.         if (!running)
  113.           running++ ;
  114.         else
  115.           popdown++ ;
  116.         disable () ;
  117.         outportb (0x20, 0x20) ;
  118.         in_0x09-- ;
  119.         return ;
  120.       }
  121.     }
  122.   }
  123.   disable () ;
  124.   (*old0x09) () ;
  125.   disable () ;
  126.   in_0x09-- ;
  127. }
  128.  
  129. /* user timer interrupt (software). use to count down for delays */
  130.  
  131. void interrupt new0x1c (void)
  132. {
  133.   union REGS  regs ;
  134.  
  135.   if (counter) counter-- ;
  136.  
  137.   if (running == 0 && paste)
  138.   {
  139.     regs.h.al = 0xff ;
  140.     while (paste != 0 && regs.h.al != 1)
  141.     {
  142.       if (home)
  143.       {
  144.         regs.h.ah = 0x05 ;
  145.         regs.x.cx = 0x4700 ; /* HOME */
  146.         int86 (0x16, ®s, ®s) ;
  147.         if (regs.h.al != 0x01) home-- ;
  148.         continue ;
  149.       }
  150.       if (*paste_ptr < 0x80)
  151.       {
  152.         if (*paste_ptr == '\n') *paste_ptr = '\r' ;
  153.         if (*paste_ptr == '\r' && home_wanted) home = home_wanted ;
  154.         regs.h.ah = 0x05 ;
  155.         regs.x.cx = *paste_ptr ;
  156.         regs.x.cx |= (unsigned) scancodes [*paste_ptr] << 8 ;
  157.         int86 (0x16, ®s, ®s) ;
  158.       }
  159.       if (regs.h.al != 0x01)
  160.       {
  161.         paste_ptr++ ;
  162.         paste-- ;
  163.         if (home)
  164.         {
  165.           regs.h.ah = 0x05 ;
  166.           regs.x.cx = 0x4700 ; /* HOME */
  167.           int86 (0x16, ®s, ®s) ;
  168.           if (regs.h.al != 0x01) home = 0 ;
  169.         }
  170.       }
  171.     }
  172.   }
  173.   (*old0x1c) () ;
  174. }
  175.  
  176. void kbinit (void)
  177. {
  178.   old0x09 = getvect (0x09) ;
  179.   setvect (0x09, new0x09) ;
  180.   *(unsigned long *) CS_old0x16 = (unsigned long) (old0x16 = getvect (0x16)) ;
  181.   setvect (0x16, (void interrupt (*) (void)) new0x16) ;
  182.   old0x1c = getvect (0x1c) ;
  183.   setvect (0x1c, (void interrupt (*) (void)) new0x1c) ;
  184. }
  185.  
  186. void deinit (void)
  187. {
  188.   setvect (0x09, old0x09) ;
  189.   setvect (0x16, old0x16) ;
  190.   setvect (0x1c, old0x1c) ;
  191. }