home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / util / misc / 028 / 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