From 7e2bf32a6f2067c337a8297da5c5ddd3b950bde2 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Wed, 20 Mar 2019 20:45:03 -0400 Subject: [PATCH] made EmuHalt class for NES trap --- doc/notes.txt | 3 ++- src/emu.ts | 13 ++++++++++++- src/pixed/pixeleditor.ts | 1 + src/platform/nes.ts | 14 +++----------- src/ui.ts | 20 ++++++++++++-------- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/doc/notes.txt b/doc/notes.txt index edd4a5f9..a63d24c9 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -91,12 +91,13 @@ TODO: - profiler restarts when paused - it's pretty easy to add a new file named like a library file (bcd.c) - put globals into view/controller objects -- cr/lf in files +- cr/lf in uploaded files? - upload binary files doesn't do what's expected, changing pulldown and whatnot - chrome autostart audio: https://github.com/processing/p5.js-sound/issues/249 - show player controls for each platform, allow touch support, navigator.getGamepads - better undo/diff for mistakes? - get rid of "illegal PC" instruction, replace with status msg +- ide bug/feature visualizer for sponsors diff --git a/src/emu.ts b/src/emu.ts index 3606621c..78d3ca0a 100644 --- a/src/emu.ts +++ b/src/emu.ts @@ -215,6 +215,9 @@ export class RAM { } } +export class EmuHalt extends Error { +} + export class AnimationTimer { callback; @@ -234,7 +237,15 @@ export class AnimationTimer { } scheduleFrame(msec:number) { - var fn = () => { this.nextFrame(); } + var fn = () => { + try { + this.nextFrame(); + } catch (e) { + this.running = false; + this.pulsing = false; + throw e; + } + } if (this.useReqAnimFrame) window.requestAnimationFrame(fn); else diff --git a/src/pixed/pixeleditor.ts b/src/pixed/pixeleditor.ts index 81b5f2be..e5898daa 100644 --- a/src/pixed/pixeleditor.ts +++ b/src/pixed/pixeleditor.ts @@ -662,6 +662,7 @@ export class PixelTextDataNode extends PixelNode { } updateRight() { var datastr = this.text.substring(this.start, this.end); + datastr = convertToHexStatements(datastr); // TODO? var words = parseHexWords(datastr); this.output = new Uint8Array(words); // TODO: 16/32? } diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 9c4d75e2..c640630b 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -1,7 +1,7 @@ "use strict"; import { Platform, Base6502Platform, BaseMAMEPlatform, getOpcodeMetadata_6502, cpuStateToLongString_6502, getToolForFilename_6502, dumpStackToString, ProfilerOutput } from "../baseplatform"; -import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, dumpRAM, KeyFlags } from "../emu"; +import { PLATFORMS, RAM, newAddressDecoder, padBytes, noise, setKeyboardFromMap, AnimationTimer, RasterVideo, Keys, makeKeycodeMap, dumpRAM, KeyFlags, EmuHalt } from "../emu"; import { hex, lpad, lzgmini, byteArrayToString } from "../util"; import { CodeAnalyzer_nes } from "../analysis"; import { SampleAudio } from "../audio"; @@ -126,9 +126,8 @@ const _JSNESPlatform = function(mainElement) { //nes.ppu.clipToTvSize = false; nes.stop = () => { // TODO: trigger breakpoint - this.pause(); console.log(nes.cpu.toJSON()); - throw ("CPU STOPPED @ PC $" + hex(nes.cpu.REG_PC)); + throw new EmuHalt("CPU STOPPED @ PC $" + hex(nes.cpu.REG_PC)); }; // insert debug hook nes.cpu._emulate = nes.cpu.emulate; @@ -148,14 +147,7 @@ const _JSNESPlatform = function(mainElement) { } advance(novideo : boolean) { - try { - nes.frame(); - } catch (e) { - // TODO? - alert(e); - console.log(e); - this.breakpointHit(this.debugClock); - } + nes.frame(); } updateDebugViews() { diff --git a/src/ui.ts b/src/ui.ts index d7ef0df9..c4fcaece 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -8,7 +8,7 @@ import { CodeProject } from "./project"; import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "./workertypes"; import { ProjectWindows } from "./windows"; import { Platform, Preset, DebugSymbols, DebugEvalCondition } from "./baseplatform"; -import { PLATFORMS } from "./emu"; +import { PLATFORMS, EmuHalt } from "./emu"; import * as Views from "./views"; import { createNewPersistentStore } from "./store"; import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, @@ -1292,13 +1292,17 @@ var qs = (function (a : string[]) { function installErrorHandler() { if (typeof window.onerror == "object") { window.onerror = function (msgevent, url, line, col, error) { - console.log(msgevent, url, line, col); - console.log(error); - ga('send', 'exception', { - 'exDescription': msgevent + " " + url + " " + " " + line + ":" + col + ", " + error, - 'exFatal': true - }); - alert(msgevent+""); + var msgstr = msgevent+""; + console.log(msgevent, url, line, col, error); + if (error instanceof EmuHalt || msgstr.indexOf("CPU STOP") >= 0) { + showErrorAlert([ {msg:msgstr, line:0} ]); + } else { + ga('send', 'exception', { + 'exDescription': msgevent + " " + url + " " + " " + line + ":" + col + ", " + error, + 'exFatal': true + }); + alert(msgevent+""); + } _pause(); }; }