MONO.H 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.h_v 2.16 06 Sep 1995 16:29:02 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.H *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : July 2, 1994 *
  26. * *
  27. * Last Update : July 2, 1994 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #ifndef MONOC_H
  33. #define MONOC_H
  34. class MonoClass {
  35. /*
  36. ** This is a private structure that is used to control which characters
  37. ** are used when a box is drawn. Line drawing on the monochrome screen is
  38. ** really made up of characters. This specifies which characters to use.
  39. */
  40. typedef struct {
  41. unsigned char UpperLeft;
  42. unsigned char TopEdge;
  43. unsigned char UpperRight;
  44. unsigned char RightEdge;
  45. unsigned char BottomRight;
  46. unsigned char BottomEdge;
  47. unsigned char BottomLeft;
  48. unsigned char LeftEdge;
  49. } BoxDataType;
  50. /*
  51. ** Each cell is constructed of the actual character that is displayed and the
  52. ** attribute to use. This character pair is located at every position on the
  53. ** display (80 x 25). Since this cell pair can be represented by a "short"
  54. ** integer, certain speed optimizations are taken in the monochrome drawing
  55. ** code.
  56. */
  57. typedef struct {
  58. char Character; // Character to display.
  59. char Attribute; // Attribute.
  60. } CellType;
  61. /*
  62. ** These private constants are used in the various monochrome operations.
  63. */
  64. enum MonoClassPortEnums {
  65. CONTROL_PORT=0x03B4, // CRTC control register.
  66. DATA_PORT=0x03B5, // CRTC data register.
  67. COLUMNS=80, // Number of columns.
  68. LINES=25, // Number of lines.
  69. SIZE_OF_PAGE=LINES*COLUMNS*sizeof(CellType), // Entire page size.
  70. DEFAULT_ATTRIBUTE=0x02 // Normal white on black color attribute.
  71. };
  72. public:
  73. enum MonoClassPageEnums {
  74. MAX_MONO_PAGES=16, // Maximum RAM pages on mono card.
  75. SEGMENT=0xB000 // Monochrome screen segment.
  76. };
  77. /*
  78. ** These are the various box styles that may be used.
  79. */
  80. typedef enum BoxStyleType {
  81. SINGLE, // Single thickness.
  82. DOUBLE_HORZ, // Double thick on the horizontal axis.
  83. DOUBLE_VERT, // Double thick on the vertical axis.
  84. DOUBLE, // Double thickness.
  85. COUNT
  86. } BoxStyleType;
  87. MonoClass(void);
  88. ~MonoClass(void);
  89. static void Enable(void) {Enabled = 1;};
  90. static void Disable(void) {Enabled = 0;};
  91. static int Is_Enabled(void) {return Enabled;};
  92. static MonoClass * Get_Current(void) {return PageUsage[0];};
  93. void Draw_Box(int x, int y, int w, int h, char attrib=DEFAULT_ATTRIBUTE, BoxStyleType thick=SINGLE);
  94. void Set_Default_Attribute(char attrib) {Attrib = attrib;};
  95. void Clear(void);
  96. void Set_Cursor(int x, int y);
  97. void Print(char const *text);
  98. void Print(int text);
  99. void Printf(char const *text, ...);
  100. void Printf(int text, ...);
  101. void Text_Print(char const *text, int x, int y, char attrib=DEFAULT_ATTRIBUTE);
  102. void Text_Print(int text, int x, int y, char attrib=DEFAULT_ATTRIBUTE);
  103. void View(void);
  104. int Get_X(void) const {return X;};
  105. int Get_Y(void) const {return Y;};
  106. /*
  107. ** Handles deep copies for the mono class objects. This performs what is essentially
  108. ** a screen copy.
  109. */
  110. MonoClass & operator = (MonoClass const & );
  111. /*
  112. ** This merely makes a duplicate of the mono object into a newly created mono
  113. ** object.
  114. */
  115. MonoClass (MonoClass const &);
  116. private:
  117. char X; // Cursor X position.
  118. char Y; // Cursor Y position.
  119. char Attrib; // Normal attribute to use if none specified.
  120. char Page; // The current page to write to.
  121. /*
  122. ** Helper functions to help with display operations.
  123. */
  124. int Offset(int x=0, int y=0) const {return (SIZE_OF_PAGE*Page) + sizeof(CellType)*(x + (y*COLUMNS));};
  125. void Scroll(int lines);
  126. void Store_Cell(CellType &cell, int x, int y) {
  127. *(CellType *)((long)MonoSegment + Offset(x, y)) = cell;
  128. };
  129. /*
  130. ** This is the segment/selector of the monochrome screen.
  131. */
  132. static void * MonoSegment;
  133. /*
  134. ** This the the arrays of characters used for drawing boxes.
  135. */
  136. static BoxDataType const CharData[4];
  137. /*
  138. ** This array contains pointers to the monochrome objects that are assigned
  139. ** to each of the monochrome pages. As the monochrome pages are made visible,
  140. ** they can be shuffled around between the actual locations. The first entry
  141. ** in this table is the one that is visible.
  142. */
  143. static MonoClass * PageUsage[MAX_MONO_PAGES];
  144. /*
  145. ** If this is true, then monochrome output is allowed. It defaults to false
  146. ** so that monochrome output must be explicitly enabled.
  147. */
  148. static int Enabled;
  149. };
  150. void Mono_Set_Cursor(int x, int y);
  151. int Mono_Printf(char const *string, ...);
  152. void Mono_Clear_Screen(void);
  153. void Mono_Text_Print(void const *text, int x, int y, int attrib);
  154. void Mono_Draw_Rect(int x, int y, int w, int h, int attrib, int thick);
  155. void Mono_Print(void const *text);
  156. int Mono_X(void);
  157. int Mono_Y(void);
  158. #endif