/* Altered System module for testbench. */
module System(DIN, Reset, PB, clock, WR_MEM_out, ADDR_out, DOUT_out, DONE, IR_out, R0_out, R1_out, R2_out, R3_out, R4_out, R5_out, R6_out, R7_out, A_out, G_out, CW);
input [15:0]DIN;
input Reset;
input PB;
input clock;
output wire WR_MEM_out;
output wire [15:0]DOUT_out;
output wire [15:0]ADDR_out;
output wire DONE;
output wire [15:0]IR_out;
output wire [15:0]R0_out;
output wire [15:0]R1_out;
output wire [15:0]R2_out;
output wire [15:0]R3_out;
output wire [15:0]R4_out;
output wire [15:0]R5_out;
output wire [15:0]R6_out;
output wire [15:0]R7_out;
output wire [15:0]G_out;
output wire [15:0]A_out;
//Control Wires
output wire [25:0]CW;
wire gnz;
wire [15:0]BusWires;
//Enables
wire R0_en, R1_en, R2_en, R3_en, R4_en, R5_en, R6_en, R7_en, A_en, G_en, IR_en;
wire ADD_SUB, COUNT_en, ADDR_en, DOUT_en, WR_MEM_en;
wire [9:0]Mux_sel;
assign Mux_sel[9:0] = CW[9:0];
assign R0_en = CW[10];
assign R1_en = CW[11];
assign R2_en = CW[12];
assign R3_en = CW[13];
assign R4_en = CW[14];
assign R5_en = CW[15];
assign R6_en = CW[16];
assign R7_en = CW[17];
assign A_en = CW[18];
assign G_en = CW[19];
assign IR_en = CW[20];
assign ADD_SUB = CW[21];
assign COUNT_en = CW[22];
assign ADDR_en = CW[23];
assign DOUT_en = CW[24];
assign WR_MEM_en = CW[25];
//Data not defined in output
wire [15:0]ADD_SUB_out;
wire [7:0]X_REG;
wire [7:0]Y_REG;
//Instantiate Registers
registers R0(Reset, R0_en, clock, BusWires, R0_out);
registers R1(Reset, R1_en, clock, BusWires, R1_out);
registers R2(Reset, R2_en, clock, BusWires, R2_out);
registers R3(Reset, R3_en, clock, BusWires, R3_out);
registers R4(Reset, R4_en, clock, BusWires, R4_out);
registers R5(Reset, R5_en, clock, BusWires, R5_out);
registers R6(Reset, R6_en, clock, BusWires, R6_out);
registers_count R7(Reset, R7_en, COUNT_en, clock, BusWires, R7_out);
registers A(Reset, A_en, clock, BusWires, A_out);
register_g G(Reset, G_en, clock, ADD_SUB_out, G_out, gnz);
registers IR(Reset, IR_en, clock, DIN, IR_out);
registers ADDR(Reset, ADDR_en, clock, BusWires, ADDR_out);
registers DOUT(Reset, DOUT_en, clock, BusWires, DOUT_out);
flip_flop WR_MEM(Reset, clock, WR_MEM_en, WR_MEM_out);
add_sub stuff(A_out, BusWires, ADD_SUB, ADD_SUB_out);
data_mux mux(Mux_sel, R0_out, R1_out, R2_out, R3_out, R4_out, R5_out, R6_out, R7_out, DIN, G_out, BusWires);
three_to_8_decoder x_decoder(IR_out[2:0],X_REG[7:0]);
three_to_8_decoder y_decoder(IR_out[5:3],Y_REG[7:0]);
control M1(IR_out[8:6], X_REG, Y_REG, PB, Reset, clock, gnz, CW[25:0], DONE);
endmodule