ReactOS  0.4.14-dev-41-g31d7680
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 
72  *Length = BytesRead;
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 }
signed char * PCHAR
Definition: retypes.h:7
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
VOID WINAPI setAH(UCHAR)
Definition: registers.c:135
#define DOS_DEVATTR_CON
Definition: device.h:25
VOID WINAPI setAX(USHORT)
Definition: registers.c:121
char CHAR
Definition: xmlstorage.h:175
VOID Int32Call(IN PCALLBACK16 Context, IN BYTE IntNumber)
Definition: int32.c:151
VOID WINAPI setAL(UCHAR)
Definition: registers.c:149
#define AX
Definition: i386-dis.c:415
UCHAR WINAPI getAH(VOID)
Definition: registers.c:128
BYTE ExtendedCode
Definition: condrv.c:27
ULONG WINAPI getZF(VOID)
Definition: registers.c:608
UCHAR WINAPI getAL(VOID)
Definition: registers.c:142
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
VOID ConDrvCleanup(VOID)
Definition: condrv.c:147
CALLBACK16 DosContext
Definition: dos.c:40
WORD NTAPI ConDrvInputStatus(PDOS_DEVICE_NODE Device)
Definition: condrv.c:79
WORD NTAPI ConDrvClose(PDOS_DEVICE_NODE Device)
Definition: condrv.c:124
VOID DosDeleteDevice(PDOS_DEVICE_NODE DeviceNode)
Definition: device.c:419
smooth NULL
Definition: ftsmooth.c:416
PDOS_DEVICE_NODE DosCreateDevice(WORD Attributes, PCHAR DeviceName)
Definition: device.c:413
void DPRINT(...)
Definition: polytest.cpp:61
PDOS_DEVICE_GENERIC_ROUTINE OpenRoutine
Definition: device.h:101
Definition: bufpool.h:45
#define FAR_POINTER(x)
Definition: emulator.h:31
PDOS_DEVICE_IO_ROUTINE WriteRoutine
Definition: device.h:98
#define PCHAR
Definition: match.c:90
WORD * PWORD
Definition: pedump.c:67
WORD NTAPI ConDrvReadInput(PDOS_DEVICE_NODE Device, DWORD Buffer, PWORD Length)
Definition: condrv.c:31
PDOS_DEVICE_NODE Con
Definition: condrv.c:26
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID ConDrvInitialize(VOID)
Definition: condrv.c:132
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
USHORT WINAPI getAX(VOID)
Definition: registers.c:114
unsigned char BYTE
Definition: mem.h:68
PDOS_DEVICE_GENERIC_ROUTINE CloseRoutine
Definition: device.h:102
WORD NTAPI ConDrvWriteOutput(PDOS_DEVICE_NODE Device, DWORD Buffer, PWORD Length)
Definition: condrv.c:96
#define DOS_DEVSTAT_DONE
Definition: device.h:49
#define DOS_DEVSTAT_BUSY
Definition: device.h:50
#define DOS_DEVATTR_CHARACTER
Definition: device.h:29
WORD NTAPI ConDrvOpen(PDOS_DEVICE_NODE Device)
Definition: condrv.c:118
unsigned short USHORT
Definition: pedump.c:61
PDOS_DEVICE_GENERIC_ROUTINE InputStatusRoutine
Definition: device.h:95
PDOS_DEVICE_IO_ROUTINE ReadRoutine
Definition: device.h:93
#define BIOS_KBD_INTERRUPT
Definition: kbdbios.h:14
#define DOS_DEVATTR_STDOUT
Definition: device.h:22
#define DOS_DEVATTR_STDIN
Definition: device.h:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255