home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / EEDRW23S.ZIP / CTRL-BRK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-25  |  2.9 KB  |  80 lines

  1. /*****************************************************************************
  2. * Module to trap ctrl-brk/hardware error and handle them gracefully.         *
  3. * Note the usage of GraphGen.c module is assumed.                 *
  4. *                                         *
  5. * Written by:  Gershon Elber            IBM PC Ver 1.0,    Jan. 1989    *
  6. *****************************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <setjmp.h>
  11. #include "Ctrl-Brk.h"
  12.  
  13. static void far *OldCtrlBrk;  /* Save here old int 1bh to be able to restore */
  14. static int WasCtrlBrkSetUp = FALSE;   /* TRUE if SetUpCtrlBrk rtn was called */
  15. int WasCtrlBrk;
  16.  
  17. static void interrupt TrapCtrlBrk(void);
  18. static int TrapCtrlC(void);
  19.  
  20. /*****************************************************************************
  21. * Routine TrapCtrlBrk gain control if Control break was typed:             *
  22. *****************************************************************************/
  23. static void interrupt TrapCtrlBrk(void)
  24. {
  25.     WasCtrlBrk = TRUE;
  26. }
  27.  
  28. /*****************************************************************************
  29. * Routine TrapCtrlC gain control if Control C was typed (DOS level):         *
  30. *****************************************************************************/
  31. static int TrapCtrlC(void)
  32. {
  33.     WasCtrlBrk = TRUE;
  34.  
  35.     return -1;                         /* Resume execution */
  36. }
  37.  
  38. /*****************************************************************************
  39. * Routine SetUpCtrlBrk must be called once by main program:             *
  40. *****************************************************************************/
  41. void SetUpCtrlBrk(void)
  42. {
  43.     if (WasCtrlBrkSetUp) return;        /* No need to to it twice! */
  44.  
  45.     OldCtrlBrk = getvect(BIOS_CTRL_BRK);
  46.     setvect(BIOS_CTRL_BRK, TrapCtrlBrk);
  47.  
  48.     ctrlbrk(TrapCtrlC);
  49.  
  50.     WasCtrlBrkSetUp = TRUE;
  51. }
  52.  
  53. /*****************************************************************************
  54. * Routine RestoreCtrlBrk must be called before the program quit:         *
  55. *****************************************************************************/
  56. void RestoreCtrlBrk(void)
  57. {
  58.     if (WasCtrlBrkSetUp)
  59.     setvect(BIOS_CTRL_BRK, (void interrupt (*)()) OldCtrlBrk);
  60.  
  61.     WasCtrlBrkSetUp = FALSE;
  62. }
  63.  
  64. /*****************************************************************************
  65. * Routine TrapHardWareError gain control if hardware fails - int 24.         *
  66. *****************************************************************************/
  67. static int TrapHardWareError(int errval, int ax, int bp, int si)
  68. {
  69.     return IGNORE;
  70. }
  71.  
  72. /*****************************************************************************
  73. * Routine SetUpHardError must be called once by main program:             *
  74. * harderr set interrupt vector 0x024 to point to TrapHardWareError.         *
  75. *****************************************************************************/ 
  76. void SetUpHardErr(void)
  77. {
  78.     harderr(TrapHardWareError);
  79. }
  80.