-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcommon.typ
More file actions
93 lines (83 loc) · 3 KB
/
common.typ
File metadata and controls
93 lines (83 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#import "@preview/cetz:0.4.2"
#let monotext(..args) = text(font: "Anonymous Pro", fallback: false, ..args)
#let awesome-brands(..args) = text(font: "Font Awesome 7 Brands", fallback: false, ..args)
#let awesome(..args) = text(font: "Font Awesome 7 Free Solid", fallback: false, ..args)
#let color-box(icon: none, title: none, fgcolor: black, bgcolor: white, title-color: white, content) = [
#let radius = 5pt
#box(fill: bgcolor, stroke: 2pt + fgcolor, radius: radius)[
#block(breakable: false, width: 100%, fill: fgcolor, inset: (x: 16pt, y: 8pt), below: 0pt, radius: (top-left: radius, top-right: radius))[
#awesome(fill: title-color, icon)
#text(fill: title-color, weight: "bold")[#title]
]
#block(breakable: false, width: 100%, inset: 16pt)[#content]
]
]
#let caveat(content) = [
#color-box(content, icon: "\u{f05a}", title: "Caveat", fgcolor: rgb("#DC143C"), bgcolor: rgb("#FFE4E1"))
]
#let speculation(content) = [
#color-box(content, icon: "\u{f12e}", title: "Speculation", fgcolor: rgb("#467BA9"), bgcolor: rgb("#F0FFFF"))
]
#let warning(content) = [
#color-box(content, icon: "\u{f06a}", title: "Warning", fgcolor: rgb("#FFD700"), bgcolor: rgb("#FFFACD"), title-color: rgb("#505050"))
]
#let bit(content) = monotext(content)
#let bin(content) = monotext("0b" + content)
#let hex(content) = monotext("0x" + content)
#let hex-range(start, end) = monotext({"0x" + start + "-0x" + end})
#let unimpl-bit() = table.cell(fill: rgb("#D3D3D3ff"))[]
#let reg-table(..args) = monotext(9pt)[
#table(
columns: (1fr, 1fr, 1fr, 1fr, 1fr, 1fr, 1fr, 1fr),
inset: 5pt,
align: center + horizon,
..args
)
]
#let reg-figure(caption: none, content) = [
#v(1cm)
#figure(
content,
caption: caption,
kind: "register",
supplement: [Register],
numbering: (..nums) => counter(heading).display((..hnums) => numbering("1", hnums.pos().at(1))) + "." + numbering("1", ..nums)
)
]
#let to-hex4(n) = {
let digits = "0123456789ABCDEF"
let result = ""
let rem = n
if rem == 0 { return "0000" }
while rem > 0 {
result = digits.at(calc.rem(rem, 16)) + result
rem = calc.quo(rem, 16)
}
while result.len() < 4 { result = "0" + result }
result
}
#let addr-space-figure(ticks: (), regions: (), caption: none) = figure(
{
set text(6pt)
cetz.canvas(length: 1cm, {
import cetz.draw: *
let W = 16.0
let H = 2.0
let total = 0x10000
for region in regions.sorted(key: r => if r.highlight { 1 } else { 0 }) {
let x0 = region.start / total * W
let x1 = region.end / total * W
rect((x0, 0), (x1, H), fill: region.color, stroke: black + if region.highlight { 1pt } else { 0.5pt })
if x1 - x0 >= 1.0 {
content((x0 + (x1 - x0) / 2, H / 2), align(center + horizon, region.label))
}
}
for addr in ticks {
let x = addr / total * W
line((x, 0), (x, -0.15), stroke: 0.4pt + black)
content((x, -0.2), anchor: "north", hex(to-hex4(addr)))
}
})
},
caption: caption,
)