wiener@stout.UCAR.EDU (Gerry Wiener) (02/18/90)
In the following code an interrupt handler for the keyboard is replaced by one that increments a counter then chains to the original handler. Question: Why doesn't "count" get incremented correctly? Please mail me the replies. Gerry Wiener Email:wiener@stout.ucar.edu ------------------------------------------------------------------------ #include <dos.h> #include <stdio.h> #define KEYBD 0x16 void (interrupt far *oldkb)(void); void interrupt far newkb(void); int count; main() { int c; oldkb = _dos_getvect(KEYBD); _dos_setvect(KEYBD, newkb); count = 0; while ((c = getchar()) != 'x') { printf("count is %d\n", count); putchar(c); } _dos_setvect(KEYBD, oldkb); } void interrupt far newkb(void) { count++; _chain_intr(oldkb); }
darcy@druid.uucp (D'Arcy J.M. Cain) (02/19/90)
In article <WIENER.90Feb17172147@stout.stout.UCAR.EDU> wiener@stout.UCAR.EDU (Gerry Wiener) writes: >In the following code an interrupt handler for the keyboard is >replaced by one that increments a counter then chains to the original >handler. Question: Why doesn't "count" get incremented correctly? >Please mail me the replies. > > Gerry Wiener Email:wiener@stout.ucar.edu > >------------------------------------------------------------------------ > >#include <dos.h> >#include <stdio.h> > >#define KEYBD 0x16 > >void (interrupt far *oldkb)(void); >void interrupt far newkb(void); >int count; > >main() >{ > int c; > > oldkb = _dos_getvect(KEYBD); > > _dos_setvect(KEYBD, newkb); > [...] > _dos_setvect(KEYBD, oldkb); >} > >void interrupt far newkb(void) >{ > count++; > _chain_intr(oldkb); >} This is just an untested guess since I no longer have MSC to try it on but try declaring count as a far int. -- D'Arcy J.M. Cain (darcy@druid) | Thank goodness we don't get all D'Arcy Cain Consulting | the government we pay for. West Hill, Ontario, Canada | (416) 281-6094 |
richard@stb.uucp (Richard Conner) (02/21/90)
In article <WIENER.90Feb17172147@stout.stout.UCAR.EDU> wiener@stout.UCAR.EDU (Gerry Wiener) writes: >In the following code an interrupt handler for the keyboard is >replaced [...] > >#define KEYBD 0x16 What you REALLY want is: #define KEYBD 0x9 /* 9 = interrupt FROM keyboard */ Interrupt 0x16 is for ROM BIOS services, i.e. turning on/off typematic, etc. 0x9 is the keyboard interrupt which occurs when each key is hit. (AS WELL AS when each key is RELEASED) -Richard -- [ .signature under construction - turn back before it's too late ]