home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / KBD.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  7.1 KB  |  381 lines

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