home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / memres41.zip / RESDEL.ASM < prev    next >
Assembly Source File  |  1988-07-24  |  27KB  |  598 lines

  1. ; Ed Jordan 201 Smallacombe Drive, Scranton, Pa. 18508
  2. ; program in the public domain
  3. ; version 1 - December 1986
  4. ;           - improved segment addressing Jan 1987
  5. ;        1.1- correct error for passing dos environment string March 1987
  6. ;        2.0  command line switch to replace entire vector table
  7. ;        2.1  support for non-contiguous env blocks
  8. ;        2.1a fixed bug - correct for code address in vector table (Mar 88)
  9. ;        2.1b fixed bug again - exe and com files have different code segments
  10. ;        3.0  enhancements - help , switch for removal of more than one utility
  11. ;             April 1988
  12. ;        4.0  fixed bug in vector routine - replaces earlier versions May 1988
  13. ; version 4.1 Rewrite of method of detecting memory blocks
  14.  
  15. po                equ             39
  16. cr                equ             13
  17. lf                equ             10
  18. el                equ             '$'
  19. eof               equ             1ah
  20. esc               equ             1bh
  21. stdin             equ             0
  22. stdout            equ             1
  23. stderr            equ             2
  24. stdaux            equ             3
  25. stdprn            equ             4
  26. envsize           equ             800h              ; max size environment
  27.  
  28. stackseg          segment stack para 'stack'
  29.                   db              40 dup('stack')
  30. stackseg          ends
  31.  
  32. dataseg           segment         public para    'data'
  33. mesg1             db              cr,lf,'Deleting ',el
  34. mesg2             db              ' memory resident programs ...',cr,lf,el
  35. mesg2a            db              ' memory resident program ...',cr,lf,el
  36. mesg3             db              'A:\VECTOR.TBL',0
  37.                   db              20 dup ('PATCH ')
  38.                   db              'END PATCH AREA'
  39. mesg4             db              'Replacing entire vector table ...',cr,lf,el
  40. mesg5             db              'RESDEL.EXE - version 4.1',cr,lf
  41.                   db              'by Ed Jordan July 1988',cr,lf,el
  42. mesg6             db              'RESDEL \n<cr> (n= 1 to 9)',cr,lf
  43.                   db              'RESDEL \R<cr> (delete all)',cr,lf,el
  44. mesg7             db              cr,lf,el
  45. mesg8             db              'Vector(s) ',el
  46. mesg9             db              '- ',el
  47. mesg10            db              '- Not Applicable',cr,lf,el
  48. mesg11            db              8,' ',8,el
  49. error1            db              ' not found.',cr,lf,el
  50. error2            db              'Insufficient memory.',cr,lf,el
  51. error3            db              'Error freeing allocated memory block.',cr,lf,el
  52. error4            db              'Please do not try to delete DOS.',cr,lf,el
  53. error5            db              'Unrecognized command.',el
  54. error6            db              '(Warning: Vector not located) ',el
  55. error7            db              cr,lf,'Warning: SHARE.EXE installed'
  56.                   db              cr,lf,'Do you want to proceed? (Y/N) ',el
  57. handle            dw              ?
  58. default_tbl       dw              0
  59. dos_seg           dw              ?
  60. nxt_env           dw              ?
  61. psp               dw              ?
  62. last_psp          dw              ?
  63. last_env          dw              ?
  64. flag              db              ?
  65. tr_tbl            db              '0123456789ABCDEF'
  66.  
  67. blocks            dw              128 dup (0)
  68.  
  69. dataseg           ends
  70.  
  71. codeseg           segment public para 'code'
  72.                   assume cs:codeseg,ds:dataseg,es:nothing,ss:stackseg
  73.  
  74. memret            proc            far
  75.                   mov             ax,dataseg
  76.                   mov             ds,ax
  77.                   push            es
  78.                   pop             ax
  79.                   mov             psp,ax
  80.                   mov             si,16h
  81.                   mov ax,word ptr es:[si]           ; parent seg
  82.                   mov             dos_seg,ax
  83.                   call            chk_share
  84.                   jb              ret2              ; exit
  85.                   call            read_chain
  86.                   call            load_default_tbl
  87.                   jb              ret2
  88.                   call            chk_cmd_line
  89.                   jb              ret2
  90.                   lea             dx,mesg1          ; delete
  91.                   call            print
  92.                   mov             dl,cl             ; number
  93.                   xor             dl,30h
  94.                   mov             ah,2              ; print number
  95.                   int             21h
  96.                   cmp             dl,31h            ; number 1 ?
  97.                   jnz             ret6
  98.                   lea             dx,mesg2a
  99.                   jmp short       ret7
  100. ret6:             lea             dx,mesg2          ; programs message
  101. ret7:             call            print
  102.                   jmp short       ret4
  103. ret1:             mov             ax,es
  104.                   mov             psp,ax
  105. ret4:             call            find_psp          ; look backwards
  106.                   jb              ret3
  107.                   call            fix_tbl           ; es = last_psp
  108.                   jb              ret4
  109.                   call            free_mem          ; free last psp
  110.                   jb              ret2
  111.                   call            find_env          ; find env of psp
  112. ret5:             loop            ret1              ; cx has count
  113.                   jmp short       ret2
  114. ret3:             lea             dx,error4         ; error message
  115.                   call            print
  116. ret2:             mov             ax,default_tbl
  117.                   or              ax,ax
  118.                   jz              ret8
  119.                   mov             es,ax
  120.                   call            free_mem
  121. ret8:             call            exit
  122. memret            endp
  123.  
  124. chk_share         proc            near
  125.                   mov             ah,30h
  126.                   int             21h               ; dos version
  127.                   cmp             al,3              ; version 3 ?
  128.                   jb              cs6
  129.                   mov             ax,1000h          ; get installed state
  130.                   int             2fh               ; multiplex interrupt
  131.                   cmp             al,0ffh           ; installed ?
  132.                   jz              cs4
  133. cs6:              clc
  134.                   jmp             cs5
  135. cs4:              lea             dx,error7         ; error message
  136.                   call            print
  137. cs3:              call            get_response
  138.                   cmp             al,'Y'
  139.                   jz              cs1
  140.                   cmp             al,'N'
  141.                   jz              cs2
  142.                   lea             dx,mesg11         ; erase response
  143.                   call            print
  144.                   jmp             cs3               ; try again
  145. cs2:              stc                               ; flag to skip
  146. cs1:              lea             dx,mesg7          ; cr lf
  147.                   call            print
  148. cs5:              ret
  149. chk_share         endp
  150.  
  151. chk_cmd_line      proc            near
  152.                   lea             dx,mesg5          ; title message
  153.                   call            print
  154.                   mov             ax,psp
  155.                   mov             es,ax
  156.                   mov             si,80h            ; offset of cmd line
  157.                   mov             al,byte ptr es:[si]
  158.                   or              al,al
  159.                   jnz             ccl4
  160.                   jmp             ccl5
  161. ccl8:             lea             dx,error5
  162.                   call            print
  163. ccl5:             lea             dx,mesg6          ; help message
  164.                   call            print
  165.                   jmp             ccl7              ; no command line switch
  166. ccl4:             mov             di,si
  167.                   inc             di                ; start of cmd line
  168.                   xor             cx,cx
  169.                   mov             cl,al
  170.                   mov             al,'\'            ; switch on cmd line
  171.                   repne scasb
  172.                   jcxz            ccl5              ; no switch found
  173.                   mov             al,byte ptr es:[di]
  174.                   call            capital
  175.                   cmp             al,'R'
  176.                   jz              ccl6
  177.                   cmp             al,'0'
  178.                   jb              ccl8
  179.                   cmp             al,'9'
  180.                   jg              ccl8
  181.                   xor             al,30h            ; make binary digit
  182.                   jz              ccl7
  183.                   xor             cx,cx             ; in cx
  184.                   mov             cl,al
  185.                   jmp             ccl1
  186. ccl6:             lea             dx,mesg4          ; replace whole table
  187.                   call            print
  188.                   push            es
  189.                   push            ds
  190.                   xor             ax,ax
  191.                   xor             si,si
  192.                   xor             di,di
  193.                   mov             es,ax
  194.                   mov             ax,default_tbl    ; copy default table
  195.                   mov             ds,ax             ; into vector table
  196.                   mov             cx,400h
  197.                   cli                               ; hold interrupts
  198.                   rep movsb                         ; ds:si to es:di
  199.                   sti                               ; enable interrupts
  200.                   pop             ds
  201.                   pop             es
  202.                   mov             ax,default_tbl    ; free memory for
  203.                   mov             es,ax             ; the default table
  204.                   call            free_mem
  205. ccl3:             call            find_psp          ; find previous psp
  206.                   jb              ccl7
  207.                   call            free_mem          ; free block
  208.                   jb              ccl1
  209.                   call            find_env          ; free env block
  210.                   jmp             ccl3
  211. ccl7:             stc                               ; set carry flag
  212. ccl1:             ret
  213. chk_cmd_line      endp
  214.  
  215. capital           proc            near
  216.                   cmp             al,'a'
  217.                   jb              cap1
  218.                   cmp             al,'z'
  219.                   jg              cap1
  220.                   xor             al,20h
  221. cap1:             ret
  222. capital           endp
  223.  
  224. free_mem          proc            near
  225.                   mov             ah,49h            ; es= block
  226.                   int             21h
  227.                   jnb             fm1
  228.                   lea             dx,error3         ; if carry set
  229.                   call            print             ; print error message
  230.                   stc
  231. fm1:              ret
  232. free_mem          endp
  233.  
  234. fix_tbl           proc            near
  235.                   db              0cch
  236.                   cld
  237.                   push            bp
  238.                   push            es
  239.                   push            ds
  240.                   push            cx
  241.                   lea             dx,mesg8          ; vector message
  242.                   call            print
  243.                   mov             dx,ds             ; save ds in dx
  244.                   mov             flag,'N'          ; no vector default
  245.                   xor             ax,ax
  246.                   mov             es,ax             ; start of vector tbl
  247.                   xor             si,si
  248.                   mov             cx,400h           ; max size of table
  249.                   mov             bp,last_psp       ; segment of earlier psp
  250.                   mov             bx,default_tbl    ; set ds to default table
  251.                   mov             di,psp            ; vector must be between
  252.                   push            es                ; last_psp and psp
  253.                   pop             ds                ; ds = es = 0
  254. ft1:              cmp             si,cx
  255.                   jnb             ft2
  256.                   lodsw
  257.                   lodsw                             ; segment
  258.                   cmp             ax,bp             ; compare with last_psp
  259.                   jb              ft1               ; must be = or higher
  260.                   cmp             ax,di             ; psp of current program
  261.                   jnb             ft1               ; must be lower
  262.                   call            replace
  263.                   call            print_num
  264.                   mov             ds,dx
  265.                   mov             flag,'Y'          ; vector located
  266.                   xor             ax,ax
  267.                   mov             ds,ax
  268.                   jmp             ft1
  269. ft2:              mov             ds,dx
  270.                   cmp             flag,'Y'
  271.                   jz              ft3
  272.                   lea             dx,error6         ; vector not found message
  273.                   call            print
  274.                   clc
  275. ft3:              pop             cx
  276.                   pop             ds
  277.                   pop             es
  278.                   pop             bp
  279.                   ret
  280. fix_tbl           endp
  281.  
  282. replace           proc            near
  283.                   push            di
  284.                   push            si
  285.                   push            ds
  286.                   dec             si
  287.                   dec             si
  288.                   dec             si
  289.                   dec             si
  290.                   mov             di,si
  291.                   mov             ds,bx             ; table segment
  292.                   movsw
  293.                   movsw                             ; copy over 2 words
  294.                   pop             ds
  295.                   pop             si
  296.                   pop             di
  297.                   ret
  298. replace           endp
  299.  
  300. print_num         proc            near
  301.                   push            ax
  302.                   push            bx
  303.                   push            cx
  304.                   push            ds
  305.                   push            si
  306.                   mov             ds,dx             ; data seg
  307.                   dec             si                ; adj to start of
  308.                   dec             si                ; vector
  309.                   dec             si
  310.                   dec             si
  311.                   mov             ax,si             ; offset of vector
  312.                   shr             ax,1
  313.                   shr             ax,1              ; divide by 4
  314.                   mov             ah,al
  315.                   xchg            ah,al
  316.                   mov             cl,4
  317.                   shr             al,cl
  318.                   mov             bx,offset tr_tbl
  319.                   xlat            tr_tbl
  320.                   call            print_al
  321.                   mov             al,ah
  322.                   and             al,0fh            ; mask off high nibble
  323.                   xlat            tr_tbl
  324.                   call            print_al
  325.                   mov             al,' '
  326.                   call            print_al
  327.                   pop             si
  328.                   pop             ds
  329.                   pop             cx
  330.                   pop             bx
  331.                   pop             ax
  332.                   ret
  333. print_num         endp
  334.  
  335. print_al          proc            near
  336.                   push            ax
  337.                   push            dx
  338.                   mov             dl,al
  339.                   mov             ah,2
  340.                   int             21h
  341.                   pop             dx
  342.                   pop             ax
  343.                   ret
  344. print_al          endp
  345.  
  346. find_psp          proc            near
  347.                   mov             si,bp             ; end of block chain
  348.                   lea             dx,blocks         ; beginning of chain
  349.                   std                               ; reverse
  350. fp1:              cmp             si,dx
  351.                   jb              fp2               ; end of loop
  352.                   lodsw
  353.                   mov             bx,ax
  354.                   lodsw
  355.                   cmp             ax,bx
  356.                   jnz             fp1
  357.                   mov             bp,si             ; update
  358.                   mov             last_psp,ax       ; save new psp
  359.                   mov             es,ax
  360.                   jmp short       fp3
  361. fp2:              stc
  362. fp3:              cld                               ; foreward
  363.                   ret
  364. find_psp          endp
  365.  
  366. load_default_tbl  proc            near
  367.                   lea             dx,mesg3
  368.                   call            open_file
  369.                   jnb             ldt1
  370.                   cld                               ; foreward
  371.                   push            es
  372.                   push            ds
  373.                   pop             es
  374.                   mov             di,dx             ; path name
  375.                   xor             al,al             ; look for 0 at end
  376.                   mov             cx,128            ; of path
  377.                   repne scasb
  378.                   std                               ; reverse direction
  379.                   dec             di
  380.                   mov byte ptr es:[di],el
  381.                   mov             si,di
  382. ldt7:             lodsb
  383.                   cmp             al,'\'
  384.                   jz              ldt6
  385.                   cmp             al,':'
  386.                   jnz             ldt7
  387. ldt6:             inc             si
  388.                   inc             si
  389.                   cld                               ; foreward again
  390.                   pop             es
  391.                   mov             dx,si
  392.                   call            print
  393.                   lea             dx,error1
  394. ltd4:             call            print
  395.                   stc
  396.                   jmp             ldt2
  397. ldt1:             mov             handle,ax
  398.                   mov             bx,200h
  399.                   call            set_memory
  400.                   jnb             ldt3
  401. ldt5:             lea             dx,error2
  402.                   jmp             ltd4
  403. ldt3:             mov             bx,40h            ;paragraphs to request
  404.                   call            req_memory
  405.                   jb              ldt5
  406.                   mov             default_tbl,ax
  407.                   mov             bx,handle
  408.                   mov             cx,400h           ;size of table
  409.                   push            ds
  410.                   mov             ds,ax
  411.                   call            read_file
  412.                   pop             ds
  413.                   jb              ldt2
  414.                   mov             bx,handle
  415.                   call            close_file
  416. ldt2:             ret
  417. load_default_tbl  endp
  418.  
  419. close_file        proc            near
  420.                   mov             ah,3eh
  421.                   int             21h               ; bx= handle
  422.                   ret
  423. close_file        endp
  424.  
  425. read_file         proc            near
  426.                   xor             dx,dx             ; ds:dx = buffer
  427.                   mov             ah,3fh            ; cx= bytes
  428.                   int             21h               ; bx= handle
  429.                   ret
  430. read_file         endp
  431.  
  432. req_memory        proc            near
  433.                   mov             ah,48h            ; bx= paragraphs requested
  434.                   int             21h
  435.                   ret
  436. req_memory        endp
  437.  
  438. set_memory        proc            near
  439.                   mov             ah,4ah            ; es= psp
  440.                   int             21h               ; bx= paragraphs
  441.                   ret
  442. set_memory        endp
  443.  
  444. open_file         proc            near
  445.                   mov             ah,3dh            ; ds:dx= asciiz
  446.                   xor             al,al             ; read only
  447.                   int             21h
  448.                   ret
  449. open_file         endp
  450.  
  451. print             proc            near
  452.                   push            ax
  453.                   mov             ah,9              ; dos print message
  454.                   int             21h               ; function
  455.                   pop             ax                ; ds:dx = message
  456.                   ret
  457. print             endp
  458.  
  459. find_env          proc            near
  460.                   db              0cch
  461.                   push            es
  462.                   push            cx
  463.                   mov             flag,'N'
  464.                   mov             bx,es             ; save psp address
  465.                   cld                               ; foreward
  466.                   push            ds
  467.                   pop             es
  468.                   lea             di,blocks         ; start
  469.                   mov             dx,di             ; at top
  470.                   xor             ax,ax             ; of the chain
  471.                   mov             cx,128
  472.                   repne scasw
  473.                   dec             di
  474.                   dec             di
  475.                   dec             di
  476.                   dec             di
  477.                   mov             si,di
  478.                   std                               ; reverse
  479. fe3:              cmp             si,dx
  480.                   jb              fe2
  481.                   lodsw
  482.                   mov             nxt_env,ax
  483.                   lodsw
  484.                   cmp             nxt_env,ax
  485.                   jz              fe3
  486.                   cmp             ax,bx             ; psp match ?
  487.                   jnz             fe3
  488.                   cmp             ax,psp            ; must not = psp
  489.                   jz              fe3
  490.                   mov             flag,'Y'          ; found block
  491.                   mov             ax,nxt_env
  492.                   mov             last_env,ax
  493.                   mov             es,ax
  494.                   call            free_mem
  495.                   jb              fe4               ; exit error
  496.                   jmp             fe3
  497. fe2:              cmp             flag,'N'
  498.                   jz              fe5
  499.                   mov             ax,last_env       ; equal to last
  500.                   cld                               ; foreward
  501.                   mov             es,ax             ; es = env
  502.                   xor             di,di
  503.                   xor             al,al
  504.                   mov             cx,16 * envsize
  505. fe8:              repne scasb
  506.                   cmp byte ptr es:[di],0            ; two zeros ?
  507.                   jnz             fe8
  508.                   inc             di
  509.                   repne scasb                       ; look for one more 0
  510.                   repne scasb                       ; point to end of name
  511.                   dec             di
  512.                   mov byte ptr es:[di],el
  513.                   std                               ; set direction flag
  514.                   mov             si,di
  515.                   dec             si
  516.                   lea             dx,mesg9          ; cr lf message
  517.                   call            print
  518.                   push            ds
  519.                   push            es
  520.                   pop             ds
  521. fe7:              lodsb
  522.                   cmp             al,'\'            ; point to name minus
  523.                   jz              fe6               ; the path and drive
  524.                   cmp             al,':'
  525.                   jnz             fe7
  526. fe6:              inc             si
  527.                   inc             si
  528.                   mov             dx,si
  529.                   call            print
  530.                   pop             ds
  531.                   lea             dx,mesg7
  532.                   call            print
  533.                   jmp short       fe4
  534. fe5:              lea             dx,mesg10
  535.                   call            print
  536. fe4:              pop             cx
  537.                   pop             es
  538.                   cld                               ; clear direction flag
  539.                   ret
  540. find_env          endp
  541.  
  542. get_response      proc            near
  543.                   mov             ah,1
  544.                   int             21h
  545.                   call            capital
  546.                   ret
  547. get_response      endp
  548.  
  549. read_chain        proc            near
  550.                   db              0cch
  551.                   cld
  552.                   push            es
  553.                   push            ds
  554.                   mov             bx,dos_seg
  555.                   lea             di,blocks
  556.                   push            ds
  557.                   pop             es
  558.                   mov             ax,bx
  559.                   dec             ax                ; point to memory ctl blk
  560. rc3:              xor             si,si
  561.                   mov             ds,ax             ; 1st mem block
  562.                   lodsb                             ; M or Z
  563.                   cmp             al,'Z'            ; end of chain
  564.                   jz              rc1
  565.                   lodsw                             ; get segment address
  566.                   cmp             ax,bx             ; = dos seg ?
  567.                   jz              rc2
  568.                   or              ax,ax             ; 0 ?
  569.                   jz              rc2
  570.                   stosw                             ; save psp address
  571.                   mov             ax,ds
  572.                   inc             ax
  573.                   stosw                             ; save block address
  574. rc2:              lodsw                             ; get size of block
  575.                   mov             dx,ds
  576.                   inc             dx
  577.                   add             ax,dx
  578.                   jmp             rc3
  579. rc1:              pop             ds
  580.                   pop             es                ; program
  581.                   dec             di
  582.                   dec             di
  583.                   mov             bp,di
  584.                   ret
  585. read_chain        endp
  586.  
  587. exit              proc            near
  588.                   jb              e1
  589.                   xor             al,al
  590.                   jmp short       e2
  591. e1:               mov             al,1              ; if carry set exit
  592. e2:               mov             ah,4ch            ; with code 1
  593.                   int             21h
  594. exit              endp
  595.  
  596. codeseg           ends
  597.                   end
  598.