Skip to content

Commit

Permalink
Merge pull request #92 from dshadoff/feature_stepby_scanline_or_displ…
Browse files Browse the repository at this point in the history
…ay_frame

Add feature to step by scanline or display frame ( #74 )
  • Loading branch information
pceDev16 authored Jul 3, 2022
2 parents a714473 + e20505a commit a813031
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 6 deletions.
67 changes: 63 additions & 4 deletions mednafen/src/drivers/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "prompt.h"
#include "video.h"

bool DebugHSyncFlag = false;
bool DebugVSyncFlag = false;

static MemDebugger* memdbg = NULL;
static std::unique_ptr<FileStream> TraceLog;
static std::string TraceLogSpec;
Expand All @@ -47,6 +50,8 @@ static bool NeedPCBPToggle;
static int NeedStep; // 0 =, 1 = , 2 =
static int NeedRun;
static bool InSteppingMode;
static bool WaitForVSYNC = false;
static bool WaitForHSYNC = false;

static std::vector<uint32> PCBreakPoints;
static std::string ReadBreakpoints, IOReadBreakpoints, AuxReadBreakpoints;
Expand Down Expand Up @@ -164,7 +169,7 @@ static void UpdateCoreHooks(void)
HaltOnAltD = MDFN_GetSettingB("debugger.haltondebug");

bool BPInUse = PCBreakPoints.size() || ReadBreakpoints.size() || WriteBreakpoints.size() || IOReadBreakpoints.size() ||
IOWriteBreakpoints.size() || AuxReadBreakpoints.size() || AuxWriteBreakpoints.size() || OpBreakpoints.size() || HaltOnAltD;
IOWriteBreakpoints.size() || AuxReadBreakpoints.size() || AuxWriteBreakpoints.size() || OpBreakpoints.size() || HaltOnAltD || WaitForHSYNC || WaitForVSYNC;
bool CPUCBNeeded = BPInUse || TraceLog || InSteppingMode || (NeedStep == 2);

CurGame->Debugger->EnableBranchTrace(BPInUse || TraceLog || IsActive);
Expand All @@ -182,7 +187,29 @@ static void UpdatePCBreakpoints(void)
UpdateCoreHooks();
}

static INLINE bool IsPCBreakPoint(uint32 A)
bool IsVSYNCBreakPoint()
{
bool VSync_Trigger = Debugger_GT_VSyncIsSet();
Debugger_GT_ResetVSync();

if (WaitForVSYNC && VSync_Trigger)
return(true);
else
return(false);
}

bool IsHSYNCBreakPoint()
{
bool HSync_Trigger = Debugger_GT_HSyncIsSet();
Debugger_GT_ResetHSync();

if (WaitForHSYNC && HSync_Trigger)
return(true);
else
return(false);
}

INLINE bool IsPCBreakPoint(uint32 A)
{
unsigned int max = PCBreakPoints.size();

Expand Down Expand Up @@ -1479,6 +1506,13 @@ static void CPUCallback(uint32 PC, bool bpoint)
DoTraceLog(PC);
}

INLINE void Debugger_GT_SetHSync(void) { DebugHSyncFlag = true; }
INLINE void Debugger_GT_ResetHSync(void) { DebugHSyncFlag = false; }
INLINE bool Debugger_GT_HSyncIsSet(void) { return(DebugHSyncFlag); }

INLINE void Debugger_GT_SetVSync(void) { DebugVSyncFlag = true; }
INLINE void Debugger_GT_ResetVSync(void) { DebugVSyncFlag = false; };
INLINE bool Debugger_GT_VSyncIsSet(void) { return(DebugVSyncFlag); }

// Function called from game thread, input driver code.
void Debugger_GT_ForceStepIfStepping(void)
Expand Down Expand Up @@ -1810,8 +1844,29 @@ void Debugger_GT_Event(const SDL_Event *event)
break;

case SDLK_s:
NeedStep = 2;
UpdateCoreHooks();
if(event->key.keysym.mod & KMOD_SHIFT)
{
Debugger_GT_ResetVSync();
Debugger_GT_ResetHSync();
WaitForHSYNC = true;
WaitForVSYNC = false;
NeedRun = true;
}
else if(event->key.keysym.mod & KMOD_CTRL)
{
Debugger_GT_ResetVSync();
Debugger_GT_ResetHSync();
WaitForHSYNC = false;
WaitForVSYNC = true;
NeedRun = true;
}
else
{
WaitForHSYNC = false;
WaitForVSYNC = false;
NeedStep = 2;
UpdateCoreHooks();
}
break;

