@[email protected] asked

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% MULT18X18D32810.7% TRELLIS_COMB125052428851.5% TRELLIS_FF145242880.6% TRELLIS_IO101975.1% TRELLIS_RAMW1200303639.5%
TimingClockAchievedConstraint $glbnet$clkp31.01 MHz25 MHz $glbnet$clkt277.32 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); // version 2.0 // Fire resolution: 80x60 â scaled to 640x480 localparam int FW = 80; localparam int FH = 60; logic [7:0] fire[FH-1:0][FW-1:0]; logic old_vsync; logic [7:0] lfsr; // length of div slows frequency of sparks logic [4:0] spark_div; logic updating; logic [6:0] ux; logic [5:0] uy; assign char = 0; assign foreground_color = 24'hFFFFFF; // Scale VGA pixel to fire coordinates wire [6:0] fx = px[9:3]; // /8 â 0..79 wire [5:0] fy = py[9:3]; // /8 â 0..59 wire [7:0] v = fire[fy][fx]; // Map intensity to flame color: red dominant, green half, blue low assign background_color = {v, v >> 1, v >> 3}; integer x,y; always_ff @(posedge clk) begin if (rst) begin old_vsync <= 0; updating <= 0; ux <= 0; uy <= 0; spark_div <= 0; lfsr <= 8'hA5; // for (y=0; y<FH; y=y+1) // for (x=0; x<FW; x=x+1) // fire[y][x] <= 0; end else begin // start update on vsync rising edge (enter VBLANK) if (vsync && !old_vsync) begin updating <= 1; ux <= 0; uy <= 0; end // scroll fire upward across many clocks if (updating) begin // slight decay based on lsb of x coordinate times 2 fire[uy][ux] <= fire[uy+1][ux] - (ux & 1)<<1; if (ux == FW-1) begin ux <= 0; if (uy == FH-2) begin updating <= 0; uy <= 0; end else begin uy <= uy + 1; end end else begin ux <= ux + 1; end end // bottom sparks (slow, only when not updating) if (vsync && !old_vsync && !updating) begin spark_div <= spark_div + 1; if (!spark_div) begin lfsr <= {lfsr[6:0], lfsr[7]^lfsr[5]^lfsr[4]^lfsr[3]}; fire[FH-1][lfsr[6:0]] <= 8'hFF; end end old_vsync <= vsync; end end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] red, green, blue; always_comb begin red = 8'(col * 4); green = 8'(py); blue = frame_counter[7:0]; background_color = {red, green, blue}; foreground_color = '1; char = 0; end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% TRELLIS_COMB821242883.4% TRELLIS_FF142242880.6% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp40.55 MHz25 MHz $glbnet$clkt284.41 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] red, green, blue; always_comb begin red = 8'(col * 4); green = 8'(py); blue = frame_counter[7:0]; background_color = {red, green, blue}; foreground_color = '1; char = 0; end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] wave_offset; logic [7:0] pattern_select; logic [7:0] hue_shift; // Create animated wave pattern for background assign wave_offset = frame_counter[7:0] + col; // Cycle through different pattern types assign pattern_select = frame_counter[10:8]; // Hue rotation effect assign hue_shift = frame_counter[15:8]; always_comb begin logic [7:0] red, green, blue; logic [7:0] char_value; logic [7:0] pattern_output; // Create cute animated pattern based on row and column case(pattern_select) 3'b000: pattern_output = (row + col) ^ wave_offset; // Diagonal stripes 3'b001: pattern_output = row * col + frame_counter[7:0]; // Grid pattern 3'b010: pattern_output = ((row ^ col) << 1) + hue_shift; // XOR pattern default: pattern_output = (row + frame_counter[7:0]) ^ col; // Animated checkerboard endcase // RGB color cycling with pattern red = pattern_output + hue_shift; green = pattern_output + (hue_shift >> 1); blue = pattern_output - hue_shift; background_color = {red, green, blue}; // Character selection creates a cute animation char_value = ((row * 13 + col * 7) + frame_counter[9:0]) % 256; // Display cute characters: stars, diamonds, hearts, etc. if (char_value < 64) char = 42; // '*' - star else if (char_value < 128) char = 43; // '+' - plus else if (char_value < 192) char = 46; // '.' - dot else char = 35; // '#' - hash // Foreground color inverts based on background brightness if ((red + green + blue) > 12'h600) foreground_color = 24'h000000; // Black text on bright background else foreground_color = 24'hFFFFFF; // White text on dark background end always_ff @(posedge clk) begin if (rst) begin frame_counter <= '0; old_vsync <= '0; end else begin // Increment frame counter on vsync falling edge if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% MULT18X18D32810.7% TRELLIS_COMB1107242884.6% TRELLIS_FF152242880.6% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp40.55 MHz25 MHz $glbnet$clkt307.69 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] wave_offset; logic [7:0] pattern_select; logic [7:0] hue_shift; // Create animated wave pattern for background assign wave_offset = frame_counter[7:0] + col; // Cycle through different pattern types assign pattern_select = frame_counter[10:8]; // Hue rotation effect assign hue_shift = frame_counter[15:8]; always_comb begin logic [7:0] red, green, blue; logic [7:0] char_value; logic [7:0] pattern_output; // Create cute animated pattern based on row and column case(pattern_select) 3'b000: pattern_output = (row + col) ^ wave_offset; // Diagonal stripes 3'b001: pattern_output = row * col + frame_counter[7:0]; // Grid pattern 3'b010: pattern_output = ((row ^ col) << 1) + hue_shift; // XOR pattern default: pattern_output = (row + frame_counter[7:0]) ^ col; // Animated checkerboard endcase // RGB color cycling with pattern red = pattern_output + hue_shift; green = pattern_output + (hue_shift >> 1); blue = pattern_output - hue_shift; background_color = {red, green, blue}; // Character selection creates a cute animation char_value = ((row * 13 + col * 7) + frame_counter[9:0]) % 256; // Display cute characters: stars, diamonds, hearts, etc. if (char_value < 64) char = 42; // '*' - star else if (char_value < 128) char = 43; // '+' - plus else if (char_value < 192) char = 46; // '.' - dot else char = 35; // '#' - hash // Foreground color inverts based on background brightness if ((red + green + blue) > 12'h600) foreground_color = 24'h000000; // Black text on bright background else foreground_color = 24'hFFFFFF; // White text on dark background end always_ff @(posedge clk) begin if (rst) begin frame_counter <= '0; old_vsync <= '0; end else begin // Increment frame counter on vsync falling edge if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); // A "heartbeat" counter that ticks every frame to create a subtle animation effect logic [31:0] frame_counter = '0; logic old_vsync = '0; // Separate RGB channels for more creative color mixing logic [7:0] r_val, g_val, b_val; // A "mood" counter that cycles through different color palettes based on row position logic [31:0] mood_counter = '0; always_comb begin // Calculate dynamic colors based on input coordinates and frame time // Red channel: influenced by column position and frame counter low bits r_val = 8'({col[2:0], frame_counter[7:0][3:0]}); // Green channel: influenced by row position and mood counter g_val = 8'({row[1:0], mood_counter[15:14]}); // Blue channel: a mix of all inputs for a "glow" effect b_val = 8'(frame_counter[7:0][6:4] ^ row[2:0]); background_color = {r_val, g_val, b_val}; // Foreground is always white with a slight tint based on frame counter foreground_color = '1; if (frame_counter[31:28]) begin foreground_color = 24'b0000_0000_0000_0000_0000_0001; // Pure white end else begin foreground_color = 'hFFFFFF; // Light cyan tint end char = row + col; end always_ff @(posedge clk) begin if (rst == 1'b1) begin frame_counter <= '0; mood_counter <= '0; end else if (vsync == 1'b0 && old_vsync == 1'b1) begin // Increment counters on every new video frame frame_counter <= frame_counter + 1; mood_counter <= mood_counter + 1; end old_vsync <= vsync; end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% TRELLIS_COMB1245242885.1% TRELLIS_FF175242880.7% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp39.97 MHz25 MHz $glbnet$clkt293.51 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); // A "heartbeat" counter that ticks every frame to create a subtle animation effect logic [31:0] frame_counter = '0; logic old_vsync = '0; // Separate RGB channels for more creative color mixing logic [7:0] r_val, g_val, b_val; // A "mood" counter that cycles through different color palettes based on row position logic [31:0] mood_counter = '0; always_comb begin // Calculate dynamic colors based on input coordinates and frame time // Red channel: influenced by column position and frame counter low bits r_val = 8'({col[2:0], frame_counter[7:0][3:0]}); // Green channel: influenced by row position and mood counter g_val = 8'({row[1:0], mood_counter[15:14]}); // Blue channel: a mix of all inputs for a "glow" effect b_val = 8'(frame_counter[7:0][6:4] ^ row[2:0]); background_color = {r_val, g_val, b_val}; // Foreground is always white with a slight tint based on frame counter foreground_color = '1; if (frame_counter[31:28]) begin foreground_color = 24'b0000_0000_0000_0000_0000_0001; // Pure white end else begin foreground_color = 'hFFFFFF; // Light cyan tint end char = row + col; end always_ff @(posedge clk) begin if (rst == 1'b1) begin frame_counter <= '0; mood_counter <= '0; end else if (vsync == 1'b0 && old_vsync == 1'b1) begin // Increment counters on every new video frame frame_counter <= frame_counter + 1; mood_counter <= mood_counter + 1; end old_vsync <= vsync; end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity my_code is generic( WIDTH : integer := 640; HEIGHT : integer := 480; CONSOLE_COLUMNS : integer := WIDTH / 8; CONSOLE_ROWS : integer := HEIGHT / 8 ); port( clk : in std_logic; rst : in std_logic; px : in integer range 0 to WIDTH - 1; py : in integer range 0 to HEIGHT - 1; hsync : in std_logic; vsync : in std_logic; col : in integer range 0 to CONSOLE_COLUMNS - 1; row : in integer range 0 to CONSOLE_ROWS - 1; char : out integer range 0 to 127 := 0; foreground_color : out std_logic_vector(23 downto 0) := (others => '0'); background_color : out std_logic_vector(23 downto 0) := (others => '1') ); end my_code; architecture rtl of my_code is -- Aliases to map the 24-bit vectors to RGB channels easily alias bg_red : std_logic_vector(7 downto 0) is background_color(23 downto 16); alias bg_green : std_logic_vector(7 downto 0) is background_color(15 downto 8); alias bg_blue : std_logic_vector(7 downto 0) is background_color(7 downto 0); alias fg_red : std_logic_vector(7 downto 0) is foreground_color(23 downto 16); alias fg_green : std_logic_vector(7 downto 0) is foreground_color(15 downto 8); alias fg_blue : std_logic_vector(7 downto 0) is foreground_color(7 downto 0); signal frame_counter : unsigned(31 downto 0) := (others => '0'); -- Player Ship ASCII Graphics (Using safe characters to avoid escape sequence issues) constant ship_t : string(1 to 4) := " .^ "; constant ship_m : string(1 to 4) := "===>"; constant ship_b : string(1 to 4) := " 'v "; -- Enemy Asteroid Graphics constant ast_1 : string(1 to 3) := "(O)"; constant ast_2 : string(1 to 3) := "{#}"; -- Game Logic State Signals signal ship_y : integer := 20; signal ast_x : integer := 80; signal ast_y : integer := 20; signal ast_type : std_logic := '0'; signal laser_x : integer := -10; signal laser_y : integer := 0; signal laser_active : std_logic := '0'; -- Math signals for procedurally generated background elements signal xor_pattern : unsigned(7 downto 0); signal star_fast : unsigned(7 downto 0); signal star_slow : unsigned(7 downto 0); begin -- 1. Procedural "Munching Squares" Hyperspace Background -- By XORing the scaled coordinates and the frame counter, we create a mathematical -- fractal pattern that continuously zooms and shifts leftward. xor_pattern <= (to_unsigned(px / 4, 8) + frame_counter(9 downto 2)) xor to_unsigned(py / 4, 8); bg_red <= std_logic_vector(xor_pattern); -- Adding a bit of green and inverted blue makes it a crazy high-contrast neon vibe bg_green <= std_logic_vector(xor_pattern(6 downto 0) & '0'); bg_blue <= std_logic_vector(not xor_pattern); -- 2. Procedural Parallax Starfield Math -- We use prime number multipliers and bit masking to create a pseudo-random distribution -- that requires ZERO hardware division or modulo operators. star_fast <= to_unsigned(col * 13 + row * 7, 8) + frame_counter(8 downto 1); star_slow <= to_unsigned(col * 29 + row * 11, 8) + frame_counter(10 downto 3); -- 3. Character & Foreground Renderer process(col, row, ship_y, ast_x, ast_y, ast_type, frame_counter, laser_x, laser_y, laser_active, star_fast, star_slow) begin -- Default: Empty space char <= 0; fg_red <= x"FF"; fg_green <= x"FF"; fg_blue <= x"FF"; -- RENDER PLAYER SHIP if col >= 5 and col < 9 then if row = ship_y - 1 then char <= character'pos(ship_t(col - 5 + 1)); fg_red <= x"00"; fg_green <= x"FF"; fg_blue <= x"FF"; -- Cyan elsif row = ship_y then char <= character'pos(ship_m(col - 5 + 1)); fg_red <= x"00"; fg_green <= x"FF"; fg_blue <= x"FF"; elsif row = ship_y + 1 then char <= character'pos(ship_b(col - 5 + 1)); fg_red <= x"00"; fg_green <= x"FF"; fg_blue <= x"FF"; end if; -- RENDER ENGINE THRUST FLAME elsif col = 4 and row = ship_y then if frame_counter(2) = '1' then char <= character'pos('~'); fg_red <= x"FF"; fg_green <= x"45"; fg_blue <= x"00"; -- Orange-Red else char <= character'pos('-'); fg_red <= x"FF"; fg_green <= x"D7"; fg_blue <= x"00"; -- Gold end if; -- RENDER LASER BEAM elsif laser_active = '1' and row = laser_y and col >= laser_x and col < laser_x + 3 then char <= character'pos('-'); fg_red <= x"FF"; fg_green <= x"00"; fg_blue <= x"00"; -- Bright Red -- RENDER INCOMING ASTEROIDS elsif row = ast_y and col >= ast_x and col < ast_x + 3 then if ast_type = '0' then char <= character'pos(ast_1(col - ast_x + 1)); else char <= character'pos(ast_2(col - ast_x + 1)); end if; fg_red <= x"A9"; fg_green <= x"A9"; fg_blue <= x"A9"; -- Gray -- RENDER PARALLAX STARFIELD else -- Check the bitmasks of our math signals to spawn stars sparsely if star_fast(4 downto 0) = "00000" then char <= character'pos('-'); -- Fast streaks fg_red <= x"AA"; fg_green <= x"AA"; fg_blue <= x"FF"; elsif star_slow(5 downto 0) = "000000" then char <= character'pos('.'); -- Slow distant dots fg_red <= x"88"; fg_green <= x"88"; fg_blue <= x"88"; end if; end if; end process; -- 4. Game Engine (Animation & Collision Logic) process(clk) variable old_vsync : std_logic := '0'; begin if rising_edge(clk) then if rst = '1' then frame_counter <= (others => '0'); ship_y <= CONSOLE_ROWS / 2; ast_x <= CONSOLE_COLUMNS + 5; ast_y <= 20; laser_active <= '0'; elsif vsync = '0' and old_vsync = '1' then -- Increment global timer frame_counter <= frame_counter + 1; -- 4a. Ship bobbing (Sine wave approximation using counter bits) if frame_counter(5 downto 0) = "000000" then if frame_counter(6) = '1' and ship_y < CONSOLE_ROWS - 4 then ship_y <= ship_y + 1; elsif frame_counter(6) = '0' and ship_y > 4 then ship_y <= ship_y - 1; end if; end if; -- 4b. Asteroid Movement (Moves leftward) if frame_counter(1 downto 0) = "00" then if ast_x < -3 then ast_x <= CONSOLE_COLUMNS + 5; -- Respawn off-screen right -- Use bits of the frame counter to randomly select new Y row and type ast_y <= 5 + to_integer(frame_counter(7 downto 3)); ast_type <= frame_counter(2); else ast_x <= ast_x - 1; end if; end if; -- 4c. Laser Physics and Collision Detection if laser_active = '1' then -- Lasers move very fast to the right laser_x <= laser_x + 2; -- Deactivate if it goes off screen if laser_x > CONSOLE_COLUMNS then laser_active <= '0'; end if; -- Collision Check: Did the laser hit the asteroid? if laser_x >= ast_x and laser_y = ast_y then ast_x <= -10; -- Banish asteroid off-screen laser_active <= '0'; -- Turn off laser end if; else -- Auto-fire mechanism: Shoot a new laser periodically! if frame_counter(6 downto 0) = "0000000" then laser_active <= '1'; laser_x <= 10; laser_y <= ship_y; end if; end if; end if; old_vsync := vsync; end if; end process; end architecture;

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% MULT18X18D42814.3% TRELLIS_COMB1842242887.6% TRELLIS_FF281242881.2% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp35.49 MHz25 MHz $glbnet$clkt312.7 MHz250 MHz
Code

