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