Make breakpoints behave better

This commit is contained in:
Will Scullin 2021-03-13 16:08:24 -08:00
parent b4d6e95ec2
commit e83fdd999e
No known key found for this signature in database
GPG Key ID: 26DCD1042C6638CD
4 changed files with 32 additions and 12 deletions

View File

@ -114,6 +114,7 @@ export class Apple2 implements Restorable<State>, DebuggerContainer {
* `runAnimationFrame` will be non-null. * `runAnimationFrame` will be non-null.
*/ */
run() { run() {
this.paused = false;
if (this.runTimer || this.runAnimationFrame) { if (this.runTimer || this.runAnimationFrame) {
return; // already running return; // already running
} }
@ -170,6 +171,7 @@ export class Apple2 implements Restorable<State>, DebuggerContainer {
} }
stop() { stop() {
this.paused = true;
if (this.runTimer) { if (this.runTimer) {
clearInterval(this.runTimer); clearInterval(this.runTimer);
} }

View File

@ -113,9 +113,9 @@ export default class SmartPort implements Card, Restorable<SmartPortState> {
debug('DumbPort card'); debug('DumbPort card');
} else { } else {
debug('SmartPort card'); debug('SmartPort card');
}
this.rom = smartPortRom; this.rom = smartPortRom;
} }
}
private decodeDisk(unit: number, disk: BlockDevice) { private decodeDisk(unit: number, disk: BlockDevice) {
this.disks[unit] = []; this.disks[unit] = [];

View File

@ -1012,7 +1012,9 @@ export default class CPU6502 {
this.sync = false; this.sync = false;
op.op(op.modeFn); op.op(op.modeFn);
cb?.(this); if (cb?.(this)) {
return;
}
} }
} }
@ -1036,7 +1038,9 @@ export default class CPU6502 {
this.sync = false; this.sync = false;
op.op(op.modeFn); op.op(op.modeFn);
cb?.(this); if (cb?.(this)) {
return;
}
} }
} }

View File

@ -33,16 +33,25 @@ export default class Debugger {
if (this.breakpoints.get(info.pc)?.(info)) { if (this.breakpoints.get(info.pc)?.(info)) {
debug('breakpoint', this.printDebugInfo(info)); debug('breakpoint', this.printDebugInfo(info));
this.container.stop(); this.container.stop();
return; return true;
} }
if (this.verbose) { if (this.verbose) {
debug(this.printDebugInfo(info)); debug(this.printDebugInfo(info));
} else { } else {
this.trace.push(info); this.updateTrace(info);
if (this.trace.length > this.maxTrace) {
this.trace.shift();
} }
});
} }
break = () => {
this.container.stop();
}
step = () => {
this.cpu.step(() => {
const info = this.cpu.getDebugInfo();
debug(this.printDebugInfo(info));
this.updateTrace(info);
}); });
} }
@ -121,10 +130,8 @@ export default class Debugger {
if (debugInfo === undefined) { if (debugInfo === undefined) {
debugInfo = this.cpu.getDebugInfo(); debugInfo = this.cpu.getDebugInfo();
} }
const { pc, ar, xr, yr, sr, sp } = debugInfo; const { ar, xr, yr, sr, sp } = debugInfo;
return [ return [
toHex(pc, 4),
'- ',
' A=' + toHex(ar), ' A=' + toHex(ar),
' X=' + toHex(xr), ' X=' + toHex(xr),
' Y=' + toHex(yr), ' Y=' + toHex(yr),
@ -180,6 +187,13 @@ export default class Debugger {
return results; return results;
} }
private updateTrace(info: DebugInfo) {
this.trace.push(info);
if (this.trace.length > this.maxTrace) {
this.trace.shift();
}
}
private padWithSymbol(pc: word): string { private padWithSymbol(pc: word): string {
const padding = ' '; const padding = ' ';
const symbol = this.symbols[pc]; const symbol = this.symbols[pc];
@ -233,7 +247,7 @@ export default class Debugger {
if (off > 127) { if (off > 127) {
off -= 256; off -= 256;
} }
pc += off + 1; pc += off + 2;
result += '' + toHexOrSymbol(pc, 4) + ' (' + off + ')'; result += '' + toHexOrSymbol(pc, 4) + ' (' + off + ')';
} }
break; break;