library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity my_code is generic( WIDTH : integer := 640; HEIGHT : integer := 480; CONSOLE_COLUMNS : integer := WIDTH / 8; CONSOLE_ROWS : integer := HEIGHT / 8 ); port( clk : in std_logic; rst : in std_logic; px : in integer range 0 to WIDTH - 1; py : in integer range 0 to HEIGHT - 1; hsync : in std_logic; vsync : in std_logic; col : in integer range 0 to CONSOLE_COLUMNS - 1; row : in integer range 0 to CONSOLE_ROWS - 1; char : out integer range 0 to 127 := 0; foreground_color : out std_logic_vector(23 downto 0) := (others => '0'); background_color : out std_logic_vector(23 downto 0) := (others => '1') ); end my_code; architecture rtl of my_code is -- Aliases to map the 24-bit vectors to RGB channels easily alias bg_red : std_logic_vector(7 downto 0) is background_color(23 downto 16); alias bg_green : std_logic_vector(7 downto 0) is background_color(15 downto 8); alias bg_blue : std_logic_vector(7 downto 0) is background_color(7 downto 0); alias fg_red : std_logic_vector(7 downto 0) is foreground_color(23 downto 16); alias fg_green : std_logic_vector(7 downto 0) is foreground_color(15 downto 8); alias fg_blue : std_logic_vector(7 downto 0) is foreground_color(7 downto 0); signal frame_counter : unsigned(31 downto 0) := (others => '0'); -- Player Ship ASCII Graphics (Using safe characters to avoid escape sequence issues) constant ship_t : string(1 to 4) := " .^ "; constant ship_m : string(1 to 4) := "===>"; constant ship_b : string(1 to 4) := " 'v "; -- Enemy Asteroid Graphics constant ast_1 : string(1 to 3) := "(O)"; constant ast_2 : string(1 to 3) := "{#}"; -- Game Logic State Signals signal ship_y : integer := 20; signal ast_x : integer := 80; signal ast_y : integer := 20; signal ast_type : std_logic := '0'; signal laser_x : integer := -10; signal laser_y : integer := 0; signal laser_active : std_logic := '0'; -- Math signals for procedurally generated background elements signal xor_pattern : unsigned(7 downto 0); signal star_fast : unsigned(7 downto 0); signal star_slow : unsigned(7 downto 0); begin -- 1. Procedural "Munching Squares" Hyperspace Background -- By XORing the scaled coordinates and the frame counter, we create a mathematical -- fractal pattern that continuously zooms and shifts leftward. xor_pattern <= (to_unsigned(px / 4, 8) + frame_counter(9 downto 2)) xor to_unsigned(py / 4, 8); bg_red <= std_logic_vector(xor_pattern); -- Adding a bit of green and inverted blue makes it a crazy high-contrast neon vibe bg_green <= std_logic_vector(xor_pattern(6 downto 0) & '0'); bg_blue <= std_logic_vector(not xor_pattern); -- 2. Procedural Parallax Starfield Math -- We use prime number multipliers and bit masking to create a pseudo-random distribution -- that requires ZERO hardware division or modulo operators. star_fast <= to_unsigned(col * 13 + row * 7, 8) + frame_counter(8 downto 1); star_slow <= to_unsigned(col * 29 + row * 11, 8) + frame_counter(10 downto 3); -- 3. Character & Foreground Renderer process(col, row, ship_y, ast_x, ast_y, ast_type, frame_counter, laser_x, laser_y, laser_active, star_fast, star_slow) begin -- Default: Empty space char <= 0; fg_red <= x"FF"; fg_green <= x"FF"; fg_blue <= x"FF"; -- RENDER PLAYER SHIP if col >= 5 and col < 9 then if row = ship_y - 1 then char <= character'pos(ship_t(col - 5 + 1)); fg_red <= x"00"; fg_green <= x"FF"; fg_blue <= x"FF"; -- Cyan elsif row = ship_y then char <= character'pos(ship_m(col - 5 + 1)); fg_red <= x"00"; fg_green <= x"FF"; fg_blue <= x"FF"; elsif row = ship_y + 1 then char <= character'pos(ship_b(col - 5 + 1)); fg_red <= x"00"; fg_green <= x"FF"; fg_blue <= x"FF"; end if; -- RENDER ENGINE THRUST FLAME elsif col = 4 and row = ship_y then if frame_counter(2) = '1' then char <= character'pos('~'); fg_red <= x"FF"; fg_green <= x"45"; fg_blue <= x"00"; -- Orange-Red else char <= character'pos('-'); fg_red <= x"FF"; fg_green <= x"D7"; fg_blue <= x"00"; -- Gold end if; -- RENDER LASER BEAM elsif laser_active = '1' and row = laser_y and col >= laser_x and col < laser_x + 3 then char <= character'pos('-'); fg_red <= x"FF"; fg_green <= x"00"; fg_blue <= x"00"; -- Bright Red -- RENDER INCOMING ASTEROIDS elsif row = ast_y and col >= ast_x and col < ast_x + 3 then if ast_type = '0' then char <= character'pos(ast_1(col - ast_x + 1)); else char <= character'pos(ast_2(col - ast_x + 1)); end if; fg_red <= x"A9"; fg_green <= x"A9"; fg_blue <= x"A9"; -- Gray -- RENDER PARALLAX STARFIELD else -- Check the bitmasks of our math signals to spawn stars sparsely if star_fast(4 downto 0) = "00000" then char <= character'pos('-'); -- Fast streaks fg_red <= x"AA"; fg_green <= x"AA"; fg_blue <= x"FF"; elsif star_slow(5 downto 0) = "000000" then char <= character'pos('.'); -- Slow distant dots fg_red <= x"88"; fg_green <= x"88"; fg_blue <= x"88"; end if; end if; end process; -- 4. Game Engine (Animation & Collision Logic) process(clk) variable old_vsync : std_logic := '0'; begin if rising_edge(clk) then if rst = '1' then frame_counter <= (others => '0'); ship_y <= CONSOLE_ROWS / 2; ast_x <= CONSOLE_COLUMNS + 5; ast_y <= 20; laser_active <= '0'; elsif vsync = '0' and old_vsync = '1' then -- Increment global timer frame_counter <= frame_counter + 1; -- 4a. Ship bobbing (Sine wave approximation using counter bits) if frame_counter(5 downto 0) = "000000" then if frame_counter(6) = '1' and ship_y < CONSOLE_ROWS - 4 then ship_y <= ship_y + 1; elsif frame_counter(6) = '0' and ship_y > 4 then ship_y <= ship_y - 1; end if; end if; -- 4b. Asteroid Movement (Moves leftward) if frame_counter(1 downto 0) = "00" then if ast_x < -3 then ast_x <= CONSOLE_COLUMNS + 5; -- Respawn off-screen right -- Use bits of the frame counter to randomly select new Y row and type ast_y <= 5 + to_integer(frame_counter(7 downto 3)); ast_type <= frame_counter(2); else ast_x <= ast_x - 1; end if; end if; -- 4c. Laser Physics and Collision Detection if laser_active = '1' then -- Lasers move very fast to the right laser_x <= laser_x + 2; -- Deactivate if it goes off screen if laser_x > CONSOLE_COLUMNS then laser_active <= '0'; end if; -- Collision Check: Did the laser hit the asteroid? if laser_x >= ast_x and laser_y = ast_y then ast_x <= -10; -- Banish asteroid off-screen laser_active <= '0'; -- Turn off laser end if; else -- Auto-fire mechanism: Shoot a new laser periodically! if frame_counter(6 downto 0) = "0000000" then laser_active <= '1'; laser_x <= 10; laser_y <= ship_y; end if; end if; end if; old_vsync := vsync; end if; end process; end architecture;


