dmgcpu
1// Elements of standard schematics ("kinda cells") used in the sequencer. Moved separately.
2
3// Module Definitions [It is possible to wrap here on your primitives]
4
5`timescale 1ns/1ns
6
7// This module is essentially used to generate the #MREQ signal. Very cleverly twisted combined logic.
8module seq_mreq ( a, b, c, d, x );
9
10input a;
11input b;
12input c;
13input d;
14output x;
15
16assign x = d ? ~((~a & c) | ~(a|b)) : 1'b1;
17
18endmodule // seq_mreq
19
20// Regular posedge DFF (dual rails)
21module seq_dff_posedge_comp ( d, clk, cclk, q );
22
23input d;
24input clk;
25input cclk;
26output q;
27
28reg val;
29initial val = 1'bx;
30
31always @(posedge clk) begin
32val <= d;
33end
34
35assign q = val;
36
37endmodule // seq_dff_posedge_comp
38
39module seq_not ( a, x );
40
41input a;
42output x;
43
44assign x = ~a;
45
46endmodule // seq_not
47
48module seq_nor3 ( a, b, c, x );
49
50input a;
51input b;
52input c;
53output x;
54
55assign x = ~(a|b|c);
56
57endmodule // seq_nor3
58
59module seq_nor ( a, b, x );
60
61input a;
62input b;
63output x;
64
65assign x = ~(a|b);
66
67endmodule // seq_nor
68
69module seq_aoi_31 ( a0, a1, a2, b, x );
70
71input a0;
72input a1;
73input a2;
74input b;
75output x;
76
77assign x = ~( (a0&a1&a2) | b);
78
79endmodule // seq_aoi_31
80
81module seq_oai_21 ( a0, a1, b, x );
82
83input a0;
84input a1;
85input b;
86output x;
87
88assign x = ~( (a0|a1) & b );
89
90endmodule // seq_oai_21
91
92// This is essentially the same rs_latch, but with the inputs rearranged.
93module seq_rs_latch2 ( nr, s, q );
94
95input nr;
96input s;
97output q;
98
99reg val;
100// Let's lower the difficulty level and use 0 here instead of `x`.
101initial val = 1'b0;
102
103// The module design is such that reset overrides set if both are set at the same time.
104always @(*) begin
105if (~nr)
106val = 1'b0;
107else if (s)
108val = 1'b1;
109end
110
111assign q = val;
112
113endmodule // seq_rs_latch2
114
115// rs_latch
116module seq_rs_latch ( nr, s, q );
117
118input nr;
119input s;
120output q;
121
122reg val;
123// Let's lower the difficulty level and use 0 here instead of `x`.
124initial val = 1'b0;
125
126// The module design is such that reset overrides set if both are set at the same time.
127always @(*) begin
128if (~nr)
129val = 1'b0;
130else if (s)
131val = 1'b1;
132end
133
134assign q = val;
135
136endmodule // seq_rs_latch
137
138module seq_latchr_comp ( q, d, res, clk, cclk, ld, nld);
139
140output q;
141input d;
142input res;
143input clk;
144input cclk;
145input ld;
146input nld;
147
148reg val_in;
149reg val_out;
150initial val_in = 1'bx;
151initial val_out = 1'bx;
152
153always @(*) begin
154if (clk && ld)
155val_in = d;
156if (res)
157val_in = 1'b0;
158end
159
160always @(negedge ld) begin
161val_out <= val_in;
162end
163
164assign q = val_out;
165
166endmodule // seq_latchr_comp
167
168module seq_nand ( a, b, x );
169
170input a;
171input b;
172output x;
173
174assign x = ~(a&b);
175
176endmodule // seq_nand
177
178module seq_nand3 ( a, b, c, x );
179
180input a;
181input b;
182input c;
183output x;
184
185assign x = ~(a&b&c);
186
187endmodule // seq_nand3
188
189module seq_nor4 ( a, b, c, d, x );
190
191input a;
192input b;
193input c;
194input d;
195output x;
196
197assign x = ~(a|b|c|d);
198
199endmodule // seq_nor4
200
201module seq_aoi_21 ( a0, a1, b, x );
202
203input a0;
204input a1;
205input b;
206output x;
207
208assign x = ~( (a0&a1) | b);
209
210endmodule // seq_aoi_21
211
212// Regular transparent latch (dual rails)
213module seq_latch_comp ( d, clk, cclk, nq );
214
215input d;
216input clk;
217input cclk;
218output nq;
219
220reg val;
221initial val = 1'b0;
222
223always @(*) begin
224if (clk)
225val = d;
226end
227
228assign nq = ~val;
229
230endmodule // seq_latch_comp
231
232module seq_aoi_22_dyn ( clk, a0, a1, b0, b1, x );
233
234input clk;
235input a0;
236input a1;
237input b0;
238input b1;
239output x;
240
241assign x = clk ? ~( (a0&a1) | (b0&b1) ) : 1'b1;
242
243endmodule // seq_aoi_22_dyn
244
245module seq_aoi_221_dyn ( clk, a0, a1, b0, b1, c, x );
246
247input clk;
248input a0;
249input a1;
250input b0;
251input b1;
252input c;
253output x;
254
255assign x = clk ? ~( (a0&a1) | (b0&b1) | c) : ~c;
256
257endmodule // seq_aoi_221_dyn
258