Recently I decided, it would be funny, to code some simple MSDOS game. Needles to say, I need code for handling keyboard events.
This is what I came up with for testing:
int i, c = 0;
for ( i = 0; i < 10; i++ )
{
asm
(
"mov $0x00, %%ah \n"
"mov $0x00, %%al \n"
"int $0x16 \n"
//"jnz keydn \n"
//"mov $0x00, %%al \n"
//"keydn: \n"
"movw %%ax, (%0) \n"
: "=r"(c)
);
printf( "%d\n", c & 0xFF );
}
The code is supposed to wait for keypress, and then print out ASCII value of the character. And everything works as expected unless I press key like backspace or esc - then segmentation fault occurs.
I'm unfamiliar with assembly, but really I can't figure out what may cause this error.
I compile with djgpp
, and run executables in DosBox
Everything is based on information provided here:
- https://courses.engr.illinois.edu/ece390/books/artofasm/CH20/CH20-3.html
- https://en.wikipedia.org/wiki/BIOS_interrupt_call
Thank you in advance! :)