#FPGA #Icepi-Zero #HDL #VHDL

@[email protected] asked

library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity my_code is generic( WIDTH : integer := 640; HEIGHT : integer := 480; CONSOLE_COLUMNS : integer := WIDTH / 8; CONSOLE_ROWS : integer := HEIGHT / 8 ); port( clk : in std_logic; rst : in std_logic; px : in integer range 0 to WIDTH - 1; py : in integer range 0 to HEIGHT - 1; hsync : in std_logic; vsync : in std_logic; col : in integer range 0 to CONSOLE_COLUMNS - 1; row : in integer range 0 to CONSOLE_ROWS - 1; char : out integer range 0 to 127 := 0; foreground_color : out std_logic_vector(23 downto 0) := (others => '0'); background_color : out std_logic_vector(23 downto 0) := (others => '1') ); end my_code; architecture rtl of my_code is -- Aliases for RGB color channels alias bg_red : std_logic_vector(7 downto 0) is background_color(23 downto 16); alias bg_green : std_logic_vector(7 downto 0) is background_color(15 downto 8); alias bg_blue : std_logic_vector(7 downto 0) is background_color(7 downto 0); alias fg_red : std_logic_vector(7 downto 0) is foreground_color(23 downto 16); alias fg_green : std_logic_vector(7 downto 0) is foreground_color(15 downto 8); alias fg_blue : std_logic_vector(7 downto 0) is foreground_color(7 downto 0); signal frame_counter : unsigned(31 downto 0) := (others => '0'); -- Our ASCII Aquarium residents constant fish_right : string(1 to 5) := " ><> "; constant fish_left : string(1 to 5) := " <>< "; constant crab : string(1 to 5) := "(\_/)"; -- Coordinates for our moving fish (unconstrained integers to allow them to swim off-screen) signal fish1_x : integer := -5; signal fish1_y : integer := 5; signal fish2_x : integer := CONSOLE_COLUMNS + 5; signal fish2_y : integer := 15; -- A slow toggle signal to make the seaweed wave back and forth signal wave_toggle : std_logic; begin -- 1. Deep Sea Gradient Background -- The water is brighter at the top (py = 0) and gets darker as it goes down. bg_red <= std_logic_vector(to_unsigned( 10, 8)); -- Minimal red underwater bg_green <= std_logic_vector(to_unsigned( 180 - (py / 3), 8)); bg_blue <= std_logic_vector(to_unsigned( 255 - (py / 4), 8)); -- 2. Foreground Color Logic process(row) begin if row >= CONSOLE_ROWS - 2 then -- Seaweed green for the bottom of the tank fg_red <= x"2E"; fg_green <= x"8B"; fg_blue <= x"57"; else -- Crisp white for the fish and bubbles fg_red <= x"FF"; fg_green <= x"FF"; fg_blue <= x"FF"; end if; end process; wave_toggle <= frame_counter(4); -- Toggles every 16 frames -- 3. Character Rendering Logic (The Magic) process(col, row, fish1_x, fish1_y, fish2_x, fish2_y, frame_counter, wave_toggle) variable bubble_offset : integer range 0 to 63; begin -- Default: Empty water char <= 0; -- Draw Fish 1 (swimming right) if row = fish1_y and col >= fish1_x and col < fish1_x + 5 then if (col - fish1_x + 1) >= 1 and (col - fish1_x + 1) <= 5 then char <= character'pos(fish_right(col - fish1_x + 1)); end if; -- Draw Fish 2 (swimming left) elsif row = fish2_y and col >= fish2_x and col < fish2_x + 5 then if (col - fish2_x + 1) >= 1 and (col - fish2_x + 1) <= 5 then char <= character'pos(fish_left(col - fish2_x + 1)); end if; -- Draw the little Crab hanging out on the sea floor elsif row = CONSOLE_ROWS - 1 and col >= 30 and col < 35 then char <= character'pos(crab(col - 30 + 1)); -- Draw animated Seaweed at the bottom elsif row >= CONSOLE_ROWS - 2 then if (col mod 7) = 0 then if wave_toggle = '1' then char <= character'pos('~'); else char <= character'pos('S'); end if; elsif (col mod 11) = 0 and row = CONSOLE_ROWS - 1 then if wave_toggle = '0' then char <= character'pos('~'); else char <= character'pos('S'); end if; end if; -- Draw organically rising bubbles else -- Select a few random-looking columns to spawn bubbles if (col = 12) or (col = 28) or (col = 52) or (col = 68) then -- Calculate an upward scrolling offset based on time and column position bubble_offset := to_integer(unsigned'(frame_counter(8 downto 3) + to_unsigned(col * 5, 6))); -- If the bubble is currently on the screen, draw it! if bubble_offset < CONSOLE_ROWS then if row = (CONSOLE_ROWS - 1 - bubble_offset) then if (col mod 3) = 0 then char <= character'pos('o'); else char <= character'pos('O'); end if; end if; end if; end if; end if; end process; -- 4. Animation Timing and Movement process(clk) variable old_vsync : std_logic := '0'; begin if rising_edge(clk) then if rst = '1' then frame_counter <= (others => '0'); fish1_x <= -5; fish2_x <= CONSOLE_COLUMNS + 5; elsif vsync = '0' and old_vsync = '1' then -- Increment frame counter at the start of each new frame frame_counter <= frame_counter + 1; -- Move Fish 1 to the right (Medium Speed) if frame_counter(2 downto 0) = "000" then if fish1_x > CONSOLE_COLUMNS then fish1_x <= -10; -- Wrap around -- Pseudo-randomize depth when it wraps fish1_y <= 3 + to_integer(frame_counter(4 downto 3)); else fish1_x <= fish1_x + 1; end if; end if; -- Move Fish 2 to the left (Slightly Faster) if frame_counter(1 downto 0) = "00" then if fish2_x < -10 then fish2_x <= CONSOLE_COLUMNS + 5; -- Wrap around -- Pseudo-randomize depth when it wraps fish2_y <= 12 + to_integer(frame_counter(5 downto 4)); else fish2_x <= fish2_x - 1; end if; end if; end if; old_vsync := vsync; end if; end process; end architecture;

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% MULT18X18D1283.6% TRELLIS_COMB2017242888.3% TRELLIS_FF210242880.9% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp32 MHz25 MHz $glbnet$clkt276.93 MHz250 MHz
Code

