adapted ALU + minor fix in add-ports

This commit is contained in:
Louis Heredero 2025-04-19 17:16:09 +02:00
parent 4733f69b51
commit cd8784fcee
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
5 changed files with 50 additions and 71 deletions

Binary file not shown.

View File

@ -113,8 +113,7 @@
pos: (15, -3.5),
size: (3, 1),
id: "Extender",
fill: util.colors.green,
debug: (bounds: true, ports: true)
fill: util.colors.green
)
wire.wire(
"Extender.north",
@ -126,12 +125,12 @@
bus: true
)
/*
let mid = ("InstDataMgr.east", 50%, "RegFile.west")
wire.wire(
"InstDataMgr.Instr",
(vertical: (), horizontal: mid),
id: "wInstDataMgr-Bus"
id: "wInstDataMgr-Bus",
name: ("Instr", none),
bus: true
)
@ -144,7 +143,7 @@
wire.wire(
"RegFile.A1",
(horizontal: mid, vertical: ()),
id: "wBus-RegFile-A1"
id: "wBus-RegFile-A1",
name: (none, "RS1"),
slice: (19, 15),
reverse: true,
@ -153,7 +152,7 @@
wire.wire(
"RegFile.A3",
(horizontal: mid, vertical: ()),
id: "wBus-RegFile-A3"
id: "wBus-RegFile-A3",
name: (none, "RD"),
slice: (11, 7),
reverse: true,
@ -162,12 +161,12 @@
wire.wire(
"Extender.in",
(horizontal: mid, vertical: ()),
id: "wBus-Extender"
id: "wBus-Extender",
slice: (31, 7),
reverse: true,
bus: true
)
element.alu(
pos: (
22, (align: "in1", with: "RegFile.RD1")
@ -179,11 +178,13 @@
wire.wire(
"RegFile.RD1",
"ALU.in1",
id: "wRegFile-ALU"
id: "wRegFile-ALU",
name: ("A", "SrcA"),
bus: true
)
wire.stub("ALU.north", side: "north")
/*
element.block(
pos: (
26, (align: "in", with: "ALU.out")

View File

@ -1,45 +1,40 @@
#import "@preview/cetz:0.3.2": draw
#import "element.typ"
#import "ports.typ": add-port
#import "../util.typ"
#let draw-shape(elmt, bounds) = {
let tl = bounds.tl
let tr = bounds.tr
let bl = bounds.bl
let br = bounds.br
#let draw-shape(id, tl, tr, br, bl, fill, stroke) = {
let p0 = tl
let p1 = (tr, 10%, br)
let p2 = (tr, 90%, br)
let p1 = util.lerp(tr, 10%, br)
let p2 = util.lerp(tr, 90%, br)
let p3 = bl
let p4 = (tl, 55%, bl)
let p5 = (tl, 50%, br)
let p6 = (tl, 45%, bl)
let p4 = util.lerp(tl, 55%, bl)
let p5 = util.lerp(tl, 50%, br)
let p6 = util.lerp(tl, 45%, bl)
let bounds2 = element.complete-bounds(elmt, (
tl: p0,
tr: p1,
br: p2,
bl: p3
))
let f1 = draw.group(name: id, {
draw.merge-path(
inset: 0.5em,
fill: fill,
stroke: stroke,
close: true,
draw.line(p0, p1, p2, p3, p4, p5, p6)
)
draw.anchor("north", (p0, 50%, p1))
draw.anchor("south", (p2, 50%, p3))
draw.anchor("west", (p0, 50%, p3))
draw.anchor("east", (p1, 50%, p2))
draw.anchor("north-west", p0)
draw.anchor("north-east", p1)
draw.anchor("south-east", p2)
draw.anchor("south-west", p3)
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 f = {
f1; f2; f3; f4
draw.line(
p0, p1, p2, p3, p4, p5, p6,
fill: elmt.fill,
stroke: elmt.stroke,
close: true
)
draw.anchor("name", (p5, 50%, (p1, 50%, p2)))
}
return (f, tl, tr, br, bl)
return (f, bounds2)
}
/// Draws an ALU with two inputs
@ -47,18 +42,7 @@
/// #examples.alu
/// For parameters description, see #doc-ref("element.elmt")
#let alu(
x: none,
y: none,
w: none,
h: none,
name: none,
name-anchor: "center",
fill: none,
stroke: black + 1pt,
id: "",
debug: (
ports: false
)
..args
) = {
let ports = (
west: (
@ -70,24 +54,18 @@
)
)
element.elmt(
return element.elmt(
draw-shape: draw-shape,
x: x,
y: y,
w: w,
h: h,
name: name,
name-anchor: name-anchor,
ports: ports,
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}
ports-pos: (
west: (
in1: l => l * 0.225,
in2: l => l * 0.775,
),
east: (
out: l => l * 0.5
)
),
debug: debug
..args
)
}

View File

@ -10,7 +10,7 @@
}
}
}
panic("Could not find port with id '" + str(id) + "'")
panic("Could not find port with id '" + str(id) + "' in ports " + repr(ports))
}
#let local-to-global(origin, u, v, points) = {

View File

@ -142,7 +142,7 @@
pt0.at(1) - pt1.at(1)
}
for (i, port) in side-ports.enumerate() {
let offset = get-port-pos(elmt, bounds, side, port, i)
let offset = get-port-pos(elmt, bounds, side, port.id, i)
let pos = (pt0, offset, pt1)
let offset-prev = if type(offset) == ratio {