Tuesday, July 17, 2012

Attaching bram to vga

The VGA is working and as a hard coded test, I created some colorful squares
using
rgb_o <= "111" when within_range else "000";

Now it is time to use something that has the potential to change over time.

I used a BRAM to store the color values for each pixel.
Although I wasn't about to harness 8 bit color, at least I was able to get 3 bit color.

I hard coded a few colors into the bram and viola! they showed up in the screen!

below is the state machine I used to test my bram.  The purpose of this
state machine is to  add things to the BRAM and then the VGA timer would read that bram.
This snippit of code only showes how I added something new to the bram.

The screen showed 3 squares of the expected size.  However, there were some random artifacts such as dots being missing or dots being missing colored or dots being in places where they shouldn't.  I believe that
it is mainly a side effect of a poorly written process.  The snippit below was meant to be quick and dirty, so it is rather unorthodox.
--==========================================

process(clock)
constant max_val: integer := (hdisp_size*vdisp_size);
variable cnt: integer:= 0;
variable color_var: std_logic_vector(2 downto 0):= (others => '0');
type states is (init,x_sq, y_sq);
variable st: states := init;
variable x_var,y_var: integer:= 0;
variable coordinate:integer:= 0;
begin
if clock = '1' and clock'event then
case st is
when init => st := x_sq;
when x_sq =>
if x_var >= hdisp_size then st:= y_sq;
x_var := 0;
else st:= x_sq;
x_var := x_var + 1;
end if;
when y_sq =>
if y_var >= vdisp_size then st := x_sq;
y_var := 0;
else st := x_sq;
y_var := y_var +1;
end if;
when others => st:=init;
end case;
coordinate := x_var + y_var*hdisp_size;
if x_var >=0 and x_var < 15 and
y_var >= 0 and y_var < 44 then
color_var := red_c;
elsif x_var >= 20 and x_var < 300 and
y_var >= 40 and y_var < 200 then
color_var := cyan_c;
elsif x_var >= 300 and x_var < 320 and
y_var >= 200 and y_var < 240 then
color_var := green_c;
else
color_var := black_c;
end if;
end if;
write_data_s <= color_var;
write_addr_s <= conv_std_logic_vector(coordinate, write_addr_s'length);
end process;


--==========================

Next, I should try adding another Bram that will hold on to the objects.  As a small example I must use the coe file that was used to make mario.  Then I will have to use easyBMP to convert more pictures into their bram equivalent.

No comments:

Post a Comment