-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor_Mapper.sv.bak
executable file
·69 lines (59 loc) · 2.84 KB
/
Color_Mapper.sv.bak
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
//-------------------------------------------------------------------------
// Color_Mapper.sv --
// Stephen Kempf --
// 3-1-06 --
// --
// Modified by David Kesler 07-16-2008 --
// Translated by Joe Meng 07-07-2013 --
// Modified by Po-Han Huang 03-03-2017 --
// --
// Spring 2017 Distribution --
// --
// For use with ECE 385 Lab 7 --
// University of Illinois ECE Department --
//-------------------------------------------------------------------------
module color_mapper ( input [9:0] BallX, BallY, // Ball coordinates
BallS, // Ball size (defined in ball.sv)
DrawX, DrawY, // Coordinates of current drawing pixel
output logic [7:0] VGA_R, VGA_G, VGA_B // VGA RGB output
);
logic ball_on;
logic [7:0] Red, Green, Blue;
/* The ball's (pixelated) circle is generated using the standard circle formula. Note that while
the single line is quite powerful descriptively, it causes the synthesis tool to use up three
of the 12 available multipliers on the chip! Since the multiplicants are required to be signed,
we have to first cast them from logic to int (signed by default) before they are multiplied. */
int DistX, DistY, Size;
assign DistX = DrawX - BallX;
assign DistY = DrawY - BallY;
assign Size = BallS;
assign VGA_R = Red;
assign VGA_G = Green;
assign VGA_B = Blue;
// Compute whether the pixel corresponds to ball or background
always_comb
begin : Ball_on_proc
if ( ( DistX*DistX + DistY*DistY) <= (Size * Size) )
ball_on = 1'b1;
else
ball_on = 1'b0;
end
// Assign color based on ball_on signal
always_comb
begin : RGB_Display
if ((ball_on == 1'b1))
begin
// White ball
Red = 8'hff;
Green = 8'hff;
Blue = 8'hff;
end
else
begin
// Background with nice color gradient
Red = 8'h3f;
Green = 8'h00;
Blue = 8'h7f - {1'b0, DrawX[9:3]};
end
end
endmodule