| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/msdos/ossdos32.c,v 1.2 1999/05/17 02:52:19 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <windows.h> |
| 24 |
#include <wincon.h> |
| 25 |
#include <string.h> |
| 26 |
#include "os.h" |
| 27 |
#include "osgen.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
HANDLE G_out_bufhdl; |
| 33 |
HANDLE G_in_bufhdl; |
| 34 |
|
| 35 |
|
| 36 |
extern int os_f_plain; |
| 37 |
|
| 38 |
|
| 39 |
static DWORD S_orig_console_out_mode; |
| 40 |
static DWORD S_orig_console_in_mode; |
| 41 |
|
| 42 |
|
| 43 |
static int S_scrwid; |
| 44 |
|
| 45 |
|
| 46 |
static COORD S_orig_buffer_size; |
| 47 |
|
| 48 |
|
| 49 |
void oss_con_init(void) |
| 50 |
{ |
| 51 |
DWORD new_console_mode; |
| 52 |
OSVERSIONINFO ver_info; |
| 53 |
|
| 54 |
|
| 55 |
G_out_bufhdl = GetStdHandle(STD_OUTPUT_HANDLE); |
| 56 |
G_in_bufhdl = GetStdHandle(STD_INPUT_HANDLE); |
| 57 |
|
| 58 |
|
| 59 |
GetConsoleMode(G_out_bufhdl, &S_orig_console_out_mode); |
| 60 |
GetConsoleMode(G_in_bufhdl, &S_orig_console_in_mode); |
| 61 |
|
| 62 |
|
| 63 |
if (os_f_plain) |
| 64 |
return; |
| 65 |
|
| 66 |
|
| 67 |
new_console_mode = S_orig_console_out_mode; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
new_console_mode &= ~ENABLE_WRAP_AT_EOL_OUTPUT; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
ver_info.dwOSVersionInfoSize = sizeof(ver_info); |
| 86 |
GetVersionEx(&ver_info); |
| 87 |
if (ver_info.dwPlatformId != VER_PLATFORM_WIN32_NT) |
| 88 |
new_console_mode &= ~ENABLE_PROCESSED_OUTPUT; |
| 89 |
|
| 90 |
|
| 91 |
SetConsoleMode(G_out_bufhdl, new_console_mode); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
void oss_con_uninit(void) |
| 96 |
{ |
| 97 |
CONSOLE_SCREEN_BUFFER_INFO info; |
| 98 |
extern int os_f_plain; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
if (!os_f_plain) |
| 111 |
{ |
| 112 |
|
| 113 |
GetConsoleScreenBufferInfo(G_out_bufhdl, &info); |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
if (info.dwCursorPosition.X != 0) |
| 123 |
{ |
| 124 |
|
| 125 |
ossdsp(info.dwCursorPosition.Y, info.dwCursorPosition.X, |
| 126 |
ossgetcolor(OSGEN_COLOR_TEXT, OSGEN_COLOR_TEXTBG, 0, 0), |
| 127 |
"\n"); |
| 128 |
} |
| 129 |
else |
| 130 |
{ |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
ossdsp(info.dwCursorPosition.Y, info.dwCursorPosition.X, |
| 136 |
ossgetcolor(OSGEN_COLOR_TEXT, OSGEN_COLOR_TEXTBG, 0, 0), |
| 137 |
" "); |
| 138 |
|
| 139 |
|
| 140 |
ossloc(info.dwCursorPosition.Y, info.dwCursorPosition.X); |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
GetConsoleScreenBufferInfo(G_out_bufhdl, &info); |
| 145 |
ossclr(info.dwCursorPosition.Y, 0, |
| 146 |
G_oss_screen_height - 1, G_oss_screen_width - 1, |
| 147 |
ossgetcolor(OSGEN_COLOR_TEXT, OSGEN_COLOR_TEXTBG, 0, 0)); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
SetConsoleMode(G_out_bufhdl, S_orig_console_out_mode); |
| 152 |
SetConsoleMode(G_in_bufhdl, S_orig_console_in_mode); |
| 153 |
|
| 154 |
|
| 155 |
if (!os_f_plain && GetConsoleScreenBufferInfo(G_out_bufhdl, &info)) |
| 156 |
{ |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
if (info.dwSize.X > S_orig_buffer_size.X) |
| 165 |
S_orig_buffer_size.X = info.dwSize.X; |
| 166 |
if (info.dwSize.Y > S_orig_buffer_size.Y) |
| 167 |
S_orig_buffer_size.Y = info.dwSize.Y; |
| 168 |
|
| 169 |
|
| 170 |
SetConsoleScreenBufferSize(G_out_bufhdl, S_orig_buffer_size); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
void oss_win_resize_event() |
| 176 |
{ |
| 177 |
CONSOLE_SCREEN_BUFFER_INFO info; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
if (!os_f_plain && GetConsoleScreenBufferInfo(G_out_bufhdl, &info)) |
| 187 |
{ |
| 188 |
COORD buf_size; |
| 189 |
|
| 190 |
|
| 191 |
info.srWindow.Bottom -= info.srWindow.Top; |
| 192 |
info.srWindow.Top = 0; |
| 193 |
info.srWindow.Right -= info.srWindow.Left; |
| 194 |
info.srWindow.Left = 0; |
| 195 |
SetConsoleWindowInfo(G_out_bufhdl, TRUE, &info.srWindow); |
| 196 |
|
| 197 |
|
| 198 |
buf_size.X = info.srWindow.Right + 1; |
| 199 |
buf_size.Y = info.srWindow.Bottom + 1; |
| 200 |
SetConsoleScreenBufferSize(G_out_bufhdl, buf_size); |
| 201 |
|
| 202 |
|
| 203 |
G_oss_screen_height = buf_size.Y; |
| 204 |
G_oss_screen_width = buf_size.X; |
| 205 |
|
| 206 |
|
| 207 |
osssb_on_resize_screen(); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
void ossscu(int top, int left, int bottom, int right, int blankcolor) |
| 213 |
{ |
| 214 |
COORD newpos; |
| 215 |
SMALL_RECT pos; |
| 216 |
SMALL_RECT clip; |
| 217 |
CHAR_INFO fill; |
| 218 |
|
| 219 |
pos.Top = clip.Top = top; |
| 220 |
pos.Left = clip.Left = left; |
| 221 |
pos.Bottom = clip.Bottom = bottom; |
| 222 |
pos.Right = clip.Right = right; |
| 223 |
|
| 224 |
newpos.X = left; |
| 225 |
newpos.Y = top + 1; |
| 226 |
|
| 227 |
fill.Char.AsciiChar = ' '; |
| 228 |
fill.Attributes = blankcolor; |
| 229 |
|
| 230 |
ScrollConsoleScreenBuffer(G_out_bufhdl, &pos, &clip, newpos, &fill); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
void ossscr(int top, int left, int bottom, int right, int blankcolor) |
| 235 |
{ |
| 236 |
COORD newpos; |
| 237 |
SMALL_RECT pos; |
| 238 |
SMALL_RECT clip; |
| 239 |
CHAR_INFO fill; |
| 240 |
|
| 241 |
pos.Top = clip.Top = top; |
| 242 |
pos.Left = clip.Left = left; |
| 243 |
pos.Bottom = clip.Bottom = bottom; |
| 244 |
pos.Right = clip.Right = right; |
| 245 |
|
| 246 |
newpos.X = left; |
| 247 |
newpos.Y = top - 1; |
| 248 |
|
| 249 |
fill.Char.AsciiChar = ' '; |
| 250 |
fill.Attributes = blankcolor; |
| 251 |
|
| 252 |
ScrollConsoleScreenBuffer(G_out_bufhdl, &pos, &clip, newpos, &fill); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
void ossclr(int top, int left, int bottom, int right, int color) |
| 257 |
{ |
| 258 |
int curline; |
| 259 |
DWORD line_len; |
| 260 |
|
| 261 |
|
| 262 |
line_len = right - left + 1; |
| 263 |
|
| 264 |
|
| 265 |
for (curline = top ; curline <= bottom ; ++curline) |
| 266 |
{ |
| 267 |
COORD pos; |
| 268 |
DWORD actual; |
| 269 |
|
| 270 |
pos.X = left; |
| 271 |
pos.Y = curline; |
| 272 |
FillConsoleOutputAttribute(G_out_bufhdl, (WORD)color, line_len, |
| 273 |
pos, &actual); |
| 274 |
FillConsoleOutputCharacter(G_out_bufhdl, ' ', line_len, |
| 275 |
pos, &actual); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
void ossloc(int line, int column) |
| 281 |
{ |
| 282 |
COORD pos; |
| 283 |
CONSOLE_SCREEN_BUFFER_INFO info; |
| 284 |
|
| 285 |
|
| 286 |
if (GetConsoleScreenBufferInfo(G_out_bufhdl, &info) |
| 287 |
&& info.dwCursorPosition.X == column |
| 288 |
&& info.dwCursorPosition.Y == line) |
| 289 |
return; |
| 290 |
|
| 291 |
|
| 292 |
pos.X = column; |
| 293 |
pos.Y = line; |
| 294 |
SetConsoleCursorPosition(G_out_bufhdl, pos); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
int ossmon(void) |
| 299 |
{ |
| 300 |
return 0; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
void ossdsp(int line, int column, int color, const char *msg) |
| 305 |
{ |
| 306 |
COORD pos; |
| 307 |
DWORD nwritten; |
| 308 |
|
| 309 |
pos.X = column; |
| 310 |
pos.Y = line; |
| 311 |
SetConsoleTextAttribute(G_out_bufhdl, (WORD)color); |
| 312 |
SetConsoleCursorPosition(G_out_bufhdl, pos); |
| 313 |
WriteConsole(G_out_bufhdl, msg, strlen(msg), &nwritten, 0); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
void ossgmx(int *max_linep, int *max_columnp) |
| 318 |
{ |
| 319 |
CONSOLE_SCREEN_BUFFER_INFO info; |
| 320 |
|
| 321 |
|
| 322 |
G_out_bufhdl = GetStdHandle(STD_OUTPUT_HANDLE); |
| 323 |
|
| 324 |
|
| 325 |
if (GetConsoleScreenBufferInfo(G_out_bufhdl, &info)) |
| 326 |
{ |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
if (!os_f_plain |
| 335 |
&& (info.srWindow.Top != 0 || info.srWindow.Left != 0 |
| 336 |
|| info.dwSize.X > info.srWindow.Right + 1 |
| 337 |
|| info.dwSize.Y > info.srWindow.Bottom + 1)) |
| 338 |
{ |
| 339 |
COORD buf_size; |
| 340 |
|
| 341 |
|
| 342 |
info.srWindow.Bottom -= info.srWindow.Top; |
| 343 |
info.srWindow.Top = 0; |
| 344 |
info.srWindow.Right -= info.srWindow.Left; |
| 345 |
info.srWindow.Left = 0; |
| 346 |
SetConsoleWindowInfo(G_out_bufhdl, TRUE, &info.srWindow); |
| 347 |
|
| 348 |
|
| 349 |
S_orig_buffer_size = info.dwSize; |
| 350 |
|
| 351 |
|
| 352 |
buf_size.X = info.srWindow.Right + 1; |
| 353 |
buf_size.Y = info.srWindow.Bottom + 1; |
| 354 |
SetConsoleScreenBufferSize(G_out_bufhdl, buf_size); |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
*max_columnp = info.srWindow.Right - info.srWindow.Left; |
| 359 |
*max_linep = info.srWindow.Bottom - info.srWindow.Top; |
| 360 |
} |
| 361 |
else |
| 362 |
{ |
| 363 |
|
| 364 |
*max_columnp = 79; |
| 365 |
*max_linep = 24; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
S_scrwid = info.dwMaximumWindowSize.X; |
| 370 |
} |