From 30e54814b2ff495cb053eb1b2c08c893a5052df0 Mon Sep 17 00:00:00 2001 From: Zjl37 <2693911885@qq.com> Date: Sat, 9 Aug 2025 03:17:38 +0800 Subject: [PATCH] commit source changes for cpud-hack --- src/elements/alu.typ | 47 +++++++++++++++++++++--------------------- src/elements/ports.typ | 4 +++- src/wire.typ | 14 ++++++++++--- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/elements/alu.typ b/src/elements/alu.typ index 9a8cb82..ada1c10 100644 --- a/src/elements/alu.typ +++ b/src/elements/alu.typ @@ -1,6 +1,6 @@ #import "@preview/cetz:0.3.2": draw #import "element.typ" -#import "ports.typ": add-port +#import "ports.typ": add-ports, add-port #let draw-shape(id, tl, tr, br, bl, fill, stroke) = { let p0 = tl @@ -31,15 +31,15 @@ draw.anchor("name", (p5, 50%, (p1, 50%, p2))) }) - let f2 = add-port(id, "west", (id: "in1"), (p0, 50%, p6)) - let f3 = add-port(id, "west", (id: "in2"), (p3, 50%, p4)) - let f4 = add-port(id, "east", (id: "out"), (p1, 50%, p2)) + // let f2 = add-port(id, "west", (id: "in1"), (p0, 50%, p6)) + // let f3 = add-port(id, "west", (id: "in2"), (p3, 50%, p4)) + // let f4 = add-port(id, "east", (id: "out"), (p1, 50%, p2)) - let f = { - f1; f2; f3; f4 - } + // let f = { + // f1; f2; f3; f4 + // } - return (f, tl, tr, br, bl) + return (f1, tl, tr, br, bl) } /// Draws an ALU with two inputs @@ -53,14 +53,7 @@ h: none, name: none, name-anchor: "center", - fill: none, - stroke: black + 1pt, - id: "", - debug: ( - ports: false - ) -) = { - let ports = ( + ports: ( west: ( (id: "in1"), (id: "in2"), @@ -68,8 +61,15 @@ east: ( (id: "out"), ) + ), + ports-margins: (west: (-30%, -30%)), + fill: none, + stroke: black + 1pt, + id: "", + debug: ( + ports: false ) - +) = { element.elmt( draw-shape: draw-shape, x: x, @@ -79,15 +79,16 @@ name: name, name-anchor: name-anchor, ports: ports, + ports-margins: ports-margins, fill: fill, stroke: stroke, id: id, - auto-ports: false, - ports-y: ( - in1: (h) => {h * 0.225}, - in2: (h) => {h * 0.775}, - out: (h) => {h * 0.5} - ), + // auto-ports: false, + // ports-y: ( + // in1: (h) => {h * 0.225}, + // in2: (h) => {h * 0.775}, + // out: (h) => {h * 0.5} + // ), debug: debug ) } \ No newline at end of file diff --git a/src/elements/ports.typ b/src/elements/ports.typ index 951fa4a..fb0a3b9 100644 --- a/src/elements/ports.typ +++ b/src/elements/ports.typ @@ -24,8 +24,10 @@ let pos1 = (rel: offset, to: pos) + let clock-line-style = port.at("clock-line-style", default: (:)) + // TODO: use context or vectors to have the height relative to the width - draw.line(prev, pos1, next) + draw.line(prev, pos1, next, ..clock-line-style) } draw.content( pos, diff --git a/src/wire.typ b/src/wire.typ index 8300a2c..e25b28e 100644 --- a/src/wire.typ +++ b/src/wire.typ @@ -215,7 +215,7 @@ if name != none { let names = () - if type(name) == str { + if type(name) == str or type(name) == content { names = ((name, name-pos),) } else if type(name) == array { @@ -267,7 +267,9 @@ /// - vertical (bool): Whether the name should be displayed vertically /// - length (number): The length of the stub /// - name-offset (number): The name offset, perpendicular to the stub -#let stub(port-id, side, name: none, vertical: false, length: 1em, name-offset: 0) = { +#let stub(port-id, side, name: none, vertical: false, length: none, name-offset: 0, directed: false) = { + let length = if length != none { length } else if directed { 1.5em } else { 1em } + let end-offset = ( north: (0, length), east: (length, 0), @@ -282,9 +284,15 @@ west: (-length, name-offset) ).at(side) + let mark = (:) + if directed { + mark = (end: ">", fill: black) + } + draw.line( + (rel: end-offset, to: port-id), port-id, - (rel: end-offset, to: port-id) + mark: mark ) if name != none { let text-anchor = if vertical {