home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_08 / 2n08042a < prev    next >
Text File  |  1991-07-01  |  7KB  |  249 lines

  1.  
  2. COMMENT ~
  3. -----------------------------------------------------------
  4.                          LISTING 1
  5.  
  6.    EXTND16.ASM
  7. This is a Terminate & Stay Resident program which when
  8. installed will intercept INT 16h calls and insure that
  9. function calls zero and one are changed to functions 10h
  10. and 11h.
  11.  
  12. The TSR consumes about 380 bytes when installed.
  13.  
  14. To create an executable, assemble & link this module and
  15. convert the .EXE to a .COM with exe2bin.
  16.  
  17. Author:  David Burki
  18. -----------------------------------------------------------
  19. END OF COMMENT ~
  20.  
  21.  
  22.  
  23. ;             ----------  EQUATES  ----------
  24. ENV_OFFSET      equ     02ch
  25. GET_KEY         equ      0
  26. CHK_FOR_KEY     equ      1
  27. X_STUFF_KEY     equ     5
  28. X_GET_KEY       equ     10h
  29. X_CHK_FOR_KEY   equ     11h
  30.  
  31.  
  32.  
  33. ;               ----------  CODE  ----------
  34. cseg segment byte public 'code'
  35.  
  36. ; --- com file setup
  37.         org     100h
  38.  
  39. assume cs:cseg, ds:nothing, es:nothing
  40.  
  41. entry:
  42.         jmp     initialize
  43.  
  44. ; --- storage for the int 16h vector that's intercepted
  45. orig_16_vect    dd      ?
  46.  
  47.  
  48.  
  49.  
  50. ;--------------------------------------------------------
  51. ; PRE_16()
  52. ;   This function gets to look at the INT 16h function call
  53. ;   and change function calls 0 & 1 to 10h & 11h so that
  54. ;   DOS can't destroy keycodes when it checks the status of
  55. ;   the BIOS kbd buffer.
  56. ;
  57. ; Caution:  Some programs (CED for example) will not
  58. ; correctly interpert the keycodes returned from the
  59. ; extended keypad keys.  Strange characters appear when
  60. ; these keys are pressed.
  61. ;--------------------------------------------------------
  62. pre_16 proc far
  63. ; --- save the flags we received & interrupts off
  64.         pushf
  65.         sti
  66.  
  67. ; --- if function is greater than 1 (status req) don't do
  68. ;     anything - just jump to the original vector
  69.         cmp     ah,1
  70.         ja      go_orig_16
  71.  
  72. ; --- otherwise, make function 0 into 10h & 1 into 11h
  73.         or      ah,10h
  74.  
  75. ; --- restore callers flags & pass on to original vector
  76. go_orig_16:
  77.         popf
  78.         jmp     orig_16_vect
  79. pre_16 endp
  80.  
  81. ; --- anything after this label is init code & will be
  82. ;     thrown away after installing
  83. end_resident label byte
  84.  
  85.  
  86. assume cs:cseg, ds:cseg, es:cseg
  87.  
  88. ;--------------------------------------------------------
  89. ; FREE_ENVIRONMENT()
  90. ;   Release this program's copy of the DOS environment in
  91. ;   order to make this TSR as small as possible.
  92. ;
  93. ; Freeing the environment makes it impossible for utilities
  94. ; like MAPMEM to determine what program owns the memory
  95. ; allocated to this resident process.
  96. ;
  97. ; Destroys:
  98. ;       AX
  99. ;--------------------------------------------------------
  100. free_environment proc near
  101.         push    es
  102.         push    si
  103.         xor     ax,ax
  104.  
  105. ; --- get environment segment from the PSP
  106.         mov     si,ENV_OFFSET
  107.  
  108. ; --- move segment addr of environment into AX & at same
  109. ;     time move the zero that's in AX into the PSP pointer
  110. ;     to the environment
  111.         xchg    ax,[si]
  112.         or      ax,ax
  113.         jz      environment_exit
  114.         mov     es,ax
  115.         mov     ah,49h
  116.         int     21h
  117. environment_exit:
  118.         pop     si
  119.         pop     es
  120.         ret
  121. free_environment endp
  122.  
  123.  
  124. ;--------------------------------------------------------
  125. ; CK_BIOS_SUPPORT
  126. ;   Check the BIOS to see if enhanced functions are
  127. ;   available by attempting to use one of the enhanced
  128. ;   functions - function 5, add keycode to BIOS keyboard
  129. ;   buffer.
  130. ; Returns:
  131. ;   Carry clear - BIOS supports enhanced functions
  132. ;   Carry set   - BIOS does not support enhanced
  133. ;                 functions
  134. ;--------------------------------------------------------
  135. ck_bios_support proc near
  136. ; --- flush the BIOS kbd buffer
  137.         mov     ah,CHK_FOR_KEY
  138.         int     16h
  139.         jz      buf_is_empty
  140.         mov     ah,GET_KEY
  141.         int     16h
  142.         jmp     ck_bios_support
  143.  
  144. ; --- once the buffer is empty, attempt to add a keycode
  145. ;     to the buffer
  146. buf_is_empty:
  147.         mov     ah,X_STUFF_KEY
  148.         mov     cx,0ffffh
  149.         int     16h
  150.  
  151. ; --- if AL comes back non-zero add keycode failed
  152.         or      al,al
  153.         jnz     no_support
  154.  
  155. ; --- just to make sure, see if the keycode at the head
  156. ;     of the BIOS kbd buffer is the one we added
  157.         mov     ah,X_CHK_FOR_KEY
  158.         int     16h
  159.  
  160. ; --- is the buffer empty?
  161.         jz      no_support
  162.  
  163. ; --- no, remove the keycode we stuffed with an extended
  164. ;     get-key function call
  165.         mov     ah,X_GET_KEY
  166.         int     16h
  167.  
  168. ; --- is it the same keycode
  169.         cmp     ax,0ffffh
  170.         je      yes_support
  171.  
  172. ; --- exit indicating no support
  173. no_support:
  174.         stc
  175.         jmp     ck_bios_exit
  176.  
  177. ; --- exit indicating support
  178. yes_support:
  179.         clc
  180.  
  181. ck_bios_exit:
  182.         ret
  183. ck_bios_support endp
  184.  
  185.  
  186. no_install_msg  db      'BIOS does not support extended '
  187.                 db      'keyboard functions.',0dh,0ah,'$'
  188.  
  189. install_msg     db      'Installing extended BIOS keyboard'
  190.                 db      ' function support.',0dh,0ah,'$'
  191.  
  192. ;--------------------------------------------------------
  193. ; INITIALIZE()
  194. ;   Check that enhanced BIOS keyboard support is
  195. ;   available and install only if it is.
  196. ;--------------------------------------------------------
  197. initialize proc near
  198.         call    free_environment
  199.         call    ck_bios_support
  200.  
  201. ; --- if extended BIOS kbd support not available don't
  202. ;     install
  203.         jc      no_install
  204.  
  205. ; --- display the install message
  206.         mov     dx,offset install_msg
  207.         mov     ah,9
  208.         int     21h
  209.  
  210. ; --- get the current INT 16h vector & sace it in a code
  211. ;     segment variable
  212.         mov     ax,3516h
  213.         int     21h
  214.         mov     word ptr orig_16_vect,bx
  215.         mov     word ptr orig_16_vect+2,es
  216.  
  217. ; --- put pre_16() in the vector table
  218.         mov     dx,offset pre_16
  219.         mov     ax,2516h
  220.         int     21h
  221.  
  222. ; --- calculate the length of the resident portion in
  223. ;     bytes and round up to next paragraph
  224.         mov     dx,offset end_resident
  225.         add     dx,15
  226.  
  227. ; --- convert bytes to paragraphs
  228.         mov     cl,4
  229.         shr     dx,cl
  230.  
  231. ; --- terminate & stay resident, DX has the size of
  232. ;     resident portion in paragraphs
  233.         mov     ah,31h
  234.         int     21h
  235.  
  236. ; --- display the non-installation message & terminate
  237. ;     the process without staying resident
  238. no_install:
  239.         mov     dx,offset no_install_msg
  240.         mov     ah,9
  241.         int     21h
  242.         mov     ax,4c01h
  243.         int     21h
  244. initialize endp
  245.  
  246. cseg ends
  247.  
  248. end entry
  249.