Skip to content

Commit fafa06b

Browse files
committed
add de1-soc demo instructions
1 parent 5dd4233 commit fafa06b

30 files changed

+3172
-0
lines changed

de1_fpga_dino_demo/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Steps to prepare a demo on a Altera/Terasic DE1-SOC
2+
3+
Install Quartus (Latest, Lite is fine)
4+
5+
You can try to install the .sof file right away, if it works.
6+
7+
If you need to rebuild the project:
8+
- Use dino_quartus_demo_top.v as your top file.
9+
- Add all the files in /src into the project
10+
- Compile
11+
12+
Tools -> Programmer
13+
- Connect to the board (make sure it is powered) with a USB / USB-B connection, into the USB-Blaster-II connection beside the power connection
14+
- Make sure you have the drivers and that the hardware says DE-SoC
15+
- If it doesn't, Hardware Setup -> Currently Selected Hardware -> DE-SoC
16+
- Press Auto-detect
17+
- ![alt text](image.png)
18+
- Press start to program the board with the bitstream
19+
20+
Usage:
21+
- The rightmost switch (SW0) is currently configured as the AI/Manual toggle
22+
SW0: Up = manual, Down = AI
23+
Key3 (button) -> Up
24+
Key2 (button) -> Down
25+
Key0 (button) -> reset

de1_fpga_dino_demo/dino_quartus_demo.qsf

