home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbopas / tsrhelp.zip / INST-CHK.INC < prev    next >
Text File  |  1992-05-29  |  2KB  |  61 lines

  1. ;---------------------------------------------------------------------------
  2. ; Install_Check:
  3. ;   If there is a copy already in memory, then when this is executed again,
  4. ;   there will be two copies.  This procedure compares the currently running
  5. ;   copy with the currently TSR copy.  It searches the first 16 bytes of the
  6. ;   UMBs up to the current one.  If it doesn't match then there's not a copy.
  7. ;   If it does match, it is very, very likely it's the same program. The 1st
  8. ;   word is NOT'ed to ensure only a running copy is found.  If the copy is
  9. ;   removed from memory, then it is NOT'ed again since it won't really be 
  10. ;   removed, just unallocated.  Otherwise there would appear to be many
  11. ;   copies running in memory when they are really unallocated and doing
  12. ;   nothing. If it is already installed, then ES will contain the segment and 
  13. ;   the carry flag is cleared.
  14. ;
  15. ;   Before:
  16. ;           CS = Current Code Segment
  17. ;   After:
  18. ;           Carry Set = Not found
  19. ;           Carry Clr = Found
  20. ;           ES = Segment found at or CS if not found
  21. ;   Changes:
  22. ;           Nothing
  23. ;---------------------------------------------------------------------------
  24. Install_Check   Proc Far
  25.         Assume CS:Code,DS:Nothing,ES:Nothing
  26.         Push BX
  27.         Push AX
  28.         Push SI
  29.         Push DI
  30.         Push CX
  31.         
  32.         Not Word Ptr CS:Start       ; Fingerprint
  33.         Mov BX,0A000h               ; Start in UMB's
  34.         Mov AX,CS                   ; Store CS
  35.         
  36. Loop1:   
  37.         Inc BX                      ; Search next segment
  38.         Mov ES,BX                  
  39.         Cmp AX,BX                   ; It's not before CS so it's not installed
  40.         JE NoCopy
  41.         Mov SI,Offset Start
  42.         Mov DI,SI
  43.         Mov CX,16                   ; Check 16 bytes
  44.         Repe Cmpsb                  ; Repeat if equal
  45.         JNE Loop1                   ; Not installed here so check next segment
  46.         CLC                         ; It is installed here as segment ES
  47. Done:        
  48.         Pop CX
  49.         Pop DI
  50.         Pop SI
  51.         Pop AX
  52.         Pop BX
  53.         Ret
  54.         
  55. NoCopy:
  56.         STC                         ; Not Found
  57.         Jmp Short Done
  58.         
  59. Install_Check   EndP
  60.  
  61.