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 // just for printing some iNES info for user..
49 #include "../../fce.h"
50 #include "../../ines.h"
52 static int ntsccol=0,ntschue=-1,ntsctint=-1;
58 int srendlinev[2]={0,0};
59 //int srendlinev[2]={0,0};
60 int erendlinev[2]={239,239};
61 //int erendlinev[2]={231,239};
62 int srendline,erendline;
65 static char BaseDirectory[2048];
69 static void DriverKill(void);
70 static int DriverInitialize(void);
75 static void ParseGI(FCEUGI *gi)
79 InputType[0]=UsrInputType[0];
80 InputType[1]=UsrInputType[1];
81 InputTypeFC=UsrInputTypeFC;
84 InputType[0]=gi->input[0];
86 InputType[1]=gi->input[1];
88 InputTypeFC=gi->inputfc;
89 FCEUI_GetCurrentVidSystem(&srendline,&erendline);
92 void FCEUD_PrintError(char *s)
97 static char *cpalette=0;
98 static void LoadCPalette(void)
103 if(!(fp=fopen(cpalette,"rb")))
105 printf(" Error loading custom palette from file: %s\n",cpalette);
108 fread(tmpp,1,192,fp);
109 FCEUI_SetPaletteArray((uint8 *)tmpp);
113 static CFGSTRUCT fceuconfig[]={
126 ADDCFGSTRUCT(DriverConfig),
130 static void SaveConfig(void)
133 sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory);
134 DriverInterface(DES_GETNTSCTINT,&ntsctint);
135 DriverInterface(DES_GETNTSCHUE,&ntschue);
136 SaveFCEUConfig(tdir,fceuconfig);
139 static void LoadConfig(void)
142 sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory);
143 LoadFCEUConfig(tdir,fceuconfig);
144 if(ntsctint>=0) DriverInterface(DES_SETNTSCTINT,&ntsctint);
145 if(ntschue>=0) DriverInterface(DES_SETNTSCHUE,&ntschue);
148 static void CreateDirs(void)
150 char *subs[5]={"fcs","snaps","gameinfo","sav","cheats"};
154 mkdir(BaseDirectory,S_IRWXU);
157 sprintf(tdir,"%s"PSS"%s",BaseDirectory,subs[x]);
162 static void SetSignals(void (*t)(int))
164 int sigs[11]={SIGINT,SIGTERM,SIGHUP,SIGPIPE,SIGSEGV,SIGFPE,SIGKILL,SIGALRM,SIGABRT,SIGUSR1,SIGUSR2};
170 static void CloseStuff(int signum)
173 printf("\nSignal %d has been caught and dealt with...\n",signum);
176 case SIGINT:printf("How DARE you interrupt me!\n");break;
177 case SIGTERM:printf("MUST TERMINATE ALL HUMANS\n");break;
178 case SIGHUP:printf("Reach out and hang-up on someone.\n");break;
179 case SIGPIPE:printf("The pipe has broken! Better watch out for floods...\n");break;
180 case SIGSEGV:printf("Iyeeeeeeeee!!! A segmentation fault has occurred. Have a fluffy day.\n");break;
181 /* So much SIGBUS evil. */
184 case SIGBUS:printf("I told you to be nice to the driver.\n");break;
187 case SIGFPE:printf("Those darn floating points. Ne'er know when they'll bite!\n");break;
188 case SIGALRM:printf("Don't throw your clock at the meowing cats!\n");break;
189 case SIGABRT:printf("Abort, Retry, Ignore, Fail?\n");break;
191 case SIGUSR2:printf("Killing your processes is not nice.\n");break;
196 static void DoArgs(int argc, char *argv[])
198 static char *cortab[5]={"none","gamepad","zapper","powerpad","arkanoid"};
199 static int cortabi[5]={SI_NONE,SI_GAMEPAD,
200 SI_ZAPPER,SI_POWERPADA,SI_ARKANOID};
201 static char *fccortab[5]={"none","arkanoid","shadow","4player","fkb"};
202 static int fccortabi[5]={SIFC_NONE,SIFC_ARKANOID,SIFC_SHADOW,
203 SIFC_4PLAYER,SIFC_FKB};
206 static char *inputa[2]={0,0};
207 static char *fcexp=0;
208 static int docheckie[4];
210 static ARGPSTRUCT FCEUArgs[]={
211 {"-soundvol",0,&soundvol,0},
212 {"-cpalette",0,&cpalette,0x4001},
214 {"-ntsccol",0,&ntsccol,0},
215 {"-pal",&docheckie[0],0,0},
216 {"-input1",0,&inputa[0],0x4001},{"-input2",0,&inputa[1],0x4001},
217 {"-fcexp",0,&fcexp,0x4001},
219 {"-gg",&docheckie[1],0,0},
220 {"-no8lim",0,&eoptions,0x8001},
221 {"-subase",0,&eoptions,0x8002},
222 {"-snapname",0,&eoptions,0x8000|EO_SNAPNAME},
223 {"-nofs",0,&eoptions,0x8000|EO_NOFOURSCORE},
224 {"-clipsides",0,&eoptions,0x8000|EO_CLIPSIDES},
225 {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE},
226 {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0},
227 {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0},
228 {"-swapbuttons",&swapbuttons, 0, 0},
229 {"-showfps",&showfps, 0, 0},
230 {0,(void *)DriverArgs,0,0},
234 memset(docheckie,0,sizeof(docheckie));
235 ParseArguments(argc, argv, FCEUArgs);
246 FCEUI_SetVidSystem(1);
248 FCEUI_SetGameGenie(1);
249 FCEUI_DisableSpriteLimitation(1);
250 FCEUI_SaveExtraDataUnderBase(eoptions&2);
251 FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
255 if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0;
256 if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239;
259 printf("main() setrendered lines: %d, %d, %d, %d\n",srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
260 printf("main() clip sides %d\n", eoptions&EO_CLIPSIDES);
262 FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
263 FCEUI_SetRenderedLines(0,erendlinev[0],srendlinev[1],erendlinev[1]);
264 FCEUI_SetSoundVolume(soundvol);
265 DriverInterface(DES_NTSCCOL,&ntsccol);
273 if(!strncmp(fccortab[y],fcexp,8))
275 UsrInputTypeFC=fccortabi[y];
290 if(!strncmp(cortab[y],inputa[x],8))
292 UsrInputType[x]=cortabi[y];
295 powerpadside&=~(1<<x);
296 powerpadside|=((((inputa[x][8])-'a')&1)^1)<<x;
306 int CLImain(int argc, char *argv[])
317 if(!DriverInitialize())
322 if(!(ret=FCEUI_Initialize()))
324 GetBaseDirectory(BaseDirectory);
325 FCEUI_SetBaseDirectory(BaseDirectory);
329 DoArgs(argc-2,&argv[1]);
335 if(!(tmp=FCEUI_LoadGame(argv[argc-1])))
341 //RefreshThrottleFPS();
344 // additional print for gpfce
347 iNES_HEADER *head = iNESGetHead();
348 MapperNo = (head->ROM_type>>4);
349 MapperNo|=(head->ROM_type2&0xF0);
350 FCEU_DispMessage("%s, Mapper: %d%s%s", PAL?"PAL":"NTSC", MapperNo, (head->ROM_type&2)?", BB":"", (head->ROM_type&4)?", T":"");
360 static int DriverInitialize(void)
362 SetSignals((void *)CloseStuff);
366 if(!InitVideo()) return 0;
368 if(!InitKeyboard()) return 0;
373 static void DriverKill(void)
391 void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count)
393 if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE))
396 if(Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE))
397 WriteSound(Buffer,Count);