cleaned up some weird code and hopefully took out some ^M's

This commit is contained in:
theoddone33
2001-04-19 20:16:40 +00:00
parent b7d4597db7
commit 16826b8468

View File

@@ -1,403 +1,395 @@
/* /*
Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com ) Copyright (C) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version 2 of the License, or (at your option) any later
version. version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
------------- -------------
Initial Linux Command Line Parsing by EvilTypeGuy (drevil@warpcore.org) April 2001 Initial Linux Command Line Parsing by EvilTypeGuy (drevil@warpcore.org) April 2001
*/ */
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#define STUB_FUNCTION fprintf(stderr,"STUB: %s at " __FILE__ ", line %d, thread %d\n",__FUNCTION__,__LINE__,getpid()) #define STUB_FUNCTION fprintf(stderr,"STUB: %s at " __FILE__ ", line %d, thread %d\n",__FUNCTION__,__LINE__,getpid())
#define DWORD unsigned long #define DWORD unsigned long
#define _MAX_PATH 80 #define _MAX_PATH 80
#define _MAX_DRIVE 80 #define _MAX_DRIVE 80
#define _MAX_DIR 80 #define _MAX_DIR 80
#define _MAX_FNAME 80 #define _MAX_FNAME 80
#define _MAX_EXT 80 #define _MAX_EXT 80
extern void zstart(void); extern void zstart(void);
extern void DosExit(void); extern void DosExit(void);
extern void ConvertJoyMap1(void); extern void ConvertJoyMap1(void);
extern void ConvertJoyMap2(void); extern void ConvertJoyMap2(void);
extern void displayparams(void); extern void displayparams(void);
extern void makeextension(void); extern void makeextension(void);
extern unsigned char Palette0, SPC700sh, OffBy1Line, DSPDisable, extern unsigned char Palette0, SPC700sh, OffBy1Line, DSPDisable,
FPUCopy, Force8b, ForcePal, ForceNTSC, GUIClick, MouseDis, FPUCopy, Force8b, ForcePal, ForceNTSC, GUIClick, MouseDis,
MusicRelVol, ScreenScale, SoundCompD, SoundQuality, MusicRelVol, ScreenScale, SoundCompD, SoundQuality,
StereoSound, V8Mode, antienab, cvidmode, debugdisble, StereoSound, V8Mode, antienab, cvidmode, debugdisble,
debugger, enterpress, finterleave, frameskip, debugger, enterpress, finterleave, frameskip,
gammalevel, guioff, per2exec, pl1contrl, pl2contrl, gammalevel, guioff, per2exec, pl1contrl, pl2contrl,
romtype, scanlines, showallext, smallscreenon, soundon, romtype, scanlines, showallext, smallscreenon, soundon,
spcon, vsyncon, DisplayS, fname, filefound, SnowOn, spcon, vsyncon, DisplayS, fname, filefound, SnowOn,
NetChatFirst,NetServer,NetNewNick, NetChatFirst,NetServer,NetNewNick,
NetFilename,GUINetTextk2,NetQuitAfter,UDPConfig; NetFilename,GUINetTextk2,NetQuitAfter,UDPConfig;
int getopt(int argc, char *const argv[], const char *optstring); int getopt(int argc, char *const argv[], const char *optstring);
extern char *optarg; extern char *optarg;
extern int optind, opterr, optopt; extern int optind, opterr, optopt;
extern int BitDepth; extern int BitDepth;
void ccmdline(void); void ccmdline(void);
char *ers[] = char *ers[] =
{ {
"Frame Skip must be a value of 0 to 9!\n", "Frame Skip must be a value of 0 to 9!\n",
"Gamma Correction Level must be a value of 0 to 5!\n", "Gamma Correction Level must be a value of 0 to 5!\n",
"Sound Sampling Rate must be a value of 0 to 5!\n", "Sound Sampling Rate must be a value of 0 to 5!\n",
"Invalid Video Mode!\n", "Invalid Video Mode!\n",
"Percentage of instructions to execute must be a number from 50 to 150!\n", "Percentage of instructions to execute must be a number from 50 to 150!\n",
"Player Input must be a value from 0 to 6!\n", "Player Input must be a value from 0 to 6!\n",
"Volume must be a number from 0 to 100!\n" "Volume must be a number from 0 to 100!\n"
}; };
//int argc; //int argc;
//char **argv; //char **argv;
char ucase(char ch){ char ucase(char ch){
if ((ch>='a') && (ch<='z')) ch-='a'-'A'; if ((ch>='a') && (ch<='z')) ch-='a'-'A';
return(ch); return(ch);
} }
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
int opt,hasroom,p,pp,arg; int opt,hasroom,p,pp,arg;
char *fvar; char *fvar;
UnProtectMemory(); UnProtectMemory();
while((opt = getopt(argc, argv, "01:2:789ab:c:d:ef:g:hijk:lmno:p:r:s:tuv:wyz?")) != -1) { while((opt = getopt(argc, argv, "01:2:789ab:c:d:ef:g:hijk:lmno:p:r:s:tuv:wyz?")) != -1) {
switch(opt) { switch(opt) {
/* Palette 0 disable */ /* Palette 0 disable */
case '0': { case '0': {
Palette0 = 1; Palette0 = 1;
break; break;
} }
/* Player 1 Input */ /* Player 1 Input */
case '1': { case '1': {
if (!hasroom) return 4; if (!hasroom) return 4;
pl1contrl = my_atoi(optarg); pl1contrl = my_atoi(optarg);
if (pl1contrl > 6) return 15; if (pl1contrl > 6) return 15;
p++; p++;
ConvertJoyMap1(); ConvertJoyMap1();
break; break;
} }
/* Player 2 Input */ /* Player 2 Input */
case '2': { case '2': {
if (!hasroom) return 4; if (!hasroom) return 4;
pl2contrl=my_atoi(optarg); pl2contrl=my_atoi(optarg);
if (pl2contrl > 6) return 15; if (pl2contrl > 6) return 15;
p++; p++;
ConvertJoyMap2(); ConvertJoyMap2();
break; break;
} }
/* SPC700 speed hack disable */ /* SPC700 speed hack disable */
case '7': { case '7': {
SPC700sh = 1; SPC700sh = 1;
break; break;
} }
case '8': { case '8': {
Force8b = 1; Force8b = 1;
break; break;
} }
/* Off by 1 line */ /* Off by 1 line */
case '9': { case '9': {
OffBy1Line = 1; OffBy1Line = 1;
break; break;
} }
case 'b': { case 'b': {
// What was this? - DDOI // What was this? - DDOI
//SoundCompD = 1; //SoundCompD = 1;
if(optarg != NULL) if(optarg != NULL)
BitDepth = atoi(optarg); BitDepth = atoi(optarg);
if (BitDepth != 8 && BitDepth != 16 && if (BitDepth != 8 && BitDepth != 16 &&
BitDepth != 24 && BitDepth != 32) BitDepth != 24 && BitDepth != 32)
{ {
printf ("%d is not a valid bit depth.\n", BitDepth); printf ("%d is not a valid bit depth.\n", BitDepth);
exit(1); exit(1);
} }
break; break;
} }
case 'c': { case 'c': {
if (strcmp(optarg,"b") == 0) { if (strcmp(optarg,"b") == 0) {
printf("\nRemove background color in 256 modes not implemented!\n"); printf("\nRemove background color in 256 modes not implemented!\n");
} }
else else
if (strcmp(optarg,"c") == 0) { if (strcmp(optarg,"c") == 0) {
smallscreenon = 1; smallscreenon = 1;
pp++; pp++;
} else { } else {
ScreenScale = 1; ScreenScale = 1;
} }
break; break;
} }
case 'd': { case 'd': {
if (strcmp(optarg,"d") == 0) { if (strcmp(optarg,"d") == 0) {
DSPDisable = 1; DSPDisable = 1;
pp++; pp++;
} else { } else {
/* debugger will never work under linux, since it's full of bios interrupt calls */ /* debugger will never work under linux, since it's full of bios interrupt calls */
printf("\nDebugger not implemented for Linux version!\n"); printf("\nDebugger not implemented for Linux version!\n");
} }
break; break;
} }
case 'e': { case 'e': {
enterpress = 1; enterpress = 1;
break; break;
} }
case 'f': { case 'f': {
if (!hasroom) return 4; if (!hasroom) return 4;
frameskip = my_atoi(optarg); frameskip = my_atoi(optarg);
if (frameskip > 9) return 10; if (frameskip > 9) return 10;
p++; p++;
break; break;
} }
case 'g': { case 'g': {
if (!hasroom) return 4; if (!hasroom) return 4;
gammalevel = my_atoi(optarg); gammalevel = my_atoi(optarg);
if (gammalevel > 5) return 11; if (gammalevel > 5) return 11;
p++; p++;
break; break;
} }
case 'h': { case 'h': {
romtype = 2; romtype = 2;
break; break;
} }
case 'i': { case 'i': {
finterleave = 1; finterleave = 1;
break; break;
} }
case 'j': { case 'j': {
GUIClick = 0; GUIClick = 0;
MouseDis = 1; MouseDis = 1;
break; break;
} }
case 'k': { case 'k': {
if (!hasroom) return 4; if (!hasroom) return 4;
MusicRelVol = my_atoi(optarg); MusicRelVol = my_atoi(optarg);
if (MusicRelVol > 100) return 16; if (MusicRelVol > 100) return 16;
p++; p++;
break; break;
} }
case 'l': { case 'l': {
romtype = 1; romtype = 1;
break; break;
} }
/* disables GUI */ /* disables GUI */
case 'm': { case 'm': {
guioff = 1; guioff = 1;
break; break;
} }
case 'n': { case 'n': {
scanlines = 1; scanlines = 1;
break; break;
} }
case 'o': { case 'o': {
if (strcmp(optarg,"m") == 0) { if (strcmp(optarg,"m") == 0) {
FPUCopy = 2; FPUCopy = 2;
pp++; pp++;
} else { } else {
FPUCopy = 0; FPUCopy = 0;
} }
break; break;
} }
case 'p': { case 'p': {
if (!hasroom) return 4; if (!hasroom) return 4;
per2exec = my_atoi(optarg); per2exec = my_atoi(optarg);
if (per2exec > 150) return 14; if (per2exec > 150) return 14;
if (per2exec < 50) return 14; if (per2exec < 50) return 14;
p++; p++;
break; break;
} }
case 'r': { case 'r': {
if (!hasroom) return 4; if (!hasroom) return 4;
SoundQuality = my_atoi(optarg); SoundQuality = my_atoi(optarg);
if (SoundQuality > 5) return 12; if (SoundQuality > 5) return 12;
p++; p++;
break; break;
} }
case 's': { case 's': {
if (strcmp(optarg,"p") == 0) { if (strcmp(optarg,"p") == 0) {
DisplayS = 1; DisplayS = 1;
pp++; pp++;
} } else if (strcmp(optarg,"a") == 0) {
showallext = 1;
else pp++;
} else if (strcmp(optarg,"n") == 0) {
if (strcmp(optarg,"a") == 0) { SnowOn = 1;
showallext = 1; pp++;
pp++; } else {
} spcon = 1;
soundon = 1;
else }
break;
if (strcmp(optarg,"n") == 0) { }
SnowOn = 1;
pp++; case 't': {
} else { ForcePal = 1;
spcon = 1; break;
soundon = 1; }
}
break; case 'u': {
} ForcePal = 2;
break;
case 't': { }
ForcePal = 1;
break; case 'v': {
} if (strcmp(optarg,"8") == 0) {
V8Mode = 1;
case 'u': { pp++;
ForcePal = 2; } else {
break; if (!hasroom) return 4;
} cvidmode = my_atoi(optarg);
case 'v': { if (cvidmode > 10) return 13;
if (strcmp(optarg,"8") == 0) { p++;
V8Mode = 1; }
pp++; break;
} else { }
if (!hasroom) return 4;
cvidmode = my_atoi(optarg); case 'w': {
vsyncon = 1;
if (cvidmode > 10) return 13; break;
p++; }
}
break; case 'y': {
} antienab = 1;
break;
case 'w': { }
vsyncon = 1;
break; case 'z': {
} StereoSound = 1;
break;
case 'y': { }
antienab = 1;
break; case '?': {
} displayparams();
return 9;
case 'z': { }
StereoSound = 1; }
break; }
}
/* execute rom filename: file.x */
case '?': { if (optopt == '?')
displayparams(); {
return 9; if (argv[optind] != NULL)
} {
} fvar=&fname;
} fvar[0] = strlen(argv[optind]);
strncpy(&fvar[1], argv[optind],127);
/* execute rom filename: file.x */ makeextension();
if (optopt == '?') }
{ }
if (argv[optind] != NULL)
{ zstart();
fvar=&fname; }
fvar[0] = strlen(argv[optind]);
strncpy(&fvar[1], argv[optind],127);
makeextension(); int my_atoi(char *nptr) {
} int p,c;
}
c = 0;
zstart(); for(p = 0; nptr[p]; p++) {
} if ( !isdigit(nptr[p]) ) c += 1;
}
int my_atoi(char *nptr) { if (c) return -1;
int p,c;
else
c = 0;
for(p = 0; nptr[p]; p++) { return atoi(nptr);
if ( !isdigit(nptr[p]) ) c += 1; }
}
if (c) return -1; void ccmdline(void) {
int p = 0;
else
p = pccmdline();
return atoi(nptr); if (p == 0) return;
}
if (p == 9) {
displayparams();
void ccmdline(void) { }
int p = 0;
if (p == 4) {
p = pccmdline(); /* printf("Mangled command line, did you forget a parm?\n"); */
if (p == 0) return; printf("Invalid Commandline!\n");
DosExit();
if (p == 9) { }
displayparams();
} if ((p > 9) && (p < 17)) {
printf(ers[p-10]);
if (p == 4) { DosExit();
/* printf("Mangled command line, did you forget a parm?\n"); */ }
printf("Invalid Commandline!\n");
DosExit(); if (p == 2) {
} DosExit();
}
if ((p > 9) && (p < 17)) {
printf(ers[p-10]); printf("cmdline returned %i\n",p);
DosExit(); DosExit();
} }
if (p == 2) { int pccmdline(void) {
DosExit(); return 0;
} }
printf("cmdline returned %i\n",p);
DosExit();
}
int pccmdline(void) {
return 0;
}