library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity my_code is generic( WIDTH : integer := 640; HEIGHT : integer := 480; CONSOLE_COLUMNS : integer := WIDTH / 8; CONSOLE_ROWS : integer := HEIGHT / 8 ); port( clk : in std_logic; rst : in std_logic; px : in integer range 0 to WIDTH - 1; py : in integer range 0 to HEIGHT - 1; hsync : in std_logic; vsync : in std_logic; col : in integer range 0 to CONSOLE_COLUMNS - 1; row : in integer range 0 to CONSOLE_ROWS - 1; char : out integer range 0 to 127 := 0; foreground_color : out std_logic_vector(23 downto 0) := (others => '0'); background_color : out std_logic_vector(23 downto 0) := (others => '1') ); end my_code; architecture rtl of my_code is -- Aliases for RGB color channels alias bg_red : std_logic_vector(7 downto 0) is background_color(23 downto 16); alias bg_green : std_logic_vector(7 downto 0) is background_color(15 downto 8); alias bg_blue : std_logic_vector(7 downto 0) is background_color(7 downto 0); alias fg_red : std_logic_vector(7 downto 0) is foreground_color(23 downto 16); alias fg_green : std_logic_vector(7 downto 0) is foreground_color(15 downto 8); alias fg_blue : std_logic_vector(7 downto 0) is foreground_color(7 downto 0); signal frame_counter : unsigned(31 downto 0) := (others => '0'); -- Our ASCII Aquarium residents constant fish_right : string(1 to 5) := " ><> "; constant fish_left : string(1 to 5) := " <>< "; constant crab : string(1 to 5) := "(\_/)"; -- Coordinates for our moving fish (unconstrained integers to allow them to swim off-screen) signal fish1_x : integer := -5; signal fish1_y : integer := 5; signal fish2_x : integer := CONSOLE_COLUMNS + 5; signal fish2_y : integer := 15; -- A slow toggle signal to make the seaweed wave back and forth signal wave_toggle : std_logic; begin -- 1. Deep Sea Gradient Background -- The water is brighter at the top (py = 0) and gets darker as it goes down. bg_red <= std_logic_vector(to_unsigned( 10, 8)); -- Minimal red underwater bg_green <= std_logic_vector(to_unsigned( 180 - (py / 3), 8)); bg_blue <= std_logic_vector(to_unsigned( 255 - (py / 4), 8)); -- 2. Foreground Color Logic process(row) begin if row >= CONSOLE_ROWS - 2 then -- Seaweed green for the bottom of the tank fg_red <= x"2E"; fg_green <= x"8B"; fg_blue <= x"57"; else -- Crisp white for the fish and bubbles fg_red <= x"FF"; fg_green <= x"FF"; fg_blue <= x"FF"; end if; end process; wave_toggle <= frame_counter(4); -- Toggles every 16 frames -- 3. Character Rendering Logic (The Magic) process(col, row, fish1_x, fish1_y, fish2_x, fish2_y, frame_counter, wave_toggle) variable bubble_offset : integer range 0 to 63; begin -- Default: Empty water char <= 0; -- Draw Fish 1 (swimming right) if row = fish1_y and col >= fish1_x and col < fish1_x + 5 then if (col - fish1_x + 1) >= 1 and (col - fish1_x + 1) <= 5 then char <= character'pos(fish_right(col - fish1_x + 1)); end if; -- Draw Fish 2 (swimming left) elsif row = fish2_y and col >= fish2_x and col < fish2_x + 5 then if (col - fish2_x + 1) >= 1 and (col - fish2_x + 1) <= 5 then char <= character'pos(fish_left(col - fish2_x + 1)); end if; -- Draw the little Crab hanging out on the sea floor elsif row = CONSOLE_ROWS - 1 and col >= 30 and col < 35 then char <= character'pos(crab(col - 30 + 1)); -- Draw animated Seaweed at the bottom elsif row >= CONSOLE_ROWS - 2 then if (col mod 7) = 0 then if wave_toggle = '1' then char <= character'pos('~'); else char <= character'pos('S'); end if; elsif (col mod 11) = 0 and row = CONSOLE_ROWS - 1 then if wave_toggle = '0' then char <= character'pos('~'); else char <= character'pos('S'); end if; end if; -- Draw organically rising bubbles else -- Select a few random-looking columns to spawn bubbles if (col = 12) or (col = 28) or (col = 52) or (col = 68) then -- Calculate an upward scrolling offset based on time and column position bubble_offset := to_integer(unsigned'(frame_counter(8 downto 3) + to_unsigned(col * 5, 6))); -- If the bubble is currently on the screen, draw it! if bubble_offset < CONSOLE_ROWS then if row = (CONSOLE_ROWS - 1 - bubble_offset) then if (col mod 3) = 0 then char <= character'pos('o'); else char <= character'pos('O'); end if; end if; end if; end if; end if; end process; -- 4. Animation Timing and Movement process(clk) variable old_vsync : std_logic := '0'; begin if rising_edge(clk) then if rst = '1' then frame_counter <= (others => '0'); fish1_x <= -5; fish2_x <= CONSOLE_COLUMNS + 5; elsif vsync = '0' and old_vsync = '1' then -- Increment frame counter at the start of each new frame frame_counter <= frame_counter + 1; -- Move Fish 1 to the right (Medium Speed) if frame_counter(2 downto 0) = "000" then if fish1_x > CONSOLE_COLUMNS then fish1_x <= -10; -- Wrap around -- Pseudo-randomize depth when it wraps fish1_y <= 3 + to_integer(frame_counter(4 downto 3)); else fish1_x <= fish1_x + 1; end if; end if; -- Move Fish 2 to the left (Slightly Faster) if frame_counter(1 downto 0) = "00" then if fish2_x < -10 then fish2_x <= CONSOLE_COLUMNS + 5; -- Wrap around -- Pseudo-randomize depth when it wraps fish2_y <= 12 + to_integer(frame_counter(5 downto 4)); else fish2_x <= fish2_x - 1; end if; end if; end if; old_vsync := vsync; end if; end process; end architecture;


