summaryrefslogtreecommitdiff
path: root/sim/decode.sv
diff options
context:
space:
mode:
Diffstat (limited to 'sim/decode.sv')
-rw-r--r--sim/decode.sv82
1 files changed, 82 insertions, 0 deletions
diff --git a/sim/decode.sv b/sim/decode.sv
new file mode 100644
index 0000000..5c9a9c9
--- /dev/null
+++ b/sim/decode.sv
@@ -0,0 +1,82 @@
1module decode
2 #( parameter UROM = "<no file specified>"
3 , parameter UIP_BITS = 15
4 , parameter UROM_BITS = 8
5 , parameter BUS_BITS = 16
6 , parameter OPCODE_BITS = 8
7 )
8 ( input bit clk
9 , input bit reset
10 , input bit [UIP_BITS-1:0] uip
11 , inout bit [BUS_BITS-1:0] abus
12 , inout bit [BUS_BITS-1:0] dbus
13 );
14
15bit [OPCODE_BITS-1:0] opcode;
16bit [BUS_BITS-1:0] a;
17bit [BUS_BITS-1:0] b;
18bit needmore;
19
20bit [UIP_BITS-1:0] new_uip;
21assign new_uip = {opcode, {(UIP_BITS-OPCODE_BITS){1'b0}}};
22
23typedef enum
24 { CLEAR
25 , DECODE
26 , OUTADDR
27 , OUTADDR_SEL0
28 , OUTADDR_SEL1
29 , OUTDATA
30 , OUTDATA_SEL0
31 , OUTDATA_SEL1
32 } CtrlBit;
33
34bit [UROM_BITS-1:0] ctrl;
35urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl);
36
37bit [1:0] asel;
38assign asel = {ctrl[OUTADDR_SEL1], ctrl[OUTADDR_SEL0]};
39
40bit [1:0] dsel;
41assign dsel = {ctrl[OUTDATA_SEL1], ctrl[OUTDATA_SEL0]};
42
43bit [BUS_BITS-1:0] aout;
44assign aout =
45 (asel == 0) ? a :
46 (asel == 1) ? b :
47 (asel == 2) ? {{(BUS_BITS-UIP_BITS){1'b0}}, new_uip} :
48 {(BUS_BITS){1'bX}};
49
50assign abus = ctrl[OUTADDR] ? aout : {(BUS_BITS){1'bZ}};
51
52bit [BUS_BITS-1:0] dout;
53assign dout =
54 (dsel == 0) ? a :
55 (dsel == 1) ? b :
56 (dsel == 2) ? {{(BUS_BITS-1){1'b0}}, needmore} :
57 {(BUS_BITS){1'bX}};
58
59assign dbus = ctrl[OUTDATA] ? dout : {(BUS_BITS){1'bZ}};
60
61always @(posedge clk) begin
62 if (reset || ctrl[CLEAR]) begin
63 opcode <= 0;
64 a <= 0;
65 b <= 0;
66 needmore <= 1;
67 end else if (ctrl[DECODE]) begin
68 automatic bit m = dbus[7];
69 automatic bit i = dbus[6];
70 automatic bit [1:0] field = dbus[5:4];
71 automatic bit [3:0] shift = dbus[3:0];
72 needmore <= m;
73 if (field == 0) begin
74 opcode <= {i ? ~opcode[OPCODE_BITS-1-4:0] : opcode[OPCODE_BITS-1-4:0], shift};
75 end else if (field == 2) begin
76 a <= {i ? ~a[BUS_BITS-1-4:0] : a[BUS_BITS-1-4:0], shift};
77 end else if (field == 3) begin
78 b <= {i ? ~b[BUS_BITS-1-4:0] : b[BUS_BITS-1-4:0], shift};
79 end
80 end
81end
82endmodule