home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / slowdown / cdtrap.asm next >
Assembly Source File  |  1987-09-21  |  3KB  |  174 lines

  1. title Carrier Loss Trap
  2. name CDtrap
  3. ;
  4. ;Inserted in the time tick interrupt, watches
  5. ;the carrier detect line, and if it goes
  6. ;false, reboots the system. This assumes that
  7. ;the console has been redirected to the AUX 
  8. ;(COM1) port. (It will work otherwise, but 
  9. ;is pretty useless.)
  10. ;
  11. ;You can run this any number of times, and it
  12. ;wont eat up more and more memory every time.
  13. ;It only installs once; each subsequent time
  14. ;CDTRAP looks for an old copy of itself and 
  15. ;turns that one on and off instead of loading
  16. ;a new one.
  17. ;
  18. ;If the CD line remains true, no action is 
  19. ;taken. It is presumed this program will not
  20. ;be run when the console is the normal CON.
  21. ;
  22. TICK    equ    08h    ;local tick
  23. COM1P    equ    3f8h+6    ;status port
  24. COM2P    equ    2f8h+6    ;
  25. CDBIT    equ    80h    ;CD status bit
  26.  
  27. code segment
  28. assume cs:code,ds:code
  29.  
  30.     org    5dh
  31. tfcb label byte
  32.  
  33.     org    100h
  34.  
  35. stack label word
  36.  
  37. start:    jmp    over
  38. ;
  39. ;......... Resident Code .................
  40. ;
  41. statp    dw COM2P        ;-6 port
  42. sig     dw 55aah        ;-4 signature
  43. flag     dw 1            ;-2 enable flag
  44. ;
  45. ;This is the thing that watches the DSR line
  46. ;on the AUX device.
  47. ;
  48. dsrtrap:
  49.     test    cs:flag,1    ;if flag zero
  50.     jz    dt2        ;dont look
  51.  
  52.     push    ax
  53.     push    dx
  54.     mov    dx,cs:statp    ;MODEM status
  55.     in    al,dx
  56.     and    al,CDBIT    ;mask CD bit
  57.     pop    dx
  58.     pop    ax
  59.     jnz    dt2        ;if true exit
  60.  
  61.     cli
  62.     int    19h        ;IBM boot
  63.  
  64. dt2:    jmp    dword ptr cs:oldvec
  65.  
  66. oldvec dd (?)            ;orig. vector,
  67.  
  68. trapend:            ;end of driver.
  69. ;
  70. ;..... End of Resident Code ..............
  71. ;
  72. signon     db "CD Trap for Pclones",13,10
  73.     db '5 Feb 85',13,10,'$'
  74.  
  75. inmsg     db 'Carrier Loss Trap Installed'
  76.     db 13,10,'$'
  77.  
  78. outmsg db 'Carrier Loss Trap Removed'
  79.     db 13,10,'$'
  80.  
  81. notmsg db 'CD trap not installed!',13,10,'$'
  82. ;
  83. ;Install or remove the DSRTRAP. If R is present
  84. ;on the command line, remove it if it exists.
  85. ;
  86. over:    mov    ax,cs
  87.     mov    ds,ax
  88.     mov    ss,ax
  89.     mov    sp,offset stack
  90.     mov    dx,offset signon
  91.     call    msg
  92.  
  93.     mov    ah,35h        ;get orig clock
  94.     mov    al,TICK        ;tick vector 
  95.     int    21h
  96.     mov    word ptr cs:oldvec,bx ;save it,
  97.     mov    word ptr cs:oldvec + 2,es
  98. ;
  99. ;If R present, remove the trap, else install
  100. ;it.
  101. ;
  102.     cmp    tfcb,'R'
  103.     jne    in
  104. ;
  105. ;Remove the trap. If already resident, clear 
  106. ;the flag, disabling it. If not installed,
  107. ;do nothing.
  108. ;
  109. out:    cmp    word ptr es:[bx]-4,55aah
  110.     je    o1
  111.     mov    dx,offset notmsg
  112.     mov    ah,0
  113.     jmp    msg_then_dos
  114.  
  115. o1:    mov    word ptr es:[bx]-2,0
  116.     mov    dx,offset outmsg
  117.     mov    ah,0
  118.     jmp    msg_then_dos
  119. ;
  120. ;Install the DSR Trap. If it is already 
  121. ;installed, just set the flag and enable it.
  122. ;If not there, install ourselves. Check for
  123. ;COM1 or COM2.
  124. ;
  125. in:    mov    ax,COM1P    ;assume COM1
  126.     cmp    tfcb,'2'
  127.     jne    i0
  128.     mov    ax,COM2P    ;else COM2
  129. i0:    mov    statp,ax    ;set port #
  130.     cmp    word ptr es:[bx]-4,55aah
  131.     jne    i1        
  132. ;
  133. ;Re-enabling an existing trap. Set flag and
  134. ;IO port number and go exit.
  135. ;
  136.     mov    byte ptr es:[bx]-2,1
  137.     mov    word ptr es:[bx]-6,ax
  138.     mov    ah,0
  139.     jmp    i2
  140.  
  141. i1:    mov    ah,25h        ;insert ours
  142.     mov    al,TICK
  143.     mov    dx,offset dsrtrap
  144.     int    21h
  145.  
  146.     mov    dx,offset trapend
  147.     add    dx,15        ;make segment
  148.     shr    dx,1        ;address of the
  149.     shr    dx,1        ;end of the
  150.     shr    dx,1        ;driver above,
  151.     shr    dx,1
  152.     mov    ah,31h        ;keep process,
  153.     mov    al,0
  154. i2:    mov    dx,offset inmsg
  155. ;
  156. ;Display a message, return to DOS with the
  157. ;passed AH and AL.
  158. ;
  159. msg_then_dos:
  160.     push    ax
  161.     call    msg
  162.     pop    ax
  163.     int    21h
  164. ;
  165. ;Display a message
  166. ;
  167. msg:    mov    ah,9
  168.     int    21h
  169.     ret
  170.  
  171. code ends
  172.  
  173.     end    start
  174.