MONOC.CPP 33 KB

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