2026-10-17 10:49:38 +00:00
|
|
|
// Flattens a component tree into a flat list of NAND gates over numbered
|
|
|
|
|
// nets. Chip boundaries and input/output pins disappear: they are aliases,
|
|
|
|
|
// merged with union-find. Net 0 is constant LOW, net 1 constant HIGH.
|
|
|
|
|
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
import { cableBits, chipPins, isPinRow, portLines, rowPin, splitLines, type ChipPins, type DefLookup } from './geometry'
|
2026-10-28 12:30:07 +00:00
|
|
|
import { colKeys } from './benchLayout'
|
2026-10-28 12:05:57 +00:00
|
|
|
import { DATA_KEYS } from './devices'
|
2026-10-17 10:49:38 +00:00
|
|
|
import type { CircuitNode, ComponentDef, Wire } from './types'
|
|
|
|
|
|
|
|
|
|
export const LOW = 0
|
|
|
|
|
export const HIGH = 1
|
|
|
|
|
|
|
|
|
|
export interface Netlist {
|
|
|
|
|
netCount: number
|
|
|
|
|
gateA: Int32Array
|
|
|
|
|
gateB: Int32Array
|
|
|
|
|
gateOut: Int32Array
|
|
|
|
|
/** Stable identity per gate ("chipNode/chipNode/nandNode"), to keep state across recompiles. */
|
|
|
|
|
gateKeys: string[]
|
|
|
|
|
/** CSR fanout: gates reading net n are fanList[fanStart[n] .. fanStart[n + 1]). */
|
|
|
|
|
fanStart: Int32Array
|
|
|
|
|
fanList: Int32Array
|
|
|
|
|
/** Net of every pin of the root circuit's nodes, keyed "nodeId:pin". */
|
|
|
|
|
pinNet: Map<string, number>
|
|
|
|
|
/** Same, for nodes at any depth, keyed "chipNode/…/nodeId:pin". Only with `trace`. */
|
|
|
|
|
tracePinNet?: Map<string, number>
|
A component faces, project library with share links, fine-grained wire editing
- Lamps and hex displays inside a component show on its box with their
labels, lit by that instance's state; Counter 4 example shows its count.
- Several projects per browser; share links at /p/<id> that the creator's
edits save to automatically, others get their own copy. Export, open a
file as project, or add a file's components to the open project.
- Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to
branch, double-click selects the whole signal, multi-select, arrow keys,
colour tags.
- Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted
as a volume on edgerealm.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
/** Inputs of lamps and displays inside the root's chips, keyed "chipNode/nodeId:pin", for drawing them on the chip. */
|
|
|
|
|
facePinNet: Map<string, number>
|
2026-10-23 10:27:12 +00:00
|
|
|
/** What each of the root circuit's output pins puts out (keyed like ChipPins outputs), after any bubble on it. */
|
|
|
|
|
outputs: Map<string, number>
|
2026-10-17 10:49:38 +00:00
|
|
|
/** User-driven sources in the root circuit (switches, buttons): nodeId → net. */
|
|
|
|
|
sources: Map<string, number>
|
|
|
|
|
clocks: Int32Array
|
A settings for every part, overlap-free wiring with crossing styles, accounts with sync
- Clicking anything opens its settings: swap parts in place (wires stay on
matching pins), clock frequency per clock, keyboard keys for switches and
buttons, lamp/display colours, note sizes, component names on the canvas,
position, unlink all wires, unpack a component, make an independent copy.
- Wires of different signals never share a line: auto routes pick free
columns or detours, remaining clashes go on separate lanes. Crossings drawn
as bow, triangle, bridge, gap or plain.
- Accounts (email + scrypt password, httpOnly session) with two-way project
sync and conflict copies; per-account limits; cross-site writes refused.
- Compatibility suite: a project and both browser-storage layouts from
release a241adc must load and compute identically.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
/** Frequency per clock in Hz; 0 follows the speed in the top bar. */
|
|
|
|
|
clockHz: Float64Array
|
|
|
|
|
/** Stable identity per clock ("chipNode/…/clockNode"), to keep its level across recompiles. */
|
|
|
|
|
clockKeys: string[]
|
2026-10-17 10:49:38 +00:00
|
|
|
errors: string[]
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
export function inputKeys(node: CircuitNode, pins?: ChipPins, get?: DefLookup): string[] {
|
2026-10-17 10:49:38 +00:00
|
|
|
switch (node.kind) {
|
2026-10-22 16:59:56 +00:00
|
|
|
case 'portin':
|
|
|
|
|
return get ? portLines(node, get).filter(l => !l.enters).map(l => l.key) : []
|
|
|
|
|
case 'portout':
|
|
|
|
|
return ['bus', ...(get ? portLines(node, get).filter(l => !l.enters).map(l => l.key) : [])]
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'nand':
|
|
|
|
|
return ['a', 'b']
|
2026-10-28 11:51:09 +00:00
|
|
|
case 'pixel':
|
|
|
|
|
return node.rgb ? ['r', 'g', 'b'] : ['a']
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'output':
|
|
|
|
|
case 'lamp':
|
2026-10-20 17:29:16 +00:00
|
|
|
case 'split':
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
case 'tag':
|
2026-10-17 10:49:38 +00:00
|
|
|
return ['a']
|
|
|
|
|
case 'hex':
|
|
|
|
|
return ['b0', 'b1', 'b2', 'b3']
|
2026-10-28 12:05:57 +00:00
|
|
|
case 'terminal':
|
|
|
|
|
return [...DATA_KEYS, 'wr', 'clr']
|
|
|
|
|
case 'keyboard':
|
|
|
|
|
return ['next']
|
2026-10-28 12:30:07 +00:00
|
|
|
case 'bench':
|
|
|
|
|
return (node.bench?.cols ?? []).filter(c => c.dir === 'check').flatMap(colKeys)
|
2026-10-21 12:38:59 +00:00
|
|
|
case 'outpanel':
|
|
|
|
|
return (node.rows ?? []).map(r => r.id)
|
2026-10-20 17:29:16 +00:00
|
|
|
case 'bundle':
|
|
|
|
|
return cableKeys(node)
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'chip':
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
return pins ? [...pins.inputs.map(p => p.key), ...portKeys(pins, 'in'), ...lineKeys(node, pins, get, true)] : []
|
2026-10-17 10:49:38 +00:00
|
|
|
default:
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
/** Keys of a component's connector ports on one side. */
|
|
|
|
|
const portKeys = (pins: ChipPins, side: 'in' | 'out') => (pins.ports ?? []).filter(p => p.side === side).map(p => p.key)
|
|
|
|
|
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
/** Keys of the lines of ports split on a placed component's box that go in (or come out). */
|
|
|
|
|
const lineKeys = (node: CircuitNode, pins: ChipPins, get: DefLookup | undefined, enters: boolean) => splitLines(node, pins, get).filter(l => l.enters === enters).map(l => l.key)
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
export function outputKeys(node: CircuitNode, pins?: ChipPins, get?: DefLookup): string[] {
|
2026-10-17 10:49:38 +00:00
|
|
|
switch (node.kind) {
|
2026-10-22 16:59:56 +00:00
|
|
|
case 'portin':
|
|
|
|
|
return ['bus', ...(get ? portLines(node, get).filter(l => l.enters).map(l => l.key) : [])]
|
|
|
|
|
case 'portout':
|
|
|
|
|
return get ? portLines(node, get).filter(l => l.enters).map(l => l.key) : []
|
2026-10-20 18:09:23 +00:00
|
|
|
case 'output':
|
|
|
|
|
case 'lamp':
|
|
|
|
|
return ['q']
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'nand':
|
|
|
|
|
case 'input':
|
|
|
|
|
case 'high':
|
|
|
|
|
case 'low':
|
|
|
|
|
case 'button':
|
|
|
|
|
case 'clock':
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
case 'ref':
|
2026-10-17 10:49:38 +00:00
|
|
|
return ['q']
|
|
|
|
|
case 'chip':
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
return pins ? [...pins.outputs.map(p => p.key), ...portKeys(pins, 'out'), ...lineKeys(node, pins, get, false)] : []
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
case 'hex':
|
|
|
|
|
return ['q0', 'q1', 'q2', 'q3']
|
2026-10-28 12:05:57 +00:00
|
|
|
case 'keyboard':
|
|
|
|
|
return [...DATA_KEYS, 'rdy']
|
2026-10-28 12:30:07 +00:00
|
|
|
case 'bench':
|
|
|
|
|
return (node.bench?.cols ?? []).filter(c => c.dir === 'drive').flatMap(colKeys)
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
case 'panel':
|
2026-10-21 12:38:59 +00:00
|
|
|
case 'outpanel':
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
return (node.rows ?? []).map(r => r.id)
|
2026-10-20 17:29:16 +00:00
|
|
|
case 'bundle':
|
|
|
|
|
return ['q']
|
|
|
|
|
case 'split':
|
|
|
|
|
return cableKeys(node)
|
2026-10-17 10:49:38 +00:00
|
|
|
default:
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
/** Kinds whose inputs can be inverted with a bubble. */
|
|
|
|
|
export const INVERTIBLE = new Set(['nand', 'chip', 'output', 'lamp'])
|
|
|
|
|
|
|
|
|
|
/** The inverted inputs of a part that it really has, each once. */
|
|
|
|
|
export function invertedPins(node: CircuitNode, pins?: ChipPins): string[] {
|
|
|
|
|
if (!node.invert?.length || !INVERTIBLE.has(node.kind)) return []
|
|
|
|
|
const keys = new Set(inputKeys(node, pins))
|
|
|
|
|
return [...new Set(node.invert)].filter(k => keys.has(k))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-20 17:29:16 +00:00
|
|
|
/** Pin keys of the single wires on a bundle or split: b0, b1, … */
|
|
|
|
|
export function cableKeys(node: CircuitNode): string[] {
|
|
|
|
|
return Array.from({ length: cableBits(node) }, (_, i) => `b${i}`)
|
|
|
|
|
}
|
|
|
|
|
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
/** Key of a panel row in the simulator's sources, like a switch's node id. */
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
export const rowSource = rowPin
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
|
A public library of components: publish yours, add everybody's
"Publish to the library…" in the menu on a circuit's name (or Space)
sends the component with every component it uses and their connector
types, under your leaderboard name. The server checks it like any
project, refuses what is missing, inside itself, nested too deep or too
big to run, and counts its transistors and pins itself. Publishing again
from the same browser makes the next version of the same entry; only that
browser holds the entry's key, so only it can update or remove it.
Challenge circuits and puzzle solutions stay private.
The Library (Components in the bottom bar, Space, the main menu) lists
every entry, newest first, searchable by name, description and author,
with a picture of its box, its transistors, pins and what comes along.
Add brings an entry into the open project and starts placing it: what the
project has in exactly that form already is used as it is, the rest comes
with new ids, a taken name gets a number, connector types join one with
the same lines. The This panel says where a component came from and
offers a newer version, which replaces it in place. A campaign only adds
what is built from parts it has earned, and its challenges take nothing
from the library.
Components keep an optional "from" mark; projects without it load and
compute as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:14:46 +00:00
|
|
|
export const MAX_DEPTH = 64
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
export function compile(getDef: DefLookup, rootId: string, opts: { trace?: boolean } = {}): Netlist {
|
|
|
|
|
const parent: number[] = [LOW, HIGH]
|
|
|
|
|
const make = () => {
|
|
|
|
|
parent.push(parent.length)
|
|
|
|
|
return parent.length - 1
|
|
|
|
|
}
|
|
|
|
|
const find = (x: number) => {
|
|
|
|
|
while (parent[x] !== x) {
|
|
|
|
|
parent[x] = parent[parent[x]!]!
|
|
|
|
|
x = parent[x]!
|
|
|
|
|
}
|
|
|
|
|
return x
|
|
|
|
|
}
|
|
|
|
|
const union = (a: number, b: number) => {
|
|
|
|
|
a = find(a)
|
|
|
|
|
b = find(b)
|
|
|
|
|
if (a === b) return
|
|
|
|
|
// Constants stay roots so they keep their fixed values.
|
|
|
|
|
if (a <= HIGH) parent[b] = a
|
|
|
|
|
else parent[a] = b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gA: number[] = []
|
|
|
|
|
const gB: number[] = []
|
|
|
|
|
const gOut: number[] = []
|
|
|
|
|
const gateKeys: string[] = []
|
A settings for every part, overlap-free wiring with crossing styles, accounts with sync
- Clicking anything opens its settings: swap parts in place (wires stay on
matching pins), clock frequency per clock, keyboard keys for switches and
buttons, lamp/display colours, note sizes, component names on the canvas,
position, unlink all wires, unpack a component, make an independent copy.
- Wires of different signals never share a line: auto routes pick free
columns or detours, remaining clashes go on separate lanes. Crossings drawn
as bow, triangle, bridge, gap or plain.
- Accounts (email + scrypt password, httpOnly session) with two-way project
sync and conflict copies; per-account limits; cross-site writes refused.
- Compatibility suite: a project and both browser-storage layouts from
release a241adc must load and compute identically.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
const clocks: { net: number; hz: number; key: string }[] = []
|
2026-10-17 10:49:38 +00:00
|
|
|
const sources = new Map<string, number>()
|
|
|
|
|
const rawPinNet = new Map<string, number>()
|
|
|
|
|
const rawTrace = opts.trace ? new Map<string, number>() : undefined
|
A component faces, project library with share links, fine-grained wire editing
- Lamps and hex displays inside a component show on its box with their
labels, lit by that instance's state; Counter 4 example shows its count.
- Several projects per browser; share links at /p/<id> that the creator's
edits save to automatically, others get their own copy. Export, open a
file as project, or add a file's components to the open project.
- Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to
branch, double-click selects the whole signal, multi-select, arrow keys,
colour tags.
- Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted
as a volume on edgerealm.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
const rawFace = new Map<string, number>()
|
2026-10-17 10:49:38 +00:00
|
|
|
const errors: string[] = []
|
|
|
|
|
const pinCache = new Map<string, ChipPins>()
|
|
|
|
|
|
|
|
|
|
const pinsOf = (node: CircuitNode): ChipPins | undefined => {
|
|
|
|
|
if (node.kind !== 'chip' || !node.chip) return undefined
|
|
|
|
|
let p = pinCache.get(node.chip)
|
|
|
|
|
if (!p) {
|
|
|
|
|
const def = getDef(node.chip)
|
|
|
|
|
if (!def) return undefined
|
|
|
|
|
p = chipPins(def)
|
|
|
|
|
pinCache.set(node.chip, p)
|
|
|
|
|
}
|
|
|
|
|
return p
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
// `portNets`: for each port part of this component, the nets of its lines, from the parent that placed it.
|
|
|
|
|
const expand = (
|
|
|
|
|
def: ComponentDef,
|
|
|
|
|
inNets: Map<string, number> | null,
|
|
|
|
|
path: string,
|
|
|
|
|
stack: string[],
|
|
|
|
|
portNets?: Map<string, number[]>,
|
|
|
|
|
): Map<string, number> => {
|
2026-10-17 10:49:38 +00:00
|
|
|
const result = new Map<string, number>()
|
|
|
|
|
if (stack.includes(def.id)) {
|
|
|
|
|
errors.push(`"${def.name}" contains itself`)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
if (stack.length >= MAX_DEPTH) {
|
|
|
|
|
errors.push(`Nesting deeper than ${MAX_DEPTH} levels`)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
const inner = [...stack, def.id]
|
|
|
|
|
|
|
|
|
|
const wiresTo = new Map<string, Wire>()
|
|
|
|
|
for (const w of def.wires) wiresTo.set(`${w.to.node}:${w.to.pin}`, w)
|
2026-10-20 17:29:16 +00:00
|
|
|
const nodeById = new Map(def.nodes.map(n => [n.id, n]))
|
2026-10-22 16:59:56 +00:00
|
|
|
// Ends of typed cables ("node:pin"): the nets of their lines, joined line by line below.
|
|
|
|
|
const ends = new Map<string, number[]>()
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
// Line pins of ports split on boxes ("node:pin"): the line's net, wired by hand or fed through the cable.
|
|
|
|
|
const lineNets = new Map<string, number>()
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
const outNet = new Map<string, number>()
|
|
|
|
|
for (const n of def.nodes) {
|
2026-10-22 16:59:56 +00:00
|
|
|
for (const k of outputKeys(n, pinsOf(n), getDef)) outNet.set(`${n.id}:${k}`, make())
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
const inNet = (nodeId: string, pin: string) => {
|
|
|
|
|
const w = wiresTo.get(`${nodeId}:${pin}`)
|
|
|
|
|
return w ? (outNet.get(`${w.from.node}:${w.from.pin}`) ?? LOW) : LOW
|
|
|
|
|
}
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
// An inverted input: the wire's signal through a NAND with both inputs tied, made once per pin.
|
|
|
|
|
const inverters = new Map<string, number>()
|
|
|
|
|
const pinIn = (n: CircuitNode, pin: string) => {
|
|
|
|
|
const raw = inNet(n.id, pin)
|
|
|
|
|
if (!n.invert?.length || !invertedPins(n, pinsOf(n)).includes(pin)) return raw
|
|
|
|
|
const key = `${n.id}:${pin}`
|
|
|
|
|
let net = inverters.get(key)
|
|
|
|
|
if (net === undefined) {
|
|
|
|
|
net = make()
|
|
|
|
|
gA.push(raw)
|
|
|
|
|
gB.push(raw)
|
|
|
|
|
gOut.push(net)
|
|
|
|
|
gateKeys.push(`${path}${n.id}~${pin}`)
|
|
|
|
|
inverters.set(key, net)
|
|
|
|
|
}
|
|
|
|
|
return net
|
|
|
|
|
}
|
|
|
|
|
// Signal tags by name: a reference carries what is wired into the tag of its name.
|
|
|
|
|
const tags = new Map<string, CircuitNode[]>()
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
const name = n.kind === 'tag' ? n.label?.trim() : ''
|
|
|
|
|
if (name) tags.set(name, [...(tags.get(name) ?? []), n])
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
const q = outNet.get(`${n.id}:q`)!
|
|
|
|
|
switch (n.kind) {
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
case 'nand': {
|
|
|
|
|
const a = pinIn(n, 'a')
|
|
|
|
|
const b = pinIn(n, 'b')
|
|
|
|
|
gA.push(a)
|
|
|
|
|
gB.push(b)
|
2026-10-17 10:49:38 +00:00
|
|
|
gOut.push(q)
|
|
|
|
|
gateKeys.push(path + n.id)
|
|
|
|
|
break
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'input':
|
|
|
|
|
if (inNets) union(q, inNets.get(n.id) ?? LOW)
|
|
|
|
|
else sources.set(n.id, q)
|
|
|
|
|
break
|
|
|
|
|
case 'button':
|
|
|
|
|
if (!inNets) sources.set(n.id, q)
|
|
|
|
|
break
|
2026-10-28 12:30:07 +00:00
|
|
|
case 'bench':
|
2026-10-28 12:05:57 +00:00
|
|
|
case 'keyboard':
|
2026-10-28 12:30:07 +00:00
|
|
|
// Set from outside (the keys typed, a bench's row), in the open circuit; inside a component it is all 0.
|
2026-10-28 12:05:57 +00:00
|
|
|
if (!inNets) for (const k of outputKeys(n)) sources.set(`${n.id}:${k}`, outNet.get(`${n.id}:${k}`)!)
|
|
|
|
|
break
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'high':
|
|
|
|
|
union(q, HIGH)
|
|
|
|
|
break
|
|
|
|
|
case 'low':
|
|
|
|
|
union(q, LOW)
|
|
|
|
|
break
|
|
|
|
|
case 'clock':
|
A settings for every part, overlap-free wiring with crossing styles, accounts with sync
- Clicking anything opens its settings: swap parts in place (wires stay on
matching pins), clock frequency per clock, keyboard keys for switches and
buttons, lamp/display colours, note sizes, component names on the canvas,
position, unlink all wires, unpack a component, make an independent copy.
- Wires of different signals never share a line: auto routes pick free
columns or detours, remaining clashes go on separate lanes. Crossings drawn
as bow, triangle, bridge, gap or plain.
- Accounts (email + scrypt password, httpOnly session) with two-way project
sync and conflict copies; per-account limits; cross-site writes refused.
- Compatibility suite: a project and both browser-storage layouts from
release a241adc must load and compute identically.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
clocks.push({ net: q, hz: n.hz ?? 0, key: path + n.id })
|
2026-10-17 10:49:38 +00:00
|
|
|
break
|
2026-10-20 17:29:16 +00:00
|
|
|
case 'split': {
|
|
|
|
|
// Wire i of the cable is whatever drives input i of the bundle at its other end.
|
|
|
|
|
const w = wiresTo.get(`${n.id}:a`)
|
|
|
|
|
const src = w && nodeById.get(w.from.node)
|
|
|
|
|
if (src?.kind !== 'bundle') break
|
|
|
|
|
const count = Math.min(cableBits(n), cableBits(src))
|
|
|
|
|
for (let i = 0; i < count; i++) union(outNet.get(`${n.id}:b${i}`)!, inNet(src.id, `b${i}`))
|
|
|
|
|
break
|
|
|
|
|
}
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
case 'panel':
|
|
|
|
|
// In the open circuit the rows are switches and buttons you use;
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
// inside a component they are its input pins. A panel kept inside
|
|
|
|
|
// has fixed switches there (a button is 0).
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
for (const r of n.rows ?? []) {
|
|
|
|
|
const net = outNet.get(`${n.id}:${r.id}`)!
|
|
|
|
|
if (r.type === 'clock') clocks.push({ net, hz: r.hz ?? 0, key: `${path}${n.id}:${r.id}` })
|
|
|
|
|
else if (!inNets) sources.set(rowSource(n.id, r.id), net)
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
else if (isPinRow(n, r)) union(net, inNets.get(rowPin(n.id, r.id)) ?? LOW)
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
else if (r.type === 'switch' && r.on) union(net, HIGH)
|
|
|
|
|
}
|
|
|
|
|
break
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'output':
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
result.set(n.id, pinIn(n, 'a'))
|
|
|
|
|
union(q, pinIn(n, 'a'))
|
|
|
|
|
break
|
|
|
|
|
case 'ref':
|
|
|
|
|
// Two tags of one name drive one signal: a short, like two wires on one input.
|
|
|
|
|
for (const t of tags.get(n.label?.trim() ?? '') ?? []) union(q, inNet(t.id, 'a'))
|
2026-10-20 18:09:23 +00:00
|
|
|
break
|
|
|
|
|
case 'lamp':
|
|
|
|
|
// A lamp passes its signal on to whatever its right pin feeds.
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
union(q, pinIn(n, 'a'))
|
2026-10-17 10:49:38 +00:00
|
|
|
break
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
case 'hex':
|
|
|
|
|
for (let i = 0; i < 4; i++) union(outNet.get(`${n.id}:q${i}`)!, inNet(n.id, `b${i}`))
|
|
|
|
|
break
|
2026-10-21 12:38:59 +00:00
|
|
|
case 'outpanel':
|
|
|
|
|
// Each row shows its signal and passes it on; inside a component the rows are its outputs.
|
|
|
|
|
for (const r of n.rows ?? []) {
|
|
|
|
|
const net = inNet(n.id, r.id)
|
|
|
|
|
union(outNet.get(`${n.id}:${r.id}`)!, net)
|
|
|
|
|
if (!n.inner) result.set(rowPin(n.id, r.id), net)
|
|
|
|
|
}
|
|
|
|
|
break
|
2026-10-22 16:59:56 +00:00
|
|
|
case 'portin':
|
|
|
|
|
case 'portout': {
|
|
|
|
|
// A connector port: its lines are the nets the parent handed in (fresh ones at the top).
|
|
|
|
|
const lines = portLines(n, getDef)
|
|
|
|
|
const nets = portNets?.get(n.id) ?? lines.map(() => make())
|
|
|
|
|
ends.set(`${n.id}:bus`, nets)
|
|
|
|
|
lines.forEach((l, i) => {
|
|
|
|
|
const net = nets[i]
|
|
|
|
|
if (net === undefined) return
|
|
|
|
|
if (l.enters) union(outNet.get(`${n.id}:${l.key}`)!, net)
|
|
|
|
|
else if (wiresTo.has(`${n.id}:${l.key}`)) union(inNet(n.id, l.key), net)
|
|
|
|
|
})
|
|
|
|
|
break
|
|
|
|
|
}
|
2026-10-17 10:49:38 +00:00
|
|
|
case 'chip': {
|
|
|
|
|
const child = n.chip ? getDef(n.chip) : undefined
|
|
|
|
|
const pins = pinsOf(n)
|
|
|
|
|
if (!child || !pins) {
|
|
|
|
|
errors.push(`Missing component in "${def.name}"`)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
const childIn = new Map<string, number>()
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
for (const p of pins.inputs) childIn.set(p.key, pinIn(n, p.key))
|
2026-10-22 16:59:56 +00:00
|
|
|
const childPorts = new Map<string, number[]>()
|
|
|
|
|
for (const p of pins.ports ?? []) {
|
|
|
|
|
const nets = (getDef.conn?.(p.conn)?.lines ?? []).map(() => make())
|
|
|
|
|
childPorts.set(p.key, nets)
|
|
|
|
|
ends.set(`${n.id}:${p.key}`, nets)
|
|
|
|
|
}
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
// A port split on the box: each line is a pin of its own as well. A
|
|
|
|
|
// wire into a line drives it like the cable would (both at once is a short).
|
|
|
|
|
for (const l of splitLines(n, pins, getDef)) {
|
|
|
|
|
const net = childPorts.get(l.port)?.[l.index]
|
|
|
|
|
if (net === undefined) continue
|
|
|
|
|
lineNets.set(`${n.id}:${l.key}`, net)
|
|
|
|
|
if (!l.enters) union(outNet.get(`${n.id}:${l.key}`)!, net)
|
|
|
|
|
else if (wiresTo.has(`${n.id}:${l.key}`)) union(inNet(n.id, l.key), net)
|
|
|
|
|
}
|
2026-10-22 16:59:56 +00:00
|
|
|
const childOut = expand(child, childIn, `${path}${n.id}/`, inner, childPorts)
|
2026-10-17 10:49:38 +00:00
|
|
|
for (const p of pins.outputs) union(outNet.get(`${n.id}:${p.key}`)!, childOut.get(p.key) ?? LOW)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-22 16:59:56 +00:00
|
|
|
// Typed cables: line i of one end is line i of the other.
|
|
|
|
|
for (const w of def.wires) {
|
|
|
|
|
const a = ends.get(`${w.from.node}:${w.from.pin}`)
|
|
|
|
|
const b = ends.get(`${w.to.node}:${w.to.pin}`)
|
|
|
|
|
if (a && b) for (let i = 0; i < Math.min(a.length, b.length); i++) union(a[i]!, b[i]!)
|
|
|
|
|
}
|
|
|
|
|
|
A finer component boxes, a regrouped parts list with keyboard search, a real green for wires and cables
- Box designer: drag pins up or down to open gaps between groups; size (+/−) and turn (R) lamps, displays, screens and drawings; pixels belong to named screens, each placed on its own; displays of the components inside can be shown on the box (off unless ticked); a list of everything the box can show, each optional; the box grows to hold what it shows
- Lamps and displays deep inside placed components light up on the box
- Parts list: one search box for parts and components (letters in order match too), recently placed parts first, grouped Logic / Inputs / Outputs / Wiring / Notes, then components by group; groups fold away
- Keys: / searches the parts list (Enter starts placing), Shift+A or Ctrl+K adds a part at the mouse
- Wires and cables get a green; the default swatch shows grey, as the default really is
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 04:48:42 +00:00
|
|
|
// Lamps, displays and pixels inside placed components, at every depth: a box may show those of parts inside it.
|
|
|
|
|
if (stack.length >= 1) {
|
A component faces, project library with share links, fine-grained wire editing
- Lamps and hex displays inside a component show on its box with their
labels, lit by that instance's state; Counter 4 example shows its count.
- Several projects per browser; share links at /p/<id> that the creator's
edits save to automatically, others get their own copy. Export, open a
file as project, or add a file's components to the open project.
- Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to
branch, double-click selects the whole signal, multi-select, arrow keys,
colour tags.
- Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted
as a volume on edgerealm.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
for (const n of def.nodes) {
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
if (n.kind === 'lamp' || n.kind === 'hex' || n.kind === 'pixel') for (const k of inputKeys(n)) rawFace.set(`${path}${n.id}:${k}`, pinIn(n, k))
|
A component faces, project library with share links, fine-grained wire editing
- Lamps and hex displays inside a component show on its box with their
labels, lit by that instance's state; Counter 4 example shows its count.
- Several projects per browser; share links at /p/<id> that the creator's
edits save to automatically, others get their own copy. Export, open a
file as project, or add a file's components to the open project.
- Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to
branch, double-click selects the whole signal, multi-select, arrow keys,
colour tags.
- Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted
as a volume on edgerealm.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-17 10:49:38 +00:00
|
|
|
if (inNets === null || rawTrace) {
|
|
|
|
|
const record = (n: CircuitNode, k: string, net: number) => {
|
|
|
|
|
if (inNets === null) rawPinNet.set(`${n.id}:${k}`, net)
|
|
|
|
|
rawTrace?.set(`${path}${n.id}:${k}`, net)
|
|
|
|
|
}
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
const pins = pinsOf(n)
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
for (const k of inputKeys(n, pins, getDef)) record(n, k, lineNets.get(`${n.id}:${k}`) ?? inNet(n.id, k))
|
2026-10-22 16:59:56 +00:00
|
|
|
for (const k of outputKeys(n, pins, getDef)) record(n, k, outNet.get(`${n.id}:${k}`)!)
|
2026-10-17 10:49:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const root = getDef(rootId)
|
2026-10-23 10:27:12 +00:00
|
|
|
const rootOut = root ? expand(root, null, '', []) : new Map<string, number>()
|
|
|
|
|
if (!root) errors.push('Circuit not found')
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
// Renumber union-find roots to 0..netCount-1, constants first.
|
|
|
|
|
const idx = new Int32Array(parent.length).fill(-1)
|
|
|
|
|
idx[find(LOW)] = LOW
|
|
|
|
|
idx[find(HIGH)] = HIGH
|
|
|
|
|
let netCount = 2
|
|
|
|
|
const canon = (x: number) => {
|
|
|
|
|
const r = find(x)
|
|
|
|
|
if (idx[r]! < 0) idx[r] = netCount++
|
|
|
|
|
return idx[r]!
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gateCount = gOut.length
|
|
|
|
|
const gateA = new Int32Array(gateCount)
|
|
|
|
|
const gateB = new Int32Array(gateCount)
|
|
|
|
|
const gateOut = new Int32Array(gateCount)
|
|
|
|
|
for (let i = 0; i < gateCount; i++) {
|
|
|
|
|
gateA[i] = canon(gA[i]!)
|
|
|
|
|
gateB[i] = canon(gB[i]!)
|
|
|
|
|
gateOut[i] = canon(gOut[i]!)
|
|
|
|
|
}
|
|
|
|
|
const mapNets = (m: Map<string, number>) => {
|
|
|
|
|
const out = new Map<string, number>()
|
|
|
|
|
for (const [k, v] of m) out.set(k, canon(v))
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
const pinNet = mapNets(rawPinNet)
|
|
|
|
|
const tracePinNet = rawTrace ? mapNets(rawTrace) : undefined
|
A component faces, project library with share links, fine-grained wire editing
- Lamps and hex displays inside a component show on its box with their
labels, lit by that instance's state; Counter 4 example shows its count.
- Several projects per browser; share links at /p/<id> that the creator's
edits save to automatically, others get their own copy. Export, open a
file as project, or add a file's components to the open project.
- Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to
branch, double-click selects the whole signal, multi-select, arrow keys,
colour tags.
- Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted
as a volume on edgerealm.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
const facePinNet = mapNets(rawFace)
|
2026-10-17 10:49:38 +00:00
|
|
|
const srcs = mapNets(sources)
|
A settings for every part, overlap-free wiring with crossing styles, accounts with sync
- Clicking anything opens its settings: swap parts in place (wires stay on
matching pins), clock frequency per clock, keyboard keys for switches and
buttons, lamp/display colours, note sizes, component names on the canvas,
position, unlink all wires, unpack a component, make an independent copy.
- Wires of different signals never share a line: auto routes pick free
columns or detours, remaining clashes go on separate lanes. Crossings drawn
as bow, triangle, bridge, gap or plain.
- Accounts (email + scrypt password, httpOnly session) with two-way project
sync and conflict copies; per-account limits; cross-site writes refused.
- Compatibility suite: a project and both browser-storage layouts from
release a241adc must load and compute identically.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
const seenClock = new Set<number>()
|
|
|
|
|
const clockList = clocks
|
|
|
|
|
.map(c => ({ ...c, net: canon(c.net) }))
|
|
|
|
|
.filter(c => !seenClock.has(c.net) && seenClock.add(c.net))
|
|
|
|
|
const clockNets = Int32Array.from(clockList.map(c => c.net))
|
2026-10-17 10:49:38 +00:00
|
|
|
|
|
|
|
|
// Fanout in CSR form.
|
|
|
|
|
const fanStart = new Int32Array(netCount + 1)
|
|
|
|
|
for (let i = 0; i < gateCount; i++) {
|
|
|
|
|
fanStart[gateA[i]! + 1]!++
|
|
|
|
|
if (gateB[i] !== gateA[i]) fanStart[gateB[i]! + 1]!++
|
|
|
|
|
}
|
|
|
|
|
for (let n = 0; n < netCount; n++) fanStart[n + 1]! += fanStart[n]!
|
|
|
|
|
const fanList = new Int32Array(fanStart[netCount]!)
|
|
|
|
|
const fill = fanStart.slice(0, netCount)
|
|
|
|
|
for (let i = 0; i < gateCount; i++) {
|
|
|
|
|
fanList[fill[gateA[i]!]!++] = i
|
|
|
|
|
if (gateB[i] !== gateA[i]) fanList[fill[gateB[i]!]!++] = i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
netCount,
|
|
|
|
|
gateA,
|
|
|
|
|
gateB,
|
|
|
|
|
gateOut,
|
|
|
|
|
gateKeys,
|
|
|
|
|
fanStart,
|
|
|
|
|
fanList,
|
|
|
|
|
pinNet,
|
|
|
|
|
tracePinNet,
|
A component faces, project library with share links, fine-grained wire editing
- Lamps and hex displays inside a component show on its box with their
labels, lit by that instance's state; Counter 4 example shows its count.
- Several projects per browser; share links at /p/<id> that the creator's
edits save to automatically, others get their own copy. Export, open a
file as project, or add a file's components to the open project.
- Wires: drag any segment or corner, Alt+drag for a new bend, Ctrl+drag to
branch, double-click selects the whole signal, multi-select, arrow keys,
colour tags.
- Share-link API (POST/GET/PUT /api/p) on Nitro fs storage in data/, mounted
as a volume on edgerealm.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 11:21:49 +00:00
|
|
|
facePinNet,
|
2026-10-23 10:27:12 +00:00
|
|
|
outputs: mapNets(rootOut),
|
2026-10-17 10:49:38 +00:00
|
|
|
sources: srcs,
|
|
|
|
|
clocks: clockNets,
|
A settings for every part, overlap-free wiring with crossing styles, accounts with sync
- Clicking anything opens its settings: swap parts in place (wires stay on
matching pins), clock frequency per clock, keyboard keys for switches and
buttons, lamp/display colours, note sizes, component names on the canvas,
position, unlink all wires, unpack a component, make an independent copy.
- Wires of different signals never share a line: auto routes pick free
columns or detours, remaining clashes go on separate lanes. Crossings drawn
as bow, triangle, bridge, gap or plain.
- Accounts (email + scrypt password, httpOnly session) with two-way project
sync and conflict copies; per-account limits; cross-site writes refused.
- Compatibility suite: a project and both browser-storage layouts from
release a241adc must load and compute identically.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 11:09:37 +00:00
|
|
|
clockHz: Float64Array.from(clockList.map(c => c.hz)),
|
|
|
|
|
clockKeys: clockList.map(c => c.key),
|
2026-10-17 10:49:38 +00:00
|
|
|
errors: [...new Set(errors)],
|
|
|
|
|
}
|
|
|
|
|
}
|