Edited: Only printf with "\n" would be shown.
int main (int argc, char *argv[])
{
REGPACK Regs;
KEY_DATA KeyData
//Set cursor position AH= 02h, BH = Page Number, DH = Row, DL = Column
Regs.h.ah = 0x02;
Regs.h.bh = 0;
Regs.h.dh = 15;
Regs.h.dl = 40;
intr(0x10, &Regs);
printf("Test");
while (KeyData.Key.ScanCode != SCAN_ESC) {
GetKey(&KeyData);
printf("Key: %c", KeyCode.Key.AsciiChar);
}
return 0;
}
The snippet is as above:
Coding Environment: Windows8.1
Tool chain: Open Watcom (WCL & WASM) v1.9
Executed on: DOSBox, real DOS 6.22
First, I found out that "printf" would not print anything on the screen, no "Test" nor "Key: X" is shown. Then I started to strike the keyboard, about 4~6 keystrokes, the string would come out in bunch, something like:
TestKey: aKey: bKey: cKey: d
The same symptoms occurred every 4~6 continuous keystrokes.
Another scenario, I didn't press anything, printf would not function, and as soon as I terminated this program by pressing "ESC", the two strings would be shown on the upper left of the screen, like there's nothing wrong.
So I began to think there is something wrong about this snippet, and printf only functions when DOS program terminate signal is occurred (INT 21h AH=4Ch).
I've re-wrote the "set cursor position" thing in pure assembly, and did a near call to the proc, the bug still occurred, and I've changed the set cursor position to set video mode 3 from video mode 3 (INT 10h, AH=00, AL=03h) to refresh the screen, no luck, either.
No matter what method I used, after INT10h, the printf just wouldn't work before a DOS terminate signal.
Does anyone know why this happened? And is there a way to avoid this, or for me to use printf mixed with INT10h?
But putc and puts could print on the screen normally under this circumstances, and printf only works when there is a "\n" character (e.g. "helloworld\n"). I'm super confused...
I cannot abandon INT10h, because MSDOS has no native support of these kind of operation, and BIOS call is also effective, nor can I abandon printf, because variadic parameters really save my butt a lot.
Thanks guys!