updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[fceu.git] / general.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdlib.h>
22#include <string.h>
23#include <stdio.h>
24
25#include "types.h"
26
27#include "general.h"
28#include "state.h"
29#include "version.h"
30#include "svga.h"
31#include "driver.h"
32
33char *marray[1]={"Error allocating memory!"};
34
35static char BaseDirectory[2048];
36static char FileBase[2048];
37static char FileExt[2048];
38static char FileBaseDirectory[2048];
39
40void FCEUI_SetBaseDirectory(char *dir)
41{
42 strncpy(BaseDirectory,dir,2047);
43 BaseDirectory[2047]=0;
44}
45
46static char *odirs[FCEUIOD__COUNT]={0,0,0,0,0}; // odirs, odors. ^_^
47
48void FCEUI_SetDirOverride(int which, char *n)
49{
50 odirs[which]=n;
51 if(which==FCEUIOD_STATE)
52 SaveStateRefresh();
53}
54
55/* We should probably use snprintf(), but many C libraries don't seem to
56 have this function.
57*/
58char *FCEU_MakeFName(int type, int id1, char *cd1)
59{
60 static uint8 ret[2048];
61
62 ret[0]=0;
63 switch(type)
64 {
65 case FCEUMKF_STATE:if(odirs[FCEUIOD_STATE])
5232c20c 66 sprintf(((char*)ret),"%s"PSS"%s.fc%d",odirs[FCEUIOD_STATE],FileBase,id1);
c62d2810 67 else
5232c20c 68 sprintf(((char*)ret),"%s"PSS"fcs"PSS"%s.fc%d",BaseDirectory,FileBase,id1);
c62d2810 69 break;
70 case FCEUMKF_SNAP:
71 if(FSettings.SnapName)
72 {
73 if(odirs[FCEUIOD_SNAPS])
5232c20c 74 sprintf(((char*)ret),"%s"PSS"%s-%d.%s",odirs[FCEUIOD_SNAPS],FileBase,id1,cd1);
c62d2810 75 else
5232c20c 76 sprintf(((char*)ret),"%s"PSS"snaps"PSS"%s-%d.%s",BaseDirectory,FileBase,id1,cd1);
c62d2810 77 }
78 else
79 {
80 if(odirs[FCEUIOD_SNAPS])
5232c20c 81 sprintf(((char*)ret),"%s"PSS"%d.%s",odirs[FCEUIOD_SNAPS],id1,cd1);
c62d2810 82 else
5232c20c 83 sprintf(((char*)ret),"%s"PSS"snaps"PSS"%d.%s",BaseDirectory,id1,cd1);
c62d2810 84 }
85 break;
d97315ac 86 case FCEUMKF_FDS:if(odirs[FCEUIOD_NV])
87 sprintf((char*)ret,"%s"PSS"%s.fds",odirs[FCEUIOD_NV],FileBase);
88 else
89 sprintf((char*)ret,"%s"PSS"sav"PSS"%s.fds",BaseDirectory,FileBase);
90 break;
c62d2810 91 case FCEUMKF_SAV:if(odirs[FCEUIOD_NV])
92 {
5232c20c 93 sprintf(((char*)ret),"%s"PSS"%s.%s",odirs[FCEUIOD_NV],FileBase,cd1);
c62d2810 94 }
95 else
96 {
97 if(FSettings.SUnderBase)
5232c20c 98 sprintf(((char*)ret),"%s"PSS"sav"PSS"%s.%s",BaseDirectory,FileBase,cd1);
c62d2810 99 else
5232c20c 100 sprintf(((char*)ret),"%s"PSS"%s.%s",FileBaseDirectory,FileBase,cd1);
c62d2810 101 }
102 break;
103 case FCEUMKF_CHEAT:
104 if(odirs[FCEUIOD_CHEATS])
5232c20c 105 sprintf(((char*)ret),"%s"PSS"%s.cht",odirs[FCEUIOD_CHEATS],FileBase);
c62d2810 106 else
5232c20c 107 sprintf(((char*)ret),"%s"PSS"cheats"PSS"%s.cht",BaseDirectory,FileBase);
c62d2810 108 break;
5232c20c 109 case FCEUMKF_GGROM:sprintf(((char*)ret),"%s"PSS"gg.rom",BaseDirectory);break;
110 case FCEUMKF_FDSROM:sprintf(((char*)ret),"%s"PSS"disksys.rom",BaseDirectory);break;
c62d2810 111 case FCEUMKF_PALETTE:
112 if(odirs[FCEUIOD_MISC])
5232c20c 113 sprintf(((char*)ret),"%s"PSS"%s.pal",odirs[FCEUIOD_MISC],FileBase);
c62d2810 114 else
5232c20c 115 sprintf(((char*)ret),"%s"PSS"gameinfo"PSS"%s.pal",BaseDirectory,FileBase);
c62d2810 116 break;
117 }
5232c20c 118 return((char *)ret);
c62d2810 119}
120
121void GetFileBase(char *f)
122{
123 char *tp1,*tp3;
124
125 #if PSS_STYLE==4
126 tp1=((char *)strrchr(f,':'));
127 #elif PSS_STYLE==1
128 tp1=((char *)strrchr(f,'/'));
129 #else
130 tp1=((char *)strrchr(f,'\\'));
131 #if PSS_STYLE!=3
132 tp3=((char *)strrchr(f,'/'));
133 if(tp1<tp3) tp1=tp3;
134 #endif
135 #endif
136 if(!tp1)
137 {
138 tp1=f;
139 strcpy(FileBaseDirectory,".");
140 }
141 else
142 {
143 memcpy(FileBaseDirectory,f,tp1-f);
144 FileBaseDirectory[tp1-f]=0;
145 tp1++;
146 }
147
148 if((tp3=strrchr(f,'.'))!=NULL)
149 {
150 memcpy(FileBase,tp1,tp3-tp1);
151 FileBase[tp3-tp1]=0;
152 strcpy(FileExt,tp3+1);
153 }
154 else
155 {
156 strcpy(FileBase,tp1);
157 FileExt[0]=0;
158 }
159}
160
161uint32 uppow2(uint32 n)
162{
163 int x;
164
165 for(x=31;x>=0;x--)
166 if(n&(1<<x))
167 {
168 if((1<<x)!=n)
169 return(1<<(x+1));
170 break;
171 }
172 return n;
173}
174