//--------------------------------------------------------------- // EXAMPLE EX20.C : Demonstrate us of DOS KEYBOARD and DISPLAY // Compile using: MCDOS ex20.c // Then run TMP.EXE on a DOS machine! // // C.P. Diduch, Jan 2000. //--------------------------------------------------------------- // Function definitions or prototypes. char inportbdos(void); void outportbdos(char X); //--------------------------------------------------------------- void main() { unsigned i; char X; i = 0; while (i < 10) { X = 0x7F & inportbdos(); outportbdos(X); i = i + 1; } } //--------------------------------------------------------------- char inportbdos(void) { char X; asm { push dx ; // Save register values. push ax ; mov ah, 8 ; // DOS Call to read a keypress. int 0x21 ; // ASCII value appears in register al. mov X, al ; pop ax ; // Restore register values. pop dx ; } return X; } //--------------------------------------------------------------- void outportbdos(char X) { asm { push dx ; // Save register values. push ax ; mov ah, 2 ; // DOS Call to read display ASCII value. mov dl, X ; // ASII value is passed in register dl. int 0x21 ; // ASCII value appears in register dl. pop ax ; // Restore register values. pop dx ; } return; }