From bb1a29a61b7b6e751e33f69e782553a05335ebd8 Mon Sep 17 00:00:00 2001 From: prescientmoon Date: Wed, 27 Nov 2024 10:51:41 +0100 Subject: [PATCH] Fix comparator pin order --- src/modules/logic-gate-info/data/tables.ts | 267 ++++++++++++--------- src/modules/saving/templates/comparator.ts | 4 +- 2 files changed, 155 insertions(+), 116 deletions(-) diff --git a/src/modules/logic-gate-info/data/tables.ts b/src/modules/logic-gate-info/data/tables.ts index dd71716..034c2d0 100644 --- a/src/modules/logic-gate-info/data/tables.ts +++ b/src/modules/logic-gate-info/data/tables.ts @@ -5,129 +5,168 @@ const _2i1oColumns = ['Input A', 'Input B', 'Output'] const delayerCols = ['Time', 'Input', 'Output'] const adderData = (half = true) => { - return recursiveCombinations([0, 1], half ? 2 : 3).map(combination => { - const a = combination[0] + combination[1] + (half ? 0 : combination[2]) + return recursiveCombinations([0, 1], half ? 2 : 3).map((combination) => { + const a = combination[0] + combination[1] + (half ? 0 : combination[2]) - return [...combination, Number(a % 2 === 1), Number(a >= 2)] - }) + return [...combination, Number(a % 2 === 1), Number(a >= 2)] + }) } const coderData = (encode = true, depth = 4) => { - return recursiveCombinations([0, 1], depth).map(combination => { - const final = combination.join('') + return recursiveCombinations([0, 1], depth).map((combination) => { + const final = combination.join('') - if (encode) { - return [...combination, final] - } else { - return [final, ...combination] - } - }) + if (encode) { + return [...combination, final] + } else { + return [final, ...combination] + } + }) } export const ioTables: Record< - string, - { - columns: string[] - data: (string | number)[][] - } + string, + { + columns: string[] + data: (string | number)[][] + } > = { - not: { - columns: ['Input', 'Output'], - data: [[0, 1], [1, 0]] - }, - and: { - columns: _2i1oColumns, - data: [[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 1]] - }, - or: { - columns: _2i1oColumns, - data: [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]] - }, - nor: { - columns: _2i1oColumns, - data: [[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 0]] - }, - nand: { - columns: _2i1oColumns, - data: [[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 0]] - }, - xor: { - columns: _2i1oColumns, - data: [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]] - }, - xnor: { - columns: _2i1oColumns, - data: [[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]] - }, - 'half adder': { - columns: ['x', 'y', 'sum', 'carry out'], - data: adderData() - }, - 'full adder': { - columns: ['carry in', 'x', 'y', 'sum', 'carry out'], - data: adderData(false) - }, - comparator: { - columns: ['Input A', `Input B`, `A > b`, `A = b`, `A < B`], - data: recursiveCombinations([0, 1], 2).map(combination => { - const [a, b] = combination + not: { + columns: ['Input', 'Output'], + data: [ + [0, 1], + [1, 0] + ] + }, + and: { + columns: _2i1oColumns, + data: [ + [0, 0, 0], + [0, 1, 0], + [1, 0, 0], + [1, 1, 1] + ] + }, + or: { + columns: _2i1oColumns, + data: [ + [0, 0, 0], + [0, 1, 1], + [1, 0, 1], + [1, 1, 1] + ] + }, + nor: { + columns: _2i1oColumns, + data: [ + [0, 0, 1], + [0, 1, 0], + [1, 0, 0], + [1, 1, 0] + ] + }, + nand: { + columns: _2i1oColumns, + data: [ + [0, 0, 1], + [0, 1, 1], + [1, 0, 1], + [1, 1, 0] + ] + }, + xor: { + columns: _2i1oColumns, + data: [ + [0, 0, 0], + [0, 1, 1], + [1, 0, 1], + [1, 1, 0] + ] + }, + xnor: { + columns: _2i1oColumns, + data: [ + [0, 0, 1], + [0, 1, 0], + [1, 0, 0], + [1, 1, 1] + ] + }, + 'half adder': { + columns: ['x', 'y', 'sum', 'carry out'], + data: adderData() + }, + 'full adder': { + columns: ['carry in', 'x', 'y', 'sum', 'carry out'], + data: adderData(false) + }, + comparator: { + columns: ['Input A', `Input B`, `A > b`, `A = b`, `A < B`], + data: recursiveCombinations([0, 1], 2).map((combination) => { + const [a, b] = combination - return [ - ...combination, - Number(a > b), - Number(a === b), - Number(a < b) - ] - }) - }, - 'parallel delayer': { - columns: delayerCols, - data: [[0, 1, 0], [500, 0, 0], [1000, 0, 1], [1500, 0, 0]] - }, - 'sequential delayer': { - columns: delayerCols, - data: [[0, 1, 0], [500, 0, 0], [1000, 0, 1], [1500, 0, 1], [2000, 0, 0]] - }, - '4 bit encoder': { - columns: ['Input A', 'Input B', 'Input C', 'Input D', `Output`], - data: coderData() - }, - '4 bit decoder': { - columns: ['Input', 'Output A', 'Output B', 'Output C', `Output D`], - data: coderData(false) - }, - 'bit merger': { - columns: _2i1oColumns, - data: coderData(true, 2) - }, - 'bit splitter': { - columns: ['Input', 'Output A', 'Output B'], - data: coderData(false, 2) - }, - button: { - columns: ['Previous', 'Output'], - data: [0, 1].map(x => [x, Number(!x)]) - }, - 'light bulb': { - columns: ['Input', 'State'], - data: [0, 1].map(x => [x, x ? 'on' : 'off']) - }, - 'rgb light': { - columns: ['Red', 'Green', 'Blue', 'Color'], - data: recursiveCombinations([0, 1], 3).map(combination => { - return [ - ...combination, - fromChunks(combination.map(value => (value ? 255 : 0))) - ] - }) - }, - incrementor: { - columns: ['x', 'x + 1'], - data: recursiveCombinations([0, 1], 2).map(combination => { - const input = combination.join('') - const output = (parseInt(input, 2) + 1).toString(2) + return [...combination, Number(a < b), Number(a === b), Number(a > b)] + }) + }, + 'parallel delayer': { + columns: delayerCols, + data: [ + [0, 1, 0], + [500, 0, 0], + [1000, 0, 1], + [1500, 0, 0] + ] + }, + 'sequential delayer': { + columns: delayerCols, + data: [ + [0, 1, 0], + [500, 0, 0], + [1000, 0, 1], + [1500, 0, 1], + [2000, 0, 0] + ] + }, + '4 bit encoder': { + columns: ['Input A', 'Input B', 'Input C', 'Input D', `Output`], + data: coderData() + }, + '4 bit decoder': { + columns: ['Input', 'Output A', 'Output B', 'Output C', `Output D`], + data: coderData(false) + }, + 'bit merger': { + columns: _2i1oColumns, + data: coderData(true, 2) + }, + 'bit splitter': { + columns: ['Input', 'Output A', 'Output B'], + data: coderData(false, 2) + }, + button: { + columns: ['Previous', 'Output'], + data: [0, 1].map((x) => [x, Number(!x)]) + }, + 'light bulb': { + columns: ['Input', 'State'], + data: [0, 1].map((x) => [x, x ? 'on' : 'off']) + }, + 'rgb light': { + columns: ['Red', 'Green', 'Blue', 'Color'], + data: recursiveCombinations([0, 1], 3).map((combination) => { + return [ + ...combination, + fromChunks(combination.map((value) => (value ? 255 : 0))) + ] + }) + }, + incrementor: { + columns: ['x', 'x + 1'], + data: recursiveCombinations([0, 1], 2).map((combination) => { + const input = combination.join('') + const output = (parseInt(input, 2) + 1).toString(2) - return [input, output] - }) - } + return [input, output] + }) + } } diff --git a/src/modules/saving/templates/comparator.ts b/src/modules/saving/templates/comparator.ts index 1d226a0..e9a66da 100644 --- a/src/modules/saving/templates/comparator.ts +++ b/src/modules/saving/templates/comparator.ts @@ -15,9 +15,9 @@ const comparatorTemplate: PartialTemplate = { const a = context.getBinary(0) const b = context.getBinary(1) - context.setBinary(0, Number(a > b), 1) + context.setBinary(0, Number(a < b), 1) context.setBinary(1, Number(a === b), 1) - context.setBinary(2, Number(a < b), 1) + context.setBinary(2, Number(a > b), 1) ` }, pins: {