main_run.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. * Copyright (C) 1999 Charles Goetzman
  7. * Copyright (C) 2002 B.D.A. (Koji) - Koji_Takeo@worldmailer.com
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. //This source code should be 8086 compatible
  24. #pragma option -2-
  25. #pragma option -1-
  26. #include "beep.h"
  27. #include "profile.h"
  28. #include "ceh.h"
  29. #include "helpsys.h"
  30. #include "sfx.h"
  31. #include "random.h"
  32. #include "edit.h"
  33. #include "ezboard.h"
  34. #include "roballoc.h"
  35. #include <setjmp.h>
  36. #include <dir.h>
  37. #include "blink.h"
  38. #include "timer.h"
  39. #include "egacode.h"
  40. #include "meminter.h"
  41. #include "string.h"
  42. #include "arrowkey.h"
  43. #include "comp_chk.h"
  44. #include "dt_data.h"
  45. #include "graphics.h"
  46. #include "cursor.h"
  47. #include "window.h"
  48. #include "palette.h"
  49. #include "getkey.h"
  50. #include "ems.h"
  51. #include <stdlib.h>
  52. #include "main.h"
  53. #include <dos.h>
  54. #include <stdio.h>
  55. #include "detect.h"
  56. #include "data.h"
  57. #include "mod.h"
  58. #include "game.h"
  59. #include "error.h"
  60. #include <time.h>
  61. #define SAVE_INDIVIDUAL
  62. //new_settings=1 if Addr IRQ or DMA was updated via CMD line so we
  63. //should keep them even if config is entered
  64. char force_ega=0,no_mouse=0,no_ems=0,new_settings=0;
  65. jmp_buf exit_jump;//Used in error function and nowhere else
  66. extern unsigned int Addr,IRQ,DMA;//Sound card parameters (-1=detect)
  67. #ifdef UNREG
  68. char *unreg_exit_mesg=
  69. "This message should not be displayed, it is a bug, if it is.";
  70. #else
  71. char *reg_exit_mesg=
  72. "Thank you for playing MegaZeux.\n\r"
  73. "Read the files help.txt, megazeux.doc and readme.1st if you need help.\n\n\r"
  74. "MegaZeux, by Greg Janson\n\r"
  75. "Additional contributors:\n\r"
  76. "\tSpider124, CapnKev, MenTaLguY, JZig, Akwende, Koji, Exophase\n\n\r"
  77. "Check the whatsnew file for new additions.\n\n\r"
  78. "Check http://www.digitalmzx.net/ for MZX source and binary distributions.\n\r$";
  79. #endif
  80. #pragma warn -par
  81. int main(int argc,char **argv) {
  82. //Temp var for number->string conversion
  83. char temp[7];
  84. //Set to 1 if any errors occur during startup
  85. char errors=0;
  86. //Used to save result of early ec_init() call
  87. char ec_i=0;
  88. //Temporary variables
  89. int t1;
  90. //Return code
  91. int ret=0;
  92. //Set if we need first time help
  93. char first_time=0;
  94. //Jump destination for exiting to DOS
  95. if(setjmp(exit_jump)) {//Exiting to DOS
  96. mod_exit();
  97. ret=3;
  98. goto escape;
  99. }
  100. //First thing- check for card and processor
  101. if(computer_check()) return 1;
  102. //Scan command line options, exit if need be
  103. if(scan_options()) return 2;
  104. if(force_ega) vga_avail=0;
  105. //Now- Page 0
  106. page_flip(0);
  107. //Init palette system and fade out
  108. init_palette();
  109. vquick_fadeout();
  110. //Setup directory strings
  111. //Get megazeux directory
  112. str_cpy(help_file,argv[0]);
  113. //Chop at last backslash
  114. for(t1=str_len(help_file);t1>=0;t1--)
  115. if(help_file[t1]=='\\') break;
  116. help_file[t1+1]=0;
  117. //Copy to config_file and MSE_file and blank_mod_file and convert_mod_file
  118. str_cpy(config_file,help_file);
  119. str_cpy(MSE_file,help_file);
  120. str_cpy(mzx_blank_mod_file,help_file);
  121. str_cpy(mzx_convert_mod_file,help_file);
  122. //Caton filenames
  123. str_cat(config_file,"megazeux.cfg");
  124. str_cat(help_file,"mzx_help.fil");
  125. //Get current directory and drive (form- C:\DIR\SUBDIR)
  126. getcwd(current_dir,PATHNAME_SIZE);
  127. str_cpy(megazeux_dir,current_dir);
  128. megazeux_drive=current_drive=getdisk();
  129. //Disable smzx mode
  130. //Switch to EGA 14 point mode and turn off cursor
  131. ega_14p_mode();
  132. cursor_off();
  133. //Init ec code and load up default set NOW to avoid seeing the
  134. //line characters shift. Save status of call for later.
  135. ec_i=ec_init();
  136. //These lines prevent a white flash onscreen
  137. init_palette();
  138. insta_fadeout();
  139. //Display Megazeux startup screen
  140. draw_window_box(0,0,79,24,0xB800,127,120,113,0);
  141. draw_window_box(2,1,77,3,0xB800,120,127,113,0);
  142. draw_window_box(2,4,77,16,0xB800,120,127,113,0);
  143. draw_window_box(2,17,77,23,0xB800,120,127,113,0);
  144. write_string("MegaZeux version 2.68",27,2,127,0xB800);
  145. // #ifdef BETA
  146. write_string("Beta; please distribute",27,17,127,0xB800);
  147. // #endif
  148. #ifdef GAMMA
  149. write_string("GAMMA- MAY CONTAIN BUGz!",27,17,127,0xB800);
  150. #endif
  151. #ifdef UNREG
  152. write_string("Unregistered Evaluation Copy",25,0,122,0xB800);
  153. #endif
  154. write_string("Graphics card:",4,18,122,0xB800);
  155. write_string("EMS available:",4,20,122,0xB800);
  156. write_string("Core mem free:",4,21,122,0xB800);
  157. write_string("Memory allocs:",4,22,122,0xB800);
  158. write_string("Keyboard handler:",41,18,122,0xB800);
  159. write_string("Mouse handler:",44,19,122,0xB800);
  160. write_string("Sound card port:",42,20,122,0xB800);
  161. write_string("Sound card IRQ:",43,21,122,0xB800);
  162. write_string("Sound card DMA:",43,22,122,0xB800);
  163. // I restored the original startup palette... - Exo
  164. set_rgb(1,31,31,31);
  165. set_rgb(6,63,0,0);
  166. set_rgb(7,21,21,21);
  167. set_rgb(8,8,8,8);
  168. set_rgb(9,42,42,63);
  169. set_rgb(10,42,63,42);
  170. set_rgb(11,42,63,63);
  171. set_rgb(12,63,42,42);
  172. set_rgb(13,63,42,63);
  173. //Fade in
  174. vquick_fadein();
  175. //Initialize systems and display progess at bottom
  176. //First, show graphics card and processor
  177. if(force_ega) write_string("EGA (command line)",19,18,125,0xB800);
  178. else write_string(gcard_strs[card-3],19,18,121,0xB800);
  179. //Initialize EMS systems
  180. if(no_ems) write_string("Forced off",19,20,125,0xB800);
  181. else if(setup_EMS()) write_string("None",19,20,124,0xB800);
  182. else {
  183. itoa(free_mem_EMS()*16,temp,10);
  184. temp[str_len(temp)+1]=0;
  185. temp[str_len(temp)]='k';
  186. if(free_mem_EMS()>=64) write_string(temp,19,20,121,0xB800);
  187. else write_string(temp,19,20,124,0xB800);
  188. }
  189. //Write up keyboard mode
  190. if(keyb_mode) write_string("Alternate mode",59,18,125,0xB800);
  191. else write_string("Default mode",59,18,121,0xB800);
  192. //Initialize windowing code
  193. if(window_cpp_entry()) {
  194. write_string("OUT OF MEMORY",19,22,124,0xB800);
  195. errors=1;
  196. }
  197. //Initialize mouse handler (from now on must hide/show it)
  198. if(!no_mouse) {
  199. m_init();
  200. m_hide();
  201. }
  202. if(no_mouse) write_string("Forced off",59,19,125,0xB800);
  203. else if(driver_activated) write_string("Ok",59,19,121,0xB800);
  204. else write_string("No mouse found",59,19,124,0xB800);
  205. //Initialize character edit code and character set
  206. if(ec_i) {
  207. write_string("OUT OF MEMORY",19,22,124,0xB800);
  208. errors=1;
  209. }
  210. //Install new timer ISR
  211. install_timer();
  212. //Allocate misc. memory
  213. t1=0;//Set to 1 for error
  214. board_list=(char far *)farmalloc(NUM_BOARDS*BOARD_NAME_SIZE);
  215. if(board_list==NULL) t1=1;
  216. board_offsets=(bOffset far *)farmalloc(NUM_BOARDS*sizeof(bOffset));
  217. if(board_offsets==NULL) t1=1;
  218. board_sizes=(unsigned long far *)farmalloc(NUM_BOARDS*4);
  219. if(board_sizes==NULL) t1=1;
  220. board_filenames=(char far *)farmalloc(NUM_BOARDS*FILENAME_SIZE);
  221. if(board_filenames==NULL) t1=1;
  222. level_id=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  223. if(level_id==NULL) t1=1;
  224. level_color=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  225. if(level_color==NULL) t1=1;
  226. level_param=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  227. if(level_param==NULL) t1=1;
  228. level_under_id=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  229. if(level_under_id==NULL) t1=1;
  230. level_under_color=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  231. if(level_under_color==NULL) t1=1;
  232. level_under_param=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  233. if(level_under_param==NULL) t1=1;
  234. overlay=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  235. if(overlay==NULL) t1=1;
  236. overlay_color=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  237. if(overlay_color==NULL) t1=1;
  238. update_done=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
  239. if(update_done==NULL) t1=1;
  240. //Allocate one more for global robot
  241. robots=(Robot far *)farmalloc((NUM_ROBOTS+1)*sizeof(Robot));
  242. if(robots==NULL) t1=1;
  243. scrolls=(Scroll far *)farmalloc(NUM_SCROLLS*sizeof(Scroll));
  244. if(scrolls==NULL) t1=1;
  245. counters=(Counter far *)farmalloc(NUM_COUNTERS*sizeof(Counter));
  246. if(counters==NULL) t1=1;
  247. sensors=(Sensor far *)farmalloc(NUM_SENSORS*sizeof(Sensor));
  248. if(sensors==NULL) t1=1;
  249. if(init_robot_mem()) t1=1;
  250. board_setup();
  251. if(sfx_init()) t1=1;
  252. if(t1) {
  253. write_string("OUT OF MEMORY",19,22,124,0xB800);
  254. errors=1;
  255. }
  256. //Initialize blink code, mod code, random number generator, and keyboard
  257. blink_off();
  258. random_seed();
  259. install_i09();
  260. installceh();
  261. //Write up free memory (below 100 shown as bad)
  262. itoa(t1=(int)(farcoreleft()>>10),temp,10);
  263. temp[str_len(temp)+1]=0;
  264. temp[str_len(temp)]='k';
  265. if(t1>=100) write_string(temp,19,21,121,0xB800);
  266. else write_string(temp,19,21,124,0xB800);
  267. //Give error message if appropriate (including if free Kb below 20)
  268. if((errors)||(t1<20)) {
  269. draw_window_box(3,9,76,11,0xB800,76,64,70,0);
  270. write_string("Out of memory error- Please increase available core/EMS memory",
  271. 9,10,79,0xB800);
  272. getkey();
  273. goto escape;
  274. }
  275. else {
  276. write_string("Ok",19,22,121,0xB800);
  277. //Configuration time
  278. //Note- music_device is from 0 to 6 at all times.
  279. //Mixing rate is 0 1 or 2, and converted to kHz before game is
  280. //started.
  281. //Search for .CFG file
  282. if(!load_config_file()) {
  283. //Loaded- display and verify
  284. save_config_file();//Update Port/IRQ/DMA
  285. write_string("Current configuration-",3,5,127,0xB800);
  286. write_string("Device for digitized music and sound:",5,6,122,0xB800);
  287. if((music_device>0)&&(music_device<6)) {
  288. write_string("Sound quality for digitized output:",7,7,122,0xB800);
  289. write_string(music_quality[mixing_rate],43,7,123,0xB800);
  290. }
  291. if((music_device>0)&&(music_device<6)) {
  292. write_string("Number of digitized sfx channels:",9,8,122,0xB800);
  293. draw_char('0'+sfx_channels,123,43,8,0xB800);
  294. }
  295. write_string("PC speaker sound effects:",17,9,122,0xB800);
  296. if(music_device==6) write_string("Gravis Ultra-Sound (no sfx)",43,6,123,0xB800);
  297. else write_string(music_devices[music_device],43,6,123,0xB800);
  298. if(sfx_on) write_string("On",43,9,123,0xB800);
  299. else write_string("Off",43,9,123,0xB800);
  300. //Port/IRQ/DMA-
  301. if(Addr==0xFFFF) write_string("Autodetect",59,20,121,0xB800);
  302. else {
  303. itoa(Addr,temp,16);
  304. temp[str_len(temp)+1]=0;
  305. temp[str_len(temp)]='h';
  306. write_string(temp,59,20,125,0xB800);
  307. }
  308. if(IRQ==0xFF) write_string("Autodetect",59,21,121,0xB800);
  309. else {
  310. itoa(IRQ,temp,10);
  311. write_string(temp,59,21,125,0xB800);
  312. }
  313. if(DMA==0xFF) write_string("Autodetect",59,22,121,0xB800);
  314. else {
  315. itoa(DMA,temp,10);
  316. write_string(temp,59,22,125,0xB800);
  317. }
  318. write_string("Press C to configure, ESC to exit, or any other key to continue.",
  319. 3,10,127,0xB800);
  320. rekey:
  321. t1=getkey();
  322. if(t1==27) goto escape;
  323. if(t1==0) goto rekey;
  324. if((t1!='c')&&(t1!='C')) goto maingame;
  325. if(!new_settings) {
  326. Addr=0xFFFF;
  327. IRQ=DMA=0xFF;
  328. write_string("Autodetect",59,20,121,0xB800);
  329. write_string("Autodetect",59,21,121,0xB800);
  330. write_string("Autodetect",59,22,121,0xB800);
  331. }
  332. }
  333. else {
  334. first_time=1;
  335. write_string("Autodetect",59,20,121,0xB800);
  336. write_string("Autodetect",59,21,121,0xB800);
  337. write_string("Autodetect",59,22,121,0xB800);
  338. }
  339. //Configure
  340. //Digitized output device
  341. draw_window_box(2,4,77,16,0xB800,120,127,113,0);
  342. write_string("Devices for digitized music and sound-",3,5,127,0xB800);
  343. for(t1=0;t1<(NUM_DEVICES/2+1);t1++) {
  344. draw_char('A'+t1,127,5,6+t1,0xB800);
  345. draw_char(')',127,6,6+t1,0xB800);
  346. write_string(music_devices[t1],8,6+t1,125,0xB800);
  347. }
  348. for(;t1<NUM_DEVICES;t1++) {
  349. draw_char('A'+t1,127,40,6+t1-NUM_DEVICES/2-1,0xB800);
  350. draw_char(')',127,41,6+t1-NUM_DEVICES/2-1,0xB800);
  351. write_string(music_devices[t1],43,6+t1-NUM_DEVICES/2-1,125,0xB800);
  352. }
  353. write_string(music_devices[NUM_DEVICES],43,9,125,0xB800);
  354. write_string("Choose an output device or press ESC to exit.",3,13,127,
  355. 0xB800);
  356. do {
  357. t1=getkey();
  358. if((t1>='a')&&(t1<='z')) t1-=32;
  359. } while((t1!=27)&&((t1<'A')||(t1>'G')));
  360. if(t1==27) goto escape;
  361. music_device=t1-'A';
  362. //Mixing rate
  363. if(music_device==0) mixing_rate=0;
  364. else if(music_device==6) mixing_rate=2;
  365. else {
  366. draw_window_box(2,4,77,16,0xB800,120,127,113,0);
  367. write_string("Choose music quality (higher quality requires more processor power)",3,5,127,0xB800);
  368. for(t1=0;t1<3;t1++) {
  369. draw_char('A'+t1,127,5,6+t1,0xB800);
  370. draw_char(')',127,6,6+t1,0xB800);
  371. write_string(music_quality[t1],8,6+t1,125,0xB800);
  372. }
  373. write_string("Choose a music quality or press ESC to exit.",3,15,127,
  374. 0xB800);
  375. do {
  376. t1=getkey();
  377. if((t1>='a')&&(t1<='z')) t1-=32;
  378. } while((t1!=27)&&((t1<'A')||(t1>'C')));
  379. if(t1==27) goto escape;
  380. mixing_rate=t1-'A';
  381. }
  382. //Sfx channels
  383. if((music_device==0)||(music_device==6)) sfx_channels=0;
  384. else {
  385. draw_window_box(2,4,77,16,0xB800,120,127,113,0);
  386. write_string("Choose number of digitized sound effect channels-",3,5,
  387. 127,0xB800);
  388. write_string("1, 2, 3, or 4, or ESC to exit.",3,7,127,0xB800);
  389. write_string("(higher requires more memory and is slower)",3,8,125,0xB800);
  390. do {
  391. t1=getkey();
  392. } while((t1!=27)&&((t1<'1')||(t1>'4')));
  393. if(t1==27) goto escape;
  394. sfx_channels=t1-'0';
  395. }
  396. //Sound effects
  397. draw_window_box(2,4,77,16,0xB800,120,127,113,0);
  398. write_string("PC speaker sound effects-",3,5,127,0xB800);
  399. write_string("Press 1 for On, 2 for Off, or ESC to exit.",3,7,127,
  400. 0xB800);
  401. do {
  402. t1=getkey();
  403. } while((t1!=27)&&(t1!='1')&&(t1!='2'));
  404. if(t1==27) goto escape;
  405. sfx_on='2'-t1;
  406. //Done
  407. save_config_file();
  408. }
  409. maingame:
  410. mixing_rate=mixing_rates[music_device][mixing_rate];
  411. if(music_device==0) music_on=0;
  412. else music_on=1;
  413. vquick_fadeout();
  414. clear_screen(1824,0xB800);
  415. //Init mod code
  416. mod_init();
  417. //First time help
  418. if(first_time) {
  419. default_palette();
  420. insta_fadein();
  421. context=71;
  422. help_system();
  423. insta_fadeout();
  424. }
  425. context=72;
  426. //Run main game (mouse is hidden and palette is faded)
  427. title_screen();
  428. update_config_file();//Save speed setting
  429. mod_exit();
  430. escape:
  431. music_device=0;//To prevent errors in accessing end_mod()
  432. vquick_fadeout();
  433. //Deallocate miscellaneous memory items
  434. sfx_exit();
  435. clear_world();
  436. exit_robot_mem();
  437. if(board_list!=NULL) farfree(board_list);
  438. if(board_offsets!=NULL) farfree(board_offsets);
  439. if(board_sizes!=NULL) farfree(board_sizes);
  440. if(board_filenames!=NULL) farfree(board_filenames);
  441. if(level_id!=NULL) farfree(level_id);
  442. if(level_color!=NULL) farfree(level_color);
  443. if(level_param!=NULL) farfree(level_param);
  444. if(level_under_id!=NULL) farfree(level_under_id);
  445. if(level_under_color!=NULL) farfree(level_under_color);
  446. if(level_under_param!=NULL) farfree(level_under_param);
  447. if(overlay!=NULL) farfree(overlay);
  448. if(overlay_color!=NULL) farfree(overlay_color);
  449. if(update_done!=NULL) farfree(update_done);
  450. if(robots!=NULL) farfree(robots);
  451. if(scrolls!=NULL) farfree(scrolls);
  452. if(counters!=NULL) farfree(counters);
  453. if(sensors!=NULL) farfree(sensors);
  454. //Uninstall systems in reverse order
  455. uninstall_i09();
  456. blink_on();
  457. clear_sfx_queue();
  458. uninstall_timer();
  459. m_deinit();
  460. window_cpp_exit();
  461. ec_exit();
  462. clear_screen(1824,0xB800);
  463. page_flip(0);
  464. init_palette();
  465. if((vga_avail)||((force_ega)&&(card>=VGAm))) vga_16p_mode();
  466. cursor_underline();
  467. asm push ds
  468. #ifdef UNREG
  469. asm mov dx,SEG unreg_exit_mesg
  470. asm mov ds,dx
  471. asm lds dx,ds:unreg_exit_mesg
  472. #else
  473. asm mov dx,SEG reg_exit_mesg
  474. asm mov ds,dx
  475. asm lds dx,ds:reg_exit_mesg
  476. #endif
  477. asm mov ah,9
  478. asm int 21h
  479. asm pop ds
  480. profiling_summary();
  481. //ERRORLEVEL
  482. return ret;
  483. }
  484. #pragma warn +par
  485. char scan_options(void) {
  486. int t1,t2;
  487. char help=0;//Set to 1 for beep+help, 2 for help
  488. //Scan the command line options and adjust global variables accordingly.
  489. //Returns non-0 if need to exit.
  490. if(_argc>1) {
  491. for(t1=1;t1<_argc;t1++) {
  492. if((_argv[t1][0]!='-')&&(_argv[t1][0]!='+')&&
  493. (_argv[t1][0]!='/')) {
  494. help=1;
  495. break;
  496. }
  497. str_lwr(_argv[t1]);
  498. //Figure it out...
  499. if(!str_cmp(&_argv[t1][1],"?")) help=2;
  500. else if(!str_cmp(&_argv[t1][1],"nomouse")) no_mouse=1;
  501. else if(!str_cmp(&_argv[t1][1],"noems")) no_ems=1;
  502. else if(!str_cmp(&_argv[t1][1],"ega")) force_ega=1;
  503. else if(!str_cmp(&_argv[t1][1],"keyb2")) keyb_mode=1;
  504. //Cheat mode- use a - followed by an ALT-254.
  505. else if(((unsigned char)_argv[t1][1])==254) cheats_active++;
  506. else if(_argv[t1][1]=='l') {
  507. //Set "current" file to string after 'l'
  508. if(str_len(&_argv[t1][2])<FILENAME_SIZE) {//Only if short enough
  509. str_cpy(curr_file,&_argv[t1][2]);
  510. add_ext(curr_file,".MZX");
  511. }
  512. }
  513. else {
  514. //Check for variable arguments for sound card port/irq/dma
  515. t2=_argv[t1][5];
  516. _argv[t1][5]=0;
  517. if(!str_cmp(&_argv[t1][1],"port")) {
  518. _argv[t1][5]=t2;
  519. //Set port
  520. Addr=strtol(&_argv[t1][5],NULL,16);
  521. new_settings=1;
  522. }
  523. else {
  524. _argv[t1][5]=t2;
  525. t2=_argv[t1][4];
  526. _argv[t1][4]=0;
  527. if(!str_cmp(&_argv[t1][1],"irq")) {
  528. _argv[t1][4]=t2;
  529. //Set IRQ
  530. IRQ=strtol(&_argv[t1][4],NULL,10);
  531. new_settings=1;
  532. }
  533. else if(!str_cmp(&_argv[t1][1],"dma")) {
  534. _argv[t1][4]=t2;
  535. //Set DMA
  536. DMA=strtol(&_argv[t1][4],NULL,10);
  537. new_settings=1;
  538. }
  539. else {
  540. help=1;
  541. break;
  542. }
  543. }
  544. }
  545. }
  546. }
  547. if(help) {
  548. if(help==1) puts("\a");
  549. else puts("");
  550. puts("MZXRun version 2.68\tCommand line parameters-\n");
  551. puts(" -? Help with parameters.");
  552. puts("-nomouse Don't use mouse, even if found.");
  553. puts(" -noems Don't use EMS memory, even if available. (NOT RECOMMENDED)");
  554. puts(" -ega Use EGA mode even if VGA or better found.");
  555. puts(" -keyb2 Use the alternate keyboard handler; Try this if the keyboard acts");
  556. puts("\t strange within the game or keys come out as if you are holding the");
  557. puts("\t Ctrl, Shift, or Alt key down, when you aren't.");
  558. puts("-l[file] Loads the world [file] up when starting MegaZeux. Do not include the");
  559. puts("\t [ or ]. You do not have to include the extension.\n");
  560. puts("Sound card settings- (see your sound card manual for details)");
  561. puts("These are only needed if autodetection fails. They are saved in the");
  562. puts("configuration file (MEGAZEUX.CFG) until you 'C'hange your configuration.\n");
  563. puts("-port230 Use base port 230h (substitute 240h, 250h, etc.)");
  564. puts(" -irq5 Use IRQ 5 (substitute 3, 4, etc.)");
  565. puts(" -dma3 Use DMA 3 (substitute 4, 5, etc.)");
  566. return 1;
  567. }
  568. return 0;
  569. }
  570. //Configuration file- MEGAZEUX.CFG.
  571. //Simple file containing music device (byte), mixing rate (word), and
  572. //whether sound is on. (byte)
  573. char load_config_file(void) {//Returns non-0 if not found
  574. int t1;
  575. FILE *fp;
  576. fp=fopen(config_file,"rb");
  577. if(fp==NULL) return 1;
  578. t1=fgetc(fp);
  579. if((t1!=126)&&(t1!=127)) {
  580. //old file- load overall_speed and return "no config file"
  581. fgetc(fp);
  582. fgetc(fp);
  583. fgetc(fp);
  584. overall_speed=fgetc(fp);
  585. if((overall_speed>9)||(overall_speed<1)) overall_speed=4;
  586. fclose(fp);
  587. return 1;
  588. }
  589. music_device=fgetc(fp);
  590. fread(&mixing_rate,2,1,fp);
  591. sfx_on=fgetc(fp);
  592. overall_speed=fgetc(fp);
  593. sfx_channels=fgetc(fp);
  594. if((overall_speed>9)||(overall_speed<1)) overall_speed=4;
  595. if(Addr==0xFFFF) fread(&Addr,2,1,fp);
  596. else fseek(fp,2,SEEK_CUR);
  597. if(DMA==0xFF) fread(&DMA,2,1,fp);
  598. else fseek(fp,2,SEEK_CUR);
  599. if(IRQ==0xFF) fread(&IRQ,2,1,fp);
  600. if(t1==126) {
  601. music_gvol=fgetc(fp);
  602. sound_gvol=fgetc(fp);
  603. }
  604. fclose(fp);
  605. return 0;
  606. }
  607. void save_config_file(void) {//Saves the .CFG file
  608. FILE *fp;
  609. fp=fopen(config_file,"wb");
  610. if(fp==NULL) return;
  611. fputc(126,fp);//Code to signify version 2.50 config file
  612. fputc(music_device,fp);
  613. fwrite(&mixing_rate,2,1,fp);
  614. fputc(sfx_on,fp);
  615. fputc(overall_speed,fp);
  616. fputc(sfx_channels,fp);
  617. fwrite(&Addr,2,1,fp);
  618. fwrite(&DMA,2,1,fp);
  619. fwrite(&IRQ,2,1,fp);
  620. fputc(music_gvol,fp);
  621. fputc(sound_gvol,fp);
  622. fclose(fp);
  623. }
  624. void update_config_file(void) {//Updates the speed setting in the .CFG file
  625. FILE *fp;
  626. fp=fopen(config_file,"rb+");
  627. if(fp==NULL) return;
  628. fseek(fp,5,SEEK_SET);
  629. fputc(overall_speed,fp);
  630. fseek(fp,7,SEEK_CUR);
  631. fputc(music_gvol,fp);
  632. fputc(sound_gvol,fp);
  633. fclose(fp);
  634. }