Fix comparator pin order

This commit is contained in:
prescientmoon 2024-11-27 10:51:41 +01:00
parent 932490ec18
commit bb1a29a61b
Signed by: prescientmoon
SSH key fingerprint: SHA256:UUF9JT2s8Xfyv76b8ZuVL7XrmimH4o49p4b+iexbVH4
2 changed files with 155 additions and 116 deletions

View file

@ -5,7 +5,7 @@ const _2i1oColumns = ['Input A', 'Input B', 'Output']
const delayerCols = ['Time', 'Input', 'Output'] const delayerCols = ['Time', 'Input', 'Output']
const adderData = (half = true) => { const adderData = (half = true) => {
return recursiveCombinations([0, 1], half ? 2 : 3).map(combination => { return recursiveCombinations([0, 1], half ? 2 : 3).map((combination) => {
const a = combination[0] + combination[1] + (half ? 0 : combination[2]) 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)]
@ -13,7 +13,7 @@ const adderData = (half = true) => {
} }
const coderData = (encode = true, depth = 4) => { const coderData = (encode = true, depth = 4) => {
return recursiveCombinations([0, 1], depth).map(combination => { return recursiveCombinations([0, 1], depth).map((combination) => {
const final = combination.join('') const final = combination.join('')
if (encode) { if (encode) {
@ -33,31 +33,64 @@ export const ioTables: Record<
> = { > = {
not: { not: {
columns: ['Input', 'Output'], columns: ['Input', 'Output'],
data: [[0, 1], [1, 0]] data: [
[0, 1],
[1, 0]
]
}, },
and: { and: {
columns: _2i1oColumns, columns: _2i1oColumns,
data: [[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 1]] data: [
[0, 0, 0],
[0, 1, 0],
[1, 0, 0],
[1, 1, 1]
]
}, },
or: { or: {
columns: _2i1oColumns, columns: _2i1oColumns,
data: [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]] data: [
[0, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 1]
]
}, },
nor: { nor: {
columns: _2i1oColumns, columns: _2i1oColumns,
data: [[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 0]] data: [
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
[1, 1, 0]
]
}, },
nand: { nand: {
columns: _2i1oColumns, columns: _2i1oColumns,
data: [[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 0]] data: [
[0, 0, 1],
[0, 1, 1],
[1, 0, 1],
[1, 1, 0]
]
}, },
xor: { xor: {
columns: _2i1oColumns, columns: _2i1oColumns,
data: [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]] data: [
[0, 0, 0],
[0, 1, 1],
[1, 0, 1],
[1, 1, 0]
]
}, },
xnor: { xnor: {
columns: _2i1oColumns, columns: _2i1oColumns,
data: [[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]] data: [
[0, 0, 1],
[0, 1, 0],
[1, 0, 0],
[1, 1, 1]
]
}, },
'half adder': { 'half adder': {
columns: ['x', 'y', 'sum', 'carry out'], columns: ['x', 'y', 'sum', 'carry out'],
@ -69,24 +102,30 @@ export const ioTables: Record<
}, },
comparator: { comparator: {
columns: ['Input A', `Input B`, `A > b`, `A = b`, `A < B`], columns: ['Input A', `Input B`, `A > b`, `A = b`, `A < B`],
data: recursiveCombinations([0, 1], 2).map(combination => { data: recursiveCombinations([0, 1], 2).map((combination) => {
const [a, b] = combination const [a, b] = combination
return [ return [...combination, Number(a < b), Number(a === b), Number(a > b)]
...combination,
Number(a > b),
Number(a === b),
Number(a < b)
]
}) })
}, },
'parallel delayer': { 'parallel delayer': {
columns: delayerCols, columns: delayerCols,
data: [[0, 1, 0], [500, 0, 0], [1000, 0, 1], [1500, 0, 0]] data: [
[0, 1, 0],
[500, 0, 0],
[1000, 0, 1],
[1500, 0, 0]
]
}, },
'sequential delayer': { 'sequential delayer': {
columns: delayerCols, columns: delayerCols,
data: [[0, 1, 0], [500, 0, 0], [1000, 0, 1], [1500, 0, 1], [2000, 0, 0]] data: [
[0, 1, 0],
[500, 0, 0],
[1000, 0, 1],
[1500, 0, 1],
[2000, 0, 0]
]
}, },
'4 bit encoder': { '4 bit encoder': {
columns: ['Input A', 'Input B', 'Input C', 'Input D', `Output`], columns: ['Input A', 'Input B', 'Input C', 'Input D', `Output`],
@ -106,24 +145,24 @@ export const ioTables: Record<
}, },
button: { button: {
columns: ['Previous', 'Output'], columns: ['Previous', 'Output'],
data: [0, 1].map(x => [x, Number(!x)]) data: [0, 1].map((x) => [x, Number(!x)])
}, },
'light bulb': { 'light bulb': {
columns: ['Input', 'State'], columns: ['Input', 'State'],
data: [0, 1].map(x => [x, x ? 'on' : 'off']) data: [0, 1].map((x) => [x, x ? 'on' : 'off'])
}, },
'rgb light': { 'rgb light': {
columns: ['Red', 'Green', 'Blue', 'Color'], columns: ['Red', 'Green', 'Blue', 'Color'],
data: recursiveCombinations([0, 1], 3).map(combination => { data: recursiveCombinations([0, 1], 3).map((combination) => {
return [ return [
...combination, ...combination,
fromChunks(combination.map(value => (value ? 255 : 0))) fromChunks(combination.map((value) => (value ? 255 : 0)))
] ]
}) })
}, },
incrementor: { incrementor: {
columns: ['x', 'x + 1'], columns: ['x', 'x + 1'],
data: recursiveCombinations([0, 1], 2).map(combination => { data: recursiveCombinations([0, 1], 2).map((combination) => {
const input = combination.join('') const input = combination.join('')
const output = (parseInt(input, 2) + 1).toString(2) const output = (parseInt(input, 2) + 1).toString(2)

View file

@ -15,9 +15,9 @@ const comparatorTemplate: PartialTemplate = {
const a = context.getBinary(0) const a = context.getBinary(0)
const b = context.getBinary(1) 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(1, Number(a === b), 1)
context.setBinary(2, Number(a < b), 1) context.setBinary(2, Number(a > b), 1)
` `
}, },
pins: { pins: {