CONFIG.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. /* VocFile: Filename of audio track override. A value of 0 tells the
  104. * player not to override the movies audio track.
  105. */
  106. NULL,
  107. /* AudioBuf: Audio buffer to use. A value of 0 tells the player that
  108. * it has to allocate a buffer itself.
  109. */
  110. NULL,
  111. /* AudioBufSize: Size of audio buffer to use/allocate. A value of -1
  112. * tells the player to compute the buffer size from the audio
  113. * information in the movie.
  114. */
  115. -1,
  116. /* AudioRate: Audio playback rate in samples per second. A value of -1
  117. * tells the player to use the audio rate of the movie.
  118. */
  119. -1,
  120. /* Volume: Volume level to playback audio track. */
  121. 0x00FF,
  122. /* HMIBufSize: Size of HMIs internal buffer. */
  123. 2048L,
  124. /* DigiHandle: Handle to an initialized HMI sound driver. A value of -1
  125. * tells the player it must initialize the HMI sound driver itself.
  126. */
  127. -1,
  128. /* DigiCard: HMI ID of audio card to use. A value of 0 tells the player
  129. * not to use any card. A value of -1 tells the player to autodetect the
  130. * card in the system.
  131. */
  132. -1,
  133. /* DigiPort: Port address of the sound card. A value of -1 tells the player
  134. * to autodetect this address.
  135. */
  136. -1,
  137. /* DigiIRQ: Interrupt number of sound card. A value of -1 tells the player
  138. * to autodetect the interrupt used by the card.
  139. */
  140. -1,
  141. /* DigiDMA: DMA channel of the sound card. A value of -1 tells the player
  142. * to autodetect the channel used by the card.
  143. */
  144. -1,
  145. /* Language: Prefered language. */
  146. 0,
  147. /* CaptionFont: Caption text font. */
  148. NULL,
  149. /* EVAFont: EVA text font. */
  150. NULL,
  151. };
  152. /* Supported video modes. */
  153. #if(VQAVIDEO_ON)
  154. enum VMTAGS {
  155. VMTAG_NONE = 0,
  156. #if(VQAMCGA_ON)
  157. VMTAG_MCGA,
  158. VMTAG_MCGA_BUF,
  159. #endif
  160. #if(VQAXMODE_ON)
  161. VMTAG_XMODE320X200,
  162. VMTAG_XMODE320X200_BUF,
  163. VMTAG_XMODE320X200_VRAM,
  164. VMTAG_XMODE320X240,
  165. VMTAG_XMODE320X240_BUF,
  166. VMTAG_XMODE320X240_VRAM,
  167. #endif
  168. #if(VQAVESA_ON)
  169. VMTAG_VESA640X480_BUF,
  170. VMTAG_VESA640X480_X2,
  171. VMTAG_VESA320X200,
  172. VMTAG_VESA320X200_BUF,
  173. #endif
  174. };
  175. typedef struct _VideoModeTag {
  176. char const *token;
  177. long id;
  178. } VideoModeTag;
  179. VideoModeTag VideoModeTags[] = {
  180. {"NONE",VMTAG_NONE},
  181. #if(VQAMCGA_ON)
  182. {"MCGA", VMTAG_MCGA},
  183. {"MCGA_BUF",VMTAG_MCGA_BUF},
  184. #endif /* VQAMCGA_ON */
  185. #if(VQAXMODE_ON)
  186. {"XMODE_320X200", VMTAG_XMODE320X200},
  187. {"XMODE_320X200_BUF", VMTAG_XMODE320X200_BUF},
  188. {"XMODE_320X200_VRAM",VMTAG_XMODE320X200_VRAM},
  189. {"XMODE_320X240", VMTAG_XMODE320X240},
  190. {"XMODE_320X240_BUF", VMTAG_XMODE320X240_BUF},
  191. {"XMODE_320X240_VRAM",VMTAG_XMODE320X240_VRAM},
  192. #endif /* VQAXMODE_ON */
  193. #if(VQAVESA_ON)
  194. {"VESA_640X480_BUF",VMTAG_VESA640X480_BUF},
  195. {"VESA_640X480_X2", VMTAG_VESA640X480_X2},
  196. {"VESA_320X200", VMTAG_VESA320X200},
  197. {"VESA_320X200_BUF",VMTAG_VESA320X200_BUF},
  198. #endif /* VQAVESA_ON */
  199. {NULL, NULL}
  200. };
  201. #endif /* VQAVIDEO_ON */
  202. /****************************************************************************
  203. *
  204. * NAME
  205. * VQA_INIConfig - Initialize VQAConfig structure with INI settings.
  206. *
  207. * SYNOPSIS
  208. * VQA_INIConfig(Config)
  209. *
  210. * void VQA_INIConfig(VQAConfig *);
  211. *
  212. * FUNCTION
  213. * Initializes the configuration structure from the player INI file.
  214. *
  215. * INPUTS
  216. * Config - Pointer to VQAConfig structure.
  217. *
  218. * RESULT
  219. * NONE
  220. *
  221. ****************************************************************************/
  222. void VQA_INIConfig(VQAConfig *config)
  223. {
  224. char *ininame;
  225. char buf[80];
  226. long i;
  227. /* Set all Config entries to 0. */
  228. memset(config, 0, sizeof(VQAConfig));
  229. /* Retrieve player INI filename from an enviroment variable if
  230. * it is provided.
  231. */
  232. if ((ininame = getenv("VQACFG")) == NULL) {
  233. ininame = "PLAYER.INI";
  234. }
  235. /*-------------------------------------------------------------------------
  236. * VIDEO MODE AND DRAW FLAGS
  237. *-----------------------------------------------------------------------*/
  238. #if(VQAVIDEO_ON)
  239. /* Get video mode from INI */
  240. GetINIString("Player", "PlayerMode", "MCGA", buf, 80, ininame);
  241. /* Search supported modes for a match. */
  242. i = 0;
  243. while (VideoModeTags[i].token != NULL) {
  244. if (stricmp(buf, VideoModeTags[i].token) == 0) {
  245. break;
  246. }
  247. i++;
  248. }
  249. /* Setup for requested mode */
  250. switch (VideoModeTags[i].id) {
  251. /* MCGA direct */
  252. #if(VQAMONO_ON)
  253. case VMTAG_MCGA:
  254. config->Vmode = MCGA;
  255. break;
  256. /* MCGA buffered */
  257. case VMTAG_MCGA_BUF:
  258. config->Vmode = MCGA;
  259. config->DrawFlags |= VQACFGF_BUFFER;
  260. break;
  261. #endif /* VQAMCGA_ON */
  262. /* XMODE direct (320x200) */
  263. #if(VQAXMODE_ON)
  264. case VMTAG_XMODE320X200:
  265. config->Vmode = XMODE_320X200;
  266. break;
  267. /* XMODE buffered (320x200) */
  268. case VMTAG_XMODE320X200_BUF:
  269. config->Vmode = XMODE_320X200;
  270. config->DrawFlags |= VQACFGF_BUFFER;
  271. break;
  272. /* XMODE VRAM codebook (320x200) */
  273. case VMTAG_XMODE320X200_VRAM:
  274. config->Vmode = XMODE_320X200;
  275. config->DrawFlags |= VQACFGF_VRAMCB;
  276. break;
  277. /* XMODE direct (320x240) */
  278. case VMTAG_XMODE320X240:
  279. config->Vmode = XMODE_320X240;
  280. break;
  281. /* XMODE buffered (320x240) */
  282. case VMTAG_XMODE320X240_BUF:
  283. config->Vmode = XMODE_320X240;
  284. config->DrawFlags |= VQACFGF_BUFFER;
  285. break;
  286. /* XMODE VRAM codebook (320x240) */
  287. case VMTAG_XMODE320X240_VRAM:
  288. config->Vmode = XMODE_320X240;
  289. config->DrawFlags |= VQACFGF_VRAMCB;
  290. break;
  291. #endif /* VQAXMODE_ON */
  292. /* VESA buffered (640x480_256) */
  293. #if(VQAVESA_ON)
  294. case VMTAG_VESA640X480_BUF:
  295. config->Vmode = VESA_640X480_256;
  296. config->DrawFlags |= VQACFGF_BUFFER;
  297. break;
  298. /* VESA buffered scaled (640x480_256) */
  299. case VMTAG_VESA640X480_X2:
  300. config->Vmode = VESA_640X480_256;
  301. config->DrawFlags |= (VQACFGF_BUFFER|VQACFGF_SCALEX2);
  302. break;
  303. /* VESA direct (320x200_32k) */
  304. case VMTAG_VESA320X200:
  305. config->Vmode = VESA_320X200_32K_1;
  306. break;
  307. /* VESA buffered (320x200_32k) */
  308. case VMTAG_VESA320X200_BUF:
  309. config->Vmode = VESA_320X200_32K_1;
  310. config->DrawFlags |= VQACFGF_BUFFER;
  311. break;
  312. #endif /* VQAVESA_ON */
  313. /* Default to MCGA direct */
  314. VMTAG_NONE:
  315. default:
  316. config->Vmode = MCGA;
  317. break;
  318. }
  319. #endif /* VQAVIDEO_ON */
  320. /* Get framerate and drawrate. */
  321. GetINIString("Player", "FrameRate", "-1", buf, 80, ininame);
  322. config->FrameRate = atoi(buf);
  323. GetINIString("Player", "DrawRate", "Variable", buf, 80, ininame);
  324. if (!stricmp(buf, "Variable")) {
  325. config->DrawRate = -1;
  326. } else {
  327. config->DrawRate = 0;
  328. }
  329. /*-------------------------------------------------------------------------
  330. * AUDIO SETTINGS
  331. *-----------------------------------------------------------------------*/
  332. GetINIString("Player", "AudioRate", "-1", buf, 80, ininame);
  333. config->AudioRate = atoi(buf);
  334. /* OptionFlags */
  335. GetINIString("Player", "SoundEnabled", "True", buf, 80, ininame);
  336. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  337. config->OptionFlags |= VQAOPTF_AUDIO;
  338. } else {
  339. config->OptionFlags &= (~VQAOPTF_AUDIO);
  340. }
  341. /* Default audio settings. */
  342. config->AudioBufSize = 32768U;
  343. config->HMIBufSize = 2048;
  344. config->DigiHandle = -1;
  345. config->Volume = 0x00FF;
  346. config->DigiCard = 0xFFFF;
  347. config->DigiPort = -1;
  348. config->DigiIRQ = -1;
  349. config->DigiDMA = -1;
  350. /* Configure sound hardware */
  351. GetINIString("Player", "Port", "-1", buf, 80, ininame);
  352. if (!stricmp(buf, "-1")) {
  353. config->DigiPort = -1;
  354. } else {
  355. sscanf(buf, "%x", &config->DigiPort);
  356. }
  357. GetINIString("Player", "IRQ", "-1", buf, 80, ininame);
  358. config->DigiIRQ = atoi(buf);
  359. GetINIString("Player", "DMA", "-1", buf, 80, ininame);
  360. config->DigiDMA = atoi(buf);
  361. /*-------------------------------------------------------------------------
  362. * GENERAL OPTIONS
  363. *-----------------------------------------------------------------------*/
  364. /* Enable/Disable single stepping */
  365. GetINIString("Player", "SingleStep", "False", buf, 80, ininame);
  366. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  367. config->OptionFlags |= VQAOPTF_STEP;
  368. config->DrawFlags |= VQACFGF_NOSKIP;
  369. } else {
  370. config->OptionFlags &= (~VQAOPTF_STEP);
  371. }
  372. /* Enable/Disable Slowpalette */
  373. GetINIString("Player", "SlowPalette", "False", buf, 80, ininame);
  374. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  375. config->OptionFlags |= VQAOPTF_SLOWPAL;
  376. } else {
  377. config->OptionFlags &= (~VQAOPTF_SLOWPAL);
  378. }
  379. /* Enable/Disable monochrome display */
  380. GetINIString("Player", "MonoOutput", "False", buf, 80, ininame);
  381. if (!stricmp(buf, "True") || !stricmp(buf, "1")) {
  382. config->OptionFlags |= VQAOPTF_MONO;
  383. } else {
  384. config->OptionFlags &= (~VQAOPTF_MONO);
  385. }
  386. /* Frame and codebook buffers */
  387. config->NumFrameBufs = 6;
  388. config->NumCBBufs = 3;
  389. }
  390. /****************************************************************************
  391. *
  392. * NAME
  393. * VQA_DefaultConfig - Initialize VQAConfig structure with defaults.
  394. *
  395. * SYNOPSIS
  396. * VQA_DefaultConfig(Config);
  397. *
  398. * void VQA_DefaultConfig(VQAConfig *);
  399. *
  400. * FUNCTION
  401. * Initialize configuration with default settings.
  402. *
  403. * INPUTS
  404. * Config - Pointer to VQA configuration structure.
  405. *
  406. * RESULT
  407. * NONE
  408. *
  409. ****************************************************************************/
  410. void VQA_DefaultConfig(VQAConfig *config)
  411. {
  412. memcpy(config, &_defaultconfig, sizeof(VQAConfig));
  413. }