home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / KBD.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-08-14  |  9.0 KB  |  363 lines

  1.                 page    58,132
  2.  
  3. ; kbd.asm
  4. ; contains: getkey(), gfkbhit(), kbfetch(), kbshift(),breakchk(),enhkbd()
  5. ;
  6. ;
  7. ; The Greenleaf Comm Library
  8. ;
  9. ; Copyright (C) 1984-90 Greenleaf Software Inc.  All Rights Reserved.
  10. ;
  11. ;
  12.                 include        model.h
  13.                 include prologue.h
  14.                 name    kbd
  15.  
  16. ;;      AUTHOR:
  17. ;        ""   21-OCT-1984  09:22:58.57
  18. ;
  19. ;;      MODIFICATIONS:
  20. ;        ""   12-JAN-1989  16:23:45.90
  21. ;         Removed translate table for getkey()
  22. ;;;
  23.  
  24.         dseg    kbd
  25.  
  26. kstfunc db      1               ;keyboard status function #
  27. sstfunc db      2               ;shift status function #
  28. kinfunc db      0               ;input function #
  29. trapptr dw      offset trfunc
  30.  
  31. i23off  dw      0
  32. i23seg  dw      0
  33. dos_handler   db      0ffh      ;keeps track of last breakchk() value
  34.                                 ;SET.  When 0FFH it means vector has
  35.                                 ;not yet been re-directed.  If
  36.                                 ;it == 0 then don't abort, if == 1
  37.                                 ;abort.
  38.  
  39.         endds
  40.  
  41.         pseg    getkey
  42.  
  43. ;==>--  unsigned getkey(void)
  44. ;
  45. ;;      ARGUMENTS:
  46. ;        (none)
  47. ;
  48. ;;      DESCRIPTION:
  49. ;         Get keyboard code without echo.
  50. ;
  51. ;;      SIDE EFFECTS:
  52. ;         none
  53. ;
  54. ;;      RETURNS:
  55. ;         8-bit standard ASCII code (0x00-0x7f) or predefined extended code
  56. ;         per ibmkeys.h
  57. ;
  58. ;;      AUTHOR:
  59. ;
  60. ;;      MODIFICATIONS:
  61. ;        David Nienhiser   12-JAN-1989  16:27:24.22
  62. ;         Removed translate table for getkey()
  63. ;;;
  64.         cproc   getkey
  65.         call    [trapptr]
  66.         mov     ah,kinfunc
  67.         int     16h             ;rom bios keyboard input
  68.         or      ax,ax           ;is it Ctrl-Break ?
  69.         jz      short gtkyex    ;if so return ax=0 for control break
  70.  
  71.         cmp     al,0e0h         ;from second set of keys?
  72.         jnz     noaltk
  73.         xor     al,al
  74. noaltk: or      al,al           ;is it extended ?
  75.         jz      gtkyex          ;return it if so
  76.         xor     ah,ah           ;else return character in AL, clear AH
  77. gtkyex:
  78.         call    doschk
  79.         cproce
  80.  
  81. ;==>--  bool gfkbhit(void)
  82. ;
  83. ;;      ARGUMENTS:
  84. ;        (none)
  85. ;
  86. ;;      DESCRIPTION:
  87. ;        Test keyboard for activity via ROM-BIOS and return result
  88. ;
  89. ;;      SIDE EFFECTS:
  90. ;        (none)
  91. ;
  92. ;;      RETURNS:
  93. ;        TRUE (1) if keyboard code available, else FALSE (0)
  94. ;
  95. ;;      AUTHOR:
  96. ;
  97. ;;      MODIFICATIONS:
  98. ;
  99. ;;;
  100.         cproc   gfkbhit
  101.         call    [trapptr]
  102.         mov     ah,kstfunc
  103.         int     16h             ;rom-bios get keyboard status
  104.         mov     ax,1
  105.         jnz     havcod
  106.         xor     ax,ax           ;say no keyboard activity
  107. havcod: cmp     kstfunc,11h
  108.         jz      skpchk          ;if new style skip next call
  109.         call    doschk
  110. skpchk:
  111.         cproce                  ; or return code in AL/AH
  112.  
  113. ;==>--  unsigned kbfetch(void)
  114. ;
  115. ;;      ARGUMENTS:
  116. ;        (none)
  117. ;
  118. ;;      DESCRIPTION:
  119. ;         One character is fetched from the keyboard FIFO buffer via
  120. ;         ROM-BIOS.  If the buffer is empty, this routine waits until
  121. ;         a key is struck.
  122. ;
  123. ;;      SIDE EFFECTS:
  124. ;         (none)
  125. ;
  126. ;;      RETURNS:
  127. ;         ASCII code (low-byte), Keyboard Scan Code (high byte)
  128. ;
  129. ;;      AUTHOR:
  130. ;
  131. ;;      MODIFICATIONS:
  132. ;
  133. ;;;
  134.         cproc   kbfetch
  135.         call    [trapptr]
  136.         mov     ah,kinfunc
  137.         int     16h             ;rom bios keyboard input
  138.         call    doschk
  139.         cproce
  140.  
  141. ;==>--  unsigned kbshift(void)
  142. ;
  143. ;;      ARGUMENTS:
  144. ;         (none)
  145. ;
  146. ;;      DESCRIPTION:
  147. ;         Get current status of keyboard shift keys via ROM-BIOS.
  148. ;
  149. ;;      SIDE EFFECTS:
  150. ;         (none)
  151. ;
  152. ;;      RETURNS:
  153. ;         status of keyboard shift keys.
  154. ;
  155. ;;      AUTHOR:
  156. ;        David Nienhiser   25-MAR-1987  09:44:45.84
  157. ;
  158. ;;      MODIFICATIONS:
  159. ;
  160. ;;;
  161.         cproc   kbshift
  162.         call    [trapptr]
  163.         mov     ah,sstfunc
  164.         int     16h
  165.         cproce
  166.  
  167. ;==>--  int breakchk(control)
  168. ;
  169. ;;      ARGUMENTS:
  170. ;        (int)  control -       OFF(0),ON(1),or (2)
  171. ;                               ON  = do not install ctrl break handler
  172. ;                               OFF = install ctrl-break handler so user
  173. ;                                     program will not exit with ctrl-break
  174. ;                               2   = Return current state (ON/OFF)
  175. ;
  176. ;;      DESCRIPTION:
  177. ;         Control/Status of control break function.
  178. ;
  179. ;;      SIDE EFFECTS:
  180. ;         If called with OFF as a parameter the control break handler
  181. ;         in this file will be installed.
  182. ;
  183. ;;      RETURNS:
  184. ;         1 if control break is ON, else 0
  185. ;
  186. ;;      AUTHOR:
  187. ;
  188. ;;      MODIFICATIONS:
  189. ;
  190. ;;;
  191.         cproc   breakchk
  192.         mov     ax,@ab[bp]      ;see what user wants 0..2
  193.         cmp     al,0            ;Install handler?
  194.         je      break_install
  195.         cmp     al,1            ;Remove handler?
  196.         je      break_remove
  197.         cmp     al,2            ;Return status?
  198.         je      break_status
  199.         or      ax,-1           ;else return error
  200.         jmp     short bcxit
  201.  
  202. break_status:
  203.         mov     ax,3300h        ;yes,check
  204.         int     21h
  205.         xor     ah,ah           ;return AL
  206.         mov     al,dl
  207.         jmp     short bcxit
  208.  
  209. break_remove:
  210.         cmp     dos_handler,0        ;See if I have the break handler
  211.         jne     bc1_ok               ;Jump if I don't, he can keep it
  212.         call    unseti23             ;Give the handler back
  213.         mov     dl,1                 ;set the command so DOS BREAK=ON
  214.         jmp     short bc1_ok         ;and exit
  215.  
  216. break_install:
  217.         cmp     dos_handler,0         ;see if vector has been re-directed
  218.         je      bc1_ok
  219.         call    seti23                ;if not re-direct to our code!
  220.         mov     dl,0                  ;set the command so DOS BREAK=OFF
  221.  
  222. bc1_ok:
  223.         push    dx
  224.         mov     ax,3301h
  225.         int     21h
  226.         pop     ax              ;saved as dx
  227. bcxit:
  228.         cproce
  229.  
  230. ;==>--  int enhkbd(void)
  231. ;
  232. ;;      ARGUMENTS:
  233. ;        (none)
  234. ;
  235. ;;      DESCRIPTION:
  236. ;        Determines if enhanced keyboard is installed.
  237. ;
  238. ;;      SIDE EFFECTS:
  239. ;        (none)
  240. ;
  241. ;;      RETURNS:
  242. ;        1 = Enhanced keyboard is installed, 0 = Not installed
  243. ;
  244. ;;      AUTHOR:
  245. ;        David Nienhiser   25-MAR-1987  10:03:02.90
  246. ;
  247. ;;      MODIFICATIONS:
  248. ;
  249. ;;;
  250.         cproc   enhkbd
  251.         call    enkbck
  252.         cproce
  253.  
  254. ;==>--  void _disenk(void)
  255. ;
  256. ;;      ARGUMENTS:
  257. ;         (none)
  258. ;
  259. ;;      DESCRIPTION:
  260. ;         Disables check/adjustment for enhanced keyboard
  261. ;
  262. ;;      SIDE EFFECTS:
  263. ;         enhanced keyboard will not be detected, must be called before
  264. ;         any other keyboard functions.
  265. ;
  266. ;;      RETURNS:
  267. ;         (void)
  268. ;
  269. ;;      AUTHOR:
  270. ;        David Nienhiser   25-MAR-1987  10:04:48.48
  271. ;
  272. ;;      MODIFICATIONS:
  273. ;
  274. ;;;
  275.         cproc   _disenk
  276.         mov     trapptr,offset trfret
  277.         cproce
  278.  
  279. ;==>--  doschk  is a procedure used only by functions in this file
  280. ;       it makes a dos call to give dos an oppurtunity to terminate
  281. ;       the current program.
  282. ;
  283. doschk  proc    near
  284.         cmp     byte ptr dos_handler,0
  285.         je      doscex
  286.         push    ax
  287.         mov     ah,0bh          ;check keyboard status via DOS
  288.         int     21h             ;this gives dos an oppurtunity to exit
  289.         pop     ax
  290. doscex: ret
  291. doschk  endp
  292.  
  293. ;==>--  INT 23 (control break) HANDLER
  294. ;
  295. ;  Interrupt 23h is re-directed to here if breakchk(0||1) is called
  296. ;
  297. ;
  298. i23hnd  proc    far
  299.         iret
  300. i23hnd  endp
  301.  
  302. ;==>--  Save current int 23h & Re-direct interrupt 23 to the i23hnd
  303. ;
  304. seti23  proc    near
  305.         push    ax              ;ah has something
  306.         push    ds
  307.         push    es
  308.         mov     ax,3523h        ;get vector to es:bx
  309.         int     21h
  310.         mov     i23off,bx
  311.         mov     i23seg,es
  312.         mov     ax,cs
  313.         mov     ds,ax
  314.         mov     dx,offset i23hnd
  315.         mov     ax,2523h        ;set interrupt #23h
  316.         int     21h
  317.         pop     es
  318.         pop     ds
  319.         pop     ax
  320.         mov     dos_handler,0
  321.         ret
  322. seti23  endp
  323.  
  324. unseti23 proc   near
  325.         push    ds
  326.         mov     dx,i23off
  327.         mov     ax,i23seg
  328.         mov     ds,ax
  329.         mov     ax,2523h
  330.         int     21h
  331.         pop     ds
  332.         mov     dos_handler,0ffH
  333.         ret
  334. unseti23 endp
  335.  
  336. enkbck  proc    near
  337.         push    ds
  338.         mov     ax,40h
  339.         mov     ds,ax
  340.         mov     bx,96h
  341.         mov     bl,[bx]
  342.         pop     ds
  343.         xor     ax,ax           ;assume not installed
  344.         and     bl,10h
  345.         jz      enot
  346.         inc     ax
  347. enot:   ret
  348. enkbck  endp
  349.  
  350. trfunc  proc    near
  351.         mov     trapptr,offset trfret
  352.         call    enkbck
  353.         or      ax,ax                   ;if enhanced kbd not installed skip
  354.         jz      trfret
  355.         mov     ah,10h
  356.         or      kstfunc,ah
  357.         or      sstfunc,ah
  358.         or      kinfunc,ah
  359. trfret: ret
  360. trfunc  endp
  361.         endps
  362.         end
  363.