CONFIG.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. * PROJECT
  25. * VQA player library. (32-Bit protected mode)
  26. *
  27. * FILE
  28. * config.c
  29. *
  30. * DESCRIPTION
  31. * Player configuration routines.
  32. *
  33. * PROGRAMMER
  34. * Bill Randolph
  35. * Denzil E. Long, Jr.
  36. *
  37. * DATE
  38. * April 10, 1995
  39. *
  40. *----------------------------------------------------------------------------
  41. *
  42. * PUBLIC
  43. * VQA_INIConfig - Initialize VQAConfig structure with INI settings.
  44. * VQA_DefaultConfig - Initialize VQAConfig structure with defaults.
  45. *
  46. ****************************************************************************/
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <string.h>
  50. #include "vqaplayp.h"
  51. #include <vqm32\all.h>
  52. /*---------------------------------------------------------------------------
  53. * PRIVATE DECLARATIONS
  54. *-------------------------------------------------------------------------*/
  55. /* Default configuration structure. */
  56. static VQAConfig _defaultconfig = {
  57. /* DrawerCallback: This is a function that is called for every frame
  58. * in the movie.
  59. */
  60. NULL,
  61. /* EventHandler: This is a function that is called for every event that
  62. * the client requested to be notified about.
  63. */
  64. NULL,
  65. /* NotifyFlags: Flags representing the events the client wishes to be
  66. * notified about during playback.
  67. */
  68. NULL,
  69. /* Vmode: Video mode to use. */
  70. MCGA,
  71. /* VBIBit: Vertical blank bit polarity. */
  72. -1,
  73. /* ImageBuf: Pointer to image buffer to draw into. */
  74. NULL,
  75. /* ImageWidth, ImageHeight: Width and height dimensions of image buffer.
  76. * A width and height value of -1 tells the player to consider the image
  77. * buffer as having the same dimensions as the frames in the movie.
  78. */
  79. 320, 200, /* Image width and height */
  80. /* X1, Y1: These are the coordinates to put the movies frame in the image
  81. * buffer. Values of -1 tell the drawer to center the frames in the buffer.
  82. */
  83. -1, -1,
  84. /* FrameRate: The rate to load the frames at. A value of -1 tells the
  85. * player to use the framerate of the movie.
  86. */
  87. -1,
  88. /* DrawRate: The rate to draw the frames at. A value of -1 tells the
  89. * player to use the framerate of the movie. A value of 0 tells the player
  90. * to use a fixed rate based on the frame size.
  91. */
  92. -1,
  93. /* TimerMethod: Timer method to use for playback. */
  94. -1,
  95. /* DrawFlags: Various drawing related flags. */
  96. 0,
  97. /* OptionFlags: Various player options. */
  98. VQAOPTF_AUDIO,
  99. /* NumFrameBufs: The number of frame buffers to allocate/use. */
  100. 6,
  101. /* NumCBBufs: The number of codebook buffers to allocate/use. */
  102. 3,
  103. #if (VQADIRECT_SOUND)
  104. /* -----------------12/15/95 10:40AM-----------------
  105. * SoundObject - ptr to games direct sound object. Null if VQ should create
  106. * --------------------------------------------------*/
  107. NULL,
  108. /* -----------------12/15/95 10:41AM-----------------
  109. * PrimaryBufferPtr - ptr to games primary sound buffer. Null if VQ should create
  110. * --------------------------------------------------*/
  111. NULL,
  112. #endif //(VQADIRECT_SOUND)
  113. /* VocFile: Filename of audio track override. A value of 0 tells the
  114. * player not to override the movies audio track.
  115. */
  116. NULL,
  117. /* AudioBuf: Audio buffer to use. A value of 0 tells the player that
  118. * it has to allocate a buffer itself.
  119. */
  120. NULL,
  121. /* AudioBufSize: Size of audio buffer to use/allocate. A value of -1
  122. * tells the player to compute the buffer size from the audio
  123. * information in the movie.
  124. */
  125. -1,
  126. /* AudioRate: Audio playback rate in samples per second. A value of -1
  127. * tells the player to use the audio rate of the movie.
  128. */
  129. -1,
  130. /* Volume: Volume level to playback audio track. */
  131. 0x00FF,
  132. /* HMIBufSize: Size of HMIs internal buffer. */
  133. #if (VQADIRECT_SOUND)
  134. 8192L,
  135. #else
  136. 2048L,
  137. #endif
  138. /* DigiHandle: Handle to an initialized HMI sound driver. A value of -1
  139. * tells the player it must initialize the HMI sound driver itself.
  140. */
  141. -1,
  142. /* DigiCard: HMI ID of audio card to use. A value of 0 tells the player
  143. * not to use any card. A value of -1 tells the player to autodetect the
  144. * card in the system.
  145. */
  146. -1,
  147. /* DigiPort: Port address of the sound card. A value of -1 tells the player
  148. * to autodetect this address.
  149. */
  150. -1,
  151. /* DigiIRQ: Interrupt number of sound card. A value of -1 tells the player
  152. * to autodetect the interrupt used by the card.
  153. */
  154. -1,
  155. /* DigiDMA: DMA channel of the sound card. A value of -1 tells the player
  156. * to autodetect the channel used by the card.
  157. */
  158. -1,
  159. /* Language: Prefered language. */
  160. 0,
  161. /* CaptionFont: Caption text font. */
  162. NULL,
  163. /* EVAFont: EVA text font. */
  164. NULL,
  165. };
  166. /* Supported video modes. */
  167. #if(VQAVIDEO_ON)
  168. enum VMTAGS {
  169. VMTAG_NONE = 0,
  170. #if(VQAMCGA_ON)
  171. VMTAG_MCGA,
  172. VMTAG_MCGA_BUF,
  173. #endif
  174. #if(VQAXMODE_ON)
  175. VMTAG_XMODE320X200,
  176. VMTAG_XMODE320X200_BUF,
  177. VMTAG_XMODE320X200_VRAM,
  178. VMTAG_XMODE320X240,
  179. VMTAG_XMODE320X240_BUF,
  180. VMTAG_XMODE320X240_VRAM,
  181. #endif
  182. #if(VQAVESA_ON)
  183. VMTAG_VESA640X480_BUF,
  184. VMTAG_VESA640X480_X2,
  185. VMTAG_VESA320X200,
  186. VMTAG_VESA320X200_BUF,
  187. #endif
  188. };
  189. typedef struct _VideoModeTag {
  190. char const *token;
  191. long id;
  192. } VideoModeTag;
  193. VideoModeTag VideoModeTags[] = {
  194. {"NONE",VMTAG_NONE},
  195. #if(VQAMCGA_ON)
  196. {"MCGA", VMTAG_MCGA},
  197. {"MCGA_BUF",VMTAG_MCGA_BUF},
  198. #endif /* VQAMCGA_ON */
  199. #if(VQAXMODE_ON)
  200. {"XMODE_320X200", VMTAG_XMODE320X200},
  201. {"XMODE_320X200_BUF", VMTAG_XMODE320X200_BUF},
  202. {"XMODE_320X200_VRAM",VMTAG_XMODE320X200_VRAM},
  203. {"XMODE_320X240", VMTAG_XMODE320X240},
  204. {"XMODE_320X240_BUF", VMTAG_XMODE320X240_BUF},
  205. {"XMODE_320X240_VRAM",VMTAG_XMODE320X240_VRAM},
  206. #endif /* VQAXMODE_ON */
  207. #if(VQAVESA_ON)
  208. {"VESA_640X480_BUF",VMTAG_VESA640X480_BUF},
  209. {"VESA_640X480_X2", VMTAG_VESA640X480_X2},
  210. {"VESA_320X200", VMTAG_VESA320X200},
  211. {"VESA_320X200_BUF",VMTAG_VESA320X200_BUF},
  212. #endif /* VQAVESA_ON */
  213. {NULL, NULL}
  214. };
  215. #endif /* VQAVIDEO_ON */
  216. /****************************************************************************
  217. *
  218. * NAME
  219. * VQA_INIConfig - Initialize VQAConfig structure with INI settings.
  220. *
  221. * SYNOPSIS
  222. * VQA_INIConfig(Config)
  223. *
  224. * void VQA_INIConfig(VQAConfig *);
  225. *
  226. * FUNCTION
  227. * Initializes the configuration structure from the player INI file.
  228. *
  229. * INPUTS
  230. * Config - Pointer to VQAConfig structure.
  231. *
  232. * RESULT
  233. * NONE
  234. *
  235. ****************************************************************************/
  236. void VQA_INIConfig(VQAConfig *config)
  237. {
  238. char *ininame;
  239. char buf[80];
  240. long i;
  241. /* Set all Config entries to 0. */
  242. memset(config, 0, sizeof(VQAConfig));
  243. /* Retrieve player INI filename from an enviroment variable if
  244. * it is provided.
  245. */
  246. if ((ininame = getenv("VQACFG")) == NULL) {
  247. ininame = "PLAYER.INI";
  248. }
  249. /*-------------------------------------------------------------------------
  250. * VIDEO MODE AND DRAW FLAGS
  251. *-----------------------------------------------------------------------*/
  252. #if(VQAVIDEO_ON)
  253. /* Get video mode from INI */
  254. GetINIString("Player", "PlayerMode", "MCGA", buf, 80, ininame);
  255. /* Search supported modes for a match. */
  256. i = 0;
  257. while (VideoModeTags[i].token != NULL) {
  258. if (stricmp(buf, VideoModeTags[i].token) == 0) {
  259. break;
  260. }
  261. i++;
  262. }
  263. /* Setup for requested mode */
  264. switch (VideoModeTags[i].id) {
  265. /* MCGA direct */
  266. #if(VQAMONO_ON)
  267. case VMTAG_MCGA:
  268. config->Vmode = MCGA;
  269. break;
  270. /* MCGA buffered */
  271. case VMTAG_MCGA_BUF:
  272. config->Vmode = MCGA;
  273. config->DrawFlags |= VQACFGF_BUFFER;
  274. break;
  275. #endif /* VQAMCGA_ON */
  276. /* XMODE direct (320x200) */
  277. #if(VQAXMODE_ON)
  278. case VMTAG_XMODE320X200:
  279. config->Vmode = XMODE_320X200;
  280. break;
  281. /* XMODE buffered (320x200) */
  282. case VMTAG_XMODE320X200_BUF:
  283. config->Vmode = XMODE_320X200;
  284. config->DrawFlags |= VQACFGF_BUFFER;
  285. break;
  286. /* XMODE VRAM codebook (320x200) */
  287. case VMTAG_XMODE320X200_VRAM:
  288. config->Vmode = XMODE_320X200;
  289. config->DrawFlags |= VQACFGF_VRAMCB;
  290. break;
  291. /* XMODE direct (320x240) */
  292. case VMTAG_XMODE320X240:
  293. config->Vmode = XMODE_320X240;
  294. break;
  295. /* XMODE buffered (320x240) */
  296. case VMTAG_XMODE320X240_BUF:
  297. config->Vmode = XMODE_320X240;
  298. config->DrawFlags |= VQACFGF_BUFFER;
  299. break;
  300. /* XMODE VRAM codebook (320x240) */
  301. case VMTAG_XMODE320X240_VRAM:
  302. config->Vmode = XMODE_320X240;
  303. config->DrawFlags |= VQACFGF_VRAMCB;
  304. break;
  305. #endif /* VQAXMODE_ON */
  306. /* VESA buffered (640x480_256) */
  307. #if(VQAVESA_ON)
  308. case VMTAG_VESA640X480_BUF:
  309. config->Vmode = VESA_640X480_256;
  310. config->DrawFlags |= VQACFGF_BUFFER;
  311. break;
  312. /* VESA buffered scaled (640x480_256) */
  313. case VMTAG_VESA640X480_X2:
  314. config->Vmode = VESA_640X480_256;
  315. config->DrawFlags |= (VQACFGF_BUFFER|VQACFGF_SCALEX2);
  316. break;
  317. /* VESA direct (320x200_32k) */
  318. case VMTAG_VESA320X200:
  319. config->Vmode = VESA_320X200_32K_1;
  320. break;
  321. /* VESA buffered (320x200_32k) */
  322. case VMTAG_VESA320X200_BUF:
  323. config->Vmode = VESA_320X200_32K_1;
  324. config->DrawFlags |= VQACFGF_BUFFER;
  325. break;
  326. #endif /* VQAVESA_ON */
  327. /* Default to MCGA direct */
  328. VMTAG_NONE:
  329. default:
  330. config->Vmode = MCGA;
  331. break;
  332. }
  333. #endif /* VQAVIDEO_ON */
  334. /* Get framerate and drawrate. */
  335. GetINIString("Player", "FrameRate", "-1", buf, 80, ininame);
  336. config->FrameRate = atoi(buf);
  337. GetINIString("Player", "DrawRate", "Variable", buf, 80, ininame);
  338. if (!stricmp(buf, "Variable")) {
  339. config->DrawRate = -1;
  340. } else {
  341. config->DrawRate = 0;
  342. }
  343. /*-------------------------------------------------------------------------
  344. * AUDIO SETTINGS
  345. *-----------------------------------------------------------------------*/
  346. GetINIString("Player", "AudioRate", "-1", buf, 80, ininame);
  347. config->AudioRate = atoi(buf);
  348. /* OptionFlags */
  349. GetINIString("Player", "SoundEnabled", "True", buf, 80, ininame);
  350. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  351. config->OptionFlags |= VQAOPTF_AUDIO;
  352. } else {
  353. config->OptionFlags &= (~VQAOPTF_AUDIO);
  354. }
  355. /* Default audio settings. */
  356. config->AudioBufSize = 32768U;
  357. config->HMIBufSize = 2048;
  358. config->DigiHandle = -1;
  359. config->Volume = 0x00FF;
  360. config->DigiCard = 0xFFFF;
  361. config->DigiPort = -1;
  362. config->DigiIRQ = -1;
  363. config->DigiDMA = -1;
  364. /* Configure sound hardware */
  365. GetINIString("Player", "Port", "-1", buf, 80, ininame);
  366. if (!stricmp(buf, "-1")) {
  367. config->DigiPort = -1;
  368. } else {
  369. sscanf(buf, "%x", &config->DigiPort);
  370. }
  371. GetINIString("Player", "IRQ", "-1", buf, 80, ininame);
  372. config->DigiIRQ = atoi(buf);
  373. GetINIString("Player", "DMA", "-1", buf, 80, ininame);
  374. config->DigiDMA = atoi(buf);
  375. /*-------------------------------------------------------------------------
  376. * GENERAL OPTIONS
  377. *-----------------------------------------------------------------------*/
  378. /* Enable/Disable single stepping */
  379. GetINIString("Player", "SingleStep", "False", buf, 80, ininame);
  380. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  381. config->OptionFlags |= VQAOPTF_STEP;
  382. config->DrawFlags |= VQACFGF_NOSKIP;
  383. } else {
  384. config->OptionFlags &= (~VQAOPTF_STEP);
  385. }
  386. /* Enable/Disable Slowpalette */
  387. GetINIString("Player", "SlowPalette", "False", buf, 80, ininame);
  388. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  389. config->OptionFlags |= VQAOPTF_SLOWPAL;
  390. } else {
  391. config->OptionFlags &= (~VQAOPTF_SLOWPAL);
  392. }
  393. /* Enable/Disable monochrome display */
  394. GetINIString("Player", "MonoOutput", "False", buf, 80, ininame);
  395. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  396. config->OptionFlags |= VQAOPTF_MONO;
  397. } else {
  398. config->OptionFlags &= (~VQAOPTF_MONO);
  399. }
  400. /* Frame and codebook buffers */
  401. config->NumFrameBufs = 6;
  402. config->NumCBBufs = 3;
  403. }
  404. /****************************************************************************
  405. *
  406. * NAME
  407. * VQA_DefaultConfig - Initialize VQAConfig structure with defaults.
  408. *
  409. * SYNOPSIS
  410. * VQA_DefaultConfig(Config);
  411. *
  412. * void VQA_DefaultConfig(VQAConfig *);
  413. *
  414. * FUNCTION
  415. * Initialize configuration with default settings.
  416. *
  417. * INPUTS
  418. * Config - Pointer to VQA configuration structure.
  419. *
  420. * RESULT
  421. * NONE
  422. *
  423. ****************************************************************************/
  424. void VQA_DefaultConfig(VQAConfig *config)
  425. {
  426. memcpy(config, &_defaultconfig, sizeof(VQAConfig));
  427. }