INFERNO.C 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /* $Source: f:/miner/source/main/rcs/inferno.c $
  14. * $Revision: 2.36 $
  15. * $Author: john $
  16. * $Date: 1996/01/05 16:52:16 $
  17. *
  18. * main() for Inferno
  19. *
  20. * $Log: inferno.c $
  21. * Revision 2.36 1996/01/05 16:52:16 john
  22. * Improved 3d stuff.
  23. *
  24. * Revision 2.35 1995/10/07 13:20:06 john
  25. * Added new modes for LCDBIOS, also added support for -JoyNice,
  26. * and added Shift+F1-F4 to controls various stereoscopic params.
  27. *
  28. * Revision 2.34 1995/06/26 11:30:57 john
  29. * Made registration/copyright screen go away after 5 minutes.
  30. *
  31. * Revision 2.33 1995/05/31 14:26:55 unknown
  32. * Fixed ugly spacing.
  33. *
  34. * Revision 2.32 1995/05/26 16:15:28 john
  35. * Split SATURN into define's for requiring cd, using cd, etc.
  36. * Also started adding all the Rockwell stuff.
  37. *
  38. * Revision 2.31 1995/05/11 13:30:01 john
  39. * Changed 3dbios detection to work like Didde Kim wanted it to.
  40. *
  41. * Revision 2.30 1995/05/08 13:53:50 john
  42. * Added code to read vipport environemnt variable.
  43. *
  44. * Revision 2.29 1995/05/08 11:26:18 john
  45. * Reversed eyes in 3dmax mode.
  46. *
  47. * Revision 2.28 1995/05/08 11:24:06 john
  48. * Made 3dmax work like Kasan wants it to.
  49. *
  50. * Revision 2.27 1995/04/23 16:06:25 john
  51. * Moved rinvul into modem/null modem menu.
  52. *
  53. * Revision 2.26 1995/04/12 13:39:26 john
  54. * Fixed bug with -lowmem not working.
  55. *
  56. * Revision 2.25 1995/04/09 14:43:00 john
  57. * Made Dynamic sockets not print Msockets for help.
  58. *
  59. * Revision 2.24 1995/04/07 16:11:33 john
  60. * Fixed problem with VFX display when using setup.
  61. *
  62. * Revision 2.23 1995/04/06 15:40:51 john
  63. * Synced VFX with setup #'s.
  64. *
  65. * Revision 2.22 1995/04/06 12:12:53 john
  66. * Fixed some bugs with 3dmax.
  67. *
  68. * Revision 2.21 1995/03/30 16:36:51 mike
  69. * text localization.
  70. *
  71. * Revision 2.20 1995/03/29 15:33:52 john
  72. * Added code to parse descent.net file.
  73. *
  74. * Revision 2.19 1995/03/28 20:08:21 john
  75. * Took away alternate server thing.
  76. *
  77. * Revision 2.18 1995/03/27 09:43:08 john
  78. * Added VR Settings in config file.
  79. *
  80. * Revision 2.17 1995/03/23 19:02:21 john
  81. * Added descent.net file use.
  82. *
  83. * Revision 2.16 1995/03/23 12:25:11 john
  84. * Moved IPX stuff into BIOS lib.
  85. *
  86. * Revision 2.15 1995/03/21 16:52:34 john
  87. * Added 320x100.
  88. *
  89. * Revision 2.14 1995/03/21 14:40:33 john
  90. * Ifdef'd out the NETWORK code.
  91. *
  92. * Revision 2.13 1995/03/16 23:13:35 john
  93. * Fixed bug with piggy paging in bitmap not checking for disk
  94. * error, hence bogifying textures if you pull the CD out.
  95. *
  96. * Revision 2.12 1995/03/16 21:45:22 john
  97. * Made all paged modes have incompatible menus!
  98. *
  99. * Revision 2.11 1995/03/15 15:19:34 john
  100. * Took out code that changes to exe dir.
  101. *
  102. * Revision 2.10 1995/03/15 14:33:37 john
  103. * Added code to force the Descent CD-rom in the drive.
  104. *
  105. * Revision 2.9 1995/03/15 11:41:27 john
  106. * Better Saturn CD-ROM support.
  107. *
  108. * Revision 2.8 1995/03/14 18:24:46 john
  109. * Force Destination Saturn to use CD-ROM drive.
  110. *
  111. * Revision 2.7 1995/03/14 16:22:35 john
  112. * Added cdrom alternate directory stuff.
  113. *
  114. * Revision 2.6 1995/03/13 15:17:19 john
  115. * Added alternate hogfile directory.
  116. *
  117. * Revision 2.5 1995/03/10 13:05:35 john
  118. * Added code so that palette is correct for VFX1 helmets.
  119. *
  120. * Revision 2.4 1995/03/07 15:12:43 john
  121. * Fixed VFX,3dmax support.
  122. *
  123. * Revision 2.3 1995/03/07 14:19:35 mike
  124. * More destination saturn stuff.
  125. *
  126. * Revision 2.2 1995/03/06 16:47:34 mike
  127. * destination saturn
  128. *
  129. * Revision 2.1 1995/03/06 15:24:06 john
  130. * New screen techniques.
  131. *
  132. * Revision 2.0 1995/02/27 11:31:29 john
  133. * New version 2.0, which has no anonymous unions, builds with
  134. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  135. *
  136. * Revision 1.295 1995/02/23 12:02:14 john
  137. * Made mono windows smaller.
  138. *
  139. * Revision 1.294 1995/02/16 17:35:00 john
  140. * Added code to allow dynamic socket changing.
  141. *
  142. * Revision 1.293 1995/02/14 19:29:29 john
  143. * Locked down critical error handler.
  144. *
  145. * Revision 1.292 1995/02/14 15:29:20 john
  146. * Added CR-LF to last line of menu help text.
  147. *
  148. * Revision 1.291 1995/02/14 11:39:01 john
  149. * Added polled/bios joystick readers.
  150. *
  151. * Revision 1.290 1995/02/13 20:35:03 john
  152. * Lintized
  153. *
  154. * Revision 1.289 1995/02/11 16:20:02 john
  155. * Added code to make the default mission be the one last played.
  156. *
  157. * Revision 1.288 1995/02/11 15:54:13 rob
  158. * changed cinvul to rinvul.
  159. *
  160. * Revision 1.287 1995/02/11 14:48:43 rob
  161. * Added max of 314 seconds to control invul. times
  162. *
  163. * Revision 1.286 1995/02/11 12:42:01 john
  164. * Added new song method, with FM bank switching..
  165. *
  166. * Revision 1.285 1995/02/11 11:36:11 rob
  167. * Added cinvul option.
  168. *
  169. * Revision 1.284 1995/02/10 16:07:45 matt
  170. * Took 'registered' out of printed info at startup
  171. *
  172. * Revision 1.283 1995/02/09 22:00:59 john
  173. * Added i-glasses tracking.
  174. *
  175. * Revision 1.282 1995/02/02 11:11:27 john
  176. * Added -nocyberman switch.
  177. *
  178. * Revision 1.281 1995/02/01 16:35:14 john
  179. * Linted.
  180. *
  181. * Revision 1.280 1995/01/31 02:04:25 matt
  182. * Fixed up cmdline help
  183. *
  184. * Revision 1.279 1995/01/30 16:25:55 john
  185. * Put back in graphical screen at program end.
  186. *
  187. * Revision 1.278 1995/01/28 17:05:50 matt
  188. * Changed imbedded copyright to use comma instead of hyphen
  189. *
  190. * Revision 1.277 1995/01/28 15:57:26 john
  191. * Made joystick calibration be only when wrong detected in
  192. * menu or joystick axis changed.
  193. *
  194. * Revision 1.276 1995/01/25 14:37:49 john
  195. * Made joystick only prompt for calibration once...
  196. *
  197. * Revision 1.275 1995/01/24 18:21:00 john
  198. * Added Adam's text warning.
  199. *
  200. * Revision 1.274 1995/01/22 15:57:20 john
  201. * Took out code that printed warning out as game exited.
  202. *
  203. * Revision 1.273 1995/01/22 13:31:35 matt
  204. * Added load of mission 0, so there's always a default mission
  205. *
  206. * Revision 1.272 1995/01/19 17:00:41 john
  207. * Made save game work between levels.
  208. *
  209. * Revision 1.271 1995/01/18 11:47:57 adam
  210. * changed copyright notice
  211. *
  212. * Revision 1.270 1995/01/15 13:42:42 john
  213. * Moved low_mem cutoff higher.
  214. *
  215. * Revision 1.269 1995/01/12 18:53:50 john
  216. * Put ifdef EDITOR around the code that checked for
  217. * a 800x600 mode, because this trashed some people's
  218. * computers (maybe) causing the mem allocation error in
  219. * mouse.c that many users reported.
  220. *
  221. * Revision 1.268 1995/01/12 11:41:42 john
  222. * Added external control reading.
  223. *
  224. * Revision 1.267 1995/01/06 10:26:55 john
  225. * Added -nodoscheck command line switch.
  226. *
  227. * Revision 1.266 1995/01/05 16:59:30 yuan
  228. * Don't show orderform in editor version.
  229. *
  230. * Revision 1.265 1994/12/28 15:33:51 john
  231. * Added -slowjoy option.
  232. *
  233. * Revision 1.264 1994/12/15 16:44:15 matt
  234. * Added trademark notice
  235. *
  236. * Revision 1.263 1994/12/14 20:13:59 john
  237. * Reduced physical mem requments to 2 MB.
  238. *
  239. * Revision 1.262 1994/12/14 19:06:17 john
  240. * Lowered physical memory requments to 2 MB.
  241. *
  242. * Revision 1.261 1994/12/14 09:41:29 allender
  243. * change to drive and directory (if needed) of command line invocation
  244. * so descent can be started from anywhere
  245. *
  246. * Revision 1.260 1994/12/13 19:08:59 john
  247. * Updated memory requirements.
  248. *
  249. * Revision 1.259 1994/12/13 17:30:33 john
  250. * Made the timer rate be changed right after initializing it.
  251. *
  252. * Revision 1.258 1994/12/13 02:46:25 matt
  253. * Added imbedded copyright
  254. *
  255. * Revision 1.257 1994/12/13 02:06:46 john
  256. * Added code to check stack used by descent... initial
  257. * check showed stack used 35k/50k, so we decided it wasn't
  258. * worth pursuing any more.
  259. *
  260. * Revision 1.256 1994/12/11 23:17:54 john
  261. * Added -nomusic.
  262. * Added RealFrameTime.
  263. * Put in a pause when sound initialization error.
  264. * Made controlcen countdown and framerate use RealFrameTime.
  265. *
  266. * Revision 1.255 1994/12/10 00:56:51 matt
  267. * Added -nomusic to command-line help
  268. *
  269. * Revision 1.254 1994/12/08 11:55:11 john
  270. * Took out low memory print.
  271. *
  272. * Revision 1.253 1994/12/08 11:51:00 john
  273. * Made strcpy only copy corect number of chars,.
  274. *
  275. * Revision 1.252 1994/12/08 00:38:29 matt
  276. * Cleaned up banner messages
  277. *
  278. * Revision 1.251 1994/12/07 19:14:52 matt
  279. * Cleaned up command-line options and command-line help message
  280. *
  281. * Revision 1.250 1994/12/06 19:33:28 john
  282. * Fixed text of message to make more sense.
  283. *
  284. * Revision 1.249 1994/12/06 16:30:55 john
  285. * Neatend mem message,..
  286. *
  287. * Revision 1.248 1994/12/06 16:17:35 john
  288. * Added better mem checking/printing.
  289. *
  290. * Revision 1.247 1994/12/06 14:14:37 john
  291. * Added code to set low mem based on memory.
  292. *
  293. * Revision 1.246 1994/12/05 12:29:09 allender
  294. * removed ifdefs around -norun option
  295. *
  296. * Revision 1.245 1994/12/05 00:03:30 matt
  297. * Added -norun option to exit after writing pig
  298. *
  299. * Revision 1.244 1994/12/04 14:47:01 john
  300. * MAde the intro and menu be the same song.
  301. *
  302. * Revision 1.243 1994/12/04 14:36:42 john
  303. * Added menu music.
  304. *
  305. * Revision 1.242 1994/12/02 13:50:17 yuan
  306. * Localization.
  307. *
  308. * Revision 1.241 1994/12/01 17:28:30 adam
  309. * added end-shareware stuff
  310. *
  311. * Revision 1.240 1994/11/30 12:10:57 adam
  312. * added support for PCX titles/brief screens
  313. *
  314. * Revision 1.239 1994/11/29 15:47:33 matt
  315. * Moved error_init to start of game, so error message prints last
  316. *
  317. * Revision 1.238 1994/11/29 14:19:22 jasen
  318. * reduced dos mem requirments.
  319. *
  320. * Revision 1.237 1994/11/29 03:46:35 john
  321. * Added joystick sensitivity; Added sound channels to detail menu. Removed -maxchannels
  322. * command line arg.
  323. *
  324. * Revision 1.236 1994/11/29 02:50:18 john
  325. * Increased the amount a joystick has to be off before
  326. * asking if they want to recalibrate their joystick.
  327. *
  328. * Revision 1.235 1994/11/29 02:01:29 john
  329. * Corrected some of the Descent command line help items.
  330. *
  331. * Revision 1.234 1994/11/29 01:39:56 john
  332. * Fixed minor bug with vfx_light help not wrapping correctly.
  333. *
  334. * Revision 1.233 1994/11/28 21:34:17 john
  335. * Reduced dos mem rqment to 70k.
  336. *
  337. * Revision 1.232 1994/11/28 21:20:38 john
  338. * First version with memory checking.
  339. *
  340. * Revision 1.231 1994/11/28 20:06:21 rob
  341. * Removed old serial param command line options.
  342. * Added -noserial and -nonetwork to help listing.
  343. *
  344. * Revision 1.230 1994/11/27 23:15:24 matt
  345. * Made changes for new mprintf calling convention
  346. *
  347. * Revision 1.229 1994/11/27 20:50:51 matt
  348. * Don't set mem stuff if no debug
  349. *
  350. * Revision 1.228 1994/11/27 18:46:21 matt
  351. * Cleaned up command-line switches a little
  352. *
  353. * Revision 1.227 1994/11/21 17:48:00 matt
  354. * Added text to specifiy whether shareware or registered version
  355. *
  356. * Revision 1.226 1994/11/21 14:44:20 john
  357. * Fixed some bugs with setting volumes even when -nosound was used. Duh!
  358. *
  359. * Revision 1.225 1994/11/21 13:53:42 matt
  360. * Took out dos extender copyright
  361. *
  362. * Revision 1.224 1994/11/21 09:46:54 john
  363. * Added -showmeminfo parameter.
  364. *
  365. * Revision 1.223 1994/11/20 22:12:05 mike
  366. * Make some stuff dependent on SHAREWARE.
  367. *
  368. * Revision 1.222 1994/11/20 21:14:09 john
  369. * Changed -serial to -noserial. MAde a 1 sec delay
  370. * before leaving title screen. Clear keyboard buffer
  371. * before asking for player name.
  372. *
  373. * Revision 1.221 1994/11/19 15:20:20 mike
  374. * rip out unused code and data
  375. *
  376. * Revision 1.220 1994/11/17 19:14:29 adam
  377. * prevented order screen from coming up when -notitles is used
  378. *
  379. * Revision 1.219 1994/11/16 11:34:39 john
  380. * Added -nottitle switch.
  381. *
  382. * Revision 1.218 1994/11/16 10:05:53 john
  383. * Added verbose messages.
  384. *
  385. * Revision 1.217 1994/11/15 20:12:34 john
  386. * Added back in inferno and parallax screens.
  387. *
  388. * Revision 1.216 1994/11/15 18:35:30 john
  389. * Added verbose setting.
  390. *
  391. * Revision 1.215 1994/11/15 17:47:44 john
  392. * Added ordering info screen.
  393. *
  394. * Revision 1.214 1994/11/15 08:57:44 john
  395. * Added MS-DOS version checking and -nonetwork option.
  396. *
  397. * Revision 1.213 1994/11/15 08:34:32 john
  398. * Added better error messages for IPX init.
  399. *
  400. * Revision 1.212 1994/11/14 20:14:18 john
  401. * Fixed some warnings.
  402. *
  403. * Revision 1.211 1994/11/14 19:50:49 john
  404. * Added joystick cal values to descent.cfg.
  405. *
  406. * Revision 1.210 1994/11/14 17:56:44 allender
  407. * make call to ReadConfigFile at startup
  408. *
  409. * Revision 1.209 1994/11/14 11:41:55 john
  410. * Fixed bug with editor/game sequencing.
  411. *
  412. * Revision 1.208 1994/11/13 17:05:11 john
  413. * Made the callsign entry be a list box and gave the ability
  414. * to delete players.
  415. *
  416. * Revision 1.207 1994/11/13 15:39:22 john
  417. * Added critical error handler to game. Took out -editor command line
  418. * option because it didn't work anymore and wasn't worth fixing. Made scores
  419. * not use MINER enviroment variable on release version, and made scores
  420. * not print an error if there is no descent.hi.
  421. *
  422. * Revision 1.206 1994/11/10 20:53:29 john
  423. * Used new sound install parameters.
  424. *
  425. * Revision 1.205 1994/11/10 11:07:52 mike
  426. * Set default detail level.
  427. *
  428. * Revision 1.204 1994/11/09 13:45:43 matt
  429. * Made -? work again for help
  430. *
  431. * Revision 1.203 1994/11/09 10:55:58 matt
  432. * Cleaned up initialization for editor -> game transitions
  433. *
  434. * Revision 1.202 1994/11/07 21:35:47 matt
  435. * Use new function iff_read_into_bitmap()
  436. *
  437. * Revision 1.201 1994/11/05 17:22:16 john
  438. * Fixed lots of sequencing problems with newdemo stuff.
  439. *
  440. * Revision 1.200 1994/11/05 14:05:44 john
  441. * Fixed fade transitions between all screens by making gr_palette_fade_in and out keep
  442. * track of whether the palette is faded in or not. Then, wherever the code needs to fade out,
  443. * it just calls gr_palette_fade_out and it will fade out if it isn't already. The same with fade_in.
  444. * This eliminates the need for all the flags like Menu_fade_out, game_fade_in palette, etc.
  445. *
  446. * Revision 1.199 1994/11/04 14:36:30 allender
  447. * change Auto_demo meaning to mean autostart from menu only. Use
  448. * FindArgs when searching for AutoDemo from command line. also,
  449. * set N_Players to 1 when starting in editor mode.
  450. *
  451. * Revision 1.198 1994/11/02 11:59:49 john
  452. * Moved menu out of game into inferno main loop.
  453. *
  454. * Revision 1.197 1994/11/01 17:57:39 mike
  455. * -noscreens option to bypass all screens.
  456. *
  457. * Revision 1.196 1994/10/28 15:42:34 allender
  458. * don't register player if Autodemo is on
  459. *
  460. * Revision 1.195 1994/10/28 10:58:01 matt
  461. * Added copyright notice for DOS4GW
  462. *
  463. * Revision 1.194 1994/10/20 21:26:48 matt
  464. * Took out old serial name/number code, and put up message if this
  465. * is a marked version.
  466. *
  467. * Revision 1.193 1994/10/19 09:52:14 allender
  468. * Print out who descent.exe belongs to if descent.exe is stamped.
  469. *
  470. * Revision 1.192 1994/10/18 16:43:05 allender
  471. * Added check for identifier stamp and time after which descent will
  472. * no longer run.
  473. *
  474. * Revision 1.191 1994/10/17 13:07:17 john
  475. * Moved the descent.cfg info into the player config file.
  476. *
  477. * Revision 1.190 1994/10/04 10:26:31 matt
  478. * Support new menu fade in
  479. *
  480. * Revision 1.189 1994/10/03 22:58:46 matt
  481. * Changed some values of game_mode
  482. *
  483. * Revision 1.188 1994/10/03 18:55:39 rob
  484. * Changed defaults for com port settings.
  485. *
  486. * Revision 1.187 1994/10/03 13:34:47 matt
  487. * Added new (and hopefully better) game sequencing functions
  488. *
  489. * Revision 1.186 1994/09/30 12:37:28 john
  490. * Added midi,digi volume to configuration.
  491. *
  492. * Revision 1.185 1994/09/30 10:08:48 john
  493. * Changed sound stuff... made it so the reseting card doesn't hang,
  494. * made volume change only if sound is installed.
  495. *
  496. * Revision 1.184 1994/09/28 17:25:00 matt
  497. * Added first draft of game save/load system
  498. *
  499. * Revision 1.183 1994/09/28 16:18:23 john
  500. * Added capability to play midi song.
  501. *
  502. * Revision 1.182 1994/09/28 11:31:18 john
  503. * Made text output unbuffered.
  504. *
  505. * Revision 1.181 1994/09/27 19:23:44 john
  506. * Added -nojoystick and -nomouse
  507. *
  508. * Revision 1.180 1994/09/24 16:55:29 rob
  509. * No longer open COM port immediately upon program start.
  510. * No longer set Network_active is serial_active is set.
  511. *
  512. * Revision 1.179 1994/09/24 14:16:30 mike
  513. * Support new game mode constants.
  514. *
  515. * Revision 1.178 1994/09/22 17:52:31 rob
  516. * Added Findargs hooks for -serial, -speed, and -com.
  517. *
  518. * Revision 1.177 1994/09/22 16:14:11 john
  519. * Redid intro sequecing.
  520. *
  521. * Revision 1.176 1994/09/21 16:32:58 john
  522. * Made mouse and keyboard init after bm_init. Why?
  523. * Because it seems to work better under virtual
  524. * memory.
  525. *
  526. * Revision 1.175 1994/09/21 16:27:52 john
  527. * Added mouse_init
  528. *
  529. * Revision 1.174 1994/09/20 15:14:10 matt
  530. * New message for new VFX switches
  531. *
  532. * Revision 1.173 1994/09/16 16:14:27 john
  533. * Added acrade sequencing.
  534. *
  535. * Revision 1.172 1994/09/16 11:49:52 john
  536. * Added first version of arcade joystick support;
  537. * Also fixed some bugs in kconfig.c, such as reading non-present
  538. * joysticks, which killed frame rate, and not reading key_down_time
  539. * when in slide mode or bank mode.
  540. *
  541. * Revision 1.171 1994/09/15 16:11:35 john
  542. * Added support for VFX1 head tracking. Fixed bug with memory over-
  543. * write when using stereo mode.
  544. *
  545. * Revision 1.170 1994/09/12 19:38:23 john
  546. * Made some stuff that prints to the DOS screen go to the
  547. * mono instead, since it really is debugging info.
  548. *
  549. * Revision 1.169 1994/08/29 21:18:28 john
  550. * First version of new keyboard/oystick remapping stuff.
  551. *
  552. * Revision 1.168 1994/08/26 13:02:00 john
  553. * Put high score system in.
  554. *
  555. * Revision 1.167 1994/08/24 19:00:23 john
  556. * Changed key_down_time to return fixed seconds instead of
  557. * milliseconds.
  558. *
  559. * Revision 1.166 1994/08/18 16:24:20 john
  560. * changed socket to channel in text.
  561. *
  562. * Revision 1.165 1994/08/18 16:16:51 john
  563. * Added support for different sockets.
  564. *
  565. * Revision 1.164 1994/08/18 10:47:53 john
  566. * *** empty log message ***
  567. *
  568. * Revision 1.163 1994/08/12 09:15:54 john
  569. * *** empty log message ***
  570. *
  571. * Revision 1.162 1994/08/12 03:11:19 john
  572. * Made network be default off; Moved network options into
  573. * main menu. Made starting net game check that mines are the
  574. * same.
  575. *
  576. * Revision 1.161 1994/08/10 19:57:05 john
  577. * Changed font stuff; Took out old menu; messed up lots of
  578. * other stuff like game sequencing messages, etc.
  579. *
  580. * Revision 1.160 1994/08/05 16:30:23 john
  581. * Added capability to turn off network.
  582. *
  583. * Revision 1.159 1994/08/04 19:42:51 matt
  584. * Moved serial number & name (and version name) from inferno.c to inferno.ini
  585. *
  586. * Revision 1.158 1994/08/03 10:30:23 matt
  587. * Change cybermaxx switches, updated command-line help, and added serial number system
  588. *
  589. * Revision 1.157 1994/07/29 18:30:10 matt
  590. * New parms (lack of parms, actually) for g3_init()
  591. *
  592. * Revision 1.156 1994/07/24 00:39:25 matt
  593. * Added more text to TEX file; make NewGame() take a start level; made game
  594. * load/save menus use open/close window funcs.
  595. *
  596. * Revision 1.155 1994/07/21 21:31:27 john
  597. * First cheapo version of VictorMaxx tracking.
  598. *
  599. * Revision 1.154 1994/07/21 18:15:34 matt
  600. * Ripped out a bunch of unused stuff
  601. *
  602. * Revision 1.153 1994/07/21 17:59:10 matt
  603. * Cleaned up initial mode game/editor code
  604. *
  605. * Revision 1.152 1994/07/21 13:11:19 matt
  606. * Ripped out remants of old demo system, and added demo only system that
  607. * disables object movement and game options from menu.
  608. *
  609. * Revision 1.151 1994/07/20 15:58:27 john
  610. * First installment of ipx stuff.
  611. *
  612. * Revision 1.150 1994/07/15 16:04:24 matt
  613. * Changed comment for milestone 3 version
  614. *
  615. * Revision 1.149 1994/07/15 13:59:24 matt
  616. * Fixed stupid mistake I make in the last revision
  617. *
  618. * Revision 1.148 1994/07/15 13:20:15 matt
  619. * Updated comand-line help
  620. *
  621. * Revision 1.147 1994/07/14 23:29:43 matt
  622. * Open two mono debug messages, one for errors & one for spew
  623. *
  624. * Revision 1.146 1994/07/09 22:48:05 matt
  625. * Added localizable text
  626. *
  627. * Revision 1.145 1994/07/02 13:49:47 matt
  628. * Cleaned up includes
  629. *
  630. * Revision 1.144 1994/06/30 20:04:43 john
  631. * Added -joydef support.
  632. *
  633. * Revision 1.143 1994/06/24 17:01:44 john
  634. * Add VFX support; Took Game Sequencing, like EndGame and stuff and
  635. * took it out of game.c and into gameseq.c
  636. *
  637. */
  638. #pragma off (unreferenced)
  639. static char rcsid[] = "$Id: inferno.c 2.36 1996/01/05 16:52:16 john Exp $";
  640. static char copyright[] = "DESCENT COPYRIGHT (C) 1994,1995 PARALLAX SOFTWARE CORPORATION";
  641. #pragma on (unreferenced)
  642. #include <io.h>
  643. #include <dos.h>
  644. #include <stdio.h>
  645. #include <malloc.h>
  646. #include <stdlib.h>
  647. #include <string.h>
  648. #include <conio.h>
  649. #include <time.h>
  650. #include <dos.h>
  651. #include <direct.h>
  652. #include "gr.h"
  653. #include "ui.h"
  654. #include "mono.h"
  655. #include "key.h"
  656. #include "timer.h"
  657. #include "3d.h"
  658. #include "bm.h"
  659. #include "inferno.h"
  660. #include "error.h"
  661. #include "cflib.h"
  662. #include "div0.h"
  663. #include "game.h"
  664. #include "segment.h" //for Side_to_verts
  665. #include "mem.h"
  666. #include "textures.h"
  667. #include "segpoint.h"
  668. #include "screens.h"
  669. #include "texmap.h"
  670. #include "texmerge.h"
  671. #include "menu.h"
  672. #include "wall.h"
  673. #include "switch.h"
  674. #include "polyobj.h"
  675. #include "effects.h"
  676. #include "digi.h"
  677. #include "iff.h"
  678. #include "pcx.h"
  679. #include "palette.h"
  680. #include "args.h"
  681. #include "sounds.h"
  682. #include "titles.h"
  683. #include "player.h"
  684. #include "text.h"
  685. #include "ipx.h"
  686. #include "newdemo.h"
  687. #include "victor.h"
  688. #include "network.h"
  689. #include "modem.h"
  690. #include "gamefont.h"
  691. #include "kconfig.h"
  692. #include "arcade.h"
  693. #include "coindev.h"
  694. #include "mouse.h"
  695. #include "joy.h"
  696. #include "dpmi.h"
  697. #include "newmenu.h"
  698. #include "desc_id.h"
  699. #include "config.h"
  700. #include "joydefs.h"
  701. #include "multi.h"
  702. #include "iglasses.h"
  703. #include "songs.h"
  704. #include "cfile.h"
  705. #include "cdrom.h"
  706. #include "gameseq.h"
  707. #ifdef EDITOR
  708. #include "editor\editor.h"
  709. #include "editor\kdefs.h"
  710. #endif
  711. #include "vers_id.h"
  712. extern int Game_simuleyes_flag;
  713. static const char desc_id_checksum_str[] = DESC_ID_CHKSUM;
  714. char desc_id_exit_num = 0;
  715. int Function_mode=FMODE_MENU; //game or editor?
  716. int Screen_mode=-1; //game screen or editor screen?
  717. //--unused-- grs_bitmap Inferno_bitmap_title;
  718. int WVIDEO_running=0; //debugger can set to 1 if running
  719. #ifdef EDITOR
  720. int Inferno_is_800x600_available = 0;
  721. #endif
  722. //--unused-- int Cyberman_installed=0; // SWIFT device present
  723. void install_int3_handler(void);
  724. int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned far * devhdr );
  725. #ifndef NDEBUG
  726. do_heap_check()
  727. {
  728. int heap_status;
  729. heap_status = _heapset( 0xFF );
  730. switch( heap_status )
  731. {
  732. case _HEAPBADBEGIN:
  733. mprintf((1, "ERROR - heap is damaged\n"));
  734. Int3();
  735. break;
  736. case _HEAPBADNODE:
  737. mprintf((1, "ERROR - bad node in heap\n" ));
  738. Int3();
  739. break;
  740. }
  741. }
  742. #endif
  743. int registered_copy=0;
  744. char name_copy[sizeof(DESC_ID_STR)];
  745. void
  746. check_id_checksum_and_date()
  747. {
  748. const char name[] = DESC_ID_STR;
  749. char time_str[] = DESC_DEAD_TIME;
  750. int i, found;
  751. unsigned long *checksum, test_checksum;
  752. time_t current_time, saved_time;
  753. saved_time = (time_t)strtol(&(time_str[strlen(time_str) - 10]), NULL, 16);
  754. if (saved_time == (time_t)0)
  755. return;
  756. strcpy(name_copy,name);
  757. registered_copy = 1;
  758. current_time = time(NULL);
  759. if (current_time >= saved_time)
  760. desc_id_exit_num = 1;
  761. test_checksum = 0;
  762. for (i = 0; i < strlen(name); i++) {
  763. found = 0;
  764. test_checksum += name[i];
  765. if (((test_checksum / 2) * 2) != test_checksum)
  766. found = 1;
  767. test_checksum = test_checksum >> 1;
  768. if (found)
  769. test_checksum |= 0x80000000;
  770. }
  771. checksum = (unsigned long *)&(desc_id_checksum_str[0]);
  772. if (test_checksum != *checksum)
  773. desc_id_exit_num = 2;
  774. printf ("%s %s\n", TXT_REGISTRATION, name);
  775. }
  776. int is_3dbios_installed()
  777. {
  778. dpmi_real_regs rregs;
  779. memset(&rregs,0,sizeof(dpmi_real_regs));
  780. rregs.eax = 0x4ed0;
  781. //rregs.ebx = 0x3d10;
  782. dpmi_real_int386x( 0x10, &rregs );
  783. if ( (rregs.edx & 0xFFFF) != 0x3344 )
  784. return 0;
  785. else
  786. return 1;
  787. }
  788. int init_graphics()
  789. {
  790. int result;
  791. result=gr_check_mode(SM_320x200C);
  792. #ifdef EDITOR
  793. if ( result==0 )
  794. result=gr_check_mode(SM_800x600V);
  795. #endif
  796. switch( result ) {
  797. case 0: //Mode set OK
  798. #ifdef EDITOR
  799. Inferno_is_800x600_available = 1;
  800. #endif
  801. break;
  802. case 1: //No VGA adapter installed
  803. printf("%s\n", TXT_REQUIRES_VGA );
  804. return 1;
  805. case 10: //Error allocating selector for A0000h
  806. printf( "%s\n",TXT_ERROR_SELECTOR );
  807. return 1;
  808. case 11: //Not a valid mode support by gr.lib
  809. printf( "%s\n", TXT_ERROR_GRAPHICS );
  810. return 1;
  811. #ifdef EDITOR
  812. case 3: //Monitor doesn't support that VESA mode.
  813. case 4: //Video card doesn't support that VESA mode.
  814. printf( "Your VESA driver or video hardware doesn't support 800x600 256-color mode.\n" );
  815. break;
  816. case 5: //No VESA driver found.
  817. printf( "No VESA driver detected.\n" );
  818. break;
  819. case 2: //Program doesn't support this VESA granularity
  820. case 6: //Bad Status after VESA call/
  821. case 7: //Not enough DOS memory to call VESA functions.
  822. case 8: //Error using DPMI.
  823. case 9: //Error setting logical line width.
  824. default:
  825. printf( "Error %d using 800x600 256-color VESA mode.\n", result );
  826. break;
  827. #endif
  828. }
  829. return 0;
  830. }
  831. extern fix fixed_frametime;
  832. // Returns 1 if ok, 0 if failed...
  833. int init_gameport()
  834. {
  835. union REGS regs;
  836. memset(&regs,0,sizeof(regs));
  837. regs.x.eax = 0x8400;
  838. regs.x.edx = 0xF0;
  839. int386( 0x15, &regs, &regs );
  840. if ( ( regs.x.eax & 0xFFFF ) == 'SG' )
  841. return 1;
  842. else
  843. return 0;
  844. }
  845. void check_dos_version()
  846. {
  847. int major, minor;
  848. union REGS regs;
  849. memset(&regs,0,sizeof(regs));
  850. regs.x.eax = 0x3000; // Get MS-DOS Version Number
  851. int386( 0x21, &regs, &regs );
  852. major = regs.h.al;
  853. minor = regs.h.ah;
  854. if ( major < 5 ) {
  855. printf( "%s %d.d\n%s", TXT_DOS_VERSION_1, major, minor, TXT_DOS_VERSION_2);
  856. exit(1);
  857. }
  858. //printf( "\nUsing MS-DOS %d.%d...\n", major, minor );
  859. }
  860. void change_to_dir(char *cmd_line)
  861. {
  862. char drive[_MAX_DRIVE], dir[_MAX_DIR], curdir[_MAX_DIR];
  863. unsigned total, cur_drive;
  864. _splitpath(cmd_line, drive, dir, NULL, NULL);
  865. dir[strlen(dir) - 1] = '\0';
  866. if (drive[0] != '\0') {
  867. _dos_getdrive(&cur_drive);
  868. if (cur_drive != (drive[0] - 'A' + 1))
  869. _dos_setdrive(drive[0] - 'A' + 1, &total);
  870. }
  871. getcwd(curdir, _MAX_DIR);
  872. if (stricmp(&(curdir[2]), dir))
  873. chdir(dir);
  874. }
  875. void dos_check_file_handles(int num_required)
  876. {
  877. int i, n;
  878. FILE * fp[16];
  879. if ( num_required > 16 )
  880. num_required = 16;
  881. n = 0;
  882. for (i=0; i<16; i++ )
  883. fp[i] = NULL;
  884. for (i=0; i<16; i++ ) {
  885. fp[i] = fopen( "nul", "wb" );
  886. if ( !fp[i] ) break;
  887. }
  888. n = i;
  889. for (i=0; i<16; i++ ) {
  890. if (fp[i])
  891. fclose(fp[i]);
  892. }
  893. if ( n < num_required ) {
  894. printf( "\n%s\n", TXT_NOT_ENOUGH_HANDLES );
  895. printf( "------------------------\n" );
  896. printf( "%d/%d %s\n", n, num_required, TXT_HANDLES_1 );
  897. printf( "%s\n", TXT_HANDLES_2);
  898. printf( "%s\n", TXT_HANDLES_3);
  899. exit(1);
  900. }
  901. }
  902. #define NEEDED_DOS_MEMORY ( 300*1024) // 300 K
  903. #define NEEDED_LINEAR_MEMORY (7680*1024) // 7.5 MB
  904. #define LOW_PHYSICAL_MEMORY_CUTOFF (5*1024*1024) // 5.0 MB
  905. #define NEEDED_PHYSICAL_MEMORY (2000*1024) // 2000 KB
  906. extern int piggy_low_memory;
  907. void mem_int_to_string( int number, char *dest )
  908. {
  909. int i,l,c;
  910. char buffer[20],*p;
  911. sprintf( buffer, "%d", number );
  912. l = strlen(buffer);
  913. if (l<=3) {
  914. // Don't bother with less than 3 digits
  915. sprintf( dest, "%d", number );
  916. return;
  917. }
  918. c = 0;
  919. p=dest;
  920. for (i=l-1; i>=0; i-- ) {
  921. if (c==3) {
  922. *p++=',';
  923. c = 0;
  924. }
  925. c++;
  926. *p++ = buffer[i];
  927. }
  928. *p++ = '\0';
  929. strrev(dest);
  930. }
  931. void check_memory()
  932. {
  933. char text[32];
  934. printf( "\n%s\n", TXT_AVAILABLE_MEMORY);
  935. printf( "----------------\n" );
  936. mem_int_to_string( dpmi_dos_memory/1024, text );
  937. printf( "Conventional: %7s KB\n", text );
  938. mem_int_to_string( dpmi_physical_memory/1024, text );
  939. printf( "Extended: %7s KB\n", text );
  940. if ( dpmi_available_memory > dpmi_physical_memory ) {
  941. mem_int_to_string( (dpmi_available_memory-dpmi_physical_memory)/1024, text );
  942. } else {
  943. mem_int_to_string( 0, text );
  944. }
  945. printf( "Virtual: %7s KB\n", text );
  946. printf( "\n" );
  947. if ( dpmi_dos_memory < NEEDED_DOS_MEMORY ) {
  948. printf( "%d %s\n", NEEDED_DOS_MEMORY - dpmi_dos_memory, TXT_MEMORY_CONFIG );
  949. exit(1);
  950. }
  951. if ( dpmi_available_memory < NEEDED_LINEAR_MEMORY ) {
  952. if ( dpmi_virtual_memory ) {
  953. printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_RECONFIGURE_VMM );
  954. } else {
  955. printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_MORE_MEMORY );
  956. printf( "%s\n", TXT_MORE_MEMORY_2);
  957. }
  958. exit(1);
  959. }
  960. if ( dpmi_physical_memory < NEEDED_PHYSICAL_MEMORY ) {
  961. printf( "%d %s\n", NEEDED_PHYSICAL_MEMORY - dpmi_physical_memory, TXT_PHYSICAL_MEMORY );
  962. if ( dpmi_virtual_memory ) {
  963. printf( "%s\n", TXT_PHYSICAL_MEMORY_2);
  964. }
  965. exit(1);
  966. }
  967. if ( dpmi_physical_memory < LOW_PHYSICAL_MEMORY_CUTOFF ) {
  968. piggy_low_memory = 1;
  969. }
  970. }
  971. int Inferno_verbose = 0;
  972. //NO_STACK_SIZE_CHECK uint * stack, *stack_ptr;
  973. //NO_STACK_SIZE_CHECK int stack_size, unused_stack_space;
  974. //NO_STACK_SIZE_CHECK int sil;
  975. //NO_STACK_SIZE_CHECK
  976. //NO_STACK_SIZE_CHECK int main(int argc,char **argv)
  977. //NO_STACK_SIZE_CHECK {
  978. //NO_STACK_SIZE_CHECK uint ret_value;
  979. //NO_STACK_SIZE_CHECK
  980. //NO_STACK_SIZE_CHECK unused_stack_space = 0;
  981. //NO_STACK_SIZE_CHECK stack = &ret_value;
  982. //NO_STACK_SIZE_CHECK stack_size = stackavail()/4;
  983. //NO_STACK_SIZE_CHECK
  984. //NO_STACK_SIZE_CHECK for ( sil=0; sil<stack_size; sil++ ) {
  985. //NO_STACK_SIZE_CHECK stack--;
  986. //NO_STACK_SIZE_CHECK *stack = 0xface0123;
  987. //NO_STACK_SIZE_CHECK }
  988. //NO_STACK_SIZE_CHECK
  989. //NO_STACK_SIZE_CHECK ret_value = descent_main( argc, argv ); // Rename main to be descent_main
  990. //NO_STACK_SIZE_CHECK
  991. //NO_STACK_SIZE_CHECK for ( sil=0; sil<stack_size; sil++ ) {
  992. //NO_STACK_SIZE_CHECK if ( *stack == 0xface0123 )
  993. //NO_STACK_SIZE_CHECK unused_stack_space++;
  994. //NO_STACK_SIZE_CHECK stack++;
  995. //NO_STACK_SIZE_CHECK }
  996. //NO_STACK_SIZE_CHECK
  997. //NO_STACK_SIZE_CHECK mprintf(( 0, "Program used %d/%d stack space\n", (stack_size - unused_stack_space)*4, stack_size*4 ));
  998. //NO_STACK_SIZE_CHECK key_getch();
  999. //NO_STACK_SIZE_CHECK
  1000. //NO_STACK_SIZE_CHECK return ret_value;
  1001. //NO_STACK_SIZE_CHECK }
  1002. extern int digi_timer_rate;
  1003. int descent_critical_error = 0;
  1004. unsigned descent_critical_deverror = 0;
  1005. unsigned descent_critical_errcode = 0;
  1006. #pragma off (check_stack)
  1007. int __far descent_critical_error_handler(unsigned deverror, unsigned errcode, unsigned __far * devhdr )
  1008. {
  1009. devhdr = devhdr;
  1010. descent_critical_error++;
  1011. descent_critical_deverror = deverror;
  1012. descent_critical_errcode = errcode;
  1013. return _HARDERR_FAIL;
  1014. }
  1015. void chandler_end (void) // dummy functions
  1016. {
  1017. }
  1018. #pragma on (check_stack)
  1019. extern int Network_allow_socket_changes;
  1020. extern void vfx_set_palette_sub(ubyte *);
  1021. extern int Game_vfx_flag;
  1022. extern int Game_victor_flag;
  1023. extern int Game_vio_flag;
  1024. extern int Game_3dmax_flag;
  1025. extern int VR_low_res;
  1026. extern void vfx_init();
  1027. #ifdef USE_CD
  1028. char destsat_cdpath[128] = "";
  1029. int find_descent_cd();
  1030. #endif
  1031. extern int Config_vr_type;
  1032. extern int Config_vr_tracking;
  1033. int main(int argc,char **argv)
  1034. {
  1035. int i,t;
  1036. ubyte title_pal[768];
  1037. error_init(NULL);
  1038. setbuf(stdout, NULL); // unbuffered output via printf
  1039. InitArgs( argc,argv );
  1040. if ( FindArg( "-verbose" ) )
  1041. Inferno_verbose = 1;
  1042. //change_to_dir(argv[0]);
  1043. // Initialize DPMI before anything else!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1044. // (To check memory size and availbabitliy and allocate some low DOS memory)
  1045. if (Inferno_verbose) printf( "%s... ", TXT_INITIALIZING_DPMI);
  1046. dpmi_init(Inferno_verbose); // Before anything
  1047. if (Inferno_verbose) printf( "\n" );
  1048. if (Inferno_verbose) printf( "\n%s...", TXT_INITIALIZING_CRIT);
  1049. if (!dpmi_lock_region((void near *)descent_critical_error_handler,(char *)chandler_end - (char near *)descent_critical_error_handler)) {
  1050. Error( "Unable to lock critial error handler" );
  1051. }
  1052. if (!dpmi_lock_region(&descent_critical_error,sizeof(int))) {
  1053. Error( "Unable to lock critial error handler" );
  1054. }
  1055. if (!dpmi_lock_region(&descent_critical_deverror,sizeof(unsigned))) {
  1056. Error( "Unable to lock critial error handler" );
  1057. }
  1058. if (!dpmi_lock_region(&descent_critical_errcode,sizeof(unsigned))) {
  1059. Error( "Unable to lock critial error handler" );
  1060. }
  1061. _harderr((void *) descent_critical_error_handler );
  1062. //Above line modified by KRB, added (void *) cast
  1063. //for the compiler.
  1064. #ifdef USE_CD
  1065. i=find_descent_cd();
  1066. if ( i>0 ) {
  1067. sprintf( destsat_cdpath, "%c:\\descent\\", i +'a' - 1 );
  1068. cfile_use_alternate_hogdir( destsat_cdpath );
  1069. }
  1070. #ifdef REQUIRE_CD
  1071. else { // NOTE ABOVE LINK!!!!!!!!!!!!!!!!!!
  1072. printf( "\n\n" );
  1073. #ifdef DEST_SAT
  1074. printf("Couldn't find the 'Descent: Destination Saturn' CD-ROM.\n" );
  1075. #else
  1076. printf("Couldn't find the Descent CD-ROM.\n" );
  1077. #endif
  1078. printf("Please make sure that it is in your CD-ROM drive and\n" );
  1079. printf("that your CD-ROM drivers are loaded correctly.\n" );
  1080. exit(1);
  1081. }
  1082. #endif
  1083. #endif
  1084. load_text();
  1085. // set_exit_message("\n\n%s", TXT_THANKS);
  1086. printf("\nDESCENT %s\n", VERSION_NAME);
  1087. printf("%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
  1088. check_id_checksum_and_date();
  1089. if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
  1090. printf( "%s\n", TXT_COMMAND_LINE_0 );
  1091. printf(" -SimulEyes %s\n",
  1092. "Enables StereoGraphics SimulEyes VR stereo display" );
  1093. printf(" -Iglasses %s\n", TXT_IGLASSES );
  1094. printf(" -VioTrack <n> %s n\n",TXT_VIOTRACK );
  1095. printf(" -3dmaxLo %s\n",TXT_KASAN );
  1096. printf(" %s\n",TXT_KASAN_2 );
  1097. printf(" -3dmaxHi %s\n",TXT_3DMAX );
  1098. printf( "%s\n", TXT_COMMAND_LINE_1 );
  1099. printf( "%s\n", TXT_COMMAND_LINE_2 );
  1100. printf( "%s\n", TXT_COMMAND_LINE_3 );
  1101. printf( "%s\n", TXT_COMMAND_LINE_4 );
  1102. printf( "%s\n", TXT_COMMAND_LINE_5 );
  1103. // printf( "\n");
  1104. printf( "%s\n", TXT_COMMAND_LINE_6 );
  1105. printf( "%s\n", TXT_COMMAND_LINE_7 );
  1106. printf( "%s\n", TXT_COMMAND_LINE_8 );
  1107. // printf( "\n");
  1108. printf( "\n%s\n",TXT_PRESS_ANY_KEY3);
  1109. getch();
  1110. printf( "\n" );
  1111. printf( "%s\n", TXT_COMMAND_LINE_9);
  1112. printf( "%s\n", TXT_COMMAND_LINE_10);
  1113. printf( "%s\n", TXT_COMMAND_LINE_11);
  1114. printf( "%s\n", TXT_COMMAND_LINE_12);
  1115. printf( "%s\n", TXT_COMMAND_LINE_13);
  1116. printf( "%s\n", TXT_COMMAND_LINE_14);
  1117. printf( "%s\n", TXT_COMMAND_LINE_15);
  1118. printf( "%s\n", TXT_COMMAND_LINE_16);
  1119. printf( "%s\n", TXT_COMMAND_LINE_17);
  1120. printf( "%s\n", TXT_COMMAND_LINE_18);
  1121. printf( " -DynamicSockets %s\n", TXT_SOCKET);
  1122. printf( " -NoFileCheck %s\n", TXT_NOFILECHECK);
  1123. printf( " -GamePort %s\n", "Use Colorado Spectrum's Notebook Gameport" );
  1124. printf( " -NoDoubleBuffer %s\n", "Use only one page of video memory" );
  1125. printf( " -LCDBios %s\n", "Enables LCDBIOS for using LCD shutter glasses" );
  1126. printf( " -JoyNice %s\n", "Joystick poller allows interrupts to occur" );
  1127. set_exit_message("");
  1128. return(0);
  1129. }
  1130. printf("\n%s\n", TXT_HELP);
  1131. #ifdef PASSWORD
  1132. if ((t = FindArg("-pswd")) != 0) {
  1133. int n;
  1134. byte *pp = Side_to_verts;
  1135. int ch;
  1136. for (n=0; n<6; n++)
  1137. for (ch=0; ch<strlen(Args[t+1]); ch++)
  1138. *pp++ ^= Args[t+1][ch];
  1139. }
  1140. else
  1141. Error("Invalid processor"); //missing password
  1142. #endif
  1143. if ( FindArg( "-autodemo" ))
  1144. Auto_demo = 1;
  1145. #ifndef RELEASE
  1146. if ( FindArg( "-noscreens" ) )
  1147. Skip_briefing_screens = 1;
  1148. #endif
  1149. Lighting_on = 1;
  1150. if ( !FindArg( "-nodoscheck" ))
  1151. check_dos_version();
  1152. if ( !FindArg( "-nofilecheck" ))
  1153. dos_check_file_handles(5);
  1154. if ( !FindArg( "-nomemcheck" ))
  1155. check_memory();
  1156. strcpy(Menu_pcx_name, "menu.pcx"); // Used to be menu2.pcx.
  1157. if (init_graphics()) return 1;
  1158. #ifdef EDITOR
  1159. if (!Inferno_is_800x600_available) {
  1160. printf( "The editor will not be available, press any key to start game...\n" );
  1161. Function_mode = FMODE_MENU;
  1162. getch();
  1163. }
  1164. #endif
  1165. #ifndef NDEBUG
  1166. minit();
  1167. mopen( 0, 9, 1, 78, 15, "Debug Spew");
  1168. mopen( 1, 2, 1, 78, 5, "Errors & Serious Warnings");
  1169. #endif
  1170. if (!WVIDEO_running)
  1171. mprintf((0,"WVIDEO_running = %d\n",WVIDEO_running));
  1172. //if (!WVIDEO_running) install_int3_handler();
  1173. //lib_init("INFERNO.DAT");
  1174. if (Inferno_verbose) printf ("%s", TXT_VERBOSE_1);
  1175. ReadConfigFile();
  1176. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_2);
  1177. timer_init();
  1178. timer_set_rate( digi_timer_rate ); // Tell our timer how fast to go (120 Hz)
  1179. joy_set_timer_rate( digi_timer_rate ); // Tell joystick how fast timer is going
  1180. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_3);
  1181. key_init();
  1182. if (!FindArg( "-nomouse" )) {
  1183. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_4);
  1184. if (FindArg( "-nocyberman" ))
  1185. mouse_init(0);
  1186. else
  1187. mouse_init(1);
  1188. } else {
  1189. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_5);
  1190. }
  1191. if (!FindArg( "-nojoystick" )) {
  1192. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_6);
  1193. joy_init();
  1194. if ( FindArg( "-joyslow" )) {
  1195. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_7);
  1196. joy_set_slow_reading(JOY_SLOW_READINGS);
  1197. }
  1198. if ( FindArg( "-joypolled" )) {
  1199. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_8);
  1200. joy_set_slow_reading(JOY_POLLED_READINGS);
  1201. }
  1202. if ( FindArg( "-joybios" )) {
  1203. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_9);
  1204. joy_set_slow_reading(JOY_BIOS_READINGS);
  1205. }
  1206. if ( FindArg( "-joynice" )) {
  1207. if (Inferno_verbose) printf( "\n%s", "Using nice joystick poller..." );
  1208. joy_set_slow_reading(JOY_FRIENDLY_READINGS);
  1209. }
  1210. if ( FindArg( "-gameport" )) {
  1211. if ( init_gameport() ) {
  1212. joy_set_slow_reading(JOY_BIOS_READINGS);
  1213. } else {
  1214. Error( "\nCouldn't initialize the Notebook Gameport.\nMake sure the NG driver is loaded.\n" );
  1215. }
  1216. }
  1217. } else {
  1218. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_10);
  1219. }
  1220. if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_11);
  1221. div0_init(DM_ERROR);
  1222. //------------ Init sound ---------------
  1223. if (!FindArg( "-nosound" )) {
  1224. if (digi_init()) {
  1225. printf( "\n%s\n", TXT_PRESS_ANY_KEY3);
  1226. key_getch();
  1227. }
  1228. } else {
  1229. if (Inferno_verbose) printf( "\n%s",TXT_SOUND_DISABLED );
  1230. }
  1231. #ifdef NETWORK
  1232. if (!FindArg( "-nonetwork" )) {
  1233. int socket=0, showaddress=0;
  1234. int ipx_error;
  1235. if (Inferno_verbose) printf( "\n%s ", TXT_INITIALIZING_NETWORK);
  1236. if ((t=FindArg("-socket")))
  1237. socket = atoi( Args[t+1] );
  1238. if ( FindArg("-showaddress") ) showaddress=1;
  1239. if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0) {
  1240. if (Inferno_verbose) printf( "%s %d.\n", TXT_IPX_CHANNEL, socket );
  1241. Network_active = 1;
  1242. } else {
  1243. switch( ipx_error ) {
  1244. case 3: if (Inferno_verbose) printf( "%s\n", TXT_NO_NETWORK); break;
  1245. case -2: if (Inferno_verbose) printf( "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
  1246. case -4: if (Inferno_verbose) printf( "%s\n", TXT_MEMORY_IPX ); break;
  1247. default:
  1248. if (Inferno_verbose) printf( "%s %d", TXT_ERROR_IPX, ipx_error );
  1249. }
  1250. if (Inferno_verbose) printf( "%s\n",TXT_NETWORK_DISABLED);
  1251. Network_active = 0; // Assume no network
  1252. }
  1253. ipx_read_user_file( "descent.usr" );
  1254. ipx_read_network_file( "descent.net" );
  1255. if ( FindArg( "-dynamicsockets" ))
  1256. Network_allow_socket_changes = 1;
  1257. else
  1258. Network_allow_socket_changes = 0;
  1259. } else {
  1260. if (Inferno_verbose) printf( "%s\n", TXT_NETWORK_DISABLED);
  1261. Network_active = 0; // Assume no network
  1262. }
  1263. if (!FindArg("-noserial"))
  1264. {
  1265. serial_active = 1;
  1266. }
  1267. else
  1268. {
  1269. serial_active = 0;
  1270. }
  1271. #endif
  1272. i = FindArg( "-vfxtrak" );
  1273. if ( i > 0 )
  1274. kconfig_sense_init();
  1275. else if ((Config_vr_type==1)&&(Config_vr_tracking>0))
  1276. kconfig_sense_init();
  1277. i = FindArg( "-maxxtrak" );
  1278. if ( i > 0)
  1279. victor_init_tracking( atoi(Args[i+1]) );
  1280. else if ((Config_vr_type==2)&&(Config_vr_tracking>0))
  1281. victor_init_tracking( Config_vr_tracking );
  1282. i = FindArg( "-viotrack" );
  1283. if ( i > 0 )
  1284. iglasses_init_tracking( atoi(Args[i+1]) );
  1285. else if ((Config_vr_type==3)&&(Config_vr_tracking>0))
  1286. iglasses_init_tracking( Config_vr_tracking );
  1287. if ( FindArg( "-vfx" ) || (Config_vr_type==1) ) {
  1288. vfx_init();
  1289. Game_vfx_flag = 1;
  1290. game_init_render_buffers(SM_640x480V, 320, 240, 0, VR_AREA_DET, 0 );
  1291. VR_low_res = 3;
  1292. } else if ( FindArg( "-cybermaxx" ) || (Config_vr_type==2) ) {
  1293. Game_victor_flag = 1;
  1294. game_init_render_buffers(SM_320x200C, 320, 100, 0, VR_INTERLACED, 1 );
  1295. VR_low_res = 0;
  1296. } else if ( FindArg( "-iglasses" ) || (Config_vr_type==3) ) {
  1297. Game_vio_flag = 1;
  1298. game_init_render_buffers(SM_320x400U, 320, 200, 1, VR_INTERLACED, 0 );
  1299. VR_low_res = 3;
  1300. } else if ( FindArg( "-cybermax2" ) || (Config_vr_type==6) ) {
  1301. game_init_render_buffers(SM_320x400U, 320, 200, 1, VR_INTERLACED, 0 );
  1302. VR_low_res = 3;
  1303. } else if ( FindArg( "-3dmaxlo" ) || (Config_vr_type==4) ) {
  1304. if (!is_3dbios_installed()) {
  1305. printf( "Error: Kasan 3DBIOS needs to be installed.\n" );
  1306. exit(1);
  1307. }
  1308. Game_3dmax_flag = 1;
  1309. game_init_render_buffers(SM_320x200C, 320, 100, 0, VR_INTERLACED, 0 );
  1310. VR_low_res = 0;
  1311. VR_switch_eyes = 0;
  1312. } else if ( FindArg( "-3dmaxhi" ) || (Config_vr_type==5) ) {
  1313. if (!is_3dbios_installed()) {
  1314. printf( "Error: Kasan's 3DBIOS needs to be installed.\n" );
  1315. exit(1);
  1316. }
  1317. Game_3dmax_flag = 2;
  1318. game_init_render_buffers(22, 320, 200, 1, VR_INTERLACED, 0 );
  1319. VR_switch_eyes = 0;
  1320. VR_low_res = 0;
  1321. } else {
  1322. int screen_mode = SM_320x200C;
  1323. int screen_width = 320;
  1324. int screen_height = 200;
  1325. int vr_mode = VR_NONE;
  1326. int screen_compatible = 1;
  1327. int use_double_buffer = 0;
  1328. if ( FindArg( "-lcdbios" ) ) {
  1329. if (!is_3dbios_installed()) {
  1330. printf( "Warning: LCDBIOS needs to be installed.\nPress Esc to continue anyway, any other key to exit.\n" );
  1331. if ( key_getch()!=KEY_ESC )
  1332. exit(1);
  1333. }
  1334. if (Inferno_verbose) printf( "Enabling LCDBIOS...\n" );
  1335. Game_3dmax_flag = 3;
  1336. screen_compatible = 0;
  1337. VR_switch_eyes = 0;
  1338. VR_low_res = 0;
  1339. vr_mode = VR_INTERLACED;
  1340. }
  1341. if ( FindArg( "-simuleyes" )) {
  1342. Game_simuleyes_flag = 1;
  1343. }
  1344. if (Game_simuleyes_flag) { // default to 320x400 (x200 per eye)
  1345. screen_mode = SM_320x400U;
  1346. screen_width = 320;
  1347. screen_height = 400;
  1348. screen_compatible = 0;
  1349. use_double_buffer = 1;
  1350. if ( FindArg( "-320x200" )) {
  1351. if (Inferno_verbose) printf( "Using 320x200...\n" );
  1352. screen_mode = SM_320x200C;
  1353. screen_width = 320;
  1354. screen_height = 200;
  1355. use_double_buffer = 0;
  1356. }
  1357. else {
  1358. if (Inferno_verbose) printf( "Using 320x400 ModeX...\n" );
  1359. }
  1360. }
  1361. if ( FindArg( "-320x240" )) {
  1362. if (Inferno_verbose) printf( "Using 320x240 ModeX...\n" );
  1363. screen_mode = SM_320x240U;
  1364. screen_width = 320;
  1365. screen_height = 240;
  1366. screen_compatible = 0;
  1367. use_double_buffer = 1;
  1368. }
  1369. if ( FindArg( "-320x400" )) {
  1370. if (Inferno_verbose) printf( "Using 320x400 ModeX...\n" );
  1371. screen_mode = SM_320x400U;
  1372. screen_width = 320;
  1373. screen_height = 400;
  1374. screen_compatible = 0;
  1375. use_double_buffer = 1;
  1376. }
  1377. if (!Game_simuleyes_flag && FindArg( "-640x400" )) {
  1378. if (Inferno_verbose) printf( "Using 640x400 VESA...\n" );
  1379. screen_mode = SM_640x400V;
  1380. screen_width = 640;
  1381. screen_height = 400;
  1382. screen_compatible = 0;
  1383. use_double_buffer = 1;
  1384. }
  1385. if (!Game_simuleyes_flag && FindArg( "-640x480" )) {
  1386. if (Inferno_verbose) printf( "Using 640x480 VESA...\n" );
  1387. screen_mode = SM_640x480V;
  1388. screen_width = 640;
  1389. screen_height = 480;
  1390. screen_compatible = 0;
  1391. use_double_buffer = 1;
  1392. }
  1393. if ( FindArg( "-320x100" )) {
  1394. if (Inferno_verbose) printf( "Using 320x100 VGA...\n" );
  1395. screen_mode = 19;
  1396. screen_width = 320;
  1397. screen_height = 100;
  1398. screen_compatible = 0;
  1399. }
  1400. if ( FindArg( "-nodoublebuffer" ) ) {
  1401. if (Inferno_verbose) printf( "Double-buffering disabled...\n" );
  1402. use_double_buffer = 0;
  1403. }
  1404. if ( vr_mode == VR_INTERLACED )
  1405. screen_height /= 2;
  1406. game_init_render_buffers(screen_mode, screen_width, screen_height, use_double_buffer, vr_mode, screen_compatible );
  1407. }
  1408. if (Game_victor_flag) {
  1409. char *vswitch = getenv( "CYBERMAXX" );
  1410. if ( vswitch ) {
  1411. char *p = strstr( vswitch, "/E:R" );
  1412. if ( p ) {
  1413. VR_switch_eyes = 1;
  1414. } else
  1415. VR_switch_eyes = 0;
  1416. } else {
  1417. VR_switch_eyes = 0;
  1418. }
  1419. }
  1420. #ifdef ARCADE
  1421. i = FindArg( "-arcade" );
  1422. if (i > 0 ) {
  1423. arcade_init();
  1424. coindev_init(0);
  1425. }
  1426. #endif
  1427. #ifdef NETWORK
  1428. // i = FindArg( "-rinvul" );
  1429. // if (i > 0) {
  1430. // int mins = atoi(Args[i+1]);
  1431. // if (mins > 314)
  1432. // mins = 314;
  1433. // control_invul_time = mins/5;
  1434. // }
  1435. control_invul_time = 0;
  1436. #endif
  1437. i = FindArg( "-xcontrol" );
  1438. if ( i > 0 ) {
  1439. kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
  1440. }
  1441. if (Inferno_verbose) printf( "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
  1442. if ((t=gr_init( SM_ORIGINAL ))!=0)
  1443. Error(TXT_CANT_INIT_GFX,t);
  1444. // Load the palette stuff. Returns non-zero if error.
  1445. mprintf( (0, "Going into graphics mode..." ));
  1446. gr_set_mode(SM_320x200C);
  1447. mprintf( (0, "\nInitializing palette system..." ));
  1448. gr_use_palette_table( "PALETTE.256" );
  1449. mprintf( (0, "\nInitializing font system..." ));
  1450. gamefont_init(); // must load after palette data loaded.
  1451. songs_play_song( SONG_TITLE, 1 );
  1452. #ifndef RELEASE
  1453. if ( !FindArg( "-notitles" ) )
  1454. #endif
  1455. { //NOTE LINK TO ABOVE!
  1456. show_title_screen( "iplogo1.pcx", 1 );
  1457. show_title_screen( "logo.pcx", 1 );
  1458. }
  1459. {
  1460. //grs_bitmap title_bm;
  1461. int pcx_error;
  1462. char filename[14];
  1463. strcpy(filename, "descent.pcx");
  1464. if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
  1465. vfx_set_palette_sub( title_pal );
  1466. gr_palette_clear();
  1467. //gr_bitmap( 0, 0, &title_bm );
  1468. gr_palette_fade_in( title_pal, 32, 0 );
  1469. //free(title_bm.bm_data);
  1470. } else {
  1471. gr_close();
  1472. Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
  1473. }
  1474. }
  1475. #ifdef EDITOR
  1476. if ( !FindArg("-nobm") )
  1477. bm_init_use_tbl();
  1478. else
  1479. bm_init();
  1480. #else
  1481. bm_init();
  1482. #endif
  1483. if ( FindArg( "-norun" ) )
  1484. return(0);
  1485. mprintf( (0, "\nInitializing 3d system..." ));
  1486. g3_init();
  1487. mprintf( (0, "\nInitializing texture caching system..." ));
  1488. texmerge_init( 10 ); // 10 cache bitmaps
  1489. mprintf( (0, "\nRunning game...\n" ));
  1490. set_screen_mode(SCREEN_MENU);
  1491. init_game();
  1492. set_detail_level_parameters(Detail_level);
  1493. Players[Player_num].callsign[0] = '\0';
  1494. if (!Auto_demo) {
  1495. key_flush();
  1496. RegisterPlayer(); //get player's name
  1497. }
  1498. gr_palette_fade_out( title_pal, 32, 0 );
  1499. //check for special stamped version
  1500. if (registered_copy) {
  1501. nm_messagebox("EVALUATION COPY",1,"Continue",
  1502. "This special evaluation copy\n"
  1503. "of DESCENT has been issued to:\n\n"
  1504. "%s\n"
  1505. "\n\n NOT FOR DISTRIBUTION",
  1506. name_copy);
  1507. gr_palette_fade_out( gr_palette, 32, 0 );
  1508. }
  1509. //kconfig_load_all();
  1510. Game_mode = GM_GAME_OVER;
  1511. if (Auto_demo) {
  1512. newdemo_start_playback("DESCENT.DEM");
  1513. if (Newdemo_state == ND_STATE_PLAYBACK )
  1514. Function_mode = FMODE_GAME;
  1515. }
  1516. build_mission_list(0); // This also loads mission 0.
  1517. while (Function_mode != FMODE_EXIT)
  1518. {
  1519. switch( Function_mode ) {
  1520. case FMODE_MENU:
  1521. if ( Auto_demo ) {
  1522. newdemo_start_playback(NULL); // Randomly pick a file
  1523. if (Newdemo_state != ND_STATE_PLAYBACK)
  1524. Error("No demo files were found for autodemo mode!");
  1525. } else {
  1526. check_joystick_calibration();
  1527. DoMenu();
  1528. #ifdef EDITOR
  1529. if ( Function_mode == FMODE_EDITOR ) {
  1530. create_new_mine();
  1531. SetPlayerFromCurseg();
  1532. }
  1533. #endif
  1534. }
  1535. break;
  1536. case FMODE_GAME:
  1537. #ifdef EDITOR
  1538. keyd_editor_mode = 0;
  1539. #endif
  1540. game();
  1541. if ( Function_mode == FMODE_MENU )
  1542. songs_play_song( SONG_TITLE, 1 );
  1543. break;
  1544. #ifdef EDITOR
  1545. case FMODE_EDITOR:
  1546. keyd_editor_mode = 1;
  1547. editor();
  1548. _harderr( (void *)descent_critical_error_handler ); // Reinstall game error handler
  1549. if ( Function_mode == FMODE_GAME ) {
  1550. Game_mode = GM_EDITOR;
  1551. editor_reset_stuff_on_level();
  1552. N_players = 1;
  1553. }
  1554. break;
  1555. #endif
  1556. default:
  1557. Error("Invalid function mode %d",Function_mode);
  1558. }
  1559. }
  1560. WriteConfigFile();
  1561. #ifndef ROCKWELL_CODE
  1562. #ifndef RELEASE
  1563. if (!FindArg( "-notitles" ))
  1564. #endif
  1565. //NOTE LINK TO ABOVE!!
  1566. #ifndef EDITOR
  1567. show_order_form();
  1568. #endif
  1569. #endif
  1570. #ifndef NDEBUG
  1571. if ( FindArg( "-showmeminfo" ) )
  1572. // show_mem_info = 1; // Make memory statistics show
  1573. #endif
  1574. return(0); //presumably successful exit
  1575. }
  1576. void check_joystick_calibration() {
  1577. int x1, y1, x2, y2, c;
  1578. fix t1;
  1579. if ( (Config_control_type!=CONTROL_JOYSTICK) &&
  1580. (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
  1581. (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
  1582. (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
  1583. ) return;
  1584. joy_get_pos( &x1, &y1 );
  1585. t1 = timer_get_fixed_seconds();
  1586. while( timer_get_fixed_seconds() < t1 + F1_0/100 )
  1587. ;
  1588. joy_get_pos( &x2, &y2 );
  1589. // If joystick hasn't moved...
  1590. if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
  1591. if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
  1592. c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
  1593. if ( c==0 ) {
  1594. joydefs_calibrate();
  1595. }
  1596. }
  1597. }
  1598. }
  1599. void show_order_form()
  1600. {
  1601. int pcx_error;
  1602. char title_pal[768];
  1603. char exit_screen[16];
  1604. gr_set_current_canvas( NULL );
  1605. gr_palette_clear();
  1606. key_flush();
  1607. #ifdef SHAREWARE
  1608. strcpy(exit_screen, "order01.pcx");
  1609. #else
  1610. #ifdef DEST_SAT
  1611. strcpy(exit_screen, "order01.pcx");
  1612. #else
  1613. strcpy(exit_screen, "warning.pcx");
  1614. #endif
  1615. #endif
  1616. if ((pcx_error=pcx_read_bitmap( exit_screen, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
  1617. vfx_set_palette_sub( title_pal );
  1618. gr_palette_fade_in( title_pal, 32, 0 );
  1619. {
  1620. int done=0;
  1621. fix time_out_value = timer_get_approx_seconds()+i2f(60*5);
  1622. while(!done) {
  1623. if ( timer_get_approx_seconds() > time_out_value ) done = 1;
  1624. if (key_inkey()) done = 1;
  1625. }
  1626. }
  1627. gr_palette_fade_out( title_pal, 32, 0 );
  1628. }
  1629. key_flush();
  1630. }
  1631. #ifdef USE_CD
  1632. #include <dos.h>
  1633. #include <stdio.h>
  1634. #include <stdlib.h>
  1635. #include <string.h>
  1636. #include "dpmi.h"
  1637. typedef struct {
  1638. char unit;
  1639. ushort dev_offset;
  1640. ushort dev_segment;
  1641. } dev_list;
  1642. typedef struct _Dev_Hdr {
  1643. unsigned int dev_next;
  1644. unsigned short dev_att;
  1645. ushort dev_stat;
  1646. ushort dev_int;
  1647. char dev_name[8];
  1648. short dev_resv;
  1649. char dev_letr;
  1650. char dev_units;
  1651. } dev_header;
  1652. int find_descent_cd()
  1653. {
  1654. dpmi_real_regs rregs;
  1655. // Get dos memory for call...
  1656. dev_list * buf;
  1657. dev_header *device;
  1658. int num_drives, i;
  1659. unsigned cdrive, cur_drive, cdrom_drive;
  1660. memset(&rregs,0,sizeof(dpmi_real_regs));
  1661. rregs.eax = 0x1500;
  1662. rregs.ebx = 0;
  1663. dpmi_real_int386x( 0x2f, &rregs );
  1664. if ((rregs.ebx & 0xffff) == 0) {
  1665. return -1; // No cdrom
  1666. }
  1667. num_drives = rregs.ebx;
  1668. buf = (dev_list *)dpmi_get_temp_low_buffer( sizeof(dev_list)*26 );
  1669. if (buf==NULL) {
  1670. return -2; // Error getting memory!
  1671. }
  1672. memset(&rregs,0,sizeof(dpmi_real_regs));
  1673. rregs.es = DPMI_real_segment(buf);
  1674. rregs.ebx = DPMI_real_offset(buf);
  1675. rregs.eax = 0x1501;
  1676. dpmi_real_int386x( 0x2f, &rregs );
  1677. cdrom_drive = 0;
  1678. _dos_getdrive(&cdrive);
  1679. for (i = 0; i < num_drives; i++) {
  1680. device = (dev_header *)((buf[i].dev_segment<<4)+ buf[i].dev_offset);
  1681. _dos_setdrive(device->dev_letr,&cur_drive);
  1682. _dos_getdrive(&cur_drive);
  1683. if (cur_drive == device->dev_letr) {
  1684. if (!chdir("\\descent")) {
  1685. FILE * fp;
  1686. #ifdef DEST_SAT
  1687. fp = fopen( "saturn.hog", "rb" );
  1688. #else
  1689. fp = fopen( "descent.hog", "rb" );
  1690. #endif
  1691. if ( fp ) {
  1692. int write_failed = 1;
  1693. fclose(fp);
  1694. fp = fopen( "descent.tmp", "wb" );
  1695. if ( fp ) {
  1696. int temp = 0x15A90C23;
  1697. if ( fwrite( &temp, sizeof(int), 1, fp )==1 ) {
  1698. fp = fopen( "descent.tmp", "rb" );
  1699. if ( fp ) {
  1700. temp = 0;
  1701. if ( fread( &temp, sizeof(int), 1, fp )==1 ) {
  1702. if ( temp == 0x15A90C23 )
  1703. write_failed = 0;
  1704. }
  1705. fclose(fp);
  1706. unlink( "descent.tmp" );
  1707. }
  1708. }
  1709. fclose(fp);
  1710. }
  1711. if ( write_failed ) {
  1712. cdrom_drive = device->dev_letr;
  1713. break;
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. _dos_setdrive(cdrive,&cur_drive);
  1720. return cdrom_drive;
  1721. }
  1722. #endif