X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=fceu.git;a=blobdiff_plain;f=drivers%2Fgp2x%2Fmain.c;h=a399e1ed44608148b4053ed9ccdc8b2a2987042a;hp=fc9c7b6929f022fee56e8d2eb6bf4c90b366dd6f;hb=e328100eecae3adfce1c3b57364bee5d166217ef;hpb=22f08d9598e12f15de5e3c2f503c2ad1298dcc17 diff --git a/drivers/gp2x/main.c b/drivers/gp2x/main.c index fc9c7b6..a399e1e 100644 --- a/drivers/gp2x/main.c +++ b/drivers/gp2x/main.c @@ -1,7 +1,4 @@ /* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Ben Parnell * * 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 @@ -18,11 +15,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* This file contains or coordinates all of the code necessary to compile - on a UNIX system that can use svgalib, such as FreeBSD and Linux. - This code is not guaranteed to compile on FreeBSD, though. -*/ - #include #include @@ -36,7 +28,10 @@ #include #include "main.h" +#include "minimal.h" #include "throttle.h" +#include "menu.h" +#include "gp2x.h" #include "../common/config.h" #include "../common/args.h" @@ -45,16 +40,22 @@ #include "dface.h" +// just for printing some iNES info for user.. +#include "../../fce.h" +#include "../../ines.h" + +// internals +extern char lastLoadedGameName[2048]; +extern uint8 Exit; // exit emu loop flag +void CloseGame(void); + +FCEUGI *fceugi = NULL; static int ntsccol=0,ntschue=-1,ntsctint=-1; int soundvol=70; int inited=0; -int swapbuttons=0; -int showfps=0; int srendlinev[2]={0,0}; -//int srendlinev[2]={0,0}; int erendlinev[2]={239,239}; -//int erendlinev[2]={231,239}; int srendline,erendline; @@ -123,32 +124,70 @@ static CFGSTRUCT fceuconfig[]={ ENDCFGSTRUCT }; -static void SaveConfig(void) +void SaveConfig(const char *name) { char tdir[2048]; - sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory); + if (name) + sprintf(tdir,"%s"PSS"cfg"PSS"%s.cfg",BaseDirectory,name); + else sprintf(tdir,"%s"PSS"fceu2.cfg",BaseDirectory); DriverInterface(DES_GETNTSCTINT,&ntsctint); DriverInterface(DES_GETNTSCHUE,&ntschue); SaveFCEUConfig(tdir,fceuconfig); } -static void LoadConfig(void) +static void LoadConfig(const char *name) { char tdir[2048]; - sprintf(tdir,"%s"PSS"fceu.cfg",BaseDirectory); + if (name) + sprintf(tdir,"%s"PSS"cfg"PSS"%s.cfg",BaseDirectory,name); + else sprintf(tdir,"%s"PSS"fceu2.cfg",BaseDirectory); LoadFCEUConfig(tdir,fceuconfig); if(ntsctint>=0) DriverInterface(DES_SETNTSCTINT,&ntsctint); if(ntschue>=0) DriverInterface(DES_SETNTSCHUE,&ntschue); } +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]) + { + 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[5]={"fcs","snaps","gameinfo","sav","cheats"}; + char *subs[]={"fcs","snaps","gameinfo","sav","cheats","cfg"}; char tdir[2048]; int x; mkdir(BaseDirectory,S_IRWXU); - for(x=0;x<5;x++) + for(x=0;x 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(); + fceugi=FCEUI_LoadGame(lastLoadedGameName); + if (fceugi) + { + LoadConfig(lastLoadedGameName); + if (Settings.region_force) + FCEUI_SetVidSystem(Settings.region_force - 1); + ParseGI(fceugi); + //RefreshThrottleFPS(); + InitOtherInput(); + + // additional print for gpfce + // TODO: handlers for other formats then iNES + { + int MapperNo; + iNES_HEADER *head = iNESGetHead(); // TODO: ReMake + MapperNo = (head->ROM_type>>4); + MapperNo|=(head->ROM_type2&0xF0); + FCEU_DispMessage("%s, Mapper: %d%s%s", PAL?"PAL":"NTSC", MapperNo, (head->ROM_type&2)?", BB":"", (head->ROM_type&4)?", T":""); + } + } + else + { + switch(LoadGameLastError) { + default: strcpy(menuErrorMsg, "failed to load ROM"); break; + case 2: strcpy(menuErrorMsg, "Can't find a ROM for movie"); break; + case 10: strcpy(menuErrorMsg, "FDS BIOS ROM is missing, read docs"); break; + case 11: strcpy(menuErrorMsg, "Error reading auxillary FDS file"); break; + } + } + } + if(Exit || !fceugi) + { + int ret; + ret = gp2x_menu_do(); + if (ret == 1) break; // exit emu + if (ret == 2) { // reload ROM + Exit = 0; + continue; + } + } + + PrepareOtherInput(); + gp2x_video_changemode(Settings.scaling == 3 ? 15 : 8); + switch (Settings.scaling & 3) { + case 0: gp2x_video_RGB_setscaling(0, 320, 240); gp2x_video_set_offs(0); break; + case 1: gp2x_video_RGB_setscaling(0, 256, 240); gp2x_video_set_offs(32); break; + case 2: gp2x_video_RGB_setscaling(0, 256, 240); gp2x_video_set_offs(32); break; // TODO + case 3: gp2x_video_RGB_setscaling(0, 320, 240); gp2x_video_set_offs(32); break; + } + gp2x_start_sound(Settings.sound_rate, 16, 0); + FCEUI_Emulate(); + } + + if (fceugi) + CloseGame(); - dk: + SaveLLGN(); DriverKill(); - return(ret?0:1); + return 0; } static int DriverInitialize(void) { SetSignals((void *)CloseStuff); - if(InitJoysticks()) - inited|=2; if(!InitVideo()) return 0; inited|=4; - if(!InitKeyboard()) return 0; - inited|=8; return 1; } static void DriverKill(void) { - SaveConfig(); + // SaveConfig(NULL); // done explicitly in menu now SetSignals(SIG_IGN); - if(inited&2) - KillJoysticks(); - if(inited&8) - KillKeyboard(); if(inited&4) KillVideo(); if(inited&1) KillSound(); - if(inited&16) - KillMouse(); inited=0; } -void FCEUD_Update(uint8 *XBuf, int16 *Buffer, int Count) +void FCEUD_Update(uint8 *xbuf, int16 *Buffer, int Count) { - if(!Count && !NoWaiting && !(eoptions&EO_NOTHROTTLE)) + if(!Count && !(eoptions&EO_NOTHROTTLE)) SpeedThrottle(); - BlitScreen(XBuf); - if(Count) - WriteSound(Buffer,Count,NoWaiting); + BlitScreen(xbuf); + if(Count && !(eoptions&EO_NOTHROTTLE)) + WriteSound(Buffer,Count); FCEUD_UpdateInput(); }