2 * COPYRIGHT: GPL - See COPYING in the top level directory
3 * PROJECT: ReactOS Virtual DOS Machine
4 * FILE: 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 if (DoEcho
) DosPrintCharacter(DOS_OUTPUT_HANDLE
, Character
);
65 Pointer
[BytesRead
++] = Character
;
67 /* Stop on first carriage return */
68 if (Character
== '\r')
70 if (DoEcho
) DosPrintCharacter(DOS_OUTPUT_HANDLE
, '\n');
79 return DOS_DEVSTAT_DONE
;
82 WORD NTAPI
ConDrvInputStatus(PDOS_DEVICE_NODE Device
)
88 setAH(0x01); // or 0x11 for enhanced, but what to choose?
89 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
94 /* If ZF is set, set the busy bit */
95 if (getZF()) return DOS_DEVSTAT_BUSY
;
96 else return DOS_DEVSTAT_DONE
;
99 WORD NTAPI
ConDrvWriteOutput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
102 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
107 for (BytesWritten
= 0; BytesWritten
< *Length
; BytesWritten
++)
109 /* Set the character */
110 setAL(Pointer
[BytesWritten
]);
112 /* Call the BIOS INT 29h "Fast Console Output" function */
113 Int32Call(&DosContext
, 0x29);
118 return DOS_DEVSTAT_DONE
;
121 WORD NTAPI
ConDrvOpen(PDOS_DEVICE_NODE Device
)
123 DPRINT("Handle to %Z opened\n", &Device
->Name
);
124 return DOS_DEVSTAT_DONE
;
127 WORD NTAPI
ConDrvClose(PDOS_DEVICE_NODE Device
)
129 DPRINT("Handle to %Z closed\n", &Device
->Name
);
130 return DOS_DEVSTAT_DONE
;
133 /* PUBLIC FUNCTIONS ***********************************************************/
135 VOID
ConDrvInitialize(VOID
)
137 Con
= DosCreateDevice(DOS_DEVATTR_STDIN
140 | DOS_DEVATTR_CHARACTER
,
143 Con
->ReadRoutine
= ConDrvReadInput
;
144 Con
->InputStatusRoutine
= ConDrvInputStatus
;
145 Con
->WriteRoutine
= ConDrvWriteOutput
;
146 Con
->OpenRoutine
= ConDrvOpen
;
147 Con
->CloseRoutine
= ConDrvClose
;
150 VOID
ConDrvCleanup(VOID
)
152 if (Con
) DosDeleteDevice(Con
);