import { Platform } from "../common/baseplatform"; import { EmuHalt, PLATFORMS } from "../common/emu"; import { Devel6502 } from "../machine/devel"; import { Base6502MachinePlatform } from "../common/baseplatform"; import { SerialIOInterface } from "../common/devices"; import { byteArrayToString, convertDataToUint8Array } from "../common/util"; import { TeleType } from "../common/teletype"; import { haltEmulation } from "../ide/ui"; var DEVEL_6502_PRESETS = [ {id:'hello.dasm', name:'Hello World (ASM)'}, ]; class SerialInOutViewer { div : HTMLElement; tty : TeleType; constructor(div: HTMLElement) { div.style.overflowY = 'auto'; var gameport = $('
').appendTo(div); $('Serial Output
').appendTo(gameport); var windowport = $('').appendTo(gameport); this.div = windowport[0]; } start() { this.tty = new TeleType(this.div, false); //this.tty.ncols = 40; } reset() { this.tty.clear(); } saveState() { return this.tty.saveState(); } loadState(state) { this.tty.loadState(state); } } function byteToASCII(b: number) : string { if (b == 10) return ''; if (b < 32) return String.fromCharCode(b + 0x2400); else return String.fromCharCode(b); } export class SerialTestHarness implements SerialIOInterface { viewer : SerialInOutViewer; bufferedRead : boolean = true; cyclesPerByte = 1000000/(57600/8); // 138.88888 cycles maxOutputBytes = 4096; inputBytes : Uint8Array; outputBytes : number[]; inputIndex : number; clk : number; bufin : string; clearToSend(): boolean { return this.outputBytes.length < this.maxOutputBytes; } sendByte(b: number) { if (this.clearToSend()) { this.outputBytes.push(b); this.viewer.tty.addtext(byteToASCII(b), 2|32); if (b == 10) this.viewer.tty.newline(); if (!this.clearToSend()) { this.viewer.tty.newline(); this.viewer.tty.addtext("⚠️ OUTPUT BUFFER FULL ⚠️", 4); } } } byteAvailable(): boolean { return this.readIndex() > this.inputIndex; } recvByte(): number { var index = this.readIndex(); this.inputIndex = index; var b = (this.inputBytes && this.inputBytes[index]) | 0; //this.bufin += byteToASCII(b); this.viewer.tty.addtext(byteToASCII(b), 2|16); if (b == 10) this.viewer.tty.newline(); return b; } readIndex(): number { return this.bufferedRead ? (this.inputIndex+1) : Math.floor(this.clk / this.cyclesPerByte); } reset() { this.inputIndex = -1; this.clk = 0; this.outputBytes = []; this.bufin = ''; } advance(clocks: number) { this.clk += clocks; } saveState() { return { clk: this.clk, idx: this.inputIndex, out: this.outputBytes.slice() } } loadState(state) { this.clk = state.clk; this.inputIndex = state.idx; this.outputBytes = state.out.slice(); } } class Devel6502Platform extends Base6502MachinePlatform