summaryrefslogtreecommitdiff
path: root/sim/control.sv
blob: 7808f61de540784d4bfb4d7d6624e7a0422e9edf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module control
    #(  parameter   UROM        = "<no file specified>"
    ,   parameter   UIP_BITS    = 15
    ,   parameter   UROM_BITS   = 8
    ,   parameter   BUS_BITS    = 16
    ,   parameter   CONST_0     = "<no file specified>"
    ,   parameter   CONST_1     = "<no file specified>"
    ,   parameter   RESET       = ~0
    )
    (   input   bit                 clk
    ,   input   bit                 reset
    ,   output  bit [UIP_BITS-1:0]  uip
    ,   inout   bit [BUS_BITS-1:0]  abus
    ,   inout   bit [BUS_BITS-1:0]  dbus
    );

typedef enum
    { HALT
    , SET_UIP_COND
    , NOCOND
    , OUTADDR
    , OUTDATA
    } CtrlBit;

bit [UROM_BITS-1:0] ctrl;
urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl);

bit [UROM_BITS*2-1:0] constant;
urom#(CONST_0, UIP_BITS, UROM_BITS) const_0(uip, constant[1*UROM_BITS-1:0*UROM_BITS]);
urom#(CONST_1, UIP_BITS, UROM_BITS) const_1(uip, constant[2*UROM_BITS-1:1*UROM_BITS]);

assign abus = ctrl[OUTADDR] ? constant : {(BUS_BITS){1'bZ}};
assign dbus = ctrl[OUTDATA] ? constant : {(BUS_BITS){1'bZ}};

bit cond;
assign cond = (dbus != 0) || ctrl[NOCOND];

always @(posedge clk) begin
    if (reset) begin
        uip <= RESET;
    end else begin
        if (! ctrl[HALT]) begin
            if (ctrl[SET_UIP_COND] && cond) begin
                uip <= abus[UIP_BITS-1:0];
            end else begin
                uip <= uip + 1;
            end
        end else begin
            $finish;
        end
    end
end

endmodule