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
31 #include <shlobj.h> // For directories configuration dialog.
44 #define EO_FSAFTERLOAD 32
45 #define EO_FOAFTERSTART 64
46 #define EO_NOTHROTTLE 128
47 #define EO_CLIPSIDES 256
48 #define EO_SNAPNAME 512
50 /* EO_USERFORCE is something I've been playing with.
51 The code for it isn't finished.
53 #define EO_USERFORCE 1024
56 #define VNSCLIP ((eoptions&EO_CLIPSIDES)?8:0)
57 #define VNSWID ((eoptions&EO_CLIPSIDES)?240:256)
59 static int eoptions=EO_BGRUN;
61 void ResetVideo(void);
62 void ShowCursorAbs(int w);
63 void HideFWindow(int h);
64 int SetMainWindowStuff(void);
65 int GetClientAbsRect(LPRECT lpRect);
66 void UpdateFCEUWindow(void);
70 HINSTANCE fceu_hInstance;
76 // cheats, misc, nonvol, states, snaps, base
77 static char *DOvers[6]={0,0,0,0,0,0};
78 static char *defaultds[5]={"cheats","gameinfo","sav","fcs","snaps"};
80 static char TempArray[2048];
81 static char BaseDirectory[2048];
87 {FCEUIOD_CHEATS,FCEUIOD_MISC,FCEUIOD_NV,FCEUIOD_STATE,FCEUIOD_SNAPS};
90 FCEUI_SetDirOverride(jlist[x], DOvers[x]);
92 FCEUI_SetBaseDirectory(DOvers[5]);
94 FCEUI_SetBaseDirectory(BaseDirectory);
95 FCEUI_SaveExtraDataUnderBase(eoptions&EO_BSAV);
97 /* Remove empty, unused directories. */
105 sprintf(TempArray,"%s\\%s",DOvers[5]?DOvers[5]:BaseDirectory,defaultds[x]);
106 RemoveDirectory(TempArray);
110 void CreateDirs(void)
117 sprintf(TempArray,"%s\\%s",DOvers[5]?DOvers[5]:BaseDirectory,defaultds[x]);
118 CreateDirectory(TempArray,0);
122 static char *gfsdir=0;
123 void GetBaseDirectory(void)
127 GetModuleFileName(0,(LPTSTR)BaseDirectory,2047);
129 for(x=strlen(BaseDirectory);x>=0;x--)
131 if(BaseDirectory[x]=='\\' || BaseDirectory[x]=='/')
132 {BaseDirectory[x]=0;break;}
136 static int exiting=0;
137 int BlockingCheck(void)
141 while( PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE ) ) {
142 if( GetMessage( &msg, 0, 0, 0)>0 )
144 TranslateMessage(&msg);
145 DispatchMessage(&msg);
149 if(exiting) return(0);
155 static int fullscreen=0;
156 static int soundflush=0;
157 static int soundsleep=0;
160 static int windowedfailed;
161 static int winsizemul=1;
162 static int winwidth,winheight;
164 static volatile int nofocus=0;
165 static volatile int userpause=0;
167 #define SO_FORCE8BIT 1
168 #define SO_SECONDARY 2
172 static int soundrate=44100;
173 static int soundbuftime=46;
174 static int soundbufsize;
175 static int soundoptions=0;
176 static int soundvolume=100;
178 static unsigned int srendline,erendline;
179 static unsigned int srendlinen=8;
180 static unsigned int erendlinen=239;
181 static unsigned int srendlinep=0;
182 static unsigned int erendlinep=239;
185 static unsigned int totallines;
187 static void FixFL(void)
189 FCEUI_GetCurrentVidSystem(&srendline,&erendline);
190 totallines=erendline-srendline+1;
193 static void UpdateRendBounds(void)
195 FCEUI_SetRenderedLines(srendlinen,erendlinen,srendlinep,erendlinep);
199 static uint8 cpalette[192];
202 static int ntsccol=0,ntsctint,ntschue;
204 void FCEUD_PrintError(char *s)
206 if(fullscreen) ShowCursorAbs(1);
207 MessageBox(0,s,"FCE Ultra Error",MB_ICONERROR|MB_OK|MB_SETFOREGROUND|MB_TOPMOST);
208 if(fullscreen)ShowCursorAbs(0);
211 void ShowAboutBox(void)
213 sprintf(TempArray,"FCE Ultra "VERSION_STRING"\n\nhttp://fceultra.sourceforge.net\n\n"__TIME__"\n"__DATE__"\n""gcc "__VERSION__);
214 MessageBox(hAppWnd,TempArray,"About FCE Ultra",MB_OK);
217 void DoFCEUExit(void)
227 static int changerecursive=0;
229 #include "throttle.c"
238 int DriverInitialize(void)
240 if(!InitializeDDraw())
246 SetVideoMode(fullscreen);
247 InitInputStuff(); /* Initialize DInput interfaces. */
248 CreateInputStuff(); /* Create and set virtual NES/FC devices. */
252 static void DriverKill(void)
254 sprintf(TempArray,"%s/fceu.cfg",BaseDirectory);
255 SaveConfig(TempArray);
258 if(soundo) TrashSound();
264 int main(int argc,char *argv[])
268 if(!FCEUI_Initialize())
271 fceu_hInstance=GetModuleHandle(0);
275 sprintf(TempArray,"%s\\fceu.cfg",BaseDirectory);
276 LoadConfig(TempArray);
277 FixGIGO(); /* Since a game doesn't have to be
278 loaded before the GUI can be used, make
279 sure the temporary input type variables
290 if(eoptions&EO_CPALETTE)
291 FCEUI_SetPaletteArray(cpalette);
303 if(!DriverInitialize())
311 else if(eoptions&EO_FOAFTERSTART)
312 LoadNewGamey(hAppWnd);
319 RedrawWindow(hAppWnd,0,0,RDW_ERASE|RDW_INVALIDATE);
331 void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
333 FCEUD_BlitScreen(XBuf);
335 FCEUD_WriteSoundData(Buffer,Count);