-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawSingleLayer.v
More file actions
83 lines (74 loc) · 2.11 KB
/
drawSingleLayer.v
File metadata and controls
83 lines (74 loc) · 2.11 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
module drawLayer #(
PIX_WIDTH=0,
PIX_HEIGHT=0,
SPRITE_SIZE=0,
SPRITEBUF_A_WIDTH=15,
SCREEN_WIDTH=0,
VRAM_A_WIDTH=16
)
(
input CLK,
input rst,
input ena,
input is_cur_state,
input [9:0]i_sprite_pix_x,
input [9:0]i_sprite_pix_y,
input i_layer_rst,
input [9:0]screen_pos_x, //left
input [9:0]screen_pos_y, //top
input theme_choose,
input [4:0]i_sprite_index,
output [SPRITEBUF_A_WIDTH-1:0]o_address_s,
output [VRAM_A_WIDTH-1:0]address_screen,
output [9:0]o_pix_x,
output [9:0]o_pix_y,
output o_layerend
);
reg [SPRITEBUF_A_WIDTH-1:0]address_s=0;
assign o_address_s=address_s;
reg [9:0]pix_x=0,pix_y=0;
assign o_pix_x=pix_x;
assign o_pix_y=pix_y;
// pipeline registers for for address calculation
reg [VRAM_A_WIDTH-1:0] address_fb1;
reg [VRAM_A_WIDTH-1:0] address_fb2;
assign address_screen=address_fb2;
assign o_layerend=(pix_y>=PIX_HEIGHT);
always @ (posedge CLK)
begin
// reset drawing
if (rst)
begin
pix_x <=0;
pix_y <=0;
address_fb1<=0;
address_s<=0;
end
else if(ena) begin
// draw background
if(i_layer_rst)begin
pix_x<=0;
pix_y<=0;
address_fb1<=0;
address_s<=0;
end
else begin
if (is_cur_state)
begin
if (pix_x < PIX_WIDTH-1)
pix_x <= pix_x + 1;
else if(pix_y < PIX_HEIGHT) begin
pix_x <= 0;
pix_y <= pix_y + 1;
end
// calculate address of sprite and frame buffer (with pipeline)
address_s <= (SPRITE_SIZE *2* (i_sprite_pix_y+SPRITE_SIZE*i_sprite_index)) +
i_sprite_pix_x+SPRITE_SIZE*theme_choose;
address_fb1 <= SCREEN_WIDTH * (pix_y + screen_pos_y) +
pix_x + screen_pos_x;
address_fb2 <= address_fb1;
end
end
end
end
endmodule