Thread: Masking CTRL-ALT-DEL and ^C Interrupts

  1. #1
    Unregistered
    Guest

    Question Masking CTRL-ALT-DEL and ^C Interrupts

    Hi, I was just wondering how to mask the interrupts for CTRL-ALT-DEL and ^C for a DOS BOX under windows?

    Thanks =)

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The only one that uses an interrupt is break. The best way to trap for these is to write a keyboard handler. There are several posts on this board related to this topic so I'll not write reams of text here. Check the board as this topic is all over it multiple times in multiple places.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I misled you a bit with my info. For Ctrl^C just write an int23h interrupt handler either in asm or C.


    Code:
    //Use (...) for C++ and (void) for C.
    
    void interrupt (*oldbreakhandler)(...)=NULL;
    
    
    void interrupt breakhandler(...)
    {
       //Do something
       //You can just disable this by putting nothing here
       //This would translate to an IRET in asm
       //Turning off CTRL-C, though, is probably not what you want
       //to do while building your code.
       
       //Example:
       //Uninstall any other int handlers we have installed
       //Free memory
       uninstallbreakhandler();
       oldbreakhandler();   //Pass the int onto the orig int 23h handler
       
       //Will terminate, but cleans up prior to terminating
    }
    
    void installbreakhandler(void)
    {
      disable();  
      //Save old handler
      oldbreakhandler=getvect(0x23);
      //Install our handler
      setvect(0x23,breakhandler);
      enable();
    }
    
    void uninstallbreakhandler(void)
    {
       //Restore the int vector table
       disable();
       setvect(0x23,oldbreakhandler);
       enable();
    }

    DOS does not restore the int vector table if you have patched interrupts and pressed CTRL-C midway in your program. This thrashes the interrupt chain for the vectors you have patched. You would have to reboot to run your code again. The above method will allow you to press CTRL-C for debugging and will properly restore the int vector table so you can run your code again w/o having to reboot.

    In a commercial build you would probably just put an IRET in the int23h handler. You will also want to patch int24h which is DOS's Critical Error Handler - not very friendly at all. Your version should help the user determine what the heck happened and why DOS failed or a DOS call failed.

  4. #4
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859
    Ctrl + C's ASCI code is 3

    As for the Invincible breakout... You can't in Windows because it will bring up the close prog dialog.
    Yoshi

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    This is for DOS, since this is the DOS programming board.

Popular pages Recent additions subscribe to a feed