KEYH.CPP 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include <dos.h>
  2. #include <i86.h>
  3. #include <bios.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include "defines.h"
  7. #include "externs.h"
  8. extern char debug;
  9. extern char on_3d;
  10. extern int counter;
  11. char return_doskey=FALSE;
  12. extern "C" int network_on;
  13. void (__interrupt __far *prev_int_9)();
  14. /****************************************************************
  15. /***************************************************************/
  16. char anykey;
  17. void __interrupt __far key_handler()
  18. {
  19. static l1=0,l2=0,l3=0; //remember last 3 codes to check for pause.
  20. int a;
  21. char ret_int;
  22. a=inp(0x60);
  23. l1=l2;
  24. l2=l3;
  25. l3=a;
  26. if (l1==0xE1 && l2==0x1d && l3==0x45)
  27. {
  28. if (!network_on)
  29. {
  30. paused=!paused;
  31. ret_int=1;
  32. }
  33. }
  34. else
  35. {
  36. ret_int=0;
  37. if (debug) // (Prnt Scr) for debug.
  38. if (key_togs[0x20]) // d
  39. ret_int=1;
  40. if (!on_3d)
  41. ret_int=1;
  42. if (return_doskey)
  43. ret_int=1;
  44. }
  45. // Ignore 0xFA...
  46. if (a!=0xfa)
  47. {
  48. if (a!=0xe0)
  49. {
  50. if (a & 0x80)
  51. {
  52. // key released...
  53. if (l2!=0xe0) // not special header.
  54. {
  55. keys[a & 0x7f]=0; // Normal key release!
  56. }
  57. else
  58. {
  59. // special...
  60. keys[SPECIALK+(a & 0x7f)]=0; // Special key release!
  61. }
  62. }
  63. else
  64. {
  65. // new key...
  66. anykey=TRUE;
  67. if (l2!=0xe0 || a!=0x2a)
  68. {
  69. // no special pre-codes...
  70. if (l2==0xe0)
  71. {
  72. if (!keys[SPECIALK+a])
  73. {
  74. // new special...
  75. keys[SPECIALK+a]=1; // Special key release!
  76. key_togs[SPECIALK+a]=!key_togs[SPECIALK+a];
  77. }
  78. }
  79. else
  80. {
  81. // Normal key depress...
  82. if (!keys[a])
  83. {
  84. // New norm. key...
  85. keys[a]=1;
  86. key_togs[a]=!key_togs[a];
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. if (a!=0xE1) //trash normal pause
  94. {
  95. if ((a & 0x7f)!=0x1d && (a & 0x7f)!=0x45)
  96. paused=0;
  97. }
  98. if (ret_int)
  99. _chain_intr(prev_int_9);
  100. else
  101. {
  102. //suspected pause - don't pass to normal key handler!
  103. outp(0x20,32); //terminate int
  104. }
  105. }
  106. void claim_key_int(void)
  107. {
  108. prev_int_9=_dos_getvect(0x9);
  109. _dos_setvect(0x9,key_handler);
  110. memset((void *)keys,0,128);
  111. }
  112. void release_key_int(void)
  113. {
  114. _dos_setvect(0x9,prev_int_9);
  115. }