I am trying to learn how to prevent the keyboard sending multiple chars to the screen and to scanf
under DOS. I am using Turbo-C with inline assembly.
If the characters entered on the keyboard are:
mmmmmmmmyyyyy nnnnnaaaaammmmmmeeeeee iiiiiissss HHHHaaaaiiiimmmm
The characters seen on the console and processed by scanf
would be:
my name is Haim
The basic output comes from the code in C which I am not allowed to touch. I must implement eliminate_multiple_press
and uneliminate_multiple_press
without touching the code in between.
The Turbo-C code I've written so far is:
#include <stdio.h>
#include <dos.h>
#include <string.h>
volatile char key;
volatile int i=0;
void interrupt (*Int9save) (void);
void interrupt kill_multiple_press()
{
asm{
MOV AL, 0
MOV AH,1
INT 16h
PUSHF
CALL DWORD PTR Int9save
MOV AX,0
}
asm{
JZ notSet
MOV key, AL
MOV AH, 04H
INT 16H
}
notSet:
//I am not sure what to do from here...............
I also know that it should be related to the zero flag, but what I
wrote so far didn`t effect on multiple characters.
}
void eliminate_multiple_press()
{
Int9save=getvect(9);
setvect(9,kill_multiple_press);
}
void uneliminate_multiple_press()
{
setvect(9,Int9save);
}
void main()
{
char str[10000]="";
clrscr();
eliminate_multiple_press();
printf("Enter your string: ");
scanf("%s",&str);
printf("\n%s",str);
uneliminate_multiple_press();
}
Information I have been given that relate to a solution are the keyboard BIOS routines that can be found at this link:
The problems I'm having are probably related to not understanding what to do at the label notSet
. The solution seems to be related to using a buffer and the register AX (especially AL), but I really have no Idea how to make scanf
to get the result I need. Does anyone have any ideas how I can complete this code to achieve the desired effect?