1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Xodnizel
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
26 #include <sys/types.h>
42 static char BaseDirectory[2048];
44 static char FileExt[2048]; /* Includes the . character, as in ".nes" */
46 static char FileBaseDirectory[2048];
48 void FCEUI_SetBaseDirectory(char *dir)
50 strncpy(BaseDirectory,dir,2047);
51 BaseDirectory[2047]=0;
54 static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0}; // odirs, odors. ^_^
56 void FCEUI_SetDirOverride(int which, char *n)
58 // FCEU_PrintError("odirs[%d]=%s->%s", which, odirs[which], n);
59 if(which < FCEUIOD__COUNT)
63 if(FCEUGameInfo) /* Rebuild cache of present states/movies. */
65 if(which==FCEUIOD_STATE)
67 else if(which == FCEUIOD_MISC)
68 FCEUMOV_CheckMovies();
74 static int asprintf(char **strp, const char *fmt, ...)
80 if(!(*strp=malloc(2048)))
82 ret=vsnprintf(*strp,2048,fmt,ap);
88 char* FCEU_GetPath(int type)
93 case FCEUMKF_STATE:if(odirs[FCEUIOD_STATE])
94 ret=strdup(odirs[FCEUIOD_STATE]);
96 asprintf(&ret,"%s"PSS"movie",BaseDirectory);
98 case FCEUMKF_MOVIE:if(odirs[FCEUIOD_MISC])
99 ret=strdup(odirs[FCEUIOD_MISC]);
101 asprintf(&ret,"%s"PSS"movie",BaseDirectory);
107 char *FCEU_MakePath(int type, const char* filebase)
113 case FCEUMKF_MOVIE:if(odirs[FCEUIOD_MISC])
114 asprintf(&ret,"%s"PSS"%s",odirs[FCEUIOD_MISC],filebase);
116 asprintf(&ret,"%s"PSS"movie"PSS"%s",BaseDirectory,filebase);
122 char *FCEU_MakeFName(int type, int id1, char *cd1)
129 case FCEUMKF_NPTEMP: asprintf(&ret,"%s"PSS"m590plqd94fo.tmp",BaseDirectory);break;
130 case FCEUMKF_MOVIE:if(id1>=0)
132 if(odirs[FCEUIOD_MISC])
133 asprintf(&ret,"%s"PSS"%s.%d.fcm",odirs[FCEUIOD_MISC],FileBase,id1);
135 asprintf(&ret,"%s"PSS"movie"PSS"%s.%d.fcm",BaseDirectory,FileBase,id1);
136 if(stat(ret,&tmpstat)==-1)
138 if(odirs[FCEUIOD_MISC])
139 asprintf(&ret,"%s"PSS"%s.%d.fcm",odirs[FCEUIOD_MISC],FileBase,id1);
141 asprintf(&ret,"%s"PSS"movie"PSS"%s.%d.fcm",BaseDirectory,FileBase,id1);
146 if(odirs[FCEUIOD_MISC])
147 asprintf(&ret,"%s"PSS"%s.fcm",odirs[FCEUIOD_MISC],FileBase);
149 asprintf(&ret,"%s"PSS"movie"PSS"%s.fcm",BaseDirectory,FileBase);
152 case FCEUMKF_STATE:if(odirs[FCEUIOD_STATE])
154 asprintf(&ret,"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1);
155 // FCEU_PrintError("A");
159 asprintf(&ret,"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1);
160 // FCEU_PrintError("B");
162 if(stat(ret,&tmpstat)==-1)
164 if(odirs[FCEUIOD_STATE])
166 asprintf(&ret,"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1);
167 // FCEU_PrintError("C");
171 asprintf(&ret,"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1);
172 // FCEU_PrintError("D");
177 if(FSettings.SnapName)
179 if(odirs[FCEUIOD_SNAPS])
180 asprintf(&ret,"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1);
182 asprintf(&ret,"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory,FileBase,id1,cd1);
186 if(odirs[FCEUIOD_SNAPS])
187 asprintf(&ret,"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1);
189 asprintf(&ret,"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1);
192 case FCEUMKF_FDS:if(odirs[FCEUIOD_NV])
193 asprintf(&ret,"%s"PSS"%s.fds",odirs[FCEUIOD_NV],FileBase);
195 asprintf(&ret,"%s"PSS"sav"PSS"%s.fds",BaseDirectory,FileBase);
197 case FCEUMKF_SAV:if(odirs[FCEUIOD_NV])
198 asprintf(&ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
200 asprintf(&ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1);
201 if(stat(ret,&tmpstat)==-1)
203 if(odirs[FCEUIOD_NV])
204 asprintf(&ret,"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
206 asprintf(&ret,"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1);
210 if(odirs[FCEUIOD_CHEATS])
211 asprintf(&ret,"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase);
213 asprintf(&ret,"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase);
215 case FCEUMKF_IPS: asprintf(&ret,"%s"PSS"%s%s.ips",FileBaseDirectory,FileBase,FileExt);
217 case FCEUMKF_GGROM:asprintf(&ret,"%s"PSS"gg.rom",BaseDirectory);break;
218 case FCEUMKF_FDSROM:asprintf(&ret,"%s"PSS"disksys.rom",BaseDirectory);break;
219 case FCEUMKF_PALETTE:
220 if(odirs[FCEUIOD_MISC])
221 asprintf(&ret,"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase);
223 asprintf(&ret,"%s"PSS"%s.pal",BaseDirectory,FileBase);
225 case FCEUMKF_MOVIEGLOB:
226 if(odirs[FCEUIOD_MISC])
227 // asprintf(&ret,"%s"PSS"%s*.fcm",odirs[FCEUIOD_MISC],FileBase);
228 asprintf(&ret,"%s"PSS"*.???",odirs[FCEUIOD_MISC]);
230 // asprintf(&ret,"%s"PSS"fcs"PSS"%s*.fcm",BaseDirectory,FileBase);
231 asprintf(&ret,"%s"PSS"movie"PSS"*.???",BaseDirectory);
233 case FCEUMKF_MOVIEGLOB2:
234 asprintf(&ret,"%s"PSS"*.???",BaseDirectory);
236 case FCEUMKF_STATEGLOB:
237 if(odirs[FCEUIOD_STATE])
238 asprintf(&ret,"%s"PSS"%s*.fc?",odirs[FCEUIOD_STATE],FileBase);
240 asprintf(&ret,"%s"PSS"fcs"PSS"%s*.fc?",BaseDirectory,FileBase);
246 void GetFileBase(const char *f)
248 const char *tp1,*tp3;
251 tp1=((char *)strrchr(f,':'));
253 tp1=((char *)strrchr(f,'/'));
255 tp1=((char *)strrchr(f,'\\'));
257 tp3=((char *)strrchr(f,'/'));
264 strcpy(FileBaseDirectory,".");
268 memcpy(FileBaseDirectory,f,tp1-f);
269 FileBaseDirectory[tp1-f]=0;
273 if(((tp3=strrchr(f,'.'))!=NULL) && (tp3>tp1))
275 memcpy(FileBase,tp1,tp3-tp1);
281 strcpy(FileBase,tp1);
286 uint32 uppow2(uint32 n)