Skip to content
Snippets Groups Projects
Commit 641ea1de authored by Fang Lu's avatar Fang Lu
Browse files

gl_image - complete

parent 35155221
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,7 @@ logic [3:0] gl_cmd, gl_cmd_in;
logic [31:0] gl_args[8], gl_args_in[8];
logic gl_exec, gl_exec_next;
logic [7:0] gl_bg_dim, gl_bg_dim_in;
logic [15:0] gl_transparency, gl_transparency_in;
logic avl_sram_ready;
......@@ -98,6 +99,7 @@ gl_mgr gl_inst(
.GL_EXEC (gl_exec),
.GL_DONE (gl_done),
.BG_DIM (gl_bg_dim),
.TRANSPARENCY (gl_transparency),
.AVL_REQ (avl_sram_writereq),
.AVL_ADDR (avl_sram_addr),
.AVL_DATA (avl_sram_data),
......@@ -165,6 +167,7 @@ always_ff @(posedge CLOCK) begin
gl_args[i] <= 0;
end
gl_bg_dim <= 8'b10000000;
gl_transparency <= 16'h07e0;
end else begin
gl_cmd <= gl_cmd_in;
gl_exec <= gl_exec_next;
......@@ -172,6 +175,7 @@ always_ff @(posedge CLOCK) begin
gl_args[i] <= gl_args_in[i];
end
gl_bg_dim <= gl_bg_dim_in;
gl_transparency <= gl_transparency_in;
end
end
......@@ -182,6 +186,7 @@ always_comb begin
gl_args_in[i] = gl_args[i];
end
gl_bg_dim_in = gl_bg_dim;
gl_transparency_in = gl_transparency;
AVL_GL_READDATA = 32'hCCCCCCCC;
if(AVL_GL_CS & AVL_GL_READ) begin
......@@ -199,17 +204,28 @@ always_comb begin
if (AVL_GL_ADDR[3]) begin
if (AVL_GL_BYTE_EN == 4'hf)
gl_args_in[AVL_GL_ADDR[2:0]] = AVL_GL_WRITEDATA;
end else if (AVL_GL_ADDR == 4'd2) begin
if (AVL_GL_BYTE_EN[0]) begin
// Initiate new command
gl_cmd_in = AVL_GL_WRITEDATA[3:0];
gl_exec_next = 1'b1;
end
end else if (AVL_GL_ADDR == 4'd3) begin
if (AVL_GL_BYTE_EN[0]) begin
// Background dimming
gl_bg_dim_in = AVL_GL_WRITEDATA[7:0];
end
end else begin
case (AVL_GL_ADDR[2:0])
3'd2: begin
if (AVL_GL_BYTE_EN[0]) begin
// Initiate new command
gl_cmd_in = AVL_GL_WRITEDATA[3:0];
gl_exec_next = 1'b1;
end
end
3'd3: begin
if (AVL_GL_BYTE_EN[0]) begin
// Background dimming
gl_bg_dim_in = AVL_GL_WRITEDATA[7:0];
end
end
3'd4: begin
if (AVL_GL_BYTE_EN[0]) begin
// Background dimming
gl_transparency_in = AVL_GL_WRITEDATA[15:0];
end
end
endcase
end
end
......
......@@ -15,8 +15,9 @@ module gl_mgr (
input logic GL_EXEC,
output logic GL_DONE,
// Background dimming
// Background processing
input logic [7:0] BG_DIM,
input logic [15:0] TRANSPARENCY,
// Avalon connection
input logic AVL_REQ,
......@@ -341,9 +342,9 @@ module gl_mgr (
.CLOCK (CLOCK),
.RESET (RESET),
.IMG_BASE (GL_ARG1),
.W (GL_ARG1[19:10]),
.H (GL_ARG1[9:0]),
.TRANSPARENCY (GL_ARG2[15:0]),
.W (GL_ARG2[19:10]),
.H (GL_ARG2[9:0]),
.TRANSPARENCY (TRANSPARENCY),
.X (image_X),
.Y (image_Y),
.EN (image_en),
......
......@@ -107,9 +107,26 @@ module gl_painter_image (
end else begin
// Done. Save data and start drawing
color_in = fb_GL_DATA;
i_in = 0;
paint_req_in = 1'b1;
state_next = s_paint;
if (color_in == TRANSPARENCY) begin
// Skip the pixel
x_in = x + 1;
img_ptr_in = img_ptr + 1;
if (x_in == W) begin
// Move to next row
x_in = 0;
y_in = y_in + 1;
if (y_in == H) begin
// Completely done.
state_next = s_fin;
DONE = 1'b1;
end
end
end else begin
// Paint the pixel
i_in = 0;
paint_req_in = 1'b1;
state_next = s_paint;
end
end
end
......@@ -120,16 +137,18 @@ module gl_painter_image (
// Value written, move to next location
i_in = i + 1;
if (Y[i_in][9] || i_in == 6) begin
// Done. Move to next pixel
// Done. Fetch next pixel
paint_req_in = 1'b0;
x_in = x + 1;
img_ptr_in = img_ptr + 1;
state_next = s_fetch;
read_req_in = 1'b1;
if (x_in == W) begin
// Move to next row
x_in = 0;
y_in = y_in + 1;
if (y_in == H) begin
// Completely done.
paint_req_in = 1'b0;
state_next = s_fin;
DONE = 1'b1;
end
......
......@@ -50,3 +50,20 @@ void gl_polygon(uint16_t x_top, uint16_t y_top,
GL_IOWR(GL_COMMAND, 0, GL_CMD_POLYGON);
}
void gl_image(uint32_t base, uint16_t w, uint16_t h,
uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
uint16_t x3, uint16_t y3, uint16_t x4, uint16_t y4,
uint16_t x5, uint16_t y5, uint16_t x6, uint16_t y6) {
gl_wait();
GL_IOWR(GL_ARGS, 0, base);
GL_IOWR(GL_ARGS, 1, gl_make_point(w, h));
GL_IOWR(GL_ARGS, 2, gl_make_point(x1, y1));
GL_IOWR(GL_ARGS, 3, gl_make_point(x2, y2));
GL_IOWR(GL_ARGS, 4, gl_make_point(x3, y3));
GL_IOWR(GL_ARGS, 5, gl_make_point(x4, y4));
GL_IOWR(GL_ARGS, 6, gl_make_point(x5, y5));
GL_IOWR(GL_ARGS, 7, gl_make_point(x6, y6));
GL_IOWR(GL_COMMAND, 0, GL_CMD_IMAGE);
}
......@@ -18,4 +18,9 @@ void gl_polygon(uint16_t x_top, uint16_t y_top,
uint16_t color0, uint16_t color1,
uint8_t gradient_direction);
void gl_image(uint32_t base, uint16_t w, uint16_t h,
uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
uint16_t x3, uint16_t y3, uint16_t x4, uint16_t y4,
uint16_t x5, uint16_t y5, uint16_t x6, uint16_t y6);
#endif
......@@ -26,6 +26,6 @@
#define GL_SRAMWR(addr, data) IOWR_32DIRECT(GL_SRAM+((addr)<<2), 0, data)
#define GL_SRAM_BGBASE 0xa0000
#define GL_SRAM_RESBASE 0xc5800
#define GL_SRAM_RESBASE 0xc8000
#endif /* SRC_GL_REGS_H_ */
......@@ -82,55 +82,33 @@ int main() {
}
}
uint32_t dim=0;
while (1) {
/*
for (int i=0; i<2; i++) {
if (kbdr[i]) {
printf("Key pressed (%d): %02x\n", i, (int)kbdr[i]);
kbdr[i] = 0;
}
}
for (int i=2; i<4; i++) {
if (kbdr[i]) {
printf("Key released (%d): %02x\n", i, (int)kbdr[i]);
kbdr[i] = 0;
bptr = 0;
sdptr = p_meta->test_img;
osu_read_song(sdptr, buf);
uint32_t pixptr = GL_SRAM_RESBASE;
for (int j=0; j<p_meta->test_h; j++) {
for (int i=0; i<p_meta->test_w; i++) {
if (bptr >= 512) {
// Fetch next
osu_read_song(++sdptr, buf);
bptr = 0;
}
c1 = buf[bptr++];
c2 = buf[bptr++];
GL_SRAMWR(pixptr++, (c2<<8)|c1);
}
}
m_mod = 0;
if (x != *mouseX) {
m_mod = 1;
x = *mouseX;
}
if (y != *mouseY) {
m_mod = 1;
y = *mouseY;
}
if (sch != *mouseWheel) {
m_mod = 1;
sch = *mouseWheel;
}
if (btn != *mouseBtn) {
m_mod = 1;
btn = *mouseBtn;
}
if (m_mod) {
printf("(%d, %d) wheel=%d btn=%x\n", x, y, sch, btn);
}
*/
dim++;
if ((dim>>8) > 128) {
dim = 0;
}
uint32_t dim=0;
while (1) {
// gl_background_dim(dim>>8);
// gl_rect(100, 100, 105, 105, gl_make_color(0xffccccc), gl_make_color(0xffccccc), gl_make_color(0xff0000), 1);
// gl_circle(200,200,50,gl_make_color(0x66ccff),gl_make_color(0x66ccff), gl_make_color(0xffffff), 1);
// gl_polygon(300,100,400,300,200,170,400,230, gl_make_color(0x66ff66), gl_make_color(0x66ff66), 1);
gl_finalize_frame();
gl_finalize_wait();
gl_image(GL_SRAM_RESBASE, p_meta->test_w, p_meta->test_h, 100, 100,
250, 100, 250, 250, 100, 250, 0xffff, 0xffff, 0xffff, 0xffff);
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment