2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: subsystems/mvdm/ntvdm/dos/dos32krnl/condrv.c
5 * PURPOSE: DOS32 CON Driver
6 * PROGRAMMERS: Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
10 /* INCLUDES *******************************************************************/
20 #include "bios/bios.h"
22 /* PRIVATE VARIABLES **********************************************************/
24 PDOS_DEVICE_NODE Con
= NULL
;
25 BYTE ExtendedCode
= 0;
27 /* PRIVATE FUNCTIONS **********************************************************/
29 WORD NTAPI
ConDrvReadInput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
33 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
39 * Use BIOS Get Keystroke function
41 while (BytesRead
< *Length
)
45 /* Call the BIOS INT 16h, AH=00h "Get Keystroke" */
47 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
49 /* Retrieve the character in AL (scan code is in AH) */
54 /* Return the extended code */
55 Character
= ExtendedCode
;
57 /* And then clear it */
61 /* Check if this is a special character */
62 if (Character
== 0) ExtendedCode
= getAH();
64 Pointer
[BytesRead
++] = Character
;
66 if (Character
!= 0 && DoEcho
)
67 DosPrintCharacter(DOS_OUTPUT_HANDLE
, Character
);
69 /* Stop on first carriage return */
70 if (Character
== '\r')
72 if (DoEcho
) DosPrintCharacter(DOS_OUTPUT_HANDLE
, '\n');
81 return DOS_DEVSTAT_DONE
;
84 WORD NTAPI
ConDrvInputStatus(PDOS_DEVICE_NODE Device
)
90 setAH(0x01); // or 0x11 for enhanced, but what to choose?
91 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
96 /* If ZF is set, set the busy bit */
97 if (getZF() && !ExtendedCode
) return DOS_DEVSTAT_BUSY
;
98 else return DOS_DEVSTAT_DONE
;
101 WORD NTAPI
ConDrvWriteOutput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
104 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
109 for (BytesWritten
= 0; BytesWritten
< *Length
; BytesWritten
++)
111 /* Set the character */
112 setAL(Pointer
[BytesWritten
]);
114 /* Call the BIOS INT 29h "Fast Console Output" function */
115 Int32Call(&DosContext
, 0x29);
120 return DOS_DEVSTAT_DONE
;
123 WORD NTAPI
ConDrvOpen(PDOS_DEVICE_NODE Device
)
125 DPRINT("Handle to %Z opened\n", &Device
->Name
);
126 return DOS_DEVSTAT_DONE
;
129 WORD NTAPI
ConDrvClose(PDOS_DEVICE_NODE Device
)
131 DPRINT("Handle to %Z closed\n", &Device
->Name
);
132 return DOS_DEVSTAT_DONE
;
135 /* PUBLIC FUNCTIONS ***********************************************************/
137 VOID
ConDrvInitialize(VOID
)
139 Con
= DosCreateDevice(DOS_DEVATTR_STDIN
142 | DOS_DEVATTR_CHARACTER
,
145 Con
->ReadRoutine
= ConDrvReadInput
;
146 Con
->InputStatusRoutine
= ConDrvInputStatus
;
147 Con
->WriteRoutine
= ConDrvWriteOutput
;
148 Con
->OpenRoutine
= ConDrvOpen
;
149 Con
->CloseRoutine
= ConDrvClose
;
152 VOID
ConDrvCleanup(VOID
)
154 if (Con
) DosDeleteDevice(Con
);