From ff79511368bed11b75ce8eea58c065b2fe258150 Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 3 Nov 2009 08:16:57 +0000 Subject: [PATCH] sync with FCEUX --- source/fceultra/boards/bmc42in1r.cpp | 30 ++++++++--- source/fceultra/fceu.cpp | 26 +++++++--- source/fceultra/input.cpp | 24 ++++++++- source/fceultra/input.h | 2 + source/fceultra/nsf.cpp | 2 +- source/fceultra/state.cpp | 78 ++++++++++++++++++++++++++-- source/fceultra/unif.cpp | 15 +++--- 7 files changed, 150 insertions(+), 27 deletions(-) diff --git a/source/fceultra/boards/bmc42in1r.cpp b/source/fceultra/boards/bmc42in1r.cpp index 5eabb8c..15afeaf 100644 --- a/source/fceultra/boards/bmc42in1r.cpp +++ b/source/fceultra/boards/bmc42in1r.cpp @@ -24,17 +24,21 @@ extern uint32 ROM_size; static uint8 hrd_sw; -static uint8 latche; +static uint8 latche[2]; static SFORMAT StateRegs[]= { {&hrd_sw, 1, "DIPSW"}, - {&latche, 1, "LATCHE"}, + {&latche, sizeof(latche), "LATCHE"}, {&hrd_sw, 1, "HRDSW"}, {0} }; static void Sync(void) { + int bank = (latche[0] >> 1 & 0x0F) | + (latche[0] >> 3 & 0x10) | + (latche[1] << 5 & 0x20); + /* if(!(latche&0x02)) setprg32r(0,0x8000,(latche&0x3F)>>1); else @@ -43,6 +47,8 @@ static void Sync(void) setprg16r(0,0xC000,latche&0x3f); } */ + /* the old one, doesnt work with 76 in 1 game + * since it doesn't account for all the PRG-ROM if(!(latche&0x20)) setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f); else @@ -50,13 +56,23 @@ static void Sync(void) setprg16r(hrd_sw,0x8000,latche&0x1f); setprg16r(hrd_sw,0xC000,latche&0x1f); } - setmirror((latche>>6)&1); + setmirror((latche>>6)&1);*/ + if(!(latche[0] & 0x20)) + setprg32r(hrd_sw,0x8000,bank); + else + { + bank = (bank << 1) | (latche[0] & 1); + setprg16r(hrd_sw,0x8000,bank); + setprg16r(hrd_sw,0xC000,bank); + } + setmirror((latche[0] & 0x40) ? MI_V : MI_H); } static DECLFW(BMC42in1rWrite) { - latche=V; - Sync(); + latche[A & 1] = V; + //latche = V; + Sync(); } static void BMC42in1rReset(void) @@ -67,7 +83,7 @@ static void BMC42in1rReset(void) static void BMC42in1rPower(void) { - latche=0; + latche[0] = latche[1] = 0; hrd_sw=0; setchr8(0); Sync(); @@ -92,7 +108,7 @@ static void M226Power(void) { if(ROM_size==64) SetupCartPRGMapping(1,PRGptr[0]+512*1024,512,0); - latche=0; + latche[0] = 0; hrd_sw=0; setchr8(0); Sync(); diff --git a/source/fceultra/fceu.cpp b/source/fceultra/fceu.cpp index af31675..0c3ea46 100644 --- a/source/fceultra/fceu.cpp +++ b/source/fceultra/fceu.cpp @@ -66,6 +66,8 @@ #include "drivers/win/main.h" #include "drivers/win/cheat.h" #include "drivers/win/texthook.h" +#include "drivers/win/ram_search.h" +#include "drivers/win/ramwatch.h" #include "drivers/win/memwatch.h" #include "drivers/win/tracer.h" #else @@ -244,11 +246,9 @@ readfunc GetReadHandler(int32 a) else return ARead[a]; } - void SetReadHandler(int32 start, int32 end, readfunc func) { int32 x; - if(!func) func=ANull; @@ -333,7 +333,7 @@ static DECLFW(BRAML) { RAM[A]=V; #ifdef _S9XLUA_H - FCEU_LuaWriteInform(); + CallRegisteredLuaMemHook(A, 1, V, LUAMEMHOOK_WRITE); #endif } @@ -341,7 +341,7 @@ static DECLFW(BRAMH) { RAM[A&0x7FF]=V; #ifdef _S9XLUA_H - FCEU_LuaWriteInform(); + CallRegisteredLuaMemHook(A&0x7FF, 1, V, LUAMEMHOOK_WRITE); #endif } @@ -488,6 +488,10 @@ endlseq: if(GameInfo->type!=GIT_NSF) FCEU_LoadGameCheats(0); +#if defined (WIN32) || defined (WIN64) + DoDebuggerRunCheck(); //Can't safely do it in loadPreferences +#endif + return GameInfo; } @@ -637,15 +641,25 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski FCEU_UpdateInput(); lagFlag = 1; + +#ifdef _S9XLUA_H + CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION); +#endif + if(geniestage!=1) FCEU_ApplyPeriodicCheats(); r = FCEUPPU_Loop(skip); if (skip != 2) ssize=FlushEmulateSound(); //If skip = 2 we are skipping sound processing - + +#ifdef _S9XLUA_H + CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION); +#endif + #ifdef WIN32 //These Windows only dialogs need to be updated only once per frame so they are included here UpdateCheatList(); UpdateTextHooker(); + Update_RAM_Search(); // Update_RAM_Watch() is also called. RamChange(); UpdateLogWindow(); //FCEUI_AviVideoUpdate(XBuf); @@ -1146,4 +1160,4 @@ uint8 FCEU_ReadRomByte(uint32 i) { if(i < 16+PRGsize[0])return PRGptr[0][i-16]; if(i < 16+PRGsize[0]+CHRsize[0])return CHRptr[0][i-16-PRGsize[0]]; return 0; -} \ No newline at end of file +} diff --git a/source/fceultra/input.cpp b/source/fceultra/input.cpp index e2f81ff..54d826b 100644 --- a/source/fceultra/input.cpp +++ b/source/fceultra/input.cpp @@ -601,6 +601,8 @@ static void LaunchPPU(void); static void LaunchHex(void); static void LaunchTraceLogger(void); static void LaunchCodeDataLogger(void); +static void LaunchRamWatch(void); +static void LaunchRamSearch(void); static void FA_SkipLag(void); static void OpenRom(void); static void CloseRom(void); @@ -720,7 +722,9 @@ struct EMUCMDTABLE FCEUI_CommandTable[]= { EMUCMD_CLOSEROM, EMUCMDTYPE_TOOL, CloseRom, 0, 0, "Close ROM", 0}, { EMUCMD_MISC_DISPLAY_MOVIESUBTITLES, EMUCMDTYPE_MISC, MovieSubtitleToggle,0,0,"Toggle Movie Subtitles", 0}, { EMUCMD_MISC_UNDOREDOSAVESTATE, EMUCMDTYPE_MISC, UndoRedoSavestate, 0,0,"Undo/Redo Savestate", 0}, - { EMUCMD_MISC_TOGGLEFULLSCREEN, EMUCMDTYPE_MISC, ToggleFullscreen, 0, 0, "Toggle Fullscreen", 0} + { EMUCMD_MISC_TOGGLEFULLSCREEN, EMUCMDTYPE_MISC, ToggleFullscreen, 0, 0, "Toggle Fullscreen", 0}, + { EMUCMD_TOOL_OPENRAMWATCH, EMUCMDTYPE_TOOL, LaunchRamWatch, 0, 0, "Open Ram Watch", 0}, + { EMUCMD_TOOL_OPENRAMSEARCH, EMUCMDTYPE_TOOL, LaunchRamSearch, 0, 0, "Open Ram Search", 0}, }; #define NUM_EMU_CMDS (sizeof(FCEUI_CommandTable)/sizeof(FCEUI_CommandTable[0])) @@ -905,6 +909,24 @@ static void LaunchCheats(void) #endif } +static void LaunchRamWatch(void) +{ +#ifdef WIN32 + extern void OpenRamWatch(); //adelikat: Blah blah hacky, I know + OpenRamWatch(); +#endif +} + +static void LaunchRamSearch(void) +{ +#ifdef WIN32 + extern void OpenRamSearch(); + OpenRamSearch(); +#endif +} + + + static void FA_SkipLag(void) { frameAdvanceLagSkip ^= 1; diff --git a/source/fceultra/input.h b/source/fceultra/input.h index 0b0779f..2d9373d 100644 --- a/source/fceultra/input.h +++ b/source/fceultra/input.h @@ -219,6 +219,8 @@ enum EMUCMD EMUCMD_MISC_DISPLAY_MOVIESUBTITLES, EMUCMD_MISC_UNDOREDOSAVESTATE, EMUCMD_MISC_TOGGLEFULLSCREEN, + EMUCMD_TOOL_OPENRAMWATCH, + EMUCMD_TOOL_OPENRAMSEARCH, EMUCMD_MAX }; diff --git a/source/fceultra/nsf.cpp b/source/fceultra/nsf.cpp index 7fa2301..f327c0d 100644 --- a/source/fceultra/nsf.cpp +++ b/source/fceultra/nsf.cpp @@ -443,7 +443,7 @@ static DECLFR(NSF_read) BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]); } #ifdef _S9XLUA_H - FCEU_LuaWriteInform(); + //CallRegisteredLuaMemHook(A, 1, V, LUAMEMHOOK_WRITE); FIXME #endif return (CurrentSong-1); } diff --git a/source/fceultra/state.cpp b/source/fceultra/state.cpp index 24f29c1..a45828f 100644 --- a/source/fceultra/state.cpp +++ b/source/fceultra/state.cpp @@ -48,6 +48,16 @@ #include "input.h" #include "zlib.h" #include "driver.h" +#ifdef _S9XLUA_H +#include "fceulua.h" +#endif + +//TODO - we really need some kind of global platform-specific options api +#ifdef WIN32 +#include "drivers/win/main.h" +#include "drivers/win/ram_search.h" +#include "drivers/win/ramwatch.h" +#endif using namespace std; @@ -68,6 +78,8 @@ char lastLoadstateMade[2048]; //Stores the filename of the last state loaded (ne bool undoLS = false; //This will be true if a backupstate was made and it was made since ROM was loaded bool redoLS = false; //This will be true if a backupstate was loaded, meaning redoLoadState can be run +bool internalSaveLoad = false; + #define SFMDATA_SIZE (64) static SFORMAT SFMDATA[SFMDATA_SIZE]; static int SFEXINDEX; @@ -437,7 +449,7 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel) void FCEUSS_Save(const char *fname) { std::fstream* st = 0; - char *fn; + char fn[2048]; if(geniestage==1) { @@ -448,11 +460,12 @@ void FCEUSS_Save(const char *fname) if(fname) //If filename is given use it. { st =FCEUD_UTF8_fstream(fname, "wb"); + strcpy(fn, fname); } else //Else, generate one { //FCEU_PrintError("daCurrentState=%d",CurrentState); - fn = strdup(FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); + strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,0).c_str()); //backup existing savestate first if (CheckFileExists(fn)) @@ -465,7 +478,6 @@ void FCEUSS_Save(const char *fname) undoSS = false; //so backup made so lastSavestateMade does have a backup file, so no undo st = FCEUD_UTF8_fstream(fn,"wb"); - free(fn); } if(st == NULL) @@ -474,6 +486,32 @@ void FCEUSS_Save(const char *fname) return; } + #ifdef _S9XLUA_H + if (!internalSaveLoad) + { + LuaSaveData saveData; + CallRegisteredLuaSaveFunctions(CurrentState, saveData); + + char luaSaveFilename [512]; + strncpy(luaSaveFilename, fn, 512); + luaSaveFilename[512-(1+7/*strlen(".luasav")*/)] = '\0'; + strcat(luaSaveFilename, ".luasav"); + if(saveData.recordList) + { + FILE* luaSaveFile = fopen(luaSaveFilename, "wb"); + if(luaSaveFile) + { + saveData.ExportRecords(luaSaveFile); + fclose(luaSaveFile); + } + } + else + { + unlink(luaSaveFilename); + } + } + #endif + if(FCEUMOV_Mode(MOVIEMODE_INACTIVE)) FCEUSS_SaveMS(st,-1); else @@ -661,6 +699,7 @@ bool FCEUSS_LoadFP(std::istream* is, ENUM_SSLOADPARAMS params) bool FCEUSS_Load(const char *fname) { std::fstream* st; + char fn[2048]; //mbg movie - this needs to be overhauled ////this fixes read-only toggle problems @@ -677,12 +716,13 @@ bool FCEUSS_Load(const char *fname) if(fname) { st=FCEUD_UTF8_fstream(fname, "rb"); + strcpy(fn, fname); } else { - string fn = FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname); + strcpy(fn, FCEU_MakeFName(FCEUMKF_STATE,CurrentState,fname).c_str()); st=FCEUD_UTF8_fstream(fn,"rb"); - strcpy(lastLoadstateMade,fn.c_str()); + strcpy(lastLoadstateMade,fn); } if(st == NULL) @@ -712,6 +752,30 @@ bool FCEUSS_Load(const char *fname) SaveStateStatus[CurrentState]=1; } delete st; + + #ifdef _S9XLUA_H + if (!internalSaveLoad) + { + LuaSaveData saveData; + + char luaSaveFilename [512]; + strncpy(luaSaveFilename, fn, 512); + luaSaveFilename[512-(1+7/*strlen(".luasav")*/)] = '\0'; + strcat(luaSaveFilename, ".luasav"); + FILE* luaSaveFile = fopen(luaSaveFilename, "rb"); + if(luaSaveFile) + { + saveData.ImportRecords(luaSaveFile); + fclose(luaSaveFile); + } + + CallRegisteredLuaLoadFunctions(CurrentState, saveData); + } + #endif + +#ifdef WIN32 + Update_RAM_Search(); // Update_RAM_Watch() is also called. +#endif return true; } else @@ -995,7 +1059,9 @@ bool CheckBackupSaveStateExist() void BackupLoadState() { string filename = GetBackupFileName(); + internalSaveLoad = true; FCEUSS_Save(filename.c_str()); + internalSaveLoad = false; undoLS = true; } @@ -1005,7 +1071,9 @@ void LoadBackup() string filename = GetBackupFileName(); //Get backup filename if (CheckBackupSaveStateExist()) { + //internalSaveLoad = true; FCEUSS_Load(filename.c_str()); //Load it + //internalSaveLoad = false; redoLS = true; //Flag redoLoadState undoLS = false; //Flag that LoadBackup cannot be run again } diff --git a/source/fceultra/unif.cpp b/source/fceultra/unif.cpp index f22c2a9..173df78 100644 --- a/source/fceultra/unif.cpp +++ b/source/fceultra/unif.cpp @@ -129,7 +129,7 @@ static int DoMirroring(FCEUFILE *fp) { uint8 t; t=FCEU_fgetc(fp); - mirrortodo=t; + mirrortodo=t; { static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"}; @@ -266,7 +266,7 @@ static int LoadPRG(FCEUFILE *fp) else FCEU_printf("\n"); - SetupCartPRGMapping(z,malloced[z],t,0); + SetupCartPRGMapping(z,malloced[z],t,0); return(1); } @@ -463,13 +463,13 @@ int LoadUNIFChunks(FCEUFILE *fp) for(;;) { t=FCEU_fread(&uchead,1,4,fp); - if(t<4) + if(t<4) { if(t>0) - return 0; + return 0; return 1; } - if(!(FCEU_read32le(&uchead.info,fp))) + if(!(FCEU_read32le(&uchead.info,fp))) return 0; t=0; x=0; @@ -481,7 +481,7 @@ int LoadUNIFChunks(FCEUFILE *fp) if(!bfunc[x].init(fp)) return 0; t=1; - break; + break; } x++; } @@ -562,7 +562,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp) #endif FCEU_fread(&unhead,1,4,fp); if(memcmp(&unhead,"UNIF",4)) - return 0; + return 0; ResetCartMapping(); @@ -599,6 +599,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp) #ifndef GEKKO FCEU_LoadGameSave(&UNIFCart); #endif + strcpy(LoadedRomFName,name); //For the debugger list GameInterface=UNIFGI; return 1;