home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / tsr / tsrsrc33.zip / MARK.ASM < prev    next >
Assembly Source File  |  1992-01-08  |  11KB  |  292 lines

  1. ;==============================================================================
  2. ; MARK.ASM - mark a position in memory,
  3. ;            above which TSRs will later be cleared by RELEASE
  4. ;            MARK can be called multiple times, each RELEASE will clear
  5. ;            above the last MARK called.
  6. ; If MARK is called with something on the command line, that text will
  7. ; be stored in the program segment prefix at offset 80H, where it is
  8. ; later accessible to RELEASE for a "named" release.
  9. ;
  10. ; Syntax:    MARK [/Q] [!][MarkName]
  11. ;==============================================================================
  12. ; written for TASM
  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 1.0  2/8/86
  18. ;     original public release
  19. ;     (thanks to Neil Rubenking for an outline of the method used)
  20. ; :
  21. ; long intervening history
  22. ; :
  23. ; version 3.0  9/24/91
  24. ;   add Quiet option
  25. ;   add code for tracking high memory
  26. ; version 3.1 11/4/91
  27. ;   no change
  28. ; version 3.2 11/22/91
  29. ;   change method of accessing high memory
  30. ;   store parent len as well as parent segment
  31. ; version 3.3 1/8/92
  32. ;   no change
  33. ;==============================================================================
  34.  
  35. Cseg    segment public para
  36.         assume  cs:Cseg, ds:Cseg, es:nothing
  37.         locals  @@
  38.  
  39.         org     81H
  40. cmdlin  label   byte                    ;first character of command line
  41.  
  42.         org     100H
  43. comentry: jmp     doit
  44.  
  45. ;put the following in the MAP file
  46. public idstr,vector,egasav,intcom,emscnt,emsmap
  47.  
  48. idstr   db      'MM3.3 TSR'             ;used to find this TSR
  49. firsthimcb dw   0                       ;segment of first mcb in high mem
  50.  
  51. ;**** the following will be overwritten by the vector table image *************
  52. ;success message and version number
  53. didit  db      'MARK 3.3, Copyright 1991 TurboPower Software',13,10
  54. didit2 db      'Marked current memory position',13,10,36
  55. errst  db      'Invalid command line',13,10,36
  56. ;file name for testing EMS presence
  57. emsnm  db      'EMMXXXX0',0
  58. quiet  db      0
  59. xmsadr  label   dword                           ;XMS control address
  60. xmsxxx  dw      2 dup (0)
  61. ;******************************************************************************
  62.  
  63. vector equ     0120H           ;offset in code seg where vector table is copied
  64. veclen equ     0400H           ;1024 bytes for vectors
  65. egasav equ     vector+veclen
  66. egalen equ     8               ;8 bytes for EGA save area
  67. intcom equ     egasav+egalen
  68. intlen equ     10H             ;16 bytes for interapps communication area
  69. parent equ     intcom+intlen
  70. parlen equ     parent+2        ;parent's PSP length
  71. emscnt equ     parlen+2
  72. emsmap equ     emscnt+2
  73. ;mcbcnt and mcbmap actually follow after used portion of emsmap
  74. mcbcnt equ     emsmap+400H     ;count of allocated mcbs
  75. mcbmap equ     mcbcnt+2        ;array of mcb segments
  76. ;newloc follows after the longest possible emsmap and mcbmap
  77. newloc equ     mcbmap+400H     ;location of relocated code
  78.  
  79. ;*****************************************************************************
  80.  
  81. doit   proc    near
  82.  
  83. ;find first mcb in high memory, if any
  84.         mov     ax,3000h                ;get DOS version
  85.         int     21H
  86.         cmp     al,3
  87.         jb      @@7                     ;no XMS driver possible
  88.         mov     ax,4300h
  89.         int     2Fh                     ;multiplex call for XMS
  90.         cmp     al,80h                  ;proper signature?
  91.         jne     @@7                     ;no XMS driver
  92.         mov     ax,4310h                ;get XMS control address
  93.         int     2Fh
  94.         mov     xmsxxx,bx               ;save it
  95.         mov     xmsxxx[2],es
  96.         mov     ah,10h
  97.         mov     dx,0FFFFh
  98.         call    xmsadr                  ;ask to allocate FFFF paras of UMB
  99.         cmp     bl,0B0h                 ;will fail with B0 if UMBs avail
  100.         je      @@0
  101.         cmp     bl,0B1h                 ;will fail with B1 if UMBs all allocated
  102.         jne     @@7                     ;no UMBs exist
  103. @@0:    int     12H
  104.         mov     cl,6
  105.         shl     ax,cl                   ;get segment of top of memory
  106.  
  107. @@1:    mov     es,ax
  108.         cmp     byte ptr es:[0000h],'M' ;potential mcb?
  109.         jnz     @@6                     ;not an mcb, try next segment
  110. @@2:    mov     cx,ax                   ;save potential start mcb in cx
  111. @@3:    inc     ax
  112.         add     ax,es:[0003h]           ;ax = start of next mcb
  113.         jc      @@5                     ;can't be an mcb if we wrapped
  114.         mov     es,ax                   ;address of next mcb
  115.         mov     dl,es:[0000h]
  116.         cmp     dl,'M'
  117.         jz      @@3                     ;good start mcb
  118.         cmp     dl,'Z'
  119.         jz      @@9                     ;good end mcb
  120. @@5:    mov     ax,cx                   ;restore last start segment
  121. @@6:    cmp     ax,0FFFFh               ;top of memory?
  122.         je      @@7
  123.         inc     ax                      ;try next segment
  124.         jmp     @@1
  125.  
  126. @@7:    xor     cx,cx                   ;no matching UMB
  127. @@9:    mov     firsthimcb,cx           ;store first high mcb
  128.  
  129. ;relocate ourselves out of the way
  130.         push    cs
  131.         pop     es
  132.         mov     di,newloc
  133.         push    di                      ;will act as a return address
  134.         mov     si,offset parse
  135.         mov     cx,lastcode-parse
  136.         cld
  137.         rep     movsb
  138.         ret                             ;"return" to the relocated code
  139.  
  140. ;scan command line for /Q option
  141. parse:  mov     si,offset cmdlin
  142.         cld
  143. get1:   lodsb
  144.         cmp     al,13                   ;end of command line?
  145.         je      pmess
  146.         cmp     al,'/'                  ;option switch?
  147.         je      getop
  148.         cmp     al,'-'
  149.         jne     get1                    ;loop around
  150. getop:  mov     di,si                   ;save option position
  151.         lodsb
  152.         cmp     al,'a'
  153.         jb      noup
  154.         cmp     al,'z'
  155.         ja      noup
  156.         and     al,0DFH                 ;uppercase
  157. noup:   cmp     al,'Q'
  158.         jne     error
  159.         mov     quiet,1                 ;set quiet flag
  160.         dec     di
  161.         mov     al,' '
  162.         stosb                           ;clear option
  163.         stosb
  164.         jmp     get1                    ;loop around
  165.  
  166. error:  mov     dx,offset errst
  167.         mov     ah,9
  168.         int     21H
  169.         mov     ax,4C01H
  170.         int     21H
  171.  
  172. ;print message if not quiet
  173. pmess:  cmp     quiet,0
  174.         jnz     chkems
  175.         mov     dx,offset didit
  176.         mov     ah,9
  177.         int     21H                     ;write success message
  178.  
  179. ;determine whether EMS is present
  180. chkems: mov     dx,offset emsnm
  181.         mov     ax,3D00H
  182.         int     21H
  183.         jnc     emspres                 ;EMS driver installed
  184.         xor     bx,bx
  185.         jmp     short stocnt
  186.  
  187. ;EMS present, close the open handle first
  188. emspres:
  189.         mov     bx,ax
  190.         mov     ah,3EH
  191.         int     21H
  192.  
  193. ;store the EMS page map
  194.         mov     ah,4DH
  195.         mov     di,emsmap
  196.         xor     bx,bx                   ;required by some versions of EMM
  197.         cld                             ;required by some versions of EMM
  198.         int     67H
  199.  
  200. ;store the number of active EMS handles
  201. stocnt:
  202.         mov     ds:[emscnt],bx          ;count of active handles
  203.  
  204. ;store the interrupt vector table (overwrites initial messages)
  205.         xor     ax,ax
  206.         mov     ds,ax                   ;source address segment 0
  207.         assume  ds:nothing
  208.         xor     si,si                   ;offset 0
  209.         mov     di,vector               ;destination offset, es=cs already
  210.         mov     cx,veclen shr 1         ;count of words to store
  211.         rep     movsw                   ;copy vectors to our table
  212.  
  213. ;store the EGA save area
  214.         mov     ax,40H
  215.         mov     ds,ax                   ;point to BIOS data area
  216.         mov     si,00A8H                ;EGA save area pointer
  217.         mov     di,egasav
  218.         mov     cx,egalen shr 1
  219.         rep     movsw                   ;copy information to our save area
  220.  
  221. ;store the interapplications communication area
  222.         mov     si,00F0H                ;interapps communication area address
  223.         mov     di,intcom
  224.         mov     cx,intlen shr 1
  225.         rep     movsw                   ;copy information to our save area
  226.  
  227. ;store the parent's PSP segment
  228.         push    cs
  229.         pop     ds                      ;ds = cs
  230.         assume  ds:cseg
  231.         mov     ax,ds:[16h]             ;get parent's PSP from our PSP
  232.         mov     ds:[parent],ax          ;store in data save area
  233.         dec     ax
  234.         mov     es,ax
  235.         mov     ax,es:[0003h]           ;get length of parent's psp
  236.         mov     ds:[parlen],ax          ;store in data save area
  237.  
  238. ;store the mcb chain
  239.         mov     ah,52H                  ;get first mcb segment
  240.         int     21H
  241.         mov     ax,es:[bx-2]            ;ax=first mcb
  242.         push    cs
  243.         pop     es                      ;es=cs
  244.  
  245.         mov     di,cs:[emscnt]          ;get starting address of mcbmap
  246.         shl     di,1
  247.         shl     di,1
  248.         add     di,emsmap
  249.         mov     si,di                   ;cs:[si] -> mcbcnt
  250.         add     di,2                    ;cs:[di] -> mcbmap
  251.         xor     cx,cx                   ;cx will count mcbs
  252.         cld
  253.         push    ds
  254.         assume  ds:nothing
  255.  
  256. mcbnext:
  257.         stosw                           ;store mcb segment held by ax
  258.         mov     ds,ax                   ;ds:[0] points to mcb
  259.         mov     ax,ds:[1]               ;get mcb owner
  260.         stosw                           ;store it
  261.         inc     cx                      ;increment count
  262.         cmp     byte ptr ds:[0],'Z'     ;end of mcb chain?
  263.         je      mcbdone
  264.         mov     ax,ds                   ;restore ax to mcb segment
  265.         inc     ax                      ;skip over mcb itself
  266.         add     ax,ds:[3]               ;add length of memory block
  267.         jmp     mcbnext
  268.  
  269. mcbdone:mov     ax,firsthimcb           ;check for high memory
  270.         or      ax,ax
  271.         jz      mcbend
  272.         mov     firsthimcb,0            ;only do it once
  273.         jmp      mcbnext
  274.  
  275. mcbend: pop     ds
  276.         assume  ds:cseg
  277.  
  278. ;terminate and stay resident
  279. gores:  mov     [si],cx                 ;store mcbcnt
  280.         mov     dx,di                   ;dx = past last used mcb segment
  281.         add     dx,000FH                ;add paragraph roundup
  282.         mov     cl,4
  283.         shr     dx,cl                   ;convert to paragraphs
  284.         mov     ax,3100H
  285.         int     21H                     ;terminate but stay resident
  286.  
  287. lastcode:
  288. doit    endp
  289.  
  290. Cseg    ends
  291.         end     ComEntry
  292.