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)
15 /* PRIVATE VARIABLES **********************************************************/
17 PDOS_DEVICE_NODE Con
= NULL
;
18 BYTE ExtendedCode
= 0;
20 /* PRIVATE FUNCTIONS **********************************************************/
22 WORD NTAPI
ConDrvReadInput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
26 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
32 * Use BIOS Get Keystroke function
34 while (BytesRead
< *Length
)
38 /* Call the BIOS INT 16h, AH=00h "Get Keystroke" */
40 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
42 /* Retrieve the character in AL (scan code is in AH) */
47 /* Return the extended code */
48 Character
= ExtendedCode
;
50 /* And then clear it */
54 /* Check if this is a special character */
55 if (Character
== 0) ExtendedCode
= getAH();
57 Pointer
[BytesRead
++] = Character
;
59 /* Stop on first carriage return */
60 if (Character
== '\r') break;
67 return DOS_DEVSTAT_DONE
;
70 WORD NTAPI
ConDrvInputStatus(PDOS_DEVICE_NODE Device
)
76 setAH(0x01); // or 0x11 for enhanced, but what to choose?
77 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
82 /* If ZF is set, set the busy bit */
83 if (getZF() && !ExtendedCode
) return DOS_DEVSTAT_BUSY
;
84 else return DOS_DEVSTAT_DONE
;
87 WORD NTAPI
ConDrvWriteOutput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
90 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
95 for (BytesWritten
= 0; BytesWritten
< *Length
; BytesWritten
++)
97 /* Set the character */
98 setAL(Pointer
[BytesWritten
]);
100 /* Call the BIOS INT 29h "Fast Console Output" function */
101 Int32Call(&DosContext
, 0x29);
106 return DOS_DEVSTAT_DONE
;
109 WORD NTAPI
ConDrvOpen(PDOS_DEVICE_NODE Device
)
111 DPRINT("Handle to %Z opened\n", &Device
->Name
);
112 return DOS_DEVSTAT_DONE
;
115 WORD NTAPI
ConDrvClose(PDOS_DEVICE_NODE Device
)
117 DPRINT("Handle to %Z closed\n", &Device
->Name
);
118 return DOS_DEVSTAT_DONE
;
121 /* PUBLIC FUNCTIONS ***********************************************************/
123 VOID
ConDrvInitialize(VOID
)
125 Con
= DosCreateDevice(DOS_DEVATTR_STDIN
128 | DOS_DEVATTR_CHARACTER
,
131 Con
->ReadRoutine
= ConDrvReadInput
;
132 Con
->InputStatusRoutine
= ConDrvInputStatus
;
133 Con
->WriteRoutine
= ConDrvWriteOutput
;
134 Con
->OpenRoutine
= ConDrvOpen
;
135 Con
->CloseRoutine
= ConDrvClose
;
138 VOID
ConDrvCleanup(VOID
)
140 if (Con
) DosDeleteDevice(Con
);