I am trying to make somewhat a TSR program (background process) for MS-DOS in C. I want the program to print "It works" and kill itself when a user press F2. But my code doesn't work. When I start .exe dos freezes and even spamming F2 for 18.2 seconds (interval interruption) doesn't help. I'm new to low-level programming so I can't google solutions for something like this and I don't understand how do interruptions work. Information for something like this is really messy nowadays. Thank you in advance.
void interrupt (*handler)();
void interrupt newHandler();
int main(void) {
handler = getvect(8);
setvect(8, newHandler);
keep(0,10000);
return 0;
}
void interrupt newHandler() {
input = getch();
if(input == 60) {
printf("It works\n");
}
else {
(*handler)();
}
}
I've tried adding this method from here Checking if a key is down in MS-DOS (C/C++). But I don't understand how am I supposed to have 3Ch in a char variable.
unsigned char read_scancode() {
unsigned char res;
_asm {
in al, 60h
mov res, al
in al, 61h
or al, 128
out 61h, al
xor al, 128
out 61h, al
}
return res;
}