From c32fec6b53758f9b33a479e31ea4b9feca7f3414 Mon Sep 17 00:00:00 2001 From: VirtualColossus Date: Sat, 30 Nov 2019 10:25:24 +0000 Subject: [PATCH] Various fixes for conditional calcs --- src/core/lib/Colossus.mjs | 12 ++++++------ src/core/lib/Lorenz.mjs | 2 ++ src/core/operations/Colossus.mjs | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/lib/Colossus.mjs b/src/core/lib/Colossus.mjs index 93ff8de5..59dc6d02 100644 --- a/src/core/lib/Colossus.mjs +++ b/src/core/lib/Colossus.mjs @@ -332,26 +332,26 @@ export class ColossusComputer { const Qswitch = this.readBusSwitches(row.Qswitches); // Match switches to bit pattern for (let s=0;s<5;s++) { - if (Qswitch[s] >= 0 && Qswitch[s] !== this.Qbits[s]) result = false; + if (Qswitch[s] >= 0 && Qswitch[s] !== parseInt(this.Qbits[s],10)) result = false; } // Check for NOT switch if (row.Negate) result = !result; // AND each row to get final result if (cnt[cPnt] === -1) { - cnt[cPnt] = (result?1:0); - } else if (result === 0) { - cnt[cPnt] = 0; + cnt[cPnt] = result; + } else if (!result) { + cnt[cPnt] = false; } } } // Negate the whole column, this allows A OR B by doing NOT(NOT A AND NOT B) for (let c=0;c<5;c++) { - if (this.qbusswitches.condNegateAll) cnt[c] = !cnt[c]; + if (this.qbusswitches.condNegateAll && cnt[c] !== -1) cnt[c] = !cnt[c]; if (this.qbusswitches.totalMotor === "" || (this.qbusswitches.totalMotor === "x" && this.totalmotor === 0) || (this.qbusswitches.totalMotor === "." && this.totalmotor === 1)) { - if (cnt[c]===1) this.allCounters[c]++; + if (cnt[c] === true) this.allCounters[c]++; } } diff --git a/src/core/lib/Lorenz.mjs b/src/core/lib/Lorenz.mjs index fa4350e0..916b470c 100644 --- a/src/core/lib/Lorenz.mjs +++ b/src/core/lib/Lorenz.mjs @@ -12,6 +12,8 @@ export const SWITCHES = [ {name: "Down (x)", value: "x"} ]; +export const VALID_ITA2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ34589+-./"; + export const ITA2_TABLE = { "A": "11000", "B": "10011", diff --git a/src/core/operations/Colossus.mjs b/src/core/operations/Colossus.mjs index 60c7f14c..896252dd 100644 --- a/src/core/operations/Colossus.mjs +++ b/src/core/operations/Colossus.mjs @@ -9,7 +9,7 @@ import Operation from "../Operation"; import OperationError from "../errors/OperationError.mjs"; import { ColossusComputer } from "../lib/Colossus.mjs"; -import { SWITCHES } from "../lib/Lorenz.mjs"; +import { SWITCHES, VALID_ITA2 } from "../lib/Lorenz.mjs"; /** * Colossus operation @@ -87,7 +87,7 @@ class Colossus extends Operation { { name: "Program to run", type: "option", - value: ["", "Letter Count", "1+2=. (1+2 Break In, Find X1,X2)", "4=3=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] + value: ["", "Letter Count", "1+2=. (1+2 Break In, Find X1,X2)", "4=5=/1=2 (Given X1,X2 find X4,X5)", "/,5,U (Count chars to find X3)"] }, { name: "K Rack: Conditional", @@ -347,6 +347,16 @@ class Colossus extends Operation { */ run(input, args) { + input = input.toUpperCase(); + for (const character of input) { + if (VALID_ITA2.indexOf(character) === -1) { + let errltr = character; + if (errltr==="\n") errltr = "Carriage Return"; + if (errltr===" ") errltr = "Space"; + throw new OperationError("Invalid ITA2 character : "+errltr); + } + } + const pattern = args[1]; const qbusin = { "Z": args[2], @@ -475,7 +485,7 @@ class Colossus extends Operation { } // 4=3=/1=2 : Find X4 & X5 where X1 & X2 are known - if (progname === "4=3=/1=2 (Given X1,X2 find X4,X5)") { + if (progname === "4=5=/1=2 (Given X1,X2 find X4,X5)") { // Set Conditional R1 : Match NOT ..?.. into counter 1 args[9] = "."; args[10] = ".";