home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / util2 / tsr.lzh / FMARK.ASM next >
Assembly Source File  |  1986-07-20  |  7KB  |  192 lines

  1. ;FMARK.ASM - mark a position in memory,
  2. ;            above which TSRs will later be cleared by RELEASE.COM
  3. ;            this version leaves a minimal size MARK in memory,
  4. ;              storing the rest on disk
  5. ;            requires a single command line parameter naming
  6. ;              the file where the mark will be stored
  7. ;
  8. ; Syntax:  FMARK [d:][path]filename
  9. ;
  10. ; VERSION 2.0  6/17/86
  11. ;   start at a version number compatible with other TSR utilities
  12. ; VERSION 2.1  7/18/86
  13. ;   keep consistent with RELEASE
  14. ;
  15. ; written for CHASM (CHeap ASseMbler)
  16. ; by Kim Kokkonen, TurboPower Software
  17. ; telephone: 408-378-3672, Compuserve 72457,2131
  18. ;
  19. ;
  20. ;
  21. fmark  proc    near
  22.  
  23. ;parse command line for file name
  24.        mov     si,81H           ;point to command line
  25.        mov     di,offset(filnm) ;point to filename storage string
  26.        cld
  27.  
  28. get1   lodsb                    ;get first non-blank
  29.        cmpb    al,32            ;skip space
  30.        je      get1
  31.        cmpb    al,9             ;skip tab
  32.        je      get1
  33.        cmpb    al,13            ;check for end of input
  34.        jne     get2             ;got a non-blank, now get the parameter
  35.        jmp     error            ;no parameter --> error
  36.  
  37. get2   cmp     al,'a'
  38.        jl      sto1
  39.        cmp     al,'z'
  40.        jg      sto1
  41.        and     al,0DFH          ;uppercase
  42. sto1   stosb                    ;store the non-blank character
  43.        lodsb                    ;get next character
  44.        cmpb    al,32            ;terminate with blank, tab, or <cr>
  45.        je      gotit
  46.        cmpb    al,9
  47.        je      gotit
  48.        cmpb    al,13
  49.        je      gotit
  50.        jmps    get2
  51.  
  52. ;create the specified file
  53. gotit  mov     al,0
  54.        stosb                    ;terminate ASCIIZ pathname
  55.        mov     dx,offset(filnm)
  56.        xor     cx,cx            ;normal attribute
  57.        mov     ah,3CH
  58.        int     21H              ;DOS CREAT
  59.        jae     store
  60.  
  61.        mov     dx,offset(badfil) ;bad file name
  62.        mov     ah,9
  63.        int     21H
  64.        jmp     error
  65.  
  66. ;store the interrupt vector table
  67. store  mov     bx,ax           ;keep file handle in bx
  68.        push    ds              ;save ds
  69.        mov     cx,400H         ;1024 bytes to store
  70.        xor     ax,ax
  71.        mov     ds,ax           ;segment 0
  72.        mov     dx,ax           ;offset 0
  73.        mov     ah,40H
  74.        int     21H             ;write block to file
  75.        pop     ds              ;get ds back
  76.        jae     ems             ;ok, continue
  77.  
  78.        mov     dx,offset(nowrit) ;write error
  79.        mov     ah,9
  80.        int     21H
  81.        jmp     error
  82.  
  83. ;determine whether EMS is present
  84. ems    push    bx              ;temporarily store the real file handle
  85.        xor     bx,bx           ;zero the EMS handle count in case EMS not present
  86.        mov     dx,offset(emsnm)
  87.        mov     ax,3D00H
  88.        int     21H
  89.        jb      sthand          ;EMS driver not installed
  90.  
  91. ;EMS present, close the open "handle" first
  92.        mov     bx,ax           ;EMS handle into bx
  93.        mov     ah,3EH
  94.        int     21H             ;close handle
  95.  
  96. ;get the current EMS page map
  97.        mov     ah,4DH
  98.        mov     di,offset(emsmap) ;es=cs already
  99.        xor     bx,bx           ;required by some versions of EMM (bug workaround)
  100.        cld                     ;required by some versions of EMM
  101.        int     67H
  102.        or      ah,ah
  103.        jz      sthand          ;result ok
  104.        xor     bx,bx           ;error, return zero EMS handles
  105.  
  106. ;store the number of active handles
  107. sthand mov     emscnt,bx       ;count of active handles
  108.  
  109. ;write the handle table to disk
  110.        shl     bx
  111.        shl     bx              ;4 bytes per handle
  112.        inc     bx
  113.        inc     bx              ;2 more bytes for the handle count
  114.        mov     cx,bx           ;number of bytes to write
  115.        pop     bx              ;get file handle back
  116.        mov     dx,offset(emscnt) ;what we're writing
  117.        mov     ah,40H
  118.        int     21H             ;write out the table
  119.        jae     closfl          ;ok,continue
  120.  
  121.        mov     dx,offset(nowrit) ;error while writing
  122.        mov     ah,9
  123.        int     21H
  124.        jmps    error
  125.  
  126. ;close up the table file
  127. closfl mov     ah,3EH
  128.        int     21H             ;close handle
  129.        jae     idstr           ;ok, continue
  130.  
  131.        mov     dx,offset(badcls) ;error while closing file
  132.        mov     ah,9
  133.        int     21H
  134.        jmps    error
  135.  
  136. ;put a standard ID string into the PSP for RELEASE to check
  137. idstr  mov     si,offset(id)
  138.        mov     di,60H          ;unused area of the PSP
  139.        mov     cx,9            ;characters in ID string
  140.        cld
  141.        rep
  142.        movsb                   ;copy string
  143.  
  144. ;deallocate environment block of this mark
  145. deall  mov     ax,[2CH]        ;environment segment
  146.        mov     es,ax           ;  into es
  147.        mov     ah,49H
  148.        int     21H             ;deallocate, no reason for an error to occur
  149.  
  150. ;print message and TSR
  151. gores  mov     dx,offset(didit)
  152.        mov     ah,9
  153.        int     21H             ;write success message including filename
  154.        mov     dx,offset(crlf) ;newline
  155.        mov     ah,9
  156.        int     21H
  157.  
  158.        xor     dx,dx           ;get number of paragraphs to keep
  159.        mov     dl,[80H]        ;length of command line
  160.        add     dx,80H          ;rest of PSP
  161.        mov     cl,4
  162.        shr     dx,cl           ;convert to paragraphs
  163.        inc     dx              ;round up
  164.        mov     ax,3100H
  165.        int     21H             ;terminate and stay resident
  166.  
  167. ;error output - show syntax line
  168. error  mov     dx,offset(syntax)
  169.        mov     ah,9
  170.        int     21H
  171.  
  172. ;exit with error
  173. errex  mov     ax,4C01H
  174.        int     21H
  175.        endp
  176.  
  177. ;messages
  178. emsnm  db      'EMMXXXX0',0    ;file name for testing EMS presence
  179. id     db      'FMARK TSR'     ;id string for RELEASE check
  180. badfil db      13,10,'Could not open file for writing',36
  181. nowrit db      13,10,'Error while writing',36
  182. badcls db      13,10,'Error closing table file',36
  183. syntax db      13,10,'Syntax:  FMARK [d:][path]filename'
  184. crlf   db      13,10,36
  185. didit  db      13,10,'FMARK 2.1 - Marked current memory position in '
  186.  
  187. ;data storage area
  188. filnm  ds      50H,36          ;file name where tables are written
  189. emscnt db      0,0             ;holds number of active pages in map that follows
  190. emsmap db      0,0             ;holds EMS page map if installed
  191.                                ;(note may extend 1K bytes past end of file in mem)
  192.