MiSTer FPGA SVI-328コアをNTTデータキーパッドだけで操作する

MiSTer FPGA SVI-328コアをNTTデータキーパッドだけで操作したい。

github.com

まずはMiSTerメニューをジョイパッド「.」、ボタンをジョイパッド「B」にアサインします。あとは数字キーが必要な事に気づきます。キーボードにジョイパッドの情報も連携して、数字キーをジョイパッド「0」「1」「2」「3」「4」「5」「6」「7」「8」「9」でも入力できるようにします。

Quartus Prime 17.0 Lite Editionをインストールして、SVI-328コアを改造していきます。

Svi328.sv

   "R0,Reset;",
//        "J,Button;",
//        "Jin,A;",
        "J1,B,0,1,2,3,4,5,6,7,8,9;",
    "V,v",`BUILD_DATE
};

(省略)

wire [3:0] svi_row;
wire [7:0] svi_col;
sviKeyboard KeyboardSVI
(
    .clk        (clk_sys),
    .reset  (reset),
    
    .keys       (PS2Keys),
    .joy        (joya),
    .svi_row (svi_row),
    .svi_col (svi_col)
    
);

keyboard_svi.vhd

    -- Ps2 Input From HPS_io
    keys        : in      std_logic_vector(10 downto 0);
    joy         : in      std_logic_vector(31 downto 0);

(省略)

architecture SYN of sviKeyboard is

  signal rst_n            : std_logic;
  signal ps2_chg     : std_logic;
  signal joy_old     : std_logic_vector(31 downto 0);

  type key_matrix is array (0 to 15) of std_logic_vector(7 downto 0);
  signal svi_matrix  : key_matrix;

(省略)

                    ps2_chg <= '0';
                    joy_old <= (others => '0');
        elsif rising_edge (clk) then
         -- note: all inputs are active HIGH
            
            ps2_chg <= keys(10);
            ps2_press := keys(9);
            ps2_scancode := keys(7 downto 0);
        
            -- Joystick buttons
            if joy(5) /= joy_old(5) then
                svi_matrix(0)(0) <= joy(5);
            end if;
            if joy(6) /= joy_old(6) then
                svi_matrix(0)(1) <= joy(6);
            end if;
            if joy(7) /= joy_old(7) then
                svi_matrix(0)(2) <= joy(7);
            end if;
            if joy(8) /= joy_old(8) then
                svi_matrix(0)(3) <= joy(8);
            end if;
            if joy(9) /= joy_old(9) then
                svi_matrix(0)(4) <= joy(9);
            end if;
            if joy(10) /= joy_old(10) then
                svi_matrix(0)(5) <= joy(10);
            end if;
            if joy(11) /= joy_old(11) then
                svi_matrix(0)(6) <= joy(11);
            end if;
            if joy(12) /= joy_old(12) then
                svi_matrix(0)(7) <= joy(12);
            end if;
            if joy(13) /= joy_old(13) then
                svi_matrix(1)(0) <= joy(13);
            end if;
            if joy(14) /= joy_old(14) then
                svi_matrix(1)(1) <= joy(14);
            end if;
            joy_old <= joy;
        
            -- svi key matrix
            if (ps2_chg /= keys(10)) then
                case ps2_scancode is
                    when SCANCODE_7         => svi_matrix(0)(7) <= ps2_press;
                    when SCANCODE_6         => svi_matrix(0)(6) <= ps2_press;
                    when SCANCODE_5            => svi_matrix(0)(5) <= ps2_press;
                    when SCANCODE_4             => svi_matrix(0)(4) <= ps2_press;
                    when SCANCODE_3         => svi_matrix(0)(3) <= ps2_press;
                    when SCANCODE_2         => svi_matrix(0)(2) <= ps2_press;
                    when SCANCODE_1         => svi_matrix(0)(1) <= ps2_press;
                    when SCANCODE_0         => svi_matrix(0)(0) <= ps2_press;