Force Nagle algorithm off for loopback
[reactos.git] / rosapps / dflat32 / console.c
1 /* ----------- console.c ---------- */
2
3 #define WIN32_LEAN_AND_MEAN
4 #include <windows.h>
5
6
7 #include "dflat.h"
8
9
10 /* ----- table of alt keys for finding shortcut keys ----- */
11 #if 0
12 static int altconvert[] = {
13 DF_ALT_A,DF_ALT_B,DF_ALT_C,DF_ALT_D,DF_ALT_E,DF_ALT_F,DF_ALT_G,DF_ALT_H,
14 DF_ALT_I,DF_ALT_J,DF_ALT_K,DF_ALT_L,DF_ALT_M,DF_ALT_N,DF_ALT_O,DF_ALT_P,
15 DF_ALT_Q,DF_ALT_R,DF_ALT_S,DF_ALT_T,DF_ALT_U,DF_ALT_V,DF_ALT_W,DF_ALT_X,
16 DF_ALT_Y,DF_ALT_Z,DF_ALT_0,DF_ALT_1,DF_ALT_2,DF_ALT_3,DF_ALT_4,DF_ALT_5,
17 DF_ALT_6,DF_ALT_7,DF_ALT_8,DF_ALT_9
18 };
19 #endif
20
21 static COORD cursorpos[DF_MAXSAVES];
22 static CONSOLE_CURSOR_INFO cursorinfo[DF_MAXSAVES];
23 static int cs = 0;
24
25
26 void DfSwapCursorStack(void)
27 {
28 if (cs > 1)
29 {
30 COORD coord;
31 CONSOLE_CURSOR_INFO csi;
32
33 coord = cursorpos[cs-2];
34 cursorpos[cs-2] = cursorpos[cs-1];
35 cursorpos[cs-1] = coord;
36
37 memcpy (&csi,
38 &cursorinfo[cs-2],
39 sizeof(CONSOLE_CURSOR_INFO));
40 memcpy (&cursorinfo[cs-2],
41 &cursorinfo[cs-1],
42 sizeof(CONSOLE_CURSOR_INFO));
43 memcpy (&cursorinfo[cs-1],
44 &csi,
45 sizeof(CONSOLE_CURSOR_INFO));
46 }
47 }
48
49
50 /* ---- Read a keystroke ---- */
51 void DfGetKey (PINPUT_RECORD lpBuffer)
52 {
53 HANDLE DfInput;
54 DWORD dwRead;
55
56 DfInput = GetStdHandle (STD_INPUT_HANDLE);
57
58 do
59 {
60 // WaitForSingleObject (DfInput, INFINITE);
61 ReadConsoleInput (DfInput, lpBuffer, 1, &dwRead);
62 if ((lpBuffer->EventType == KEY_EVENT) &&
63 (lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
64 break;
65 }
66 while (TRUE);
67 }
68
69
70 /* ---------- read the keyboard shift status --------- */
71
72 int DfGetShift(void)
73 {
74 // regs.h.ah = 2;
75 // int86(KEYBRD, &regs, &regs);
76 // return regs.h.al;
77 /* FIXME */
78
79 return 0;
80 }
81
82
83 /* -------- sound a buzz tone ---------- */
84 void DfBeep(void)
85 {
86 Beep(440, 50);
87 // MessageBeep (-1);
88 }
89
90
91 /* ------ position the DfCursor ------ */
92 void DfCursor(int x, int y)
93 {
94 COORD coPos;
95
96 coPos.X = (USHORT)x;
97 coPos.Y = (USHORT)y;
98 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
99 }
100
101
102 /* ------- get the current DfCursor position ------- */
103 void DfCurrCursor(int *x, int *y)
104 //VOID GetCursorXY (PSHORT x, PSHORT y)
105 {
106 CONSOLE_SCREEN_BUFFER_INFO csbi;
107
108 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
109
110 *x = (int)csbi.dwCursorPosition.X;
111 *y = (int)csbi.dwCursorPosition.Y;
112 }
113
114
115 /* ------ save the current DfCursor configuration ------ */
116 void DfSaveCursor(void)
117 {
118 if (cs < DF_MAXSAVES)
119 {
120 CONSOLE_SCREEN_BUFFER_INFO csbi;
121
122 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
123 cursorpos[cs].X = csbi.dwCursorPosition.X;
124 cursorpos[cs].Y = csbi.dwCursorPosition.Y;
125
126 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
127 &(cursorinfo[cs]));
128
129 cs++;
130 }
131 }
132
133 /* ---- restore the saved DfCursor configuration ---- */
134 void DfRestoreCursor(void)
135 {
136 if (cs)
137 {
138 --cs;
139 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE),
140 cursorpos[cs]);
141 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
142 &(cursorinfo[cs]));
143 }
144 }
145
146 /* ------ make a normal DfCursor ------ */
147 void DfNormalCursor(void)
148 {
149 CONSOLE_CURSOR_INFO csi;
150
151 csi.bVisible = TRUE;
152 csi.dwSize = 5;
153 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
154 &csi);
155 }
156
157 /* ------ hide the DfCursor ------ */
158 void DfHideCursor(void)
159 {
160 CONSOLE_CURSOR_INFO csi;
161
162 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
163 &csi);
164 csi.bVisible = FALSE;
165 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
166 &csi);
167 }
168
169 /* ------ unhide the DfCursor ------ */
170 void DfUnhideCursor(void)
171 {
172 CONSOLE_CURSOR_INFO csi;
173
174 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
175 &csi);
176 csi.bVisible = TRUE;
177 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
178 &csi);
179 }
180
181 /* set the DfCursor size (in percent) */
182 void DfSetCursorSize (unsigned t)
183 {
184 CONSOLE_CURSOR_INFO csi;
185
186 GetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
187 &csi);
188
189 if (t < 2)
190 csi.dwSize = 2;
191 else if (t > 90)
192 csi.dwSize = 90;
193 else
194 csi.dwSize = t;
195 SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
196 &csi);
197 }
198
199
200 /* ------ convert an Alt+ key to its letter equivalent ----- */
201 int DfAltConvert(int c)
202 {
203 return c;
204 #if 0
205 int i, a = 0;
206 for (i = 0; i < 36; i++)
207 if (c == altconvert[i])
208 break;
209 if (i < 26)
210 a = 'a' + i;
211 else if (i < 36)
212 a = '0' + i - 26;
213 return a;
214 #endif
215 }
216
217 /* EOF */