From b29dcf610d657777a92f7d85c00d772cdd7c73cb Mon Sep 17 00:00:00 2001 From: Richard Widen Date: Mon, 23 Apr 2012 15:05:01 +0200 Subject: [PATCH] Ritar perfekt, lagt till fforsta kod for sprites --- FirstGraphicTest.vhd | 37 ++++++++++++++++++++++++++++++------- GraphicsPicker.vhd | 33 ++++++++++++++++++++++++--------- sraknare.vhd | 8 ++++---- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/FirstGraphicTest.vhd b/FirstGraphicTest.vhd index 389e215..f3a88cc 100644 --- a/FirstGraphicTest.vhd +++ b/FirstGraphicTest.vhd @@ -54,8 +54,8 @@ architecture Behavioral of FirstGraphicTest is spriteVgaRed: in std_logic_vector(2 downto 0); spriteVgaGreen: in std_logic_vector(2 downto 0); spriteVgaBlue: in std_logic_vector(2 downto 1); - y : in integer range 0 to 521; - x : in integer range 0 to 800; + y : in integer range 0 to 520; + x : in integer range 0 to 799; vgaRed: OUT std_logic_vector(2 downto 0); vgaGreen: OUT std_logic_vector(2 downto 0); vgaBlue: OUT std_logic_vector(2 downto 1) @@ -68,10 +68,23 @@ architecture Behavioral of FirstGraphicTest is rst : IN std_logic; vsynk : OUT std_logic; hsynk : OUT std_logic; - y : inout integer range 0 to 521; - x : inout integer range 0 to 800 + y : inout integer range 0 to 520; + x : inout integer range 0 to 799 ); END COMPONENT; + + COMPONENT SpriteGpu + PORT( clk : in STD_LOGIC; + x : in integer; + y : in integer; + spriteVgaRed: out std_logic_vector(2 downto 0); + spriteVgaGreen: out std_logic_vector(2 downto 0); + spriteVgaBlue: out std_logic_vector(2 downto 1); + collision: out std_logic; + rst : in STD_LOGIC); + + END COMPONENT; + --Inputs @@ -84,8 +97,8 @@ architecture Behavioral of FirstGraphicTest is signal spriteVgaGreen: std_logic_vector(2 downto 0) := (others => '1'); signal spriteVgaBlue: std_logic_vector(2 downto 1) := (others => '0'); - signal y : integer range 0 to 521 := 0 ; - signal x : integer range 0 to 800 := 0 ; + signal y : integer range 0 to 520 := 0 ; + signal x : integer range 0 to 799 := 0 ; @@ -95,6 +108,7 @@ architecture Behavioral of FirstGraphicTest is -- Clock period definitions constant clk_period : time := 1 ns; signal resetcounter : integer range 0 to 20 :=0; + signal collision : std_logic; begin picker: GraphicsPicker PORT MAP ( clk => clk, @@ -119,7 +133,16 @@ begin x => x, y => y ); - + gpu: SpriteGpu PORT MAP ( + clk => clk, + rst => rst, + x => x, + y => y, + spriteVgaRed=> spriteVgaRed, + spriteVgaGreen=> spriteVgaGreen, + spriteVgaBlue=> spriteVgaBlue, + collision=> collision + ); clk_process :process begin diff --git a/GraphicsPicker.vhd b/GraphicsPicker.vhd index 2830574..aad8376 100644 --- a/GraphicsPicker.vhd +++ b/GraphicsPicker.vhd @@ -40,8 +40,8 @@ entity GraphicsPicker is spriteVgaRed: in std_logic_vector(2 downto 0); spriteVgaGreen: in std_logic_vector(2 downto 0); spriteVgaBlue: in std_logic_vector(2 downto 1); - y : in integer range 0 to 521; - x : in integer range 0 to 800; + y : in integer range 0 to 520; + x : in integer range 0 to 799; vgaRed: OUT std_logic_vector(2 downto 0); vgaGreen: OUT std_logic_vector(2 downto 0); vgaBlue: OUT std_logic_vector(2 downto 1) @@ -49,19 +49,34 @@ entity GraphicsPicker is end GraphicsPicker; architecture Behavioral of GraphicsPicker is +signal whiteVgaRed: std_logic_vector(2 downto 0) := "111"; +signal whiteVgaGreen: std_logic_vector(2 downto 0) := "000"; +signal whiteVgaBlue: std_logic_vector(2 downto 1) := "00"; +signal blackVgaRed: std_logic_vector(2 downto 0) := "000"; +signal blackVgaGreen: std_logic_vector(2 downto 0) := "000"; +signal blackVgaBlue: std_logic_vector(2 downto 1) := "11"; begin + process(clk) begin if rising_edge(clk) then - if y>200 and x>200 then - vgaRed<=spriteVgaRed; - vgaGreen<=spriteVgaGreen; - vgaBlue<=spriteVgaBlue; + if y>200 and y<480 then + if x<640 then + vgaRed<=spriteVgaRed; + vgaGreen<=spriteVgaGreen; + vgaBlue<=spriteVgaBlue; + end if; + elsif y<=200 then + if x<640 then + vgaRed<=tileVgaRed; + vgaGreen<=tileVgaGreen; + vgaBlue<=tileVgaBlue; + end if; else - vgaRed<=tileVgaRed; - vgaGreen<=tileVgaGreen; - vgaBlue<=tileVgaBlue; + vgaRed<="000"; + vgaGreen<="000"; + vgaBlue<="00"; end if; end if; end process; diff --git a/sraknare.vhd b/sraknare.vhd index 899cfc8..0a41c6f 100644 --- a/sraknare.vhd +++ b/sraknare.vhd @@ -33,8 +33,8 @@ rst : in STD_LOGIC; vsynk : out STD_LOGIC; hsynk : out STD_LOGIC; - y : inout integer range 0 to 521; - x : inout integer range 0 to 800 + y : inout integer range 0 to 520; + x : inout integer range 0 to 799 ); end sraknare; architecture Behavioral of sraknare is @@ -60,9 +60,9 @@ else counter <= 3; else counter <= 0; - if x=800 then --800 + if x=799 then --800 x<=0; --0 - if y=521 then --521 + if y=520 then --521 y<=0; --0 else y<=y + 1;