home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / TRAPDEMO.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  84 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Demonstrate TRAPFLAG.ASM
  5. **
  6. **  public domain by Bob Stout
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <dos.h>
  12. #include <conio.h>
  13. #include "extkword.h"
  14.  
  15. #ifdef __WATCOMC__
  16.  #pragma aux ins09  "_*" parm caller [] modify [ax bx cx dx es]
  17.  #pragma aux undo09 "_*" parm caller [] modify [ax bx cx dx es]
  18. #endif
  19.  
  20. extern void ins09(void);
  21. extern void undo09(void);
  22.  
  23. extern volatile int FAR ccrcvd;
  24.  
  25. static void biosprt(char *p)
  26. {
  27.       union REGS regs;
  28.  
  29.       while (*p)
  30.       {
  31.             regs.h.ah = 0x0e;             /* Low-level services only!     */
  32.             regs.h.al = *p++;
  33.             regs.x.bx = 0;
  34.             int86(0x10, ®s, ®s);
  35.       }
  36. }
  37.  
  38. static void FAR my_cc(void)
  39. {
  40.       char *p1 = "Ctrl-";
  41.       char *p2 = "C";
  42.       char *p3 = "Break";
  43.       char *p4 = " received\r\n";
  44.  
  45.       biosprt(p1);
  46.       if (1 == ccrcvd)
  47.             biosprt(p2);
  48.       else  biosprt(p3);
  49.       biosprt(p4);
  50. }
  51.  
  52. main()
  53. {
  54.       int ch = 0;
  55.  
  56.       setbuf(stdout, NULL);
  57.       my_cc();
  58.       ins09();
  59.       atexit(undo09);
  60.       puts("New Ints 09h & 1Bh installed...");
  61.       puts("Hit Esc to quit...");
  62.       do
  63.       {
  64.             if (kbhit())
  65.             {
  66.                   if (0x1b != (ch = getch()))
  67.                   {
  68.                         if (0x20 > ch)
  69.                         {
  70.                               fputc('^', stdout);
  71.                               ch += '@';
  72.                         }
  73.                         fputc(ch, stdout);
  74.                   }
  75.             }
  76.             if (ccrcvd)
  77.             {
  78.                   my_cc();
  79.                   ccrcvd = 0;
  80.             }
  81.       } while (0x1b != ch);
  82.       return 0;
  83. }
  84.