ReactOS 0.4.16-dev-297-gc569aee
condrv.c
Go to the documentation of this file.
1/*
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)
8 */
9
10/* INCLUDES *******************************************************************/
11
12#include "ntvdm.h"
13
14#define NDEBUG
15#include <debug.h>
16
17#include "emulator.h"
18
19#include "dos.h"
20#include "dos/dem.h"
21
22#include "bios/bios.h"
23
24/* PRIVATE VARIABLES **********************************************************/
25
28
29/* PRIVATE FUNCTIONS **********************************************************/
30
32{
33 CHAR Character;
34 WORD BytesRead = 0;
35 PCHAR Pointer = (PCHAR)FAR_POINTER(Buffer);
36
37 /* Save AX */
38 USHORT AX = getAX();
39
40 /*
41 * Use BIOS Get Keystroke function
42 */
43 while (BytesRead < *Length)
44 {
45 if (!ExtendedCode)
46 {
47 /* Call the BIOS INT 16h, AH=00h "Get Keystroke" */
48 setAH(0x00);
50
51 /* Retrieve the character in AL (scan code is in AH) */
52 Character = getAL();
53 }
54 else
55 {
56 /* Return the extended code */
57 Character = ExtendedCode;
58
59 /* And then clear it */
60 ExtendedCode = 0;
61 }
62
63 /* Check if this is a special character */
64 if (Character == 0) ExtendedCode = getAH();
65
66 Pointer[BytesRead++] = Character;
67
68 /* Stop on first carriage return */
69 if (Character == '\r') break;
70 }
71
73
74 /* Restore AX */
75 setAX(AX);
76 return DOS_DEVSTAT_DONE;
77}
78
80{
81 /* Save AX */
82 USHORT AX = getAX();
83
84 /* Call the BIOS */
85 setAH(0x01); // or 0x11 for enhanced, but what to choose?
87
88 /* Restore AX */
89 setAX(AX);
90
91 /* If ZF is set, set the busy bit */
92 if (getZF() && !ExtendedCode) return DOS_DEVSTAT_BUSY;
93 else return DOS_DEVSTAT_DONE;
94}
95
97{
99 PCHAR Pointer = (PCHAR)FAR_POINTER(Buffer);
100
101 /* Save AX */
102 USHORT AX = getAX();
103
105 {
106 /* Set the character */
107 setAL(Pointer[BytesWritten]);
108
109 /* Call the BIOS INT 29h "Fast Console Output" function */
110 Int32Call(&DosContext, 0x29);
111 }
112
113 /* Restore AX */
114 setAX(AX);
115 return DOS_DEVSTAT_DONE;
116}
117
119{
120 DPRINT("Handle to %Z opened\n", &Device->Name);
121 return DOS_DEVSTAT_DONE;
122}
123
125{
126 DPRINT("Handle to %Z closed\n", &Device->Name);
127 return DOS_DEVSTAT_DONE;
128}
129
130/* PUBLIC FUNCTIONS ***********************************************************/
131
133{
138 "CON");
139
145}
146
148{
149 if (Con) DosDeleteDevice(Con);
150}
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
CALLBACK16 DosContext
Definition: dos.c:40
#define FAR_POINTER(x)
Definition: emulator.h:35
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#define AX
Definition: i386-dis.c:424
VOID Int32Call(IN PCALLBACK16 Context, IN BYTE IntNumber)
Definition: int32.c:151
#define BIOS_KBD_INTERRUPT
Definition: kbdbios.h:14
#define PCHAR
Definition: match.c:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
WORD * PWORD
Definition: pedump.c:67
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT
Definition: sndvol32.h:73
PDOS_DEVICE_GENERIC_ROUTINE OpenRoutine
Definition: device.h:101
PDOS_DEVICE_IO_ROUTINE WriteRoutine
Definition: device.h:98
PDOS_DEVICE_IO_ROUTINE ReadRoutine
Definition: device.h:93
PDOS_DEVICE_GENERIC_ROUTINE CloseRoutine
Definition: device.h:102
PDOS_DEVICE_GENERIC_ROUTINE InputStatusRoutine
Definition: device.h:95
WORD NTAPI ConDrvOpen(PDOS_DEVICE_NODE Device)
Definition: condrv.c:118
WORD NTAPI ConDrvClose(PDOS_DEVICE_NODE Device)
Definition: condrv.c:124
PDOS_DEVICE_NODE Con
Definition: condrv.c:26
WORD NTAPI ConDrvInputStatus(PDOS_DEVICE_NODE Device)
Definition: condrv.c:79
BYTE ExtendedCode
Definition: condrv.c:27
WORD NTAPI ConDrvReadInput(PDOS_DEVICE_NODE Device, DWORD Buffer, PWORD Length)
Definition: condrv.c:31
VOID ConDrvCleanup(VOID)
Definition: condrv.c:147
WORD NTAPI ConDrvWriteOutput(PDOS_DEVICE_NODE Device, DWORD Buffer, PWORD Length)
Definition: condrv.c:96
VOID ConDrvInitialize(VOID)
Definition: condrv.c:132
PDOS_DEVICE_NODE DosCreateDevice(WORD Attributes, PCHAR DeviceName)
Definition: device.c:413
VOID DosDeleteDevice(PDOS_DEVICE_NODE DeviceNode)
Definition: device.c:419
#define DOS_DEVATTR_STDIN
Definition: device.h:21
#define DOS_DEVATTR_CON
Definition: device.h:25
#define DOS_DEVATTR_STDOUT
Definition: device.h:22
#define DOS_DEVSTAT_BUSY
Definition: device.h:50
#define DOS_DEVSTAT_DONE
Definition: device.h:49
#define DOS_DEVATTR_CHARACTER
Definition: device.h:29
#define NTAPI
Definition: typedefs.h:36
char * PCHAR
Definition: typedefs.h:51
ULONG WINAPI getZF(VOID)
Definition: registers.c:608
VOID WINAPI setAL(UCHAR)
Definition: registers.c:149
UCHAR WINAPI getAL(VOID)
Definition: registers.c:142
VOID WINAPI setAH(UCHAR)
Definition: registers.c:135
USHORT WINAPI getAX(VOID)
Definition: registers.c:114
VOID WINAPI setAX(USHORT)
Definition: registers.c:121
UCHAR WINAPI getAH(VOID)
Definition: registers.c:128
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
char CHAR
Definition: xmlstorage.h:175
unsigned char BYTE
Definition: xxhash.c:193