sync with FCEUX

This commit is contained in:
dborth 2009-11-03 08:16:57 +00:00
parent 5e7b40508d
commit ff79511368
7 changed files with 150 additions and 27 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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;

View File

@ -219,6 +219,8 @@ enum EMUCMD
EMUCMD_MISC_DISPLAY_MOVIESUBTITLES,
EMUCMD_MISC_UNDOREDOSAVESTATE,
EMUCMD_MISC_TOGGLEFULLSCREEN,
EMUCMD_TOOL_OPENRAMWATCH,
EMUCMD_TOOL_OPENRAMSEARCH,
EMUCMD_MAX
};

View File

@ -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);
}

View File

@ -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
}

View File

@ -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;