diff options
| author | Julian Blake Kongslie | 2021-07-06 09:44:36 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-07-06 09:44:36 -0700 |
| commit | 60e1775b874015a3451e4bde10a8eb30701b1165 (patch) | |
| tree | 477a2835c0f7e616bdeeabe6aee85f8af8b79650 /sim/decode.sv | |
| download | breadboarding-60e1775b874015a3451e4bde10a8eb30701b1165.tar.xz | |
Initial commit.
Diffstat (limited to '')
| -rw-r--r-- | sim/decode.sv | 82 |
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 @@ | |||
| 1 | module 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 | |||
| 15 | bit [OPCODE_BITS-1:0] opcode; | ||
| 16 | bit [BUS_BITS-1:0] a; | ||
| 17 | bit [BUS_BITS-1:0] b; | ||
| 18 | bit needmore; | ||
| 19 | |||
| 20 | bit [UIP_BITS-1:0] new_uip; | ||
| 21 | assign new_uip = {opcode, {(UIP_BITS-OPCODE_BITS){1'b0}}}; | ||
| 22 | |||
| 23 | typedef enum | ||
| 24 | { CLEAR | ||
| 25 | , DECODE | ||
| 26 | , OUTADDR | ||
| 27 | , OUTADDR_SEL0 | ||
| 28 | , OUTADDR_SEL1 | ||
| 29 | , OUTDATA | ||
| 30 | , OUTDATA_SEL0 | ||
| 31 | , OUTDATA_SEL1 | ||
| 32 | } CtrlBit; | ||
| 33 | |||
| 34 | bit [UROM_BITS-1:0] ctrl; | ||
| 35 | urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl); | ||
| 36 | |||
| 37 | bit [1:0] asel; | ||
| 38 | assign asel = {ctrl[OUTADDR_SEL1], ctrl[OUTADDR_SEL0]}; | ||
| 39 | |||
| 40 | bit [1:0] dsel; | ||
| 41 | assign dsel = {ctrl[OUTDATA_SEL1], ctrl[OUTDATA_SEL0]}; | ||
| 42 | |||
| 43 | bit [BUS_BITS-1:0] aout; | ||
| 44 | assign 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 | |||
| 50 | assign abus = ctrl[OUTADDR] ? aout : {(BUS_BITS){1'bZ}}; | ||
| 51 | |||
| 52 | bit [BUS_BITS-1:0] dout; | ||
| 53 | assign dout = | ||
| 54 | (dsel == 0) ? a : | ||
| 55 | (dsel == 1) ? b : | ||
| 56 | (dsel == 2) ? {{(BUS_BITS-1){1'b0}}, needmore} : | ||
| 57 | {(BUS_BITS){1'bX}}; | ||
| 58 | |||
| 59 | assign dbus = ctrl[OUTDATA] ? dout : {(BUS_BITS){1'bZ}}; | ||
| 60 | |||
| 61 | always @(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 | ||
| 81 | end | ||
| 82 | endmodule | ||
