forked from zhanghai/archexp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminal.v
More file actions
49 lines (41 loc) · 1.21 KB
/
Terminal.v
File metadata and controls
49 lines (41 loc) · 1.21 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
`timescale 1ns / 1ps
module Terminal (
input clock,
input isVgaActive,
input [9:0] vgaX,
input [8:0] vgaY,
output [7:0] vgaColor,
input [11:0] textAddress,
output [7:0] textReadData,
input shouldWriteText,
input [7:0] textWriteData
);
localparam COLOR_BLACK = 8'b000_000_00;
localparam COLOR_RED = 8'b111_000_00;
localparam COLOR_WHITE = 8'b111_111_11;
// 640x480, 80x30
// Make synthesizer happy so that it won't mess up.
//reg [15:0] text [0:2399];
reg [15:0] text [0:4095];
wire [11:0] textIndex = vgaX / 8 + (vgaY / 16) * 80;
wire [15:0] textData = text[textIndex];
wire [7:0] fontIndex = textData[7:0];
wire [2:0] fontX = vgaX % 8;
wire [3:0] fontY = vgaY % 16;
wire [11:0] fontAddress = fontIndex * 16 + fontY;
wire [7:0] fontData;
Font font (
.a(fontAddress[11:0]),
.spo(fontData[7:0])
);
wire hasPoint = fontData[8 - fontX];
wire [7:0] textColor = textData[15:8];
assign vgaColor = isVgaActive ? (hasPoint ? textColor : COLOR_BLACK) : 8'b0;
always @(posedge clock) begin
if (shouldWriteText) begin
// HACK FOR LOVE!
text[textAddress] <= {textWriteData == "" ? COLOR_RED : COLOR_WHITE, textWriteData};
end
end
assign textReadData = text[textAddress][7:0];
endmodule