DOS and Win now use the new command line parser. Fixed some warnings. Removed some garbage.

This commit is contained in:
n-a-c-h
2005-04-04 00:14:15 +00:00
parent 51e64bc96a
commit 3e535ba1e9
7 changed files with 52 additions and 1289 deletions

View File

@@ -1,3 +1,25 @@
/*
Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
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.
*/
#ifndef MEMTABLE_H
#define MEMTABLE_H

View File

@@ -1,425 +0,0 @@
/*
Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
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.
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
int pccmdline(void);
extern void zstart(void);
extern void DosExit(void);
extern void ConvertJoyMap1(void);
extern void ConvertJoyMap2(void);
extern void displayparams(void);
extern void makeextension(void);
extern unsigned char Palette0, SPC700sh, OffBy1Line, DSPDisable,
MMXSupport, Force8b, ForcePal, GUIClick, MouseDis,
MusicRelVol, ScreenScale, SoundQuality,
StereoSound, V8Mode, antienab, cvidmode, debugdisble,
debugger, enterpress, finterleave, frameskip,
gammalevel, guioff, per2exec, pl1contrl, pl2contrl,
romtype, scanlines, showallext, smallscreenon, soundon,
spcon, vsyncon, DisplayS, fname, filefound, SnowOn,
Triplebufen;
// FIX STATMAT
extern unsigned char autoloadstate;
// FIX STATMAT
void ccmdline(void);
char *ers[] =
{
"Frame Skip must be a value of 0 to 9!\n",
"Gamma Correction Level must be a value of 0 to 15!\n",
"Sound Sampling Rate must be a value of 0 to 6!\n",
"Invalid Video Mode!\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",
"Volume must be a number from 0 to 100!\n"
};
int argc;
char **argv;
int main(int margc, char **margv)
{
argc=margc;
argv=margv;
zstart();
return(0);
}
int my_atoi(char *nptr)
{
int p,c;
c=0;
for(p=0;nptr[p];p++)
{
if( !isdigit(nptr[p]) ) c+=1;
}
if(c) return -1;
else return atoi(nptr);
}
void ccmdline(void)
{
int p=0;
p=pccmdline();
if(p == 0) return;
if(p == 9)
{
displayparams();
}
if(p == 4)
{
// printf("Mangled command line, did you forget a parm?\n");
printf("Invalid Commandline!\n");
DosExit();
}
if((p > 9) && (p < 17))
{
printf(ers[p-10]);
DosExit();
}
if(p == 2)
{
DosExit();
}
printf("cmdline returned %i\n",p);
DosExit();
}
int pccmdline(void)
{
int p;
int gfnm=0;
for(p=1;p<argc;p++)
{
/*
printf("(%i/%i): %s\n",p,argc,argv[p]);
*/
if((argv[p][0] == '-') || (argv[p][0] == '/'))
{
int hasroom=0;
int pp=1;
int cp=p;
int nn='_';
for(pp=1;argv[cp][pp];pp++)
{
if( (p+1) < argc) hasroom=1;
nn=tolower(argv[cp][pp+1]);
switch(tolower(argv[cp][pp]))
{
case '1': /* Player 1 Input */
{
if(!hasroom) return 4;
pl1contrl=my_atoi(argv[p+1]);
if(pl1contrl > 6) return 15;
p++;
ConvertJoyMap1();
break;
}
case '2': /* Player 2 Input */
{
if(!hasroom) return 4;
pl2contrl=my_atoi(argv[p+1]);
if(pl2contrl > 6) return 15;
p++;
ConvertJoyMap2();
break;
}
case '3':
{
vsyncon=0;
Triplebufen=1;
p++;
break;
}
case 'f':
{
if(!hasroom) return 4;
frameskip=my_atoi(argv[p+1]);
if(frameskip > 9) return 10;
frameskip++;
p++;
break;
}
case 'g':
{
if(!hasroom) return 4;
gammalevel=my_atoi(argv[p+1]);
if(gammalevel > 15) return 11;
p++;
break;
}
case 'p':
{
if(!hasroom) return 4;
per2exec=my_atoi(argv[p+1]);
if(per2exec > 150) return 14;
if(per2exec < 50) return 14;
p++;
break;
}
case 'r':
{
if(!hasroom) return 4;
SoundQuality=my_atoi(argv[p+1]);
if(SoundQuality > 6) return 12;
p++;
break;
}
case 'v':
{
if(nn == '8')
{
V8Mode=1;
pp++;
}
else
{
if(!hasroom) return 4;
cvidmode=my_atoi(argv[p+1]);
if(cvidmode > 14) return 13;
p++;
}
break;
}
case 'k':
{
if(!hasroom) return 4;
MusicRelVol=my_atoi(argv[p+1]);
if(MusicRelVol > 100) return 16;
p++;
break;
}
case '8':
{
Force8b=1;
break;
}
case '0': /* Palette 0 disable */
{
Palette0=1;
break;
}
case '7': /* SPC700 speed hack disable */
{
SPC700sh=1;
break;
}
case '9': /* Off by 1 line */
{
OffBy1Line=1;
break;
}
case 'e':
{
enterpress=1;
break;
}
case 'h':
{
romtype=2;
break;
}
case 'l':
{
romtype=1;
break;
}
case 'm':
{
guioff=1; /* disables GUI */
break;
}
case 'n':
{
if(!hasroom) return 4;
scanlines=my_atoi(argv[p+1]);
p++;
break;
}
case 's':
{
if(nn == 'p')
{
DisplayS=1;
pp++;
}
else
if(nn == 'a')
{
showallext=1;
pp++;
}
else
if(nn == 'n')
{
SnowOn=1;
pp++;
}
else
{
spcon=1;
soundon=1;
}
break;
}
case 't':
{
ForcePal=1;
break;
}
case 'u':
{
ForcePal=2;
break;
}
case 'w':
{
Triplebufen=0;
vsyncon=1;
break;
}
case 'z':
{
// FIX STATMAT
if(nn == 's')
{
if(!hasroom) return 4;
autoloadstate=my_atoi(argv[p+1]) + 1;
p++;
}
else StereoSound=0;
// FIX STATMAT
break;
}
case 'd':
{
if(nn == 'd')
{
DSPDisable=1;
pp++;
}
else
{
debugger=1;
debugdisble=0;
}
break;
}
case 'c':
{
if(nn == 'c')
{
smallscreenon=1;
pp++;
}
else
{
ScreenScale=1;
}
break;
}
case 'y':
{
antienab=1;
break;
}
case 'o':
{
if(nn == 'm')
{
MMXSupport=1;
pp++;
}
else
{
MMXSupport=0;
}
break;
}
case 'i':
{
finterleave=1;
break;
}
case 'j':
{
GUIClick=0;
MouseDis=1;
break;
}
case '?':
{
return 9;
}
}
}
}
else
{
if(gfnm > 0)
{
printf("Limit yourself to one filename\n");
return 2;
}
else
{
char *fvar;
fvar=&fname;
fvar[0] = strlen(argv[p]);
strncpy(&fvar[1],argv[p],127);
gfnm++;
}
}
}
if(gfnm == 1)
{
filefound=0;
makeextension();
}
return 0;
}

