MONOC.CPP (57712B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: /CounterStrike/MONOC.CPP 1 3/03/97 10:25a Joe_bostic $ */ 17 /*********************************************************************************************** 18 *** 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 *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : MONO.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : July 2, 1994 * 28 * * 29 * Last Update : June 5, 1996 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * MonoClass::Clear -- Clears the monochrome screen object. * 34 * MonoClass::Draw_Box -- Draws a box using the IBM linedraw characters. * 35 * MonoClass::Fill_Attrib -- Fill a block with specified attribute. * 36 * MonoClass::MonoClass -- The default constructor for monochrome screen object. * 37 * MonoClass::Pan -- Scroll the window right or left. * 38 * MonoClass::Print -- Prints the text string at the current cursor coordinates. * 39 * MonoClass::Print -- Simple print of text number. * 40 * MonoClass::Printf -- Prints a formatted string to the monochrome screen. * 41 * MonoClass::Printf -- Prints formatted text using text string number. * 42 * MonoClass::Scroll -- Scroll the monochrome screen up by the specified lines. * 43 * MonoClass::Set_Cursor -- Sets the monochrome cursor to the coordinates specified. * 44 * MonoClass::Sub_Window -- Partitions the mono screen into a sub-window. * 45 * MonoClass::Text_Print -- Prints text to the monochrome object at coordinates indicated. * 46 * MonoClass::Text_Print -- Simple text printing from text number. * 47 * MonoClass::View -- Brings the mono object to the main display. * 48 * MonoClass::operator = -- Handles making one mono object have the same imagery as another. * 49 * MonoClass::~MonoClass -- The default destructor for a monochrome screen object. * 50 * Mono_Clear_Screen -- Clear the currently visible monochrome page. * 51 * Mono_Draw_Rect -- Draws rectangle to monochrome screen. * 52 * Mono_Print -- Prints simple text to monochrome screen. * 53 * Mono_Printf -- Prints formatted text to visible page. * 54 * Mono_Text_Print -- Prints text to location specified. * 55 * Mono_X -- Fetches the X cursor position for current visible mono page. * 56 * Mono_Y -- Fetches the Y cursor position for current mono page. * 57 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 58 59 //#if (0)//PG 60 //#include "watcom.h" 61 #include "monoc.h" 62 63 #include "function.h" 64 65 #include <stdlib.h> 66 #include <stdio.h> 67 #include <dos.h> 68 //#include <mem.h> 69 #include <stdarg.h> 70 #include <string.h> 71 72 73 //PG 74 //extern void output(short port, short data); 75 //#pragma aux output parm [dx] [ax] = \ 76 // "out dx,al" \ 77 // "inc dx" \ 78 // "mov al,ah" \ 79 // "out dx,al" 80 81 82 bool MonoClass::Enabled = 0; 83 MonoClass * MonoClass::PageUsage[MonoClass::MAX_MONO_PAGES]; 84 //MonoClass::MonoPageType * MonoClass::MonoRAM = (MonoClass::MonoPageType *) 0xB0000; 85 86 /* 87 ** These are the IBM linedraw characters. 88 */ 89 MonoClass::BoxDataType const MonoClass::CharData[MonoClass::COUNT] = { 90 {0xDA,0xC4,0xBF,0xB3,0xD9,0xC4,0xC0,0xB3}, // Single line 91 {0xD5,0xCD,0xB8,0xB3,0xBE,0xCD,0xD4,0xB3}, // Double horz. 92 {0xD6,0xC4,0xB7,0xBA,0xBD,0xC4,0xD3,0xBA}, // Double vert. 93 {0xC9,0xCD,0xBB,0xBA,0xBC,0xCD,0xC8,0xBA} // Double horz and vert. 94 }; 95 96 97 #ifdef NEVER 98 template<class T> 99 T min(T a, T b) { 100 if (a < b) return(a); 101 return(b); 102 } 103 104 template<class T> 105 T max(T a, T b) { 106 if (a > b) return(a); 107 return(b); 108 } 109 #endif 110 111 112 /*********************************************************************************************** 113 * MonoClass::MonoClass -- The default constructor for monochrome screen object. * 114 * * 115 * This is the constructor for monochrome screen objects. It handles allocating a free * 116 * monochrome page. If there are no more pages available, then this is a big error. The * 117 * page allocated may not be the visible one. Call the View function in order to bring * 118 * it to the displayed page. * 119 * * 120 * INPUT: none * 121 * * 122 * OUTPUT: none * 123 * * 124 * WARNINGS: none * 125 * * 126 * HISTORY: * 127 * 10/17/1994 JLB : Created. * 128 *=============================================================================================*/ 129 MonoClass::MonoClass(void) : 130 X(0), 131 Y(0), 132 Attrib(NORMAL), 133 Page(0), 134 SubX(0), 135 SubY(0), 136 SubW(COLUMNS), 137 SubH(LINES) 138 { 139 int index; 140 141 for (index = 0; index < MAX_MONO_PAGES; index++) { 142 if (!PageUsage[index]) { 143 PageUsage[index] = this; 144 Page = (char)index; 145 break; 146 } 147 } 148 if (index == MAX_MONO_PAGES) { 149 // Major error message should pop up here! 150 delete this; 151 } 152 } 153 154 155 /*********************************************************************************************** 156 * MonoClass::~MonoClass -- The default destructor for a monochrome screen object. * 157 * * 158 * This is the default destructor for a monochrome screen object. * 159 * * 160 * INPUT: none * 161 * * 162 * OUTPUT: none * 163 * * 164 * WARNINGS: none * 165 * * 166 * HISTORY: * 167 * 10/17/1994 JLB : Created. * 168 *=============================================================================================*/ 169 MonoClass::~MonoClass(void) 170 { 171 PageUsage[Page] = 0; 172 } 173 174 175 /*********************************************************************************************** 176 * MonoClass::Pan -- Scroll the window right or left. * 177 * * 178 * This routine will scroll the window to the right or left as indicated by the number of * 179 * rows. * 180 * * 181 * INPUT: cols -- The number of columns to pan the window. Positive numbers pan to the left * 182 * while negative numbers pan to the right. * 183 * * 184 * OUTPUT: none * 185 * * 186 * WARNINGS: none * 187 * * 188 * HISTORY: * 189 * 06/05/1996 JLB : Created. * 190 *=============================================================================================*/ 191 void MonoClass::Pan(int cols) 192 { 193 if (cols == 0) return; 194 195 if (abs(cols) >= SubW) { 196 Clear(); 197 return; 198 } 199 200 CellType cell; 201 cell.Character = ' '; 202 cell.Attribute = Attrib; 203 204 if (cols > 0) { 205 for (int index = SubY; index < SubY+SubH; index++) { 206 memmove(&Page_Ptr()->Data[index][SubX], &Page_Ptr()->Data[index][SubX+cols], sizeof(CellType)*(SubW-cols)); 207 for (int cc = SubX+SubW-cols; cc < SubX+SubW; cc++) { 208 Page_Ptr()->Data[index][cc] = cell; 209 } 210 } 211 } else { 212 for (int index = SubY; index < SubY+SubH; index++) { 213 memmove(&Page_Ptr()->Data[index][SubX-cols], &Page_Ptr()->Data[index][SubX], sizeof(CellType)*(SubW+cols)); 214 for (int cc = SubX; cc < SubX-cols; cc++) { 215 Page_Ptr()->Data[index][cc] = cell; 216 } 217 } 218 } 219 Set_Cursor(X-cols, Y); 220 } 221 222 223 /*********************************************************************************************** 224 * MonoClass::Sub_Window -- Partitions the mono screen into a sub-window. * 225 * * 226 * This routine is used to partition the monochrome screen so that only a sub-window will * 227 * be processed. By using this, a separate rectangle of the screen can be cleared, * 228 * scrolled, panned, or printed into. * 229 * * 230 * INPUT: x,y -- The upper left corner of the new sub-window. * 231 * * 232 * w,h -- Dimensions of the sub-window specified in characters. * 233 * * 234 * OUTPUT: none * 235 * * 236 * WARNINGS: The parameters are clipped as necessary. * 237 * * 238 * HISTORY: * 239 * 06/05/1996 JLB : Created. * 240 *=============================================================================================*/ 241 void MonoClass::Sub_Window(int x, int y, int w, int h) 242 { 243 /* 244 ** Undo any sub window adjustments to the cursor position. 245 */ 246 X += SubX; 247 Y += SubY; 248 249 /* 250 ** Ensure parameters are legal. 251 */ 252 x = min(x, COLUMNS-1); 253 x = max(x, 0); 254 y = min(y, LINES-1); 255 y = max(y, 0); 256 if (w == -1) w = COLUMNS-x; 257 if (h == -1) h = LINES-y; 258 259 /* 260 ** Assign the new sub-region. 261 */ 262 SubX = x; 263 SubY = y; 264 SubW = w; 265 SubH = h; 266 267 /* 268 ** Move the cursor (if necessary) so that it falls within that region. 269 */ 270 int xx = X; 271 int yy = Y; 272 xx = min(xx, SubX+SubW-1); 273 xx = max(xx, SubX); 274 yy = min(yy, SubY+SubH-1); 275 yy = max(yy, SubY); 276 Set_Cursor(xx-SubX, yy-SubY); 277 } 278 279 280 /*********************************************************************************************** 281 * MonoClass::Draw_Box -- Draws a box using the IBM linedraw characters. * 282 * * 283 * Use this routine to draw a box to the monochrome screen. The IBM line draw characters * 284 * are used to give the it a fancy appearance. There are several line draw modes supported. * 285 * * 286 * INPUT: x,y -- The coordinates of the upper left corner of the box. * 287 * * 288 * w,y -- The width and height (respectively) to make the box. * 289 * * 290 * attrib -- The text attribute to use when drawing the box outline characters. * 291 * * 292 * thick -- The thickness style to use. Examine the BoxStyleType enum for * 293 * elaboration on the supported styles. * 294 * * 295 * OUTPUT: none * 296 * * 297 * WARNINGS: The interior of the box is NOT cleared by this routine. It is advised that this * 298 * area be cleared before the box is drawn. * 299 * * 300 * HISTORY: * 301 * 10/17/1994 JLB : Created. * 302 *=============================================================================================*/ 303 void MonoClass::Draw_Box(int x, int y, int w, int h, MonoAttribute attrib, BoxStyleType thick) 304 { 305 CellType cell; 306 MonoAttribute oldattrib = Attrib; 307 308 if (!Enabled || !w || !h) return; 309 310 x = min(x, SubW); 311 x = max(x, 0); 312 y = min(y, SubH); 313 y = max(y, 0); 314 w = min(w, SubW-x); 315 w = max(w, 1); 316 h = min(h, SubH-y); 317 h = max(h, 1); 318 319 x += SubX; 320 y += SubY; 321 322 cell.Attribute = attrib; 323 324 /* 325 ** Draw the horizontal lines. 326 */ 327 for (int xpos = 0; xpos < w-2; xpos++) { 328 cell.Character = CharData[thick].TopEdge; 329 Page_Ptr()->Data[y][x+xpos+1] = cell; 330 cell.Character = CharData[thick].BottomEdge; 331 Page_Ptr()->Data[y+h-1][x+xpos+1] = cell; 332 } 333 334 /* 335 ** Draw the vertical lines. 336 */ 337 for (int ypos = 0; ypos < h-2; ypos++) { 338 cell.Character = CharData[thick].LeftEdge; 339 Page_Ptr()->Data[y+ypos+1][x] = cell; 340 cell.Character = CharData[thick].RightEdge; 341 Page_Ptr()->Data[y+ypos+1][x+w-1] = cell; 342 } 343 344 /* 345 ** Draw the four corners. 346 */ 347 if (w > 1 && h > 1) { 348 cell.Character = CharData[thick].UpperLeft; 349 Page_Ptr()->Data[y][x] = cell; 350 cell.Character = CharData[thick].UpperRight; 351 Page_Ptr()->Data[y][x+w-1] = cell; 352 cell.Character = CharData[thick].BottomRight; 353 Page_Ptr()->Data[y+h-1][x+w-1] = cell; 354 cell.Character = CharData[thick].BottomLeft; 355 Page_Ptr()->Data[y+h-1][x] = cell; 356 } 357 358 Attrib = oldattrib; 359 } 360 361 362 /*********************************************************************************************** 363 * MonoClass::Set_Cursor -- Sets the monochrome cursor to the coordinates specified. * 364 * * 365 * Use this routine to set the monochrome's cursor position to the coordinates specified. * 366 * This is the normal way of controlling where the next Print or Printf will output the * 367 * text to. * 368 * * 369 * INPUT: x,y -- The coordinate to position the monochrome cursor. 0,0 is the upper left * 370 * corner. * 371 * * 372 * OUTPUT: none * 373 * * 374 * WARNINGS: none * 375 * * 376 * HISTORY: * 377 * 10/17/1994 JLB : Created. * 378 *=============================================================================================*/ 379 void MonoClass::Set_Cursor(int x, int y) 380 { 381 x = min(x, SubW); 382 x = max(x, 0); 383 y = min(y, SubH); 384 y = max(y, 0); 385 386 X = x; 387 Y = y; 388 #if (0)//PG 389 if (!Enabled) return; 390 391 /* 392 ** Update the visible cursor position only if the this mono page is the currently 393 ** visible one. 394 */ 395 int pos = ((y+SubY)*COLUMNS)+(x+SubX); 396 if (Page == 0) { 397 output(CONTROL_PORT, (short)(0x0E|(pos&0xFF00))); 398 output(CONTROL_PORT, (short)(0x0F|(pos<<8))); 399 } 400 #endif 401 } 402 403 404 /*********************************************************************************************** 405 * MonoClass::Clear -- Clears the monochrome screen object. * 406 * * 407 * This routine will fill the monochrome screen object with spaces. It is clearing the * 408 * screen of data, making it free for output. The cursor is positioned at the upper left * 409 * corner of the screen by this routine. * 410 * * 411 * INPUT: none * 412 * * 413 * OUTPUT: none * 414 * * 415 * WARNINGS: none * 416 * * 417 * HISTORY: * 418 * 10/17/1994 JLB : Created. * 419 *=============================================================================================*/ 420 void MonoClass::Clear(void) 421 { 422 if (!Enabled) return; 423 424 Set_Cursor(0, 0); 425 426 CellType cell; 427 cell.Attribute = Attrib; 428 cell.Character = ' '; 429 430 for (int rows = 0; rows < SubH; rows++) { 431 for (int cols = 0; cols < SubW; cols++) { 432 Page_Ptr()->Data[rows+SubX][cols+SubY] = cell; 433 } 434 } 435 } 436 437 438 /*********************************************************************************************** 439 * MonoClass::Fill_Attrib -- Fill a block with specified attribute. * 440 * * 441 * This routine will give the specified attribute to the characters within the block * 442 * but will not change the characters themselves. You can use this routine to change the * 443 * underline, blink, or inverse characteristics of text. * 444 * * 445 * INPUT: x,y -- The upper left coordinate of the region to change. * 446 * * 447 * w,h -- The dimensions of the region to change (in characters). * 448 * * 449 * attrib -- The attribute to fill into the region specified. * 450 * * 451 * OUTPUT: none * 452 * * 453 * WARNINGS: none * 454 * * 455 * HISTORY: * 456 * 06/04/1996 JLB : Created. * 457 *=============================================================================================*/ 458 void MonoClass::Fill_Attrib(int x, int y, int w, int h, MonoAttribute attrib) 459 { 460 if (!w || !h || x >= SubW || h >= SubH || x+w > SubW || y+h > SubH) return; 461 462 for (int rows = y; rows < y+h; rows++) { 463 for (int cols = x; cols < x+w; cols++) { 464 Page_Ptr()->Data[rows+SubY][cols+SubX].Attribute = attrib; 465 } 466 } 467 } 468 469 470 /*********************************************************************************************** 471 * MonoClass::Scroll -- Scroll the monochrome screen up by the specified lines. * 472 * * 473 * Use this routine to scroll the monochrome screen up by the number of lines specified. * 474 * This routine is typically called by the printing functions so that the monochrome screen * 475 * behaves in the expected manner -- printing at the bottom of the screen scrolls it up * 476 * to make room for new text. * 477 * * 478 * INPUT: lines -- The number of lines to scroll the monochrome screen. * 479 * * 480 * OUTPUT: none * 481 * * 482 * WARNINGS: none * 483 * * 484 * HISTORY: * 485 * 10/17/1994 JLB : Created. * 486 *=============================================================================================*/ 487 void MonoClass::Scroll(int lines) 488 { 489 if (!Enabled || lines <= 0) return; 490 491 if (abs(lines) >= SubH) { 492 Clear(); 493 return; 494 } 495 496 CellType cell; 497 cell.Attribute = Attrib; 498 cell.Character = ' '; 499 500 if (lines > 0) { 501 for (int row = 0; row < SubH-lines; row++) { 502 memmove(&Page_Ptr()->Data[SubY+row][SubX], &Page_Ptr()->Data[SubY+row+1][SubX], SubW*sizeof(CellType)); 503 } 504 for (int frow = SubH-lines; frow < SubH; frow++) { 505 for (int cc = 0; cc < SubW; cc++) { 506 Page_Ptr()->Data[SubY+frow][SubX+cc] = cell; 507 } 508 } 509 } else { 510 for (int row = SubH-1; row >= -lines; row--) { 511 memmove(&Page_Ptr()->Data[SubY+row][SubX], &Page_Ptr()->Data[SubY+row-1][SubX], SubW*sizeof(CellType)); 512 } 513 for (int frow = 0; frow < -lines; frow++) { 514 for (int cc = 0; cc < SubW; cc++) { 515 Page_Ptr()->Data[SubY+frow][SubX+cc] = cell; 516 } 517 } 518 } 519 520 Set_Cursor(X, Y-lines); 521 } 522 523 524 /*********************************************************************************************** 525 * MonoClass::Printf -- Prints a formatted string to the monochrome screen. * 526 * * 527 * Use this routine to output a formatted string, using the standard formatting options, * 528 * to the monochrome screen object's current cursor position. * 529 * * 530 * INPUT: text -- Pointer to the text to print. * 531 * * 532 * ... -- Any optional parameters to supply in formatting the text. * 533 * * 534 * OUTPUT: none * 535 * * 536 * WARNINGS: The total formatted text length must not exceed 255 characters. * 537 * * 538 * HISTORY: * 539 * 10/17/1994 JLB : Created. * 540 *=============================================================================================*/ 541 void MonoClass::Printf(char const *text, ...) 542 { 543 va_list va; 544 /* 545 ** The buffer object is placed at the end of the local variable list 546 ** so that if the sprintf happens to spill past the end, it isn't likely 547 ** to trash anything (important). The buffer is then manually truncated 548 ** to maximum allowed size before being printed. 549 */ 550 char buffer[256]; 551 552 if (!Enabled) return; 553 554 va_start(va, text); 555 vsprintf(buffer, text, va); 556 buffer[sizeof(buffer)-1] = '\0'; 557 558 Print(buffer); 559 va_end(va); 560 } 561 562 563 /*********************************************************************************************** 564 * MonoClass::Printf -- Prints formatted text using text string number. * 565 * * 566 * This routine will take the given text string number and print the formatted text to * 567 * the monochrome screen. * 568 * * 569 * INPUT: text -- The text number to convert into real text (by way of external function). * 570 * * 571 * ... -- Additional parameters as needed. * 572 * * 573 * OUTPUT: none * 574 * * 575 * WARNINGS: none * 576 * * 577 * HISTORY: * 578 * 06/04/1996 JLB : Created. * 579 *=============================================================================================*/ 580 void MonoClass::Printf(int text, ...) 581 { 582 va_list va; 583 584 /* 585 ** The buffer object is placed at the end of the local variable list 586 ** so that if the sprintf happens to spill past the end, it isn't likely 587 ** to trash anything (important). The buffer is then manually truncated 588 ** to maximum allowed size before being printed. 589 */ 590 char buffer[256]; 591 592 if (!Enabled) return; 593 594 va_start(va, text); 595 vsprintf(buffer, Text_String(text), va); 596 buffer[sizeof(buffer)-1] = '\0'; 597 598 Print(buffer); 599 va_end(va); 600 } 601 602 603 /*********************************************************************************************** 604 * MonoClass::Print -- Prints the text string at the current cursor coordinates. * 605 * * 606 * Use this routine to output the specified text string at the monochrome object's current * 607 * text coordinate position. * 608 * * 609 * INPUT: ptr -- Pointer to the string to print. * 610 * * 611 * OUTPUT: none * 612 * * 613 * WARNINGS: none * 614 * * 615 * HISTORY: * 616 * 10/17/1994 JLB : Created. * 617 *=============================================================================================*/ 618 void MonoClass::Print(char const * ptr) 619 { 620 int startcol = X; 621 char const * text; 622 CellType cell; 623 624 if (!ptr || !Enabled) return; 625 626 text = ptr; 627 cell.Attribute = Attrib; 628 while (*text) { 629 630 cell.Character = *text; 631 632 /* 633 ** Sometimes the character string is used for cursor control instead 634 ** of plain text output. Check for this case. 635 */ 636 switch (cell.Character) { 637 638 /* 639 ** The "return" code behaves as it did in the old C library 640 ** mono system. That is, it returns the cursor position to 641 ** the next line but at the starting column of the print. 642 */ 643 case '\r': 644 if (Y == SubH-1) { 645 Scroll(1); 646 } 647 Set_Cursor(startcol, Y+1); 648 break; 649 650 /* 651 ** The TAB character is not currently handled. Convert it to 652 ** a space instead. 653 */ 654 case '\t': 655 cell.Character = ' '; 656 // fall into normal print case. 657 658 /* 659 ** All other characters are output directly and the cursor moves 660 ** rightward to match. If the cursor wraps past the right 661 ** edge it is moved to the next now down at left margin. If the 662 ** cursor goes off the bottom of the display, the display is scrolled 663 ** upward a line. 664 */ 665 default: 666 Page_Ptr()->Data[SubY+Y][SubX+X] = cell; 667 668 if (X < SubW-1) { 669 Set_Cursor(X+1, Y); 670 break; 671 } 672 // Fall into newline case. 673 674 /* 675 ** The "newline" code behaves like the console newline character. 676 ** That is, it moves the cursor down one line and at the first 677 ** column. 678 */ 679 case '\n': 680 if (Y == SubH-1) { 681 Scroll(1); 682 } 683 Set_Cursor(0, Y+1); 684 break; 685 } 686 text++; 687 } 688 } 689 690 691 /*********************************************************************************************** 692 * MonoClass::Text_Print -- Prints text to the monochrome object at coordinates indicated. * 693 * * 694 * Use this routine to output text to the monochrome object at the X and Y coordinates * 695 * specified. * 696 * * 697 * INPUT: text -- Pointer to the text string to display. * 698 * * 699 * x,y -- The X and Y character coordinates to start the printing at. * 700 * * 701 * attrib-- Optional parameter that specifies what text attribute code to use. * 702 * * 703 * OUTPUT: none * 704 * * 705 * WARNINGS: none * 706 * * 707 * HISTORY: * 708 * 10/17/1994 JLB : Created. * 709 *=============================================================================================*/ 710 void MonoClass::Text_Print(char const *text, int x, int y, MonoAttribute attrib) 711 { 712 int oldx = X; 713 int oldy = Y; 714 MonoAttribute oldattrib = Attrib; 715 716 X = (char)x; 717 Y = (char)y; 718 Attrib = attrib; 719 Print(text); 720 Attrib = oldattrib; 721 Set_Cursor(oldx, oldy); 722 } 723 724 725 /*********************************************************************************************** 726 * MonoClass::Text_Print -- Simple text printing from text number. * 727 * * 728 * This will print the text (represented by the text number) to the location on the * 729 * monochrome screen specified. * 730 * * 731 * INPUT: text -- The text number to print (converted to real text by external routine). * 732 * * 733 * x,y -- The coordinates to begin the printing at. * 734 * * 735 * attrib-- The character attribute to use while printing. * 736 * * 737 * OUTPUT: none * 738 * * 739 * WARNINGS: none * 740 * * 741 * HISTORY: * 742 * 06/04/1996 JLB : Created. * 743 *=============================================================================================*/ 744 void MonoClass::Text_Print(int text, int x, int y, MonoAttribute attrib) 745 { 746 int oldx = X; 747 int oldy = Y; 748 MonoAttribute oldattrib = Attrib; 749 750 if (text != 0) { 751 X = (char)x; 752 Y = (char)y; 753 Attrib = attrib; 754 Print(Text_String(text)); 755 Attrib = oldattrib; 756 Set_Cursor(oldx, oldy); 757 } 758 } 759 760 761 /*********************************************************************************************** 762 * MonoClass::Print -- Simple print of text number. * 763 * * 764 * Prints text represented by the text number specified. * 765 * * 766 * INPUT: text -- The text number to print (converted to real text by external routine). * 767 * * 768 * OUTPUT: none * 769 * * 770 * WARNINGS: none * 771 * * 772 * HISTORY: * 773 * 06/04/1996 JLB : Created. * 774 *=============================================================================================*/ 775 void MonoClass::Print(int text) 776 { 777 Print(Text_String(text)); 778 } 779 780 781 /*********************************************************************************************** 782 * MonoClass::operator = -- Handles making one mono object have the same imagery as another. * 783 * * 784 * The assignment operator will handle copying the imagery from one monochrome object to * 785 * another. Use this routine in to make two monochrome class objects visually identical. * 786 * * 787 * INPUT: src -- A reference to the source (right side) monochrome object. * 788 * * 789 * OUTPUT: none * 790 * * 791 * WARNINGS: none * 792 * * 793 * HISTORY: * 794 * 10/17/1994 JLB : Created. * 795 *=============================================================================================*/ 796 MonoClass & MonoClass::operator = (MonoClass const & src) 797 { 798 memmove(Page_Ptr(), src.Page_Ptr(), sizeof(MonoPageType)); 799 Set_Cursor(src.X, src.Y); 800 return(*this); 801 } 802 803 804 /*********************************************************************************************** 805 * MonoClass::View -- Brings the mono object to the main display. * 806 * * 807 * Use this routine to display the mono object on the monochrome screen. It is possible * 808 * that the mono object exists on some background screen memory. Calling this routine will * 809 * perform the necessary memory swapping to bring the data to the front. The mono object * 810 * that was currently being viewed is not destroyed by this function. It is merely moved * 811 * off to some background page. It can be treated normally, except that is just isn't * 812 * visible. * 813 * * 814 * INPUT: none * 815 * * 816 * OUTPUT: none * 817 * * 818 * WARNINGS: none * 819 * * 820 * HISTORY: * 821 * 10/17/1994 JLB : Created. * 822 *=============================================================================================*/ 823 void MonoClass::View(void) 824 { 825 if (Get_Current() == this) return; 826 827 /* 828 ** If the visible page is already assigned to a real monochrome page 829 ** object, then it must be swapped with the new one. 830 */ 831 MonoClass * displace = Get_Current(); 832 if (displace) { 833 for (int line = 0; line < LINES; line++) { 834 for (int col = 0; col < COLUMNS; col++) { 835 CellType temp = Page_Ptr()->Data[line][col]; 836 Page_Ptr()->Data[line][col] = Raw_Ptr(0)->Data[line][col]; 837 Raw_Ptr(0)->Data[line][col] = temp; 838 } 839 } 840 displace->Page = Page; 841 842 } else { 843 844 /* 845 ** Just copy the new page over since the display page is not assigned 846 ** to a real monochrome page object. 847 */ 848 memmove(Raw_Ptr(0), Page_Ptr(), sizeof(MonoPageType)); 849 } 850 PageUsage[Page] = displace; 851 PageUsage[0] = this; 852 Page = 0; 853 854 Set_Cursor(X, Y); 855 } 856 857 858 859 /************************************************************************************ 860 ** This is the set of C wrapper functions that access the MonoClass support routines. 861 ** Since the C interface doesn't have the ability to write to non-visible pages, it 862 ** will just blast the output to whichever mono page is currently visible. If there is 863 ** no mono class object that is visible, then one will be created -- BUT NOT FREED. 864 ** Typically, this is ok, since the C interface will create only one MonoClass object 865 ** and the system supports up to 8. 866 */ 867 void Mono_Set_Cursor(int x, int y) 868 { 869 if (MonoClass::Is_Enabled()) { 870 MonoClass * mono = MonoClass::Get_Current(); 871 if (!mono) { 872 mono = new MonoClass(); 873 mono->View(); 874 } 875 mono->Set_Cursor(x, y); 876 } 877 } 878 879 880 /*********************************************************************************************** 881 * Mono_Printf -- Prints formatted text to visible page. * 882 * * 883 * This routine will print formatted text (with parameters) to the visible monochrome page * 884 * at whatever the current cursor location is. * 885 * * 886 * INPUT: string -- The string to use as the main text and formatting control string. * 887 * * 888 * ... -- Any additional parameters required by the formatting string. * 889 * * 890 * OUTPUT: Returns with the number of characters written to the display. * 891 * * 892 * WARNINGS: The total size of the formatted text must not exceed 256 characters. * 893 * * 894 * HISTORY: * 895 * 06/04/1996 JLB : Created. * 896 *=============================================================================================*/ 897 int Mono_Printf(char const * string, ...) 898 { 899 va_list va; 900 char buffer[256]; 901 902 buffer[0] = '\0'; 903 if (MonoClass::Is_Enabled()) { 904 MonoClass * mono = MonoClass::Get_Current(); 905 if (!mono) { 906 mono = new MonoClass(); 907 mono->View(); 908 } 909 910 va_start(va, string); 911 vsprintf(buffer, string, va); 912 913 mono->Print(buffer); 914 915 va_end(va); 916 } 917 return((short)strlen(buffer)); 918 } 919 920 921 /*********************************************************************************************** 922 * Mono_Clear_Screen -- Clear the currently visible monochrome page. * 923 * * 924 * This routine will clear the currently visible monochrome page. * 925 * * 926 * INPUT: none * 927 * * 928 * OUTPUT: none * 929 * * 930 * WARNINGS: none * 931 * * 932 * HISTORY: * 933 * 06/04/1996 JLB : Created. * 934 *=============================================================================================*/ 935 void Mono_Clear_Screen(void) 936 { 937 if (MonoClass::Is_Enabled()) { 938 MonoClass * mono = MonoClass::Get_Current(); 939 if (!mono) { 940 mono = new MonoClass(); 941 mono->View(); 942 } 943 mono->Clear(); 944 } 945 } 946 947 948 /*********************************************************************************************** 949 * Mono_Text_Print -- Prints text to location specified. * 950 * * 951 * This routine will print the specified text to the location indicated. * 952 * * 953 * INPUT: text -- Pointer to the text to print. * 954 * * 955 * x,y -- The coordinate to print the text at. * 956 * * 957 * attrib-- The attribute to use when printing the text. * 958 * * 959 * OUTPUT: none * 960 * * 961 * WARNINGS: none * 962 * * 963 * HISTORY: * 964 * 06/04/1996 JLB : Created. * 965 *=============================================================================================*/ 966 void Mono_Text_Print(void const *text, int x, int y, int attrib) 967 { 968 if (MonoClass::Is_Enabled()) { 969 MonoClass * mono = MonoClass::Get_Current(); 970 if (!mono) { 971 mono = new MonoClass(); 972 mono->View(); 973 } 974 mono->Text_Print((const char*)text, x, y, (MonoClass::MonoAttribute)attrib); 975 } 976 } 977 978 979 /*********************************************************************************************** 980 * Mono_Draw_Rect -- Draws rectangle to monochrome screen. * 981 * * 982 * Use this routine to draw a rectangle to the monochrome screen. The dimensions, attribute,* 983 * and line style are controlled by parameters. * 984 * * 985 * INPUT: x,y -- Coordinate of upper left corner of the box to draw. * 986 * * 987 * w,h -- The width and height of the box to draw. * 988 * * 989 * attrib-- The attribute to use when drawing the box. * 990 * * 991 * thick -- The line drawing style to use. * 992 * * 993 * OUTPUT: none * 994 * * 995 * WARNINGS: none * 996 * * 997 * HISTORY: * 998 * 06/04/1996 JLB : Created. * 999 *=============================================================================================*/ 1000 void Mono_Draw_Rect(int x, int y, int w, int h, int attrib, int thick) 1001 { 1002 if (MonoClass::Is_Enabled()) { 1003 MonoClass * mono = MonoClass::Get_Current(); 1004 if (!mono) { 1005 mono = new MonoClass(); 1006 mono->View(); 1007 } 1008 mono->Draw_Box(x, y, w, h, (MonoClass::MonoAttribute)attrib, (MonoClass::BoxStyleType)thick); 1009 } 1010 } 1011 1012 1013 /*********************************************************************************************** 1014 * Mono_Print -- Prints simple text to monochrome screen. * 1015 * * 1016 * This is the non-formatting print to the monochrome screen. * 1017 * * 1018 * INPUT: text -- Pointer to the text that will be printed. * 1019 * * 1020 * OUTPUT: none * 1021 * * 1022 * WARNINGS: none * 1023 * * 1024 * HISTORY: * 1025 * 06/04/1996 JLB : Created. * 1026 *=============================================================================================*/ 1027 void Mono_Print(void const *text) 1028 { 1029 if (MonoClass::Is_Enabled()) { 1030 MonoClass * mono = MonoClass::Get_Current(); 1031 if (!mono) { 1032 mono = new MonoClass(); 1033 mono->View(); 1034 } 1035 mono->Print((const char*)text); 1036 } 1037 } 1038 1039 1040 /*********************************************************************************************** 1041 * Mono_X -- Fetches the X cursor position for current visible mono page. * 1042 * * 1043 * Use this routine to get the current cursor X position. This only applies to the * 1044 * currently visible monochrome page. * 1045 * * 1046 * INPUT: none * 1047 * * 1048 * OUTPUT: Returns with X position of cursor. * 1049 * * 1050 * WARNINGS: none * 1051 * * 1052 * HISTORY: * 1053 * 06/04/1996 JLB : Created. * 1054 *=============================================================================================*/ 1055 int Mono_X(void) 1056 { 1057 if (MonoClass::Is_Enabled()) { 1058 MonoClass * mono = MonoClass::Get_Current(); 1059 if (!mono) { 1060 mono = new MonoClass(); 1061 mono->View(); 1062 } 1063 return(short)mono->Get_X(); 1064 } 1065 return(0); 1066 } 1067 1068 1069 /*********************************************************************************************** 1070 * Mono_Y -- Fetches the Y cursor position for current mono page. * 1071 * * 1072 * This routine will fetch the current Y cursor position for the monochrome page. * 1073 * * 1074 * INPUT: none * 1075 * * 1076 * OUTPUT: Returns with the current Y position of the monochrome page. * 1077 * * 1078 * WARNINGS: none * 1079 * * 1080 * HISTORY: * 1081 * 06/04/1996 JLB : Created. * 1082 *=============================================================================================*/ 1083 int Mono_Y(void) 1084 { 1085 if (MonoClass::Is_Enabled()) { 1086 MonoClass * mono = MonoClass::Get_Current(); 1087 if (!mono) { 1088 mono = new MonoClass(); 1089 mono->View(); 1090 } 1091 return(short)mono->Get_X(); 1092 } 1093 return(0); 1094 } 1095 1096 1097 void Mono_Put_Char(char , int ) 1098 { 1099 } 1100 1101 void Mono_Scroll(int ) 1102 { 1103 } 1104 1105 void Mono_View_Page(int ) 1106 { 1107 } 1108 1109 int Mono_Printf(int string, ...) 1110 { 1111 va_list va; 1112 char buffer[256]; 1113 1114 buffer[0] = '\0'; 1115 if (MonoClass::Is_Enabled()) { 1116 MonoClass * mono = MonoClass::Get_Current(); 1117 if (!mono) { 1118 mono = new MonoClass(); 1119 mono->View(); 1120 } 1121 1122 va_start(va, string); 1123 vsprintf(buffer, Text_String(string), va); 1124 1125 mono->Print(buffer); 1126 1127 va_end(va); 1128 } 1129 return((short)strlen(buffer)); 1130 } 1131 1132 //#endif