1 /* ----------- console.c ---------- */
3 #define WIN32_LEAN_AND_MEAN
10 /* ----- table of alt keys for finding shortcut keys ----- */
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
21 static int cursorpos
[MAXSAVES
];
22 static int cursorshape
[MAXSAVES
];
26 void SwapCursorStack(void)
29 swap(cursorpos
[cs
-2], cursorpos
[cs
-1]);
30 swap(cursorshape
[cs
-2], cursorshape
[cs
-1]);
35 /* ---- Read a keystroke ---- */
36 void GetKey (PINPUT_RECORD lpBuffer
)
41 hInput
= GetStdHandle (STD_INPUT_HANDLE
);
45 // WaitForSingleObject (hInput, INFINITE);
46 ReadConsoleInput (hInput
, lpBuffer
, 1, &dwRead
);
47 if ((lpBuffer
->EventType
== KEY_EVENT
) &&
48 (lpBuffer
->Event
.KeyEvent
.bKeyDown
== TRUE
))
55 /* ---------- read the keyboard shift status --------- */
59 // int86(KEYBRD, ®s, ®s);
67 /* -------- sound a buzz tone ---------- */
75 /* ------ position the cursor ------ */
76 void cursor(int x
, int y
)
82 SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE
), coPos
);
85 /* ------ get cursor shape and position ------ */
86 static void getcursor(void)
90 regs.h.ah = READCURSOR;
91 regs.x.bx = video_page;
92 int86(VIDEO, ®s, ®s);
97 /* ------- get the current cursor position ------- */
99 void curr_cursor(int *x
, int *y
)
100 //VOID GetCursorXY (PSHORT x, PSHORT y)
102 CONSOLE_SCREEN_BUFFER_INFO csbi
;
104 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE
), &csbi
);
106 *x
= (int)csbi
.dwCursorPosition
.X
;
107 *y
= (int)csbi
.dwCursorPosition
.Y
;
111 /* ------ save the current cursor configuration ------ */
112 void savecursor(void)
117 cursorshape[cs] = regs.x.cx;
118 cursorpos[cs] = regs.x.dx;
124 /* ---- restore the saved cursor configuration ---- */
125 void restorecursor(void)
131 regs.x.dx = cursorpos[cs];
132 regs.h.ah = SETCURSOR;
133 regs.x.bx = video_page;
134 int86(VIDEO, ®s, ®s);
135 set_cursor_type(cursorshape[cs]);
140 /* ------ make a normal cursor ------ */
141 void normalcursor(void)
143 // set_cursor_type(0x0607);
146 /* ------ hide the cursor ------ */
147 void hidecursor(void)
151 regs.h.ch |= HIDECURSOR;
152 regs.h.ah = SETCURSORTYPE;
153 int86(VIDEO, ®s, ®s);
157 /* ------ unhide the cursor ------ */
158 void unhidecursor(void)
162 regs.h.ch &= ~HIDECURSOR;
163 regs.h.ah = SETCURSORTYPE;
164 int86(VIDEO, ®s, ®s);
168 /* ---- use BIOS to set the cursor type ---- */
169 void set_cursor_type(unsigned t
)
173 regs.h.ah = SETCURSORTYPE;
174 regs.x.bx = video_page;
176 int86(VIDEO, ®s, ®s);
181 /* ------ convert an Alt+ key to its letter equivalent ----- */
182 int AltConvert(int c
)
187 for (i
= 0; i
< 36; i
++)
188 if (c
== altconvert
[i
])