import { SourceLocation } from "../workertypes"; import { DataValue, ECSError } from "./ecs"; export interface DecoderResult { properties: {[name: string] : DataValue} } abstract class LineDecoder { curline: number = 0; // for debugging, zero-indexed lines : string[][]; // array of token arrays constructor( text: string ) { // split the text into lines and into tokens this.lines = text.split('\n').map(s => s.trim()).filter(s => !!s).map(s => s.split(/\s+/)); } decodeBits(s: string, n: number, msbfirst: boolean) { if (s.length != n) throw new ECSError(`Expected ${n} characters`); let b = 0; for (let i=0; i 1) { console.log(changed, cur, prev); throw new ECSError(`More than one register change in line ${i+1}: [${changed}]`); } let chgidx = changed.length ? changed[0] : regs.length-1; data[dataofs - 1] = regs[chgidx]; data[dataofs - 2] = cur[chgidx]; prev[chgidx] = cur[chgidx]; } return { properties: { data } } } } export class VCSBitmap48Decoder extends LineDecoder { parse() { let height = this.lines.length; let bitmap0 = new Uint8Array(height); let bitmap1 = new Uint8Array(height); let bitmap2 = new Uint8Array(height); let bitmap3 = new Uint8Array(height); let bitmap4 = new Uint8Array(height); let bitmap5 = new Uint8Array(height); for (let i=0; i