home *** CD-ROM | disk | FTP | other *** search
/ Multimedia & CD-ROM 3 / mmcd03-jun1995-cd.iso / utils / various / utils-1 / install.asm < prev    next >
Assembly Source File  |  1991-06-24  |  14KB  |  293 lines

  1. ;****************************************************************************
  2. ; INSTALL inserts a bookmark in memory that allows TSRs installed above it
  3. ; to be uninstalled.  Its syntax is
  4. ;
  5. ;       INSTALL [bookmark]
  6. ;
  7. ; where "bookmark" is the name of the bookmark.  This parameter can be
  8. ; passed to REMOVE when a TSR is uninstalled.  Only the first 32 characters
  9. ; of the bookmark name are used.
  10. ;****************************************************************************
  11.  
  12. code            segment
  13.                 assume  cs:code
  14.                 org     100h
  15. begin:          jmp     init
  16.  
  17. nextblock       dw      0FFFFh                  ;Pointer to next block
  18. bookmark        db      "(No Name)",24 dup (0Dh);Bookmark name
  19. signature       db      0,1,2,"INSTALL",2,1,0   ;Program signature
  20. vectors         dw      512 dup (?)             ;Interrupt vectors
  21. prog_id         db      ?                       ;Multiplex ID number
  22. int2Fh          dd      ?                       ;Interrupt 2FH vector
  23.  
  24. ;****************************************************************************
  25. ; MPLEX_INT handles interrupt 2FH.  If, on entry, AH is set to INSTALL's
  26. ; multiplex ID number, MPLEX_INT uses the value in AL as a function code.
  27. ; The functions supported are:
  28. ;
  29. ;    00H    Returns FFH in AL to indicate the program is installed
  30. ;           and returns the address of its signature in ES:DI.
  31. ;****************************************************************************
  32.  
  33. mplex_int       proc    far
  34.                 pushf                           ;Save FLAGS register
  35.                 cmp     ah,cs:[prog_id]         ;Branch if AH holds the
  36.                 je      mplex2                  ;  multiplex ID
  37.                 popf                            ;Restore FLAGS
  38.                 jmp     cs:[int2Fh]             ;Pass the interrupt on
  39. ;
  40. ; Function 00H verifies that the program is installed.
  41. ;               
  42. mplex2:         popf                            ;Restore FLAGS
  43.                 or      al,al                   ;Branch if function code
  44.                 jnz     mplex3                  ;  is other than 00H
  45.                 mov     al,0FFh                 ;Set AL to FFH
  46.                 push    cs                      ;Point ES:DI to the program
  47.                 pop     es                      ;  signature
  48.                 mov     di,offset signature
  49. mplex3:         iret                            ;Return from interrupt
  50. mplex_int       endp
  51.  
  52. ;****************************************************************************
  53. ; Data that will be discarded when the program becomes memory-resident.
  54. ;****************************************************************************
  55.  
  56. helpmsg         db      "Places a bookmark in memory that allows TSRs to "
  57.                 db      "be uninstalled.",13,10,13,10
  58.                 db      "INSTALL [bookmark]",13,10,13,10
  59.                 db      "  bookmark  Name of the bookmark being installed."
  60.                 db      13,10,13,10
  61.                 db      "Once a bookmark is placed, TSRs installed above "
  62.                 db      "it in memory can be",13,10
  63.                 db      "uninstalled with INSTALL's companion program, "
  64.                 db      "REMOVE.",13,10,"$"
  65.  
  66. errmsg1         db      "Requires DOS 3.0 or higher",13,10,"$"
  67. errmsg2         db      "INSTALL cannot be loaded high",13,10,"$"
  68. errmsg3         db      "Program could not be installed",13,10,"$"
  69.  
  70. msg1            db      "Bookmark created.  Use REMOVE to remove it."
  71.                 db      13,10,"$"
  72.  
  73. ;****************************************************************************
  74. ; INIT makes the program resident in memory.
  75. ;****************************************************************************
  76.  
  77.                 assume  cs:code,ds:code
  78.  
  79. init            proc    near
  80.                 cld                             ;Clear direction flag
  81.                 mov     si,81h                  ;Point SI to command line
  82.                 call    scanhelp                ;Scan for "/?" switch
  83.                 jnc     checkver                ;Branch if not found
  84.                 mov     ah,09h                  ;Display help text and exit
  85.                 mov     dx,offset helpmsg       ;  with ERRORLEVEL=0
  86.                 int     21h
  87.                 mov     ax,4C00h
  88.                 int     21h
  89. ;
  90. ; Check the DOS version and make sure the program isn't loaded high.
  91. ;
  92. checkver:       mov     dx,offset errmsg1       ;Exit if DOS version
  93.                 mov     ah,30h                  ;  is less than 3.0
  94.                 int     21h
  95.                 cmp     al,3
  96.                 jae     checkaddr
  97.  
  98. error:          mov     ah,09h                  ;Display error message and
  99.                 int     21h                     ;  exit with ERRORLEVEL=1
  100.                 mov     ax,4C01h
  101.                 int     21h
  102.  
  103. checkaddr:      mov     dx,offset errmsg2       ;Exit if program is loaded
  104.                 mov     ax,cs                   ;  at segment A000H or
  105.                 cmp     ax,0A000h               ;  higher
  106.                 jae     error
  107. ;
  108. ; Parse the command line.
  109. ;
  110.                 call    findchar                ;Advance to first character
  111.                 jc      copy                    ;Branch if no parameters
  112.                 mov     di,offset bookmark      ;Point DI to buffer
  113.                 mov     cx,32                   ;Initialize counter
  114. parse1:         lodsb                           ;Get a character
  115.                 cmp     al,"a"                  ;Capitalize it if it's
  116.                 jb      parse2                  ;  between "a" and "z"
  117.                 cmp     al,"z"
  118.                 ja      parse2
  119.                 and     al,0DFh
  120. parse2:         stosb                           ;Store it
  121.                 cmp     al,0Dh                  ;Branch if was a carriage
  122.                 je      copy                    ;  return
  123.                 loop    parse1                  ;Loop back for more
  124. ;
  125. ; Copy the interrupt vector table from low memory.
  126. ;
  127. copy:           push    ds                      ;Save DS
  128.                 sub     si,si                   ;Point DS:SI to 0000:0000
  129.                 mov     ds,si
  130.                 assume  ds:nothing
  131.                 mov     di,offset vectors       ;Point DI to storage area
  132.                 mov     cx,512                  ;Initialize counter
  133.                 cli                             ;Disable interrupts
  134.                 rep     movsw                   ;Copy the vector table
  135.                 sti                             ;Enable interrupts
  136.                 pop     ds                      ;Restore DS
  137.                 assume  ds:code
  138. ;
  139. ; Install the program.
  140. ;
  141.                 call    check_install           ;Branch if a copy of INSTALL
  142.                 jnc     install_full            ;  is not already installed
  143.  
  144.                 mov     di,offset nextblock     ;Point DI to NEXTBLOCK
  145. install1:       cmp     word ptr es:[di],0FFFFh ;Branch if this is not the
  146.                 jne     install2                ;  last block in the chain
  147.                 mov     word ptr es:[di],cs     ;Record the address of this
  148.                 jmp     short install_part      ;  block if it is
  149. install2:       mov     es,es:[di]              ;Point ES to next block in
  150.                 jmp     install1                ;  the chain and loop back
  151.  
  152. install_full:   call    mplex_id                ;Find a multiplex ID number
  153.                 mov     dx,offset errmsg3       ;Error if none available
  154.                 jc      error
  155.                 mov     prog_id,ah              ;Save the ID number
  156.  
  157.                 mov     ax,352Fh                ;Hook interrupt 2FH
  158.                 int     21h
  159.                 mov     word ptr int2Fh,bx
  160.                 mov     word ptr int2Fh[2],es
  161.                 mov     ax,252Fh
  162.                 mov     dx,offset mplex_int
  163.                 int     21h
  164.  
  165. install_part:   mov     ah,49h                  ;Get the segment address of
  166.                 mov     es,ds:[2Ch]             ;  the environment block
  167.                 int     21h                     ;  and free the segment
  168.  
  169.                 mov     ah,09h                  ;Display message verifying
  170.                 mov     dx,offset msg1          ;  the installation
  171.                 int     21h
  172.  
  173.                 mov     ax,3100h                ;Terminate with function 31H
  174.                 mov     dx,(offset helpmsg - offset code + 15) shr 4
  175.                 int     21h
  176. init            endp
  177.  
  178. ;****************************************************************************
  179. ; FINDCHAR advances SI to the next non-space or non-comma character.
  180. ; On return, carry set indicates EOL was encountered.
  181. ;****************************************************************************
  182.  
  183. findchar        proc    near
  184.                 lodsb                           ;Get the next character
  185.                 cmp     al,20h                  ;Loop if space
  186.                 je      findchar
  187.                 cmp     al,2Ch                  ;Loop if comma
  188.                 je      findchar
  189.                 dec     si                      ;Point SI to the character
  190.                 cmp     al,0Dh                  ;Exit with carry set if end
  191.                 je      eol                     ;  of line is reached
  192.  
  193.                 clc                             ;Clear carry and exit
  194.                 ret
  195.  
  196. eol:            stc                             ;Set carry and exit
  197.                 ret
  198. findchar        endp
  199.  
  200. ;****************************************************************************
  201. ; SCANHELP scans the command line for a /? switch.  If found, carry returns
  202. ; set and SI contains its offset.  If not found, carry returns clear.
  203. ;****************************************************************************
  204.  
  205. scanhelp        proc    near
  206.                 push    si                      ;Save SI
  207. scanloop:       lodsb                           ;Get a character
  208.                 cmp     al,0Dh                  ;Exit if end of line
  209.                 je      scan_exit
  210.                 cmp     al,"?"                  ;Loop if not "?"
  211.                 jne     scanloop
  212.                 cmp     byte ptr [si-2],"/"     ;Loop if not "/"
  213.                 jne     scanloop
  214.  
  215.                 add     sp,2                    ;Clear the stack
  216.                 sub     si,2                    ;Adjust SI
  217.                 stc                             ;Set carry and exit
  218.                 ret
  219.  
  220. scan_exit:      pop     si                      ;Restore SI
  221.                 clc                             ;Clear carry and exit
  222.                 ret
  223. scanhelp        endp
  224.  
  225. ;****************************************************************************
  226. ; CHECK_INSTALL returns carry set if the program is already installed,
  227. ; carry clear if it's not.  If carry returns set, AH holds the program's
  228. ; multiplex ID number.
  229. ;****************************************************************************
  230.  
  231. check_install   proc    near
  232.                 mov     ax,8000h                ;Initialize AH and AL
  233.                 mov     cx,80h                  ;Initialize count
  234.  
  235. chinst1:        push    ax                      ;Save AX and CX
  236.                 push    cx
  237.                 sub     di,di                   ;Set ES and DI to 0
  238.                 mov     es,di
  239.                 int     2Fh                     ;Interrupt 2Fh
  240.                 cmp     al,0FFh                 ;Nothing here if AL isn't
  241.                 jne     chinst2                 ;  equal to FFH
  242.  
  243.                 mov     si,offset signature     ;See if program signature
  244.                 mov     cx,13                   ;  appears at the address
  245.                 repe    cmpsb                   ;  returned in ES:DI
  246.                 jne     chinst2                 ;Branch if it does not
  247.  
  248.                 pop     cx                      ;Clear the stack and exit
  249.                 pop     ax                      ;  with carry set
  250.                 stc
  251.                 ret
  252.  
  253. chinst2:        pop     cx                      ;Retrieve AX and CX
  254.                 pop     ax
  255.                 inc     ah                      ;Next multiplex ID
  256.                 loop    chinst1                 ;Loop until done
  257.  
  258.                 clc                             ;Exit with carry clear
  259.                 ret
  260. check_install   endp
  261.  
  262. ;****************************************************************************
  263. ; MPLEX_ID searches for an unused multiplex ID number.  If one is found,
  264. ; it is returned in AH with carry clear.  Carry set means no multiplex
  265. ; ID numbers are currently available.
  266. ;****************************************************************************
  267.  
  268. mplex_id        proc    near
  269.                 mov     ax,8000h                ;Initialize AH and AL
  270.                 mov     cx,80h                  ;Initialize count
  271.  
  272. mxid1:          push    ax                      ;Save AX and CX
  273.                 push    cx
  274.                 int     2Fh                     ;Interrupt 2Fh
  275.                 or      al,al                   ;Branch if AL=0
  276.                 jz      mxid2
  277.                 pop     cx                      ;Retrieve AX and CX
  278.                 pop     ax
  279.                 inc     ah                      ;Increment ID number
  280.                 loop    mxid1                   ;Loop until done
  281.  
  282.                 stc                             ;Exit with carry set
  283.                 ret
  284.  
  285. mxid2:          pop     cx                      ;Clear the stack and exit
  286.                 pop     ax                      ;  with carry clear
  287.                 clc
  288.                 ret
  289. mplex_id        endp
  290.  
  291. code            ends
  292.                 end     begin
  293.