From 0e4ed8ce213303572676762dcf7c58a6dde744a8 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Fri, 23 Oct 2020 19:34:19 -0500 Subject: [PATCH] haltEmulation() instead of EmuHalt --- src/ide/ui.ts | 11 ++++++++--- src/platform/basic.ts | 18 ++++++++++++++++++ src/platform/devel.ts | 9 +++++---- src/platform/nes.ts | 2 +- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/ide/ui.ts b/src/ide/ui.ts index 28d49a41..a08b5080 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -1934,13 +1934,18 @@ function globalErrorHandler(msgevent) { } else { var err = msgevent.error || msgevent.reason; if (err != null && err instanceof EmuHalt) { - setDebugButtonState("pause", "stopped"); - emulationHalted(err); - // TODO: reset platform? + haltEmulation(err); } } } +export function haltEmulation(err?: EmuHalt) { + console.log("haltEmulation"); + _pause(); + emulationHalted(err); + // TODO: reset platform? +} + // catch errors function installErrorHandler() { window.addEventListener('error', globalErrorHandler); diff --git a/src/platform/basic.ts b/src/platform/basic.ts index 4c9fc010..c9c172ba 100644 --- a/src/platform/basic.ts +++ b/src/platform/basic.ts @@ -7,6 +7,8 @@ import { BASICRuntime } from "../common/basic/runtime"; import { BASICProgram } from "../common/basic/compiler"; import { TeleTypeWithKeyboard } from "../common/teletype"; import { lpad } from "../common/util"; +import { FileData } from "../common/workertypes"; +import { haltEmulation } from "../ide/ui"; // TODO: make this a callback const BASIC_PRESETS = [ { id: 'hello.bas', name: 'Hello' }, @@ -31,6 +33,8 @@ class BASICPlatform implements Platform { tty: TeleTypeWithKeyboard; hotReload: boolean = true; animcount: number = 0; + internalFiles : {[path:string] : FileData} = {}; + transcript: string[]; constructor(mainElement: HTMLElement) { //super(); @@ -82,6 +86,7 @@ class BASICPlatform implements Platform { // TODO: why null sometimes? this.animcount = 0; // exit advance loop when printing this.tty.print(s); + this.transcript.push(s); } this.runtime.resume = this.resume.bind(this); } @@ -106,6 +111,7 @@ class BASICPlatform implements Platform { this.pause(); if (this.runtime.exited) { this.exitmsg(); + this.didExit(); } } this.clock++; @@ -145,6 +151,7 @@ class BASICPlatform implements Platform { this.tty.clear(); this.runtime.reset(); this.clock = 0; + this.transcript = []; } pause(): void { @@ -289,6 +296,17 @@ class BASICPlatform implements Platform { return false; } } + readFile(path: string) : FileData { + return this.internalFiles[path]; + } + writeFile(path: string, data: FileData) : boolean { + this.internalFiles[path] = data; + return true; + } + didExit() { + this.internalFiles['stdout.txt'] = this.transcript.join(""); + haltEmulation(); + } } // diff --git a/src/platform/devel.ts b/src/platform/devel.ts index 83eeaabf..ed14860b 100644 --- a/src/platform/devel.ts +++ b/src/platform/devel.ts @@ -4,9 +4,9 @@ import { EmuHalt, PLATFORMS } from "../common/emu"; import { Devel6502 } from "../machine/devel"; import { Base6502MachinePlatform } from "../common/baseplatform"; import { SerialIOInterface } from "../common/devices"; -import { convertDataToUint8Array, hex } from "../common/util"; +import { byteArrayToString, convertDataToUint8Array, hex } from "../common/util"; import { TeleType } from "../common/teletype"; -import { emulationHalted, loadScript } from "../ide/ui"; +import { haltEmulation, loadScript } from "../ide/ui"; var DEVEL_6502_PRESETS = [ {id:'hello.dasm', name:'Hello World (ASM)'}, @@ -144,8 +144,9 @@ class Devel6502Platform extends Base6502MachinePlatform implements Pl advance(novideo: boolean) { if (this.isBlocked()) { - this.internalFiles['serialout.dat'] = new Uint8Array(this.serial.outputBytes); - throw new EmuHalt(null); // TODO: throws nasty exception + this.internalFiles['serialout.dat'] = byteArrayToString(this.serial.outputBytes); + haltEmulation(); + return 0; } return super.advance(novideo); } diff --git a/src/platform/nes.ts b/src/platform/nes.ts index 5bc191d8..7a4ec02c 100644 --- a/src/platform/nes.ts +++ b/src/platform/nes.ts @@ -132,7 +132,7 @@ class JSNESPlatform extends Base6502Platform implements Platform, Probeable { //this.nes.ppu.clipToTvSize = false; this.nes.stop = () => { this.haltAndCatchFire("Illegal instruction"); - throw new EmuHalt("CPU STOPPED"); + throw new EmuHalt("CPU STOPPED"); //TODO: haltEmulation() }; // insert debug hook this.nes.cpu._emulate = this.nes.cpu.emulate;