diff --git a/info.yaml b/info.yaml index cb4e2f9..18c0048 100644 --- a/info.yaml +++ b/info.yaml @@ -18,6 +18,7 @@ project: # Don't forget to also update `PROJECT_SOURCES` in test/Makefile. source_files: - "tt_um_nvious_graphics.v" + - "gradient_rom.v" - "hvsync_generator.v" # The pinout of your project. Leave unused pins blank. DO NOT delete or add any pins. diff --git a/src/gradient_rom.v b/src/gradient_rom.v new file mode 100644 index 0000000..b49a9e4 --- /dev/null +++ b/src/gradient_rom.v @@ -0,0 +1,147 @@ +`ifndef GRADIENT_ROM_H +`define GRADIENT_ROM_H + +// Gradient lookup table + +module gradient_rom( + input wire [6:0] y, + input wire [1:0] x, + output wire pixel +); + reg [3:0] g[127:0]; + assign pixel = g[y][x]; + + initial begin + g[ 0] = 4'b0000; + g[ 1] = 4'b0000; + g[ 2] = 4'b0000; + g[ 3] = 4'b0000; + g[ 4] = 4'b0100; + g[ 5] = 4'b0000; + g[ 6] = 4'b0000; + g[ 7] = 4'b0000; + g[ 8] = 4'b0100; + g[ 9] = 4'b0000; + g[ 10] = 4'b0001; + g[ 11] = 4'b0000; + g[ 12] = 4'b0100; + g[ 13] = 4'b0000; + g[ 14] = 4'b0001; + g[ 15] = 4'b0000; + g[ 16] = 4'b0100; + g[ 17] = 4'b0000; + g[ 18] = 4'b0101; + g[ 19] = 4'b0000; + g[ 20] = 4'b0100; + g[ 21] = 4'b0000; + g[ 22] = 4'b0101; + g[ 23] = 4'b0000; + g[ 24] = 4'b0100; + g[ 25] = 4'b0000; + g[ 26] = 4'b0101; + g[ 27] = 4'b0000; + g[ 28] = 4'b0101; + g[ 29] = 4'b0000; + g[ 30] = 4'b0101; + g[ 31] = 4'b0000; + g[ 32] = 4'b0101; + g[ 33] = 4'b0000; + g[ 34] = 4'b0101; + g[ 35] = 4'b0010; + g[ 36] = 4'b0101; + g[ 37] = 4'b0000; + g[ 38] = 4'b0101; + g[ 39] = 4'b0010; + g[ 40] = 4'b0101; + g[ 41] = 4'b1000; + g[ 42] = 4'b0101; + g[ 43] = 4'b0010; + g[ 44] = 4'b0101; + g[ 45] = 4'b1000; + g[ 46] = 4'b0101; + g[ 47] = 4'b0010; + g[ 48] = 4'b0101; + g[ 49] = 4'b1010; + g[ 50] = 4'b0101; + g[ 51] = 4'b0010; + g[ 52] = 4'b0101; + g[ 53] = 4'b1010; + g[ 54] = 4'b0101; + g[ 55] = 4'b0010; + g[ 56] = 4'b0101; + g[ 57] = 4'b1010; + g[ 58] = 4'b0101; + g[ 59] = 4'b1010; + g[ 60] = 4'b0101; + g[ 61] = 4'b1010; + g[ 62] = 4'b0101; + g[ 63] = 4'b1010; + g[ 64] = 4'b0101; + g[ 65] = 4'b1010; + g[ 66] = 4'b0101; + g[ 67] = 4'b1110; + g[ 68] = 4'b0101; + g[ 69] = 4'b1010; + g[ 70] = 4'b0101; + g[ 71] = 4'b1110; + g[ 72] = 4'b0101; + g[ 73] = 4'b1011; + g[ 74] = 4'b0101; + g[ 75] = 4'b1110; + g[ 76] = 4'b0101; + g[ 77] = 4'b1011; + g[ 78] = 4'b0101; + g[ 79] = 4'b1110; + g[ 80] = 4'b0101; + g[ 81] = 4'b1111; + g[ 82] = 4'b0101; + g[ 83] = 4'b1110; + g[ 84] = 4'b0101; + g[ 85] = 4'b1111; + g[ 86] = 4'b0101; + g[ 87] = 4'b1110; + g[ 88] = 4'b0101; + g[ 89] = 4'b1111; + g[ 90] = 4'b0101; + g[ 91] = 4'b1111; + g[ 92] = 4'b0101; + g[ 93] = 4'b1111; + g[ 94] = 4'b0101; + g[ 95] = 4'b1111; + g[ 96] = 4'b0101; + g[ 97] = 4'b1111; + g[ 98] = 4'b0101; + g[ 99] = 4'b1111; + g[100] = 4'b0111; + g[101] = 4'b1111; + g[102] = 4'b0101; + g[103] = 4'b1111; + g[104] = 4'b0111; + g[105] = 4'b1111; + g[106] = 4'b1101; + g[107] = 4'b1111; + g[108] = 4'b0111; + g[109] = 4'b1111; + g[110] = 4'b1101; + g[111] = 4'b1111; + g[112] = 4'b0111; + g[113] = 4'b1111; + g[114] = 4'b1111; + g[115] = 4'b1111; + g[116] = 4'b0111; + g[117] = 4'b1111; + g[118] = 4'b1111; + g[119] = 4'b1111; + g[120] = 4'b0111; + g[121] = 4'b1111; + g[122] = 4'b1111; + g[123] = 4'b1111; + g[124] = 4'b1111; + g[125] = 4'b1111; + g[126] = 4'b1111; + g[127] = 4'b1111; + end + +endmodule + +`endif diff --git a/src/tt_um_nvious_graphics.v b/src/tt_um_nvious_graphics.v index b3c51fe..1e90069 100644 --- a/src/tt_um_nvious_graphics.v +++ b/src/tt_um_nvious_graphics.v @@ -109,17 +109,74 @@ module tt_um_nvious_graphics( wire [9:0] hy0 = 439 - y; wire [9:0] hx1 = 511 - x; wire [9:0] hy1 = y - 440; - wire hq0 = (hy0[4:0] < circle[hx0[4:0]]) & (hx0 < 32) & (hy0 < 32); - wire hq1 = (hy0[4:0] < circle[hx1[4:0]]) & (hx1 < 32) & (hy0 < 32); - wire hq2 = (hy1[4:0] < circle[hx0[4:0]]) & (hx0 < 32) & (hy1 < 32); - wire hq3 = (hy1[4:0] < circle[hx1[4:0]]) & (hx1 < 32) & (hy1 < 32); + wire hq0 = (hy0[4:0] < (circle[{hx0[4:0],2'b00}][6:2])) & (hx0 < 32) & (hy0 < 32); + wire hq1 = (hy0[4:0] < (circle[{hx1[4:0],2'b00}][6:2])) & (hx1 < 32) & (hy0 < 32); + wire hq2 = (hy1[4:0] < (circle[{hx0[4:0],2'b00}][6:2])) & (hx0 < 32) & (hy1 < 32); + wire hq3 = (hy1[4:0] < (circle[{hx1[4:0],2'b00}][6:2])) & (hx1 < 32) & (hy1 < 32); wire h = hq0 | hq1 | hq2 | hq3; + wire [9:0] sx0 = x - 320; + wire [9:0] sy0 = 239 - y; + wire [9:0] sx1 = 319 - x; + wire [9:0] sy1 = y - 240; + wire sq0 = (sy0[6:0] < (circle[sx0[6:0]])) & (sx0 < 128) & (sy0 < 128); + wire sq1 = (sy0[6:0] < (circle[sx1[6:0]])) & (sx1 < 128) & (sy0 < 128); + wire sq2 = (sy1[6:0] < (circle[sx0[6:0]])) & (sx0 < 128) & (sy1 < 64);//128); + wire sq3 = (sy1[6:0] < (circle[sx1[6:0]])) & (sx1 < 128) & (sy1 < 64);//128); + wire s = sq0 | sq1 | sq2 | sq3; + + wire [5:0] black = 6'b000000; + wire [5:0] gray = 6'b010101; + wire [5:0] cyan = 6'b101111; + wire [5:0] red = 6'b110001; + wire [5:0] orange = 6'b110101; + wire [5:0] yellow = 6'b111101; + wire [5:0] pink = 6'b110011; + wire [5:0] dark_purple = 6'b100010; + wire [5:0] dark_blue = 6'b000001; + wire mask = a | b | c | d | e | f | g | h; - wire [5:0] bg = (x[3] ^ y[3]) ? 6'b010101 : 6'b000000; - wire [5:0] mg = mask ? ((x[0] ^ y[0]) ? 6'b010101 : bg) : bg; - wire [5:0] fg = 6'b111111; - assign RGB = video_active ? (((a & led[0]) | (b & led[1]) | (c & led[2]) | (d & led[3]) | (e & led[4]) | (f & led[5]) | (g & led[6]) | (h & led[7])) ? fg : mg) : 6'b000000; + + wire xor0 = x[0] ^ y[0]; + wire xor1 = (~x[0] & ~y[0]) & (x[1] & y[1]); + + wire bg0 = y < 50; + wire bg1 = y < 75 & xor1; + wire bg2 = y < 100 & xor0; + wire bg3 = y > 99 & y < 125 & xor1; + + // gradient + wire gsky; // gradient sky + gradient_rom gradient_sky( + .y(y[6:0]), + .x(x[1:0]), + .pixel(gsky) + ); + + wire gsun; // gradient of sun + gradient_rom gradient_sun( + .y(sy1[6:0]), + .x(x[1:0]), + .pixel(gsun) + ); + + // background (sky) + //wire [5:0] bg = (x[3] ^ y[3]) ? gray : black; + //wire [5:0] bg = bg0 ? dark_purple : (bg1 ? dark_purple : (bg2 ? dark_purple : (bg3 ? dark_purple : black))); + //wire [5:0] bg = (y < 112) ? (gsun ? black : dark_purple) : (y < 200) ? black : ((y < 256) ? (gsky ? pink : black) : black); + //wire [5:0] bg = (y < 112) ? (gsun ? black : dark_blue) : ((y > 200 && sy1 < 64) ? (gsun ? 6'b100010 : black) : black); + //wire [5:0] bg = (y < 128) ? (gsky ? dark_blue : black) : ((y > 200 && sy1 < 64) ? (gsun ? 6'b100010 : dark_blue) : dark_blue); + wire [5:0] bg = (y < 128) ? (gsky ? dark_blue : black) : ((y > 200 && sy1 < 64) ? (gsun ? 6'b100010 : dark_blue) : (y > sy1) ? black: dark_blue); + // c-ground (stars) + wire [5:0] cg = ((x[6]^y[6]) & (x[5:0]==32 & y[5:0]==32) & (y < sy1) ) ? cyan : bg; + // d-ground (sun) + wire [5:0] dg = s ? ((sy1 < 128) ? (gsun ? red : orange) : (gsun ? orange : yellow)) : cg; + // e-ground + //wire [5:0] eg = mask & xor1 ? cyan : dg; + wire [5:0] eg = dg; + // foreground + wire [5:0] fg = cyan; + assign RGB = video_active ? (((a & led[0]) | (b & led[1]) | (c & led[2]) | (d & led[3]) | (e & led[4]) | (f & led[5]) | (g & led[6]) | (h & led[7])) ? fg : eg) : 6'b000000; always @(posedge vsync) begin if (~rst_n) begin @@ -131,40 +188,135 @@ module tt_um_nvious_graphics( end end - reg [4:0] circle[0:31]; + reg [6:0] circle[0:127]; initial begin - circle[ 0] = 5'd31; - circle[ 1] = 5'd31; - circle[ 2] = 5'd31; - circle[ 3] = 5'd31; - circle[ 4] = 5'd31; - circle[ 5] = 5'd31; - circle[ 6] = 5'd30; - circle[ 7] = 5'd30; - circle[ 8] = 5'd30; - circle[ 9] = 5'd30; - circle[10] = 5'd29; - circle[11] = 5'd29; - circle[12] = 5'd29; - circle[13] = 5'd28; - circle[14] = 5'd28; - circle[15] = 5'd27; - circle[16] = 5'd27; - circle[17] = 5'd26; - circle[18] = 5'd25; - circle[19] = 5'd24; - circle[20] = 5'd24; - circle[21] = 5'd23; - circle[22] = 5'd22; - circle[23] = 5'd21; - circle[24] = 5'd20; - circle[25] = 5'd18; - circle[26] = 5'd17; - circle[27] = 5'd15; - circle[28] = 5'd13; - circle[29] = 5'd11; - circle[30] = 5'd8; - circle[31] = 5'd0; + circle[ 0] = 7'd127; + circle[ 1] = 7'd127; + circle[ 2] = 7'd127; + circle[ 3] = 7'd127; + circle[ 4] = 7'd127; + circle[ 5] = 7'd127; + circle[ 6] = 7'd127; + circle[ 7] = 7'd127; + circle[ 8] = 7'd127; + circle[ 9] = 7'd127; + circle[ 10] = 7'd127; + circle[ 11] = 7'd127; + circle[ 12] = 7'd127; + circle[ 13] = 7'd127; + circle[ 14] = 7'd127; + circle[ 15] = 7'd126; + circle[ 16] = 7'd126; + circle[ 17] = 7'd126; + circle[ 18] = 7'd126; + circle[ 19] = 7'd126; + circle[ 20] = 7'd126; + circle[ 21] = 7'd126; + circle[ 22] = 7'd125; + circle[ 23] = 7'd125; + circle[ 24] = 7'd125; + circle[ 25] = 7'd125; + circle[ 26] = 7'd125; + circle[ 27] = 7'd124; + circle[ 28] = 7'd124; + circle[ 29] = 7'd124; + circle[ 30] = 7'd124; + circle[ 31] = 7'd123; + circle[ 32] = 7'd123; + circle[ 33] = 7'd123; + circle[ 34] = 7'd123; + circle[ 35] = 7'd122; + circle[ 36] = 7'd122; + circle[ 37] = 7'd122; + circle[ 38] = 7'd121; + circle[ 39] = 7'd121; + circle[ 40] = 7'd121; + circle[ 41] = 7'd120; + circle[ 42] = 7'd120; + circle[ 43] = 7'd120; + circle[ 44] = 7'd119; + circle[ 45] = 7'd119; + circle[ 46] = 7'd119; + circle[ 47] = 7'd118; + circle[ 48] = 7'd118; + circle[ 49] = 7'd117; + circle[ 50] = 7'd117; + circle[ 51] = 7'd116; + circle[ 52] = 7'd116; + circle[ 53] = 7'd116; + circle[ 54] = 7'd115; + circle[ 55] = 7'd115; + circle[ 56] = 7'd114; + circle[ 57] = 7'd114; + circle[ 58] = 7'd113; + circle[ 59] = 7'd113; + circle[ 60] = 7'd112; + circle[ 61] = 7'd111; + circle[ 62] = 7'd111; + circle[ 63] = 7'd110; + circle[ 64] = 7'd110; + circle[ 65] = 7'd109; + circle[ 66] = 7'd109; + circle[ 67] = 7'd108; + circle[ 68] = 7'd107; + circle[ 69] = 7'd107; + circle[ 70] = 7'd106; + circle[ 71] = 7'd105; + circle[ 72] = 7'd105; + circle[ 73] = 7'd104; + circle[ 74] = 7'd103; + circle[ 75] = 7'd102; + circle[ 76] = 7'd102; + circle[ 77] = 7'd101; + circle[ 78] = 7'd100; + circle[ 79] = 7'd99; + circle[ 80] = 7'd99; + circle[ 81] = 7'd98; + circle[ 82] = 7'd97; + circle[ 83] = 7'd96; + circle[ 84] = 7'd95; + circle[ 85] = 7'd94; + circle[ 86] = 7'd93; + circle[ 87] = 7'd92; + circle[ 88] = 7'd91; + circle[ 89] = 7'd91; + circle[ 90] = 7'd90; + circle[ 91] = 7'd88; + circle[ 92] = 7'd87; + circle[ 93] = 7'd86; + circle[ 94] = 7'd85; + circle[ 95] = 7'd84; + circle[ 96] = 7'd83; + circle[ 97] = 7'd82; + circle[ 98] = 7'd81; + circle[ 99] = 7'd79; + circle[100] = 7'd78; + circle[101] = 7'd77; + circle[102] = 7'd75; + circle[103] = 7'd74; + circle[104] = 7'd73; + circle[105] = 7'd71; + circle[106] = 7'd70; + circle[107] = 7'd68; + circle[108] = 7'd67; + circle[109] = 7'd65; + circle[110] = 7'd63; + circle[111] = 7'd61; + circle[112] = 7'd60; + circle[113] = 7'd58; + circle[114] = 7'd56; + circle[115] = 7'd54; + circle[116] = 7'd51; + circle[117] = 7'd49; + circle[118] = 7'd47; + circle[119] = 7'd44; + circle[120] = 7'd41; + circle[121] = 7'd38; + circle[122] = 7'd35; + circle[123] = 7'd31; + circle[124] = 7'd27; + circle[125] = 7'd22; + circle[126] = 7'd15; + circle[127] = 7'd0; end - endmodule