Skip to content

Commit 7cd7e55

Browse files
author
Even Zhou
committed
After Sunday
1 parent 0875350 commit 7cd7e55

File tree

9 files changed

+578
-197
lines changed

9 files changed

+578
-197
lines changed

game_handler.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module game_handler(
2626

2727
always @(negedge wrong, posedge reset, posedge start_reset) begin
2828
if (reset || start_reset)
29-
wrong_time <= 4'd4;
29+
wrong_time <= 4'd5;
3030
else if (load)
3131
wrong_time <= wrong_time - 1'd1;
3232
end
@@ -52,7 +52,7 @@ module game_handler(
5252

5353
.win(win),
5454
.wrong(wrong),
55-
.current_state(guessed_mask[25:0])
55+
.current_mask(guessed_mask[25:0])
5656
);
5757

5858
endmodule

game_process.v

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@ module game_process(
55
input [25:0] mask,
66

77
output reg win, wrong,
8-
output reg [25:0] current_state
8+
output reg [25:0] current_mask
99
);
1010

11-
reg [25:0] next_state;
11+
reg [25:0] next_mask;
1212

1313
always @(posedge clk) begin
1414
if (reset) begin
15-
current_state <= 26'b0;
16-
next_state <= 26'b0;
15+
current_mask <= 26'b0;
16+
next_mask <= 26'b0;
17+
win <= 1'b0;
1718
wrong <= 1'b0;
1819
end
1920
else begin
20-
next_state <= current_state;
21+
next_mask <= current_mask;
2122
if (load) begin
22-
next_state[load_x] = 1'b1;
23-
current_state <= next_state;
23+
next_mask[load_x] = 1'b1;
24+
current_mask <= next_mask;
2425
wrong <= (mask[load_x] == 1'b1);
25-
win <= ((current_state & ~mask) == ~mask);
26+
win <= ((current_mask & ~mask) == ~mask);
2627
end
2728
end
2829
end

game_status.v

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,39 @@ module game_status(
1111
LOSTGAME = 2'd3;
1212

1313
reg [1:0] next_state;
14+
reg [27:0] rate_divider;
15+
reg start_rate_divider;
1416

1517
always @(*) begin
18+
start_rate_divider = 1'b0;
1619
case (current_state)
1720
START: next_state = start_game ? INGAME : START;
1821
INGAME: begin
19-
if (win_game)
22+
if (win_game) begin
2023
next_state = WINGAME;
21-
else if (lost_game)
24+
start_rate_divider = 1'b1;
25+
end
26+
else if (lost_game) begin
2227
next_state = LOSTGAME;
28+
start_rate_divider = 1'b1;
29+
end
2330
else
2431
next_state = INGAME;
2532
end
26-
WINGAME: next_state = start_game ? START : WINGAME;
27-
LOSTGAME: next_state = start_game ? START : LOSTGAME;
33+
WINGAME: next_state = (rate_divider == 28'd0) ? START : WINGAME;
34+
LOSTGAME: next_state = (rate_divider == 28'd0) ? START : LOSTGAME;
2835
default: next_state = START;
2936
endcase
3037
end
3138

32-
always @(posedge clk)
33-
begin
39+
always @(posedge clk) begin
40+
if (start_rate_divider)
41+
rate_divider <= 28'd249999999;
42+
else if (rate_divider > 28'd0)
43+
rate_divider <= rate_divider - 28'd1;
44+
end
45+
46+
always @(posedge clk) begin
3447
if (reset)
3548
current_state <= START;
3649
else

hangman.qsf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,9 @@ set_global_assignment -name VERILOG_FILE keyboard_driver/keyboard_press_driver.v
707707
set_global_assignment -name VERILOG_FILE keyboard_driver/keyboard_inner_driver.v
708708
set_global_assignment -name QIP_FILE word_ram.qip
709709
set_global_assignment -name QIP_FILE letter_ram.qip
710+
set_global_assignment -name VERILOG_FILE word_ram.v
710711
set_global_assignment -name VERILOG_FILE vga_handler.v
712+
set_global_assignment -name VERILOG_FILE letter_ram.v
711713
set_global_assignment -name VERILOG_FILE keyboard_handler.v
712714
set_global_assignment -name VERILOG_FILE hex_decoder.v
713715
set_global_assignment -name VERILOG_FILE hangman.v

hangman.qws

0 Bytes
Binary file not shown.

hangman.v

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module hangman(
55
input [3:0] SW,
66

77
output [9:0] LEDR,
8-
output [6:0] HEX0, HEX1, HEX2, HEX3, HEX4,
8+
output [6:0] HEX0,
99
output VGA_CLK, VGA_HS, VGA_VS, VGA_BLANK_N, VGA_SYNC_N,
1010
output [9:0] VGA_R, VGA_G, VGA_B
1111
);
@@ -76,18 +76,8 @@ module hangman(
7676
);
7777

7878
hex_decoder h0(
79-
.hex_digit(pressedLetter[3:0]),
80-
.segments(HEX0[6:0])
81-
);
82-
83-
hex_decoder h1(
84-
.hex_digit({3'b000, pressedLetter[4]}),
85-
.segments(HEX1[6:0])
86-
);
87-
88-
hex_decoder h4(
8979
.hex_digit(wrong_time[3:0]),
90-
.segments(HEX4[6:0])
80+
.segments(HEX0[6:0])
9181
);
9282

9383
assign LEDR[1:0] = game_state[1:0];

letter_ram.mif

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
WIDTH = 64;
2-
DEPTH = 35;
2+
DEPTH = 36;
33

44
ADDRESS_RADIX = DEC;
55
DATA_RADIX = HEX;
66

77
CONTENT %may be mirrored%
88
BEGIN
99
0: 0C1E33333F333300; %A%
10-
1: 3F66663E66663F00;
11-
2: 3C66030303663C00;
12-
3: 1F36666666361F00;
13-
4: 7F46161E16467F00;
14-
5: 7F46161E16060F00;
15-
6: 3C66030373667C00;
16-
7: 3333333F33333300;
17-
8: 1E0C0C0C0C0C1E00;
18-
9: 7830303033331E00;
19-
10: 6766361E36666700;
20-
11: 0F06060646667F00;
21-
12: 63777F7F6B636300;
22-
13: 63676F7B73636300;
23-
14: 1C36636363361C00;
24-
15: 3F66663E06060F00;
25-
16: 1E3333333B1E3800;
26-
17: 3F66663E36666700;
27-
18: 1E33070E38331E00;
28-
19: 3F2D0C0C0C0C1E00;
29-
20: 3333333333333F00;
30-
21: 33333333331E0C00;
31-
22: 6363636B7F776300;
32-
23: 6363361C1C366300;
33-
24: 3333331E0C0C1E00;
10+
1: 3F66663E66663F00; %B%
11+
2: 3C66030303663C00; %C%
12+
3: 1F36666666361F00; %D%
13+
4: 7F46161E16467F00; %E%
14+
5: 7F46161E16060F00; %F%
15+
6: 3C66030373667C00; %G%
16+
7: 3333333F33333300; %H%
17+
8: 1E0C0C0C0C0C1E00; %I%
18+
9: 7830303033331E00; %J%
19+
10: 6766361E36666700; %K%
20+
11: 0F06060646667F00; %L%
21+
12: 63777F7F6B636300; %M%
22+
13: 63676F7B73636300; %N%
23+
14: 1C36636363361C00; %O%
24+
15: 3F66663E06060F00; %P%
25+
16: 1E3333333B1E3800; %Q%
26+
17: 3F66663E36666700; %R%
27+
18: 1E33070E38331E00; %S%
28+
19: 3F2D0C0C0C0C1E00; %T%
29+
20: 3333333333333F00; %U%
30+
21: 33333333331E0C00; %V%
31+
22: 6363636B7F776300; %W%
32+
23: 6363361C1C366300; %X%
33+
24: 3333331E0C0C1E00; %Y%
3434
25: 7F6331184C667F00; %Z%
3535
26: FF00000000000000; %_%
3636
27: 000000C060331E0C; %check%
3737
28: 00C3663C183C66C3; %cross%
3838
29: FF818181818181FF; %head%
39-
30: 1818181818180000; %no limbs%
40-
31: 18181F1818180000; %1 arm%
41-
32: 1818FF1818180000; %2 arm%
42-
33: 1818FF1818182040; %2 arm, 1 leg%
43-
34: 1818FF1818182442; %2 arm, 2 leg%
39+
30: 0000000000000000; %nothing%
40+
31: 1818181818180000; %no limbs%
41+
32: 18181F1818180000; %1 arm%
42+
33: 1818FF1818180000; %2 arm%
43+
34: 1818FF1818182040; %2 arm, 1 leg%
44+
35: 1818FF1818182442; %2 arm, 2 leg%
4445
END;

letter_ram.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module letter_ram (
9090
altsyncram_component.intended_device_family = "Cyclone V",
9191
altsyncram_component.lpm_hint = "ENABLE_RUNTIME_MOD=NO",
9292
altsyncram_component.lpm_type = "altsyncram",
93-
altsyncram_component.numwords_a = 35,
93+
altsyncram_component.numwords_a = 36,
9494
altsyncram_component.operation_mode = "SINGLE_PORT",
9595
altsyncram_component.outdata_aclr_a = "NONE",
9696
altsyncram_component.outdata_reg_a = "UNREGISTERED",
@@ -126,7 +126,7 @@ endmodule
126126
// Retrieval info: PRIVATE: JTAG_ID STRING "NONE"
127127
// Retrieval info: PRIVATE: MAXIMUM_DEPTH NUMERIC "0"
128128
// Retrieval info: PRIVATE: MIFfilename STRING "letter_ram.mif"
129-
// Retrieval info: PRIVATE: NUMWORDS_A NUMERIC "35"
129+
// Retrieval info: PRIVATE: NUMWORDS_A NUMERIC "36"
130130
// Retrieval info: PRIVATE: RAM_BLOCK_TYPE NUMERIC "0"
131131
// Retrieval info: PRIVATE: READ_DURING_WRITE_MODE_PORT_A NUMERIC "3"
132132
// Retrieval info: PRIVATE: RegAddr NUMERIC "1"
@@ -146,7 +146,7 @@ endmodule
146146
// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone V"
147147
// Retrieval info: CONSTANT: LPM_HINT STRING "ENABLE_RUNTIME_MOD=NO"
148148
// Retrieval info: CONSTANT: LPM_TYPE STRING "altsyncram"
149-
// Retrieval info: CONSTANT: NUMWORDS_A NUMERIC "35"
149+
// Retrieval info: CONSTANT: NUMWORDS_A NUMERIC "36"
150150
// Retrieval info: CONSTANT: OPERATION_MODE STRING "SINGLE_PORT"
151151
// Retrieval info: CONSTANT: OUTDATA_ACLR_A STRING "NONE"
152152
// Retrieval info: CONSTANT: OUTDATA_REG_A STRING "UNREGISTERED"

0 commit comments

Comments
 (0)