-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnake.v
125 lines (115 loc) · 2.65 KB
/
Snake.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 13:47:54 05/16/2014
// Design Name:
// Module Name: Snake
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Snake(
input [3:0] PUSH_BUTTONS,
input CLOCK,
input RESET,
output [7:0] COLOUR_OUT,
output HS,
output VS,
output [3:0] SEG_SELECT,
output [7:0] HEX_OUT,
output [7:0] LEDS // for debugging
);
// the wires for connecting the modules
wire [1:0] MasterState;
wire [1:0] NavState;
wire [7:0] RandomAddrH;
wire [6:0] RandomAddrV;
wire [9:0] AddrH;
wire [8:0] AddrV;
wire [7:0] Colour;
wire ReachedTarget;
wire [3:0] Score; // the score we get from the score counter
wire Gameclock;
wire Suicide;
// initialize the modules
MasterStateMachine MasterSTM (
.RESET(RESET),
.CLOCK(CLOCK),
.PUSH_BUTTONS(PUSH_BUTTONS),
.SCORE_IN(Score),
.STATE_OUT(MasterState),
.SUICIDE_IN(Suicide)
);
NavigationStateMachine NavSTM (
.RESET(RESET),
.CLOCK(Gameclock),
.PUSH_BUTTONS(PUSH_BUTTONS),
.STATE_OUT(NavState)
);
RandomWrapper RNDMWrp (
.CLK(CLOCK),
.RESET(RESET),
.NEXT(ReachedTarget),
.MASTER_STATE(MasterState),
.HORIZONTAL(RandomAddrH),
.VERTICAL(RandomAddrV)
);
// Change this to adjust the snake's speed
GenericCounter #(
.COUNTER_WIDTH(22),
.COUNTER_MAX(4166667))
GameSpeed(
.CLK(CLOCK),
.RESET(1'b0),
.ENABLE_IN(1),
.TRIGG_OUT(Gameclock)
);
SnakeControl SnakeCtl (
.CLK(CLOCK),
.GAMECLOCK(Gameclock),
.ADDRH(AddrH),
.ADDRV(AddrV),
.COLOUR(Colour),
.REACHED_TARGET(ReachedTarget),
.MASTER_STATE(MasterState),
.NAVIGATION_STATE(NavState),
.RAND_ADDRH(RandomAddrH),
.RAND_ADDRV(RandomAddrV),
.DEBUG_OUT(LEDS),
.SCORE(Score),
.SUICIDE(Suicide)
);
VGAWrapper VGAWrp (
.CLK(CLOCK),
.MASTER_STATE(MasterState),
.ADDRH(AddrH),
.ADDRV(AddrV),
.CIN(Colour),
.COUT(COLOUR_OUT),
.HS(HS),
.VS(VS)
);
ScoreCounter ScoreCnt(
.RESET(RESET),
.GAMECLOCK(Gameclock),
.REACHED_TARGET(ReachedTarget),
.CURRENT_SCORE(Score)
);
Seg7Decoder Seg7Dec(
.SEG_SELECT_IN(0),
.SEG_SELECT_OUT(SEG_SELECT),
.BIN_IN(Score),
.HEX_OUT(HEX_OUT),
.DOT_IN(0)
);
endmodule