Fix comparator pin order
This commit is contained in:
parent
932490ec18
commit
bb1a29a61b
|
@ -5,129 +5,168 @@ 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)]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
return [...combination, final]
|
return [...combination, final]
|
||||||
} else {
|
} else {
|
||||||
return [final, ...combination]
|
return [final, ...combination]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ioTables: Record<
|
export const ioTables: Record<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
columns: string[]
|
columns: string[]
|
||||||
data: (string | number)[][]
|
data: (string | number)[][]
|
||||||
}
|
}
|
||||||
> = {
|
> = {
|
||||||
not: {
|
not: {
|
||||||
columns: ['Input', 'Output'],
|
columns: ['Input', 'Output'],
|
||||||
data: [[0, 1], [1, 0]]
|
data: [
|
||||||
},
|
[0, 1],
|
||||||
and: {
|
[1, 0]
|
||||||
columns: _2i1oColumns,
|
]
|
||||||
data: [[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
|
},
|
||||||
},
|
and: {
|
||||||
or: {
|
columns: _2i1oColumns,
|
||||||
columns: _2i1oColumns,
|
data: [
|
||||||
data: [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]]
|
[0, 0, 0],
|
||||||
},
|
[0, 1, 0],
|
||||||
nor: {
|
[1, 0, 0],
|
||||||
columns: _2i1oColumns,
|
[1, 1, 1]
|
||||||
data: [[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 0]]
|
]
|
||||||
},
|
},
|
||||||
nand: {
|
or: {
|
||||||
columns: _2i1oColumns,
|
columns: _2i1oColumns,
|
||||||
data: [[0, 0, 1], [0, 1, 1], [1, 0, 1], [1, 1, 0]]
|
data: [
|
||||||
},
|
[0, 0, 0],
|
||||||
xor: {
|
[0, 1, 1],
|
||||||
columns: _2i1oColumns,
|
[1, 0, 1],
|
||||||
data: [[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]]
|
[1, 1, 1]
|
||||||
},
|
]
|
||||||
xnor: {
|
},
|
||||||
columns: _2i1oColumns,
|
nor: {
|
||||||
data: [[0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
|
columns: _2i1oColumns,
|
||||||
},
|
data: [
|
||||||
'half adder': {
|
[0, 0, 1],
|
||||||
columns: ['x', 'y', 'sum', 'carry out'],
|
[0, 1, 0],
|
||||||
data: adderData()
|
[1, 0, 0],
|
||||||
},
|
[1, 1, 0]
|
||||||
'full adder': {
|
]
|
||||||
columns: ['carry in', 'x', 'y', 'sum', 'carry out'],
|
},
|
||||||
data: adderData(false)
|
nand: {
|
||||||
},
|
columns: _2i1oColumns,
|
||||||
comparator: {
|
data: [
|
||||||
columns: ['Input A', `Input B`, `A > b`, `A = b`, `A < B`],
|
[0, 0, 1],
|
||||||
data: recursiveCombinations([0, 1], 2).map(combination => {
|
[0, 1, 1],
|
||||||
const [a, b] = combination
|
[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 [
|
return [...combination, Number(a < b), Number(a === b), Number(a > b)]
|
||||||
...combination,
|
})
|
||||||
Number(a > b),
|
},
|
||||||
Number(a === b),
|
'parallel delayer': {
|
||||||
Number(a < b)
|
columns: delayerCols,
|
||||||
]
|
data: [
|
||||||
})
|
[0, 1, 0],
|
||||||
},
|
[500, 0, 0],
|
||||||
'parallel delayer': {
|
[1000, 0, 1],
|
||||||
columns: delayerCols,
|
[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],
|
||||||
'4 bit encoder': {
|
[500, 0, 0],
|
||||||
columns: ['Input A', 'Input B', 'Input C', 'Input D', `Output`],
|
[1000, 0, 1],
|
||||||
data: coderData()
|
[1500, 0, 1],
|
||||||
},
|
[2000, 0, 0]
|
||||||
'4 bit decoder': {
|
]
|
||||||
columns: ['Input', 'Output A', 'Output B', 'Output C', `Output D`],
|
},
|
||||||
data: coderData(false)
|
'4 bit encoder': {
|
||||||
},
|
columns: ['Input A', 'Input B', 'Input C', 'Input D', `Output`],
|
||||||
'bit merger': {
|
data: coderData()
|
||||||
columns: _2i1oColumns,
|
},
|
||||||
data: coderData(true, 2)
|
'4 bit decoder': {
|
||||||
},
|
columns: ['Input', 'Output A', 'Output B', 'Output C', `Output D`],
|
||||||
'bit splitter': {
|
data: coderData(false)
|
||||||
columns: ['Input', 'Output A', 'Output B'],
|
},
|
||||||
data: coderData(false, 2)
|
'bit merger': {
|
||||||
},
|
columns: _2i1oColumns,
|
||||||
button: {
|
data: coderData(true, 2)
|
||||||
columns: ['Previous', 'Output'],
|
},
|
||||||
data: [0, 1].map(x => [x, Number(!x)])
|
'bit splitter': {
|
||||||
},
|
columns: ['Input', 'Output A', 'Output B'],
|
||||||
'light bulb': {
|
data: coderData(false, 2)
|
||||||
columns: ['Input', 'State'],
|
},
|
||||||
data: [0, 1].map(x => [x, x ? 'on' : 'off'])
|
button: {
|
||||||
},
|
columns: ['Previous', 'Output'],
|
||||||
'rgb light': {
|
data: [0, 1].map((x) => [x, Number(!x)])
|
||||||
columns: ['Red', 'Green', 'Blue', 'Color'],
|
},
|
||||||
data: recursiveCombinations([0, 1], 3).map(combination => {
|
'light bulb': {
|
||||||
return [
|
columns: ['Input', 'State'],
|
||||||
...combination,
|
data: [0, 1].map((x) => [x, x ? 'on' : 'off'])
|
||||||
fromChunks(combination.map(value => (value ? 255 : 0)))
|
},
|
||||||
]
|
'rgb light': {
|
||||||
})
|
columns: ['Red', 'Green', 'Blue', 'Color'],
|
||||||
},
|
data: recursiveCombinations([0, 1], 3).map((combination) => {
|
||||||
incrementor: {
|
return [
|
||||||
columns: ['x', 'x + 1'],
|
...combination,
|
||||||
data: recursiveCombinations([0, 1], 2).map(combination => {
|
fromChunks(combination.map((value) => (value ? 255 : 0)))
|
||||||
const input = combination.join('')
|
]
|
||||||
const output = (parseInt(input, 2) + 1).toString(2)
|
})
|
||||||
|
},
|
||||||
|
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]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: {
|
||||||
|
|
Loading…
Reference in a new issue