From cc0cb584a83a729e52ca0ab7e54beaee34072535 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 1 Dec 2019 11:47:42 -0600 Subject: [PATCH] added message when emulation stopped (EmuHalt) --- src/common/baseplatform.ts | 9 ++++++--- src/common/emu.ts | 2 +- src/ide/ui.ts | 3 ++- src/platform/nes.ts | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/common/baseplatform.ts b/src/common/baseplatform.ts index f676fe6b..87fd7f81 100644 --- a/src/common/baseplatform.ts +++ b/src/common/baseplatform.ts @@ -143,7 +143,7 @@ export interface MemoryBus { export type DebugCondition = () => boolean; export type DebugEvalCondition = (c:CpuState) => boolean; -export type BreakpointCallback = (s:EmuState) => void; +export type BreakpointCallback = (s:EmuState, msg?:string) => void; // for composite breakpoints w/ single debug function export class BreakpointList { id2bp : {[id:string] : Breakpoint} = {}; @@ -283,16 +283,19 @@ export abstract class BaseDebugPlatform extends BasePlatform { wasBreakpointHit() : boolean { return this.debugBreakState != null; } - breakpointHit(targetClock : number) { + breakpointHit(targetClock : number, reason? : string) { console.log(this.debugTargetClock, targetClock, this.debugClock, this.isStable()); this.debugTargetClock = targetClock; this.debugBreakState = this.saveState(); console.log("Breakpoint at clk", this.debugClock, "PC", this.debugBreakState.c.PC.toString(16)); this.pause(); if (this.onBreakpointHit) { - this.onBreakpointHit(this.debugBreakState); + this.onBreakpointHit(this.debugBreakState, reason); } } + haltAndCatchFire(reason : string) { + this.breakpointHit(this.debugClock, reason); + } runEval(evalfunc : DebugEvalCondition) { this.setDebugCondition( () => { if (++this.debugClock >= this.debugTargetClock && this.isStable()) { diff --git a/src/common/emu.ts b/src/common/emu.ts index e1fb962d..69711583 100644 --- a/src/common/emu.ts +++ b/src/common/emu.ts @@ -251,7 +251,7 @@ export class AnimationTimer { } catch (e) { this.running = false; this.pulsing = false; - throw e; // TODO: throw EmuHalt hides stack trace + throw e; } } if (this.useReqAnimFrame) diff --git a/src/ide/ui.ts b/src/ide/ui.ts index 8b7d0a15..252631a5 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -1123,9 +1123,10 @@ function uiDebugCallback(state: EmuState) { } function setupDebugCallback(btnid? : string) { - if (platform.setupDebug) platform.setupDebug((state:EmuState) => { + if (platform.setupDebug) platform.setupDebug((state:EmuState, msg:string) => { uiDebugCallback(state); setDebugButtonState(btnid||"pause", "stopped"); + msg && showErrorAlert([{msg:"STOPPED: " + msg, line:0}]); }); } diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 626eb8d9..d6d17e24 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -131,7 +131,7 @@ class JSNESPlatform extends Base6502Platform implements Platform, Probeable { //this.nes.ppu.showSpr0Hit = true; //this.nes.ppu.clipToTvSize = false; this.nes.stop = () => { - this.breakpointHit(this.debugClock); + this.haltAndCatchFire("Illegal instruction"); throw new EmuHalt("CPU STOPPED"); }; // insert debug hook