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