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,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]
})
}
}

View file

@ -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: {