X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=fceu.git;a=blobdiff_plain;f=drivers%2Fcommon%2Fmain.c;fp=drivers%2Fcommon%2Fmain.c;h=616b7c6252467359bc8bbc0a7db906632f5b1c66;hp=0000000000000000000000000000000000000000;hb=4a2a617ac879a95babe3b8a822188b71e9769ba4;hpb=396c448eb538587248ddbf586a90371c71b48183 diff --git a/drivers/common/main.c b/drivers/common/main.c new file mode 100644 index 0000000..616b7c6 --- /dev/null +++ b/drivers/common/main.c @@ -0,0 +1,544 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "main.h" +#include "throttle.h" +#include "config.h" +#include "args.h" +#include "unixdsp.h" +#include "cheat.h" +#include "dface.h" +#include "platform.h" +#include "menu.h" +#include "settings.h" + +#include "../../fce.h" +#include "../../cart.h" + + +// these are now here to try to make compatible configs +// between different versions of the emu +DSETTINGS Settings; +CFGSTRUCT DriverConfig[]={ + AC(Settings.turbo_rate_add), + AC(Settings.sound_rate), + AC(Settings.showfps), + AC(Settings.scaling), + AC(Settings.frameskip), + AC(Settings.sstate_confirm), + AC(Settings.region_force), + AC(Settings.cpuclock), + AC(Settings.mmuhack), + AC(Settings.ramtimings), + AC(Settings.gamma), + AC(Settings.perfect_vsync), + AC(Settings.accurate_mode), + ENDCFGSTRUCT +}; + +void CleanSurface(void); + +// internals +extern uint8 Exit; // exit emu loop flag +extern int FSkip; +void CloseGame(void); + +FCEUGI *fceugi = NULL; +int ntsccol=0,ntschue=-1,ntsctint=-1; +int soundvol=70; +int inited=0; + +int srendlinev[2]={8,0}; +int erendlinev[2]={231,239}; +int srendline,erendline; + + +static char BaseDirectory[2048]; + +int eoptions=0; + +static void DriverKill(void); +static int DriverInitialize(void); + +static int gametype; +#include "input.c" + +static void ParseGI(FCEUGI *gi) +{ + gametype=gi->type; + + InputType[0]=UsrInputType[0]; + InputType[1]=UsrInputType[1]; + InputTypeFC=UsrInputTypeFC; + + if(gi->input[0]>=0) + InputType[0]=gi->input[0]; + if(gi->input[1]>=0) + InputType[1]=gi->input[1]; + if(gi->inputfc>=0) + InputTypeFC=gi->inputfc; +} + +void FCEUD_PrintError(char *s) +{ + puts(s); +} + +char *cpalette=0; +void LoadCPalette(void) +{ + char tmpp[192]; + FILE *fp; + + if(!(fp=fopen(cpalette,"rb"))) + { + printf(" Error loading custom palette from file: %s\n",cpalette); + free(cpalette); + cpalette=0; + return; + } + fread(tmpp,1,192,fp); + FCEUI_SetPaletteArray((uint8 *)tmpp); + fclose(fp); +} + +static CFGSTRUCT fceuconfig[]={ + AC(soundvol), + ACS(cpalette), + AC(ntsctint), + AC(ntschue), + AC(ntsccol), + AC(UsrInputTypeFC), + ACA(UsrInputType), + AC(powerpadside), + AC(powerpadsc), + AC(eoptions), + ACA(srendlinev), + ACA(erendlinev), + ADDCFGSTRUCT(DriverConfig), + ENDCFGSTRUCT +}; + +static const char *skip_path(const char *path) +{ + const char *p; + if (path == NULL) return NULL; + for (p = path+strlen(path)-1; p > path && *p != '/'; p--); + if (*p == '/') p++; + return p; +} + +int SaveConfig(const char *llgn_path) +{ + const char *name = skip_path(llgn_path); + char tdir[2048]; + int ret; + if (name) + sprintf(tdir,"%s"PSS"cfg"PSS"%s.cfg",BaseDirectory,name); + else sprintf(tdir,"%s"PSS"fceu2.cfg",BaseDirectory); + printf("saving cfg to %s ... ", tdir); fflush(stdout); + FCEUI_GetNTSCTH(&ntsctint, &ntschue); + ret=SaveFCEUConfig(tdir,fceuconfig); + printf(ret == 0 ? "done\n" : "failed\n"); + return ret; +} + +static int LoadConfig(const char *llgn_path) +{ + const char *name = skip_path(llgn_path); + char tdir[2048]; + int ret; + if (name) + sprintf(tdir,"%s"PSS"cfg"PSS"%s.cfg",BaseDirectory,name); + else sprintf(tdir,"%s"PSS"fceu2.cfg",BaseDirectory); + printf("loading cfg from %s ... ", tdir); fflush(stdout); + FCEUI_GetNTSCTH(&ntsctint, &ntschue); /* Get default settings for if no config file exists. */ + ret=LoadFCEUConfig(tdir,fceuconfig); + FCEUI_SetNTSCTH(ntsccol, ntsctint, ntschue); + printf(ret == 0 ? "done\n" : "failed\n"); + return ret; +} + +static void LoadLLGN(void) +{ + char tdir[2048]; + FILE *f; + int len; + sprintf(tdir,"%s"PSS"last_rom.txt",BaseDirectory); + f=fopen(tdir, "r"); + if(f) + { + len = fread(lastLoadedGameName, 1, sizeof(lastLoadedGameName)-1, f); + lastLoadedGameName[len] = 0; + fclose(f); + } +} + +static void SaveLLGN(void) +{ + // save last loaded game name + if (lastLoadedGameName[0] && !(eoptions&EO_NOAUTOWRITE)) + { + char tdir[2048]; + FILE *f; + sprintf(tdir,"%s"PSS"last_rom.txt",BaseDirectory); + f=fopen(tdir, "w"); + if(f) + { + fwrite(lastLoadedGameName, 1, strlen(lastLoadedGameName), f); + fclose(f); + sync(); + } + } +} + + +static void CreateDirs(void) +{ + char *subs[]={"fcs","snaps","gameinfo","sav","cheats","cfg","pal"}; + char tdir[2048]; + int x; + + mkdir(BaseDirectory,S_IRWXU); + for(x=0;x239) srendlinev[x]=0; + if(erendlinev[x]239) erendlinev[x]=239; + } + + FCEUI_SetRenderedLines(srendlinev[0],erendlinev[0],srendlinev[1],erendlinev[1]); + FCEUI_SetSoundVolume(80); + #ifdef NETWORK + if(docheckie2[0]) + netplay=2; + else if(docheckie2[1]) + netplay=1; + + if(netplay) + FCEUI_SetNetworkPlay(netplay); + #endif + DoDriverArgs(); + + if(fcexp) + { + int y; + for(y=0;y<5;y++) + { + if(!strncmp(fccortab[y],fcexp,8)) + { + UsrInputTypeFC=fccortabi[y]; + break; + } + } + free(fcexp); + } + for(x=0;x<2;x++) + { + int y; + + if(!inputa[x]) + continue; + + for(y=0;y<5;y++) + { + if(!strncmp(cortab[y],inputa[x],8)) + { + UsrInputType[x]=cortabi[y]; + if(y==3) + { + powerpadside&=~(1< 1 && !last_arg_parsed) + { + strncpy(lastLoadedGameName, argv[argc-1], sizeof(lastLoadedGameName)); + lastLoadedGameName[sizeof(lastLoadedGameName)-1] = 0; + Exit = 0; + } + else + { + Exit = 1; + } + + while (1) + { + if(!Exit) + { + if (fceugi) + CloseGame(); + ret=LoadConfig(lastLoadedGameName); + if (ret != 0) + { + LoadConfig(NULL); + } + FCEUI_SetEmuMode(Settings.accurate_mode); + fceugi=FCEUI_LoadGame(lastLoadedGameName); + if (fceugi) + { + char infostring[32]; + if (Settings.region_force) + FCEUI_SetVidSystem(Settings.region_force - 1); + ParseGI(fceugi); + InitOtherInput(); + + if ((eoptions&EO_GG) && geniestage == 0) { + strcpy(infostring, "gg.rom is missing, GG disabled"); + eoptions&=~EO_GG; + FCEUI_SetGameGenie(0); + } else + GameInterface(GI_INFOSTRING, infostring); + FCEU_DispMessage("%s", infostring); + } + else + { + switch(LoadGameLastError) { + default: menu_update_msg("failed to load ROM"); break; + case 2: menu_update_msg("Can't find a ROM for ips/movie"); break; + case 10: menu_update_msg("FDS BIOS ROM is missing, read docs"); break; + case 11: menu_update_msg("Error reading auxillary FDS file"); break; + } + } + } + if(Exit || !fceugi) + { + int ret; + ret = menu_loop(); + if (ret == 1) break; // exit emu + if (ret == 2) { // reload ROM + Exit = 0; + continue; + } + } + + PrepareOtherInput(); + FCEUI_GetCurrentVidSystem(&srendline,&erendline); + platform_apply_config(); + CleanSurface(); + StartSound(); + RefreshThrottleFPS(); + FCEUI_Emulate(); + } + + if (fceugi) + CloseGame(); + + SaveLLGN(); + FCEUI_Kill(); + DriverKill(); + platform_finish(); + return 0; +} + +static int DriverInitialize(void) +{ + SetSignals((void *)CloseStuff); + + if(!InitVideo()) return 0; + inited|=4; + return 1; +} + +static void DriverKill(void) +{ + // SaveConfig(NULL); // done explicitly in menu now + SetSignals(SIG_DFL); + + if(cpalette) free(cpalette); + cpalette=0; + + if(inited&4) + KillVideo(); + if(inited&1) + KillSound(); + inited=0; +} + +void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count) +{ + FCEUD_UpdateInput(); // must update input before blitting because of save confirmation stuff + BlitPrepare(xbuf == NULL); + if(!(eoptions&EO_NOTHROTTLE)) + { + if(Count) + WriteSound(Buffer,Count); + SpeedThrottle(); + } + BlitScreen(xbuf == NULL); + // make sure last frame won't get skipped, because we need it for menu bg + if (Exit) FSkip=0; +} + +