-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharHandler.v
More file actions
141 lines (126 loc) · 6.38 KB
/
charHandler.v
File metadata and controls
141 lines (126 loc) · 6.38 KB
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
/*----- Module Overview ------------------------------------------------*
* *
* ________________________ *
* *
* | | *
* clock -------> | | *
* reset -------> | | *
* pixelCnt --/10--> | | -------> readEn *
* lineCnt --/09--> | | -------> rowCnt *
* rgbDepth --/09--> | charHandler | -------> colCnt *
* charSize -------> | | --/09--> vgaRGB *
* upOffset -------> | | *
* downOffset -------> | | *
* leftOffset -------> | | *
* rightOffset -------> | | *
* bitDisp -------> | | *
* ________________________ *
* *
* *
*-----------------------------------------------------------------------*/
`include "globalVariables.v"
module charHandler ( clock, reset, pixelCnt, lineCnt, charRGB, bgRGB, flashClk, posVerStart, posVerEnd , posHorStart,posHorEnd, bitDisp, readEn, rowCnt, colCnt, vgaRGB );
input clock;
input reset;
input flashClk; /* Tracks the flash clock edge */
input [9:0] pixelCnt; /* Counter of pixels in a line of the active region */
input [8:0] lineCnt; /* Counter of lines in a frame of active region */
input [8:0] charRGB; /* Tracks the depth of each Color of the drawable object */
input [8:0] bgRGB; /* Tracks the depth of each Color of the background */
input bitDisp; /* Tracks wether a bit of the drawable object is displayed or not */
input [8:0] posVerStart;
input [8:0] posVerEnd;
input [9:0] posHorStart;
input [9:0] posHorEnd;
reg colEn; /* ...... */
reg rowEn; /* ...... */
reg reqRow; /* ...... */
reg reqCol; /* ...... */
output reg [8:0] vgaRGB; /* ...... */
output readEn; /* ...... */
output reg [3:0] rowCnt; /* Counter of lines in active Region */
output reg [2:0] colCnt; /* Counter of pixels in active Region */
always @ ( posedge clock or posedge reset ) begin
if ( reset )
begin
rowCnt <= 4'd0;
rowEn <= 1'b0;
end
else if ( lineCnt == posVerEnd || lineCnt == `VDR )
rowEn <= 1'b0;
else if ( posVerStart < posVerEnd ) /* Displayed region is inside Active region bound */
begin
if ( lineCnt == posVerEnd ) /* Reached the last pixel of Active Region, so reset the counter */
rowCnt <= 4'd0;
else if ( ( lineCnt >= posVerStart - 1 ) && ( lineCnt <= posVerEnd - 1 ) ) /* Did not reach the pixel line, so increase the counter */
begin
rowCnt <= lineCnt - ( posVerStart - 1 );
rowEn <= 1'b1;
end
end
else /* Displayed region needs beading */
begin
if ( lineCnt == `VDR )
rowCnt <= 4'd0;
else if ( ( lineCnt <= posVerEnd - 1 ) || ( lineCnt >= posVerStart - 1 ) )
begin
rowCnt <= ( lineCnt <= posVerEnd - 1 ) ? ( `VDR - posVerEnd + lineCnt ) : ( lineCnt - ( posVerStart - 1 ) ) ;
rowEn <= 1'b1;
end
end
end
always @ ( posedge clock or posedge reset ) begin
if ( reset )
begin
colCnt <= 3'd0;
colEn <= 1'b0;
end
else if ( pixelCnt == posHorEnd || pixelCnt == `HDR )
colEn <= 1'b0;
else if ( posHorStart < posHorEnd ) /* Displayed region is inside Active region bound */
begin
if ( pixelCnt == posHorEnd ) /* Reached the last pixel of Active Region, so reset the counter */
colCnt <= 3'd0;
else if ( ( pixelCnt >= posHorStart - 1 ) && ( pixelCnt <= posHorEnd - 1 ) ) /* Did not reach the pixel line, so increase the counter */
begin
colCnt <= pixelCnt - ( posHorStart - 1 );
colEn <= 1'b1;
end
end
else /* Displayed region needs beading */
begin
if ( pixelCnt == `HDR )
colCnt <= 3'd0;
else if ( ( pixelCnt <= posHorEnd - 1 ) || ( pixelCnt >= posHorStart - 1 ) )
begin
colCnt <= ( pixelCnt <= posHorEnd - 1 ) ? ( `HDR - posHorEnd + pixelCnt ) : ( pixelCnt - ( posHorStart - 1 ) ) ;
colEn <= 1'b1;
end
end
end
always @ ( posedge clock or posedge reset ) begin
if ( reset )
reqRow <= 1'b0;
else if ( lineCnt == posVerEnd )
reqRow <= 1'b0;
else if ( lineCnt == ( posVerStart - 2 ) )
reqRow <= 1'b1;
end
always @ ( posedge clock or posedge reset ) begin
if ( reset )
reqCol <= 1'b0;
else if ( posHorStart < posHorEnd )
reqCol <= ( pixelCnt == posHorStart - 2 ) ? 1'b1 : 1'b0 ;
else
reqCol <= ( pixelCnt == `HDR - 2 ) ? 1'b1 : 1'b0 ;
end
assign readEn = reqCol && reqRow;
always @ ( posedge clock or posedge reset ) begin
if ( reset )
vgaRGB <= 9'd0; /* Clear RGB Buffer */
else if ( rowEn && colEn && bitDisp && ~flashClk ) /* Inside Active Region and Have a pixel to display */
vgaRGB <= { charRGB[8:6], charRGB[5:3], charRGB[2:0] }; /* Pass each color's depth to output's buffer */
else
vgaRGB <= { bgRGB[8:6], bgRGB[5:3], bgRGB[2:0] }; /* Outside Display Region everything is black and nothing to display */
end
endmodule