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