case SDLK_w:
Expand Down Expand Up @@ -1869,7 +1924,11 @@ void Debugger_GT_Event(const SDL_Event *event)
PromptTAKC = event->key.keysym.sym;
}
else if(InSteppingMode)
{
WaitForHSYNC = false;
WaitForVSYNC = false;
NeedRun = true;
}
break;

case SDLK_l:
Expand Down
23 changes: 23 additions & 0 deletions mednafen/src/drivers/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ void Debugger_GT_ForceSteppingMode(void);
void Debugger_GT_ForceStepIfStepping(void); // For synchronizations with save state loading and reset/power toggles.
void Debugger_GT_SyncDisToPC(void); // Synch disassembly address to current PC/IP/whatever.

void Debugger_GT_SetHSync(void);
void Debugger_GT_ResetHSync(void);
bool Debugger_GT_HSyncIsSet(void);

void Debugger_GT_SetVSync(void);
void Debugger_GT_ResetVSync(void);
bool Debugger_GT_VSyncIsSet(void);

bool IsVSYNCBreakPoint(void);
bool IsHSYNCBreakPoint(void);

// Must be called in a specific place in the game thread's execution path.
void Debugger_GTR_PassBlit(void);

Expand All @@ -57,6 +68,18 @@ static INLINE bool Debugger_GT_IsInSteppingMode(void) { return(false); }
static INLINE void Debugger_GT_ForceSteppingMode(void) { }
static INLINE void Debugger_GT_ForceStepIfStepping(void) { }
static INLINE void Debugger_GT_SyncDisToPC(void) { }

static INLINE void Debugger_GT_SetHSync(void) { }
static INLINE void Debugger_GT_ResetHSync(void) { }
static INLINE bool Debugger_GT_HSyncSet(void) { return(false); }

static INLINE void Debugger_GT_SetVSync(void) { }
static INLINE void Debugger_GT_ResetVSync(void) { }
static INLINE bool Debugger_GT_VSyncSet(void) { return(false); }

static INLINE bool IsVSYNCBreakPoint(void) { }
static INLINE bool IsHSYNCBreakPoint(void) { }

static INLINE void Debugger_GTR_PassBlit(void) { }
static INLINE void Debugger_MT_DrawToScreen(const MDFN_PixelFormat& pf, signed screen_w, signed screen_h) { }
static INLINE bool Debugger_IsActive(void) { return(false); }
Expand Down
2 changes: 1 addition & 1 deletion mednafen/src/hw_video/huc6270/vdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ class VDC
int HPhase, VPhase;
int HNextEvent;
int32 HPhaseCounter, VPhaseCounter;
int32 Scanline_from_VSYNC;
uint32 Scanline_from_VSYNC;

int32 sprite_cg_fetch_counter;

Expand Down
6 changes: 5 additions & 1 deletion mednafen/src/pce/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
#define EX_GETFNT 0xE060
#define EX_VSYNC 0xE07B

extern bool IsHSYNCBreakPoint();
extern bool IsVSYNCBreakPoint();


namespace MDFN_IEN_PCE
{

Expand Down Expand Up @@ -378,7 +382,7 @@ static bool CPUHandler(uint32 PC)

PCE_InDebug++;

FoundBPoint = TestPCBP(PC) | TestOpBP(HuCPU.PeekLogical(PC));
FoundBPoint = TestPCBP(PC) | TestOpBP(HuCPU.PeekLogical(PC)) | IsVSYNCBreakPoint() | IsHSYNCBreakPoint();

if(NeedExecSimu)
TestRWBP();
Expand Down
7 changes: 7 additions & 0 deletions mednafen/src/pce/vce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "pcecd.h"
#include <trio/trio.h>

extern bool DebugHSyncFlag;
extern bool DebugVSyncFlag;

namespace MDFN_IEN_PCE
{

Expand Down Expand Up @@ -482,9 +485,13 @@ INLINE void VCE::SyncSub(int32 clocks)
{
scanline = 0;
framenum++;
DebugVSyncFlag = true;
}
else
{
scanline++;
DebugHSyncFlag = true;
}

if(scanline == 14 + 240) // does this need to be 242 as well?
FrameDone = true;
Expand Down

0 comments on commit a813031

Please sign in to comment.