@@ -20,27 +20,11 @@ module tt_um_uwasic_dinogame #(parameter CONV = 2) (
2020 wire [1 :0 ] game_tick_20hz; // two consecutive pulses generated ([0] and then [1]), enabling pipelining
2121
2222 wire debounce_countdown_en; // pulse on rising edge of 5th vpos bit
23- wire button_up;
24- wire button_down;
2523
26- button_debounce button_up_debounce (
27- .clk(clk),
28- .rst_n(rst_n),
29- .countdown_en(debounce_countdown_en),
30- .button_in(ui_in[0 ]),
31- .button_out(button_up)
32- );
33-
34- button_debounce button_down_debounce (
35- .clk(clk),
36- .rst_n(rst_n),
37- .countdown_en(debounce_countdown_en),
38- .button_in(ui_in[1 ]),
39- .button_out(button_down)
40- );
4124
4225 // GAME STATE SIGNALS
4326 wire crash; // set to 1'b1 by rendering when collision occurs
27+ wire crash_out;
4428 wire [5 :0 ] player_position;
4529 wire game_start_pulse;
4630 wire game_over_pulse;
@@ -63,14 +47,58 @@ module tt_um_uwasic_dinogame #(parameter CONV = 2) (
6347 .lfsr_data(rng)
6448 );
6549
50+ // Gamepad Pmod support
51+ wire gamepad_pmod_latch = ui_in[4 ];
52+ wire gamepad_pmod_clk = ui_in[5 ];
53+ wire gamepad_pmod_data = ui_in[6 ];
54+ wire gamepad_is_present; // HIGH when gamepad is connected
55+ wire gamepad_up;
56+ wire gamepad_down;
57+ wire gamepad_start; // Can leverage start, select from SNES
58+ wire gamepad_b;
59+ wire gamepad_y;
60+ wire gamepad_select;
61+ wire gamepad_left;
62+ wire gamepad_right;
63+ wire gamepad_a;
64+ wire gamepad_x;
65+ wire gamepad_l;
66+ wire gamepad_r;
67+
68+ // Synchronizes pmod_data, pmod_clk, pmod_latch signals to system clock
69+ // domain.
70+ gamepad_pmod_single gamepad_pmod (
71+ // Inputs:
72+ .clk(clk),
73+ .rst_n(rst_n),
74+ .pmod_latch(gamepad_pmod_latch),
75+ .pmod_clk(gamepad_pmod_clk),
76+ .pmod_data(gamepad_pmod_data),
77+
78+ // Outputs:
79+ .is_present(gamepad_is_present),
80+ .up(gamepad_up),
81+ .down(gamepad_down),
82+ .start(gamepad_up),
83+ .b(gamepad_b),
84+ .y(gamepad_y),
85+ .select(gamepad_select),
86+ .left(gamepad_left),
87+ .right(gamepad_right),
88+ .a(gamepad_a),
89+ .x (gamepad_x),
90+ .l(gamepad_l),
91+ .r(gamepad_r)
92+ );
93+
6694 player_controller player_constroller_inst (
6795 .clk(clk),
6896 .rst_n(rst_n),
6997 .game_tick(game_tick_20hz),
7098 .button_start(button_up),
7199 .button_up(button_up),
72- .button_down(button_down ),
73- .crash(crash ),
100+ .button_down(gamepad_down ),
101+ .crash(crash_out ),
74102 .player_position(player_position),
75103 .game_frozen(game_frozen),
76104 .game_start_pulse(game_start_pulse),
@@ -79,7 +107,7 @@ module tt_um_uwasic_dinogame #(parameter CONV = 2) (
79107 .game_state(game_state)
80108 );
81109
82- obstacles #(.GEN_LINE(71 ), .CONV(CONV)) obstacles_inst (
110+ obstacles #(.GEN_LINE(71 ), .CONV(CONV)) obstacles_inst (
83111 .clk(clk),
84112 .rst_n(rst_n),
85113 .game_frozen(game_frozen),
@@ -243,7 +271,7 @@ module tt_um_uwasic_dinogame #(parameter CONV = 2) (
243271 ScoreModule score_module_inst (
244272 .game_start(game_start_pulse),
245273 .game_frozen(game_frozen),
246- .game_tick(game_tick_20hz[ 0 ] ),
274+ .game_tick(game_tick_60hz ),
247275 .clk(clk), // clock
248276 .rst_n(rst_n), // reset_n - low to reset
249277 .score(score)
@@ -256,6 +284,18 @@ module tt_um_uwasic_dinogame #(parameter CONV = 2) (
256284 .jump_pulse(jump_pulse),
257285 .sound(uio_out[7 ])
258286 );
287+
288+ ai_controller #(.CONV(CONV)) ai_controller_inst (
289+ .clk(clk),
290+ .rst_n(rst_n),
291+ .gamepad_is_present(gamepad_is_present),
292+ .gamepad_up(gamepad_up),
293+ .obstacle1_pos(obstacle1_pos),
294+ .obstacle2_pos(obstacle2_pos),
295+ .crash(crash),
296+ .button_up(button_up),
297+ .crash_out(crash_out)
298+ );
259299
260300 // TinyVGA PMOD
261301 assign uo_out = {hsync, B[0 ], G[0 ], R[0 ], vsync, B[1 ], G[1 ], R[1 ]};
0 commit comments