home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / intercep.asm < prev    next >
Assembly Source File  |  1994-03-04  |  6KB  |  173 lines

  1. Article 4827 of comp.sys.ibm.pc:
  2. Path: brl-smoke!brl-adm!husc6!uwvax!uwmacc!hobbes!circle
  3. From: galvin@circle.UUCP (John Galvin)
  4. Newsgroups: comp.sys.ibm.pc
  5. Subject: preventing MS-DOS from printing ^C while within MS C
  6. Date: 29 Jun 87 03:53:30 GMT
  7.  
  8.  
  9.      A while ago someone asked how to prevent MS-DOS from printing ^C
  10. when using signal() to trap Ctrl-C's.  The code below does this for
  11. MS-DOS machines which are BIOS compatible with the IBM PC.  Through
  12. sheer laziness I have not tested it without signal().
  13.  
  14.      When the BIOS determines that a Ctrl-C has been pressed it does
  15. two important things.  First it sets bit 7 of 0040:0071 (labeled in
  16. the BIOS listing as BIOS_BREAK).  Then it does an interrupt 0x1B.  The
  17. interrupt routine that MS-DOS supplies for int 1B sticks a control C
  18. character (0x03) into the keyboard buffer.  That is why the ^C is
  19. printed out by MS-DOS.  The code below intercepts that interrupt so
  20. that the ^C is not put into the buffer.  It does not, however, affect
  21. the byte at BIOS_BREAK in any way.  if you want to prevent that flag
  22. from being seen by DOS, just add some code to zero out that location in
  23. the int 1B interrupt handler.
  24.  
  25.      To use these routines, just call intercept() when you want to
  26. prevent DOS from printing ^C.  Remember to call release() before the
  27. program exits.  Hope this is what you were looking for...
  28.                             John
  29.  
  30. --  
  31. John Galvin         UUCP:    ...uwvax!uwmacc!hobbes!circle!galvin
  32. 213 N. Hamilton #9  FidoNet: Sysop of 121/0, and 121/1.  (608) 258-9723
  33. Madison, Wi  53703  AT&T:    (608) 258-9721
  34.  
  35.  
  36. -------------------------------Cut Here---------------------------------
  37.  
  38.         TITLE   Intercept.asm - intercept ^C
  39.         PAGE    66,132
  40. ;
  41. ;       Intercept.ASM
  42. ;
  43. ;       Author:  John Galvin
  44. ;       Date:    06-Jan-1987
  45. ;       Purpose: to intercept a control-C from Microsoft C
  46. ;
  47. ;       Copyright (C) 1987 by John W. Galvin.
  48. ;
  49. ;       This source code may be freely used and distributed provided that
  50. ;       it is not sold, no charge whatsoever is made for its distribution,
  51. ;       and the above copyright and authorship information remains with
  52. ;       the source code.
  53. ;
  54. ;               John Galvin - FidoNet 121/0 & 121/1
  55. ;                             UUCP ...!uwvax!uwmacc!hobbes!circle!galvin
  56. ;
  57. ;       use the following to assemble this code for the small memory model:
  58. ;               masm /ml intercep.asm;
  59. ;       for the large memory model use:
  60. ;               masm /ml /dLPROG intercep.asm;
  61. ;
  62. ;       Update History:
  63. ;           06-Jan-1987 - initial version.
  64. ;           28-Jun-1987 - threw in some comments for release.
  65. ;
  66.  
  67. ifdef LPROG
  68.     assume CS:INTERCEP_TEXT
  69.     INTERCEP_TEXT       segment byte    public 'CODE'
  70. else
  71.     assume CS:_TEXT
  72.     _TEXT       segment byte    public 'CODE'
  73. endif
  74.  
  75.         PUBLIC _intercept, _release
  76.  
  77.  
  78. oldseg  dw      ?       ; the old segment of the break interrupt vector
  79. oldoff  dw      ?       ; the old offset of the break interrupt vector
  80.  
  81.  
  82. ;----------------------------------------------------------------------------
  83. ;       Name: do_intcpt
  84. ;       
  85. ;       This is an interrupt handler for int 1B, the Keyboard Break
  86. ;       interrupt.  As it stands it just does a return from interrupt.
  87. ;       This routine is local to this file.
  88. ;
  89. ifdef LPROG
  90.         do_intcpt       PROC FAR
  91. else
  92.         do_intcpt       PROC NEAR
  93. endif
  94.         iret
  95. do_intcpt       ENDP
  96.  
  97.  
  98. ;----------------------------------------------------------------------------
  99. ;       Name: _intercept
  100. ;
  101. ;       This routine changes the Keyboard Break interrupt handler
  102. ;       to do_intcpt.
  103. ;
  104. ifdef LPROG
  105.         _intercept      PROC FAR
  106. else
  107.         _intercept      PROC NEAR
  108. endif
  109.         push    bp                      ; save bp
  110.         mov     bp, sp                  ; setup bp
  111.         push    di                      ; save possible register variable
  112.         push    si                      ; save possible register variable
  113.         push    es
  114.         mov     ax, 351Bh               ; DOS get vector service
  115.         int     21h
  116.         mov     ax, es                  ; segment returned in es
  117.         mov     cs:oldseg, ax           ; save old routine's segment address
  118.         mov     cs:oldoff, bx           ; and offset
  119.         mov     ax, 251Bh               ; DOS set vector service
  120.         mov     dx, offset do_intcpt    ; offset of our interrupt handler
  121.         push    ds
  122.         push    cs
  123.         pop     ds                      ; get segment address of our handler
  124.         int     21h                     ; set the vector
  125.         pop     ds                      ; restore ds
  126.         pop     es                      ; restore es
  127.         pop     si                      ; restore si
  128.         pop     di                      ; restore di
  129.         mov     sp, bp                  ; chop stack for return to calling function
  130.         pop     bp                      ; restore bp
  131.         ret                             ; return to calling function
  132. _intercept      ENDP
  133.  
  134.  
  135. ;----------------------------------------------------------------------------
  136. ;       Name: _release
  137. ;
  138. ;       This routine changes the Keyboard Break interrupt handler back to
  139. ;       the original MS-DOS routine.
  140. ;
  141. ifdef LPROG
  142.         _release        PROC FAR
  143. else
  144.         _release        PROC NEAR
  145. endif
  146.         push    bp                      ; save bp
  147.         mov     bp, sp                  ; setup bp 
  148.         push    di                      ; save possible register variable
  149.         push    si                      ; save possible register variable
  150.         push    ds
  151.         mov     ax, 251Bh               ; DOS set vector service
  152.         mov     dx, cs:oldoff           ; old handler's offset
  153.         mov     bx, cs:oldseg           ; old handler's segment
  154.         mov     ds, bx
  155.         int     21h                     ; set the vector
  156.         pop     ds
  157.         pop     si                      ; restore si
  158.         pop     di                      ; restore di
  159.         mov     sp, bp                  ; chop stack for return to calling function
  160.         pop     bp                      ; restore bp
  161.         ret                             ; return to calling function
  162. _release        ENDP
  163.  
  164. ifdef LPROG
  165.         INTERCEP_TEXT   ENDS
  166. else
  167.         _TEXT   ENDS
  168. endif
  169.  
  170. END
  171.  
  172.  
  173.