From e83fdd999edf23bebd6a05e4dea402799a0253e4 Mon Sep 17 00:00:00 2001 From: Will Scullin Date: Sat, 13 Mar 2021 16:08:24 -0800 Subject: [PATCH] Make breakpoints behave better --- js/apple2.ts | 2 ++ js/cards/smartport.ts | 2 +- js/cpu6502.ts | 8 ++++++-- js/debugger.ts | 32 +++++++++++++++++++++++--------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/js/apple2.ts b/js/apple2.ts index 2cb79bd..8e3cc8f 100644 --- a/js/apple2.ts +++ b/js/apple2.ts @@ -114,6 +114,7 @@ export class Apple2 implements Restorable, DebuggerContainer { * `runAnimationFrame` will be non-null. */ run() { + this.paused = false; if (this.runTimer || this.runAnimationFrame) { return; // already running } @@ -170,6 +171,7 @@ export class Apple2 implements Restorable, DebuggerContainer { } stop() { + this.paused = true; if (this.runTimer) { clearInterval(this.runTimer); } diff --git a/js/cards/smartport.ts b/js/cards/smartport.ts index a90d9d5..a9116b8 100644 --- a/js/cards/smartport.ts +++ b/js/cards/smartport.ts @@ -113,8 +113,8 @@ export default class SmartPort implements Card, Restorable { debug('DumbPort card'); } else { debug('SmartPort card'); + this.rom = smartPortRom; } - this.rom = smartPortRom; } private decodeDisk(unit: number, disk: BlockDevice) { diff --git a/js/cpu6502.ts b/js/cpu6502.ts index 9170c3d..cc492e8 100644 --- a/js/cpu6502.ts +++ b/js/cpu6502.ts @@ -1012,7 +1012,9 @@ export default class CPU6502 { this.sync = false; op.op(op.modeFn); - cb?.(this); + if (cb?.(this)) { + return; + } } } @@ -1036,7 +1038,9 @@ export default class CPU6502 { this.sync = false; op.op(op.modeFn); - cb?.(this); + if (cb?.(this)) { + return; + } } } diff --git a/js/debugger.ts b/js/debugger.ts index bf646b3..6823782 100644 --- a/js/debugger.ts +++ b/js/debugger.ts @@ -33,19 +33,28 @@ export default class Debugger { if (this.breakpoints.get(info.pc)?.(info)) { debug('breakpoint', this.printDebugInfo(info)); this.container.stop(); - return; + return true; } if (this.verbose) { debug(this.printDebugInfo(info)); } else { - this.trace.push(info); - if (this.trace.length > this.maxTrace) { - this.trace.shift(); - } + this.updateTrace(info); } }); } + break = () => { + this.container.stop(); + } + + step = () => { + this.cpu.step(() => { + const info = this.cpu.getDebugInfo(); + debug(this.printDebugInfo(info)); + this.updateTrace(info); + }); + } + continue = () => { this.container.run(); } @@ -121,10 +130,8 @@ export default class Debugger { if (debugInfo === undefined) { debugInfo = this.cpu.getDebugInfo(); } - const { pc, ar, xr, yr, sr, sp } = debugInfo; + const { ar, xr, yr, sr, sp } = debugInfo; return [ - toHex(pc, 4), - '- ', ' A=' + toHex(ar), ' X=' + toHex(xr), ' Y=' + toHex(yr), @@ -180,6 +187,13 @@ export default class Debugger { return results; } + private updateTrace(info: DebugInfo) { + this.trace.push(info); + if (this.trace.length > this.maxTrace) { + this.trace.shift(); + } + } + private padWithSymbol(pc: word): string { const padding = ' '; const symbol = this.symbols[pc]; @@ -233,7 +247,7 @@ export default class Debugger { if (off > 127) { off -= 256; } - pc += off + 1; + pc += off + 2; result += '' + toHexOrSymbol(pc, 4) + ' (' + off + ')'; } break;