home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / MIRFIX.ZIP / MIRFIX.ASM next >
Encoding:
Assembly Source File  |  1991-09-16  |  5.5 KB  |  176 lines

  1. page,128
  2. ;----------------------------------------------------------------------
  3. ;
  4. ; MIRFIX.ASM
  5. ;
  6. ; fixes a bug in MIRROR.COM
  7. ;
  8. ; compile:      MASM mirfix;
  9. ;               LINK mirfix;
  10. ;               EXE2BIN mirfix.exe mirfix.com
  11. ;               DEL mirfix.exe
  12. ;
  13. ; explanation:  MIRROR traps INT 21h to enable delete tracking.
  14. ;               When deleting a file with zero length, INT 21h returns
  15. ;               with interrupts clear. At times this may cause programs
  16. ;               to hang since no keyboard, timer, mouse, or any other
  17. ;               hardware interrupts can be processed with CLI.
  18. ;
  19. ; how it works: MIRFIX traps INT 21h. This interrupt trap works as follows:
  20. ;
  21. ;               Get the pushed flags (INT command works like PUSHF, CALL FAR)
  22. ;               Mask out the interrupt flag value and save it
  23. ;               Call the original interrupt
  24. ;               Merge the caller's interrupt flag to the flags register
  25. ;               Return from INT 21h
  26. ;
  27. ;               The fix procedure is written totally reentrant since we
  28. ;               do not use local variables during the call to original
  29. ;               INT 21h. (DOS or any other TSR could call INT 21h
  30. ;               recursively).
  31. ;
  32. ; how to load:  Load MIRFIX immediately after loading MIRROR /Tx in your
  33. ;               AUTOEXEC.BAT file.
  34. ;               MIRFIX can be kept quiet appending any command line
  35. ;               parameter, e.g.
  36. ;                      MIRFIX shutup
  37. ;               or     MIRFIX x
  38. ;----------------------------------------------------------------------
  39.  
  40. mirfix segment byte public 'CODE'
  41.         assume cs:mirfix
  42.         assume ds:mirfix
  43.  
  44. ;----------------------------------------------------------------------
  45.         ; COM style entry point
  46. ;----------------------------------------------------------------------
  47.  
  48. org     100h
  49. startfix:
  50.         jmp     fix_transient
  51.  
  52. ;----------------------------------------------------------------------
  53.         ; the TSR's resident data area
  54. ;----------------------------------------------------------------------
  55.  
  56.         int21   dd ?                   ; original interrupt address
  57.  
  58.         save_a  dw ?                   ; three word save areas
  59.         save_b  dw ?
  60.         save_c  dw ?
  61.  
  62.  
  63. ;----------------------------------------------------------------------
  64.         ; INT 21h fix procedure (resident)
  65. ;----------------------------------------------------------------------
  66.  
  67. fixint proc far
  68.  
  69.         ; we need the AX register, so save it
  70.         mov     cs:[save_a], ax
  71.  
  72.         ; get the return address off the stack
  73.         pop     cs:[save_b]
  74.         pop     cs:[save_c]
  75.  
  76.         ; get the flags off the stack
  77.         pop     ax
  78.  
  79.         ; push the return address back
  80.         push    cs:[save_c]
  81.         push    cs:[save_b]
  82.  
  83.         pushf                          ; save the flags (AND operation)
  84.         and     ax, 0200h              ; mask out int flag
  85.         popf
  86.  
  87.         push    ax                     ; save iflag on stack
  88.  
  89.         mov     ax, cs:[save_a]        ; restore caller's AX
  90.  
  91.         ; now call original DOS interrupt
  92.         pushf
  93.         call    cs:[int21]
  94.  
  95.         ; we need AX and BX, so save them
  96.         mov     cs:[save_a], ax        ; save AX and BX
  97.         mov     cs:[save_b], bx
  98.  
  99.         pushf                          ; get the flags into AX
  100.         pop     ax
  101.  
  102.         pop     bx                     ; retrieve saved int flag
  103.  
  104.         or      ax, bx                 ; merge it into flags
  105.  
  106.         push    ax                     ; back into the flags register
  107.         popf
  108.  
  109.         mov     ax, cs:[save_a]        ; restore AX and BX
  110.         mov     bx, cs:[save_b]
  111.  
  112.         ret                            ; the flags have already been removed
  113.  
  114. fixint endp
  115.  
  116.  
  117. ;----------------------------------------------------------------------
  118. ; MIRFIX transient part
  119. ;----------------------------------------------------------------------
  120.  
  121. author  db 13, 10
  122.         db 'MIRFIX - written 1991 by E.Vogelsinger, EDP-Services, Vienna, Austria', 13, 10
  123.         db 'Fixes a nasty bug in MIRROR.COM (1991 by Central Point Software).', 13, 10, '$'
  124.  
  125. fix_transient:
  126.         mov     ax, cs
  127.         mov     ds, ax
  128.  
  129.         mov     bx, 81h                ; point to command line
  130.  
  131.         mov     cl, byte ptr [bx-1]    ; get length
  132.         sub     ch, ch
  133.         jcxz    show_author
  134.  
  135. scan_cmd:
  136.         cmp     byte ptr [bx], ' '     ; scan command line
  137.         jz      @F                     ; for some non-blank entry
  138.         cmp     byte ptr [bx], 09      ; to disable author notice
  139.         jz      @F
  140.         cmp     byte ptr [bx], 0Dh
  141.         jz      show_author
  142.  
  143.         jmp     short go_resident      ; some non-blank entry has been found
  144.  
  145. @@:     inc     bx
  146.         loop    scan_cmd
  147.  
  148. show_author:
  149.         mov     dx, offset author
  150.         mov     ah, 09h
  151.         int     21h
  152.  
  153. go_resident:
  154.         mov     ax, 3521h              ; get INT 21h address
  155.         int     21h
  156.         mov     word ptr [int21], bx
  157.         mov     ax, es
  158.         mov     word ptr [int21+2], ax
  159.  
  160.         mov     dx, offset fixint      ; hook into INT 21h
  161.         mov     ax, 2521h
  162.         int     21h
  163.  
  164.  
  165.                                        ; calculate resident size
  166.         mov     dx, offset author
  167.         add     dx, 0Fh                ; make paragraphs
  168.         mov     cx, 4
  169.         shr     dx, cl
  170.  
  171.         mov     ax, 3100h              ; TSR
  172.         int     21h
  173.  
  174. mirfix ends
  175. end startfix    ; specify entry point
  176.