Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/dpv/LgateDPV.m4

raw
1 divert(-1)
2 # LgateDPV.m4
3 ###########################################################################
4
5 define(`And',`GenLogGate(AND,$@)')
6 define(`Nand',`GenLogGate(NAND,$@)')
7 define(`Or',`GenLogGate(OR,$@)')
8 define(`Nor',`GenLogGate(NOR,$@)')
9 define(`Xor',`GenLogGate(XOR,$@)')
10 define(`Nxor',`GenLogGate(NXOR,$@)')
11 define(`Not',`GenLogGate(NOT,$@)')
12
13 define(`GenLogGate',`[ pushdef(`m4nargs',0)dnl
14 # Count the arguments and draw the gate
15 Loopover_(`a',`define(`m4nargs',incr(m4nargs))',shift($@))dnl
16 G: ifelse(`$1',NOT,`NOT_gate()',`$1_gate(m4nargs)')
17 Out: G.Out
18 T: (G.In1.x-2*L_unit,G.y)
19 # Sublayer gates with centre at the height of G
20 SubLayer: [ pushdef(`m4_nct',0)
21 pushdef(`m4glayer')dnl
22 Loopover_(`arg',
23 `define(`m4_nct',incr(m4_nct))dnl
24 # Stack the input label or draw a sublayer gate
25 pushdef(`m4InNames')dnl
26 Gate`'m4_nct: ifelse(patsubst(substr(arg,0,1),`[a-zA-Z]',`&'),&,
27 `[ In`'arg: ifdef(`MarkLogInputs',`"arg" above',Here)
28 pushdef(`m4InNames',In`'arg)dnl
29 Out: Here ] ht 2*L_unit',
30 `arg') ifelse(m4_nct,1,,`with .ne at last [].se+(0,-L_unit)')
31 ifdef(`MarkSubLayers',
32 `{ box wid last [].wid ht last [].ht at last [] }')
33 # Prepend gate name to labels
34 m4LogPromote(Gate`'m4_nct)',
35 shift($@)) dnl
36 # Promote gate labels to Sublayer block
37 pushdef(`m4InNames') m4LogLabel()
38 MidOut: 0.5 between Gate`'eval((m4_nct+1)/2).Out \
39 and Gate`'eval((m4_nct+2)/2).Out
40 popdef(`m4_nct')dnl
41 ] with .MidOut at T+(-m4nargs*L_unit,0) # end SubLayer
42 ifdef(`MarkSubLayers',
43 `{ box wid last [].wid ht last [].ht at last [] }')
44 # Promote sublayer labels to outer block
45 pushdef(`m4glayer') m4LogPromote(SubLayer) dnl
46 pushdef(`m4InNames') m4LogLabel() dnl
47 # Draw the connecting lines
48 define(`m4hhv',`(m4nargs-1)/2')dnl
49 for_(1,m4nargs,1,`
50 line from G.In`'m4x \
51 left G.In`'m4x.x-T.x+(m4hhv-abs(m4x-m4hhv-1))*L_unit \
52 then up SubLayer.Gate`'m4x.Out.y-G.In`'m4x.y \
53 then to SubLayer.Gate`'m4x.Out')
54 popdef(`m4nargs') dnl
55 ]')
56
57 # Manage names of sublayer inputs
58 define(`m4LogPromote',`ifelse(m4InNames,,`popdef(`m4InNames')',
59 `pushdef(`m4glayer',m4InNames:$1)
60 popdef(`m4InNames') m4LogPromote($1)') ')dnl
61
62 define(`m4LogLabel',`ifelse(m4glayer,,`popdef(`m4glayer')',
63 `define(`m4BaseIn',`substr(m4glayer,0,index(m4glayer,:))')dnl
64 m4glayer.m4BaseIn
65 pushdef(`m4InNames',m4BaseIn) popdef(`m4glayer') m4LogLabel()') ')dnl
66
67 # Clear a name stack
68 define(`stack_del',`ifelse($1,`$1',,`popdef(`$1')$0($@)')')
69
70 ###########################################################################
71 divert(0)dnl
72 .PS
73 log_init(svg_font(sans-serif,11bp__))
74 #define(`MarkLogInputs')
75
76 define(`bbelow',`with .nw at last [].sw+(0,-0.2)')
77
78 define(`MarkLogInputs')
79 Ex1:Or(x1,q,`Or(y1,z1)',`Or(z3,u,v,`Or(w,r)',x2,y2,z2,m)')
80 `"Or(x1,q,`Or(y1,z1)',`Or(z3,u,v,`Or(w,r)',x2,y2,z2,m)')"' \
81 at Ex1.se+(-0.4,-0.2)
82 undefine(`MarkLogInputs')
83
84 line from Ex1.Inx1 to (Ex1.w,Ex1.Inx1)-(L_unit,0)
85 line from Ex1.Inx2 to (Here,Ex1.Inx2) then to Here; dot
86 line to Here-(2*L_unit,0); Inx: "x" above
87
88 line from Ex1.Iny1 to (Ex1.w,Ex1.Iny1)-(2*L_unit,0)
89 line from Ex1.Iny2 to (Here,Ex1.Iny2) then to Here; dot
90 line to Here-(2*L_unit,0); Iny: "y" above
91
92 line from Ex1.Inz1 to (Ex1.w,Ex1.Inz1)-(3*L_unit,0)
93 {line from Ex1.Inz3 to (Ex1.Inz3,Ex1.Inz1); dot}
94 line from Ex1.Inz2 to (Here,Ex1.Inz2) then to Here; dot
95 line to Here-(2*L_unit,0); Inz: "z" above
96
97 Ex2: And(`Not(A)',B,C,`Nor(A2,D)') with .nw at Ex1.Out+(0.75,0.2)
98 line right 3*L_unit from Ex2.Out
99 "svg_it(ABC(A+D))" above ljust at Ex2.G.nw
100 line right 0.1 at last ""+(0.1,0.16)
101 line right 0.35 at last ""+(0.55,0.16)
102 line from Ex2.InA2 to (Ex2.InA2,Ex2.InA); dot
103 line to Ex2.InA chop -3*L_unit chop 0
104 "svg_it(A)" rjust at last line.start
105 "svg_it(B)" rjust at Ex2.InB
106 "svg_it(C)" rjust at Ex2.InC
107 "svg_it(D)" rjust at Ex2.InD
108 `"And(`Not(A)',B,C,`Nor(A2,D)')"' wid 2.1 with .w at Ex2.sw-(0,0.2)
109 `"line from Ex2.InA2 to (Ex2.InA2,Ex2.InA); dot"' wid 3.2 \
110 with .w at last "".w+(0,-0.2)
111 `"line to Ex2.InA chop -3*L_unit chop 0"' wid 2.60 \
112 with .w at last "".w+(0,-0.2)
113 `"\"A\" rjust at last line.start"' wid 1.6 with .w at last "".w+(0,-0.2)
114 `"\"B\" rjust at Ex2.InB; \"C\" rjust at Ex2.InC"' wid 2.7 with .w \
115 at last "".w+(0,-0.2)
116
117 Ex3: Or(`And(A1,C1)',`And(B1,`Not(C2)')',`And(`Not(A2)',B2,C3)') \
118 with .nw at Ex1.sw+(0,-0.4)
119 line right 3*L_unit from Ex3.Out
120 line from Ex3.InB2 to (Ex3.InA2,Ex3.InB2)+(-2*L_unit,0) \
121 then up Ex3.InB1.y-Ex3.InB2.y; dot
122 line from Ex3.InB1 to Here chop 0 chop -2*L_unit; B: "svg_it(B)" rjust
123 line from Ex3.InA2 to (Ex3.InA2,Ex3.InA1); dot
124 line from Ex3.InA1 to (B,Here) ; "svg_it(A)" rjust
125 line from Ex3.InC2 to (Ex3.InC2,Ex3.InC1) then to Ex3.InC1
126 dot(at Ex3.InC2); line to (B,Here); "svg_it(C)" rjust
127 dot(at ((Ex3.InC2)+(-2*L_unit,0),Ex3.InC2))
128 line to (Here,Ex3.InC3) then to Ex3.InC3
129 "svg_it(AC+BC+ABC)" above ljust at Ex3.G.nw
130 line right 0.1 at last ""+(0.5,0.16)
131 line right 0.1 at last ""+(0.73,0.16)
132 `"Or(`And(A1,C1)',`And(B1,`Not(C2)')',`And(`Not(A2)',B2,C3)')"' \
133 at (B,Ex3.s)+(0,-0.2) ljust
134
135 # define(`MarkSubLayers')
136 Ex4: And(`Or(`Nand(`Or(A,B)',C)',D)',E) with .w at Ex3.e+(1.25,0)
137 "svg_it(A)" rjust at Ex4.InA
138 "svg_it(B)" rjust at Ex4.InB
139 line from Ex4.InC to (Ex4.InA,Ex4.InC); "svg_it(C)" rjust
140 line from Ex4.InD to (Ex4.InA,Ex4.InD); "svg_it(D)" rjust
141 line from Ex4.InE to (Ex4.InA,Ex4.InE); "svg_it(E)" rjust
142 line right 3*L_unit from Ex4.Out
143 "svg_it((D+(A+B)C)E)" above ljust at Ex4.G.nw
144 line right 0.5 at last ""+(0.6,0.16)
145 `"And(`Or(`Nand(`Or(A,B)',C)',D)',E)"' at Ex4.sw+(0,-0.2) ljust
146 # undefine(`MarkSubLayers')
147
148 stack_del(`m4InNames') # clear the name stack in case other diagrams need it
149 # extend the bounding box
150 move from Ex1.nw+(-0.35,0.1) to Ex4.Out+(1,-0.65)
151
152 command "</g>" # end font
153 .PE