3 `define STATE_INIT 3'd0
4 `define STATE_READ_A 3'd1
5 `define STATE_READ_B 3'd2
6 `define STATE_WRITE 3'd3
10 `define FLAG_ROUTER 4'd10
11 `define FLAG_ROUTER_ACK 4'd11
12 `define FLAG_DAISY_CHAIN 4'd12
13 `define FLAG_LONG_PARITY 4'd13
14 `define FLAG_INPUT 4'd14
15 `define FLAG_ZERO 4'd15
17 `define DIRECTION_N 3'd0
18 `define DIRECTION_NE 3'd1
19 `define DIRECTION_E 3'd2
20 `define DIRECTION_SE 3'd3
21 `define DIRECTION_S 3'd4
22 `define DIRECTION_SW 3'd5
23 `define DIRECTION_W 3'd6
24 `define DIRECTION_NW 3'd7
27 (input clk, input text[54:0],
28 input cube, input daisy_chain, input pin_input, input router_ack,
29 input [7:0] news_in, output [7:0] news_out,
30 output flag_out, output reg writing_to_router,
31 output mem_in, input mem_out
34 wire [3:0] read_flag = text[30:27];
35 wire [3:0] write_flag = text[26:23];
36 wire [3:0] condition_flag = text[22:19];
37 wire condition_sense = text[18];
38 wire [7:0] memory_truth_table = text[17:10];
39 wire [7:0] flag_truth_table = text[9:2];
40 wire [1:0] news_direction = text[1:0];
42 reg [7:0] general_flags;
44 wire [15:0] flags = {1'd0, pin_input, 1'd0, daisy_chain, router_ack, 1'd0, cube, news_flag, general_flags};
47 flags[7:0] = general_flags[7:0];
49 `DIRECTION_NORTH: news_flag = north_in;
50 `DIRECTION_EAST: news_flag = east_in;
51 `DIRECTION_WEST: news_flag = west_in;
52 `DIRECTION_SOUTH: news_flag = south_in;
53 endcase // case (news_direction)
66 alu_in_f = flags[read_flag];
67 alu_index = (alu_in_a << 2) + (alu_in_b << 1) + alu_in_f;
69 alu_out_memory = memory_truth_table[alu_index];
70 alu_out_flag = flag_truth_table[alu_index];
73 assign flag_out = alu_out_flag;
75 reg [2:0] state = `STATE_INIT;
77 always @ (posedge clk) begin
81 mem_addr <= address_a;
82 state <= `STATE_READ_A
88 mem_addr <= address_b;
90 writing_to_router <= 0;
91 state <= `STATE_READ_B;
97 mem_addr <= address_a;
98 state <= `STATE_WRITE;
103 mem_in <= alu_out_memory;
105 state <= `STATE_READ_A;
108 general_flags[write_flag[2:0]] <= alu_out_flag;
110 if(write_flag == `FLAG_ROUTER_DATA)
111 writing_to_router <= 1;