You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

463 lines
19 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /* TDisplay/TScreen header.
  2. Copyright (c) 2002-2003 by Salvador E. Tropea (SET)
  3. Covered by the GPL license.
  4. This driver defines a class compatible with original Turbo Vision but
  5. implemented in a very different way. Most members are function pointer
  6. that can be changed by the hardware/OS dependent driver.
  7. This idea was propposed by JASC.
  8. I also included some members that Robert added to original TV.
  9. A lot of new members were added, this is just compatible with Borland's
  10. classes, but doesn't have much in common.
  11. */
  12. #if defined( Uses_TScreen ) && !defined( __TScreen )
  13. #define __TScreen
  14. class TVCodePage;
  15. // Components are 0-255
  16. struct TScreenColor
  17. {
  18. uchar R,G,B,Alpha;
  19. };
  20. struct TScreenFont256
  21. {
  22. unsigned w,h;
  23. uchar *data;
  24. };
  25. struct TScreenResolution
  26. {
  27. unsigned x,y;
  28. };
  29. // Type for the callback called when the driver needs a new font.
  30. typedef TScreenFont256 *(*TVScreenFontRequestCallBack)(int which, unsigned w,
  31. unsigned height);
  32. // Type for the callback called when the driver is detected.
  33. // This is called when we know which driver will be used but it isn't
  34. // initilized yet.
  35. typedef void (*TVScreenDriverDetectCallBack)();
  36. const int TDisplayDOSModesNum=18;
  37. /**[txh]********************************************************************
  38. Description:
  39. SET: Here I'm writing some implementation details that could help to
  40. understand it.@*
  41. This class is the low level stuff and is used by TScreen. The user isn't
  42. supposed to call it.@*
  43. Example: TDisplay::getRows() is needed by TScreen to know the display
  44. rows, but a class (like TDesktop) should use TScreen::getRows(), it will
  45. return a cached data that can additionally have some translation applied to
  46. the value returned by TDisplay::getRows().@*
  47. It should be posible to split the physical screen in 4 different screens
  48. handled by a special TScreen class. In this case TDisplay::getRows will
  49. return a different value than TScreen, lets say the double. Then calling
  50. TScreen::clearScreen will erase the current "screen" and not the whole
  51. physical screen.@*
  52. JASC have the idea of making some of the members pointers that can be
  53. changed by the hardware layers. I implemented it but with many
  54. differences.@*
  55. ***************************************************************************/
  56. class TDisplay
  57. {
  58. public:
  59. friend class TView;
  60. // Members defined by original TV library v2.0
  61. enum videoModes
  62. {
  63. smBW80 = 0x0002,
  64. smCO80 = 0x0003,
  65. smCO80x25 = 0x0003,
  66. smMono = 0x0007,
  67. smFont8x8 = 0x0100,
  68. // Modes defined by Robert
  69. // Extended
  70. smCO80x28 = 0x0103,
  71. smCO80x35 = 0x0203,
  72. smCO80x40 = 0x0303,
  73. smCO80x43 = 0x0403,
  74. smCO80x50 = 0x0503,
  75. // Tweaked
  76. smCO80x30 = 0x0703,
  77. smCO80x34 = 0x0803,
  78. smCO90x30 = 0x0903,
  79. smCO90x34 = 0x0A03,
  80. smCO94x30 = 0x0B03,
  81. smCO94x34 = 0x0C03,
  82. smCO82x25 = 0x0D03, // Created by SET to get 8x16 char cells
  83. // Common VESA text modes
  84. smCO80x60 = 0x0108,
  85. smCO132x25= 0x0109,
  86. smCO132x43= 0x010A,
  87. smCO132x50= 0x010B,
  88. smCO132x60= 0x010C
  89. };
  90. static void (*clearScreen)(uchar w, uchar h);
  91. // SET: The following two are for compatibility, see *CursorShape
  92. static void setCursorType(ushort val);
  93. static ushort getCursorType();
  94. static ushort (*getRows)();
  95. static ushort (*getCols)();
  96. static void (*setCrtMode)(ushort mode);
  97. static ushort (*getCrtMode)();
  98. // Not found in original TV 2.0
  99. // Robert added it to know the cursor position and restore it.
  100. static void (*getCursorPos)(unsigned &x, unsigned &y); // old GetCursor
  101. static void (*setCursorPos)(unsigned x, unsigned y); // ols SetCursor
  102. // SET: I moved it to the class
  103. // Returns 0 if the MSB of the background selects more colors.
  104. static int (*getBlinkState)();
  105. // SET: A new and more rasonable way to choose a video mode
  106. // static int (*setCrtModeRes)(unsigned w, unsigned h, int fW=-1, int fH=-1);
  107. static int (*setCrtModeRes)(unsigned w, unsigned h, int fW, int fH);
  108. // SET: These are the real functions for *CursorType
  109. static void (*setCursorShape)(unsigned start, unsigned end);
  110. static void (*getCursorShape)(unsigned &start, unsigned &end);
  111. // SET: This version sets the mode through an external program or other complex
  112. // mode setting.
  113. static void (*setCrtModeExt)(char *mode);
  114. // SET: Fonts handling. I changed it for a new approach, see TScreen
  115. // SET: Checks if screen size was changed by an external "force"
  116. static int (*checkForWindowSize)(void);
  117. // SET: For windowed cases
  118. static
  119. const char *(*getWindowTitle)(void);
  120. static int (*setWindowTitle)(const char *name);
  121. // SET: Roman Valyushenko propposed some mechanism no indicate the
  122. // application is busy
  123. static Boolean (*showBusyState)(Boolean state);
  124. // SET: The bell/beep is something really tied to the terminal
  125. static void (*beep)();
  126. static void bell() { beep(); };
  127. // This should be called before initialization.
  128. // Isn't mandatory but helps some drivers.
  129. static void setArgv(int aArgc, char **aArgv, char **aEnvir);
  130. // Driver options
  131. static Boolean setShowCursorEver(Boolean value);
  132. static Boolean getShowCursorEver() { return opts1 & ShowCursorEver ? True : False; };
  133. static Boolean setDontMoveHiddenCursor(Boolean value);
  134. static Boolean getDontMoveHiddenCursor() { return opts1 & DontMoveHiddenCursor ? True : False; };
  135. // Helper to look for the closest resolution from a list
  136. static Boolean searchClosestRes(TScreenResolution *res, unsigned x, unsigned y,
  137. unsigned cant, unsigned &pos);
  138. // Returns the default palette
  139. static const TScreenColor *getDefaultPalette() { return PC_BIOSPalette; }
  140. // Uses to be called when driver is detected but not yet initialized
  141. static TVScreenDriverDetectCallBack setDetectCallBack(TVScreenDriverDetectCallBack aCB);
  142. // Searchs information about a known DOS video mode
  143. static Boolean searchDOSModeInfo(ushort mode, unsigned &w, unsigned &h, int &fW, int &fH);
  144. // Used to know the format needed for buffers passed to setCharacters
  145. static int getDrawingMode() { return drawingMode; }
  146. // Tables for the DOS video modes, used to look for similar modes by other drivers
  147. static TScreenResolution dosModesRes[];
  148. static TScreenResolution dosModesCell[];
  149. static int dosModes[];
  150. // Drawing modes:
  151. // codepage: cells are 8 bits, the first is the character in the current code
  152. // page encoding and the next is the colors attribute.
  153. // unicode16: cells are 16 bits, the first is the 16 bits unicode value and
  154. // the next is the colors attribute.
  155. enum { codepage=0, unicode16=1 };
  156. // We must remove it
  157. static int dual_display;
  158. protected:
  159. // SET: Those are more complex so now they aren't inline
  160. TDisplay();
  161. TDisplay(const TDisplay&);
  162. // We will use casts to base classes, destructors must be pointers
  163. virtual ~TDisplay();
  164. // A copy of the command line arguments, old applications doesn't
  165. // provide it.
  166. static int argc;
  167. static char **argv;
  168. // Note: MinGW defines a macro called environ in stdlib.h so no C++
  169. // member can be named environ. It should be just _environ and the
  170. // internal name __environ. Is a serious namespace pollution.
  171. static char **environment;
  172. // Special options
  173. enum Options1
  174. {
  175. ShowCursorEver=1, // The main goal of this option is to verify the help
  176. // for Braille Terminals
  177. DontMoveHiddenCursor=2 // This option disables the help for Braille
  178. // Terminals in favor of speed.
  179. };
  180. static uint32 opts1;
  181. // Helper to access TVCodePage and set the default values
  182. static void SetDefaultCodePages(int idScr, int idApp, int idInp);
  183. // Hardware Palette handling routines and variables.
  184. // This is low level and should be called from TScreen.
  185. static void (*getDisPaletteColors)(int from, int number, TScreenColor *colors);
  186. static int (*setDisPaletteColors)(int from, int number, TScreenColor *colors);
  187. // The shell/user palette
  188. static TScreenColor OriginalPalette[16];
  189. // The palette we are using
  190. static TScreenColor ActualPalette[16];
  191. // The PC BIOS palette
  192. static TScreenColor PC_BIOSPalette[16];
  193. // To know if the palette changed (set by high level routines)
  194. static char paletteModified;
  195. // This is the palette parsed from the tvrc file or the application
  196. static TScreenColor UserStartPalette[16];
  197. // Code page initializator
  198. static TVCodePage *codePage;
  199. // Initialization call back
  200. static TVScreenDriverDetectCallBack dCB;
  201. // Are we showing signs of busy state?
  202. static Boolean busyState;
  203. // Format used for the drawing calls (codepage, unicode16, etc.)
  204. static int drawingMode;
  205. // Default behaviors
  206. static void defaultClearScreen(uchar, uchar);
  207. static ushort defaultGetRows();
  208. static ushort defaultGetCols();
  209. static void defaultSetCrtMode(ushort mode);
  210. static ushort defaultGetCrtMode();
  211. static void defaultGetCursorPos(unsigned &x, unsigned &y);
  212. static void defaultSetCursorPos(unsigned x, unsigned y);
  213. static void defaultSetCursorShape(unsigned start, unsigned end);
  214. static void defaultGetCursorShape(unsigned &start, unsigned &end);
  215. static void defaultSetCrtModeExt(char *mode);
  216. static int defaultCheckForWindowSize(void);
  217. static const char *defaultGetWindowTitle(void);
  218. static int defaultSetWindowTitle(const char *name);
  219. static int defaultGetBlinkState();
  220. static void defaultGetDisPaletteColors(int from, int number, TScreenColor *colors);
  221. static int defaultSetDisPaletteColors(int from, int number, TScreenColor *colors);
  222. static int defaultSetCrtModeRes(unsigned w, unsigned h, int fW=-1, int fH=-1);
  223. static Boolean defaultShowBusyState(Boolean state);
  224. static void defaultBeep();
  225. private:
  226. // From original TV 2.0.
  227. // As they are private I just ignore them.
  228. //static void videoInt();
  229. //static void updateIntlChars();
  230. // From where they came from? TV 1.03?
  231. //static ushort * equipment;
  232. //static uchar * crtInfo;
  233. //static uchar * crtRows;
  234. //static uchar Page;
  235. };
  236. // virtual to avoid problems with multiple inheritance
  237. class TScreen : virtual public TDisplay
  238. {
  239. public:
  240. // From original TV 2.0
  241. TScreen();
  242. // We will use casts to base classes, destructors must be pointers
  243. virtual ~TScreen();
  244. static void (*setVideoMode)(ushort mode);
  245. static void (*clearScreen)();
  246. static ushort startupMode;
  247. static ushort startupCursor;
  248. static ushort screenMode;
  249. static uchar screenWidth;
  250. static uchar screenHeight;
  251. // True if it have more than 25 lines (obsolete)
  252. static Boolean hiResScreen;
  253. // True if we must be careful about writing to video screen (obsolete)
  254. static Boolean checkSnow;
  255. // Current cursor shape
  256. static ushort cursorLines;
  257. // Pointer to the screen arranged as Attribut/Character array.
  258. // This is optional and in some particular platform could be a NULL pointer.
  259. // SET: Changed to avoid problems, in fact some casts to int failed in
  260. // Alpha/Linux. We found it with Dim Zegebart.
  261. static uint16 *screenBuffer;
  262. static void (*setCrtData)();
  263. static ushort (*fixCrtMode)(ushort mode);
  264. // SET: Currently they are wrappers that ensure we don't nest calls and
  265. // then calls the real members.
  266. static void suspend();
  267. static void resume();
  268. // SET: Real suspend and resume
  269. static void (*Suspend)();
  270. static void (*Resume)();
  271. // New functionality
  272. // Needed by some mouse handlers
  273. static ushort (*getCharacter)(unsigned offset);
  274. // Only used internally by Win32 ports
  275. static void (*getCharacters)(unsigned offset, ushort *buf, unsigned count);
  276. // Used by TView and some mouse handlers, also internally
  277. static void (*setCharacter)(unsigned offset, uint32 value);
  278. static void (*setCharacters)(unsigned offset, ushort *values, unsigned count);
  279. // SET: Used to set the video mode using an external program
  280. static void (*setVideoModeExt)(char *mode);
  281. // SET: Set the video mode using sizes.
  282. static int (*setVideoModeRes)(unsigned w, unsigned h, int fW, int fH);
  283. // SET: executes the indicated command
  284. static int (*System)(const char *command, pid_t *pidChild, int in,
  285. int out, int err);
  286. // Palette handling, they call the TDisplay members
  287. static void getPaletteColors(int from, int number, TScreenColor *colors);
  288. static void setPaletteColors(int from, int number, TScreenColor *colors);
  289. static void resetPalette(); // Sets the original palette
  290. // Font handling
  291. // These funtions can fail and only drivers with CanSetFontSize should
  292. // implement theme. The rest uses defaults that ever fails.
  293. static int (*getFontGeometry)(unsigned &w, unsigned &h);
  294. static int (*getFontGeometryRange)(unsigned &wmin, unsigned &hmin,
  295. unsigned &umax, unsigned &hmax);
  296. // The following are implemented only if CanSetBFont and/or CanSetSBFont
  297. // are set.
  298. static int setPrimaryFont(TScreenFont256 *font, int fontCP=-1, int appCP=-1)
  299. { return setFont(1,font,0,NULL,fontCP,appCP); };
  300. static int setSecondaryFont(TScreenFont256 *font)
  301. { return setFont(0,NULL,1,font,-1,-1); };
  302. // That's the real function to set the fonts
  303. static int (*setFont)(int changeP, TScreenFont256 *fontP,
  304. int changeS, TScreenFont256 *fontS,
  305. int fontCP, int appCP);
  306. static void (*restoreFonts)();
  307. static TVScreenFontRequestCallBack
  308. setFontRequestCallBack(TVScreenFontRequestCallBack cb);
  309. // Helpers:
  310. static int disableSecondaryFont() { return setSecondaryFont(NULL); };
  311. static int disablePrimaryFont() { return setPrimaryFont(NULL); };
  312. static Boolean isSecondaryFontEnabled() { return useSecondaryFont ? True : False; };
  313. // It looks for a configuration variable that belongs to the current driver
  314. static Boolean optSearch(const char *variable, long &val);
  315. static char *optSearch(const char *variable);
  316. static const char
  317. *getDriverShortName() { return currentDriverShortName; }
  318. static void beep() { TDisplay::beep(); };
  319. static void bell() { TDisplay::beep(); };
  320. // SET: flags capabilities flags
  321. enum Capabilities1
  322. {
  323. CodePageVar=1,
  324. CanSetPalette=2, // We can change colors
  325. CanReadPalette=4, // We have reliable information about the original colors.
  326. // If this value isn't present the user can set the palette,
  327. // but the original colors want be restored at exit. We will
  328. // try to let them as default for the used display.
  329. PalNeedsRedraw=8, // Indicates we must redraw after changing the palette.
  330. CursorShapes=16, // When the cursor shape is usable.
  331. UseScreenSaver=32, // Does screen saver have any sense for this driver?
  332. CanSetBFont=64, // We can set the primary bitmap font
  333. CanSetSBFont=128, // We can set the secondary bitmap font
  334. CanSetFontSize=256, // We can set the width and height of the font
  335. CanSetVideoSize=512,// We can set the video size (window size or video mode)
  336. NoUserScreen=0x400 // No user screen exists i.e. we are in a window we draw
  337. };
  338. // Used internally to avoid nested calls to suspend/resume
  339. static char suspended;
  340. // SET: Indicates if the screen was initialized by the TScreen constructor
  341. static char initialized;
  342. // SET: It says if we should offer the user to select the code page
  343. // or the terminal have a fixed encoding and needs things as is.
  344. static Boolean codePageVariable() { return flags0 & CodePageVar ? True : False; };
  345. static Boolean canSetPalette() { return flags0 & CanSetPalette ? True : False; };
  346. static Boolean canReadPalette() { return flags0 & CanReadPalette ? True : False; };
  347. static Boolean palNeedsRedraw() { return flags0 & PalNeedsRedraw ? True : False; };
  348. static Boolean cursorShapes() { return flags0 & CursorShapes ? True : False; };
  349. static Boolean useScreenSaver() { return flags0 & UseScreenSaver ? True : False; };
  350. static Boolean canSetBFont() { return flags0 & CanSetBFont ? True : False; };
  351. static Boolean canSetSBFont() { return flags0 & CanSetSBFont ? True : False; };
  352. static Boolean canSetFontSize() { return flags0 & CanSetFontSize ? True : False; };
  353. static Boolean canSetVideoSize() { return flags0 & CanSetVideoSize ? True : False; };
  354. static Boolean noUserScreen() { return flags0 & NoUserScreen ? True : False; };
  355. protected:
  356. // SET: Capabilities flags
  357. static uint32 flags0;
  358. static const char *currentDriverShortName;
  359. // Indicates if we must use the secondary font for the higher foreground
  360. // colors.
  361. static char useSecondaryFont;
  362. // Font Request Call Back
  363. static TVScreenFontRequestCallBack frCB;
  364. // Values from the user configuration
  365. static long forcedAppCP, forcedScrCP, forcedInpCP;
  366. // Used to set the palette requested by the user/application
  367. static Boolean parseUserPalette();
  368. // SET: Default behaviors:
  369. static void defaultSetVideoMode(ushort mode);
  370. static void defaultSetVideoModeExt(char *mode);
  371. static int defaultSetVideoModeRes(unsigned w, unsigned h, int fW=-1, int fH=-1);
  372. static void defaultClearScreen();
  373. static void defaultSetCrtData();
  374. static ushort defaultFixCrtMode(ushort mode);
  375. static ushort defaultGetCharacter(unsigned offset);
  376. static void defaultGetCharacters(unsigned offset, ushort *buf, unsigned count);
  377. static void defaultSetCharacter(unsigned offset, uint32 value);
  378. static void defaultSetCharacters(unsigned offset, ushort *values, unsigned count);
  379. static int defaultSystem(const char *command, pid_t *pidChild, int in, int out,
  380. int err);
  381. static int defaultGetFontGeometry(unsigned &w, unsigned &h);
  382. static int defaultGetFontGeometryRange(unsigned &wmin, unsigned &hmin,
  383. unsigned &umax, unsigned &hmax);
  384. static int defaultSetFont(int changeP, TScreenFont256 *fontP,
  385. int changeS, TScreenFont256 *fontS,
  386. int fontCP=-1, int appCP=-1);
  387. static void defaultRestoreFonts();
  388. // The following members are used to implement a tricky initialization
  389. // process.
  390. // Externally it looks like a the old mechanism, you create a TScreen object
  391. // and you destroy it. Internally it detects the correct driver and creates
  392. // an object of this class, when you destroy the TScreen objects it destroys
  393. // the right class.
  394. private:
  395. // SET: It indicates the class is initialized or at least trying to do it
  396. // It avoids problems with inheritance and calls to base classes.
  397. static char initCalled;
  398. static TScreen *driver;
  399. };
  400. #if 0
  401. // SET: Added the following functionallity:
  402. // Linux specific stuff, enclose it in TVOSf_Linux section:
  403. // If you want to setup a specific value define this variable in your code
  404. // and assign a value. If the variable isn't in your code the linker will use
  405. // a definition found in the library.
  406. extern unsigned TurboVision_screenOptions;
  407. // This value makes the screen driver try to provide a mode that supports
  408. // a switch to the user screen.
  409. // Current example: if the TScreen class have access to the /dev/vcsaN
  410. // devices for writing we can't provide user screen (no way to read the
  411. // screen and tcsetattr or endwin() fails). Even with that it's better than
  412. // using escape sequences, but RHIDE will work better if can switch. So I'm
  413. // adding it so Robert can ask for it (or not).
  414. const unsigned TurboVision_screenUserScreenNeeded=1;
  415. // SET: Moved/Redefined
  416. // Internally used by Linux driver, don't use
  417. #endif
  418. #endif // Uses_TScreen