home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / SYSUTL / TSRSRC31.ZIP / MARK.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-11-04  |  8.4 KB  |  236 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. ;==============================================================================
  29.  
  30. Cseg      segment public para
  31.           assume  cs:Cseg, ds:Cseg, es:nothing
  32.  
  33.           org     81H
  34. cmdlin    label   byte               ;first character of command line
  35.  
  36.           org     100H
  37. comentry: jmp     doit
  38.  
  39. ;put the following in the MAP file
  40. public idstr,vector,egasav,intcom,emscnt,emsmap
  41.  
  42. idstr  db      'M3.1 PARAMETER BLOCK FOLLOWS' ;used to find this TSR
  43.  
  44. ;**** the following will be overwritten by the vector table image *************
  45. ;success message and version number
  46. didit  db      'MARK 3.1, Copyright 1991 TurboPower Software',13,10
  47. didit2 db      'Marked current memory position',13,10,36
  48. errst  db      'Invalid command line',13,10,36
  49. ;file name for testing EMS presence
  50. emsnm  db      'EMMXXXX0',0
  51. quiet  db      0
  52. ;******************************************************************************
  53.  
  54. vector equ     0120H           ;offset in code seg where vector table is copied
  55. veclen equ     0400H           ;1024 bytes for vectors
  56. egasav equ     vector+veclen
  57. egalen equ     8               ;8 bytes for EGA save area
  58. intcom equ     egasav+egalen
  59. intlen equ     10H             ;16 bytes for interapps communication area
  60. parent equ     intcom+intlen
  61. parlen equ     2               ;2 bytes for parent's PSP
  62. emscnt equ     parent+parlen
  63. emsmap equ     emscnt+2
  64. ;mcbcnt and mcbmap actually follow after used portion of emsmap
  65. mcbcnt equ     emsmap+400H     ;count of allocated mcbs
  66. mcbmap equ     mcbcnt+2        ;array of mcb segments
  67. ;newloc follows after the longest possible emsmap and mcbmap
  68. newloc equ     mcbmap+400H     ;location of relocated code
  69.  
  70. ;*****************************************************************************
  71.  
  72. doit   proc    near
  73.  
  74. ;relocate ourselves out of the way
  75.        mov     di,newloc
  76.        push    di                       ;will act as a return address
  77.        mov     si,offset parse
  78.        mov     cx,lastcode-parse
  79.        cld
  80.        rep     movsb
  81.        ret                              ;"return" to the relocated code
  82.  
  83. ;scan command line for /Q option
  84. parse: mov     si,offset cmdlin
  85.        cld
  86. get1:  lodsb
  87.        cmp     al,13                    ;end of command line?
  88.        je      pmess
  89.        cmp     al,'/'                   ;option switch?
  90.        je      getop
  91.        cmp     al,'-'
  92.        jne     get1                     ;loop around
  93. getop: mov     di,si                    ;save option position
  94.        lodsb
  95.        cmp     al,'a'
  96.        jb      noup
  97.        cmp     al,'z'
  98.        ja      noup
  99.        and     al,0DFH                  ;uppercase
  100. noup:  cmp     al,'Q'
  101.        jne     error
  102.        mov     quiet,1                  ;set quiet flag
  103.        dec     di
  104.        mov     al,' '
  105.        stosb                            ;clear option
  106.        stosb
  107.        jmp     get1                     ;loop around
  108.  
  109. error: mov     dx,offset errst
  110.        mov     ah,9
  111.        int     21H
  112.        mov     ax,4C01H
  113.        int     21H
  114.  
  115. ;print message if not quiet
  116. pmess: cmp     quiet,0
  117.        jnz     chkems
  118.        mov     dx,offset didit
  119.        mov     ah,9
  120.        int     21H                      ;write success message
  121.  
  122. ;determine whether EMS is present
  123. chkems:mov     dx,offset emsnm
  124.        mov     ax,3D00H
  125.        int     21H
  126.        jnc     emspres                  ;EMS driver installed
  127.        xor     bx,bx
  128.        jmp     short stocnt
  129.  
  130. ;EMS present, close the open handle first
  131. emspres:
  132.        mov     bx,ax
  133.        mov     ah,3EH
  134.        int     21H
  135.  
  136. ;store the EMS page map
  137.        mov     ah,4DH
  138.        mov     di,emsmap
  139.        xor     bx,bx                    ;required by some versions of EMM
  140.        cld                              ;required by some versions of EMM
  141.        int     67H
  142.  
  143. ;store the number of active EMS handles
  144. stocnt:
  145.        mov     ds:[emscnt],bx           ;count of active handles
  146.  
  147. ;store the interrupt vector table (overwrites initial messages)
  148.        xor     ax,ax
  149.        mov     ds,ax                    ;source address segment 0
  150.        assume  ds:nothing
  151.        xor     si,si                    ;offset 0
  152.        mov     di,vector                ;destination offset, es=cs already
  153.        mov     cx,veclen shr 1          ;count of words to store
  154.        rep     movsw                    ;copy vectors to our table
  155.  
  156. ;store the EGA save area
  157.        mov     ax,40H
  158.        mov     ds,ax                    ;point to BIOS data area
  159.        mov     si,00A8H                 ;EGA save area pointer
  160.        mov     di,egasav
  161.        mov     cx,egalen shr 1
  162.        rep     movsw                    ;copy information to our save area
  163.  
  164. ;store the interapplications communication area
  165.        mov     si,00F0H                 ;interapps communication area address
  166.        mov     di,intcom
  167.        mov     cx,intlen shr 1
  168.        rep     movsw                    ;copy information to our save area
  169.  
  170. ;store the parent's PSP segment
  171.        mov     ax,cs                    ;CS = PSP
  172.        mov     ds,ax                    ;now DS = PSP
  173.        mov     ax,ds:[16h]              ;get parent's PSP from our PSP
  174.        mov     ds:[parent],ax           ;store in data save area
  175.  
  176. ;store the mcb chain
  177.        mov     ax,5802H
  178.        int     21H                      ;get UMB link status
  179.        jnc     linkok
  180.        mov     al,0
  181. linkok:xor     ah,ah
  182.        push    ax                       ;save link status
  183.        mov     ax,5803H
  184.        mov     bx,1                     ;open up high memory
  185.        int     21H
  186.  
  187.        mov     ah,52H                   ;get first mcb segment
  188.        int     21H
  189.        mov     ax,es:[bx-2]             ;ax=first mcb
  190.        push    cs
  191.        pop     es                       ;es=cs
  192.  
  193.        mov     di,cs:[emscnt]           ;get starting address of mcbmap
  194.        shl     di,1
  195.        shl     di,1
  196.        add     di,emsmap
  197.        mov     si,di                    ;cs:[si] -> mcbcnt
  198.        add     di,2                     ;cs:[di] -> mcbmap
  199.        xor     cx,cx                    ;cx will count mcbs
  200.        cld
  201.        push    ds
  202.  
  203. mcbnext:
  204.        stosw                            ;store mcb segment held by ax
  205.        mov     ds,ax                    ;ds:[0] points to mcb
  206.        mov     ax,ds:[1]                ;get mcb owner
  207.        stosw                            ;store it
  208.        inc     cx                       ;increment count
  209.        cmp     byte ptr ds:[0],'Z'      ;end of mcb chain?
  210.        je      mcbdone
  211.        mov     ax,ds                    ;restore ax to mcb segment
  212.        inc     ax                       ;skip over mcb itself
  213.        add     ax,ds:[3]                ;add length of memory block
  214.        jmp     mcbnext
  215.  
  216. mcbdone:
  217.        pop     ds
  218.        mov     ax,5803H
  219.        pop     bx                       ;restore high memory link
  220.        int     21H
  221.  
  222. ;terminate and stay resident
  223. gores: mov     [si],cx                  ;store mcbcnt
  224.        mov     dx,di                    ;dx = past last used mcb segment
  225.        add     dx,000FH                 ;add paragraph roundup
  226.        mov     cl,4
  227.        shr     dx,cl                    ;convert to paragraphs
  228.        mov     ax,3100H
  229.        int     21H                      ;terminate but stay resident
  230.  
  231. lastcode:
  232. doit    endp
  233.  
  234. Cseg    ends
  235.         end     ComEntry
  236.