View File

@@ -28,6 +28,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#else
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/stat.h>
#define DIR_SLASH "\\"
@@ -1936,7 +1937,6 @@ void SetAddressingModes(), GenerateBank0Table();
void SetAddressingModesSA1(), GenerateBank0TableSA1();
void InitDSP(), InitDSP2(), InitDSP4(), InitFxTables(), initregr(), initregw();
void SPC7110Load();
void rep_stosd(void (**fptrarray)(), void (*fptr), unsigned int);
void CheckROMTypeC()
{

View File

@@ -170,7 +170,7 @@ WINVIDOBJ=${VIDEODIR}/sw_draw${OE} ${VIDEODIR}/hq2x16${OE} ${VIDEODIR}/hq2x32${O
#only used on Win32
WINOBJ=${WINDIR}/copyvwin${OE} ${DRESOBJ}\
${WINDIR}/winintrf${OE} ${WINDIR}/winlink${OE} ${WINDIR}/zloaderw${OE}\
${WINDIR}/winintrf${OE} ${WINDIR}/winlink${OE}\
${WINDIR}/zipxw${OE} ${WINDIR}/zfilew${OE}
NETOBJ=${NETDIR}/ztcp${OE}
@@ -187,7 +187,7 @@ JMAOBJ=${JMADIR}/7zlzma${OE} ${JMADIR}/crc32${OE} ${JMADIR}/iiostrm${OE}\
${JMADIR}/winout${OE} ${JMADIR}/zsnesjma${OE}
MAINOBJ=cfgload${OE} endmem${OE} init${OE} initc${OE} uic${OE} patch${OE}\
ui${OE} vcache${OE} version${OE} zmovie${OE} zstate${OE}
ui${OE} vcache${OE} version${OE} zmovie${OE} zstate${OE} zloader${OE}
DOSOBJORIG=${DOSDIR}/debug${OE} ${DOSDIR}/joy${OE} ${DOSDIR}/modemrtn${OE} ${DOSDIR}/vesa2${OE}\
${DOSDIR}/initvid${OE} ${DOSDIR}/sw${OE} ${DOSDIR}/gppro${OE} ${DOSDIR}/vesa12${OE}\
@@ -197,7 +197,7 @@ DOSOBJORIG=${DOSDIR}/debug${OE} ${DOSDIR}/joy${OE} ${DOSDIR}/modemrtn${OE} ${DOS
OBJSORIG=${CHIPSOBJ} ${CPUOBJ} ${GUIOBJ} ${VIDEOBJ} ${MAINOBJ} ${ZIPOBJ} ${EFFECTSOBJ} ${JMAOBJ}
ifeq (${OS},__MSDOS__)
DOSOBJ=${DOSOBJORIG} ${DOSDIR}/dosintrf${OE} ${DOSDIR}/sound${OE} ${DOSDIR}/zloader${OE} ${DOSDIR}/zfile${OE}
DOSOBJ=${DOSOBJORIG} ${DOSDIR}/dosintrf${OE} ${DOSDIR}/sound${OE} ${DOSDIR}/zfile${OE}
OBJS=${OBJSORIG} ${DOSOBJ} ${PREOBJ}
DELETEOBJS=${OBJSORIG} ${DOSOBJ}
endif
@@ -256,6 +256,7 @@ patch${OE}: $<
endmem${OE}: $< macros.mac
zmovie${OE}: $< gblvars.h
zstate${OE}: $< gblvars.h
zloader${OE}: $<
${CPUDIR}/execute${OE}: $< macros.mac
${CPUDIR}/table${OE}: $< ${CPUDIR}/65816d.inc ${CPUDIR}/address.inc ${CPUDIR}/addrni.inc ${CPUDIR}/e65816.inc\
@@ -356,7 +357,6 @@ ${WINDIR}/copyvwin${OE}: $< macros.mac
${WINDIR}/winintrf${OE}: $< macros.mac
${WINDIR}/zfilew${OE}: $<
${WINDIR}/zipxw${OE}: $<
${WINDIR}/zloaderw${OE}: $<
ifeq (${ENV},msvc)
${WINDIR}/zsnes.res: ${WINDIR}/zsnes.rc
rc ${WINDIR}/zsnes.rc

View File

@@ -829,7 +829,7 @@ NEWSYM tparms
je .yesgui
cmp byte[fname],0
jne .yesgui
jmp displayparams
jmp DosExit
.yesgui
mov byte[romloadskip],1
@@ -843,125 +843,6 @@ SECTION .data
.waitkey db 'Press Any Key to Continue.',0
.ret db 13,10,0
SECTION .text
NEWSYM displayparams
mov edx,.noparams ;use extended
call PrintStr
%ifndef __LINUX__
call WaitForKey
%endif
mov edx,.noparms2 ;use extended
call PrintStr
%ifndef __LINUX__
call WaitForKey
%endif
mov edx,.noparms3 ;use extended
call PrintStr
jmp DosExit
; yes it sucks, i had to change the one character options to have at least two characters
; that way i could distinguish from the other two character options that share the same
; first letter...only way getopt works correctly :|
; EvilTypeGuy
SECTION .data
%ifdef __LINUX__
.noparams db 'Usage : zsnes [-d,-f #, ... ] <filename.smc>',13,10
db ' Eg : zsnes -s -r 2 game.smc',13,10,13,10
%else
.noparams db 'Usage : ZSNES [-d,-f #, ... ] <filename.SMC>',13,10
db ' Eg : ZSNES -s -r 2 game.smc',13,10,13,10
%endif
db ' -0 Disable Color 0 modification in 8-bit modes',13,10
db ' -1 #/-2 # Select Player 1/2 Input :',13,10
db ' 0 = None 1 = Keyboard 2 = Joystick 3 = Gamepad',13,10
db ' 4 = 4Button 5 = 6Button 6 = Sidewinder ',13,10
db ' -7 Disable SPC700 speedhack',13,10
db ' -8 Force 8-bit sound',13,10
db ' -9 Off by 1 line fix',13,10
db ' -a Enable automatic frame rate',13,10
%ifdef __LINUX__
db ' -cs Enable full/wide screen (when available)',13,10
%else
db ' -c Enable full screen (when available)',13,10
%endif
db ' -cb Remove Background Color in 256 color video modes',13,10
db ' -cc Enable small screen (when available)',13,10
; debugger not available in linux version
; because of bios interrupt code
%ifndef __LINUX__
db ' -d Start with debugger enabled',13,10
%endif
db ' -dd Disable sound DSP emulation',13,10
%ifndef __LINUX__
;db ' -e Skip enter key press at the beginning',13,10
%endif
db ' -f # Enable fixed frame rate [0...9]',13,10
%ifndef __LINUX__
db ' -g # Specify gamma correction value [0...15]',13,10
db ' (Only works properly in 8-bit modes)',13,10
%endif
db ' -h Force HiROM',13,10
db ' -i Uninterleave ROM Image',13,10
db ' -j Disable Mouse (Automatically turns off right mouse click)',13,10
db ' -k # Set Volume Level (0 .. 100)',13,10
db 'Press any key to continue.',0
.noparms2 db 13,' -l Force LoROM ',13,10
db ' -m Disable GUI (Must specify ROM filename)',13,10
%ifdef __LINUX__
db ' -n Enable full scanlines (when available)',13,10
%else
db ' -n # Enable scanlines (when available)',13,10
db ' Where # is: 1 = full, 2 = 25%, 3 = 50%',13,10
%endif
db ' -om Enable MMX support (when available)',13,10
db ' -p # Percentage of instructions to execute [50..120]',13,10
db ' -r # Set Sampling Sound Blaster Sampling Rate & Bit :',13,10
db ' 0 = 8000Hz 1 = 11025Hz 2 = 22050Hz 3 = 44100Hz',13,10
db ' 4 = 16000Hz 5 = 32000Hz',13,10
%ifdef __LINUX__
db ' -se Enable SPC700/DSP emulation (Sound)',13,10
%else
db ' -s Enable SPC700/DSP emulation (Sound)',13,10
%endif
db ' -sa Show all extensions in GUI (*.*)',13,10
db ' -sn Enable Snowy GUI Background',13,10
db ' -t Force NTSC timing',13,10
db ' -u Force PAL timing',13,10
%ifndef __LINUX__
db ' -v # Select Video Mode :',13,10
db ' 0 = 256x224x8B (MODEQ) 1 = 256x240x8B (MODEQ)',13,10
db ' 2 = 256x256x8B (MODEQ) 3 = 320x224x8B (MODEX)',13,10
db ' 4 = 320x240x8B (MODEX) 5 = 320x256x8B (MODEX)',13,10
db ' 6 = 640x480x16B (VESA1) 7 = 320x240x8B (VESA2)',13,10
db ' 8 = 320x240x16B (VESA2) 9 = 320x480x8B (VESA2)',13,10
db ' 10 = 320x480x16B (VESA2) 11 = 512x384x8B (VESA2)',13,10
db ' 12 = 512x384x16B (VESA2) 13 = 640x400x8B (VESA2)',13,10
db ' 14 = 640x400x16B (VESA2) 15 = 640x480x8B (VESA2)',13,10
db ' 16 = 640x480x16B (VESA2) 17 = 800x600x8B (VESA2)',13,10
db ' 18 = 800x600x16B (VESA2)',13,10
%endif
db ' -w Enable vsync (disables triple buffering)',13,10
db 'Press any key to continue.',0
.noparms3 db 13,' -y Enable EAGLE (640x480x8B only) or Interpolation (640x480x16B only)',13,10
%ifdef __MSDOS__
db ' -3 Enable triple buffering (disables vsync)',13,10
%endif
db ' -z Disable Stereo Sound',13,10
; FIX STATMAT
%ifdef __WIN32__
db ' -zs # Auto load specified save state slot on startup ',13,10
; FIX STATMAT
%endif
db '',13,10
db ' File Formats Supported by GUI : .SMC,.SFC,.SWC,.FIG,.MGD,.UFO,.BIN,',13,10
db ' .058,.078,.1,.USA,.EUR,.JAP',13,10
%ifdef __MSDOS__
db '',13,10
db ' Microsoft-style options (/option) are also accepted',13,10
%endif
db '',13,10,0
SECTION .text
%ifndef __LINUX__

View File

@@ -1,735 +0,0 @@
/*
Copyright (C) 1997-2005 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
http://www.zsnes.com
http://sourceforge.net/projects/zsnes
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.
*/
#include <windows.h>
#include <stdio.h>
#include <ctype.h>
#include <direct.h>
#include <winuser.h>
extern void ImportDirectX(void);
extern void zstart(void);
extern void DosExit(void);
extern void ConvertJoyMap1(void);
extern void ConvertJoyMap2(void);
extern void displayparams(void);
extern void makeextension(void);
extern unsigned char KitchenSync;
extern unsigned char Force60hz;
int pccmdline(void);
extern unsigned char Palette0, SPC700sh, OffBy1Line, DSPDisable,
MMXSupport, Force8b, ForcePal, GUIClick, MouseDis,
MusicRelVol, ScreenScale, SoundQuality,
StereoSound, V8Mode, antienab, cvidmode, debugdisble,
debugger, enterpress, finterleave, frameskip,
gammalevel, guioff, per2exec, pl1contrl, pl2contrl,
romtype, scanlines, showallext, smallscreenon, soundon,
spcon, vsyncon, DisplayS, fname, filefound, SnowOn,
NetChatFirst,NetServer,NetNewNick,
NetFilename,CmdLineTCPIPAddress,NetQuitAfter,UDPConfig,
CmdLineNetPlay;
// FIX STATMAT
extern unsigned char autoloadstate;
// FIX STATMAT
void ccmdline(void);
char *ers[] =
{
"Frame Skip must be a value of 0 to 9!\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",
"Invalid Video Mode!\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",
"Volume must be a number from 0 to 100!\n"
};
int argc;
char **argv;
char ucase(char ch){
if ((ch>='a') && (ch<='z')) ch-='a'-'A';
return(ch);
}
extern HINSTANCE hInst;
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
int longueur;
char path_buffer[_MAX_PATH], drive[_MAX_DRIVE] ,dir[_MAX_DIR];
char fname2[_MAX_FNAME],ext[_MAX_EXT], File[_MAX_PATH];
//MK: Unused 2003/08/31
//DWORD dwRead;
char * strp;
// START FIX - STATMAT - 22/01/02
/* REMOVED
int nofile;
REMOVED */
char *endquote_pos = NULL;
// END FIX - STATMAT - 22/01/02
char ExtA[4][512];
int charptr,strptr,strcharptr,dquotes;
int i,j;
hInst=hInstance;
ImportDirectX();
// Commandline: /ABCDE <nickname> <fname> <IP Addy>
// nickname = user nickname
// fname = filename w/ full path (if L) or path name (if C)
// <IP Addy> = IP Address (Client Only)
// A = U (UDP - Recommended if works), T (TCP/IP)
// B = S (Server), C (Client)
// C = C (Chat first), L (load game first)
// D = N (Stay in ZSNESw after disconnect), Q (Quit after disconnect)
// E = # of connections (Keep it 2 for now)
// eg: ZSNESW /UCCN2 nickname d:\snesroms 202.36.124.28
strptr=0;
charptr=0;
while (szCmdLine[charptr]!=0){
while (szCmdLine[charptr]==' ') charptr++;
dquotes=0;
if (szCmdLine[charptr]=='"'){
dquotes=1;
charptr++;
}
strcharptr=0;
while (((szCmdLine[charptr]!=' ') || (dquotes)) && (szCmdLine[charptr]!=0)) {
if (szCmdLine[charptr]=='"'){
dquotes=0;
} else {
if (strptr<4){
ExtA[strptr][strcharptr]=szCmdLine[charptr];
if (strcharptr<511)
strcharptr++;
}
}
charptr++;
}
ExtA[strptr][strcharptr]=0;
if (strcharptr) strptr++;
charptr++;
}
NetServer=0;
NetChatFirst=0;
NetQuitAfter=0;
//nofile=0;
if ((strptr>2) && (ExtA[0][0]=='/') && (strlen(ExtA[0])>=5)){
//nofile=1;
if (ucase(ExtA[0][1])=='T') UDPConfig=0;
if (ucase(ExtA[0][2])=='S') NetServer=1;
if (ucase(ExtA[0][2])=='C') NetServer=2;
if (ucase(ExtA[0][3])=='C') NetChatFirst=0;
if (ucase(ExtA[0][3])=='L') NetChatFirst=1;
if (ucase(ExtA[0][4])=='N') NetQuitAfter=0;
if (ucase(ExtA[0][4])=='Q') NetQuitAfter=1;
strp=&NetNewNick;
i=0; j=0;
while (ExtA[1][i]!=0){
switch (ExtA[1][i]){
case '_':
case '-':
case '^':
case '=':
case '+':
case '[':
case ']':
if (j<10){
strp[j]=ExtA[1][i];
j++;
}
break;
default:
if (((ucase(ExtA[1][i])>='A') && (ucase(ExtA[1][i])<='Z'))
|| ((ExtA[1][i]>='0') && (ExtA[1][i]<='9'))){
if (j<10){
strp[j]=ExtA[1][i];
j++;
}
}
break;
}
i++;
}
strp[j]=0;
strp=&NetFilename;
strncpy(strp,ExtA[2],512);
strp[511]=0;
if (NetServer==2){
if (strptr<4) {
NetServer=0;
} else {
CmdLineNetPlay = 1;
strp=&CmdLineTCPIPAddress;
strncpy(strp,ExtA[3],28);
}
}
}
GetModuleFileName(NULL,path_buffer,sizeof(path_buffer));
_splitpath( path_buffer, drive, dir, fname2, ext );
_chdrive(drive[0]-'A'+1);
chdir(dir+1);
argc=0;
longueur=strlen(szCmdLine);
// START FIX - STATMAT - 22/01/02
//if((longueur!=0) && (!nofile))
if(longueur != 0)
{
argv = (char **) calloc(1, sizeof(char *));
argv[0] = (char *) calloc(1, strlen(fname2) + strlen(ext) + 1);
sprintf(argv[0], "%s%s\0", fname2, ext);
strp = strtok(szCmdLine, " ");
argc = 1;
while(strp)
{
argv = (char **) realloc(argv, (argc + 1) * sizeof(char *));
// The parameter is in quotes ("")
if(*strp == '"')
{
// Skip the opening quote
strp++;
endquote_pos = strchr(strp, '"');
// There were no spaces in between the quotes
// so we know strptr contains the entire string
if(endquote_pos)
{
// Get rid of the closing quote
*endquote_pos = '\0';
argv[argc] = (char *) calloc(1, strlen(strp) + 1);
strcpy(argv[argc], strp);
argc++;
}
// There are spaces inbetween the quotes
else
{
// Make sure it's not just a single quote
// on the end of the param string
if(strp + (strlen(strp) + 1) <= szCmdLine + longueur)
{
endquote_pos = strchr(strp + (strlen(strp) + 1), '"');
}
if(endquote_pos)
{
argv[argc] = (char *) calloc(1, (endquote_pos - strp) + 2);
strcpy(argv[argc], strp);
i = 0;
strp = strtok(NULL, " ");
while(strp)
{
// We've got another opening quote
// before a closing one?
if(*strp == '"')
{
strp++;
argv[argc] = (char *) realloc(argv[argc],
strlen(argv[argc]) + strlen(strp) + 2);
i = 1;
}
else if(strp[strlen(strp) - 1] == '"')
{
// Get rid of the closing quote
strp[strlen(strp) - 1] = '\0';
i = 1;
}
if(*strp)
{
strcat(argv[argc], " ");
strcat(argv[argc], strp);
}
if(i) break;
strp = strtok(NULL, " ");
}
argc++;
}
else
{
// Mangled parameter - don't use?
}
}
}
// Netplay parameters
else if(*strp == '/' && strlen(strp) >= 5)
{
i = j = strptr = 0;
do
{
strp++;
strptr++;
if(*strp == '"')
{
j = !j;
}
else if(*strp == ' ' && !j)
{
i++;
}
}
while(i < 3 && strp < szCmdLine + longueur);
// Just blank the params with spaces,
// as they are no longer needed
memset(strp - strptr, 32, strptr);
}
else
{
argv[argc] = (char *) calloc(1, strlen(strp) + 1);
strcpy(argv[argc], strp);
argc++;
}
// Remove any remaining quotes from the parameter
if(argv[argc - 1] && strchr(argv[argc - 1], '"'))
{
strptr = i = 0;
memset(File, 0, sizeof(File));
do
{
if(argv[argc - 1][strptr] != '"')
{
// Just hijack File string buffer
File[i] = argv[argc - 1][strptr];
i++;
}
strptr++;
}
while(argv[argc - 1][strptr]);
sprintf(argv[argc - 1], "%s\0", File);
}
strp = strtok(NULL, " ");
}
// Put one last null pointer onto the end of the argv array
argv = (char **) realloc(argv, (argc + 1) * sizeof(char *));
argv[argc] = NULL;
}
zstart();
if(argc)
{
// Free up our created argv array
// use argc + 1 to allow for our terminating null pointer
for(strptr = 0 ; strptr < (argc + 1) ; strptr++)
{
free(argv[strptr]);
}
free(argv);
}
// END FIX - STATMAT - 22/01/02
return(0);
}
int my_atoi(char *nptr)
{
int p,c;
c=0;
for(p=0;nptr[p];p++)
{
if( !isdigit(nptr[p]) ) c+=1;
}
if(c) return -1;
else return atoi(nptr);
}
void ccmdline(void)
{
int p=0;
p=pccmdline();
if(p == 0) return;
if(p == 9)
{
displayparams();
}
if(p == 4)
{
// printf("Mangled command line, did you forget a parm?\n");
printf("Invalid Commandline!\n");
DosExit();
}
if((p > 9) && (p < 17))
{
printf(ers[p-10]);
DosExit();
}
if(p == 2)
{
DosExit();
}
printf("cmdline returned %i\n",p);
DosExit();
}
int pccmdline(void)
{
int p;
int gfnm=0;
for(p=1;p<argc;p++)
{
/*
printf("(%i/%i): %s\n",p,argc,argv[p]);
*/
if(argv[p][0] == '-')
{
int hasroom=0;
int pp=1;
int cp=p;
int nn='_';
for(pp=1;argv[cp][pp];pp++)
{
if( (p+1) < argc) hasroom=1;
nn=tolower(argv[cp][pp+1]);
switch(tolower(argv[cp][pp]))
{
case '1': /* Player 1 Input */
{
if(!hasroom) return 4;
pl1contrl=my_atoi(argv[p+1]);
if(pl1contrl > 6) return 15;
p++;
ConvertJoyMap1();
break;
}
case '2': /* Player 2 Input */
{
if(!hasroom) return 4;
pl2contrl=my_atoi(argv[p+1]);
if(pl2contrl > 6) return 15;
p++;
ConvertJoyMap2();
break;
}
case 'f':
{
if(!hasroom) return 4;
frameskip=my_atoi(argv[p+1]);
if(frameskip > 9) return 10;
frameskip++;
p++;
break;
}
case 'g':
{
if(!hasroom) return 4;
gammalevel=my_atoi(argv[p+1]);
if(gammalevel > 5) return 11;
p++;
break;
}
case 'p':
{
if(!hasroom) return 4;
per2exec=my_atoi(argv[p+1]);
if(per2exec > 150) return 14;
if(per2exec < 50) return 14;
p++;
break;
}
case 'r':
{
if(!hasroom) return 4;
SoundQuality=my_atoi(argv[p+1]);
if(SoundQuality > 6) return 12;
p++;
break;
}
case 'v':
{
if(nn == '8')
{
V8Mode=1;
pp++;
}
else
{
if(!hasroom) return 4;
cvidmode=my_atoi(argv[p+1]);
if(cvidmode > 10) return 13;
p++;
}
break;
}
case 'k':
{
if(!hasroom) return 4;
MusicRelVol=my_atoi(argv[p+1]);
if(MusicRelVol > 100) return 16;
p++;
break;
}
case '8':
{
Force8b=1;
break;
}
case '0': /* Palette 0 disable */
{
Palette0=1;
break;
}
case '7': /* SPC700 speed hack disable */
{
SPC700sh=1;
break;
}
case '9': /* Off by 1 line */
{
OffBy1Line=1;
break;
}
case 'e':
{
enterpress=1;
break;
}
case 'h':
{
romtype=2;
break;
}
case 'l':
{
romtype=1;
break;
}
case 'm':
{
guioff=1; /* disables GUI */
break;
}
case 'n':
{
scanlines=1;
break;
}
case 's':
{
if(nn == 'p')
{
DisplayS=1;
pp++;
}
else
if(nn == 'a')
{
showallext=1;
pp++;
}
else
if(nn == 'n')
{
SnowOn=1;
pp++;
}
else
{
spcon=1;
soundon=1;
}
break;
}
case 't':
{
ForcePal=1;
break;
}
case 'u':
{
ForcePal=2;
break;
}
case 'w':
{
vsyncon=1;
break;
}
case 'z':
{
// FIX STATMAT
if(nn == 's')
{
if(!hasroom) return 4;
autoloadstate=my_atoi(argv[p+1]) + 1;
p++;
}
else StereoSound=0;
// FIX STATMAT
break;
}
case 'd':
{
if(nn == 'd')
{
DSPDisable=1;
pp++;
}
else
{
debugger=1;
debugdisble=0;
}
break;
}
case 'c':
{
if(nn == 'c')
{
smallscreenon=1;
pp++;
}
else
{
ScreenScale=1;
}
break;
}
case 'y':
{
antienab=1;
break;
}
case 'o':
{
if(nn == 'm')
{
MMXSupport=1;
pp++;
}
else
{
MMXSupport=0;
}
break;
}
case 'i':
{
finterleave=1;
break;
}
case 'j':
{
GUIClick=0;
MouseDis=1;
break;
}
case 'K':
{
KitchenSync=1;
break;
}
case '6':
{
Force60hz=1;
break;
}
case '?':
{
return 9;
}
}
}
}
else
{
if(gfnm > 0) // Quick fix to allow spaces, might produce strange names
// if there are unrecognized options
{
char *fvar, *fvar2;
fvar=&fname;
fvar2=&fname+fvar[0]+1;
if(fvar[0]+3>127) return(2);
fvar2[0]=' ';
strncpy(&fvar2[1],argv[p],127-fvar[0]-1);
fvar[0] += strlen(argv[p])+1;
gfnm++;
}
else
{
char *fvar;
fvar=&fname;
fvar[0] = strlen(argv[p]);
strncpy(&fvar[1],argv[p],127);
gfnm++;
}
}
}
if(gfnm > 0)
{
filefound=0;
makeextension();
}
return 0;
}

View File

@@ -27,6 +27,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#define DIR_SLASH '\\'
#ifdef __WIN32__
#include <windows.h>
@@ -39,6 +41,8 @@ extern unsigned char NetChatFirst, NetServer, NetNewNick, NetFilename[512], CmdL
#endif
#ifdef __WIN32__
void ImportDirectX();
extern unsigned char KitchenSync, Force60hz;
#endif
@@ -180,7 +184,7 @@ static size_t zatoi(const char *str)
return((size_t)atoi(orig_str));
}
static void handle_params(int argc, const char **argv)
static void handle_params(int argc, char *argv[])
{
int i;
@@ -530,11 +534,20 @@ static void handle_params(int argc, const char **argv)
}
}
int argc;
char **argv;
void ccmdline()
{
handle_params(argc, argv);
}
#ifdef __WIN32__
extern HINSTANCE hInst;
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
handle_params(__argc, __argv);
argc = __argc;
argv = __argv;
hInst=hInstance;
ImportDirectX();
@@ -542,10 +555,17 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
zstart();
return(0);
}
#else
int main(int argc, const char **argv)
int main(int zargc, char *zargv[])
{
handle_params(argc, argv);
argc = zargc;
argv = zargv;
#ifdef __LINUX__
handle_params(zargc, zargv);
#endif
zstart();
return(0);