Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
mono.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /G/wwlib/mono.cpp $*
26 * *
27 * $Author:: Neal_k $*
28 * *
29 * $Modtime:: 10/04/99 10:25a $*
30 * *
31 * $Revision:: 3 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * MonoClass::Clear -- Clears the monochrome screen object. *
36 * MonoClass::Draw_Box -- Draws a box using the IBM linedraw characters. *
37 * MonoClass::Fill_Attrib -- Fill a block with specified attribute. *
38 * MonoClass::MonoClass -- The default constructor for monochrome screen object. *
39 * MonoClass::Pan -- Scroll the window right or left. *
40 * MonoClass::Print -- Prints the text string at the current cursor coordinates. *
41 * MonoClass::Print -- Simple print of text number. *
42 * MonoClass::Printf -- Prints a formatted string to the monochrome screen. *
43 * MonoClass::Printf -- Prints formatted text using text string number. *
44 * MonoClass::Scroll -- Scroll the monochrome screen up by the specified lines. *
45 * MonoClass::Set_Cursor -- Sets the monochrome cursor to the coordinates specified. *
46 * MonoClass::Sub_Window -- Partitions the mono screen into a sub-window. *
47 * MonoClass::Text_Print -- Prints text to the monochrome object at coordinates indicated. *
48 * MonoClass::Text_Print -- Simple text printing from text number. *
49 * MonoClass::View -- Brings the mono object to the main display. *
50 * MonoClass::operator = -- Handles making one mono object have the same imagery as another. *
51 * MonoClass::~MonoClass -- The default destructor for a monochrome screen object. *
52 * Mono_Clear_Screen -- Clear the currently visible monochrome page. *
53 * Mono_Draw_Rect -- Draws rectangle to monochrome screen. *
54 * Mono_Print -- Prints simple text to monochrome screen. *
55 * Mono_Printf -- Prints formatted text to visible page. *
56 * Mono_Text_Print -- Prints text to location specified. *
57 * Mono_X -- Fetches the X cursor position for current visible mono page. *
58 * Mono_Y -- Fetches the Y cursor position for current mono page. *
59 * MonoClass::Set_Default_Attribute -- Set the default attribute for this window. *
60 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
61
62#include "always.h"
63#include "data.h"
64#include "mono.h"
65#include "monodrvr.h"
66#include <stdio.h>
67
68
69/*
70** Global flag to indicate whether mono output is enabled. If it is not enabled,
71** then no mono output will occur.
72*/
73bool MonoClass::Enabled = false;
74
75
76/*
77** This points to the current mono displayed screen.
78*/
80
81
82/***********************************************************************************************
83 * MonoClass::MonoClass -- The default constructor for monochrome screen object. *
84 * *
85 * This is the constructor for monochrome screen objects. It handles allocating a free *
86 * monochrome page. If there are no more pages available, then this is a big error. The *
87 * page allocated may not be the visible one. Call the View function in order to bring *
88 * it to the displayed page. *
89 * *
90 * INPUT: none *
91 * *
92 * OUTPUT: none *
93 * *
94 * WARNINGS: none *
95 * *
96 * HISTORY: *
97 * 10/17/1994 JLB : Created. *
98 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
99 *=============================================================================================*/
101 Handle(INVALID_HANDLE_VALUE)
102{
103#ifdef _WINDOWS
104 Handle = CreateFile("\\\\.\\MONO", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
105 if (Current == NULL) {
106 Current = this;
107 }
108#endif
109}
110
111
112/***********************************************************************************************
113 * MonoClass::~MonoClass -- The default destructor for a monochrome screen object. *
114 * *
115 * This is the default destructor for a monochrome screen object. *
116 * *
117 * INPUT: none *
118 * *
119 * OUTPUT: none *
120 * *
121 * WARNINGS: none *
122 * *
123 * HISTORY: *
124 * 10/17/1994 JLB : Created. *
125 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
126 *=============================================================================================*/
128{
129#ifdef _WINDOWS
130 if (Handle != INVALID_HANDLE_VALUE) {
131 CloseHandle(Handle);
132 Handle = INVALID_HANDLE_VALUE;
133 }
134 if (Current == this) {
135 Current = NULL;
136 }
137#endif
138}
139
140
141/***********************************************************************************************
142 * MonoClass::Pan -- Scroll the window right or left. *
143 * *
144 * This routine will scroll the window to the right or left as indicated by the number of *
145 * rows. *
146 * *
147 * INPUT: cols -- The number of columns to pan the window. Positive numbers pan to the left *
148 * while negative numbers pan to the right. *
149 * *
150 * OUTPUT: none *
151 * *
152 * WARNINGS: none *
153 * *
154 * HISTORY: *
155 * 06/05/1996 JLB : Created. *
156 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
157 *=============================================================================================*/
159{
160#ifdef _WINDOWS
161 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
162 unsigned long retval;
163 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_PAN, NULL, 0, NULL, 0, &retval, 0);
164 }
165#endif
166}
167
168
169/***********************************************************************************************
170 * MonoClass::Sub_Window -- Partitions the mono screen into a sub-window. *
171 * *
172 * This routine is used to partition the monochrome screen so that only a sub-window will *
173 * be processed. By using this, a separate rectangle of the screen can be cleared, *
174 * scrolled, panned, or printed into. *
175 * *
176 * INPUT: x,y -- The upper left corner of the new sub-window. *
177 * *
178 * w,h -- Dimensions of the sub-window specified in characters. *
179 * *
180 * OUTPUT: none *
181 * *
182 * WARNINGS: The parameters are clipped as necessary. *
183 * *
184 * HISTORY: *
185 * 06/05/1996 JLB : Created. *
186 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
187 *=============================================================================================*/
188void MonoClass::Sub_Window(int x, int y, int w, int h)
189{
190#ifdef _WINDOWS
191 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
192 struct subwindow {
193 int X,Y,W,H;
194 } subwindow;
195 unsigned long retval;
196
197 subwindow.X = x;
198 subwindow.Y = y;
199 subwindow.W = w;
200 subwindow.H = h;
201 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_SET_WINDOW, &subwindow, sizeof(subwindow), NULL, 0, &retval, 0);
202 }
203#endif
204}
205
206
207/***********************************************************************************************
208 * MonoClass::Set_Cursor -- Sets the monochrome cursor to the coordinates specified. *
209 * *
210 * Use this routine to set the monochrome's cursor position to the coordinates specified. *
211 * This is the normal way of controlling where the next Print or Printf will output the *
212 * text to. *
213 * *
214 * INPUT: x,y -- The coordinate to position the monochrome cursor. 0,0 is the upper left *
215 * corner. *
216 * *
217 * OUTPUT: none *
218 * *
219 * WARNINGS: none *
220 * *
221 * HISTORY: *
222 * 10/17/1994 JLB : Created. *
223 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
224 *=============================================================================================*/
225void MonoClass::Set_Cursor(int x, int y)
226{
227#ifdef _WINDOWS
228 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
229 struct {
230 int X,Y;
231 } cursor;
232 unsigned long retval;
233
234 cursor.X = x;
235 cursor.Y = y;
236 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_SET_CURSOR, &cursor, sizeof(cursor), NULL, 0, &retval, 0);
237 }
238#endif
239}
240
241
242/***********************************************************************************************
243 * MonoClass::Clear -- Clears the monochrome screen object. *
244 * *
245 * This routine will fill the monochrome screen object with spaces. It is clearing the *
246 * screen of data, making it free for output. The cursor is positioned at the upper left *
247 * corner of the screen by this routine. *
248 * *
249 * INPUT: none *
250 * *
251 * OUTPUT: none *
252 * *
253 * WARNINGS: none *
254 * *
255 * HISTORY: *
256 * 10/17/1994 JLB : Created. *
257 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
258 *=============================================================================================*/
260{
261#ifdef _WINDOWS
262 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
263 unsigned long retval;
264
265 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_CLEAR_SCREEN, NULL, 0, NULL, 0, &retval, 0);
266 }
267#endif
268}
269
270
271/***********************************************************************************************
272 * MonoClass::Fill_Attrib -- Fill a block with specified attribute. *
273 * *
274 * This routine will give the specified attribute to the characters within the block *
275 * but will not change the characters themselves. You can use this routine to change the *
276 * underline, blink, or inverse characteristics of text. *
277 * *
278 * INPUT: x,y -- The upper left coordinate of the region to change. *
279 * *
280 * w,h -- The dimensions of the region to change (in characters). *
281 * *
282 * attrib -- The attribute to fill into the region specified. *
283 * *
284 * OUTPUT: none *
285 * *
286 * WARNINGS: none *
287 * *
288 * HISTORY: *
289 * 06/04/1996 JLB : Created. *
290 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
291 *=============================================================================================*/
292void MonoClass::Fill_Attrib(int x, int y, int w, int h, MonoAttribute attrib)
293{
294#ifdef _WINDOWS
295 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
296 unsigned long retval;
297 struct fillcontrol {
298 int X,Y,W,H,A;
299 } fillcontrol;
300
301
302 fillcontrol.X = x;
303 fillcontrol.Y = y;
304 fillcontrol.W = w;
305 fillcontrol.H = h;
306 fillcontrol.A = attrib;
307 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_FILL_ATTRIB, &fillcontrol, sizeof(fillcontrol), NULL, 0, &retval, 0);
308 }
309#endif
310}
311
312
313/***********************************************************************************************
314 * MonoClass::Scroll -- Scroll the monochrome screen up by the specified lines. *
315 * *
316 * Use this routine to scroll the monochrome screen up by the number of lines specified. *
317 * This routine is typically called by the printing functions so that the monochrome screen *
318 * behaves in the expected manner -- printing at the bottom of the screen scrolls it up *
319 * to make room for new text. *
320 * *
321 * INPUT: lines -- The number of lines to scroll the monochrome screen. *
322 * *
323 * OUTPUT: none *
324 * *
325 * WARNINGS: none *
326 * *
327 * HISTORY: *
328 * 10/17/1994 JLB : Created. *
329 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
330 *=============================================================================================*/
332{
333#ifdef _WINDOWS
334 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
335 unsigned long retval;
336 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_SCROLL, NULL, 0, NULL, 0, &retval, 0);
337 }
338#endif
339}
340
341
342/***********************************************************************************************
343 * MonoClass::Printf -- Prints a formatted string to the monochrome screen. *
344 * *
345 * Use this routine to output a formatted string, using the standard formatting options, *
346 * to the monochrome screen object's current cursor position. *
347 * *
348 * INPUT: text -- Pointer to the text to print. *
349 * *
350 * ... -- Any optional parameters to supply in formatting the text. *
351 * *
352 * OUTPUT: none *
353 * *
354 * WARNINGS: The total formatted text length must not exceed 255 characters. *
355 * *
356 * HISTORY: *
357 * 10/17/1994 JLB : Created. *
358 *=============================================================================================*/
359void MonoClass::Printf(char const *text, ...)
360{
361#ifdef _WINDOWS
362 va_list va;
363 /*
364 ** The buffer object is placed at the end of the local variable list
365 ** so that if the sprintf happens to spill past the end, it isn't likely
366 ** to trash anything (important). The buffer is then manually truncated
367 ** to maximum allowed size before being printed.
368 */
369 char buffer[256];
370
371 if ( !Enabled || (Handle == INVALID_HANDLE_VALUE) ) return;
372
373 va_start(va, text);
374 vsprintf(buffer, text, va);
375 buffer[sizeof(buffer)-1] = '\0';
376
377 Print(buffer);
378 va_end(va);
379#endif
380}
381
382
383/***********************************************************************************************
384 * MonoClass::Printf -- Prints formatted text using text string number. *
385 * *
386 * This routine will take the given text string number and print the formatted text to *
387 * the monochrome screen. *
388 * *
389 * INPUT: text -- The text number to convert into real text (by way of external function). *
390 * *
391 * ... -- Additional parameters as needed. *
392 * *
393 * OUTPUT: none *
394 * *
395 * WARNINGS: none *
396 * *
397 * HISTORY: *
398 * 06/04/1996 JLB : Created. *
399 *=============================================================================================*/
400void MonoClass::Printf(int text, ...)
401{
402#ifdef _WINDOWS
403 va_list va;
404
405 /*
406 ** The buffer object is placed at the end of the local variable list
407 ** so that if the sprintf happens to spill past the end, it isn't likely
408 ** to trash anything (important). The buffer is then manually truncated
409 ** to maximum allowed size before being printed.
410 */
411 char buffer[256];
412
413 if ( !Enabled || (Handle == INVALID_HANDLE_VALUE) ) return;
414
415 va_start(va, text);
416 vsprintf(buffer, Fetch_String(text), va);
417 buffer[sizeof(buffer)-1] = '\0';
418
419 Print(buffer);
420 va_end(va);
421#endif
422}
423
424
425/***********************************************************************************************
426 * MonoClass::Print -- Prints the text string at the current cursor coordinates. *
427 * *
428 * Use this routine to output the specified text string at the monochrome object's current *
429 * text coordinate position. *
430 * *
431 * INPUT: ptr -- Pointer to the string to print. *
432 * *
433 * OUTPUT: none *
434 * *
435 * WARNINGS: none *
436 * *
437 * HISTORY: *
438 * 10/17/1994 JLB : Created. *
439 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
440 *=============================================================================================*/
441void MonoClass::Print(char const * ptr)
442{
443#ifdef _WINDOWS
444 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
445 unsigned long retval;
446 WriteFile(Handle, ptr, strlen(ptr), &retval, NULL);
447 }
448#endif
449}
450
451
452/***********************************************************************************************
453 * MonoClass::Set_Default_Attribute -- Set the default attribute for this window. *
454 * *
455 * This will change the default attribute to that specified. All future text will use *
456 * this new attribute. *
457 * *
458 * INPUT: attrib -- The attribute to make the current default. *
459 * *
460 * OUTPUT: none *
461 * *
462 * WARNINGS: none *
463 * *
464 * HISTORY: *
465 * 01/06/1997 JLB : Created. *
466 *=============================================================================================*/
468{
469#ifdef _WINDOWS
470 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
471 unsigned long retval;
472 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_SET_ATTRIBUTE, &attrib, 1, NULL, 0, &retval, 0);
473 }
474#endif
475}
476
477
478/***********************************************************************************************
479 * MonoClass::Text_Print -- Prints text to the monochrome object at coordinates indicated. *
480 * *
481 * Use this routine to output text to the monochrome object at the X and Y coordinates *
482 * specified. *
483 * *
484 * INPUT: text -- Pointer to the text string to display. *
485 * *
486 * x,y -- The X and Y character coordinates to start the printing at. *
487 * *
488 * attrib-- Optional parameter that specifies what text attribute code to use. *
489 * *
490 * OUTPUT: none *
491 * *
492 * WARNINGS: none *
493 * *
494 * HISTORY: *
495 * 10/17/1994 JLB : Created. *
496 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
497 *=============================================================================================*/
498void MonoClass::Text_Print(char const *text, int x, int y, MonoAttribute attrib)
499{
500#ifdef _WINDOWS
501 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
502 unsigned long retval;
503
504 Set_Cursor(x, y);
505 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_SET_ATTRIBUTE, &attrib, 1, NULL, 0, &retval, 0);
506 Print(text);
507 }
508#endif
509}
510
511
512/***********************************************************************************************
513 * MonoClass::Text_Print -- Simple text printing from text number. *
514 * *
515 * This will print the text (represented by the text number) to the location on the *
516 * monochrome screen specified. *
517 * *
518 * INPUT: text -- The text number to print (converted to real text by external routine). *
519 * *
520 * x,y -- The coordinates to begin the printing at. *
521 * *
522 * attrib-- The character attribute to use while printing. *
523 * *
524 * OUTPUT: none *
525 * *
526 * WARNINGS: none *
527 * *
528 * HISTORY: *
529 * 06/04/1996 JLB : Created. *
530 *=============================================================================================*/
531void MonoClass::Text_Print(int text, int x, int y, MonoAttribute attrib)
532{
533 Text_Print(Fetch_String(text), x, y, attrib);
534}
535
536
537/***********************************************************************************************
538 * MonoClass::Print -- Simple print of text number. *
539 * *
540 * Prints text represented by the text number specified. *
541 * *
542 * INPUT: text -- The text number to print (converted to real text by external routine). *
543 * *
544 * OUTPUT: none *
545 * *
546 * WARNINGS: none *
547 * *
548 * HISTORY: *
549 * 06/04/1996 JLB : Created. *
550 *=============================================================================================*/
551void MonoClass::Print(int text)
552{
553 Print(Fetch_String(text));
554}
555
556
557/***********************************************************************************************
558 * MonoClass::View -- Brings the mono object to the main display. *
559 * *
560 * Use this routine to display the mono object on the monochrome screen. It is possible *
561 * that the mono object exists on some background screen memory. Calling this routine will *
562 * perform the necessary memory swapping to bring the data to the front. The mono object *
563 * that was currently being viewed is not destroyed by this function. It is merely moved *
564 * off to some background page. It can be treated normally, except that is just isn't *
565 * visible. *
566 * *
567 * INPUT: none *
568 * *
569 * OUTPUT: none *
570 * *
571 * WARNINGS: none *
572 * *
573 * HISTORY: *
574 * 10/17/1994 JLB : Created. *
575 * 01/06/1997 JLB : Updated to WindowsNT style of mono output. *
576 *=============================================================================================*/
578{
579#ifdef _WINDOWS
580 if ( Enabled && (Handle != INVALID_HANDLE_VALUE) ) {
581 unsigned long retval;
582 DeviceIoControl(Handle, (DWORD)IOCTL_MONO_BRING_TO_TOP, NULL, 0, NULL, 0, &retval, 0);
583 Current = this;
584 }
585#endif
586}
587
#define NULL
Definition BaseType.h:92
unsigned long DWORD
Definition bittype.h:57
#define IOCTL_MONO_SET_WINDOW
Definition MONODRVR.H:71
#define IOCTL_MONO_BRING_TO_TOP
Definition MONODRVR.H:66
#define IOCTL_MONO_SCROLL
Definition MONODRVR.H:65
#define IOCTL_MONO_CLEAR_SCREEN
Definition MONODRVR.H:62
#define IOCTL_MONO_SET_ATTRIBUTE
Definition MONODRVR.H:67
#define IOCTL_MONO_FILL_ATTRIB
Definition MONODRVR.H:75
#define IOCTL_MONO_PAN
Definition MONODRVR.H:68
#define IOCTL_MONO_SET_CURSOR
Definition MONODRVR.H:64
void View(void)
Definition mono.cpp:577
MonoClass(void)
Definition mono.cpp:100
static MonoClass * Current
Definition MONO.H:83
void Print(char const *text)
Definition mono.cpp:441
void Sub_Window(int x=0, int y=0, int w=80, int h=25)
Definition mono.cpp:188
void Printf(char const *text,...)
Definition mono.cpp:359
void Set_Cursor(int x, int y)
Definition mono.cpp:225
void Set_Default_Attribute(MonoAttribute attrib)
Definition mono.cpp:467
~MonoClass(void)
Definition mono.cpp:127
void Pan(int cols=1)
Definition mono.cpp:158
MonoAttribute
Definition MONO.H:47
void Text_Print(char const *text, int x, int y, MonoAttribute attrib=NORMAL)
Definition mono.cpp:498
void Clear(void)
Definition mono.cpp:259
void Fill_Attrib(int x, int y, int w, int h, MonoAttribute attrib)
Definition mono.cpp:292
void Scroll(int lines=1)
Definition mono.cpp:331
char const * Fetch_String(int id)
Definition data.cpp:200
#define W(x)
Definition generals.cpp:204
#define H(x, y, z)
Definition md5.cpp:88