home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / SYSUTL / TSRSRC31.ZIP / FMARK.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-11-04  |  12.4 KB  |  362 lines

  1. ;==============================================================================
  2. ;FMARK.ASM - mark a position in memory,
  3. ;            above which TSRs will later be cleared by RELEASE
  4. ;            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 [/Q] [d:][path]filename
  10. ;==============================================================================
  11. ; written for TASM
  12. ; by Kim Kokkonen, TurboPower Software
  13. ; Copyright (c) 1986,1991 Kim Kokkonen, TurboPower Software.
  14. ; May be freely distributed but not sold except by permission.
  15. ; telephone: 719-260-6641, Compuserve 76004,2611
  16. ;==============================================================================
  17. ; version 2.0  6/17/86
  18. ;   start at a version number compatible with other TSR utilities
  19. ; :
  20. ; long intervening history
  21. ; :
  22. ; version 3.0  9/24/91
  23. ;   add Quiet option
  24. ; version 3.1  11/4/91
  25. ;   no change
  26. ;==============================================================================
  27. ;
  28. Cseg      segment public para
  29.           assume  cs:Cseg, ds:Cseg, es:Cseg
  30.  
  31.           org     016H               ;access to parent's PSP
  32. parpsp    label   word
  33.  
  34.           org     02CH
  35. envseg    label   word               ;access to environment segment
  36.  
  37.           org     80H
  38. cmdlen    label   byte               ;command line length
  39.           org     81H
  40. cmdlin    label   byte               ;first character of command line
  41.  
  42.           org     100H
  43.  
  44. fmark     proc    near
  45.  
  46. comentry:
  47.  
  48. ;deallocate environment block of this mark
  49.        push    es
  50.        mov     ax,envseg       ;environment segment
  51.        mov     es,ax           ;  into es
  52.        mov     ah,49H
  53.        int     21H             ;deallocate, no reason for an error to occur
  54.        pop     es
  55.  
  56. ;parse command line for file name
  57.        mov     si,offset cmdlin ;point to command line
  58.        mov     di,offset filnm  ;point to filename storage string
  59.        cld
  60.  
  61. get1:  lodsb                    ;get first non-blank
  62.        cmp     al,32            ;skip space
  63.        je      get1
  64.        cmp     al,9             ;skip tab
  65.        je      get1
  66.        cmp     al,13            ;check for end of input
  67.        jne     geto             ;got a non-blank, now get the parameter
  68.        cmp     di,offset filnm  ;filename already specified?
  69.        jne     gotit            ;done if so
  70.        jmp     error            ;no parameter --> error
  71.  
  72. geto:  cmp     al,'/'           ;check for option
  73.        je      getoc
  74.        cmp     al,'-'
  75.        jne     get2
  76. getoc: lodsb
  77.        call    upcase
  78.        cmp     al,'Q'
  79.        jnz     operr
  80.        mov     quiet,1          ;set quiet option
  81.        jmp     get1             ;loop around
  82.  
  83. operr: mov     dx,offset badopt ;bad option
  84.        jmp     errmsg
  85.  
  86. get2:  cmp     di,offset filnm  ;filename already specified?
  87.        jne     operr            ;error if so
  88.  
  89. get2a: call    upcase           ;upcase char in al
  90.        stosb                    ;store the non-blank character
  91.        lodsb                    ;get next character
  92.        cmp     al,32
  93.        je      get1             ;loop back around for blank
  94.        cmp     al,9
  95.        je      get1             ;loop back around for tab
  96.        cmp     al,13
  97.        je      gotit            ;terminate for <cr>
  98.        jmp     short get2a      ;keep adding characters to filename
  99.  
  100. ;create the specified file
  101. gotit: mov     al,0
  102.        stosb                    ;terminate ASCIIZ pathname
  103.        mov     dx,offset filnm
  104.        xor     cx,cx            ;normal attribute
  105.        mov     ah,3CH
  106.        int     21H              ;DOS CREAT
  107.        jae     store
  108.  
  109.        mov     dx,offset badfil ;bad file name
  110.        jmp     errmsg
  111.  
  112. ;store the interrupt vector table
  113. store: mov     bx,ax           ;keep file handle in bx
  114.        push    ds              ;save ds
  115.        mov     cx,400H         ;1024 bytes to store
  116.        xor     ax,ax
  117.        mov     ds,ax           ;segment 0
  118.        assume  ds:nothing
  119.        mov     dx,ax           ;offset 0
  120.        mov     ah,40H
  121.        int     21H             ;write block to file
  122.        pop     ds              ;get ds back
  123.        assume  ds:cseg
  124.        jae     egasav          ;ok, continue
  125.  
  126.        mov     dx,offset nowrit ;write error
  127.        jmp     errmsg
  128.  
  129. ;store the EGA save pointer
  130. egasav: push    ds             ;save ds
  131.        mov     cx,0008H        ;8 bytes to store
  132.        mov     ax,0040H
  133.        mov     ds,ax           ;BIOS data segment
  134.        assume  ds:nothing
  135.        mov     dx,00A8H        ;EGA save table pointer
  136.        mov     ah,40H
  137.        int     21H             ;write block to file
  138.        pop     ds              ;get ds back
  139.        assume  ds:cseg
  140.        jae     intcom          ;ok, continue
  141.  
  142.        mov     dx,offset nowrit ;write error
  143.        jmp     errmsg
  144.  
  145. ;store the interapplications communications area
  146. intcom: push    ds             ;save ds
  147.        mov     cx,0010H        ;16 bytes to store
  148.        mov     ax,0040H
  149.        mov     ds,ax           ;BIOS data segment
  150.        assume  ds:nothing
  151.        mov     dx,00F0H        ;interapplications communication area
  152.        mov     ah,40H
  153.        int     21H             ;write block to file
  154.        pop     ds              ;get ds back
  155.        assume  ds:cseg
  156.        jae     parent          ;ok, continue
  157.  
  158.        mov     dx,offset nowrit ;write error
  159.        jmp     errmsg
  160.  
  161. ;store the parent's psp
  162. parent:
  163.        mov     cx,2            ;2 bytes to store
  164.        mov     dx,offset parpsp  ;point to parent's psp
  165.        mov     ah,40H
  166.        int     21H             ;write block to file
  167.        jae     ems             ;ok, continue
  168.  
  169.        mov     dx,offset nowrit ;write error
  170.        jmp     errmsg
  171.  
  172. ;determine whether EMS is present
  173. ems:   push    bx              ;temporarily store the file handle
  174.        xor     bx,bx           ;zero the EMS handle count in case EMS not present
  175.        mov     dx,offset emsnm
  176.        mov     ax,3D00H
  177.        int     21H
  178.        jb      sthand          ;EMS driver not installed
  179.  
  180. ;EMS present, close the open "handle" first
  181.        mov     bx,ax           ;EMS handle into bx
  182.        mov     ah,3EH
  183.        int     21H             ;close handle
  184.  
  185. ;get the current EMS page map
  186.        mov     ah,4DH
  187.        mov     di,offset emsmap ;es=cs already
  188.        xor     bx,bx           ;required by some versions of EMM (bug workaround)
  189.        cld                     ;required by some versions of EMM
  190.        int     67H
  191.        or      ah,ah
  192.        jz      sthand          ;result ok
  193.        xor     bx,bx           ;error, return zero EMS handles
  194.  
  195. ;store the number of active handles
  196. sthand: mov     emscnt,bx      ;count of active handles
  197.  
  198. ;write the handle table to disk
  199.        shl     bx,1
  200.        shl     bx,1            ;4 bytes per handle
  201.        inc     bx
  202.        inc     bx              ;2 more bytes for the handle count
  203.        mov     cx,bx           ;number of bytes to write
  204.        pop     bx              ;get file handle back
  205.        mov     dx,offset emscnt ;what we're writing
  206.        mov     ah,40H
  207.        int     21H             ;write out the table
  208.        jae     stomcb          ;ok,continue
  209.  
  210.        mov     dx,offset nowrit ;error while writing
  211.        jmp     errmsg
  212.  
  213. ;write the allocated mcb chain
  214. stomcb:push    bx                       ;save file handle
  215.        mov     ax,5802H
  216.        int     21H                      ;get UMB link status
  217.        jnc     linkok
  218.        mov     al,0
  219. linkok:xor     ah,ah
  220.        push    ax                       ;save link status
  221.        mov     ax,5803H
  222.        mov     bx,1                     ;open up high memory
  223.        int     21H
  224.  
  225.        mov     ah,52H                   ;get first mcb segment
  226.        int     21H
  227.        mov     ax,es:[bx-2]             ;ax=first mcb
  228.        push    cs
  229.        pop     es                       ;es=cs
  230.  
  231.        mov     di,emscnt                ;get starting address of mcbmap
  232.        shl     di,1
  233.        shl     di,1
  234.        add     di,offset emsmap
  235.        mov     si,di                    ;cs:[si] -> mcbcnt
  236.        add     di,2                     ;cs:[di] -> mcbmap
  237.        xor     cx,cx                    ;cx will count mcbs
  238.        cld
  239.        push    ds
  240.  
  241. mcbnext:
  242.        stosw                            ;store mcb segment held by ax
  243.        mov     ds,ax                    ;ds:[0] points to mcb
  244.        mov     ax,ds:[1]                ;get mcb owner
  245.        stosw                            ;store it
  246.        inc     cx                       ;increment count
  247.        cmp     byte ptr ds:[0],'Z'      ;end of mcb chain?
  248.        je      mcbdone
  249.        mov     ax,ds                    ;restore ax to mcb segment
  250.        inc     ax                       ;skip over mcb itself
  251.        add     ax,ds:[3]                ;add length of memory block
  252.        jmp     mcbnext
  253.  
  254. mcbdone:
  255.        pop     ds
  256.        mov     ax,5803H
  257.        pop     bx                       ;restore high memory link
  258.        int     21H
  259.  
  260.        mov     [si],cx                  ;store number of mcbs
  261.        sub     di,si                    ;di=number of bytes in mcb group table
  262.        mov     cx,di                    ;count of bytes in cx
  263.        mov     dx,si                    ;what we're writing (mcbcnt+mcbmap)
  264.        pop     bx                       ;get file handle back
  265.        mov     ah,40H
  266.        int     21H                      ;write out the table
  267.        jae     closfl                   ;ok,continue
  268.  
  269.        mov     dx,offset nowrit         ;error while writing
  270.        jmp     errmsg
  271.  
  272. ;close up the table file
  273. closfl:mov     ah,3EH
  274.        int     21H                      ;close handle
  275.        jae     idstr                    ;ok, continue
  276.  
  277.        mov     dx,offset badcls         ;error while closing file
  278.        jmp     errmsg
  279.  
  280. ;put a standard ID string into the PSP for RELEASE to check
  281. idstr: mov     si,offset id
  282.        mov     di,60H          ;unused area of the PSP
  283.        mov     cx,idlen        ;characters in ID string
  284.        cld
  285.        rep     movsb           ;copy string
  286.  
  287. ;copy the filename into the command tail
  288.        mov     si,offset filnm
  289.        mov     di,offset cmdlin
  290.        xor     cx,cx
  291. nxtf:  lodsb
  292.        or      al,al
  293.        jz      donf
  294.        inc     cx
  295.        stosb
  296.        jmp     nxtf
  297. donf:  mov     cmdlen,cl
  298.  
  299. ;print message and TSR
  300. gores: cmp     quiet,0         ;check quiet flag
  301.        jnz     gores1
  302.        mov     dx,offset didit
  303.        mov     ah,9
  304.        int     21H             ;write success message including filename
  305.        mov     dx,offset crlf  ;newline
  306.        mov     ah,9
  307.        int     21H
  308.  
  309. gores1:xor     dx,dx           ;get number of paragraphs to keep
  310.        mov     dl,cmdlen       ;length of command line
  311.        add     dx,0090H        ;rest of PSP plus paragraph margin
  312.        mov     cl,4
  313.        shr     dx,cl           ;convert to paragraphs
  314.        mov     ax,3100H
  315.        int     21H             ;terminate but stay resident
  316.  
  317. ;error output - show syntax line
  318. ;dx has offset of error message
  319. errmsg:mov     ah,9
  320.        int     21H
  321. error: mov     dx,offset syntax
  322.        mov     ah,9
  323.        int     21H
  324.        mov     ax,4C01H
  325.        int     21H
  326.  
  327. fmark  endp
  328.  
  329. upcase proc    near
  330.        cmp     al,'a'
  331.        jb      noup
  332.        cmp     al,'z'
  333.        ja      noup
  334.        and     al,0DFH          ;uppercase
  335. noup:  ret
  336. upcase endp
  337.  
  338. emsnm  db      'EMMXXXX0',0    ;file name for testing EMS presence
  339. id     db      'FM3.1 TSR'     ;id string for RELEASE check
  340. idlen  equ     $-id
  341.  
  342. ;messages
  343. badfil db      13,10,'Could not open file for writing',36
  344. nowrit db      13,10,'Error while writing',36
  345. badcls db      13,10,'Error closing table file',36
  346. badopt db      13,10,'Bad command line option',36
  347. syntax db      13,10,'Syntax:  FMARK [/Q] [d:][path]filename'
  348. crlf   db      13,10,36
  349. didit  db      'FMARK 3.1, Copyright 1991 TurboPower Software',13,10
  350. didit2 db      'Marked current memory position in '
  351.  
  352. ;data storage area
  353. filnm  db      50H dup (36)    ;mark file name
  354. quiet  db      0               ;quiet flag
  355. emscnt dw      0               ;holds number of active pages in map that follows
  356. emsmap =       $               ;EMS page map (up to 1024 bytes)
  357. mcbcnt =       emsmap+400H     ;number of allocated mcbs
  358. mcbmap =       mcbcnt+2        ;MCB map (up to 1024 bytes)
  359.  
  360. Cseg    ends
  361.         end     ComEntry
  362.