Lines changed: 701 additions & 0 deletions
Large diffs are not rendered by default.
6.38 MB
Binary file not shown.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// top wrapper for DE1-SOC
2+
3+
4+
module dino_quartus_demo_top(
5+
input wire CLOCK_50,
6+
input wire [3:0] KEY,
7+
input wire [17:0] SW,
8+
9+
output wire VGA_HS,
10+
output wire VGA_VS,
11+
output wire [7:6] VGA_R,
12+
output wire [7:6] VGA_G,
13+
output wire [7:6] VGA_B,
14+
output wire VGA_CLK
15+
);
16+
17+
wire clk_25mhz;
18+
wire [7:0] uio_oe;
19+
wire [6:0] uio_out;
20+
wire out_sound;
21+
22+
//---------------------------------------------
23+
// TinyTapeout module wrapper
24+
//---------------------------------------------
25+
26+
// assign uo_out = {hsync, B[0], G[0], R[0], vsync, B[1], G[1], R[1]};
27+
28+
29+
tt_um_uwasic_dinogame dino_inst(
30+
.ui_in({5'b00000, start, up, down}), // button mapping
31+
.uo_out({VGA_HS, VGA_B[6], VGA_G[6], VGA_R[6], VGA_VS, VGA_B[7], VGA_G[7], VGA_R[7]}), // VGA
32+
.uio_in(8'b0),
33+
.uio_out({out_sound, uio_out}),
34+
.uio_oe(uio_oe),
35+
.clk(clk_25mhz),
36+
.rst_n(~reset), // active low reset
37+
.ena(1'b1)
38+
);
39+
40+
//---------------------------------------------
41+
// assign your DE1 buttons to start/up/down
42+
//---------------------------------------------
43+
wire up = ~KEY[3];
44+
wire down = ~KEY[2];
45+
wire start = SW[0];
46+
wire reset = ~KEY[0];
47+
48+
//---------------------------------------------
49+
// clock divider – same as your TT code
50+
//---------------------------------------------
51+
clock_div clk_div_inst (
52+
.clk(CLOCK_50),
53+
.reset(1'b0),
54+
.clk_out(clk_25mhz)
55+
);
56+
57+
assign VGA_CLK = clk_25mhz;
58+
59+
60+
endmodule
61+
62+
module clock_div (clk,reset, clk_out);
63+
64+
input clk;
65+
input reset;
66+
output clk_out;
67+
68+
reg r_reg;
69+
wire [1:0] r_nxt;
70+
reg clk_track;
71+
72+
always @(posedge clk or posedge reset)
73+
74+
begin
75+
if (reset)
76+
begin
77+
r_reg <= 1'b0;
78+
clk_track <= 1'b0;
79+
end
80+
81+
else if (r_nxt == 2'b01)
82+
begin
83+
r_reg <= 0;
84+
clk_track <= ~clk_track;
85+
end
86+
87+
else
88+
r_reg <= r_nxt;
89+
end
90+
91+
assign r_nxt = r_reg+1;
92+
assign clk_out = clk_track;
93+
endmodule
94+
95+

de1_fpga_dino_demo/image.png

12 KB
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
`default_nettype none
2+
3+
module ai_controller
4+
#( parameter CONV = 0, parameter PLAYER_OFFSET = 6, parameter OBSTACLE_TRESHOLD = 40 )
5+
(
6+
input wire clk,
7+
input wire rst_n,
8+
input wire game_tick,
9+
input wire gamepad_is_present,
10+
input wire gamepad_start,
11+
input wire gamepad_up,
12+
input wire gamepad_down,
13+
input wire [9:CONV] obstacle1_pos,
14+
input wire [9:CONV] obstacle2_pos,
15+
input wire crash,
16+
input wire game_frozen,
17+
output reg button_start,
18+
output reg button_up,
19+
output reg button_down
20+
);
21+
22+
localparam RESTART_DELAY = 60; // Clock cycles to wait after crash to restart
23+
24+
// reg [9:CONV] obstacle_threshold; // When an obstacle reaches this xpos, set button_up signal
25+
reg [7:0] restart_counter;
26+
27+
always @(posedge clk) begin
28+
if (!rst_n) begin
29+
button_start <= 1'b0;
30+
button_up <= 1'b0;
31+
button_down <= 1'b0;
32+
restart_counter <= 8'b00000000;
33+
end else if (gamepad_is_present) begin
34+
button_start <= gamepad_start;
35+
button_up <= gamepad_up;
36+
button_down <= gamepad_down;
37+
end else if (game_tick) begin
38+
if (crash | game_frozen) begin
39+
restart_counter <= restart_counter + 1;
40+
if (restart_counter == RESTART_DELAY) begin
41+
button_start <= 1'b1;
42+
restart_counter <= 8'b00000000;
43+
end else begin
44+
button_start <= 1'b0;
45+
end
46+
button_up <= 1'b0;
47+
button_down <= 1'b0;
48+
end else if ((obstacle1_pos <= OBSTACLE_TRESHOLD && obstacle1_pos > PLAYER_OFFSET) || (obstacle2_pos <= OBSTACLE_TRESHOLD && obstacle2_pos > PLAYER_OFFSET)) begin
49+
button_up <= 1'b1;
50+
end else begin
51+
button_up <= 1'b0;
52+
end
53+
end
54+
end
55+
56+
57+
58+
endmodule
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
module audio_interface(
3+
input wire clk,
4+
input wire rst_n,
5+
input wire game_is_over,
6+
input wire jump_pulse,
7+
output reg sound
8+
);
9+
wire jump_sound;
10+
wire game_over_sound;
11+
12+
always @(posedge clk) begin
13+
if (!rst_n) begin
14+
sound <= 0;
15+
end else begin
16+
sound <= jump_sound | game_over_sound;
17+
end
18+
end
19+
20+
jump_sound_player i_jump(
21+
.clk(clk),
22+
.rst_n(rst_n),
23+
.sound_trigger(jump_pulse),
24+
.wave_out(jump_sound)
25+
);
26+
27+
game_over_sound_player i_over(
28+
.clk(clk),
29+
.rst_n(rst_n),
30+
.is_over(game_is_over),
31+
.wave_out(game_over_sound)
32+
);
33+
34+
endmodule
35+
36+

de1_fpga_dino_demo/src/bg_line.v

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module bg_line #(parameter CONV = 0, parameter GND_LINE = 0) (
2+
// Graphics
3+
input wire [9:CONV] i_vpos,
4+
output reg o_color_bg // Dedicated outputs
5+
);
6+
7+
8+
always @(*) begin
9+
o_color_bg = 1'b0;
10+
// optimize this heavily for ROM
11+
if (i_vpos == GND_LINE) begin
12+
o_color_bg = 1'b1;
13+
end
14+
end
15+
endmodule
16+
17+

de1_fpga_dino_demo/src/bg_object.v

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module bg_object
2+
#( parameter CONV = 0)
3+
(
4+
input wire clk,
5+
input wire rst_n,
6+
input wire game_tick, // 20 Hz
7+
input wire [7:0] rng,
8+
output reg [9:CONV] bg_object_pos
9+
);
10+
always @(posedge clk) begin
11+
if (!rst_n) begin
12+
bg_object_pos <= 0;
13+
end else begin
14+
if (game_tick) begin
15+
if (bg_object_pos != 0) bg_object_pos <= bg_object_pos - 1;
16+
if (bg_object_pos == 0) begin
17+
bg_object_pos <= {{(5-CONV){1'b1}}, rng[6:2]};
18+
end
19+
end
20+
end
21+
end
22+
endmodule
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
`default_nettype none
2+
3+
module bg_object_rom (
4+
input wire clk,
5+
input wire rst,
6+
input wire [5:0] i_rom_counter,
7+
output reg o_sprite_color
8+
);
9+
10+
reg [2:0] rom_x;
11+
reg [2:0] rom_y;
12+
13+
14+
always @(*) begin
15+
{rom_y, rom_x} = i_rom_counter;
16+
end
17+
18+
reg [7:0] icon_cloud [7:0];
19+
20+
always @(posedge clk) begin
21+
if (rst) begin
22+
icon_cloud[0] <= 8'b00000000;
23+
icon_cloud[1] <= 8'b00000000;
24+
icon_cloud[2] <= 8'b00001100;
25+
icon_cloud[3] <= 8'b00011110;
26+
icon_cloud[4] <= 8'b01101011;
27+
icon_cloud[5] <= 8'b11000001;
28+
icon_cloud[6] <= 8'b11111111;
29+
icon_cloud[7] <= 8'b01100110;
30+
end
31+
end
32+
33+
always @(*) begin
34+
o_sprite_color = icon_cloud[rom_y][rom_x];
35+
end
36+
37+
endmodule
38+

0 commit comments

Comments
 (0)