home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / GDOSMEM / GTSR.AS_ / GTSR.AS
Encoding:
Text File  |  1993-02-08  |  5.8 KB  |  212 lines

  1.         name    gtsr
  2.  
  3. ;**************************************************************************
  4. ;
  5. ;       GTSR
  6. ;
  7. ;       This program is the companion TSR for the Windows program
  8. ;       "Gdosmem". The purpose of this TSR is to hook INT 60h and
  9. ;       wait for requests from the Windows program.
  10. ;
  11. ;       The Gdosmem program allocates memory using GlobalDosAlloc,
  12. ;       and then displays the contents using the returned selector
  13. ;       value. Then, it issues INT60's to this TSR program, passing
  14. ;       in the returned segment value of the allocated memory. This
  15. ;       TSR increments the word at that location, and the results
  16. ;       are subsequently displayed in the Windows APP.
  17. ;
  18. ;       This demonstrates a simple technique for communication between
  19. ;       a Windows app and a DOS TSR.
  20. ;
  21. ;       NOTE: The memory allocated using GlobalDosAlloc is local to
  22. ;       the Windows VM. Thus, other virtual machines will not have
  23. ;       access to this memory location. 
  24. ;
  25. ;--------------------------------------------------------------------------
  26. ;
  27. ;       GTSR Installation Check
  28. ;
  29. ;       entry:
  30. ;           AX = GTSR Identification #
  31. ;           BX = 0
  32. ;       exit
  33. ;           BX = GTSR Identification #
  34. ;
  35. ;--------------------------------------------------------------------------
  36. ;
  37. ;       GTSR Increment WORD in CX:DX
  38. ;
  39. ;       entry:
  40. ;           AX = GTSR Identification #
  41. ;           BX = 1
  42. ;           CX = Segment => WORD
  43. ;           DX = Offset  => WORD
  44. ;
  45. ;**************************************************************************
  46.  
  47. Vect_Num equ    60h
  48. Signature equ   899ah
  49.  
  50. cr      equ     0dh
  51. lf      equ     0ah
  52.  
  53.  
  54. _TEXT   segment word public 'CODE'
  55.         assume cs:_TEXT,ds:_DATA
  56.  
  57. ;*-----------------------  TSR Data Area ---------------------*
  58. count   dw      0
  59. oldint  dd      0
  60. ;*-----------------------  TSR Code --------------------------*
  61. handle  proc
  62.  
  63.         push    si
  64.         push    di
  65.         push    es
  66.         push    ds
  67.         push    ax
  68.         push    bx
  69.         push    cx
  70.         push    dx
  71.  
  72.         cmp     ax, Signature           ; look for our signature
  73.         jnz     short chain             ; no, just chain
  74.         cmp     bx, 0                   ; installation check?
  75.         jnz     short chk1
  76.         mov     bx, ax                  ; show that we're here
  77.         jmp     short return
  78.  
  79. chk1:
  80.         cmp     bx, 1                   ; increment pointer?
  81.         jnz     short chain             ; no, just forget it
  82.         mov     ds, cx                  ; segment value here
  83.         mov     bx, dx                  ; offset here
  84.         inc     word ptr [bx]           ; add it in
  85.         jmp     short return
  86.         
  87. chain:                                  ; chain to previous handler
  88.         pop     dx
  89.         pop     cx
  90.         pop     bx
  91.         pop     ax
  92.         pop     ds
  93.         pop     es
  94.         pop     di
  95.         pop     si
  96.  
  97.         jmp     DWORD PTR cs:oldint
  98.  
  99. return:                                 ; return to caller
  100.         pop     dx
  101.         pop     cx
  102.         add     sp, 2       ;!!!! DON'T RESTORE BX !!!!!!
  103.         pop     ax
  104.         pop     ds
  105.         pop     es
  106.         pop     di
  107.         pop     si
  108.         iret
  109. handle  endp
  110.  
  111.  
  112.         ALIGN   16
  113. init_fence:           ; All code following this label will be discarded
  114.  
  115. ;*-------------------------- Initialization Code ----------------------*
  116.  
  117. gtsr    proc    far
  118.         mov     ax,_DATA
  119.         mov     ds,ax
  120.  
  121.         mov     ax,Vect_Num
  122.         mov     bx,offset tsrmsgx
  123.         call    hexasc
  124.  
  125.         mov     dx,offset tsrmsg        ;Print message
  126.         mov     cx,tsrmsgl
  127.         mov     bx,1                    ;stdout
  128.         mov     ah,40h                  ;write
  129.         int     21h
  130.  
  131. ;get old vector
  132.         mov     ah,35h
  133.         mov     al,Vect_Num
  134.         int     21h
  135.         mov     WORD PTR cs:oldint,bx
  136.         mov     WORD PTR cs:oldint+2,es
  137.  
  138.         push    ds
  139.         mov     dx, offset handle
  140.         push    cs
  141.         pop     ds
  142.         mov     ah,25h
  143.         mov     al,Vect_Num
  144.         int     21h
  145.         pop     ds
  146.  
  147.  
  148.         
  149.         mov     ax,3100h        ;TSR
  150.         mov     dx,offset init_fence
  151.         add     dx,15
  152.         shr     dx,1
  153.         shr     dx,1
  154.         shr     dx,1
  155.         shr     dx,1
  156.         add     dx,16
  157.         int     21h
  158. gtsr    endp
  159.  
  160. ;***********************************************************************
  161.  
  162. hexasc  proc    near            ; converts word to hex ASCII
  163.                                 ; call with AX = value,
  164.                                 ; DS:BX = address for string
  165.                                 ; returns AX, BX destroyed
  166.  
  167.         push    cx              ; save registers
  168.         push    dx
  169.  
  170.         mov     dx,4            ; initialize character counter
  171. hexasc1:
  172.         mov     cx,4            ; isolate next four bits
  173.         rol     ax,cl
  174.         mov     cx,ax
  175.         and     cx,0fh
  176.         add     cx,'0'          ; convert to ASCII
  177.         cmp     cx,'9'          ; is it 0-9?
  178.         jbe     hexasc2         ; yes, jump
  179.         add     cx,'A'-'9'-1    ; add fudge factor for A-F
  180.  
  181. hexasc2:                        ; store this character
  182.         mov     [bx],cl
  183.         inc     bx              ; bump string pointer
  184.  
  185.         dec     dx              ; count characters converted
  186.         jnz     hexasc1         ; loop, not four yet
  187.  
  188.         pop     dx              ; restore registers
  189.         pop     cx
  190.         ret                     ; back to caller
  191.  
  192. hexasc  endp
  193.  
  194.         
  195.  
  196. _TEXT   ends
  197.  
  198.  
  199. ;*--------------------------------------------------------------------*
  200.  
  201. _DATA   segment word public 'DATA'
  202. tsrmsg  db      'hooking interrupt '
  203. tsrmsgx dd      ?
  204.         db      cr,lf
  205. tsrmsgl equ     $-tsrmsg
  206.  
  207. _DATA   ends
  208.  
  209.  
  210.  
  211.         end     gtsr          
  212.