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