mirror of
https://github.com/Gehstock/Mist_FPGA.git
synced 2026-01-27 20:27:24 +00:00
Update MiST components
This commit is contained in:
@@ -8,10 +8,10 @@ module arcade_inputs(
|
||||
input key_strobe,
|
||||
input key_pressed,
|
||||
input [7:0] key_code,
|
||||
input [15:0] joystick_0,
|
||||
input [15:0] joystick_1,
|
||||
input [15:0] joystick_2,
|
||||
input [15:0] joystick_3,
|
||||
input [19:0] joystick_0,
|
||||
input [19:0] joystick_1,
|
||||
input [19:0] joystick_2,
|
||||
input [19:0] joystick_3,
|
||||
|
||||
// required rotating of controls
|
||||
input rotate,
|
||||
@@ -24,36 +24,43 @@ module arcade_inputs(
|
||||
|
||||
// tilt, coin4-1, start4-1
|
||||
output [8:0] controls,
|
||||
// fire12-1, up, down, left, right
|
||||
output [15:0] player1,
|
||||
output [15:0] player2,
|
||||
output [15:0] player3,
|
||||
output [15:0] player4
|
||||
// up2, down2, left2, right2, fire12-1, up, down, left, right
|
||||
output [19:0] player1,
|
||||
output [19:0] player2,
|
||||
output [19:0] player3,
|
||||
output [19:0] player4
|
||||
);
|
||||
|
||||
assign controls = { btn_tilt,
|
||||
btn_coin | btn_coin4_mame, btn_coin | btn_coin3_mame, btn_coin | btn_coin2_mame, btn_coin | btn_coin1_mame,
|
||||
btn_four_players | btn_start4_mame, btn_three_players | btn_start3_mame, btn_two_players | btn_start2_mame, btn_one_player | btn_start1_mame };
|
||||
btn_four_players | btn_start4_mame, btn_three_players | btn_start3_mame, btn_two_players | btn_start2_mame, btn_one_player | btn_start1_mame };
|
||||
|
||||
wire [15:0] joy0 = joyswap ? joystick_1 : joystick_0;
|
||||
wire [15:0] joy1 = joyswap ? joystick_0 : joystick_1;
|
||||
wire [15:0] joy2 = joystick_2;
|
||||
wire [15:0] joy3 = joystick_3;
|
||||
wire [19:0] joy0 = joyswap ? joystick_1 : joystick_0;
|
||||
wire [19:0] joy1 = joyswap ? joystick_0 : joystick_1;
|
||||
wire [19:0] joy2 = joystick_2;
|
||||
wire [19:0] joy3 = joystick_3;
|
||||
|
||||
wire [15:0] p1;
|
||||
wire [15:0] p2;
|
||||
wire [15:0] p3;
|
||||
wire [15:0] p4;
|
||||
wire [19:0] p1;
|
||||
wire [19:0] p2;
|
||||
wire [19:0] p3;
|
||||
wire [19:0] p4;
|
||||
|
||||
assign p1[15:4] = joy0[15:4] | { 4'h0, btn_fireH, btn_fireG, btn_fireF, btn_fireE, btn_fireD, btn_fireC, btn_fireB, btn_fireA };
|
||||
assign p2[15:4] = joy1[15:4] | { 4'h0, btn_fire2H, btn_fire2G, btn_fire2F, btn_fire2E, btn_fire2D, btn_fire2C, btn_fire2B, btn_fire2A };
|
||||
assign p3[15:4] = joy2[15:4];
|
||||
assign p4[15:4] = joy3[15:4];
|
||||
|
||||
control_rotator r1(joy0[3:0], {btn_up, btn_down, btn_left, btn_right }, rotate, orientation, p1[3:0]);
|
||||
control_rotator r2(joy1[3:0], {btn_up2, btn_down2, btn_left2, btn_right2}, rotate, orientation, p2[3:0]);
|
||||
control_rotator r3(joy2[3:0], 4'd0, rotate, orientation, p3[3:0]);
|
||||
control_rotator r4(joy3[3:0], 4'd0, rotate, orientation, p4[3:0]);
|
||||
// Left or only stick
|
||||
control_rotator l1(joy0[3:0], {btn_up, btn_down, btn_left, btn_right }, rotate, orientation, p1[3:0]);
|
||||
control_rotator l2(joy1[3:0], {btn_up2, btn_down2, btn_left2, btn_right2}, rotate, orientation, p2[3:0]);
|
||||
control_rotator l3(joy2[3:0], 4'd0, rotate, orientation, p3[3:0]);
|
||||
control_rotator l4(joy3[3:0], 4'd0, rotate, orientation, p4[3:0]);
|
||||
|
||||
// Right stick
|
||||
control_rotator r1(joy0[19:16], 4'd0, rotate, orientation, p1[19:16]);
|
||||
control_rotator r2(joy1[19:16], 4'd0, rotate, orientation, p2[19:16]);
|
||||
control_rotator r3(joy2[19:16], 4'd0, rotate, orientation, p3[19:16]);
|
||||
control_rotator r4(joy3[19:16], 4'd0, rotate, orientation, p4[19:16]);
|
||||
|
||||
assign player1 = oneplayer ? p1 | p2 : p1;
|
||||
assign player2 = oneplayer ? p1 | p2 : p2;
|
||||
|
||||
@@ -17,21 +17,24 @@ generic(
|
||||
PS2DIV : integer := 100;
|
||||
ROM_DIRECT_UPLOAD : boolean := false;
|
||||
SD_IMAGES: integer := 2;
|
||||
PS2BIDIR : boolean := false
|
||||
PS2BIDIR : boolean := false;
|
||||
FEATURES: std_logic_vector(31 downto 0) := (others=>'0')
|
||||
);
|
||||
port (
|
||||
clk_sys : in std_logic;
|
||||
clk_sd : in std_logic := '0';
|
||||
SPI_CLK, SPI_SS_IO, SPI_MOSI :in std_logic;
|
||||
SPI_MISO : out std_logic;
|
||||
conf_str : in std_logic_vector(8*STRLEN-1 downto 0);
|
||||
conf_str : in std_logic_vector(8*STRLEN-1 downto 0) := (others => '0');
|
||||
conf_addr : out std_logic_vector(9 downto 0);
|
||||
conf_chr : in std_logic_vector(7 downto 0) := (others => '0');
|
||||
joystick_0 : out std_logic_vector(31 downto 0);
|
||||
joystick_1 : out std_logic_vector(31 downto 0);
|
||||
joystick_2 : out std_logic_vector(31 downto 0);
|
||||
joystick_3 : out std_logic_vector(31 downto 0);
|
||||
joystick_4 : out std_logic_vector(31 downto 0);
|
||||
joystick_analog_0 : out std_logic_vector(15 downto 0);
|
||||
joystick_analog_1 : out std_logic_vector(15 downto 0);
|
||||
joystick_analog_0 : out std_logic_vector(31 downto 0);
|
||||
joystick_analog_1 : out std_logic_vector(31 downto 0);
|
||||
status : out std_logic_vector(63 downto 0);
|
||||
switches : out std_logic_vector(1 downto 0);
|
||||
buttons : out std_logic_vector(1 downto 0);
|
||||
@@ -117,4 +120,4 @@ port (
|
||||
);
|
||||
end component mist_video;
|
||||
|
||||
end package;
|
||||
end package;
|
||||
|
||||
@@ -36,7 +36,7 @@ module sd_card (
|
||||
output sd_sdhc,
|
||||
|
||||
input img_mounted,
|
||||
input [31:0] img_size,
|
||||
input [63:0] img_size,
|
||||
|
||||
output reg sd_busy = 0,
|
||||
// data coming in from io controller
|
||||
@@ -49,6 +49,9 @@ module sd_card (
|
||||
input [8:0] sd_buff_addr,
|
||||
|
||||
// configuration input
|
||||
// in case of a VHD file, this will determine the SD Card type returned to the SPI master
|
||||
// in case of a pass-through, the firmware will display a warning if SDHC is not allowed,
|
||||
// but the card inserted is SDHC
|
||||
input allow_sdhc,
|
||||
|
||||
input sd_cs,
|
||||
@@ -57,9 +60,9 @@ module sd_card (
|
||||
output reg sd_sdo
|
||||
);
|
||||
|
||||
wire [31:0] OCR = { 1'b1, sd_sdhc, 6'h0, 9'h1f, 15'h0 }; // bit31 = finished powerup
|
||||
// bit30 = 1 -> high capaciry card (sdhc)
|
||||
// 15-23 supported voltage range
|
||||
wire [31:0] OCR = { 1'b1, sdhc, 6'h0, 9'h1f, 15'h0 }; // bit31 = finished powerup
|
||||
// bit30 = 1 -> high capaciry card (sdhc)
|
||||
// 15-23 supported voltage range
|
||||
wire [7:0] READ_DATA_TOKEN = 8'hfe;
|
||||
|
||||
// number of bytes to wait after a command before sending the reply
|
||||
@@ -131,12 +134,16 @@ assign sd_conf = sd_configuring;
|
||||
|
||||
reg sd_configuring = 1;
|
||||
reg [4:0] conf_buff_ptr;
|
||||
reg [7:0] conf_byte;
|
||||
reg [7:0] conf_byte_orig;
|
||||
reg[255:0] csdcid;
|
||||
|
||||
reg vhd = 0;
|
||||
reg [40:0] vhd_size;
|
||||
|
||||
// conf[0]==1 -> io controller is using an sdhc card
|
||||
wire sd_has_sdhc = conf[0];
|
||||
assign sd_sdhc = allow_sdhc && sd_has_sdhc;
|
||||
assign sd_sdhc = (allow_sdhc & sd_has_sdhc) | vhd; // report to user_io
|
||||
wire sdhc = allow_sdhc & (sd_has_sdhc | vhd); // used internally
|
||||
|
||||
always @(posedge clk_sys) begin
|
||||
reg old_mounted;
|
||||
@@ -148,22 +155,72 @@ always @(posedge clk_sys) begin
|
||||
end
|
||||
else csdcid[(31-sd_buff_addr) << 3 +:8] <= sd_buff_dout;
|
||||
end
|
||||
conf_byte <= csdcid[(31-conf_buff_ptr) << 3 +:8];
|
||||
conf_byte_orig <= csdcid[(31-conf_buff_ptr) << 3 +:8];
|
||||
|
||||
old_mounted <= img_mounted;
|
||||
if (~old_mounted & img_mounted) begin
|
||||
// update card size in case of a virtual SD image
|
||||
if (sd_sdhc)
|
||||
// CSD V2.0 size = (c_size + 1) * 512K
|
||||
csdcid[69:48] <= {9'd0, img_size[31:19] } - 1'd1;
|
||||
else begin
|
||||
// CSD V1.0 no. of blocks = c_size ** (c_size_mult + 2)
|
||||
csdcid[49:47] <= 3'd7; //c_size_mult
|
||||
csdcid[73:62] <= img_size[29:18]; //c_size
|
||||
end
|
||||
vhd <= |img_size;
|
||||
vhd_size <= img_size[40:0];
|
||||
end
|
||||
end
|
||||
|
||||
// CSD V1.0 no. of blocks = c_size ** (c_size_mult + 2)
|
||||
wire [127:0] csd_sd = {
|
||||
8'h00, // CSD_STRUCTURE + reserved
|
||||
8'h2d, // TAAC
|
||||
8'd0, // NSAC
|
||||
8'h32, // TRAN_SPEED
|
||||
12'h5b5, // CCC
|
||||
4'h9, // READ_BL_LEN
|
||||
1'b1, 1'b0, 1'b0, 1'b0, // READ_BL_PARTIAL, WRITE_BLK_MISALIGN, READ_BLK_MISALIGN, DSR_IMP
|
||||
2'd0, vhd_size[29:18], // reserved + C_SIZE
|
||||
3'b111, // VDD_R_CURR_MIN
|
||||
3'b110, // VDD_R_CURR_MAX
|
||||
3'b111, // VDD_W_CURR_MIN
|
||||
3'b110, // VDD_W_CURR_MAX
|
||||
3'd7, // C_SIZE_MULT
|
||||
1'b1, // ERASE_BLK_EN
|
||||
7'd127, // SECTOR_SIZE
|
||||
7'd0, // WP_GRP_SIZE
|
||||
1'b0, // WP_GRP_ENABLE,
|
||||
2'b00, // reserved,
|
||||
3'd5, // R2W_FACTOR,
|
||||
4'h9, // WRITE_BL_LEN,
|
||||
1'b0, // WRITE_BL_PARTIAL,
|
||||
5'd0, // reserved,
|
||||
8'd0,
|
||||
7'h67, // CRC (wrong, but usually not checked)
|
||||
1'b1 };
|
||||
|
||||
// CSD V2.0 size = (c_size + 1) * 512K
|
||||
wire [127:0] csd_sdhc = {
|
||||
8'h40, // CSD_STRUCTURE + reserved
|
||||
8'h0e, // TAAC
|
||||
8'd0, // NSAC
|
||||
8'h32, // TRAN_SPEED
|
||||
12'h5b5, // CCC
|
||||
4'h9, // READ_BL_LEN
|
||||
1'b0, 1'b0, 1'b0, 1'b0, // READ_BL_PARTIAL, WRITE_BLK_MISALIGN, READ_BLK_MISALIGN, DSR_IMP
|
||||
6'd0, // reserved
|
||||
vhd_size[40:19] - 1'd1, // C_SIZE
|
||||
1'b0, // reserved
|
||||
1'b1, // ERASE_BLK_EN
|
||||
7'd127, // SECTOR_SIZE
|
||||
7'd0, // WP_GRP_SIZE
|
||||
1'b0, // WP_GRP_ENABLE,
|
||||
2'b00, // reserved,
|
||||
3'd2, // R2W_FACTOR,
|
||||
4'h9, // WRITE_BL_LEN,
|
||||
1'b0, // WRITE_BL_PARTIAL,
|
||||
5'd0, // reserved,
|
||||
8'd0,
|
||||
7'h78, // CRC (wrong, but usually not checked)
|
||||
1'b1 };
|
||||
|
||||
wire [7:0] conf_byte = (!conf_buff_ptr[4] | !vhd) ? conf_byte_orig : // CID or CSD if not VHD
|
||||
sdhc ? csd_sdhc[(15-conf_buff_ptr[3:0]) << 3 +:8] :
|
||||
csd_sd[(15-conf_buff_ptr[3:0]) << 3 +:8];
|
||||
|
||||
always@(posedge clk_sys) begin
|
||||
|
||||
reg old_sd_sck;
|
||||
@@ -223,7 +280,7 @@ always@(posedge clk_sys) begin
|
||||
RD_STATE_WAIT_BUSY:
|
||||
if (~sd_busy) begin
|
||||
sd_buff_sel <= 0;
|
||||
sd_lba <= sd_sdhc?args[39:8]:{9'd0, args[39:17]};
|
||||
sd_lba <= sdhc?args[39:8]:{9'd0, args[39:17]};
|
||||
sd_rd <= 1; // trigger request to io controller
|
||||
sd_busy <= 1;
|
||||
read_state <= RD_STATE_WAIT_IO;
|
||||
@@ -501,7 +558,7 @@ always@(posedge clk_sys) begin
|
||||
if (~sd_busy) begin
|
||||
if (wr_first) begin
|
||||
sd_buff_sel <= 0;
|
||||
sd_lba <= sd_sdhc?args[39:8]:{9'd0, args[39:17]};
|
||||
sd_lba <= sdhc?args[39:8]:{9'd0, args[39:17]};
|
||||
wr_first <= 0;
|
||||
end else begin
|
||||
sd_buff_sel <= !sd_buff_sel;
|
||||
|
||||
@@ -40,8 +40,8 @@ module user_io (
|
||||
output reg [31:0] joystick_2,
|
||||
output reg [31:0] joystick_3,
|
||||
output reg [31:0] joystick_4,
|
||||
output reg [15:0] joystick_analog_0,
|
||||
output reg [15:0] joystick_analog_1,
|
||||
output reg [31:0] joystick_analog_0,
|
||||
output reg [31:0] joystick_analog_1,
|
||||
output [1:0] buttons,
|
||||
output [1:0] switches,
|
||||
output scandoubler_disable,
|
||||
@@ -104,6 +104,7 @@ parameter PS2DIV=100; // master clock divider for psk2_kbd/mouse clk
|
||||
parameter ROM_DIRECT_UPLOAD=0; // direct upload used for file uploads from the ARM
|
||||
parameter SD_IMAGES=2; // number of block-access images (max. 4 supported in current firmware)
|
||||
parameter PS2BIDIR=0; // bi-directional PS2 interface
|
||||
parameter FEATURES=0; // requested features from the firmware
|
||||
|
||||
localparam W = $clog2(SD_IMAGES);
|
||||
|
||||
@@ -139,8 +140,8 @@ wire [7:0] sd_cmd = { 4'h6, sd_conf, sd_sdhc, sd_wr[drive_sel], sd_rd[drive_sel]
|
||||
wire spi_sck = SPI_CLK;
|
||||
|
||||
// ---------------- PS2 ---------------------
|
||||
// 8 byte fifos to store ps2 bytes
|
||||
localparam PS2_FIFO_BITS = 3;
|
||||
// 16 byte fifos to store ps2 bytes
|
||||
localparam PS2_FIFO_BITS = 4;
|
||||
|
||||
reg ps2_clk;
|
||||
always @(posedge clk_sys) begin
|
||||
@@ -495,6 +496,11 @@ always@(posedge spi_sck or posedge SPI_SS_IO) begin : spi_transmitter
|
||||
if(byte_cnt[0]) spi_byte_out <= serial_out_status;
|
||||
else spi_byte_out <= serial_out_byte;
|
||||
|
||||
// core features
|
||||
8'h80:
|
||||
if (byte_cnt == 0) spi_byte_out <= 8'h80;
|
||||
else spi_byte_out <= FEATURES[(4-byte_cnt)<<3 +:8];
|
||||
|
||||
endcase
|
||||
end
|
||||
end
|
||||
@@ -624,6 +630,18 @@ always @(posedge clk_sys) begin : cmd_block
|
||||
joystick_analog_0[7:0] <= spi_byte_in;
|
||||
else if(stick_idx == 1)
|
||||
joystick_analog_1[7:0] <= spi_byte_in;
|
||||
end else if(abyte_cnt == 4) begin
|
||||
// fourth byte is 2nd x axis
|
||||
if(stick_idx == 0)
|
||||
joystick_analog_0[31:24] <= spi_byte_in;
|
||||
else if(stick_idx == 1)
|
||||
joystick_analog_1[31:24] <= spi_byte_in;
|
||||
end else if(abyte_cnt == 5) begin
|
||||
// fifth byte is 2nd y axis
|
||||
if(stick_idx == 0)
|
||||
joystick_analog_0[23:16] <= spi_byte_in;
|
||||
else if(stick_idx == 1)
|
||||
joystick_analog_1[23:16] <= spi_byte_in;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user