Advertisement
aidanozo

Untitled

Nov 20th, 2024
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module full_flagram (
  2.     output wire [15:0] o_w_out,
  3.     input wire i_w_clk,
  4.     input wire [3:0] i_w_address,
  5.     input wire [3:0] i_w_data,
  6.     input wire i_w_we,
  7.     input wire i_w_oe,
  8.     input wire i_w_flags_out
  9. );
  10.     // FLAGS
  11.     wire [15:0] l_w_flags;
  12.  
  13.     // RAM read data
  14.     wire [3:0] l_w_ram_data;
  15.  
  16.     // RAM
  17.     sol_ram #(
  18.         .p_data_width(4),
  19.         .p_address_width(4)
  20.     ) ram_inst (
  21.         .o_w_out(l_w_ram_data),
  22.         .i_w_in(i_w_data),
  23.         .i_w_address(i_w_address),
  24.         .i_w_we(i_w_we),
  25.         .i_w_oe(i_w_oe),
  26.         .i_w_clk(i_w_clk)
  27.     );
  28.  
  29.     // Flags
  30.     wire Z_flag;
  31.     wire S_flag;
  32.     wire E_flag;
  33.     wire O_flag;
  34.     wire C2_flag;
  35.     wire S2_flag;
  36.     wire G4_flag;
  37.     wire L4_flag;
  38.     wire POW_flag;
  39.     wire SMAX_flag;
  40.     wire SMIN_flag;
  41.     wire MAX_flag;
  42.     wire PAL_flag;
  43.     wire SB2_flag;
  44.  
  45.     assign Z_flag = (|l_w_ram_data);
  46.     assign S_flag = l_w_ram_data[3];
  47.     assign E_flag = (~(^l_w_ram_data));
  48.     assign O_flag = (^l_w_ram_data);
  49.     assign C2_flag = !l_w_ram_data[2];
  50.     assign S2_flag = l_w_ram_data[2];
  51.     assign G4_flag = l_w_ram_data > 4'd4;
  52.     assign L4_flag = l_w_ram_data < 4'd4;
  53.     assign POW_flag = (l_w_ram_data == 4'd1) || (l_w_ram_data == 4'd2) || (l_w_ram_data == 4'd4) || (l_w_ram_data == 4'd8);
  54.     assign SMAX_flag = l_w_ram_data == 4'd7;
  55.     assign SMIN_flag = l_w_ram_data == 4'd8;
  56.     assign MAX_flag = l_w_ram_data == 4'd15;
  57.     assign PAL_flag = (l_w_ram_data[0] == l_w_ram_data[3]) && (l_w_ram_data[1] == l_w_ram_data[2]);
  58.     assign SB2_flag = (l_w_ram_data[3] == l_w_ram_data[2]) || (l_w_ram_data[2] == l_w_ram_data[1]) || (l_w_ram_data[1] == l_w_ram_data[0]);
  59.  
  60.     wire [15:0] l_w_flags_in;
  61.     wire [15:0] l_w_flags_out;
  62.     assign l_w_flags_in = {2'd0, SB2_flag, PAL_flag, MAX_flag, SMIN_flag, SMAX_flag, POW_flag, L4_flag, G4_flag, S2_flag, C2_flag, O_flag, E_flag, S_flag, Z_flag};
  63.  
  64.     // register for FLGAS
  65.     sol_register #(
  66.         .p_data_width(16)
  67.     ) register_inst (
  68.         .o_w_out(l_w_flags_out),
  69.         .i_w_in(l_w_flags_in),
  70.         .i_w_we(i_w_oe),
  71.         .i_w_oe(i_w_flags_out),
  72.         .i_w_clk(i_w_clk),
  73.         .i_w_reset(1'b1)
  74.     );
  75.  
  76.     assign o_w_out = i_w_we ? 16'd0 : (i_w_oe ? {12'd0, l_w_ram_data} : (i_w_flags_out ? l_w_flags_out : 16'd0));
  77.  
  78. endmodule
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. module sol_flagram (
  86.     output wire [3:0] o_w_out,
  87.     input wire i_w_clk,
  88.     input wire [3:0] i_w_address,
  89.     input wire [3:0] i_w_data,
  90.     input wire i_w_we,
  91.     input wire i_w_oe,
  92.     input wire i_w_flags_out
  93. );
  94.  
  95.     wire [15:0] l_w_full_out;
  96.  
  97.     full_flagram full_flagram_inst (
  98.         .o_w_out(l_w_full_out),
  99.         .i_w_clk(i_w_clk),
  100.         .i_w_address(i_w_address),
  101.         .i_w_data(i_w_data),
  102.         .i_w_we(i_w_we),
  103.         .i_w_oe(i_w_oe),
  104.         .i_w_flags_out(i_w_flags_out)
  105.     );
  106.  
  107.     assign o_w_out = (i_w_we || i_w_oe) ? l_w_full_out[3:0] : (
  108.         i_w_flags_out ? {l_w_full_out[4'd`OP3], l_w_full_out[4'd`OP2], l_w_full_out[4'd`OP1], l_w_full_out[4'd`OP0]} : 4'd0
  109.     );
  110. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement