From dbfc6eb56b5088038ad3080b6c3bff57feaa8d7a Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Fri, 23 Oct 2026 12:24:35 +0200 Subject: [PATCH] WIP inverter fixes and a bottom parts dock (from Linux, before merging the Windows work) Co-Authored-By: Claude Opus 5.5 (1M context) --- app/assets/css/main.css | 709 +++++++++++++++++++++---- app/components/editor/App.vue | 24 +- app/components/editor/Canvas.vue | 23 +- app/components/editor/Dock.vue | 428 +++++++++++++++ app/components/editor/Inspector.vue | 33 +- app/components/editor/MenuCampaign.vue | 3 +- app/components/editor/NodeView.vue | 3 +- app/components/editor/Palette.vue | 317 ----------- app/components/editor/PartThumb.vue | 38 ++ app/components/editor/PinRow.vue | 2 +- app/components/editor/ProjectList.vue | 2 +- app/components/editor/Rail.vue | 34 -- app/components/editor/Toolbar.vue | 128 +++-- app/composables/useEditor.ts | 29 +- app/composables/useMenu.ts | 1 - app/lib/logic/analyze.ts | 4 +- app/lib/logic/compile.ts | 7 +- app/lib/logic/puzzles.ts | 4 +- app/lib/logic/sim.ts | 6 + app/lib/logic/wide.ts | 2 +- tests/signals.test.ts | 52 +- 21 files changed, 1286 insertions(+), 563 deletions(-) create mode 100644 app/components/editor/Dock.vue delete mode 100644 app/components/editor/Palette.vue create mode 100644 app/components/editor/PartThumb.vue delete mode 100644 app/components/editor/Rail.vue diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 0d5020d..49a2d37 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -55,48 +55,40 @@ kbd { } /* ── Layout ─────────────────────────────────────────────────────── */ +/* The canvas fills the screen; the bars, the parts dock and the side panel float over it. */ .app { - display: grid; - grid-template-rows: 48px 1fr; - height: 100dvh; -} - -.workspace { - --left: 236px; - --right: 300px; - display: grid; - grid-template-columns: var(--left) 1fr var(--right); - min-height: 0; -} - -.workspace.no-left { - --left: 36px !important; -} - -.workspace.no-right { - --right: 36px !important; -} - -.stage { position: relative; - min-width: 0; + height: 100dvh; + overflow: hidden; +} + +.workspace { + position: absolute; + inset: 0; +} + +.stage { + position: absolute; + inset: 0; overflow: hidden; } -.palette, .inspector { - background: var(--panel); - min-height: 0; + position: absolute; + z-index: 25; + top: 58px; + right: 10px; + bottom: 10px; + width: 316px; display: flex; flex-direction: column; -} - -.palette { - border-right: 1px solid var(--border); -} - -.inspector { - border-left: 1px solid var(--border); + min-height: 0; + background: rgb(19 24 31 / 0.96); + backdrop-filter: blur(8px); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: 0 18px 50px rgb(0 0 0 / 0.45); + overflow: hidden; } .scroll { @@ -107,51 +99,144 @@ kbd { scrollbar-color: var(--border) transparent; } -@media (max-width: 1100px) { - .workspace { - --left: 210px; - --right: 260px; - } -} - @media (max-width: 820px) { - .workspace { - grid-template-columns: 1fr; - grid-template-rows: 1fr 40%; - } - .palette { - display: none; - } .inspector { - border-left: 0; - border-top: 1px solid var(--border); + top: auto; + left: 8px; + right: 8px; + width: auto; + height: 45%; } } -/* ── Toolbar ────────────────────────────────────────────────────── */ -.toolbar { +/* ── Top bar ────────────────────────────────────────────────────── */ +.hud { + position: absolute; + z-index: 30; + top: 10px; + left: 10px; + right: 10px; + display: flex; + align-items: flex-start; + justify-content: space-between; + gap: 10px; + pointer-events: none; +} + +.hud-group { + display: flex; + align-items: center; + gap: 2px; + min-width: 0; + height: 38px; + padding: 0 4px; + background: rgb(19 24 31 / 0.92); + backdrop-filter: blur(8px); + border: 1px solid var(--border); + border-radius: 10px; + box-shadow: 0 6px 20px rgb(0 0 0 / 0.3); + pointer-events: auto; +} + +.hud-btn { + position: relative; + display: inline-flex; + align-items: center; + gap: 6px; + height: 30px; + min-width: 30px; + justify-content: center; + padding: 0 7px; + border-radius: 7px; + color: var(--text); + font-size: 13px; +} + +.hud-btn:hover:not(:disabled) { + background: var(--panel-2); +} + +.hud-btn.active { + color: var(--accent); + background: rgb(76 194 255 / 0.12); +} + +.hud-btn:disabled { + opacity: 0.35; + cursor: not-allowed; +} + +.hud-btn.brand { + color: var(--on); +} + +.hud-project { + max-width: 200px; + font-weight: 600; +} + +.hud-sep { + width: 1px; + height: 18px; + margin: 0 4px; + background: var(--border); +} + +.hud-circuit { + position: relative; display: flex; align-items: center; - justify-content: space-between; - gap: 12px; - padding: 0 10px; - background: var(--panel); - border-bottom: 1px solid var(--border); min-width: 0; } -.brand { - display: flex; - align-items: center; - gap: 8px; - font-weight: 700; - letter-spacing: -0.01em; - color: var(--on); - padding-right: 6px; +.hud-circuit select { + appearance: none; + max-width: 220px; + height: 30px; + padding: 0 24px 0 8px; + border-radius: 7px; + background: transparent; + color: var(--text); + font-size: 13px; + font-weight: 600; + cursor: pointer; } -.brand span { +.hud-circuit select:hover { + background: var(--panel-2); +} + +.hud-circuit svg { + position: absolute; + right: 6px; + pointer-events: none; +} + +.hud-select { + height: 28px; + padding: 0 4px; + border-radius: 7px; + background: var(--panel-2); + border: 1px solid var(--border); color: var(--text); + font-size: 12px; +} + +.hud-sim { + padding: 0 6px; +} + +.hud-sim .status { + background: transparent; +} + +@media (max-width: 760px) { + .hud-sim { + display: none; + } + .hud-project { + max-width: 90px; + } } .tb-btn { @@ -1615,8 +1700,8 @@ kbd { .zoom-controls { position: absolute; - right: 12px; - bottom: 12px; + left: 10px; + bottom: 10px; display: flex; align-items: center; gap: 2px; @@ -1662,7 +1747,7 @@ kbd { .toast { position: fixed; left: 50%; - bottom: 24px; + bottom: 104px; transform: translateX(-50%); z-index: 60; padding: 8px 14px; @@ -2292,7 +2377,7 @@ kbd { /* ── Right panel tabs ───────────────────────────────────────────── */ .itabs { display: grid; - grid-template-columns: repeat(4, 1fr); + grid-template-columns: repeat(4, 1fr) auto; border-bottom: 1px solid var(--border); flex-shrink: 0; } @@ -2643,48 +2728,23 @@ kbd { color: var(--text); } -.itabs { - grid-template-columns: 30px repeat(4, 1fr); -} - -.rail { +.itabs .itabs-tools { display: flex; - flex-direction: column; align-items: center; - gap: 2px; - padding-top: 6px; - background: var(--panel); - min-height: 0; + padding: 0 4px; } -.rail.left { - border-right: 1px solid var(--border); -} - -.rail.right { - border-left: 1px solid var(--border); -} - -.rail-btn { - display: grid; - place-items: center; - width: 28px; - height: 28px; - border-radius: 6px; - color: var(--muted); -} - -.rail-btn:hover { - background: var(--panel-2); - color: var(--text); -} - -.tabs .collapse-btn, .itabs .collapse-btn { - flex: 0 0 30px; - flex-direction: row; + flex: 0 0 26px; + width: 26px; + height: 26px; padding: 0; - border-bottom: 2px solid transparent; + border: 0; + border-radius: 6px; +} + +.itabs .collapse-btn.active { + color: var(--accent); } /* Ribbon cable: sleeve, dark core, one thin line per wire in its own colour. */ @@ -3819,3 +3879,440 @@ table.board { .menu-board .name-row .field { margin-bottom: 0; } + +/* ── Parts dock (bottom) ────────────────────────────────────────── */ +.dock { + position: absolute; + z-index: 28; + left: 50%; + bottom: 10px; + transform: translateX(-50%); + display: flex; + flex-direction: column; + align-items: center; + gap: 8px; + width: min(940px, calc(100% - 20px)); + pointer-events: none; +} + +/* With the side panel open, the dock keeps to the space left of it. */ +.workspace.with-panel .dock { + left: calc((100% - 336px) / 2); + width: min(940px, calc(100% - 356px)); +} + +.dock > * { + pointer-events: auto; +} + +.dock-bar { + display: flex; + align-items: center; + gap: 2px; + max-width: 100%; + padding: 4px; + overflow-x: auto; + scrollbar-width: none; + background: rgb(19 24 31 / 0.94); + backdrop-filter: blur(8px); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: 0 10px 30px rgb(0 0 0 / 0.4); +} + +.dock-cat { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + gap: 3px; + flex-shrink: 0; + min-width: 74px; + padding: 6px 8px 5px; + border-radius: 9px; + font-size: 11px; + font-weight: 600; + color: var(--muted); + transition: + background 0.12s, + color 0.12s; +} + +.dock-cat:hover, +.dock-cat.active { + color: var(--text); + background: var(--panel-2); +} + +.dock-cat.active { + box-shadow: inset 0 -2px 0 var(--accent); +} + +.dock-cat.task > svg { + color: var(--lamp); +} + +.dock-count { + position: absolute; + top: 3px; + right: 6px; + font-family: var(--font-mono); + font-size: 9px; + color: var(--muted); +} + +.dock-sep { + flex-shrink: 0; + width: 1px; + height: 30px; + margin: 0 4px; + background: var(--border); +} + +.dock-search { + display: flex; + align-items: center; + gap: 6px; + flex-shrink: 0; + width: 150px; + height: 40px; + padding: 0 10px; + border-radius: 9px; + color: var(--muted); + cursor: text; + transition: width 0.15s; +} + +.dock-search.open, +.dock-search:focus-within { + width: 220px; + background: var(--panel-2); + color: var(--text); +} + +.dock-search input { + flex: 1; + min-width: 0; + background: transparent; + font-size: 13px; + color: var(--text); + outline: none; +} + +.dock-flyout { + width: 100%; + background: rgb(19 24 31 / 0.96); + backdrop-filter: blur(8px); + border: 1px solid var(--border); + border-radius: 12px; + box-shadow: 0 16px 40px rgb(0 0 0 / 0.45); + overflow: hidden; +} + +.dock-flyout.pinned { + border-color: rgb(76 194 255 / 0.35); +} + +.flyout-head { + display: flex; + align-items: center; + gap: 12px; + min-height: 34px; + padding: 4px 8px 0 14px; +} + +.flyout-title { + font-size: 12px; + font-weight: 700; +} + +.flyout-note { + font-size: 11px; + color: var(--muted); +} + +.flyout-tabs { + display: flex; + gap: 2px; + overflow-x: auto; + scrollbar-width: none; +} + +.flyout-tabs button { + flex-shrink: 0; + padding: 4px 9px; + border-radius: 6px; + font-size: 12px; + font-weight: 600; + color: var(--muted); +} + +.flyout-tabs button:hover { + color: var(--text); +} + +.flyout-tabs button.active { + background: var(--panel-2); + color: var(--text); +} + +.flyout-tabs .count { + margin-left: 3px; + font-family: var(--font-mono); + font-size: 10px; + color: var(--muted); +} + +.flyout-progress { + display: flex; + align-items: center; + gap: 8px; + font-family: var(--font-mono); + font-size: 11px; + color: var(--muted); +} + +.flyout-progress .bar { + width: 120px; + height: 5px; + border-radius: 3px; + background: var(--bg); + overflow: hidden; +} + +.flyout-progress .bar span { + display: block; + height: 100%; + background: var(--on); +} + +.strip-wrap { + position: relative; +} + +.strip { + display: flex; + gap: 6px; + padding: 8px 12px 12px; + overflow-x: auto; + scroll-behavior: smooth; + scrollbar-width: thin; + scrollbar-color: var(--border) transparent; +} + +.strip-empty { + padding: 28px 8px; + font-size: 12px; + color: var(--muted); +} + +.strip-arrow { + position: absolute; + z-index: 2; + top: 0; + bottom: 6px; + display: grid; + place-items: center; + width: 32px; + color: var(--text); +} + +.strip-arrow.left { + left: 0; + background: linear-gradient(90deg, rgb(19 24 31) 40%, transparent); +} + +.strip-arrow.right { + right: 0; + background: linear-gradient(270deg, rgb(19 24 31) 40%, transparent); +} + +.tile-slot { + position: relative; + flex-shrink: 0; +} + +.tile { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + gap: 4px; + flex-shrink: 0; + width: 104px; + height: 104px; + padding: 6px 6px 7px; + border: 1px solid var(--border); + border-radius: 10px; + background: var(--panel-2); + text-align: center; + cursor: grab; + transition: + border-color 0.12s, + transform 0.12s, + background 0.12s; +} + +.tile:hover, +.tile.active { + border-color: var(--accent); + transform: translateY(-2px); +} + +.tile.placing { + border-color: var(--accent); + background: rgb(76 194 255 / 0.1); +} + +.tile.blocked { + cursor: not-allowed; + opacity: 0.5; +} + +.tile.blocked:hover { + transform: none; + border-color: var(--border); +} + +.tile-art { + display: grid; + place-items: center; + flex: 1; + width: 100%; + min-height: 0; + color: var(--muted); +} + +.part-thumb { + width: 100%; + height: 100%; + max-height: 58px; + overflow: visible; +} + +.part-thumb .node.ghost { + opacity: 1; +} + +.part-thumb text { + pointer-events: none; +} + +.tile-name { + width: 100%; + overflow: hidden; + font-size: 12px; + font-weight: 600; + line-height: 1.2; + white-space: nowrap; + text-overflow: ellipsis; +} + +.tile-meta { + font-size: 10px; + line-height: 1; + color: var(--muted); + white-space: nowrap; +} + +.tile-lock { + position: absolute; + top: 6px; + right: 6px; + color: var(--muted); +} + +.tile-edit { + position: absolute; + top: 4px; + right: 4px; + display: grid; + place-items: center; + width: 22px; + height: 22px; + border-radius: 6px; + background: var(--panel); + border: 1px solid var(--border); + color: var(--muted); + opacity: 0; + transition: opacity 0.12s; +} + +.tile-slot:hover .tile-edit, +.tile-edit:focus-visible { + opacity: 1; +} + +.tile-edit:hover { + color: var(--text); + border-color: var(--accent); +} + +.tile.add { + border-style: dashed; + cursor: pointer; +} + +.tile.task { + cursor: pointer; +} + +.tile.task.solved .tile-art { + color: var(--on); +} + +.tile.task.weekly .tile-art, +.tile.task.puzzle .tile-art { + color: var(--accent); +} + +.tile.task.locked { + opacity: 0.5; +} + +.tile.task.current { + border-color: var(--lamp); +} + +.flyout-enter-active, +.flyout-leave-active { + transition: + opacity 0.14s, + transform 0.14s; +} + +.flyout-enter-from, +.flyout-leave-to { + opacity: 0; + transform: translateY(8px); +} + +.dock-show { + position: absolute; + z-index: 28; + left: 50%; + bottom: 10px; + transform: translateX(-50%); + display: flex; + align-items: center; + gap: 6px; + padding: 5px 12px; + border-radius: 999px; + font-size: 12px; + font-weight: 600; + color: var(--muted); + background: rgb(19 24 31 / 0.92); + border: 1px solid var(--border); +} + +.dock-show:hover { + color: var(--text); +} + +@media (prefers-reduced-motion: reduce) { + .flyout-enter-active, + .flyout-leave-active, + .tile { + transition: none; + } +} diff --git a/app/components/editor/App.vue b/app/components/editor/App.vue index 619b44b..f588598 100644 --- a/app/components/editor/App.vue +++ b/app/components/editor/App.vue @@ -13,6 +13,9 @@ const link = computed(() => { return l && end ? { n: l.at + 1, total: l.queue.length, label: end.label, dir: end.dir } : null }) +/** The side panel: kept open, or open while something is selected. */ +const panel = computed(() => ed.sidebars.right || ed.selection.value.length + ed.wireSel.value.length > 0) + onMounted(() => { const stop = ed.startLoop() onBeforeUnmount(stop) @@ -34,18 +37,17 @@ watch(
- diff --git a/app/components/editor/Rail.vue b/app/components/editor/Rail.vue deleted file mode 100644 index de48c66..0000000 --- a/app/components/editor/Rail.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/app/components/editor/Toolbar.vue b/app/components/editor/Toolbar.vue index a829c55..9cfb6d5 100644 --- a/app/components/editor/Toolbar.vue +++ b/app/components/editor/Toolbar.vue @@ -1,4 +1,9 @@ diff --git a/app/composables/useEditor.ts b/app/composables/useEditor.ts index 840fef8..c48da87 100644 --- a/app/composables/useEditor.ts +++ b/app/composables/useEditor.ts @@ -172,15 +172,19 @@ function create() { } /** Tab shown in the right panel. */ const rightTab = ref<'selection' | 'circuit' | 'pins' | 'test'>('circuit') - /** Which side panels are open; remembered in this browser. */ - const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: true }) + /** + * Left: the parts dock at the bottom is shown. Right: the side panel is + * kept open (it also opens on its own while something is selected). + * Remembered in this browser; a fresh layout starts clean. + */ + const sidebars = reactive<{ left: boolean; right: boolean }>({ left: true, right: false }) try { - Object.assign(sidebars, JSON.parse(localStorage.getItem('logigate:sidebars') ?? '{}')) + Object.assign(sidebars, JSON.parse(localStorage.getItem('logigate:layout') ?? '{}')) } catch {} function toggleSidebar(side: 'left' | 'right', open = !sidebars[side]) { sidebars[side] = open try { - localStorage.setItem('logigate:sidebars', JSON.stringify(sidebars)) + localStorage.setItem('logigate:layout', JSON.stringify(sidebars)) } catch {} } /** Asks the canvas to centre on a part. */ @@ -805,8 +809,6 @@ function create() { /** The title menu shows when the app opens at /; links open straight into the editor. */ const screen = ref<'menu' | 'editor'>(location.pathname === '/' ? 'menu' : 'editor') const menuPage = ref('main') - /** Tab of the parts panel on the left. */ - const paletteTab = ref<'parts' | 'challenges'>('parts') function enterGame() { screen.value = 'editor' @@ -838,15 +840,21 @@ function create() { return m.id === meta.value.id ? project.value : loadProject(m.id) } - /** Into the campaign: the newest one, or a new one. */ + /** Into the campaign: the newest one where it was left, or a new one at its first challenge. */ function playCampaign() { const m = newestOf('campaign') if (m) switchProject(m.id) - else newProject(false, true) - paletteTab.value = 'challenges' + else startCampaign() enterGame() } + /** A new campaign, open at its first challenge. */ + function startCampaign() { + newProject(false, true) + const first = CHALLENGES.find(c => challengeOpen(project.value, c.id)) + if (first) beginChallenge(first) + } + /** Into the challenges project (made on first use: NAND only, every challenge open). */ function intoChallenges() { const m = newestOf('challenges') @@ -857,7 +865,6 @@ function create() { p.mode = 'challenges' activate(addProject(p), p) } - paletteTab.value = 'challenges' } function playChallenge(c: Challenge) { @@ -2135,7 +2142,7 @@ function create() { setScreen, screen, menuPage, - paletteTab, + startCampaign, enterGame, showMenu, projectMode, diff --git a/app/composables/useMenu.ts b/app/composables/useMenu.ts index bcb7d58..21b0558 100644 --- a/app/composables/useMenu.ts +++ b/app/composables/useMenu.ts @@ -96,7 +96,6 @@ export function useMenu() { function rename(id: string) { ed.selection.value = [id] ed.wireSel.value = [] - ed.toggleSidebar('right', true) ed.labelFocus.value++ } diff --git a/app/lib/logic/analyze.ts b/app/lib/logic/analyze.ts index 7904006..4a9c11d 100644 --- a/app/lib/logic/analyze.ts +++ b/app/lib/logic/analyze.ts @@ -37,7 +37,7 @@ export function truthTable(getDef: DefLookup, defId: string): TruthTable | { err const ins = pins.inputs.map((_, k) => (i >> (n - 1 - k)) & 1) pins.inputs.forEach((p, k) => sim.setSource(p.key, ins[k] === 1)) const settled = sim.run(SETTLE_BUDGET) - rows.push({ ins, outs: pins.outputs.map(p => sim.pin(p.key, 'a')), settled }) + rows.push({ ins, outs: pins.outputs.map(p => sim.output(p.key)), settled }) } return { inputs: pins.inputs.map(p => p.label), outputs: pins.outputs.map(p => p.label), rows } } @@ -176,7 +176,7 @@ export function runSteps(getDef: DefLookup, defId: string, steps: TestStep[]): T for (const [l, v] of Object.entries(step.set)) sim.setSource(find(pins.inputs, l)!.key, v === 1) if (!sim.run(SETTLE_BUDGET)) return { pass: false, message: 'The circuit oscillates and never settles', failedStep: i } for (const [l, want] of Object.entries(step.expect)) { - const got = sim.pin(find(pins.outputs, l)!.key, 'a') + const got = sim.output(find(pins.outputs, l)!.key) if (got !== want) { const inputs = Object.entries(step.set).map(([k, v]) => `${k}=${v}`).join(' ') return { pass: false, message: `With ${inputs}: ${l} is ${got}, expected ${want}`, failedStep: i } diff --git a/app/lib/logic/compile.ts b/app/lib/logic/compile.ts index c72cafa..fda4269 100644 --- a/app/lib/logic/compile.ts +++ b/app/lib/logic/compile.ts @@ -24,6 +24,8 @@ export interface Netlist { tracePinNet?: Map /** Inputs of lamps and displays inside the root's chips, keyed "chipNode/nodeId:pin", for drawing them on the chip. */ facePinNet: Map + /** What each of the root circuit's output pins puts out (keyed like ChipPins outputs), after any bubble on it. */ + outputs: Map /** User-driven sources in the root circuit (switches, buttons): nodeId → net. */ sources: Map clocks: Int32Array @@ -310,8 +312,8 @@ export function compile(getDef: DefLookup, rootId: string, opts: { trace?: boole } const root = getDef(rootId) - if (root) expand(root, null, '', []) - else errors.push('Circuit not found') + const rootOut = root ? expand(root, null, '', []) : new Map() + if (!root) errors.push('Circuit not found') // Renumber union-find roots to 0..netCount-1, constants first. const idx = new Int32Array(parent.length).fill(-1) @@ -373,6 +375,7 @@ export function compile(getDef: DefLookup, rootId: string, opts: { trace?: boole pinNet, tracePinNet, facePinNet, + outputs: mapNets(rootOut), sources: srcs, clocks: clockNets, clockHz: Float64Array.from(clockList.map(c => c.hz)), diff --git a/app/lib/logic/puzzles.ts b/app/lib/logic/puzzles.ts index 37c0704..f4b132f 100644 --- a/app/lib/logic/puzzles.ts +++ b/app/lib/logic/puzzles.ts @@ -71,7 +71,7 @@ export function describeCircuit(get: DefLookup, defId: string): { inputs: string if (!sim.run(STEP_BUDGET)) throw new Error('The circuit keeps oscillating, so it has no clear answer') steps.push({ set: Object.fromEntries(pins.inputs.map((p, k) => [p.label, ins[k]!])), - expect: Object.fromEntries(pins.outputs.map(p => [p.label, sim.pin(p.key, 'a')])), + expect: Object.fromEntries(pins.outputs.map(p => [p.label, sim.output(p.key)])), }) } return { inputs: pins.inputs.map(p => p.label), outputs: pins.outputs.map(p => p.label), steps, sequential } @@ -162,7 +162,7 @@ export function scoreSolution(components: ComponentDef[], defId: string, spec: P for (const [l, v] of Object.entries(step.set)) sim.setSource(find(pins.inputs, l)!.key, v === 1) if (!settle()) return out(false, left <= 0 ? 'The circuit takes too long to settle' : 'The circuit oscillates and never settles', delay) for (const [l, want] of Object.entries(step.expect)) { - const got = sim.pin(find(pins.outputs, l)!.key, 'a') + const got = sim.output(find(pins.outputs, l)!.key) if (got !== want) { const ins = Object.entries(step.set).map(([k, v]) => `${k}=${v}`).join(' ') return out(false, `${spec.steps.length > 1 << spec.inputs.length ? `Step ${i + 1}: with` : 'With'} ${ins}: ${l} is ${got}, expected ${want}`, delay) diff --git a/app/lib/logic/sim.ts b/app/lib/logic/sim.ts index 46935aa..5eedb3a 100644 --- a/app/lib/logic/sim.ts +++ b/app/lib/logic/sim.ts @@ -112,6 +112,12 @@ export class Simulator { return net === undefined ? 0 : this.values[net]! } + /** What an output pin of the root circuit puts out (a ChipPins output key), after any bubble on it. */ + output(key: string): number { + const net = this.nl.outputs.get(key) + return net === undefined ? 0 : this.values[net]! + } + /** Value at a lamp or display input inside one of the root circuit's chips. */ face(chipNode: string, node: string, pin: string): number { const net = this.nl.facePinNet.get(`${chipNode}/${node}:${pin}`) diff --git a/app/lib/logic/wide.ts b/app/lib/logic/wide.ts index 53803a8..daf9945 100644 --- a/app/lib/logic/wide.ts +++ b/app/lib/logic/wide.ts @@ -36,7 +36,7 @@ function table(get: DefLookup, base: string): number[] | null { sim.setSource(pins.inputs[0]!.key, (i & 2) !== 0) sim.setSource(pins.inputs[1]!.key, (i & 1) !== 0) if (!sim.run(200_000)) return null - out.push(sim.pin(pins.outputs[0]!.key, 'a')) + out.push(sim.output(pins.outputs[0]!.key)) } return out } diff --git a/tests/signals.test.ts b/tests/signals.test.ts index d49fd38..ea73693 100644 --- a/tests/signals.test.ts +++ b/tests/signals.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { nandCounts, stats } from '../app/lib/logic/analyze' +import { nandCounts, runSteps, stats, truthTable } from '../app/lib/logic/analyze' import { transistorBreakdown } from '../app/lib/logic/bulk' import { compile } from '../app/lib/logic/compile' import { chipPins } from '../app/lib/logic/geometry' @@ -130,3 +130,53 @@ describe('inverted inputs', () => { expect(stats(compile(lookup(p), 'outer')).nands).toBe(counts.get('outer')) }) }) + +describe('outputs as the checks read them', () => { + it('a bubble on an output pin counts in the truth table and the challenge check', () => { + // NOT: one NAND fed twice gives !A; a bubble on Q inverts it back to A. + const { p, def } = circuit( + [ + { id: 'a', kind: 'input', x: 0, y: 0, label: 'A' }, + { id: 'g', kind: 'nand', x: 6, y: 0 }, + { id: 'q', kind: 'output', x: 14, y: 0, label: 'Q', invert: ['a'] }, + ], + [ + { id: 'w1', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'a' } }, + { id: 'w2', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'b' } }, + { id: 'w3', from: { node: 'g', pin: 'q' }, to: { node: 'q', pin: 'a' } }, + ], + ) + const t = truthTable(lookup(p), def.id) + expect('rows' in t && t.rows.map(r => r.outs[0])).toEqual([0, 1]) + const steps = [ + { set: { A: 0 }, expect: { Q: 0 } }, + { set: { A: 1 }, expect: { Q: 1 } }, + ] + expect(runSteps(lookup(p), def.id, steps).pass).toBe(true) + // The output pin shows what leaves the circuit; its input pin shows the wire. + const s = run(p, def, { a: true }) + expect([s.pin('q', 'a'), s.pin('q', 'q'), s.output('q')]).toEqual([0, 1, 1]) + }) + + it('rows of an output panel are outputs in the truth table', () => { + const { p, def } = circuit( + [ + { id: 'a', kind: 'input', x: 0, y: 0, label: 'A' }, + { id: 'g', kind: 'nand', x: 6, y: 0 }, + { id: 'op', kind: 'outpanel', x: 14, y: 0, rows: [{ id: 'r0', type: 'switch', label: 'Y' }, { id: 'r1', type: 'switch', label: 'Z' }] }, + ], + [ + { id: 'w1', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'a' } }, + { id: 'w2', from: { node: 'a', pin: 'q' }, to: { node: 'g', pin: 'b' } }, + { id: 'w3', from: { node: 'g', pin: 'q' }, to: { node: 'op', pin: 'r0' } }, + { id: 'w4', from: { node: 'a', pin: 'q' }, to: { node: 'op', pin: 'r1' } }, + ], + ) + const t = truthTable(lookup(p), def.id) + expect('rows' in t && t.outputs).toEqual(['Y', 'Z']) + expect('rows' in t && t.rows.map(r => r.outs)).toEqual([ + [1, 0], + [0, 1], + ]) + }) +})