MONOC.CPP 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. ** Command & Conquer(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. /* $Header: F:\projects\c&c\vcs\code\monoc.cpv 2.13 16 Oct 1995 16:50:36 JOE_BOSTIC $ */
  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. * File Name : MONO.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : July 2, 1994 *
  30. * *
  31. * Last Update : October 17, 1994 [JLB] *
  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::MonoClass -- The default constructor for monochrome screen object. *
  38. * MonoClass::operator = -- Handles making one mono object have the same imagery as another. *
  39. * MonoClass::Print -- Prints the text string at the current cursor coordinates. *
  40. * MonoClass::Printf -- Prints a formatted string to the monochrome screen. *
  41. * MonoClass::Scroll -- Scroll the monochrome screen up by the specified lines. *
  42. * MonoClass::Set_Cursor -- Sets the monochrome cursor to the coordinates specified. *
  43. * MonoClass::Text_Print -- Prints text to the monochrome object at coordinates indicated. *
  44. * MonoClass::View -- Brings the mono object to the main display. *
  45. * MonoClass::~MonoClass -- The default destructor for a monochrome screen object. *
  46. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  47. //#pragma inline
  48. #include "function.h"
  49. #include "monoc.h"
  50. #include <stdlib.h>
  51. #include <stdio.h>
  52. #include <dos.h>
  53. #include <mem.h>
  54. #include <stdarg.h>
  55. #include <string.h>
  56. //extern void output(short port, short data);
  57. //#pragma aux output parm [dx] [ax] = \
  58. // "out dx,al" \
  59. // "inc dx" \
  60. // "mov al,ah" \
  61. // "out dx,al"
  62. int MonoClass::Enabled = 0;
  63. MonoClass * MonoClass::PageUsage[MonoClass::MAX_MONO_PAGES] = {0,0,0,0,0,0,0,0};
  64. //DOSSegmentClass MonoClass::MonoSegment(MonoClass::SEGMENT);
  65. void * MonoClass::MonoSegment = (void*)0x000b0000;
  66. /*
  67. ** These are the IBM linedraw characters.
  68. */
  69. MonoClass::BoxDataType const MonoClass::CharData[MonoClass::COUNT] = {
  70. {0xDA,0xC4,0xBF,0xB3,0xD9,0xC4,0xC0,0xB3}, // Single line
  71. {0xD5,0xCD,0xB8,0xB3,0xBE,0xCD,0xD4,0xB3}, // Double horz.
  72. {0xD6,0xC4,0xB7,0xBA,0xBD,0xC4,0xD3,0xBA}, // Double vert.
  73. {0xC9,0xCD,0xBB,0xBA,0xBC,0xCD,0xC8,0xBA} // Double horz and vert.
  74. };
  75. /***********************************************************************************************
  76. * MonoClass::MonoClass -- The default constructor for monochrome screen object. *
  77. * *
  78. * This is the constructor for monochrome screen objects. It handles allocating a free *
  79. * monochrome page. If there are no more pages available, then this is a big error. The *
  80. * page allocated may not be the visible one. Call the View function in order to bring *
  81. * it to the displayed page. *
  82. * *
  83. * INPUT: none *
  84. * *
  85. * OUTPUT: none *
  86. * *
  87. * WARNINGS: none *
  88. * *
  89. * HISTORY: *
  90. * 10/17/1994 JLB : Created. *
  91. *=============================================================================================*/
  92. MonoClass::MonoClass(void)
  93. {
  94. int index;
  95. Attrib = DEFAULT_ATTRIBUTE; // Normal text color.
  96. X = Y = 0;
  97. for (index = 0; index < MAX_MONO_PAGES; index++) {
  98. if (!PageUsage[index]) {
  99. PageUsage[index] = this;
  100. Page = (char)index;
  101. break;
  102. }
  103. }
  104. if (index == MAX_MONO_PAGES) {
  105. // Major error message should pop up here!
  106. delete this;
  107. }
  108. }
  109. /***********************************************************************************************
  110. * MonoClass::~MonoClass -- The default destructor for a monochrome screen object. *
  111. * *
  112. * This is the default destructor for a monochrome screen object. *
  113. * *
  114. * INPUT: none *
  115. * *
  116. * OUTPUT: none *
  117. * *
  118. * WARNINGS: none *
  119. * *
  120. * HISTORY: *
  121. * 10/17/1994 JLB : Created. *
  122. *=============================================================================================*/
  123. MonoClass::~MonoClass(void)
  124. {
  125. PageUsage[Page] = 0;
  126. }
  127. /***********************************************************************************************
  128. * MonoClass::Draw_Box -- Draws a box using the IBM linedraw characters. *
  129. * *
  130. * Use this routine to draw a box to the monochrome screen. The IBM line draw characters *
  131. * are used to give the it a fancy appearance. There are several line draw modes supported. *
  132. * *
  133. * INPUT: x,y -- The coordinates of the upper left corner of the box. *
  134. * *
  135. * w,y -- The width and height (respectively) to make the box. *
  136. * *
  137. * attrib -- The text attribute to use when drawing the box outline characters. *
  138. * *
  139. * thick -- The thickness style to use. Examine the BoxStyleType enum for *
  140. * elaboration on the supported styles. *
  141. * *
  142. * OUTPUT: none *
  143. * *
  144. * WARNINGS: The interior of the box is NOT cleared by this routine. It is advised that this *
  145. * area be cleared before the box is drawn. *
  146. * *
  147. * HISTORY: *
  148. * 10/17/1994 JLB : Created. *
  149. *=============================================================================================*/
  150. void MonoClass::Draw_Box(int x, int y, int w, int h, char attrib, BoxStyleType thick)
  151. {
  152. CellType cell;
  153. char oldattrib = Attrib;
  154. if (!Enabled || !w || !h) return;
  155. cell.Attribute = attrib;
  156. /*
  157. ** Draw the horizontal lines.
  158. */
  159. for (int xpos = 0; xpos < w-2; xpos++) {
  160. cell.Character = CharData[thick].TopEdge;
  161. Store_Cell(cell, x+xpos+1, y);
  162. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x+xpos+1, y));
  163. cell.Character = CharData[thick].BottomEdge;
  164. Store_Cell(cell, x+xpos+1, y+h-1);
  165. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x+xpos+1, y+h-1));
  166. }
  167. /*
  168. ** Draw the vertical lines.
  169. */
  170. for (int ypos = 0; ypos < h-2; ypos++) {
  171. cell.Character = CharData[thick].LeftEdge;
  172. Store_Cell(cell, x, y+ypos+1);
  173. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x, y+ypos+1));
  174. cell.Character = CharData[thick].RightEdge;
  175. Store_Cell(cell, x+w-1, y+ypos+1);
  176. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x+w-1, y+ypos+1));
  177. }
  178. /*
  179. ** Draw the four corners.
  180. */
  181. if (w > 1 && h > 1) {
  182. cell.Character = CharData[thick].UpperLeft;
  183. Store_Cell(cell, x, y);
  184. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x, y));
  185. cell.Character = CharData[thick].UpperRight;
  186. Store_Cell(cell, x+w-1, y);
  187. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x+w-1, y));
  188. cell.Character = CharData[thick].BottomRight;
  189. Store_Cell(cell, x+w-1, y+h-1);
  190. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x+w-1, y+h-1));
  191. cell.Character = CharData[thick].BottomLeft;
  192. Store_Cell(cell, x, y+h-1);
  193. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(x, y+h-1));
  194. }
  195. Attrib = oldattrib;
  196. }
  197. /***********************************************************************************************
  198. * MonoClass::Set_Cursor -- Sets the monochrome cursor to the coordinates specified. *
  199. * *
  200. * Use this routine to set the monochrome's cursor position to the coordinates specified. *
  201. * This is the normal way of controlling where the next Print or Printf will output the *
  202. * text to. *
  203. * *
  204. * INPUT: x,y -- The coordinate to position the monochrome cursor. 0,0 is the upper left *
  205. * corner. *
  206. * *
  207. * OUTPUT: none *
  208. * *
  209. * WARNINGS: none *
  210. * *
  211. * HISTORY: *
  212. * 10/17/1994 JLB : Created. *
  213. *=============================================================================================*/
  214. void MonoClass::Set_Cursor(int x, int y)
  215. {
  216. #ifdef FIX_ME_LATER
  217. int pos = (y*COLUMNS)+x;
  218. if (!Enabled) return;
  219. X = (char)(x%COLUMNS);
  220. Y = (char)(y%LINES);
  221. if (Page == 0) {
  222. _DX = CONTROL_PORT;
  223. _AX = (short)(0x0E|(pos&0xFF00));
  224. asm {
  225. out dx,al
  226. inc dx
  227. mov al,ah
  228. out dx,al
  229. }
  230. _DX = CONTROL_PORT;
  231. _AX = (short)(0x0F|(pos<<8));
  232. asm {
  233. out dx,al
  234. inc dx
  235. mov al,ah
  236. out dx,al
  237. }
  238. // outportb(CONTROL_PORT,0x0E|(pos&0xFF00));
  239. // outportb(CONTROL_PORT,0x0F|(pos<<8));
  240. }
  241. #endif //FIX_ME_LATER
  242. x=y;
  243. y=x;
  244. }
  245. /***********************************************************************************************
  246. * MonoClass::Clear -- Clears the monochrome screen object. *
  247. * *
  248. * This routine will fill the monochrome screen object with spaces. It is clearing the *
  249. * screen of data, making it free for output. The cursor is positioned at the upper left *
  250. * corner of the screen by this routine. *
  251. * *
  252. * INPUT: none *
  253. * *
  254. * OUTPUT: none *
  255. * *
  256. * WARNINGS: none *
  257. * *
  258. * HISTORY: *
  259. * 10/17/1994 JLB : Created. *
  260. *=============================================================================================*/
  261. void MonoClass::Clear(void)
  262. {
  263. CellType cell;
  264. // int offset;
  265. if (!Enabled) return;
  266. Set_Cursor(0, 0);
  267. cell.Attribute = Attrib;
  268. cell.Character = ' ';
  269. // offset = Offset(0, 0);
  270. for (int y = 0; y < LINES; y++) {
  271. for (int x = 0; x < COLUMNS; x++) {
  272. Store_Cell(cell, x, y);
  273. }
  274. }
  275. }
  276. /***********************************************************************************************
  277. * MonoClass::Scroll -- Scroll the monochrome screen up by the specified lines. *
  278. * *
  279. * Use this routine to scroll the monochrome screen up by the number of lines specified. *
  280. * This routine is typically called by the printing functions so that the monochrome screen *
  281. * behaves in the expected manner -- printing at the bottom of the screen scrolls it up *
  282. * to make room for new text. *
  283. * *
  284. * INPUT: lines -- The number of lines to scroll the monochrome screen. *
  285. * *
  286. * OUTPUT: none *
  287. * *
  288. * WARNINGS: none *
  289. * *
  290. * HISTORY: *
  291. * 10/17/1994 JLB : Created. *
  292. *=============================================================================================*/
  293. void MonoClass::Scroll(int lines)
  294. {
  295. CellType cell;
  296. if (!Enabled || lines <= 0) return;
  297. memmove( (void*)((long)MonoSegment + Offset(0, 0)),
  298. (void*)((long)MonoSegment + Offset(0, lines)),
  299. (LINES-lines)*COLUMNS*sizeof(CellType));
  300. // DOSSegmentClass::Copy(MonoSegment, Offset(0, lines), MonoSegment, Offset(0, 0), (LINES-lines)*COLUMNS*sizeof(CellType));
  301. Y--;
  302. cell.Attribute = Attrib;
  303. cell.Character = ' ';
  304. for (int l = LINES-lines; l < LINES; l++) {
  305. for (int index = 0; index < COLUMNS; index++) {
  306. Store_Cell(cell, index, l);
  307. // MonoSegment.Copy_Word_To(*(short*)&cell, Offset(index, l));
  308. }
  309. }
  310. }
  311. /***********************************************************************************************
  312. * MonoClass::Printf -- Prints a formatted string to the monochrome screen. *
  313. * *
  314. * Use this routine to output a formatted string, using the standard formatting options, *
  315. * to the monochrome screen object's current cursor position. *
  316. * *
  317. * INPUT: text -- Pointer to the text to print. *
  318. * *
  319. * ... -- Any optional parameters to supply in formatting the text. *
  320. * *
  321. * OUTPUT: none *
  322. * *
  323. * WARNINGS: The total formatted text length must not exceed 255 characters. *
  324. * *
  325. * HISTORY: *
  326. * 10/17/1994 JLB : Created. *
  327. *=============================================================================================*/
  328. void MonoClass::Printf(char const *text, ...)
  329. {
  330. va_list va;
  331. /*
  332. ** The buffer object is placed at the end of the local variable list
  333. ** so that if the sprintf happens to spill past the end, it isn't likely
  334. ** to trash anything (important). The buffer is then manually truncated
  335. ** to maximum allowed size before being printed.
  336. */
  337. char buffer[256];
  338. if (!Enabled) return;
  339. va_start(va, text);
  340. vsprintf(buffer, text, va);
  341. buffer[sizeof(buffer)-1] = '\0';
  342. Print(buffer);
  343. va_end(va);
  344. }
  345. #ifdef NEVER
  346. void MonoClass::Printf(int text, ...)
  347. {
  348. va_list va;
  349. /*
  350. ** The buffer object is placed at the end of the local variable list
  351. ** so that if the sprintf happens to spill past the end, it isn't likely
  352. ** to trash anything (important). The buffer is then manually truncated
  353. ** to maximum allowed size before being printed.
  354. */
  355. char buffer[256];
  356. if (!Enabled) return;
  357. va_start(va, text);
  358. vsprintf(buffer, Text_String(text), va);
  359. buffer[sizeof(buffer)-1] = '\0';
  360. Print(buffer);
  361. va_end(va);
  362. }
  363. #endif
  364. /***********************************************************************************************
  365. * MonoClass::Print -- Prints the text string at the current cursor coordinates. *
  366. * *
  367. * Use this routine to output the specified text string at the monochrome object's current *
  368. * text coordinate position. *
  369. * *
  370. * INPUT: ptr -- Pointer to the string to print. *
  371. * *
  372. * OUTPUT: none *
  373. * *
  374. * WARNINGS: none *
  375. * *
  376. * HISTORY: *
  377. * 10/17/1994 JLB : Created. *
  378. *=============================================================================================*/
  379. void MonoClass::Print(char const *ptr)
  380. {
  381. // int optr;
  382. char startcol = X;
  383. char const * text;
  384. CellType cell;
  385. if (!ptr || !Enabled) return;
  386. text = ptr;
  387. cell.Attribute = Attrib;
  388. // optr = Offset(X, Y);
  389. while (*text) {
  390. /*
  391. ** Sometimes the character string is used for cursor control instead
  392. ** of plain text output. Check for this case.
  393. */
  394. switch (*text) {
  395. /*
  396. ** The "return" code behaves as it did in the old C library
  397. ** mono system. That is, it returns the cursor position to
  398. ** the next line but at the starting column of the print.
  399. */
  400. case '\r':
  401. X = startcol;
  402. Y++;
  403. Scroll(Y-(LINES-1));
  404. // optr = Offset(X, Y);
  405. break;
  406. /*
  407. ** The "newline" code behaves like the console newline character.
  408. ** That is, it moves the cursor down one line and at the first
  409. ** column.
  410. */
  411. case '\n':
  412. X = 0;
  413. Y++;
  414. Scroll(Y-(LINES-1));
  415. // optr = Offset(X, Y);
  416. break;
  417. /*
  418. ** All other characters are output directly and the cursor moves
  419. ** rightward to match. If the cursor wraps past the right
  420. ** edge is it moved to the next now down at left margin. If the
  421. ** cursor goes off the bottom of the display, the display is scrolled
  422. ** upward a line.
  423. */
  424. default:
  425. cell.Character = *text;
  426. Store_Cell(cell, X, Y);
  427. // MonoSegment.Copy_Word_To(*(short*)&cell, optr);
  428. // optr += sizeof(CellType);
  429. X++;
  430. if (X >= COLUMNS) {
  431. X = 0;
  432. Y++;
  433. if (Y > (LINES-1)) {
  434. Scroll(Y-(LINES-1));
  435. // optr = Offset(X, Y);
  436. }
  437. }
  438. break;
  439. }
  440. text++;
  441. }
  442. Set_Cursor(X, Y);
  443. }
  444. /***********************************************************************************************
  445. * MonoClass::Text_Print -- Prints text to the monochrome object at coordinates indicated. *
  446. * *
  447. * Use this routine to output text to the monochrome object at the X and Y coordinates *
  448. * specified. *
  449. * *
  450. * INPUT: text -- Pointer to the text string to display. *
  451. * *
  452. * x,y -- The X and Y character coordinates to start the printing at. *
  453. * *
  454. * attrib-- Optional parameter that specifies what text attribute code to use. *
  455. * *
  456. * OUTPUT: none *
  457. * *
  458. * WARNINGS: none *
  459. * *
  460. * HISTORY: *
  461. * 10/17/1994 JLB : Created. *
  462. *=============================================================================================*/
  463. void MonoClass::Text_Print(char const *text, int x, int y, char attrib)
  464. {
  465. char oldx = X;
  466. char oldy = Y;
  467. char oldattrib = Attrib;
  468. X = (char)x;
  469. Y = (char)y;
  470. Attrib = attrib;
  471. Print(text);
  472. Attrib = oldattrib;
  473. Set_Cursor(oldx, oldy);
  474. }
  475. #ifdef NEVER
  476. void MonoClass::Text_Print(int text, int x, int y, char attrib)
  477. {
  478. char oldx = X;
  479. char oldy = Y;
  480. char oldattrib = Attrib;
  481. if (text != TXT_NONE) {
  482. X = (char)x;
  483. Y = (char)y;
  484. Attrib = attrib;
  485. Print(Text_String(text));
  486. Attrib = oldattrib;
  487. Set_Cursor(oldx, oldy);
  488. }
  489. }
  490. void MonoClass::Print(int text)
  491. {
  492. Print(Text_String(text));
  493. }
  494. #endif
  495. /***********************************************************************************************
  496. * MonoClass::operator = -- Handles making one mono object have the same imagery as another. *
  497. * *
  498. * The assignment operator will handle copying the imagery from one monochrome object to *
  499. * another. Use this routine in to make two monochrome class objects visually identical. *
  500. * *
  501. * INPUT: src -- A reference to the source (right side) monochrome object. *
  502. * *
  503. * OUTPUT: none *
  504. * *
  505. * WARNINGS: none *
  506. * *
  507. * HISTORY: *
  508. * 10/17/1994 JLB : Created. *
  509. *=============================================================================================*/
  510. MonoClass & MonoClass::operator = (MonoClass const & src)
  511. {
  512. memcpy((void*)((long)MonoSegment + src.Offset(0, 0)), (void*)((long)MonoSegment + Offset(0, 0)), SIZE_OF_PAGE);
  513. // DOSSegmentClass::Copy(MonoSegment, src.Offset(0, 0), MonoSegment, Offset(0,0), SIZE_OF_PAGE);
  514. Set_Cursor(src.X, src.Y);
  515. return(*this);
  516. }
  517. /***********************************************************************************************
  518. * MonoClass::View -- Brings the mono object to the main display. *
  519. * *
  520. * Use this routine to display the mono object on the monochrome screen. It is possible *
  521. * that the mono object exists on some background screen memory. Calling this routine will *
  522. * perform the necessary memory swapping to bring the data to the front. The mono object *
  523. * that was currently being viewed is not destroyed by this function. It is merely moved *
  524. * off to some background page. It can be treated normally, except that is just isn't *
  525. * visible. *
  526. * *
  527. * INPUT: none *
  528. * *
  529. * OUTPUT: none *
  530. * *
  531. * WARNINGS: none *
  532. * *
  533. * HISTORY: *
  534. * 10/17/1994 JLB : Created. *
  535. *=============================================================================================*/
  536. void MonoClass::View(void)
  537. {
  538. MonoClass *displace; // The page that is being displaced.
  539. if (Get_Current() == this) return;
  540. /*
  541. ** If the visible page is already assigned to a real monochrome page
  542. ** object, then it must be swapped with the new one.
  543. */
  544. displace = Get_Current();
  545. if (displace) {
  546. char temp[SIZE_OF_PAGE];
  547. memcpy(&temp[0], MonoSegment, SIZE_OF_PAGE);
  548. memcpy(MonoSegment, (void*)((long)MonoSegment + Offset(0, 0)), SIZE_OF_PAGE);
  549. memcpy((void*)((long)MonoSegment + Offset(0, 0)), &temp[0], SIZE_OF_PAGE);
  550. // DOSSegmentClass::Swap(MonoSegment, Offset(0, 0), MonoSegment, 0, SIZE_OF_PAGE);
  551. displace->Page = Page;
  552. } else {
  553. /*
  554. ** Just copy the new page over since the display page is not assigned
  555. ** to a real monochrome page object.
  556. */
  557. memcpy(MonoSegment, (void*)((long)MonoSegment + Offset(0, 0)), SIZE_OF_PAGE);
  558. // DOSSegmentClass::Copy(MonoSegment, Offset(0, 0), MonoSegment, 0, SIZE_OF_PAGE);
  559. }
  560. PageUsage[Page] = displace;
  561. PageUsage[0] = this;
  562. Page = 0;
  563. Set_Cursor(X, Y);
  564. }
  565. /************************************************************************************
  566. ** This is the set of C wrapper functions that access the MonoClass support routines.
  567. ** Since the C interface doesn't have the ability to write to non-visible pages, it
  568. ** will just blast the output to whichever mono page is currently visible. If there is
  569. ** no mono class object that is visible, then one will be created -- BUT NOT FREED.
  570. ** Typically, this is ok, since the C interface will create only one MonoClass object
  571. ** and the system supports up to 8.
  572. */
  573. void Mono_Set_Cursor(int x, int y)
  574. {
  575. if (MonoClass::Is_Enabled()) {
  576. MonoClass *mono = MonoClass::Get_Current();
  577. if (!mono) {
  578. mono = new MonoClass();
  579. mono->View();
  580. }
  581. mono->Set_Cursor(x, y);
  582. }
  583. }
  584. int Mono_Printf(char const *string, ...)
  585. {
  586. va_list va;
  587. char buffer[256];
  588. buffer[0] = '\0';
  589. if (MonoClass::Is_Enabled()) {
  590. MonoClass *mono = MonoClass::Get_Current();
  591. if (!mono) {
  592. mono = new MonoClass();
  593. mono->View();
  594. }
  595. va_start(va, string);
  596. vsprintf(buffer, string, va);
  597. mono->Print(buffer);
  598. va_end(va);
  599. }
  600. return((short)strlen(buffer));
  601. }
  602. void Mono_Clear_Screen(void)
  603. {
  604. if (MonoClass::Is_Enabled()) {
  605. MonoClass *mono = MonoClass::Get_Current();
  606. if (!mono) {
  607. mono = new MonoClass();
  608. mono->View();
  609. }
  610. mono->Clear();
  611. }
  612. }
  613. void Mono_Text_Print(void const *text, int x, int y, int attrib)
  614. {
  615. if (MonoClass::Is_Enabled()) {
  616. MonoClass *mono = MonoClass::Get_Current();
  617. if (!mono) {
  618. mono = new MonoClass();
  619. mono->View();
  620. }
  621. mono->Text_Print((const char*)text, x, y, (char)attrib);
  622. }
  623. }
  624. void Mono_Draw_Rect(int x, int y, int w, int h, int attrib, int thick)
  625. {
  626. if (MonoClass::Is_Enabled()) {
  627. MonoClass *mono = MonoClass::Get_Current();
  628. if (!mono) {
  629. mono = new MonoClass();
  630. mono->View();
  631. }
  632. mono->Draw_Box(x, y, w, h, (char)attrib, (MonoClass::BoxStyleType)thick);
  633. }
  634. }
  635. void Mono_Print(void const *text)
  636. {
  637. if (MonoClass::Is_Enabled()) {
  638. MonoClass *mono = MonoClass::Get_Current();
  639. if (!mono) {
  640. mono = new MonoClass();
  641. mono->View();
  642. }
  643. mono->Print((const char*)text);
  644. }
  645. }
  646. int Mono_X(void)
  647. {
  648. if (MonoClass::Is_Enabled()) {
  649. MonoClass *mono = MonoClass::Get_Current();
  650. if (!mono) {
  651. mono = new MonoClass();
  652. mono->View();
  653. }
  654. return(short)mono->Get_X();
  655. }
  656. return(0);
  657. }
  658. int Mono_Y(void)
  659. {
  660. if (MonoClass::Is_Enabled()) {
  661. MonoClass *mono = MonoClass::Get_Current();
  662. if (!mono) {
  663. mono = new MonoClass();
  664. mono->View();
  665. }
  666. return(short)mono->Get_X();
  667. }
  668. return(0);
  669. }
  670. void Mono_Put_Char(char , int )
  671. {
  672. }
  673. void Mono_Scroll(int )
  674. {
  675. }
  676. void Mono_View_Page(int )
  677. {
  678. }
  679. #ifdef NEVER
  680. int Mono_Printf(int string, ...)
  681. {
  682. va_list va;
  683. char buffer[256];
  684. buffer[0] = '\0';
  685. if (MonoClass::Is_Enabled()) {
  686. MonoClass *mono = MonoClass::Get_Current();
  687. if (!mono) {
  688. mono = new MonoClass();
  689. mono->View();
  690. }
  691. va_start(va, string);
  692. vsprintf(buffer, Text_String(string), va);
  693. mono->Print(buffer);
  694. va_end(va);
  695. }
  696. return((short)strlen(buffer));
  697. }
  698. #endif