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;
54 int srendlinev[2]={0,0};
55 //int srendlinev[2]={0,0};
56 int erendlinev[2]={239,239};
57 //int erendlinev[2]={231,239};
58 int srendline,erendline;
61 static char BaseDirectory[2048];
65 static void DriverKill(void);
66 static int DriverInitialize(void);
71 static void ParseGI(FCEUGI *gi)
75 InputType[0]=UsrInputType[0];
76 InputType[1]=UsrInputType[1];
77 InputTypeFC=UsrInputTypeFC;
80 InputType[0]=gi->input[0];
82 InputType[1]=gi->input[1];
84 InputTypeFC=gi->inputfc;
85 FCEUI_GetCurrentVidSystem(&srendline,&erendline);
88 void FCEUD_PrintError(char *s)
93 static char *cpalette=0;
94 static void LoadCPalette(void)
99 if(!(fp=fopen(cpalette,"rb")))
101 printf(" Error loading custom palette from file: %s\n",cpalette);
104 fread(tmpp,1,192,fp);
105 FCEUI_SetPaletteArray((uint8 *)tmpp);
109 static CFGSTRUCT fceuconfig[]={
122 ADDCFGSTRUCT(DriverConfig),
126 static void SaveConfig(void)
129 sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory);
130 DriverInterface(DES_GETNTSCTINT,&ntsctint);
131 DriverInterface(DES_GETNTSCHUE,&ntschue);
132 SaveFCEUConfig(tdir,fceuconfig);
135 static void LoadConfig(void)
138 sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory);
139 LoadFCEUConfig(tdir,fceuconfig);
140 if(ntsctint>=0) DriverInterface(DES_SETNTSCTINT,&ntsctint);
141 if(ntschue>=0) DriverInterface(DES_SETNTSCHUE,&ntschue);
144 static void CreateDirs(void)
146 char *subs[5]={"fcs","snaps","gameinfo","sav","cheats"};
150 mkdir(BaseDirectory,S_IRWXU);
153 sprintf(tdir,"%s"PSS"%s",BaseDirectory,subs[x]);
158 static void SetSignals(void (*t)(int))
160 int sigs[11]={SIGINT,SIGTERM,SIGHUP,SIGPIPE,SIGSEGV,SIGFPE,SIGKILL,SIGALRM,SIGABRT,SIGUSR1,SIGUSR2};
166 static void CloseStuff(int signum)
169 printf("\nSignal %d has been caught and dealt with...\n",signum);
172 case SIGINT:printf("How DARE you interrupt me!\n");break;
173 case SIGTERM:printf("MUST TERMINATE ALL HUMANS\n");break;
174 case SIGHUP:printf("Reach out and hang-up on someone.\n");break;
175 case SIGPIPE:printf("The pipe has broken! Better watch out for floods...\n");break;
176 case SIGSEGV:printf("Iyeeeeeeeee!!! A segmentation fault has occurred. Have a fluffy day.\n");break;
177 /* So much SIGBUS evil. */
180 case SIGBUS:printf("I told you to be nice to the driver.\n");break;
183 case SIGFPE:printf("Those darn floating points. Ne'er know when they'll bite!\n");break;
184 case SIGALRM:printf("Don't throw your clock at the meowing cats!\n");break;
185 case SIGABRT:printf("Abort, Retry, Ignore, Fail?\n");break;
187 case SIGUSR2:printf("Killing your processes is not nice.\n");break;
192 static void DoArgs(int argc, char *argv[])
194 static char *cortab[5]={"none","gamepad","zapper","powerpad","arkanoid"};
195 static int cortabi[5]={SI_NONE,SI_GAMEPAD,
196 SI_ZAPPER,SI_POWERPAD,SI_ARKANOID};
197 static char *fccortab[5]={"none","arkanoid","shadow","4player","fkb"};
198 static int fccortabi[5]={SIFC_NONE,SIFC_ARKANOID,SIFC_SHADOW,
199 SIFC_4PLAYER,SIFC_FKB};
202 static char *inputa[2]={0,0};
203 static char *fcexp=0;
204 static int docheckie[4];
206 static ARGPSTRUCT FCEUArgs[]={
207 {"-soundvol",0,&soundvol,0},
208 {"-cpalette",0,&cpalette,0x4001},
210 {"-ntsccol",0,&ntsccol,0},
211 {"-pal",&docheckie[0],0,0},
212 {"-input1",0,&inputa[0],0x4001},{"-input2",0,&inputa[1],0x4001},
213 {"-fcexp",0,&fcexp,0x4001},
215 {"-gg",&docheckie[1],0,0},
216 {"-no8lim",0,&eoptions,0x8001},
217 {"-subase",0,&eoptions,0x8002},
218 {"-snapname",0,&eoptions,0x8000|EO_SNAPNAME},
219 {"-nofs",0,&eoptions,0x8000|EO_NOFOURSCORE},
220 {"-clipsides",0,&eoptions,0x8000|EO_CLIPSIDES},
221 {"-nothrottle",0,&eoptions,0x8000|EO_NOTHROTTLE},
222 {"-slstart",0,&srendlinev[0],0},{"-slend",0,&erendlinev[0],0},
223 {"-slstartp",0,&srendlinev[1],0},{"-slendp",0,&erendlinev[1],0},
224 {"-swapbuttons",&swapbuttons, 0, 0},
225 {"-showfps",&showfps, 0, 0},
226 {0,(void *)DriverArgs,0,0},
230 memset(docheckie,0,sizeof(docheckie));
231 ParseArguments(argc, argv, FCEUArgs);
242 FCEUI_SetVidSystem(1);
244 FCEUI_SetGameGenie(1);
245 FCEUI_DisableSpriteLimitation(1);
246 FCEUI_SaveExtraDataUnderBase(eoptions&2);
247 FCEUI_SetSnapName(eoptions&EO_SNAPNAME);
251 if(srendlinev[x]<0 || srendlinev[x]>239) srendlinev[x]=0;
252 if(erendlinev[x]<srendlinev[x] || erendlinev[x]>239) erendlinev[x]=239;
255 printf("main() setrendered lines: %d, %d, %d, %d\n",srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
256 printf("main() clip sides %d\n", eoptions&EO_CLIPSIDES);
258 FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]);
259 FCEUI_SetRenderedLines(0,erendlinev[0],srendlinev[1],erendlinev[1]);
260 FCEUI_SetSoundVolume(soundvol);
261 DriverInterface(DES_NTSCCOL,&ntsccol);
269 if(!strncmp(fccortab[y],fcexp,8))
271 UsrInputTypeFC=fccortabi[y];
286 if(!strncmp(cortab[y],inputa[x],8))
288 UsrInputType[x]=cortabi[y];
291 powerpadside&=~(1<<x);
292 powerpadside|=((((inputa[x][8])-'a')&1)^1)<<x;
302 int CLImain(int argc, char *argv[])
307 if(!(ret=FCEUI_Initialize()))
309 GetBaseDirectory(BaseDirectory);
310 FCEUI_SetBaseDirectory(BaseDirectory);
319 DoArgs(argc-2,&argv[1]);
325 if(!(tmp=FCEUI_LoadGame(argv[argc-1])))
331 RefreshThrottleFPS();
332 if(!DriverInitialize())
345 static int DriverInitialize(void)
347 SetSignals((void *)CloseStuff);
351 if(!InitVideo()) return 0;
353 if(!InitKeyboard()) return 0;
358 static void DriverKill(void)
376 void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
378 if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE))
382 WriteSound(Buffer,Count,NoWaiting);