home *** CD-ROM | disk | FTP | other *** search
/ The Business Master (3rd Edition) / The Business Master (3rd Edition).iso / files / utilstem / tsrman / fmark.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-31  |  9.1 KB  |  231 lines

  1. ;=======================================================================
  2. ;FMARK.ASM - mark a position in memory,
  3. ;30-May-1989 above which TSRs will later be cleared by UnMark.COM
  4. ;03:10       this version leaves a minimal size MARK in memory,
  5. ;              storing the rest on disk
  6. ;            requires a single command line parameter naming
  7. ;              the file where the mark will be stored
  8. ;
  9. ; Syntax:  FMARK [d:][path]filename
  10. ;=======================================================================
  11. ; written for MASM (version 4 or later) or TASM
  12. ; by Kim Kokkonen, TurboPower Software
  13. ; telephone: 408-438-8608, Compuserve 72457,2131
  14. ;=======================================================================
  15. ; VERSION 2.0  6/17/86
  16. ;   start at a version number compatible with other TSR utilities
  17. ; VERSION 2.1  7/18/86
  18. ;   keep consistent with RELEASE
  19. ; VERSION 2.2  3/4/87
  20. ;   add save area for BIOS data areas
  21. ;     40:A8 (8 bytes for EGA)
  22. ;     40:F0 (16 bytes for interapplications communications)
  23. ; VERSION 2.3  5/2/87
  24. ;   convert to MASM
  25. ; VERSION 2.4  5/17/87
  26. ;   for consistency with RELEASE
  27. ; VERSION 2.5  6/2/87
  28. ;   fix bug in memory allocated when command line is 15 bytes long
  29. ;   add version checking for consistency between FMARK and RELEASE
  30. ; VERSION 3.1  5/30/89 for use with UnMark and ReMark 3.1
  31. ;   by Tom Gilbert's Heart & Mind includes TurboPower 2.8
  32. ;   fix problem occurring when command processor is an EXE file,
  33. ;     by storing parent's PSP segment as part of MARK save area
  34. ;     (thanks to Tom Rawson for this code)
  35. ;=======================================================================
  36.  
  37. Cseg    segment public para
  38.         assume  cs:Cseg, ds:Cseg, es:Cseg
  39.  
  40.         org     016H            ;access to parent's PSP
  41. parpsp  label   word
  42.  
  43.         org     02CH
  44. envseg  label   word            ;access to environment segment
  45.  
  46.         org     80H
  47. cmdlen  label   byte            ;command line length
  48.         org     81H
  49. cmdlin  label   byte            ;first character of command line
  50.  
  51.         org     100H
  52. fmark   proc    near
  53.  
  54. ComEntry:                       ;parse  command line for file name
  55.         mov     si,offset cmdlin ;point to command line
  56.         mov     di,offset filnm  ;point to filename storage string
  57.         cld
  58.  
  59. get1:   lodsb                   ;get first non-blank
  60.         cmp     al,32           ;skip space
  61.         je      get1
  62.         cmp     al,9            ;skip tab
  63.         je      get1
  64.         cmp     al,13           ;check for end of input
  65.         jne     get2            ;got a non-blank, now get the parameter
  66.         jmp     error           ;no parameter --> error
  67.  
  68. get2:   cmp     al,'a'
  69.         jl      sto1
  70.         cmp     al,'z'
  71.         jg      sto1
  72.         and     al,0DFH         ;uppercase
  73. sto1:   stosb                   ;store the non-blank character
  74.         lodsb                   ;get next character
  75.         cmp     al,32           ;terminate with blank, tab, or <cr>
  76.         je      gotit
  77.         cmp     al,9
  78.         je      gotit
  79.         cmp     al,13
  80.         je      gotit
  81.         jmp     short get2
  82.  
  83. gotit:  mov     al,0            ;create the specified file
  84.         stosb                   ;terminate ASCIIZ pathname
  85.         mov     dx,offset filnm
  86.         xor     cx,cx           ;normal attribute
  87.         mov     ah,3CH
  88.         int     21H             ;DOS CREAT
  89.         jae     store
  90.         mov     dx,offset badfil ;bad file name
  91.         mov     ah,9
  92.         int     21H
  93.         jmp     error
  94.  
  95. store:  mov     bx,ax           ;keep file handle in bx
  96.         push    ds              ;save ds
  97.         mov     cx,400H         ;1024 bytes to store
  98.         xor     ax,ax
  99.         mov     ds,ax           ;segment 0
  100.         assume  ds:nothing
  101.         mov     dx,ax           ;offset 0
  102.         mov     ah,40H          ;write the interrupt
  103.         int     21H             ;vector table block to file
  104.         pop     ds              ;get ds back
  105.         assume  ds:Cseg         ;If Write Fails
  106.         jc      fwerr           ;Then Error Exit
  107. egasav: push    ds              ;Else save ds
  108.         mov     cx,0008H        ;8 bytes to store
  109.         mov     ax,0040H
  110.         mov     ds,ax           ;BIOS data segment
  111.         assume  ds:nothing
  112.         mov     dx,00A8H        ;EGA save table pointer
  113.         mov     ah,40H          ;store the EGA data area
  114.         int     21H             ;write block to file
  115.         pop     ds              ;get ds back
  116.  
  117.         assume  ds:Cseg         ;If Write Fails
  118.         jc      fwerr           ;Then Error Exit
  119. intcom: push    ds              ;Else save ds
  120.         mov     cx,0010H        ;16 bytes to store
  121.         mov     ax,0040H
  122.         mov     ds,ax           ;BIOS data segment
  123.         assume  ds:nothing      ;store the interapplications
  124.         mov     dx,00F0H        ;communication area
  125.         mov     ah,40H
  126.         int     21H             ;write block to file
  127.         pop     ds              ;get ds back
  128.         assume  ds:Cseg         ;If Write Fails
  129.         jc      fwerr           ;Then Error Exit
  130. parent: mov     cx,2            ;Else store the parent's psp
  131.         mov     dx,offset parpsp
  132.         mov     ah,40H
  133.         int     21H             ;If write block to file fails
  134.         jc      fwerr           ;Then Error Exit
  135.                                 ;Else determine whether EMS is present
  136. ems:    push    bx              ;temporarily store the file handle
  137.         xor     bx,bx           ;zero the EMS handle count in case
  138.         mov     dx,offset emsnm ;EMS not present
  139.         mov     ax,3D00H
  140.         int     21H
  141.         jb      sthand          ;EMS driver not installed
  142.  
  143.         mov     bx,ax           ;EMS handle into bx
  144.         mov     ah,3EH          ;close the
  145.         int     21H             ;open "handle"
  146.  
  147.         mov     ah,4DH          ;get the current EMS page map
  148.         mov     di,offset emsmap ;es=cs already
  149.         xor     bx,bx           ;required by some versions of EMM
  150.         cld                     ;required by some versions of EMM
  151.         int     67H
  152.         or      ah,ah
  153.         jz      sthand          ;result ok
  154.         xor     bx,bx           ;error, return zero EMS handles
  155. sthand: mov     emscnt,bx       ;store count of active handles
  156.         shl     bx,1
  157.         shl     bx,1            ;4 bytes per handle
  158.         inc     bx
  159.         inc     bx              ;2 more bytes for the handle count
  160.         mov     cx,bx           ;number of bytes to write
  161.         pop     bx              ;get file handle back
  162.         mov     dx,offset emscnt ;what we're writing
  163.         mov     ah,40H
  164.         int     21H             ;write out the table
  165.         jae     closfl          ;ok,continue
  166.  
  167. fwerr:  mov     dx,offset nowrit
  168.         mov     ah,9            ;error while writing
  169.         int     21H
  170.         jmp     short error
  171.  
  172. closfl: mov     ah,3EH          ;close up the table file
  173.         int     21H             ;close handle
  174.         jae     idstr           ;ok, continue
  175.         mov     dx,offset badcls
  176.         mov     ah,9            ;error while closing file
  177.         int     21H
  178.         jmp     short error
  179.  
  180. ;put a standard ID string into the PSP for RELEASE to check
  181. idstr:  mov     si,offset id
  182.         mov     di,60H          ;unused area of the PSP
  183.         mov     cx,idlen        ;characters in ID string
  184.         cld
  185.         rep     movsb           ;copy string
  186.  
  187. ;deallocate environment block of this mark
  188. deall:  mov     ax,envseg       ;environment segment
  189.         mov     es,ax           ;  into es
  190.         mov     ah,49H          ;deallocate
  191.         int     21H             ;no reason for an error to occur
  192. gores:  mov     dx,offset didit ;print message and TSR
  193.         mov     ah,9            ;write success message
  194.         int     21H             ;including filename
  195.         mov     dx,offset crlf  ;and newline
  196.         mov     ah,9
  197.         int     21H
  198.         xor     dx,dx           ;get number of paragraphs to keep
  199.         mov     dl,cmdlen       ;length of command line
  200.         add     dx,0090H        ;rest of PSP plus paragraph margin
  201.         mov     cl,4
  202.         shr     dx,cl           ;convert to paragraphs
  203.         mov     ax,3100H
  204.         int     21H             ;terminate and stay resident
  205.  
  206. ;error output - show syntax line
  207. error:  mov     dx,offset syntax
  208.         mov     ah,9
  209.         int     21H
  210.         mov     ax,4C01H        ;exit with error
  211.         int     21H
  212. fmark   endp
  213.  
  214. emsnm   db  'EMMXXXX0',0    ;file name for testing EMS presence
  215. id      db  'FM3.1 TSR'     ;id string for UnMark/ReMark check
  216. idlen   equ $-id
  217. ;messages
  218. badfil  db  13,10,'Could not open file for writing',36
  219. nowrit  db  13,10,'Error while writing',36
  220. badcls  db  13,10,'Error closing table file',36
  221. syntax  db  13,10,'Syntax:  FMARK [d:][path]filename'
  222. crlf    db  13,10,36
  223. didit   db  13,10,'FMARK 3.1 - Marked current memory position in '
  224. ;data storage area
  225. filnm   db  44H dup (36)    ;mark file name
  226. emscnt  dw  0   ;holds number of active pages in map that follows
  227. emsmap  db  0   ;holds EMS page map if installed
  228.                 ;(note may extend 1K bytes past end of file in memory)
  229. Cseg    ends
  230.         end     ComEntry
  231.