123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- /* $Id$
- * MegaZeux
- *
- * Copyright (C) 1996 Greg Janson
- * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
- * Copyright (C) 1999 Charles Goetzman
- * Copyright (C) 2002 B.D.A. (Koji) - Koji_Takeo@worldmailer.com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
- //This source code should be 8086 compatible
- #pragma option -2-
- #pragma option -1-
- #include "beep.h"
- #include "profile.h"
- #include "ceh.h"
- #include "helpsys.h"
- #include "sfx.h"
- #include "random.h"
- #include "edit.h"
- #include "ezboard.h"
- #include "roballoc.h"
- #include <setjmp.h>
- #include <dir.h>
- #include "blink.h"
- #include "timer.h"
- #include "egacode.h"
- #include "meminter.h"
- #include "string.h"
- #include "arrowkey.h"
- #include "comp_chk.h"
- #include "dt_data.h"
- #include "graphics.h"
- #include "cursor.h"
- #include "window.h"
- #include "palette.h"
- #include "getkey.h"
- #include "ems.h"
- #include <stdlib.h>
- #include "main.h"
- #include <dos.h>
- #include <stdio.h>
- #include "detect.h"
- #include "data.h"
- #include "mod.h"
- #include "game.h"
- #include "error.h"
- #include <time.h>
- #define SAVE_INDIVIDUAL
- //new_settings=1 if Addr IRQ or DMA was updated via CMD line so we
- //should keep them even if config is entered
- char force_ega=0,no_mouse=0,no_ems=0,new_settings=0;
- jmp_buf exit_jump;//Used in error function and nowhere else
- extern unsigned int Addr,IRQ,DMA;//Sound card parameters (-1=detect)
- #ifdef UNREG
- char *unreg_exit_mesg=
- "This message should not be displayed, it is a bug, if it is.";
- #else
- char *reg_exit_mesg=
- "Thank you for playing MegaZeux.\n\r"
- "Read the files help.txt, megazeux.doc and readme.1st if you need help.\n\n\r"
- "Contributors to MZX:\n\r"
- "MZX 1.0-2.51 base code:\n\r"
- " Greg Janson - everything\n\r"
- "MZX spider s1-s3.1 series contributers:\n\r"
- " Charles Goetzman - mzx s1 base and misc. code\n\r"
- " MenTaLguY - anti-flicker code, mouse buffering, mod \"*\"\n\r"
- " Ben Zeigler - under bug fix and getting the thing to run\n\r"
- "MadBrain - MZX s3.2 (BIMSG, etc.)\n\r"
- "Akwende - MZXAK 1.0 basecode and misc. code\n\r"
- "MZX 2.6:\n\r"
- " Koji - New functions, real distance, etc.\n\r"
- " Exophase - New functions, debugging, etc.\n\r"
- " Inmate2993 - Use all 16 bits of a counter.\n\r"
- "MZX 2.61:\n\r"
- " Koji - Bug fixes and etc.\n\r"
- "MZX 2.62:\n\r"
- " Exophase - Strings, Mod_order, etc.\n\r"
- "\nhttp://www.digitalmzx.net/ for MZX source and binary distributions.\n\r$";
- #endif
- #pragma warn -par
- int main(int argc,char **argv) {
- //Temp var for number->string conversion
- char temp[7];
- //Set to 1 if any errors occur during startup
- char errors=0;
- //Used to save result of early ec_init() call
- char ec_i=0;
- //Temporary variables
- int t1;
- //Return code
- int ret=0;
- //Set if we need first time help
- char first_time=0;
- //Jump destination for exiting to DOS
- if(setjmp(exit_jump)) {//Exiting to DOS
- mod_exit();
- ret=3;
- goto escape;
- }
- //First thing- check for card and processor
- if(computer_check()) return 1;
- //Scan command line options, exit if need be
- if(scan_options()) return 2;
- if(force_ega) vga_avail=0;
- //Now- Page 0
- page_flip(0);
- //Init palette system and fade out
- init_palette();
- vquick_fadeout();
- //Setup directory strings
- //Get megazeux directory
- str_cpy(help_file,argv[0]);
- //Chop at last backslash
- for(t1=str_len(help_file);t1>=0;t1--)
- if(help_file[t1]=='\\') break;
- help_file[t1+1]=0;
- //Copy to config_file and MSE_file and blank_mod_file and convert_mod_file
- str_cpy(config_file,help_file);
- str_cpy(MSE_file,help_file);
- str_cpy(mzx_blank_mod_file,help_file);
- str_cpy(mzx_convert_mod_file,help_file);
- //Caton filenames
- str_cat(config_file,"megazeux.cfg");
- str_cat(help_file,"mzx_help.fil");
- //Get current directory and drive (form- C:\DIR\SUBDIR)
- getcwd(current_dir,PATHNAME_SIZE);
- str_cpy(megazeux_dir,current_dir);
- megazeux_drive=current_drive=getdisk();
- //Disable smzx mode
- //Switch to EGA 14 point mode and turn off cursor
- ega_14p_mode();
- cursor_off();
- //Init ec code and load up default set NOW to avoid seeing the
- //line characters shift. Save status of call for later.
- ec_i=ec_init();
- //These lines prevent a white flash onscreen
- init_palette();
- insta_fadeout();
- //Display Megazeux startup screen
- draw_window_box(0,0,79,24,0xB800,127,120,113,0);
- draw_window_box(2,1,77,3,0xB800,120,127,113,0);
- draw_window_box(2,4,77,16,0xB800,120,127,113,0);
- draw_window_box(2,17,77,23,0xB800,120,127,113,0);
- write_string("MegaZeux version 2.62",27,2,127,0xB800);
- // #ifdef BETA
- write_string("Beta - Distribute me please!",27,17,127,0xB800);
- // #endif
- #ifdef GAMMA
- write_string("GAMMA- MAY CONTAIN BUGz!",27,17,127,0xB800);
- #endif
- #ifdef UNREG
- write_string("Unregistered Evaluation Copy",25,0,122,0xB800);
- #endif
- write_string("Graphics card:",4,18,122,0xB800);
- write_string("EMS available:",4,20,122,0xB800);
- write_string("Core mem free:",4,21,122,0xB800);
- write_string("Memory allocs:",4,22,122,0xB800);
- write_string("Keyboard handler:",41,18,122,0xB800);
- write_string("Mouse handler:",44,19,122,0xB800);
- write_string("Sound card port:",42,20,122,0xB800);
- write_string("Sound card IRQ:",43,21,122,0xB800);
- write_string("Sound card DMA:",43,22,122,0xB800);
- // I restored the original startup palette... - Exo
- set_rgb(1,31,31,31);
- set_rgb(6,63,0,0);
- set_rgb(7,21,21,21);
- set_rgb(8,8,8,8);
- set_rgb(9,42,42,63);
- set_rgb(10,42,63,42);
- set_rgb(11,42,63,63);
- set_rgb(12,63,42,42);
- set_rgb(13,63,42,63);
- //Fix palette to be nicer.
- //Not if I can help it!
- //the random palettes are uglier
- //than sin! Couldn't find the original
- //so I'll just use the default -Koji
- /* randomize();
- switch(random(100)%4)
- {
- case(0):
- set_rgb(1,31,0,0);
- set_rgb(6,53,0,0);
- set_rgb(7,21,0,0);
- set_rgb(8,11,0,0);
- set_rgb(9,63,63,0);
- set_rgb(10,63,31,0);
- set_rgb(11,63,21,21);
- set_rgb(12,63,42,42);
- set_rgb(13,63,42,21);
- set_rgb(15,63,0,0);
- break;
- case(1):
- set_rgb(1,46,29,31); //CORNER
- set_rgb(6,50,33,35); //BACKGROUN
- set_rgb(7,55,38,40); //MID Edge
- set_rgb(8,41,24,26); //DARK Edge
- set_rgb(9,63,46,48); //ACTIVE Text
- set_rgb(10,41,24,26); //STATIC Text
- set_rgb(11,55,36,39); //SELECTION Text
- set_rgb(12,51,34,38); //
- set_rgb(13,63,46,48); //
- set_rgb(15,63,46,48); //LIGHT EDGE
- break;
- case(2):
- set_rgb(1,0,31,0);
- set_rgb(6,0,53,0);
- set_rgb(7,0,21,0);
- set_rgb(8,0,11,0);
- set_rgb(9,0,63,63);
- set_rgb(10,0,63,31);
- set_rgb(11,21,63,21);
- set_rgb(12,42,63,42);
- set_rgb(13,21,63,42);
- set_rgb(15,0,63,0);
- break;
- case(3):
- set_rgb(1,0,0,31);
- set_rgb(6,0,0,53);
- set_rgb(7,0,0,21);
- set_rgb(8,0,0,11);
- set_rgb(9,0,63,63);
- set_rgb(10,0,31,63);
- set_rgb(11,21,21,63);
- set_rgb(12,42,42,63);
- set_rgb(13,21,42,63);
- set_rgb(15,0,0,63);
- break;
- }*/
- //Fade in
- vquick_fadein();
- //Initialize systems and display progess at bottom
- //First, show graphics card and processor
- if(force_ega) write_string("EGA (command line)",19,18,125,0xB800);
- else write_string(gcard_strs[card-3],19,18,121,0xB800);
- //Initialize EMS systems
- if(no_ems) write_string("Forced off",19,20,125,0xB800);
- else if(setup_EMS()) write_string("None",19,20,124,0xB800);
- else {
- itoa(free_mem_EMS()*16,temp,10);
- temp[str_len(temp)+1]=0;
- temp[str_len(temp)]='k';
- if(free_mem_EMS()>=64) write_string(temp,19,20,121,0xB800);
- else write_string(temp,19,20,124,0xB800);
- }
- //Write up keyboard mode
- if(keyb_mode) write_string("Alternate mode",59,18,125,0xB800);
- else write_string("Default mode",59,18,121,0xB800);
- //Initialize windowing code
- if(window_cpp_entry()) {
- write_string("OUT OF MEMORY",19,22,124,0xB800);
- errors=1;
- }
- //Initialize mouse handler (from now on must hide/show it)
- if(!no_mouse) {
- m_init();
- m_hide();
- }
- if(no_mouse) write_string("Forced off",59,19,125,0xB800);
- else if(driver_activated) write_string("Ok",59,19,121,0xB800);
- else write_string("No mouse found",59,19,124,0xB800);
- //Initialize character edit code and character set
- if(ec_i) {
- write_string("OUT OF MEMORY",19,22,124,0xB800);
- errors=1;
- }
- //Install new timer ISR
- install_timer();
- //Allocate misc. memory
- t1=0;//Set to 1 for error
- board_list=(char far *)farmalloc(NUM_BOARDS*BOARD_NAME_SIZE);
- if(board_list==NULL) t1=1;
- board_offsets=(bOffset far *)farmalloc(NUM_BOARDS*sizeof(bOffset));
- if(board_offsets==NULL) t1=1;
- board_sizes=(unsigned long far *)farmalloc(NUM_BOARDS*4);
- if(board_sizes==NULL) t1=1;
- board_filenames=(char far *)farmalloc(NUM_BOARDS*FILENAME_SIZE);
- if(board_filenames==NULL) t1=1;
- level_id=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(level_id==NULL) t1=1;
- level_color=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(level_color==NULL) t1=1;
- level_param=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(level_param==NULL) t1=1;
- level_under_id=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(level_under_id==NULL) t1=1;
- level_under_color=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(level_under_color==NULL) t1=1;
- level_under_param=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(level_under_param==NULL) t1=1;
- overlay=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(overlay==NULL) t1=1;
- overlay_color=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(overlay_color==NULL) t1=1;
- update_done=(unsigned char far *)farmalloc(MAX_ARRAY_X*MAX_ARRAY_Y);
- if(update_done==NULL) t1=1;
- //Allocate one more for global robot
- robots=(Robot far *)farmalloc((NUM_ROBOTS+1)*sizeof(Robot));
- if(robots==NULL) t1=1;
- scrolls=(Scroll far *)farmalloc(NUM_SCROLLS*sizeof(Scroll));
- if(scrolls==NULL) t1=1;
- counters=(Counter far *)farmalloc(NUM_COUNTERS*sizeof(Counter));
- if(counters==NULL) t1=1;
- sensors=(Sensor far *)farmalloc(NUM_SENSORS*sizeof(Sensor));
- if(sensors==NULL) t1=1;
- if(init_robot_mem()) t1=1;
- board_setup();
- if(sfx_init()) t1=1;
- if(t1) {
- write_string("OUT OF MEMORY",19,22,124,0xB800);
- errors=1;
- }
- //Initialize blink code, mod code, random number generator, and keyboard
- blink_off();
- random_seed();
- install_i09();
- installceh();
- //Write up free memory (below 100 shown as bad)
- itoa(t1=(int)(farcoreleft()>>10),temp,10);
- temp[str_len(temp)+1]=0;
- temp[str_len(temp)]='k';
- if(t1>=100) write_string(temp,19,21,121,0xB800);
- else write_string(temp,19,21,124,0xB800);
- //Give error message if appropriate (including if free Kb below 20)
- if((errors)||(t1<20)) {
- draw_window_box(3,9,76,11,0xB800,76,64,70,0);
- write_string("Out of memory error- Please increase available core/EMS memory",
- 9,10,79,0xB800);
- getkey();
- goto escape;
- }
- else {
- write_string("Ok",19,22,121,0xB800);
- //Configuration time
- //Note- music_device is from 0 to 6 at all times.
- //Mixing rate is 0 1 or 2, and converted to kHz before game is
- //started.
- //Search for .CFG file
- if(!load_config_file()) {
- //Loaded- display and verify
- save_config_file();//Update Port/IRQ/DMA
- write_string("Current configuration-",3,5,127,0xB800);
- write_string("Device for digitized music and sound:",5,6,122,0xB800);
- if((music_device>0)&&(music_device<6)) {
- write_string("Sound quality for digitized output:",7,7,122,0xB800);
- write_string(music_quality[mixing_rate],43,7,123,0xB800);
- }
- if((music_device>0)&&(music_device<6)) {
- write_string("Number of digitized sfx channels:",9,8,122,0xB800);
- draw_char('0'+sfx_channels,123,43,8,0xB800);
- }
- write_string("PC speaker sound effects:",17,9,122,0xB800);
- if(music_device==6) write_string("Gravis Ultra-Sound (no sfx)",43,6,123,0xB800);
- else write_string(music_devices[music_device],43,6,123,0xB800);
- if(sfx_on) write_string("On",43,9,123,0xB800);
- else write_string("Off",43,9,123,0xB800);
- //Port/IRQ/DMA-
- if(Addr==0xFFFF) write_string("Autodetect",59,20,121,0xB800);
- else {
- itoa(Addr,temp,16);
- temp[str_len(temp)+1]=0;
- temp[str_len(temp)]='h';
- write_string(temp,59,20,125,0xB800);
- }
- if(IRQ==0xFF) write_string("Autodetect",59,21,121,0xB800);
- else {
- itoa(IRQ,temp,10);
- write_string(temp,59,21,125,0xB800);
- }
- if(DMA==0xFF) write_string("Autodetect",59,22,121,0xB800);
- else {
- itoa(DMA,temp,10);
- write_string(temp,59,22,125,0xB800);
- }
- write_string("Press C to configure, ESC to exit, or any other key to continue.",
- 3,10,127,0xB800);
- rekey:
- t1=getkey();
- if(t1==27) goto escape;
- if(t1==0) goto rekey;
- if((t1!='c')&&(t1!='C')) goto maingame;
- if(!new_settings) {
- Addr=0xFFFF;
- IRQ=DMA=0xFF;
- write_string("Autodetect",59,20,121,0xB800);
- write_string("Autodetect",59,21,121,0xB800);
- write_string("Autodetect",59,22,121,0xB800);
- }
- }
- else {
- first_time=1;
- write_string("Autodetect",59,20,121,0xB800);
- write_string("Autodetect",59,21,121,0xB800);
- write_string("Autodetect",59,22,121,0xB800);
- }
- //Configure
- //Digitized output device
- draw_window_box(2,4,77,16,0xB800,120,127,113,0);
- write_string("Devices for digitized music and sound-",3,5,127,0xB800);
- for(t1=0;t1<(NUM_DEVICES/2+1);t1++) {
- draw_char('A'+t1,127,5,6+t1,0xB800);
- draw_char(')',127,6,6+t1,0xB800);
- write_string(music_devices[t1],8,6+t1,125,0xB800);
- }
- for(;t1<NUM_DEVICES;t1++) {
- draw_char('A'+t1,127,40,6+t1-NUM_DEVICES/2-1,0xB800);
- draw_char(')',127,41,6+t1-NUM_DEVICES/2-1,0xB800);
- write_string(music_devices[t1],43,6+t1-NUM_DEVICES/2-1,125,0xB800);
- }
- write_string(music_devices[NUM_DEVICES],43,9,125,0xB800);
- write_string("Choose an output device or press ESC to exit.",3,13,127,
- 0xB800);
- do {
- t1=getkey();
- if((t1>='a')&&(t1<='z')) t1-=32;
- } while((t1!=27)&&((t1<'A')||(t1>'G')));
- if(t1==27) goto escape;
- music_device=t1-'A';
- //Mixing rate
- if(music_device==0) mixing_rate=0;
- else if(music_device==6) mixing_rate=2;
- else {
- draw_window_box(2,4,77,16,0xB800,120,127,113,0);
- write_string("Choose music quality (higher quality requires more processor power)",3,5,127,0xB800);
- for(t1=0;t1<3;t1++) {
- draw_char('A'+t1,127,5,6+t1,0xB800);
- draw_char(')',127,6,6+t1,0xB800);
- write_string(music_quality[t1],8,6+t1,125,0xB800);
- }
- write_string("Choose a music quality or press ESC to exit.",3,15,127,
- 0xB800);
- do {
- t1=getkey();
- if((t1>='a')&&(t1<='z')) t1-=32;
- } while((t1!=27)&&((t1<'A')||(t1>'C')));
- if(t1==27) goto escape;
- mixing_rate=t1-'A';
- }
- //Sfx channels
- if((music_device==0)||(music_device==6)) sfx_channels=0;
- else {
- draw_window_box(2,4,77,16,0xB800,120,127,113,0);
- write_string("Choose number of digitized sound effect channels-",3,5,
- 127,0xB800);
- write_string("1, 2, 3, or 4, or ESC to exit.",3,7,127,0xB800);
- write_string("(higher requires more memory and is slower)",3,8,125,0xB800);
- do {
- t1=getkey();
- } while((t1!=27)&&((t1<'1')||(t1>'4')));
- if(t1==27) goto escape;
- sfx_channels=t1-'0';
- }
- //Sound effects
- draw_window_box(2,4,77,16,0xB800,120,127,113,0);
- write_string("PC speaker sound effects-",3,5,127,0xB800);
- write_string("Press 1 for On, 2 for Off, or ESC to exit.",3,7,127,
- 0xB800);
- do {
- t1=getkey();
- } while((t1!=27)&&(t1!='1')&&(t1!='2'));
- if(t1==27) goto escape;
- sfx_on='2'-t1;
- //Done
- save_config_file();
- }
- maingame:
- mixing_rate=mixing_rates[music_device][mixing_rate];
- if(music_device==0) music_on=0;
- else music_on=1;
- vquick_fadeout();
- clear_screen(1824,0xB800);
- //Init mod code
- mod_init();
- //First time help
- if(first_time) {
- default_palette();
- insta_fadein();
- context=71;
- help_system();
- insta_fadeout();
- }
- context=72;
- //Run main game (mouse is hidden and palette is faded)
- title_screen();
- update_config_file();//Save speed setting
- mod_exit();
- escape:
- music_device=0;//To prevent errors in accessing end_mod()
- vquick_fadeout();
- //Deallocate miscellaneous memory items
- sfx_exit();
- clear_world();
- exit_robot_mem();
- if(board_list!=NULL) farfree(board_list);
- if(board_offsets!=NULL) farfree(board_offsets);
- if(board_sizes!=NULL) farfree(board_sizes);
- if(board_filenames!=NULL) farfree(board_filenames);
- if(level_id!=NULL) farfree(level_id);
- if(level_color!=NULL) farfree(level_color);
- if(level_param!=NULL) farfree(level_param);
- if(level_under_id!=NULL) farfree(level_under_id);
- if(level_under_color!=NULL) farfree(level_under_color);
- if(level_under_param!=NULL) farfree(level_under_param);
- if(overlay!=NULL) farfree(overlay);
- if(overlay_color!=NULL) farfree(overlay_color);
- if(update_done!=NULL) farfree(update_done);
- if(robots!=NULL) farfree(robots);
- if(scrolls!=NULL) farfree(scrolls);
- if(counters!=NULL) farfree(counters);
- if(sensors!=NULL) farfree(sensors);
- //Uninstall systems in reverse order
- uninstall_i09();
- blink_on();
- clear_sfx_queue();
- uninstall_timer();
- m_deinit();
- window_cpp_exit();
- ec_exit();
- clear_screen(1824,0xB800);
- page_flip(0);
- init_palette();
- if((vga_avail)||((force_ega)&&(card>=VGAm))) vga_16p_mode();
- cursor_underline();
- asm push ds
- #ifdef UNREG
- asm mov dx,SEG unreg_exit_mesg
- asm mov ds,dx
- asm lds dx,ds:unreg_exit_mesg
- #else
- asm mov dx,SEG reg_exit_mesg
- asm mov ds,dx
- asm lds dx,ds:reg_exit_mesg
- #endif
- asm mov ah,9
- asm int 21h
- asm pop ds
- profiling_summary();
- //ERRORLEVEL
- return ret;
- }
- #pragma warn +par
- char scan_options(void) {
- int t1,t2;
- char help=0;//Set to 1 for beep+help, 2 for help
- //Scan the command line options and adjust global variables accordingly.
- //Returns non-0 if need to exit.
- if(_argc>1) {
- for(t1=1;t1<_argc;t1++) {
- if((_argv[t1][0]!='-')&&(_argv[t1][0]!='+')&&
- (_argv[t1][0]!='/')) {
- help=1;
- break;
- }
- str_lwr(_argv[t1]);
- //Figure it out...
- if(!str_cmp(&_argv[t1][1],"?")) help=2;
- else if(!str_cmp(&_argv[t1][1],"nomouse")) no_mouse=1;
- else if(!str_cmp(&_argv[t1][1],"noems")) no_ems=1;
- else if(!str_cmp(&_argv[t1][1],"ega")) force_ega=1;
- else if(!str_cmp(&_argv[t1][1],"keyb2")) keyb_mode=1;
- //Cheat mode- use a - followed by an ALT-254.
- else if(((unsigned char)_argv[t1][1])==254) cheats_active++;
- else if(_argv[t1][1]=='l') {
- //Set "current" file to string after 'l'
- if(str_len(&_argv[t1][2])<FILENAME_SIZE) {//Only if short enough
- str_cpy(curr_file,&_argv[t1][2]);
- add_ext(curr_file,".MZX");
- }
- }
- else {
- //Check for variable arguments for sound card port/irq/dma
- t2=_argv[t1][5];
- _argv[t1][5]=0;
- if(!str_cmp(&_argv[t1][1],"port")) {
- _argv[t1][5]=t2;
- //Set port
- Addr=strtol(&_argv[t1][5],NULL,16);
- new_settings=1;
- }
- else {
- _argv[t1][5]=t2;
- t2=_argv[t1][4];
- _argv[t1][4]=0;
- if(!str_cmp(&_argv[t1][1],"irq")) {
- _argv[t1][4]=t2;
- //Set IRQ
- IRQ=strtol(&_argv[t1][4],NULL,10);
- new_settings=1;
- }
- else if(!str_cmp(&_argv[t1][1],"dma")) {
- _argv[t1][4]=t2;
- //Set DMA
- DMA=strtol(&_argv[t1][4],NULL,10);
- new_settings=1;
- }
- else {
- help=1;
- break;
- }
- }
- }
- }
- }
- if(help) {
- if(help==1) puts("\a");
- else puts("");
- puts("MegaZeux version 2.61\tCommand line parameters-\n");
- puts(" -? Help with parameters.");
- puts("-nomouse Don't use mouse, even if found.");
- puts(" -noems Don't use EMS memory, even if available. (NOT RECOMMENDED)");
- puts(" -ega Use EGA mode even if VGA or better found.");
- puts(" -keyb2 Use the alternate keyboard handler; Try this if the keyboard acts");
- puts("\t strange within the game or keys come out as if you are holding the");
- puts("\t Ctrl, Shift, or Alt key down, when you aren't.");
- puts("-l[file] Loads the world [file] up when starting MegaZeux. Do not include the");
- puts("\t [ or ]. You do not have to include the extension.\n");
- puts("Sound card settings- (see your sound card manual for details)");
- puts("These are only needed if autodetection fails. They are saved in the");
- puts("configuration file (MEGAZEUX.CFG) until you 'C'hange your configuration.\n");
- puts("-port230 Use base port 230h (substitute 240h, 250h, etc.)");
- puts(" -irq5 Use IRQ 5 (substitute 3, 4, etc.)");
- puts(" -dma3 Use DMA 3 (substitute 4, 5, etc.)");
- return 1;
- }
- return 0;
- }
- //Configuration file- MEGAZEUX.CFG.
- //Simple file containing music device (byte), mixing rate (word), and
- //whether sound is on. (byte)
- char load_config_file(void) {//Returns non-0 if not found
- int t1;
- FILE *fp;
- fp=fopen(config_file,"rb");
- if(fp==NULL) return 1;
- t1=fgetc(fp);
- if((t1!=126)&&(t1!=127)) {
- //old file- load overall_speed and return "no config file"
- fgetc(fp);
- fgetc(fp);
- fgetc(fp);
- overall_speed=fgetc(fp);
- if((overall_speed>9)||(overall_speed<1)) overall_speed=4;
- fclose(fp);
- return 1;
- }
- music_device=fgetc(fp);
- fread(&mixing_rate,2,1,fp);
- sfx_on=fgetc(fp);
- overall_speed=fgetc(fp);
- sfx_channels=fgetc(fp);
- if((overall_speed>9)||(overall_speed<1)) overall_speed=4;
- if(Addr==0xFFFF) fread(&Addr,2,1,fp);
- else fseek(fp,2,SEEK_CUR);
- if(DMA==0xFF) fread(&DMA,2,1,fp);
- else fseek(fp,2,SEEK_CUR);
- if(IRQ==0xFF) fread(&IRQ,2,1,fp);
- if(t1==126) {
- music_gvol=fgetc(fp);
- sound_gvol=fgetc(fp);
- }
- fclose(fp);
- return 0;
- }
- void save_config_file(void) {//Saves the .CFG file
- FILE *fp;
- fp=fopen(config_file,"wb");
- if(fp==NULL) return;
- fputc(126,fp);//Code to signify version 2.50 config file
- fputc(music_device,fp);
- fwrite(&mixing_rate,2,1,fp);
- fputc(sfx_on,fp);
- fputc(overall_speed,fp);
- fputc(sfx_channels,fp);
- fwrite(&Addr,2,1,fp);
- fwrite(&DMA,2,1,fp);
- fwrite(&IRQ,2,1,fp);
- fputc(music_gvol,fp);
- fputc(sound_gvol,fp);
- fclose(fp);
- }
- void update_config_file(void) {//Updates the speed setting in the .CFG file
- FILE *fp;
- fp=fopen(config_file,"rb+");
- if(fp==NULL) return;
- fseek(fp,5,SEEK_SET);
- fputc(overall_speed,fp);
- fseek(fp,7,SEEK_CUR);
- fputc(music_gvol,fp);
- fputc(sound_gvol,fp);
- fclose(fp);
- }
|