#FPGA #Icepi-Zero #HDL #VHDL

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = 0; logic old_vsync = 0; logic [7:0] red, green, blue; // Define a simple character mapping for demonstration. logic [7:0] char_code; always_comb begin // Calculate the character code based on pixel coordinates. // This creates a very basic "pixelated" text effect. char_code = (px % 8) << 4 | (py % 8); // Combine X and Y into a single char code // Simple color palette - Red for important, Green for normal, Blue for background red = 8'(col * 2); // More intense red based on column. green = 8'(py); // Normal green for the row. blue = frame_counter[7:0]; // Blue changes with the frame counter background_color = {red, green, blue}; foreground_color = char_code[7:0] ? 1'b1 : 1'b0; // Turn on foreground only when a character is being drawn. char = char_code; end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% TRELLIS_COMB855242883.5% TRELLIS_FF143242880.6% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp38.29 MHz25 MHz $glbnet$clkt293.69 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = 0; logic old_vsync = 0; logic [7:0] red, green, blue; // Define a simple character mapping for demonstration. logic [7:0] char_code; always_comb begin // Calculate the character code based on pixel coordinates. // This creates a very basic "pixelated" text effect. char_code = (px % 8) << 4 | (py % 8); // Combine X and Y into a single char code // Simple color palette - Red for important, Green for normal, Blue for background red = 8'(col * 2); // More intense red based on column. green = 8'(py); // Normal green for the row. blue = frame_counter[7:0]; // Blue changes with the frame counter background_color = {red, green, blue}; foreground_color = char_code[7:0] ? 1'b1 : 1'b0; // Turn on foreground only when a character is being drawn. char = char_code; end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [7:0] frame_counter; logic old_vsync; logic [7:0] red, green, blue; logic [7:0] character_data; // Data for the character to display // Character mapping - a simplified ASCII representation. More characters can be added. localparam CHAR_A = 8'h41; localparam CHAR_B = 8'h42; localparam CHAR_C = 8'h43; always_ff @(posedge clk) begin if (rst) begin frame_counter <= 0; old_vsync <= 0; character_data <= 8'h00; // Blank character end else begin frame_counter <= frame_counter + 1; old_vsync <= vsync; // Simple animation: A rotating character if (frame_counter % 30 == 0) begin //Update every 30 frames character_data <= (frame_counter / 30) % 3 ? CHAR_A : (frame_counter / 30) % 3 + 1 ? CHAR_B : CHAR_C; end end end always_comb begin // Color mapping - a simple color scheme. Adjust as needed. red = 8'(col * 2); //Red scales with column position green = 8'(py * 3); //Green scales with row position blue = frame_counter[7:0] % 64; //Blue cycles through a range background_color = {red, green, blue}; //Foreground color based on the character being displayed. if (character_data == CHAR_A) begin foreground_color = 24'h00FF0000; //Green on Black for 'A' end else if(character_data == CHAR_B) begin foreground_color = 24'hFF000000; //Red on Black for 'B' end else if (character_data == CHAR_C) begin foreground_color = 24'h0000FF00; //Green on Black for 'C' end else begin foreground_color = 24'hFFFFFF00; //White on Black for default character. end char = character_data; end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% DP16KD2563.6% EHXPLLL1250% MULT18X18D1283.6% TRELLIS_COMB1002242884.1% TRELLIS_FF143242880.6% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp38.73 MHz25 MHz $glbnet$clkt279.49 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [7:0] frame_counter; logic old_vsync; logic [7:0] red, green, blue; logic [7:0] character_data; // Data for the character to display // Character mapping - a simplified ASCII representation. More characters can be added. localparam CHAR_A = 8'h41; localparam CHAR_B = 8'h42; localparam CHAR_C = 8'h43; always_ff @(posedge clk) begin if (rst) begin frame_counter <= 0; old_vsync <= 0; character_data <= 8'h00; // Blank character end else begin frame_counter <= frame_counter + 1; old_vsync <= vsync; // Simple animation: A rotating character if (frame_counter % 30 == 0) begin //Update every 30 frames character_data <= (frame_counter / 30) % 3 ? CHAR_A : (frame_counter / 30) % 3 + 1 ? CHAR_B : CHAR_C; end end end always_comb begin // Color mapping - a simple color scheme. Adjust as needed. red = 8'(col * 2); //Red scales with column position green = 8'(py * 3); //Green scales with row position blue = frame_counter[7:0] % 64; //Blue cycles through a range background_color = {red, green, blue}; //Foreground color based on the character being displayed. if (character_data == CHAR_A) begin foreground_color = 24'h00FF0000; //Green on Black for 'A' end else if(character_data == CHAR_B) begin foreground_color = 24'hFF000000; //Red on Black for 'B' end else if (character_data == CHAR_C) begin foreground_color = 24'h0000FF00; //Green on Black for 'C' end else begin foreground_color = 24'hFFFFFF00; //White on Black for default character. end char = character_data; end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] red, green, blue; // Define a simple character set - ASCII for demonstration. Can be expanded. logic [7:0] char_code; localparam MAX_CHARS = 256; //ASCII range always_comb begin // Simple character mapping based on row and column. Makes it look like text! if (row < CONSOLE_ROWS && col < CONSOLE_COLUMNS) begin char_code = { (col % MAX_CHARS), (row % MAX_CHARS) }; //Basic char selection. //This is a simplistic demo, a real console would need more sophisticated mapping! end else begin char_code = 8'h20; // Space if out of bounds end red = 8'(col * 4); green = 8'(py); blue = frame_counter[7:0]; background_color = {red, green, blue}; //Foreground color - a simple gradient based on row. //This adds visual interest and makes it look like something is "drawing." foreground_color = { (row % 16'hF000) , // Red component: Gradual change in red (row % 16'h00FF), // Green component: Gradual change in green (row % 16'h0000) // Blue Component: Constant blue. }; char = char_code; end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% TRELLIS_COMB819242883.4% TRELLIS_FF142242880.6% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp41.45 MHz25 MHz $glbnet$clkt361.01 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] red, green, blue; // Define a simple character set - ASCII for demonstration. Can be expanded. logic [7:0] char_code; localparam MAX_CHARS = 256; //ASCII range always_comb begin // Simple character mapping based on row and column. Makes it look like text! if (row < CONSOLE_ROWS && col < CONSOLE_COLUMNS) begin char_code = { (col % MAX_CHARS), (row % MAX_CHARS) }; //Basic char selection. //This is a simplistic demo, a real console would need more sophisticated mapping! end else begin char_code = 8'h20; // Space if out of bounds end red = 8'(col * 4); green = 8'(py); blue = frame_counter[7:0]; background_color = {red, green, blue}; //Foreground color - a simple gradient based on row. //This adds visual interest and makes it look like something is "drawing." foreground_color = { (row % 16'hF000) , // Red component: Gradual change in red (row % 16'h00FF), // Green component: Gradual change in green (row % 16'h0000) // Blue Component: Constant blue. }; char = char_code; end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog

