Skip to content

Commit

Permalink
Fixes in debugger.
Browse files Browse the repository at this point in the history
fvdhoef committed Oct 22, 2023
1 parent 8468edb commit fef2a6f
Showing 3 changed files with 49 additions and 32 deletions.
63 changes: 35 additions & 28 deletions System/emulator/EmuState.cpp
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ void EmuState::reset() {
emuMode = Em_Running;
}

unsigned EmuState::emulate() {
int EmuState::cpuEmulate() {
if (tmpBreakpoint == z80ctx.PC) {
tmpBreakpoint = -1;
emuMode = EmuState::Em_Halted;
@@ -75,6 +75,8 @@ unsigned EmuState::emulate() {
for (int i = 0; i < (int)breakpoints.size(); i++) {
auto &bp = breakpoints[i];
if (bp.enabled && bp.type == 0 && bp.onX && z80ctx.PC == bp.value && bp.value != lastBpAddress) {
printf("Halted! %d\n", lastBpAddress);

emuMode = EmuState::Em_Halted;
lastBp = i;
lastBpAddress = bp.value;
@@ -84,8 +86,6 @@ unsigned EmuState::emulate() {
}
lastBp = -1;

unsigned resultFlags = 0;

bool haltAfterThis = false;
if (haltAfterRet >= 0) {
z80ctx.tstates = 0;
@@ -104,33 +104,43 @@ unsigned EmuState::emulate() {
}
}

int delta = 0;
int count = emuState.sysCtrlTurbo ? 2 : 1;
for (int i = 0; i < count; i++) {
z80ctx.tstates = 0;
Z80Execute(&z80ctx);
delta += z80ctx.tstates * 2;
z80ctx.tstates = 0;
Z80Execute(&z80ctx);
int delta = z80ctx.tstates * 2;

if (traceEnable && (!z80ctx.halted || !prevHalted)) {
cpuTrace.emplace_back();
auto &entry = cpuTrace.back();
entry.pc = z80ctx.PC;
entry.r1 = z80ctx.R1;
entry.r2 = z80ctx.R2;
if (traceEnable && (!z80ctx.halted || !prevHalted)) {
cpuTrace.emplace_back();
auto &entry = cpuTrace.back();
entry.pc = z80ctx.PC;
entry.r1 = z80ctx.R1;
entry.r2 = z80ctx.R2;

z80ctx.tstates = 0;
Z80Debug(&z80ctx, entry.bytes, entry.instrStr);
z80ctx.tstates = 0;
Z80Debug(&z80ctx, entry.bytes, entry.instrStr);

while ((int)cpuTrace.size() > traceDepth) {
cpuTrace.pop_front();
}
while ((int)cpuTrace.size() > traceDepth) {
cpuTrace.pop_front();
}
prevHalted = z80ctx.halted;
}
delta /= count;
prevHalted = z80ctx.halted;

int prevLineHalfCycles = lineHalfCycles;
if (haltAfterThis) {
emuMode = EmuState::Em_Halted;
}
return delta;
}

unsigned EmuState::emulate() {
unsigned resultFlags = 0;

int delta = cpuEmulate();
if (emuState.sysCtrlTurbo) {
if (emuMode != EmuState::Em_Halted)
delta += cpuEmulate();
delta /= 2;
}

int prevLineHalfCycles = lineHalfCycles;
lineHalfCycles += delta;
sampleHalfCycles += delta;

@@ -186,11 +196,8 @@ unsigned EmuState::emulate() {
resultFlags |= ERF_NEW_AUDIO_SAMPLE;
}

lastBpAddress = -1;

if (haltAfterThis) {
emuMode = EmuState::Em_Halted;
}
if (delta)
lastBpAddress = -1;

return resultFlags;
}
1 change: 1 addition & 0 deletions System/emulator/EmuState.h
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ struct EmuState {
static void ioWrite(size_t param, uint16_t addr, uint8_t data);

unsigned emulate();
int cpuEmulate();
unsigned audioLeft = 0;
unsigned audioRight = 0;

17 changes: 13 additions & 4 deletions System/emulator/UI/UI.cpp
Original file line number Diff line number Diff line change
@@ -607,10 +607,19 @@ void UI::wndCpuState(bool *p_open) {
Z80Debug(&emuState.z80ctx, tmp1, tmp2);

unsigned instLen = (unsigned)strlen(tmp1) / 3;
bool isCall = (strncmp(tmp2, "CALL ", 5) == 0);
bool isRst = (strncmp(tmp2, "RST ", 4) == 0);

if (isCall || isRst) {
bool doStepOver =
(strncmp(tmp2, "CALL ", 5) == 0 ||
strncmp(tmp2, "RST ", 4) == 0 ||
strcmp(tmp2, "CPDR") == 0 ||
strcmp(tmp2, "CPIR") == 0 ||
strcmp(tmp2, "INDR") == 0 ||
strcmp(tmp2, "INIR") == 0 ||
strcmp(tmp2, "LDDR") == 0 ||
strcmp(tmp2, "LDIR") == 0 ||
strcmp(tmp2, "OTDR") == 0 ||
strcmp(tmp2, "OTIR") == 0);

if (doStepOver) {
emuState.tmpBreakpoint = emuState.z80ctx.PC + instLen;

if (strncmp(tmp2, "RST 8H", 6) == 0 ||

0 comments on commit fef2a6f

Please sign in to comment.