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

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