🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc.programmer
Article #932

Re: Avoiding ^C

#932
From: Paul Buder
Date: Wed, 11 Jul 1990 06:35
56 lines
2656 bytes
>In article <10688@spool.cs.wisc.edu>, so@brownie.cs.wisc.edu (Bryan So) writes:
> I have tried to trap the Ctrl-Break and Ctrl-C interrupts by
> "signal", "ctrlbrk" in Turbo C and installing my own 0x23 handler.
> But there seems to be no way to prevent "^C" from printing out to
> the screen.  Can somebody explain a way to do it?  Thanks.
> 
> Bryan

 Since this Control C question has been going on for some time now and no
 one has given anything that sounds like a workable answer I offer this 
 solution.  It traps Control-C and Control-Break at Int 9 so that they 
 never get to DOS or to the BIOS.  This was compiled with Microsoft C.

#include <stdio.h>
#include <dos.h>

/*This gives the status of the control and alt keys, among others */
unsigned char far *kstatus;       
interrupt far scancode(void);     /*func decl for the interrupt routine */
void (interrupt far *oldvect)();  /*the old int 9 vector */
main()
    {
    int c;
    oldvect=_dos_getvect(9);     /*get old INT 9 vector */
    _dos_setvect(9, scancode);   /*install the new one */
    (int)kstatus=0x417;          /*the location of the keyboard status byte */

    /* and some test lines to try pressing control-c or break. */

    for(c=0; c<500; c++)
        printf("\nThis is line number %d", c);

    _dos_setvect(9, oldvect);    /*deactivate */
    }

/*The interrupt routine to check for Control-C */

interrupt far scancode(void)
    {
    unsigned char kb;

    kb=inp(0x60);/*port 0 of 8255, where character's scan codes are received */
    /*0x2e==the letter 'c', 0x46==break, */
    /*kstatus==4 means the control key is pressed. */

    if( (kb==0x2e || kb==0x46) && ((*kstatus) & 4)==4)
        {
    /*port 1 of 8255. Bit 7=0 means enabled kb, bit7=1 means kb acknowledge */
        outp(0x61, inp(0x61) | 0x80); /*raise bit 7 (send acknowledge) */
        outp(0x61, inp(0x61) & 0x7f); /*zero bit 7  (enable keyboard) */
        _enable();                    /*allow 8088 to send more interrupts */
        outp(0x20, 0x20);             /*allow 8259 to send more interrupts */
        }
    else
        _chain_intr(oldvect);/*call regular int 9 to do normal char processing*/
    }
Technical Details
Message-ID: <1990Jul11.063545.14094@techbook.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!cvedc!nosun!techbook!paulb
References: <10688@spool.cs.wisc.edu> <577@dg.dg.com> <1990Jun30.203726.7480@sjsumcs.sjsu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ogicse!cvedc!nosun!techbook!paulb
From: paulb@techbook.com (Paul Buder)
Newsgroups: comp.sys.ibm.pc.programmer
Subject: Re: Avoiding ^C
Message-ID: <1990Jul11.063545.14094@techbook.com>
Date: 11 Jul 90 06:35:45 GMT
References: <10688@spool.cs.wisc.edu> <577@dg.dg.com> <1990Jun30.203726.7480@sjsumcs.sjsu.edu>
Organization: TECHbooks of Beaverton Oregon - Public Access Unix
Lines: 56