home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TSRSRC29.ZIP / FMARK.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-01-04  |  9.6 KB  |  286 lines

  1. ;==============================================================================
  2. ;FMARK.ASM - mark a position in memory,
  3. ;            above which TSRs will later be cleared by RELEASE.COM
  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 [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 2.6  1/15/89
  31. ;   fix problem occurring when command processor is an EXE file,
  32. ;     by storing parent's PSP segment as part of MARK save area
  33. ;     (thanks to Tom Rawson for this code)
  34. ; VERSION 2.7
  35. ;   skipped
  36. ; VERSION 2.8
  37. ;   for consistency with MARKNET/RELNET
  38. ; VERSION 2.9
  39. ;   for consistency with MARKNET/RELNET
  40. ;==============================================================================
  41. ;
  42. Cseg      segment public para
  43.           assume  cs:Cseg, ds:Cseg, es:Cseg
  44.  
  45.           org     016H               ;access to parent's PSP
  46. parpsp    label   word
  47.  
  48.           org     02CH
  49. envseg    label   word               ;access to environment segment
  50.  
  51.           org     80H
  52. cmdlen    label   byte               ;command line length
  53.           org     81H
  54. cmdlin    label   byte               ;first character of command line
  55.  
  56.           org     100H
  57.  
  58. fmark     proc    near
  59.  
  60. comentry:
  61.  
  62. ;parse command line for file name
  63.        mov     si,offset cmdlin ;point to command line
  64.        mov     di,offset filnm  ;point to filename storage string
  65.        cld
  66.  
  67. get1:  lodsb                    ;get first non-blank
  68.        cmp     al,32            ;skip space
  69.        je      get1
  70.        cmp     al,9             ;skip tab
  71.        je      get1
  72.        cmp     al,13            ;check for end of input
  73.        jne     get2             ;got a non-blank, now get the parameter
  74.        jmp     error            ;no parameter --> error
  75.  
  76. get2:  cmp     al,'a'
  77.        jl      sto1
  78.        cmp     al,'z'
  79.        jg      sto1
  80.        and     al,0DFH          ;uppercase
  81. sto1:  stosb                    ;store the non-blank character
  82.        lodsb                    ;get next character
  83.        cmp     al,32            ;terminate with blank, tab, or <cr>
  84.        je      gotit
  85.        cmp     al,9
  86.        je      gotit
  87.        cmp     al,13
  88.        je      gotit
  89.        jmp     short get2
  90.  
  91. ;create the specified file
  92. gotit: mov     al,0
  93.        stosb                    ;terminate ASCIIZ pathname
  94.        mov     dx,offset filnm
  95.        xor     cx,cx            ;normal attribute
  96.        mov     ah,3CH
  97.        int     21H              ;DOS CREAT
  98.        jae     store
  99.  
  100.        mov     dx,offset badfil ;bad file name
  101.        mov     ah,9
  102.        int     21H
  103.        jmp     error
  104.  
  105. ;store the interrupt vector table
  106. store: mov     bx,ax           ;keep file handle in bx
  107.        push    ds              ;save ds
  108.        mov     cx,400H         ;1024 bytes to store
  109.        xor     ax,ax
  110.        mov     ds,ax           ;segment 0
  111.        assume  ds:nothing
  112.        mov     dx,ax           ;offset 0
  113.        mov     ah,40H
  114.        int     21H             ;write block to file
  115.        pop     ds              ;get ds back
  116.        assume  ds:cseg
  117.        jae     egasav          ;ok, continue
  118.  
  119.        mov     dx,offset nowrit ;write error
  120.        mov     ah,9
  121.        int     21H
  122.        jmp     error
  123.  
  124. ;store the EGA save pointer
  125. egasav: push    ds             ;save ds
  126.        mov     cx,0008H        ;8 bytes to store
  127.        mov     ax,0040H
  128.        mov     ds,ax           ;BIOS data segment
  129.        assume  ds:nothing
  130.        mov     dx,00A8H        ;EGA save table pointer
  131.        mov     ah,40H
  132.        int     21H             ;write block to file
  133.        pop     ds              ;get ds back
  134.        assume  ds:cseg
  135.        jae     intcom          ;ok, continue
  136.  
  137.        mov     dx,offset nowrit ;write error
  138.        mov     ah,9
  139.        int     21H
  140.        jmp     error
  141.  
  142. ;store the interapplications communications area
  143. intcom: push    ds             ;save ds
  144.        mov     cx,0010H        ;16 bytes to store
  145.        mov     ax,0040H
  146.        mov     ds,ax           ;BIOS data segment
  147.        assume  ds:nothing
  148.        mov     dx,00F0H        ;interapplications communication area
  149.        mov     ah,40H
  150.        int     21H             ;write block to file
  151.        pop     ds              ;get ds back
  152.        assume  ds:cseg
  153.        jae     parent          ;ok, continue
  154.  
  155.        mov     dx,offset nowrit ;write error
  156.        mov     ah,9
  157.        int     21H
  158.        jmp     error
  159.  
  160. ;store the parent's psp
  161. parent:
  162.        mov     cx,2            ;2 bytes to store
  163.        mov     dx,offset parpsp  ;point to parent's psp
  164.        mov     ah,40H
  165.        int     21H             ;write block to file
  166.        jae     ems             ;ok, continue
  167.  
  168.        mov     dx,offset nowrit ;write error
  169.        mov     ah,9
  170.        int     21H
  171.        jmp     error
  172.  
  173. ;determine whether EMS is present
  174. ems:   push    bx              ;temporarily store the file handle
  175.        xor     bx,bx           ;zero the EMS handle count in case EMS not present
  176.        mov     dx,offset emsnm
  177.        mov     ax,3D00H
  178.        int     21H
  179.        jb      sthand          ;EMS driver not installed
  180.  
  181. ;EMS present, close the open "handle" first
  182.        mov     bx,ax           ;EMS handle into bx
  183.        mov     ah,3EH
  184.        int     21H             ;close handle
  185.  
  186. ;get the current EMS page map
  187.        mov     ah,4DH
  188.        mov     di,offset emsmap ;es=cs already
  189.        xor     bx,bx           ;required by some versions of EMM (bug workaround)
  190.        cld                     ;required by some versions of EMM
  191.        int     67H
  192.        or      ah,ah
  193.        jz      sthand          ;result ok
  194.        xor     bx,bx           ;error, return zero EMS handles
  195.  
  196. ;store the number of active handles
  197. sthand: mov     emscnt,bx      ;count of active handles
  198.  
  199. ;write the handle table to disk
  200.        shl     bx,1
  201.        shl     bx,1            ;4 bytes per handle
  202.        inc     bx
  203.        inc     bx              ;2 more bytes for the handle count
  204.        mov     cx,bx           ;number of bytes to write
  205.        pop     bx              ;get file handle back
  206.        mov     dx,offset emscnt ;what we're writing
  207.        mov     ah,40H
  208.        int     21H             ;write out the table
  209.        jae     closfl          ;ok,continue
  210.  
  211.        mov     dx,offset nowrit ;error while writing
  212.        mov     ah,9
  213.        int     21H
  214.        jmp     short error
  215.  
  216. ;close up the table file
  217. closfl: mov     ah,3EH
  218.        int     21H             ;close handle
  219.        jae     idstr           ;ok, continue
  220.  
  221.        mov     dx,offset badcls ;error while closing file
  222.        mov     ah,9
  223.        int     21H
  224.        jmp     short error
  225.  
  226. ;put a standard ID string into the PSP for RELEASE to check
  227. idstr: mov     si,offset id
  228.        mov     di,60H          ;unused area of the PSP
  229.        mov     cx,idlen        ;characters in ID string
  230.        cld
  231.        rep     movsb           ;copy string
  232.  
  233. ;deallocate environment block of this mark
  234. deall: mov     ax,envseg       ;environment segment
  235.        mov     es,ax           ;  into es
  236.        mov     ah,49H
  237.        int     21H             ;deallocate, no reason for an error to occur
  238.  
  239. ;print message and TSR
  240. gores: mov     dx,offset didit
  241.        mov     ah,9
  242.        int     21H             ;write success message including filename
  243.        mov     dx,offset crlf  ;newline
  244.        mov     ah,9
  245.        int     21H
  246.  
  247.        xor     dx,dx           ;get number of paragraphs to keep
  248.        mov     dl,cmdlen       ;length of command line
  249.        add     dx,0090H        ;rest of PSP plus paragraph margin
  250.        mov     cl,4
  251.        shr     dx,cl           ;convert to paragraphs
  252.        mov     ax,3100H
  253.        int     21H             ;terminate and stay resident
  254.  
  255. ;error output - show syntax line
  256. error: mov     dx,offset syntax
  257.        mov     ah,9
  258.        int     21H
  259.  
  260. ;exit with error
  261.        mov     ax,4C01H
  262.        int     21H
  263.  
  264. fmark  endp
  265.  
  266. emsnm  db      'EMMXXXX0',0    ;file name for testing EMS presence
  267. id     db      'FM2.9 TSR'     ;id string for RELEASE check
  268. idlen  equ     $-id
  269.  
  270. ;messages
  271. badfil db      13,10,'Could not open file for writing',36
  272. nowrit db      13,10,'Error while writing',36
  273. badcls db      13,10,'Error closing table file',36
  274. syntax db      13,10,'Syntax:  FMARK [d:][path]filename'
  275. crlf   db      13,10,36
  276. didit  db      'FMARK 2.9 - Marked current memory position in '
  277.  
  278. ;data storage area
  279. filnm  db      44H dup (36)    ;mark file name
  280. emscnt dw      0               ;holds number of active pages in map that follows
  281. emsmap db      0               ;holds EMS page map if installed
  282.                                ;(note may extend 1K bytes past end of file in memory)
  283.  
  284. Cseg    ends
  285.         end     ComEntry
  286.