@[email protected] asked

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] red, green, blue; // Simulate a simple text rendering. Adjustments for character mapping and color. logic [7:0] character_code; // Representing the ASCII value of the character to display. always_comb begin // Map row/col to a character code (simplified). character_code = (py / 16) + (px / 8); // Example mapping, adjust as needed. if(character_code > 127) character_code = 127; // Limit to ASCII range red = 8'(col * 4); green = 8'(py); blue = frame_counter[7:0]; background_color = {red, green, blue}; foreground_color = '1; char = character_code; // Assign the character code to the output. end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule

Sucess!

UtilizationCellUsedAvailableUsage DCCA2563.6% EHXPLLL1250% TRELLIS_COMB1363242885.6% TRELLIS_FF143242880.6% TRELLIS_IO101975.1%
TimingClockAchievedConstraint $glbnet$clkp39.67 MHz25 MHz $glbnet$clkt265.46 MHz250 MHz
Code

module my_code #( parameter int WIDTH = 640, parameter int HEIGHT = 480, parameter int CONSOLE_COLUMNS = WIDTH / 8, parameter int CONSOLE_ROWS = HEIGHT / 8 )( input logic clk, input logic rst, input int px, input int py, input logic hsync, input logic vsync, input int col, input int row, output int char, output logic [23:0] foreground_color, output logic [23:0] background_color ); logic [31:0] frame_counter = '0; logic old_vsync = '0; logic [7:0] red, green, blue; // Simulate a simple text rendering. Adjustments for character mapping and color. logic [7:0] character_code; // Representing the ASCII value of the character to display. always_comb begin // Map row/col to a character code (simplified). character_code = (py / 16) + (px / 8); // Example mapping, adjust as needed. if(character_code > 127) character_code = 127; // Limit to ASCII range red = 8'(col * 4); green = 8'(py); blue = frame_counter[7:0]; background_color = {red, green, blue}; foreground_color = '1; char = character_code; // Assign the character code to the output. end always_ff @(posedge clk) begin if (vsync == 1'b0 && old_vsync == 1'b1) begin frame_counter <= frame_counter + 1; end old_vsync <= vsync; end endmodule


#FPGA #Icepi-Zero #HDL #SystemVerilog