VIDEO.CPP 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. ** Command & Conquer Red Alert(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. /****************************************************************************
  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. *
  24. * FILE
  25. * video.c
  26. *
  27. * DESCRIPTION
  28. * Video mode setting. (32-Bit protected mode)
  29. *
  30. * PROGRAMMER
  31. * Denzil E. Long, Jr.
  32. *
  33. * DATE
  34. * Febuary 3, 1995
  35. *
  36. *----------------------------------------------------------------------------
  37. *
  38. * PUBLIC
  39. * SetVideoMode - Set the video mode.
  40. * GetDisplayInfo - Get the display info for the current video mode.
  41. * GetVBIBit - Get the vertical blank bit polarity.
  42. *
  43. ****************************************************************************/
  44. #include <stdlib.h>
  45. #include <dos.h>
  46. #include <conio.h>
  47. #ifndef __WATCOMC__
  48. #include <pharlap.h>
  49. #include <pldos32.h>
  50. #else
  51. #include "realmode.h"
  52. #endif
  53. #include "video.h"
  54. /*---------------------------------------------------------------------------
  55. * PRIVATE DECLARATIONS
  56. *-------------------------------------------------------------------------*/
  57. static DisplayInfo _Display = {-1,0,0,0,NULL};
  58. /****************************************************************************
  59. *
  60. * NAME
  61. * SetVideoMode - Set the display to the specified video mode.
  62. *
  63. * SYNOPSIS
  64. * DisplayInfo = SetVideoMode(Mode)
  65. *
  66. * DisplayInfo *SetVideoMode(long);
  67. *
  68. * FUNCTION
  69. * Set the video display adapter to the desired video mode.
  70. *
  71. * INPUTS
  72. * Mode - Desired video mode.
  73. *
  74. * RESULT
  75. * DisplayInfo - Pointer to DisplayInfo structure, otherwise 0 for error.
  76. *
  77. ****************************************************************************/
  78. DisplayInfo *SetVideoMode(long mode)
  79. {
  80. #ifdef __WATCOMC__
  81. union REGS regs;
  82. struct SREGS sregs;
  83. #else
  84. union _REGS regs;
  85. #endif
  86. DisplayInfo *di = NULL;
  87. VESAModeInfo *vminfo;
  88. long error;
  89. /* Initialize the video manager on the first invocation of
  90. * SetVideoMode()
  91. */
  92. if (_Display.Mode == -1) {
  93. _Display.VBIbit = TestVBIBit();
  94. }
  95. /* Clear the VRAM before enabling the mode so that there is
  96. * not any garbage on the screen.
  97. */
  98. ClearVRAM();
  99. /* If the requested mode is the same as the current mode then
  100. * we do not need to do anything.
  101. */
  102. if (mode != _Display.Mode) {
  103. /* Uninitialize VESA if the previous mode was a VESA mode and the new
  104. * mode is not.
  105. */
  106. if (((_Display.Mode >= VESA_MIN) && (_Display.Mode <= VESA_MAX))
  107. && ((mode < VESA_MIN) && (mode > VESA_MAX))) {
  108. UninitVESA();
  109. }
  110. /* Set display to an XMode. */
  111. if ((mode >= XMODE_MIN) && (mode <= XMODE_MAX)) {
  112. SetXMode(mode);
  113. ClearXMode();
  114. SetupXPaging();
  115. ShowXPage(0);
  116. _Display.Mode = mode;
  117. _Display.Extended = NULL;
  118. di = &_Display;
  119. /* Set display resolution information */
  120. switch (mode) {
  121. case XMODE_320X200:
  122. _Display.XRes = 320;
  123. _Display.YRes = 200;
  124. break;
  125. case XMODE_320X240:
  126. _Display.XRes = 320;
  127. _Display.YRes = 240;
  128. break;
  129. case XMODE_320X400:
  130. _Display.XRes = 320;
  131. _Display.YRes = 400;
  132. break;
  133. case XMODE_320X480:
  134. _Display.XRes = 320;
  135. _Display.YRes = 480;
  136. break;
  137. case XMODE_360X400:
  138. _Display.XRes = 360;
  139. _Display.YRes = 400;
  140. break;
  141. case XMODE_360X480:
  142. _Display.XRes = 360;
  143. _Display.YRes = 480;
  144. break;
  145. }
  146. }
  147. else if ((mode >= VESA_MIN) && (mode <= VESA_MAX)) {
  148. /* Initialize the VESA manager if the current mode is not a VESA
  149. * mode.
  150. */
  151. if ((_Display.Mode < VESA_MIN) || (_Display.Mode > VESA_MAX)) {
  152. error = InitVESA();
  153. }
  154. if (!error) {
  155. /* Set the display to MCGA before going into VESA. This needs to be
  156. * done to ensure that the video ram selector is initialized. This
  157. * fixes a bug in some VESA BIOS'.
  158. */
  159. #ifndef __WATCOMC__
  160. regs.x.ax = mode;
  161. _int86(0x10, &regs, &regs);
  162. #else
  163. segread(&sregs);
  164. regs.x.eax = mode;
  165. int386x(0x10, &regs, &regs, &sregs);
  166. #endif
  167. if ((vminfo = SetVESAMode(mode)) != NULL) {
  168. _Display.Mode = mode;
  169. _Display.XRes = (long)vminfo->XRes;
  170. _Display.YRes = (long)vminfo->YRes;
  171. _Display.Extended = vminfo;
  172. di = &_Display;
  173. }
  174. }
  175. }
  176. else {
  177. #ifndef __WATCOMC__
  178. regs.x.ax = mode;
  179. _int86(0x10, &regs, &regs);
  180. #else
  181. segread(&sregs);
  182. regs.x.eax = mode;
  183. int386x(0x10, &regs, &regs, &sregs);
  184. #endif
  185. _Display.Mode = mode;
  186. _Display.XRes = 320;
  187. _Display.YRes = 200;
  188. _Display.Extended = NULL;
  189. di = &_Display;
  190. }
  191. } else {
  192. di = &_Display;
  193. }
  194. return (di);
  195. }
  196. /****************************************************************************
  197. *
  198. * NAME
  199. * GetDisplayInfo - Get the display info for the current video mode.
  200. *
  201. * SYNOPSIS
  202. * DisplayInfo = GetDisplayInfo()
  203. *
  204. * DisplayInfo *GetDisplayInfo(void);
  205. *
  206. * FUNCTION
  207. * Return a pointer to the current display information structure.
  208. *
  209. * INPUTS
  210. * NONE
  211. *
  212. * RESULT
  213. * DisplayInfo - Pointer to initialized display info or NULL if not valid.
  214. *
  215. ****************************************************************************/
  216. DisplayInfo *GetDisplayInfo(void)
  217. {
  218. if (_Display.Mode != 0) {
  219. return (&_Display);
  220. } else {
  221. return (NULL);
  222. }
  223. }
  224. /****************************************************************************
  225. *
  226. * NAME
  227. * GetVBIBit - Get the vertical blank bit polarity.
  228. *
  229. * SYNOPSIS
  230. * VBIBit = GetVBIBit()
  231. *
  232. * long GetVBIBit(void);
  233. *
  234. * FUNCTION
  235. * Return the polarity of the vertical blank bit.
  236. *
  237. * INPUTS
  238. * NONE
  239. *
  240. * RESULT
  241. * VBIBit - Vertical blank bit polarity.
  242. *
  243. ****************************************************************************/
  244. long GetVBIBit(void)
  245. {
  246. return (_Display.VBIbit);
  247. }