This commit is contained in:
VirtualColossus 2019-12-04 14:29:41 +00:00
commit a387db6109
3 changed files with 21 additions and 9 deletions

View File

@ -355,26 +355,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]++;
}
}

View File

@ -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",

View File

@ -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] = ".";