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; extern uint32 ROM_size;
static uint8 hrd_sw; static uint8 hrd_sw;
static uint8 latche; static uint8 latche[2];
static SFORMAT StateRegs[]= static SFORMAT StateRegs[]=
{ {
{&hrd_sw, 1, "DIPSW"}, {&hrd_sw, 1, "DIPSW"},
{&latche, 1, "LATCHE"}, {&latche, sizeof(latche), "LATCHE"},
{&hrd_sw, 1, "HRDSW"}, {&hrd_sw, 1, "HRDSW"},
{0} {0}
}; };
static void Sync(void) static void Sync(void)
{ {
int bank = (latche[0] >> 1 & 0x0F) |
(latche[0] >> 3 & 0x10) |
(latche[1] << 5 & 0x20);
/* if(!(latche&0x02)) /* if(!(latche&0x02))
setprg32r(0,0x8000,(latche&0x3F)>>1); setprg32r(0,0x8000,(latche&0x3F)>>1);
else else
@ -43,6 +47,8 @@ static void Sync(void)
setprg16r(0,0xC000,latche&0x3f); 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)) if(!(latche&0x20))
setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f); setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f);
else else
@ -50,13 +56,23 @@ static void Sync(void)
setprg16r(hrd_sw,0x8000,latche&0x1f); setprg16r(hrd_sw,0x8000,latche&0x1f);
setprg16r(hrd_sw,0xC000,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) static DECLFW(BMC42in1rWrite)
{ {
latche=V; latche[A & 1] = V;
Sync(); //latche = V;
Sync();
} }
static void BMC42in1rReset(void) static void BMC42in1rReset(void)
@ -67,7 +83,7 @@ static void BMC42in1rReset(void)
static void BMC42in1rPower(void) static void BMC42in1rPower(void)
{ {
latche=0; latche[0] = latche[1] = 0;
hrd_sw=0; hrd_sw=0;
setchr8(0); setchr8(0);
Sync(); Sync();
@ -92,7 +108,7 @@ static void M226Power(void)
{ {
if(ROM_size==64) if(ROM_size==64)
SetupCartPRGMapping(1,PRGptr[0]+512*1024,512,0); SetupCartPRGMapping(1,PRGptr[0]+512*1024,512,0);
latche=0; latche[0] = 0;
hrd_sw=0; hrd_sw=0;
setchr8(0); setchr8(0);
Sync(); Sync();

View File

@ -66,6 +66,8 @@
#include "drivers/win/main.h" #include "drivers/win/main.h"
#include "drivers/win/cheat.h" #include "drivers/win/cheat.h"
#include "drivers/win/texthook.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/memwatch.h"
#include "drivers/win/tracer.h" #include "drivers/win/tracer.h"
#else #else
@ -244,11 +246,9 @@ readfunc GetReadHandler(int32 a)
else else
return ARead[a]; return ARead[a];
} }
void SetReadHandler(int32 start, int32 end, readfunc func) void SetReadHandler(int32 start, int32 end, readfunc func)
{ {
int32 x; int32 x;
if(!func) if(!func)
func=ANull; func=ANull;
@ -333,7 +333,7 @@ static DECLFW(BRAML)
{ {
RAM[A]=V; RAM[A]=V;
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
FCEU_LuaWriteInform(); CallRegisteredLuaMemHook(A, 1, V, LUAMEMHOOK_WRITE);
#endif #endif
} }
@ -341,7 +341,7 @@ static DECLFW(BRAMH)
{ {
RAM[A&0x7FF]=V; RAM[A&0x7FF]=V;
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
FCEU_LuaWriteInform(); CallRegisteredLuaMemHook(A&0x7FF, 1, V, LUAMEMHOOK_WRITE);
#endif #endif
} }
@ -488,6 +488,10 @@ endlseq:
if(GameInfo->type!=GIT_NSF) if(GameInfo->type!=GIT_NSF)
FCEU_LoadGameCheats(0); FCEU_LoadGameCheats(0);
#if defined (WIN32) || defined (WIN64)
DoDebuggerRunCheck(); //Can't safely do it in loadPreferences
#endif
return GameInfo; return GameInfo;
} }
@ -637,15 +641,25 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
FCEU_UpdateInput(); FCEU_UpdateInput();
lagFlag = 1; lagFlag = 1;
#ifdef _S9XLUA_H
CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION);
#endif
if(geniestage!=1) FCEU_ApplyPeriodicCheats(); if(geniestage!=1) FCEU_ApplyPeriodicCheats();
r = FCEUPPU_Loop(skip); r = FCEUPPU_Loop(skip);
if (skip != 2) ssize=FlushEmulateSound(); //If skip = 2 we are skipping sound processing if (skip != 2) ssize=FlushEmulateSound(); //If skip = 2 we are skipping sound processing
#ifdef _S9XLUA_H
CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
#endif
#ifdef WIN32 #ifdef WIN32
//These Windows only dialogs need to be updated only once per frame so they are included here //These Windows only dialogs need to be updated only once per frame so they are included here
UpdateCheatList(); UpdateCheatList();
UpdateTextHooker(); UpdateTextHooker();
Update_RAM_Search(); // Update_RAM_Watch() is also called.
RamChange(); RamChange();
UpdateLogWindow(); UpdateLogWindow();
//FCEUI_AviVideoUpdate(XBuf); //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])return PRGptr[0][i-16];
if(i < 16+PRGsize[0]+CHRsize[0])return CHRptr[0][i-16-PRGsize[0]]; if(i < 16+PRGsize[0]+CHRsize[0])return CHRptr[0][i-16-PRGsize[0]];
return 0; return 0;
} }

View File

@ -601,6 +601,8 @@ static void LaunchPPU(void);
static void LaunchHex(void); static void LaunchHex(void);
static void LaunchTraceLogger(void); static void LaunchTraceLogger(void);
static void LaunchCodeDataLogger(void); static void LaunchCodeDataLogger(void);
static void LaunchRamWatch(void);
static void LaunchRamSearch(void);
static void FA_SkipLag(void); static void FA_SkipLag(void);
static void OpenRom(void); static void OpenRom(void);
static void CloseRom(void); static void CloseRom(void);
@ -720,7 +722,9 @@ struct EMUCMDTABLE FCEUI_CommandTable[]=
{ EMUCMD_CLOSEROM, EMUCMDTYPE_TOOL, CloseRom, 0, 0, "Close ROM", 0}, { 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_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_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])) #define NUM_EMU_CMDS (sizeof(FCEUI_CommandTable)/sizeof(FCEUI_CommandTable[0]))
@ -905,6 +909,24 @@ static void LaunchCheats(void)
#endif #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) static void FA_SkipLag(void)
{ {
frameAdvanceLagSkip ^= 1; frameAdvanceLagSkip ^= 1;

View File

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

View File

@ -443,7 +443,7 @@ static DECLFR(NSF_read)
BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]); BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]);
} }
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
FCEU_LuaWriteInform(); //CallRegisteredLuaMemHook(A, 1, V, LUAMEMHOOK_WRITE); FIXME
#endif #endif
return (CurrentSong-1); return (CurrentSong-1);
} }

View File

@ -48,6 +48,16 @@
#include "input.h" #include "input.h"
#include "zlib.h" #include "zlib.h"
#include "driver.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; 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 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 redoLS = false; //This will be true if a backupstate was loaded, meaning redoLoadState can be run
bool internalSaveLoad = false;
#define SFMDATA_SIZE (64) #define SFMDATA_SIZE (64)
static SFORMAT SFMDATA[SFMDATA_SIZE]; static SFORMAT SFMDATA[SFMDATA_SIZE];
static int SFEXINDEX; static int SFEXINDEX;
@ -437,7 +449,7 @@ bool FCEUSS_SaveMS(std::ostream* outstream, int compressionLevel)
void FCEUSS_Save(const char *fname) void FCEUSS_Save(const char *fname)
{ {
std::fstream* st = 0; std::fstream* st = 0;
char *fn; char fn[2048];
if(geniestage==1) if(geniestage==1)
{ {
@ -448,11 +460,12 @@ void FCEUSS_Save(const char *fname)
if(fname) //If filename is given use it. if(fname) //If filename is given use it.
{ {
st =FCEUD_UTF8_fstream(fname, "wb"); st =FCEUD_UTF8_fstream(fname, "wb");
strcpy(fn, fname);
} }
else //Else, generate one else //Else, generate one
{ {
//FCEU_PrintError("daCurrentState=%d",CurrentState); //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 //backup existing savestate first
if (CheckFileExists(fn)) 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 undoSS = false; //so backup made so lastSavestateMade does have a backup file, so no undo
st = FCEUD_UTF8_fstream(fn,"wb"); st = FCEUD_UTF8_fstream(fn,"wb");
free(fn);
} }
if(st == NULL) if(st == NULL)
@ -474,6 +486,32 @@ void FCEUSS_Save(const char *fname)
return; 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)) if(FCEUMOV_Mode(MOVIEMODE_INACTIVE))
FCEUSS_SaveMS(st,-1); FCEUSS_SaveMS(st,-1);
else else
@ -661,6 +699,7 @@ bool FCEUSS_LoadFP(std::istream* is, ENUM_SSLOADPARAMS params)
bool FCEUSS_Load(const char *fname) bool FCEUSS_Load(const char *fname)
{ {
std::fstream* st; std::fstream* st;
char fn[2048];
//mbg movie - this needs to be overhauled //mbg movie - this needs to be overhauled
////this fixes read-only toggle problems ////this fixes read-only toggle problems
@ -677,12 +716,13 @@ bool FCEUSS_Load(const char *fname)
if(fname) if(fname)
{ {
st=FCEUD_UTF8_fstream(fname, "rb"); st=FCEUD_UTF8_fstream(fname, "rb");
strcpy(fn, fname);
} }
else 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"); st=FCEUD_UTF8_fstream(fn,"rb");
strcpy(lastLoadstateMade,fn.c_str()); strcpy(lastLoadstateMade,fn);
} }
if(st == NULL) if(st == NULL)
@ -712,6 +752,30 @@ bool FCEUSS_Load(const char *fname)
SaveStateStatus[CurrentState]=1; SaveStateStatus[CurrentState]=1;
} }
delete st; 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; return true;
} }
else else
@ -995,7 +1059,9 @@ bool CheckBackupSaveStateExist()
void BackupLoadState() void BackupLoadState()
{ {
string filename = GetBackupFileName(); string filename = GetBackupFileName();
internalSaveLoad = true;
FCEUSS_Save(filename.c_str()); FCEUSS_Save(filename.c_str());
internalSaveLoad = false;
undoLS = true; undoLS = true;
} }
@ -1005,7 +1071,9 @@ void LoadBackup()
string filename = GetBackupFileName(); //Get backup filename string filename = GetBackupFileName(); //Get backup filename
if (CheckBackupSaveStateExist()) if (CheckBackupSaveStateExist())
{ {
//internalSaveLoad = true;
FCEUSS_Load(filename.c_str()); //Load it FCEUSS_Load(filename.c_str()); //Load it
//internalSaveLoad = false;
redoLS = true; //Flag redoLoadState redoLS = true; //Flag redoLoadState
undoLS = false; //Flag that LoadBackup cannot be run again undoLS = false; //Flag that LoadBackup cannot be run again
} }

View File

@ -129,7 +129,7 @@ static int DoMirroring(FCEUFILE *fp)
{ {
uint8 t; uint8 t;
t=FCEU_fgetc(fp); t=FCEU_fgetc(fp);
mirrortodo=t; mirrortodo=t;
{ {
static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"}; static char *stuffo[6]={"Horizontal","Vertical","$2000","$2400","\"Four-screen\"","Controlled by Mapper Hardware"};
@ -266,7 +266,7 @@ static int LoadPRG(FCEUFILE *fp)
else else
FCEU_printf("\n"); FCEU_printf("\n");
SetupCartPRGMapping(z,malloced[z],t,0); SetupCartPRGMapping(z,malloced[z],t,0);
return(1); return(1);
} }
@ -463,13 +463,13 @@ int LoadUNIFChunks(FCEUFILE *fp)
for(;;) for(;;)
{ {
t=FCEU_fread(&uchead,1,4,fp); t=FCEU_fread(&uchead,1,4,fp);
if(t<4) if(t<4)
{ {
if(t>0) if(t>0)
return 0; return 0;
return 1; return 1;
} }
if(!(FCEU_read32le(&uchead.info,fp))) if(!(FCEU_read32le(&uchead.info,fp)))
return 0; return 0;
t=0; t=0;
x=0; x=0;
@ -481,7 +481,7 @@ int LoadUNIFChunks(FCEUFILE *fp)
if(!bfunc[x].init(fp)) if(!bfunc[x].init(fp))
return 0; return 0;
t=1; t=1;
break; break;
} }
x++; x++;
} }
@ -562,7 +562,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp)
#endif #endif
FCEU_fread(&unhead,1,4,fp); FCEU_fread(&unhead,1,4,fp);
if(memcmp(&unhead,"UNIF",4)) if(memcmp(&unhead,"UNIF",4))
return 0; return 0;
ResetCartMapping(); ResetCartMapping();
@ -599,6 +599,7 @@ int UNIFLoad(const char *name, FCEUFILE *fp)
#ifndef GEKKO #ifndef GEKKO
FCEU_LoadGameSave(&UNIFCart); FCEU_LoadGameSave(&UNIFCart);
#endif #endif
strcpy(LoadedRomFName,name); //For the debugger list
GameInterface=UNIFGI; GameInterface=UNIFGI;
return 1; return 1;