/** ADAMEm: Coleco ADAM emulator ********************************************/ /** **/ /** ADAMEm.c **/ /** **/ /** This file contains the main() function starting the emulator **/ /** **/ /** Copyright (C) Marcel de Kogel 1996,1997,1998,1999 **/ /** You are not allowed to distribute this software commercially **/ /** Please, notify me, if you make any changes to this file **/ /****************************************************************************/ #include #include #include #include "Coleco.h" #ifdef MSDOS #include "MSDOS.h" #include #include #endif #ifdef LINUX_SVGA #include "SVGALib.h" #endif #ifdef UNIX_X #include "X.h" #endif #include "Help.h" /* Program title for -help output */ extern char Title[]; #define MAX_CONFIG_FILE_SIZE 1024 #define MAX_FILE_NAME 256 char *Options[]= { "verbose","help","cpuspeed","ifreq", "cheat","video","sound","joystick","swapbuttons", "expansion","calibrate","overscan","volume","soundtrack", "trap","os7","sensitivity","reverb","chorus","uperiod", "soundquality","speakerchannels","keys","printer","keypad", "eos","wp","diska","diskb","diskc","diskd", "tapea","tapeb","tapec","taped","sync","adam","cv","stereo", "printertype","chipset","sprite","shm","savecpu","palette", "ram","snap","autosnap","diskspeed","tapespeed","lpt","tdos", NULL }; char *AbvOptions[]= { "vb","he","cs","if", "cheat","vi","so","js","sb", "ex","ca","os","vo","st", "trap","os7","se","re","ch","up", "sq","sc","ke","pr","kp", "eos","wp","da","db","dc","dd", "ta","tb","tc","td","sy","adam","cv","stereo", "pt","chipset","sprite","shm","savecpu","pal", "ram","sn","asn","ds","ts","lpt","tdos", NULL }; #define PROGRAM_ADAMEM 0 #define PROGRAM_CVEM 1 static int Program; static int CPUSpeed; static int _argc; static char *_argv[256]; static char MainConfigFile[MAX_CONFIG_FILE_SIZE]; static char SubConfigFile[MAX_CONFIG_FILE_SIZE]; static char szTempFileName[MAX_FILE_NAME]; static char _CartName[MAX_FILE_NAME]; static char CartNameNoExt[MAX_FILE_NAME]; static char _SnapshotName[MAX_FILE_NAME]; static char _OS7File[MAX_FILE_NAME]; static char _EOSFile[MAX_FILE_NAME]; static char _WPFile[MAX_FILE_NAME]; static char ProgramPath[MAX_FILE_NAME]; static char ProgramName[MAX_FILE_NAME]; static int CartNameSupplied=0; #ifndef MSDOS /* Get full path name, convert all backslashes to UNIX style slashes */ static void _fixpath (char *old,char *new) { strcpy (new,old); } #endif #ifdef MSDOS static void ParseSpeakerChannels (char *p) { int i,a; memset (spk_channels,0,sizeof(spk_channels)); for (i=0;i<4&&p;++i) { a=atoi(p); if (a<0 || a>4) a=0; spk_channels[i]=a; p=strchr(p,','); if (p) { *p='\0'; ++p; } } } #endif static int ParseOptions (int argc,char *argv[]) { int N,I,J,tmp; int misparm; for(N=1,I=0;N=argc) return 0; break; default: return 0; } } } return 1; } static void LoadConfigFile (char *szFileName,unsigned char *ptr) { FILE *infile; infile=fopen (szFileName,"rb"); if (infile==NULL) return; fread (ptr,1,MAX_CONFIG_FILE_SIZE,infile); fclose (infile); while (*ptr) { while (*ptr && *ptr<=' ') ++ptr; if (*ptr) { _argv[_argc++]=ptr; while (*ptr && *ptr>' ') ++ptr; if (*ptr) *ptr++='\0'; } } } static void FixFileNames (void) { char *p=NULL,*q=NULL,*x=NULL; int i; CartNameNoExt[0]='\0'; if (!CartNameSupplied) { for (i=0;i<2;++i) if (DiskName[i]) { _fixpath (DiskName[i],CartNameNoExt); break; } if (CartNameNoExt[0]=='\0') for (i=0;i<2;++i) if (TapeName[i]) { _fixpath (TapeName[i],CartNameNoExt); break; } } if (CartNameNoExt[0]=='\0') _fixpath (CartName,CartNameNoExt); p=CartNameNoExt; q=strchr(CartNameNoExt,'/'); while (q) /* get last '/' */ { p=++q; q=strchr(q,'/'); }; q=NULL; while ((p=strchr(p,'.'))!=NULL) /* get last '.' */ { q=p; ++p; } if (q) /* remove extension */ *q='\0'; p=CartName; q=strchr(CartName,'/'); if (!q) strchr(CartName,'\\'); while (q) /* get last '/' */ { p=++q; x=strchr(q,'/'); if (!x) x=strchr(q,'\\'); q=x; }; q=NULL; while ((p=strchr(p,'.'))!=NULL) /* get last '.' */ { q=p; ++p; } strcpy (_CartName,CartName); if (!q) strcat (_CartName,".rom"); CartName=_CartName; } static void FixROMPath (char **file,char *storage) { char *p=NULL,*q=NULL; if (!strchr(*file,'/') && !strchr(*file,'\\')) { /* If no path is given, assume emulator path */ strcpy (storage,ProgramPath); strcat (storage,*file); } else { _fixpath (*file,storage); } p=storage; q=strchr(storage,'/'); while (q) /* get last '/' */ { p=++q; q=strchr(q,'/'); }; q=NULL; while ((p=strchr(p,'.'))!=NULL) /* get last '.' */ { q=p; ++p; } if (!q) /* Default extension='.rom' */ strcat (storage,".rom"); *file=storage; } static void GetPath (char *szFullPath,char *szPath,char *szFile) { char *p,*q; strcpy (szPath,szFullPath); p=szPath; q=strchr(p,'/'); while (q) /* get last '/' */ { p=++q; q=strchr(q,'/'); }; if (szFile) { strcpy (szFile,p); *p='\0'; /* remove filename */ p=szFile; q=NULL; while ((p=strchr(p,'.'))!=NULL) /* get last '.' */ { q=p; ++p; } if (q) *q='\0'; /* remove extension */ } else *p='\0'; /* remove filename */ } int main (int argc,char *argv[]) { Verbose=1; CPUSpeed=100; IFreq=50; UPeriod=3; CheatCount=0; #ifdef MSDOS PrnName=LPTName="PRN"; #endif memset (MainConfigFile,0,sizeof(MainConfigFile)); memset (SubConfigFile,0,sizeof(SubConfigFile)); GetPath (argv[0],ProgramPath,ProgramName); if (!strcmp(ProgramName,"cvem") || !strcmp(ProgramName,"cvemx")) { EmuMode=0; Program=PROGRAM_CVEM; } else { EmuMode=1; Program=PROGRAM_ADAMEM; } _argc=1; _argv[0]=argv[0]; /* Load Config Files */ strcpy (szTempFileName,ProgramPath); strcat (szTempFileName,ProgramName); strcat (szTempFileName,".cfg"); strcpy (szJoystickFileName,ProgramPath); strcat (szJoystickFileName,"adamem.joy"); #ifdef SOUND strcpy (szSoundFileName,ProgramPath); strcat (szSoundFileName,"adamem.snd"); #endif LoadConfigFile (szTempFileName,MainConfigFile); if (!ParseOptions(_argc,_argv)) return 1; GetCartName (argc,argv); FixFileNames (); #if defined(MSDOS) || defined(LINUX_SVGA) strcpy (szBitmapFile,CartNameNoExt); strcat (szBitmapFile,".b00"); #endif #if defined(MSDOS) || defined(LINUX_SVGA) || defined(UNIX_X) strcpy (szSnapshotFile,CartNameNoExt); strcat (szSnapshotFile,".s00"); #endif strcpy (szTempFileName,CartNameNoExt); strcat (szTempFileName,".cfg"); _argc=1; LoadConfigFile (szTempFileName,SubConfigFile); if (!ParseOptions(_argc,_argv)) return 1; if (!ParseOptions(argc,argv)) return 1; if (SaveSnapshot && !SnapshotName) { strcpy (_SnapshotName,CartNameNoExt); strcat (_SnapshotName,".snp"); SnapshotName=_SnapshotName; } FixROMPath (&OS7File,_OS7File); FixROMPath (&EOSFile,_EOSFile); FixROMPath (&WPFile,_WPFile); if (!UPeriod) UPeriod=3; if (UPeriod>10) UPeriod=10; if (IFreq<10) IFreq=10; if (IFreq>200) IFreq=200; if (CPUSpeed>1000) CPUSpeed=1000; if (CPUSpeed<10) CPUSpeed=10; Z80_IPeriod=(3579545*CPUSpeed)/(100*1000); if (PalNum<0) PalNum=0; if (PalNum>=NR_PALETTES) PalNum=NR_PALETTES-1; #ifndef MSDOS if (!InitMachine()) return 0; #endif StartColeco(); TrashColeco(); #ifndef MSDOS TrashMachine (); #endif return 0; }