build_no_slv <= conv_std_logic_vector(BUILD_NO, 16);


stat(S_HW_ID)        <= conv_std_logic_vector(TOP_ID, 16);         -- 0 0x00
stat(S_SANITY)       <= x"a510";                                   -- 1 0x02
stat(S_VERSION)      <= conv_std_logic_vector(BUILD_NO, 16);       -- 2 0x04
stat(S_MODULECOUNT)  <= conv_std_logic_vector(MODULECOUNT, 16);    -- 3 0x06
stat(S_TB_TCOUNT)    <= tb_tcount;                                 -- 4 0x08
stat(S_TB_BCOUNT)    <= tb_bcount;                                 -- 5 0x0a
stat(S_TBSQ_FLAGS)   <= sq_stat & tb_flags;                        -- 6 0x0c
stat(S_BCID_L1A)     <= x"0" & bcid_l1a;                           -- 7 0x0e
stat(S_L0ID_LO)      <= l0id(15 downto 0);                         -- 8 0x10
stat(S_L0ID_HI)      <= l0id(31 downto 16);                        -- 9 0x12
stat(S_SF0_STAT_LO)  <= sf_stat_word_i(0)(15 downto 0);            -- 10 0x14
stat(S_SF0_STAT_HI)  <= sf_stat_word_i(0)(31 downto 16);           -- 11 0x16
stat(S_SF1_STAT_LO)  <= sf_stat_word_i(1)(15 downto 0);            -- 12 0x18
stat(S_SF1_STAT_HI)  <= sf_stat_word_i(1)(31 downto 16);           -- 13 0x1a
stat(S_CU_STAT)      <= stat_word_cu(15 downto 0);                 -- 14 0x1c 
stat(S_GENSTAT)      <= stat_clks_top_i & stat_clks_main_i &
                        "00" & clk_ext_on_i & busy_ro;         -- 15 0x1e
stat(S_TOP_RAW)      <= RO_MOD_RAW(15 downto 0);                    -- 16 0x20
stat(S_TOP_HST)      <= RO_MOD_HST(15 downto 0);                    -- 17 0x22
stat(S_BOT_RAW)      <= RO_MOD_RAW(31 downto 16);                   -- 18 0x24
stat(S_BOT_HST)      <= RO_MOD_HST(31 downto 16);                   -- 19 0x26
stat(S_IDC_HSTRAW)   <= x"0" & RO_MOD_HST(35 downto 32) &
                        x"0" & RO_MOD_RAW(35 downto 32);            -- 20 0x28
stat(S_SPY_HOLD_REG) <= spy_hold_reg;                              -- 21 0x2a
stat(S_TIMESTAMP_LO) <= epoc_secs(15 downto 0);                    -- 22 0x2c
stat(S_TIMESTAMP_HI) <= epoc_secs(31 downto 16);                   -- 23 0x2e
stat(S_SQ_ADDR)      <= sq_addr;                                   -- 24 0x30
--stat(S_SK_ADDR)      <= sk_addr;                                   -- 25 0x32
stat(S_L0ID_L1)        <= x"00" & l0id_l1;                         -- 26 0x34
stat(27)             <= tdc_data_i(15 downto 0);                   -- 27 0x36
stat(28)             <= tdc_counter2_i(31 downto 16);                -- 28 0x38
stat(29)             <= tdc_counter2_i(15 downto 0);                 -- 29 0x3a
stat(30)             <= tdc_counter1_i(31 downto 16);                -- 30 0x3c
stat(31)             <= tdc_counter1_i(15 downto 0);                 -- 31 0x3e


MODULECOUNT <=
    conv_integer(RO_MOD_PRES(35)) +
    conv_integer(RO_MOD_PRES(34)) +
    conv_integer(RO_MOD_PRES(33)) +
    conv_integer(RO_MOD_PRES(32)) +
    conv_integer(RO_MOD_PRES(31)) +
    conv_integer(RO_MOD_PRES(30)) +
    conv_integer(RO_MOD_PRES(29)) +
    conv_integer(RO_MOD_PRES(28)) +
    conv_integer(RO_MOD_PRES(27)) +
    conv_integer(RO_MOD_PRES(26)) +
    conv_integer(RO_MOD_PRES(25)) +
    conv_integer(RO_MOD_PRES(24)) +
    conv_integer(RO_MOD_PRES(23)) +
    conv_integer(RO_MOD_PRES(22)) +
    conv_integer(RO_MOD_PRES(21)) +
    conv_integer(RO_MOD_PRES(20)) +
    conv_integer(RO_MOD_PRES(19)) +
    conv_integer(RO_MOD_PRES(18)) +
    conv_integer(RO_MOD_PRES(17)) +
    conv_integer(RO_MOD_PRES(16)) +
    conv_integer(RO_MOD_PRES(15)) +
    conv_integer(RO_MOD_PRES(14)) +
    conv_integer(RO_MOD_PRES(13)) +
    conv_integer(RO_MOD_PRES(12)) +
    conv_integer(RO_MOD_PRES(11)) +
    conv_integer(RO_MOD_PRES(10)) +
    conv_integer(RO_MOD_PRES(9)) +
    conv_integer(RO_MOD_PRES(8)) +
    conv_integer(RO_MOD_PRES(7)) +
    conv_integer(RO_MOD_PRES(6)) +
    conv_integer(RO_MOD_PRES(5)) +
    conv_integer(RO_MOD_PRES(4)) +
    conv_integer(RO_MOD_PRES(3)) +
    conv_integer(RO_MOD_PRES(2)) +
    conv_integer(RO_MOD_PRES(1)) +
    conv_integer(RO_MOD_PRES(0));