1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* This file contains or coordinates all of the code necessary to compile
22 on a UNIX system that can use svgalib, such as FreeBSD and Linux.
23 This code is not guaranteed to compile on FreeBSD, though.
28 #include <sys/types.h>
41 #include "../common/config.h"
42 #include "../common/args.h"
43 #include "../common/unixdsp.h"
44 #include "../common/cheat.h"
48 static int ntsccol=0,ntschue=-1,ntsctint=-1;
49 /*static*/ int soundvol=100;
52 int srendlinev[2]={8,0};
53 int erendlinev[2]={239,239};
54 int srendline,erendline;
57 static char BaseDirectory[2048];
61 static void DriverKill(void);
62 static int DriverInitialize(void);
67 static void ParseGI(FCEUGI *gi)
71 InputType[0]=UsrInputType[0];
72 InputType[1]=UsrInputType[1];
73 InputTypeFC=UsrInputTypeFC;
76 InputType[0]=gi->input[0];
78 InputType[1]=gi->input[1];
80 InputTypeFC=gi->inputfc;
81 FCEUI_GetCurrentVidSystem(&srendline,&erendline);
84 void FCEUD_PrintError(char *s)
89 static char *cpalette=0;
90 static void LoadCPalette(void)
95 if(!(fp=fopen(cpalette,"rb")))
97 printf(" Error loading custom palette from file: %s\n",cpalette);
100 fread(tmpp,1,192,fp);
101 FCEUI_SetPaletteArray(tmpp);
105 static CFGSTRUCT fceuconfig[]={
118 ADDCFGSTRUCT(DriverConfig),
122 static void SaveConfig(void)
125 sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory);
126 DriverInterface(DES_GETNTSCTINT,&ntsctint);
127 DriverInterface(DES_GETNTSCHUE,&ntschue);
128 SaveFCEUConfig(tdir,fceuconfig);
131 static void LoadConfig(void)
134 sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory);
135 LoadFCEUConfig(tdir,fceuconfig);
136 if(ntsctint>=0) DriverInterface(DES_SETNTSCTINT,&ntsctint);
137 if(ntschue>=0) DriverInterface(DES_SETNTSCHUE,&ntschue);
140 static void CreateDirs(void)
142 char *subs[5]={"fcs","snaps","gameinfo","sav","cheats"};
146 mkdir(BaseDirectory,S_IRWXU);
149 sprintf(tdir,"%s"PSS"%s",BaseDirectory,subs[x]);
154 static void SetSignals(void (*t)(int))
156 int sigs[11]={SIGINT,SIGTERM,SIGHUP,SIGPIPE,SIGSEGV,SIGFPE,SIGKILL,SIGALRM,SIGABRT,SIGUSR1,SIGUSR2};
162 static void CloseStuff(int signum)
165 printf("\nSignal %d has been caught and dealt with...\n",signum);
168 case SIGINT:printf("How DARE you interrupt me!\n");break;
169 case SIGTERM:printf("MUST TERMINATE ALL HUMANS\n");break;
170 case SIGHUP:printf("Reach out and hang-up on someone.\n");break;
171 case SIGPIPE:printf("The pipe has broken! Better watch out for floods...\n");break;
172 case SIGSEGV:printf("Iyeeeeeeeee!!! A segmentation fault has occurred. Have a fluffy day.\n");break;
173 /* So much SIGBUS evil. */
176 case SIGBUS:printf("I told you to be nice to the driver.\n");break;
179 case SIGFPE:printf("Those darn floating points. Ne'er know when they'll bite!\n");break;
180 case SIGALRM:printf("Don't throw your clock at the meowing cats!\n");break;
181 case SIGABRT:printf("Abort, Retry, Ignore, Fail?\n");break;
183 case SIGUSR2:printf("Killing your processes is not nice.\n");break;
188 static void DoArgs(int argc, char *argv[])
190 static char *cortab[5]={"none","gamepad","zapper","powerpad","arkanoid"};
191 static int cortabi[5]={SI_NONE,SI_GAMEPAD,
192 SI_ZAPPER,SI_POWERPADA,SI_ARKANOID};
193 static char *fccortab[5]={"none","arkanoid","shadow","4player","fkb"};
194 static int fccortabi[5]={SIFC_NONE,SIFC_ARKANOID,SIFC_SHADOW,
195 SIFC_4PLAYER,SIFC_FKB};
198 static char *inputa[2]={0,0};
199 static char *fcexp=0;
200 static int docheckie[4];
202 static ARGPSTRUCT FCEUArgs[]={
203 {"-soundvol",0,&soundvol,0},
204 {"-cpalette",0,&cpalette,0x4001},
206 {"-ntsccol",0,&ntsccol,0},
207 {"-pal",&docheckie[0],0,0},
208 {"-input1",0,&inputa[0],0x4001},{"-input2",0,&inputa[1],0x4001},
209 {"-fcexp",0,&fcexp,0x4001},
211 {"-gg",&docheckie[1],0,0},
212 {"-no8lim",0,&eoptions,0x8001},
213 {"-subase",0,&eoptions,0x8002},
214 {"-snapname",0,&eoptions,0x8000|EO_SNAPNAME},
215 {"-nofs",0,&eoptions,0x8000|EO_NOFOURSCORE},
216 {"-clipsides",0,&eoptions,0x8000|EO_CLIPSIDES},
217 {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE},
218 {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0},
219 {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0},
220 {0,(void *)DriverArgs,0,0},
224 memset(docheckie,0,sizeof(docheckie));
225 ParseArguments(argc, argv, FCEUArgs);
236 FCEUI_SetVidSystem(1);
238 FCEUI_SetGameGenie(1);
240 FCEUI_DisableSpriteLimitation(eoptions&1);
241 FCEUI_SaveExtraDataUnderBase(eoptions&2);
242 FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
246 if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0;
247 if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239;
250 FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
251 FCEUI_SetSoundVolume(soundvol);
252 //DriverInterface(DES_NTSCCOL,&ntsccol);
260 if(!strncmp(fccortab[y],fcexp,8))
262 UsrInputTypeFC=fccortabi[y];
277 if(!strncmp(cortab[y],inputa[x],8))
279 UsrInputType[x]=cortabi[y];
282 powerpadside&=~(1<<x);
283 powerpadside|=((((inputa[x][8])-'a')&1)^1)<<x;
293 int CLImain(int argc, char *argv[])
298 if(!(ret=FCEUI_Initialize()))
300 GetBaseDirectory(BaseDirectory);
301 FCEUI_SetBaseDirectory(BaseDirectory);
310 DoArgs(argc-2,&argv[1]);
311 FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue);
317 if(!(tmp=FCEUI_LoadGame(argv[argc-1])))
323 RefreshThrottleFPS();
324 if(!DriverInitialize())
337 static int DriverInitialize(void)
339 SetSignals((void *)CloseStuff);
343 if(!InitVideo()) return 0;
345 if(!InitKeyboard()) return 0;
350 static void DriverKill(void)
368 void FCEUD_Update(uint8 *XBuf, int16 *Buffer, int Count)
370 if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE))
374 WriteSound(Buffer,Count,NoWaiting);