Skip to content

Commit def5768

Browse files
committed
remove fflush call on every single instruction trace, which can make modern SSD go totally dysfunctional. attempt to recover from this by flushing once a frame and whenever emulation pauses, so that you have a flushed trace file while debugging or whenever the main menu is interactive.
1 parent 4ed4757 commit def5768

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/driver.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ void FCEUD_DebugBreakpoint(int bp_num);
330330
///the driver should log the current instruction, if it wants (we should move the code in the win driver that does this to the shared area)
331331
void FCEUD_TraceInstruction(uint8 *opcode, int size);
332332

333+
///the driver should flush its trace log
334+
void FCEUD_FlushTrace();
335+
333336
///the driver might should update its NTView (only used if debugging support is compiled in)
334337
void FCEUD_UpdateNTView(int scanline, bool drawall);
335338

src/drivers/win/tracer.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,12 @@ void BeginLoggingSequence(void)
732732
return;
733733
}
734734

735+
void FCEUD_FlushTrace()
736+
{
737+
if(LOG_FP)
738+
fflush(LOG_FP);
739+
}
740+
735741
//todo: really speed this up
736742
void FCEUD_TraceInstruction(uint8 *opcode, int size)
737743
{
@@ -975,7 +981,6 @@ void OutputLogLine(const char *str, std::vector<uint16>* addressesLog, bool add_
975981
fputs(str, LOG_FP);
976982
if (add_newline)
977983
fputs("\n", LOG_FP);
978-
fflush(LOG_FP);
979984
} else
980985
{
981986
if (add_newline)

src/fceu.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski
808808

809809
if (skip != 2) ssize = FlushEmulateSound(); //If skip = 2 we are skipping sound processing
810810

811+
//flush tracer once a frame, since we're likely to end up back at a user interaction loop after this with emulation paused
812+
FCEUD_FlushTrace();
813+
811814
#ifdef _S9XLUA_H
812815
CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION);
813816
#endif
@@ -1228,12 +1231,16 @@ void FCEUI_ClearEmulationFrameStepped()
12281231
//ideally maybe we shouldnt be using this, but i need it for quick merging
12291232
void FCEUI_SetEmulationPaused(int val) {
12301233
EmulationPaused = val;
1234+
if(EmulationPaused)
1235+
FCEUD_FlushTrace();
12311236
}
12321237

12331238
void FCEUI_ToggleEmulationPause(void)
12341239
{
12351240
EmulationPaused = (EmulationPaused & EMULATIONPAUSED_PAUSED) ^ EMULATIONPAUSED_PAUSED;
12361241
DebuggerWasUpdated = false;
1242+
if(EmulationPaused)
1243+
FCEUD_FlushTrace();
12371244
}
12381245

12391246
void FCEUI_FrameAdvanceEnd(void) {

0 commit comments

Comments
 (0)