Y del test de NEPTUNO el código asociado al manejo de los JOYSTICKS DB9 con norma ATARI.
La versión actual para la placa madre del ZXTRES es una derivación de este esquema.
Y el código asociado a esta forma de manejar los joys tanto en NEPTUNO -> "Ya dije la palabra maldita, ¿O tal vez no?" como en ZXTRES:
https://github.com/neptuno-fpga/board_test
Señales en el módulo.
Código: Seleccionar todo
output wire JOY_CLK,
output wire JOY_LOAD,
input wire JOY_DATA,
output wire joyP7_o,
Código: Seleccionar todo
wire joy1up;
wire joy1down;
wire joy1left;
wire joy1right;
wire joy1fire1;
wire joy1fire2;
wire joy1start;
wire joy2up;
wire joy2down;
wire joy2left;
wire joy2right;
wire joy2fire1;
wire joy2fire2;
wire joy2start;
//assign joyP7_o = 1'b1;
wire [11:0] joy1_o;
wire [11:0] joy2_o;
wire clk_joy;
Código: Seleccionar todo
// Llamamos a la instancia de los Joysticks
joydecoder los_joysticks (
.clk(clk50mhz),
.joy_data(JOY_DATA),
.joy_clk(JOY_CLK),
.joy_load_n(JOY_LOAD),
.joy1up(joy1up),
.joy1down(joy1down),
.joy1left(joy1left),
.joy1right(joy1right),
.joy1fire1(joy1fire1),
.joy1fire2(joy1fire2),
.joy2up(joy2up),
.joy2down(joy2down),
.joy2left(joy2left),
.joy2right(joy2right),
.joy2fire1(joy2fire1),
.joy2fire2(joy2fire2),
.hsync(hsync)
);
// assign joyP7_o = 1'bz;
// PARA 6 BOTONES
// Llamamos a la maquina de estados para leer los 6 botones del mando de Megadrive
// Formato joy1_o [11:0] = MXYZ SACB RLDU
sega_joystick joy (
.joy1_up_i (joy1up),
.joy1_down_i (joy1down),
.joy1_left_i (joy1left),
.joy1_right_i (joy1right),
.joy1_p6_i (joy1fire1),
.joy1_p9_i (joy1fire2),
.joy2_up_i (joy2up),
.joy2_down_i (joy2down),
.joy2_left_i (joy2left),
.joy2_right_i (joy2right),
.joy2_p6_i (joy2fire1),
.joy2_p9_i (joy2fire2),
.vga_hsync_n_s(hsync),
.joyX_p7_o (joyP7_o),
.joy1_o (joy1_o),
.joy2_o (joy2_o)
);
Código: Seleccionar todo
module sega_joystick
(
input joy1_up_i,
input joy1_down_i,
input joy1_left_i,
input joy1_right_i,
input joy1_p6_i,
input joy1_p9_i,
input joy2_up_i,
input joy2_down_i,
input joy2_left_i,
input joy2_right_i,
input joy2_p6_i,
input joy2_p9_i,
output joyX_p7_o, // -- send to Select pin 7 of the Megadrive Joystick
input vga_hsync_n_s,
output wire [11:0] joy1_o, // -- MS ZYX CBA RLDU
output wire [11:0] joy2_o // -- MS ZYX CBA RLDU
);
//---- Joystick read with sega 6 button support ----------------------
reg [11:0]joy1_s = 12'hFFF;
reg [11:0]joy2_s = 12'hFFF;
reg joyP7_s;
reg [7:0]state_v = 8'd0;
reg j1_sixbutton_v = 1'b0;
reg j2_sixbutton_v = 1'b0;
always @(negedge vga_hsync_n_s)
begin
state_v <= state_v + 1;
case (state_v) //-- joy_s format MXYZ SACB RLDU
8'd0:
joyP7_s <= 1'b0;
8'd1:
joyP7_s <= 1'b1;
8'd2:
begin
joy1_s[3:0] <= {joy1_right_i, joy1_left_i, joy1_down_i, joy1_up_i}; //-- R, L, D, U
joy2_s[3:0] <= {joy2_right_i, joy2_left_i, joy2_down_i, joy2_up_i}; //-- R, L, D, U
joy1_s[5:4] <= {joy1_p9_i, joy1_p6_i}; //-- C, B
joy2_s[5:4] <= {joy2_p9_i, joy2_p6_i}; //-- C, B
joyP7_s <= 1'b0;
j1_sixbutton_v <= 1'b0; //-- Assume it's not a six-button controller
j2_sixbutton_v <= 1'b0; //-- Assume it's not a six-button controller
end
8'd3:
begin
if (joy1_right_i == 1'b0 && joy1_left_i == 1'b0) // it's a megadrive controller
joy1_s[7:6] <= { joy1_p9_i , joy1_p6_i }; //-- Start, A
else
joy1_s[7:4] <= { 1'b1, 1'b1, joy1_p9_i, joy1_p6_i }; //-- read A/B as master System
if (joy2_right_i == 1'b0 && joy2_left_i == 1'b0) // it's a megadrive controller
joy2_s[7:6] <= { joy2_p9_i , joy2_p6_i }; //-- Start, A
else
joy2_s[7:4] <= { 1'b1, 1'b1, joy2_p9_i, joy2_p6_i }; //-- read A/B as master System
joyP7_s <= 1'b1;
end
8'd4:
joyP7_s <= 1'b0;
8'd5:
begin
if (joy1_right_i == 1'b0 && joy1_left_i == 1'b0 && joy1_down_i == 1'b0 && joy1_up_i == 1'b0 )
j1_sixbutton_v <= 1'b1; // --it's a six button
if (joy2_right_i == 1'b0 && joy2_left_i == 1'b0 && joy2_down_i == 1'b0 && joy2_up_i == 1'b0 )
j2_sixbutton_v <= 1'b1; // --it's a six button
joyP7_s <= 1'b1;
end
8'd6:
begin
if (j1_sixbutton_v == 1'b1)
joy1_s[11:8] <= { joy1_right_i, joy1_left_i, joy1_down_i, joy1_up_i }; //-- Mode, X, Y e Z
if (j2_sixbutton_v == 1'b1)
joy2_s[11:8] <= { joy2_right_i, joy2_left_i, joy2_down_i, joy2_up_i }; //-- Mode, X, Y e Z
joyP7_s <= 1'b0;
end
default:
joyP7_s <= 1'b1;
endcase
end
assign joyX_p7_o = joyP7_s;
assign joy1_o = joy1_s;
assign joy2_o = joy2_s;
endmodule
Código: Seleccionar todo
module joydecoder (
input wire clk,
input wire joy_data,
output wire joy_clk,
output wire joy_load_n,
output wire joy1up,
output wire joy1down,
output wire joy1left,
output wire joy1right,
output wire joy1fire1,
output wire joy1fire2,
output wire joy2up,
output wire joy2down,
output wire joy2left,
output wire joy2right,
output wire joy2fire1,
output wire joy2fire2,
input wire hsync
);
reg hsync_s;
reg [7:0] clkdivider = 8'h00;
assign joy_clk = clkdivider[1];
always @(posedge clk) begin
clkdivider <= clkdivider + 8'd1;
end
reg [15:0] joyswitches = 16'hFFFF;
assign joy1up = joyswitches[7];
assign joy1down = joyswitches[6];
assign joy1left = joyswitches[5];
assign joy1right = joyswitches[4];
assign joy1fire1 = joyswitches[3];
assign joy1fire2 = joyswitches[2];
assign joy2up = joyswitches[15];
assign joy2down = joyswitches[14];
assign joy2left = joyswitches[13];
assign joy2right = joyswitches[12];
assign joy2fire1 = joyswitches[11];
assign joy2fire2 = joyswitches[10];
reg [3:0] state = 4'd0;
assign joy_load_n = ~(state == 4'd0);
always @(negedge joy_clk) begin
/*hsync_s <= hsync;
if (hsync_s ^ hsync) state <= 4'd0;
else*/ state <= state + 4'd1;
case (state)
4'd0: joyswitches[0] <= joy_data;
4'd1: joyswitches[1] <= joy_data;
4'd2: joyswitches[2] <= joy_data;
4'd3: joyswitches[3] <= joy_data;
4'd4: joyswitches[4] <= joy_data;
4'd5: joyswitches[5] <= joy_data;
4'd6: joyswitches[6] <= joy_data;
4'd7: joyswitches[7] <= joy_data;
4'd8: joyswitches[8] <= joy_data;
4'd9: joyswitches[9] <= joy_data;
4'd10: joyswitches[10] <= joy_data;
4'd11: joyswitches[11] <= joy_data;
4'd12: joyswitches[12] <= joy_data;
4'd13: joyswitches[13] <= joy_data;
4'd14: joyswitches[14] <= joy_data;
4'd15: joyswitches[15] <= joy_data;
endcase
end
endmodule