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 *******************************************************************/
19 #include "bios/bios.h"
21 /* PRIVATE VARIABLES **********************************************************/
23 PDOS_DEVICE_NODE ConIn
= NULL
, ConOut
= NULL
;
25 /* PRIVATE FUNCTIONS **********************************************************/
27 WORD NTAPI
ConDrvReadInput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
31 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
37 * Use BIOS Get Keystroke function
39 for (BytesRead
= 0; BytesRead
< *Length
; BytesRead
++)
41 /* Call the BIOS INT 16h, AH=00h "Get Keystroke" */
43 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
45 /* Retrieve the character in AL (scan code is in AH) */
48 if (DoEcho
) DosPrintCharacter(DOS_OUTPUT_HANDLE
, Character
);
49 Pointer
[BytesRead
] = Character
;
51 /* Stop on first carriage return */
52 if (Character
== '\r')
54 if (DoEcho
) DosPrintCharacter(DOS_OUTPUT_HANDLE
, '\n');
63 return DOS_DEVSTAT_DONE
;
66 WORD NTAPI
ConDrvInputStatus(PDOS_DEVICE_NODE Device
)
72 setAH(0x01); // or 0x11 for enhanced, but what to choose?
73 Int32Call(&DosContext
, BIOS_KBD_INTERRUPT
);
78 /* If ZF is set, set the busy bit */
79 if (getZF()) return DOS_DEVSTAT_BUSY
;
80 else return DOS_DEVSTAT_DONE
;
83 WORD NTAPI
ConDrvWriteOutput(PDOS_DEVICE_NODE Device
, DWORD Buffer
, PWORD Length
)
86 PCHAR Pointer
= (PCHAR
)FAR_POINTER(Buffer
);
89 * Use BIOS Teletype function
96 // FIXME: Use BIOS Write String function INT 10h, AH=13h ??
97 for (BytesWritten
= 0; BytesWritten
< *Length
; BytesWritten
++)
99 /* Set the parameters */
100 setAL(Pointer
[BytesWritten
]);
101 setBL(DOS_CHAR_ATTRIBUTE
);
102 setBH(Bda
->VideoPage
);
104 /* Call the BIOS INT 10h, AH=0Eh "Teletype Output" */
106 Int32Call(&DosContext
, BIOS_VIDEO_INTERRUPT
);
109 /* Restore AX and BX */
112 return DOS_DEVSTAT_DONE
;
115 WORD NTAPI
ConDrvOpen(PDOS_DEVICE_NODE Device
)
117 DPRINT("Handle to %Z opened\n", &Device
->Name
);
118 return DOS_DEVSTAT_DONE
;
121 WORD NTAPI
ConDrvClose(PDOS_DEVICE_NODE Device
)
123 DPRINT("Handle to %Z closed\n", &Device
->Name
);
124 return DOS_DEVSTAT_DONE
;
127 /* PUBLIC FUNCTIONS ***********************************************************/
129 VOID
ConDrvInitialize(PDOS_DEVICE_NODE
*InputDevice
, PDOS_DEVICE_NODE
*OutputDevice
)
131 ConIn
= DosCreateDevice(DOS_DEVATTR_STDIN
133 | DOS_DEVATTR_CHARACTER
,
135 ConOut
= DosCreateDevice(DOS_DEVATTR_STDOUT
137 | DOS_DEVATTR_CHARACTER
,
139 ASSERT(ConIn
!= NULL
&& ConOut
!= NULL
);
141 ConIn
->ReadRoutine
= ConDrvReadInput
;
142 ConIn
->InputStatusRoutine
= ConDrvInputStatus
;
143 ConOut
->WriteRoutine
= ConDrvWriteOutput
;
144 ConIn
->OpenRoutine
= ConOut
->OpenRoutine
= ConDrvOpen
;
145 ConIn
->CloseRoutine
= ConOut
->CloseRoutine
= ConDrvClose
;
147 if (InputDevice
) *InputDevice
= ConIn
;
148 if (OutputDevice
) *OutputDevice
= ConOut
;
151 VOID
ConDrvCleanup(VOID
)
153 if (ConIn
) DosDeleteDevice(ConIn
);
154 if (ConOut
) DosDeleteDevice(ConOut
);