Memory: Input renaming pass.
[firearm.git] / Terminal.v
CommitLineData
1d97a095
JW
1module Terminal(
2 input clk,
3
4 input cp_req,
5 input [31:0] cp_insn,
6 output reg cp_ack,
7 output reg cp_busy,
8 input cp_rnw,
9 output reg [31:0] cp_read = 0,
fd003c7a
JW
10 input [31:0] cp_write
11`ifdef verilator
12`else
13 , output reg [8:0] sys_odata = 0,
14 input [8:0] sys_idata,
15 output reg sys_tookdata = 0
16`endif
17);
1d97a095
JW
18
19 /* Terminal pretends to be cp5. */
20 reg towrite = 0;
21 reg [7:0] data = 0;
7282e8f8
JW
22 reg [8:0] indata = 0; /* High bit is if data is present. */
23 reg didread = 0;
1d97a095
JW
24
25 always @(*)
26 begin
27 towrite = 0;
28 data = 8'hxx;
29 cp_ack = 0;
30 cp_busy = 0;
7282e8f8
JW
31 cp_read = 0;
32 didread = 0;
1d97a095
JW
33 if (cp_req && (cp_rnw == 0) && (cp_insn[27:24] == 4'b1110) && (cp_insn[19:16] == 4'b0000) && (cp_insn[11:8] == 4'h5))
34 begin
35 towrite = 1;
36 data = cp_write[7:0];
37 cp_ack = 1;
7282e8f8
JW
38 end else if (cp_req && (cp_rnw == 1) && (cp_insn[27:24] == 4'b1110) && (cp_insn[19:16] == 4'b0001) && (cp_insn[11:8] == 4'h5))
39 begin
40 cp_read = {23'h0, indata[8:0]};
41 cp_ack = 1;
42 didread = cp_insn[7:5] == 1;
1d97a095
JW
43 end
44 end
c7963e21 45`ifdef verilator
1d97a095
JW
46 always @(posedge clk)
47 if (towrite)
48 $c("{extern void term_output(unsigned char d); term_output(",data,");}");
7282e8f8 49 else if (didread || !indata[8])
fb33d467 50 indata <= $c("({extern unsigned int term_input(); term_input();})");
fd003c7a
JW
51`else
52 always @(posedge clk)
53 begin
fb33d467 54 sys_odata <= {towrite,data};
fd003c7a
JW
55 if (didread || !indata[8])
56 begin
fb33d467
JW
57 indata <= sys_idata;
58 sys_tookdata <= 1;
fd003c7a 59 end else
fb33d467 60 sys_tookdata <= 0;
fd003c7a 61 end
c7963e21 62`endif
1d97a095 63endmodule
This page took 0.029622 seconds and 4 git commands to generate.