]>
Witch of Git - minecraft-eda/blob - genlib.py
2 Generate a cell library for redstone circuits
11 (12, {'Y': '!(A & B)'}),
13 (12, {'Y': '!(A | B)'}),
14 (18, {'Y': 'A & B & C'}),
15 (18, {'Y': '!(A & B & C)'}),
16 (18, {'Y': 'A | B | C'}),
17 (18, {'Y': '!(A | B | C)'}),
18 (18, {'Y': '(A & B) | C'}),
19 (18, {'Y': '(A & B) | !C'}),
20 (18, {'Y': '!(A & B) | C'}),
21 (18, {'Y': '!(A & B) | !C'}),
22 (18, {'Y': '(A | B) & C'}),
23 (18, {'Y': '!((A | B) & C)'}),
24 (24, {'Y': 'A & B & C & D'}),
25 (24, {'Y': '!(A & B & C & D)'}),
26 (24, {'Y': 'A | B | C | D'}),
27 (24, {'Y': '!(A | B | C | D)'}),
28 (24, {'Y': '(A | B) & (C | D)'}),
29 (24, {'Y': '!((A | B) & (C | D))'}),
30 (24, {'Y': '(A & B) | (C & D)'}),
31 (24, {'Y': '(A & B) | !(C & D)'}),
32 (24, {'Y': '!(A & B) | !(C & D)'}),
33 (24, {'Y': '!((A & B) | !(C & D))'}),
34 (24, {'Y': '!(!(A & B) | (C & D))'}),
35 (24, {'Y': '!(!(A & B) | !(C & D))'}),
36 (24, {'Y': '(A | B) & C & D'}),
37 (24, {'Y': '!((A | B) & C & D)'}),
38 (24, {'Y': '(A | B) & (C | D)'}),
39 (24, {'Y': '!((A | B) & (C | D))'}),
43 ff(IQ, IQN) { clocked_on: C; next_state: D; }
44 pin(C) { direction: input; clock: true; }
45 pin(D) { direction: input; }
46 pin(Q) { direction: output; function: "IQ"; }
52 ff(IQ, IQN) { clocked_on: "!C"; next_state: D; }
53 pin(C) { direction: input; clock: true; }
54 pin(D) { direction: input; }
55 pin(Q) { direction: output; function: "IQ"; }
62 for eq
in eqs
.values():
64 eq
.replace('(', ' ').replace(')', ' ')
65 .replace('&', ' ').replace('|', ' ')
66 .replace('+', ' ').replace('*', ' ')
67 .replace('!', ' ').split()
73 f
"{x}={f.replace(' ', '').replace('|', '+')}"
74 for x
, f
in eqs
.items()
77 def print_lib(lib
, defns
):
78 print(f
"library({lib}) {{")
80 for i
, defn
in enumerate(defns
):
81 if isinstance(defn
, str):
82 print(' ' + defn
.strip().replace('\n', '\n '))
87 print(f
"Warning: {name} defined at both {defined[name]} and {i}, skipping...", file=sys
.stderr
)
90 inputs
= find_inputs(eqs
)
91 print(f
""" cell("{name}") {{""")
92 print(f
""" area: {area};""")
93 for pin
in sorted(inputs
):
94 print(f
" pin({pin}) {{ direction: input; }}")
95 for x
, f
in eqs
.items():
96 print(f
""" pin({x}) {{ direction: output; function: "{f}"; }}""")
100 print_lib("redstone", CELLS
)