-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixel_data.v
163 lines (153 loc) · 3.59 KB
/
Pixel_data.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 09:18:11 07/19/2015
// Design Name:
// Module Name: Pixel_data
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module Pixel_data(
input clk,
input reset,
input [9:0] x_pos,
input [9:0] y_pos,
input [7:0] data,
output reg [3:0] RED,
output reg [3:0] GREEN,
output reg [3:0] BLUE,
output reg [2:0]address
);
//
reg[2:0]x;
/////////////////////////////////////////////////////
///////// ball parameters and screen edges///////////
/////////////////////////////////////////////////////
wire[9:0]ball_x_left;
wire[9:0]ball_x_right;
wire[9:0]ball_y_top;
wire[9:0]ball_y_buttom;
reg signed[31:0] delta_x;
reg signed[31:0] delta_y;
wire[9:0]ball_x;
wire[9:0]ball_y;
reg [9:0]ball_rx;
reg [9:0]ball_ry;
//////////////////////////////////////////////////////////
parameter[3:0]ball_size=8;
localparam xinc1 = +1;
localparam xdec1 = -1;
localparam yinc1 = +1;
localparam ydec1 =-1;
wire refresh_clk;
////////////////////////////////////////////////////////////
assign ball_x_left = ball_rx;
assign ball_x_right = ball_x_left + 8- 1;
assign ball_y_top = ball_ry;
assign ball_y_buttom = ball_y_top + 8- 1;
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
always@(*)
begin
if(ball_ry<1)
delta_y=yinc1;
else if(ball_ry>479)
delta_y=ydec1;
else if(ball_rx<1)
delta_x=xinc1;
else if(ball_rx>638)
delta_x=xdec1;
end
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
always@(posedge clk or posedge reset)begin
if(reset)begin
ball_rx=300;
ball_ry=400;
//delta_x=-1;
//delta_y=+1;
end
else
begin
ball_rx=ball_x;
ball_ry=ball_y;
end
end
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
always@(posedge clk )
begin
if( y_pos >=ball_y_top && y_pos <=ball_y_buttom && x_pos>=ball_x_left && x_pos<=ball_x_right)
begin
address<=y_pos[2:0]-ball_y_top[2:0];
x<=x_pos[2:0]-ball_x_left[2:0];
if(data[x]==1'b1)
begin
RED=4'b1111;
GREEN=4'b0000;
BLUE=4'b1111;
end
else begin
RED=4'b0000;
GREEN=4'b0000;
BLUE=4'b0000;
end
end
else begin
RED=4'b0000;
GREEN=4'b0000;
BLUE=4'b0000;
end
end
/////////////////////////////////////////////////////////////
assign refresh_clk = (x_pos==0 && y_pos==460);
assign ball_x = refresh_clk?( ball_rx + delta_x):ball_rx;
assign ball_y = refresh_clk?(ball_ry + delta_y):ball_ry;
////////////////////////////////////////////////////////////
/*
always@(clk or x_pos or y_pos)
begin
if(y_pos>=0&&y_pos<=7)
begin
y=y_pos[2:0];
x=x_pos[2:0];
address<=y;
if(data[x]==1'b1)
begin
RED=4'b1111;
GREEN=4'b0000;
BLUE=4'b1111;
end
else begin
RED=4'b0000;
GREEN=4'b0000;
BLUE=4'b0000;
end
end
// else if(y_pos>300 && y_pos<400 && x_pos>300 && x_pos<400)
// begin
// RED=4'b1111;
// GREEN=4'b0000;
// BLUE=4'b1111;
// end
else begin
RED=4'b0000;
GREEN=4'b0000;
BLUE=4'b0000;
end
end
*/
endmodule