commit source changes for cpud-hack

This commit is contained in:
2025-08-09 03:17:38 +08:00
parent 693676d61a
commit 30e54814b2
3 changed files with 38 additions and 27 deletions

View File

@@ -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
)
}

View File

@@ -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,

View File

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