Added D-Flat/32 library
[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 ALT_A,ALT_B,ALT_C,ALT_D,ALT_E,ALT_F,ALT_G,ALT_H,
14 ALT_I,ALT_J,ALT_K,ALT_L,ALT_M,ALT_N,ALT_O,ALT_P,
15 ALT_Q,ALT_R,ALT_S,ALT_T,ALT_U,ALT_V,ALT_W,ALT_X,
16 ALT_Y,ALT_Z,ALT_0,ALT_1,ALT_2,ALT_3,ALT_4,ALT_5,
17 ALT_6,ALT_7,ALT_8,ALT_9
18 };
19 #endif
20
21 static int cursorpos[MAXSAVES];
22 static int cursorshape[MAXSAVES];
23 static int cs;
24
25
26 void SwapCursorStack(void)
27 {
28 if (cs > 1) {
29 swap(cursorpos[cs-2], cursorpos[cs-1]);
30 swap(cursorshape[cs-2], cursorshape[cs-1]);
31 }
32 }
33
34
35 /* ---- Read a keystroke ---- */
36 void GetKey (PINPUT_RECORD lpBuffer)
37 {
38 HANDLE hInput;
39 DWORD dwRead;
40
41 hInput = GetStdHandle (STD_INPUT_HANDLE);
42
43 do
44 {
45 // WaitForSingleObject (hInput, INFINITE);
46 ReadConsoleInput (hInput, lpBuffer, 1, &dwRead);
47 if ((lpBuffer->EventType == KEY_EVENT) &&
48 (lpBuffer->Event.KeyEvent.bKeyDown == TRUE))
49 break;
50 }
51 while (TRUE);
52 }
53
54
55 /* ---------- read the keyboard shift status --------- */
56 int getshift(void)
57 {
58 // regs.h.ah = 2;
59 // int86(KEYBRD, &regs, &regs);
60 // return regs.h.al;
61 /* FIXME */
62
63 return 0;
64 }
65
66
67 /* -------- sound a buzz tone ---------- */
68 void beep(void)
69 {
70 Beep(440, 50);
71 // MessageBeep (-1);
72 }
73
74
75 /* ------ position the cursor ------ */
76 void cursor(int x, int y)
77 {
78 COORD coPos;
79
80 coPos.X = (USHORT)x;
81 coPos.Y = (USHORT)y;
82 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coPos);
83 }
84
85 /* ------ get cursor shape and position ------ */
86 static void getcursor(void)
87 {
88 /*
89 videomode();
90 regs.h.ah = READCURSOR;
91 regs.x.bx = video_page;
92 int86(VIDEO, &regs, &regs);
93 */
94 /* FIXME */
95 }
96
97 /* ------- get the current cursor position ------- */
98
99 void curr_cursor(int *x, int *y)
100 //VOID GetCursorXY (PSHORT x, PSHORT y)
101 {
102 CONSOLE_SCREEN_BUFFER_INFO csbi;
103
104 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi);
105
106 *x = (int)csbi.dwCursorPosition.X;
107 *y = (int)csbi.dwCursorPosition.Y;
108 }
109
110
111 /* ------ save the current cursor configuration ------ */
112 void savecursor(void)
113 {
114 /*
115 if (cs < MAXSAVES) {
116 getcursor();
117 cursorshape[cs] = regs.x.cx;
118 cursorpos[cs] = regs.x.dx;
119 cs++;
120 }
121 */
122 }
123
124 /* ---- restore the saved cursor configuration ---- */
125 void restorecursor(void)
126 {
127 /*
128 if (cs) {
129 --cs;
130 videomode();
131 regs.x.dx = cursorpos[cs];
132 regs.h.ah = SETCURSOR;
133 regs.x.bx = video_page;
134 int86(VIDEO, &regs, &regs);
135 set_cursor_type(cursorshape[cs]);
136 }
137 */
138 }
139
140 /* ------ make a normal cursor ------ */
141 void normalcursor(void)
142 {
143 // set_cursor_type(0x0607);
144 }
145
146 /* ------ hide the cursor ------ */
147 void hidecursor(void)
148 {
149 /*
150 getcursor();
151 regs.h.ch |= HIDECURSOR;
152 regs.h.ah = SETCURSORTYPE;
153 int86(VIDEO, &regs, &regs);
154 */
155 }
156
157 /* ------ unhide the cursor ------ */
158 void unhidecursor(void)
159 {
160 /*
161 getcursor();
162 regs.h.ch &= ~HIDECURSOR;
163 regs.h.ah = SETCURSORTYPE;
164 int86(VIDEO, &regs, &regs);
165 */
166 }
167
168 /* ---- use BIOS to set the cursor type ---- */
169 void set_cursor_type(unsigned t)
170 {
171 /*
172 videomode();
173 regs.h.ah = SETCURSORTYPE;
174 regs.x.bx = video_page;
175 regs.x.cx = t;
176 int86(VIDEO, &regs, &regs);
177 */
178 }
179
180
181 /* ------ convert an Alt+ key to its letter equivalent ----- */
182 int AltConvert(int c)
183 {
184 return c;
185 #if 0
186 int i, a = 0;
187 for (i = 0; i < 36; i++)
188 if (c == altconvert[i])
189 break;
190 if (i < 26)
191 a = 'a' + i;
192 else if (i < 36)
193 a = '0' + i - 26;
194 return a;
195 #endif
196 }
197
198 /* EOF */