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
33 char *marray[1]={"Error allocating memory!"};
35 static char BaseDirectory[2048];
36 static char FileBase[2048];
37 static char FileExt[2048];
38 static char FileBaseDirectory[2048];
40 void FCEUI_SetBaseDirectory(char *dir)
42 strncpy(BaseDirectory,dir,2047);
43 BaseDirectory[2047]=0;
46 static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0}; // odirs, odors. ^_^
48 void FCEUI_SetDirOverride(int which, char *n)
51 if(which==FCEUIOD_STATE)
55 /* We should probably use snprintf(), but many C libraries don't seem to
58 char *FCEU_MakeFName(int type, int id1, char *cd1)
60 static uint8 ret[2048];
65 case FCEUMKF_STATE:if(odirs[FCEUIOD_STATE])
66 sprintf(((char*)ret),"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1);
68 sprintf(((char*)ret),"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1);
71 if(FSettings.SnapName)
73 if(odirs[FCEUIOD_SNAPS])
74 sprintf(((char*)ret),"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1);
76 sprintf(((char*)ret),"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory,FileBase,id1,cd1);
80 if(odirs[FCEUIOD_SNAPS])
81 sprintf(((char*)ret),"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1);
83 sprintf(((char*)ret),"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1);
86 case FCEUMKF_SAV:if(odirs[FCEUIOD_NV])
88 sprintf(((char*)ret),"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
92 if(FSettings.SUnderBase)
93 sprintf(((char*)ret),"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1);
95 sprintf(((char*)ret),"%s"PSS"%s.%s",FileBaseDirectory,FileBase,cd1);
99 if(odirs[FCEUIOD_CHEATS])
100 sprintf(((char*)ret),"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase);
102 sprintf(((char*)ret),"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase);
104 case FCEUMKF_GGROM:sprintf(((char*)ret),"%s"PSS"gg.rom",BaseDirectory);break;
105 case FCEUMKF_FDSROM:sprintf(((char*)ret),"%s"PSS"disksys.rom",BaseDirectory);break;
106 case FCEUMKF_PALETTE:
107 if(odirs[FCEUIOD_MISC])
108 sprintf(((char*)ret),"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase);
110 sprintf(((char*)ret),"%s"PSS"gameinfo"PSS"%s.pal",BaseDirectory,FileBase);
116 void GetFileBase(char *f)
121 tp1=((char *)strrchr(f,':'));
123 tp1=((char *)strrchr(f,'/'));
125 tp1=((char *)strrchr(f,'\\'));
127 tp3=((char *)strrchr(f,'/'));
134 strcpy(FileBaseDirectory,".");
138 memcpy(FileBaseDirectory,f,tp1-f);
139 FileBaseDirectory[tp1-f]=0;
143 if((tp3=strrchr(f,'.'))!=NULL)
145 memcpy(FileBase,tp1,tp3-tp1);
147 strcpy(FileExt,tp3+1);
151 strcpy(FileBase,tp1);
156 uint32 uppow2(uint32 n)