Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- use IEEE.STD_LOGIC_UNSIGNED.ALL;
- ---- Uncomment the following library declaration if instantiating
- ---- any Xilinx primitives in this code.
- --library UNISIM;
- --use UNISIM.VComponents.all;
- entity vga_text is
- Port ( clk : in STD_LOGIC;
- iowr : in STD_LOGIC;
- addr : in STD_LOGIC_VECTOR (31 downto 0);
- data : in STD_LOGIC_VECTOR (31 downto 0);
- r : out STD_LOGIC;
- g : out STD_LOGIC;
- b : out STD_LOGIC;
- vga_blank : out STD_LOGIC;
- vsync : out STD_LOGIC;
- hsync : out STD_LOGIC;
- dout: out std_logic_vector(31 downto 0));
- end vga_text;
- architecture Behavioral of vga_text is
- -- Symbols format
- -- 7 6 5 4 3 2 1 0
- -- 15 14 13 12 11 10 9 8
- -- 23 22 21 20 19 18 17 16
- -- 31 30 29 28 27 26 25 24
- -- 39 38 37 36 35 34 33 32
- -- ...
- -- 127 126 125 124 123 122 121 120
- signal SAddrA: std_logic_vector(7 downto 0);
- signal SAddrRead, SAddrWrite: integer range 0 to 255;
- signal SDataA, SDinA: std_logic_vector(127 downto 0);
- signal SWeA: std_logic;
- type TScreen is array (0 to 1999) of std_logic_vector(17 downto 0);
- signal Screen: TScreen;
- signal scrAddrA, scrAddrB: integer range 0 to 1999;
- signal scrDataA, scrDataB, scrDinB: std_logic_vector(17 downto 0);
- signal scrWeB: std_logic;
- type TColor is array (0 to 31) of std_logic_vector(23 downto 0);
- signal PalleteColor: TColor :=
- (
- 0 => x"000000",
- 1 => x"0000FF",
- 2 => x"00FF00",
- 3 => x"00FFFF",
- 4 => x"FF0000",
- 5 => x"FF00FF",
- 6 => x"FFFF00",
- 7 => x"FFFFFF",
- others => x"FFFFFF"
- );
- signal PalleteAddr: integer range 0 to 31;
- signal VCounter : integer range 0 to 520 := 0;
- signal HCounter : integer range 0 to 800 := 0;
- signal div : std_logic := '0';
- signal scrX, scrX_new: std_logic_vector(9 downto 0);
- signal scrY, scrY_new: std_logic_vector(9 downto 0);
- signal textX: integer range 0 to 79;
- signal textX2: integer range 0 to 79;
- signal textY: integer range 0 to 24;
- signal SymbolPoint: integer range 0 to 127;
- signal curColor: std_logic_vector(23 downto 0);
- signal r_in, g_in, b_in: std_logic_vector(7 downto 0);
- signal GotoX: integer range 0 to 79;
- signal GotoY: integer range 0 to 24;
- signal Color, BgColor: std_logic_vector(4 downto 0);
- signal isLowLevel: std_logic;
- signal scrAddrBLowLevel, scrAddrBNormal: integer range 0 to 1999;
- signal scrDinBLowLevel, scrDinBNormal: std_logic_vector(17 downto 0);
- signal scrWebLowLevel, scrWebNormal: std_logic;
- signal scrData: std_logic_vector(17 downto 0);
- signal SymbolX: std_logic_vector(2 downto 0);
- signal SymbolY: std_logic_vector(3 downto 0);
- signal selector: std_logic_vector(31 downto 0);
- signal isCaretPos: std_logic;
- signal isLowLinePosB, isLowLinePos: std_logic;
- signal isVertLinePosB, isVertLinePos: std_logic;
- -- cursor settings
- signal isLowLine: std_logic := '1';
- signal isBlackSquare: std_logic := '0';
- signal isBlinking: std_logic := '1';
- signal isVertLine: std_logic := '0';
- signal timeCount: std_logic_vector(31 downto 0) := (others => '0');
- signal blinkTotal: std_logic_vector(31 downto 0) := conv_std_logic_vector(50000000, 32);
- signal blinkOff: std_logic_vector(31 downto 0) := conv_std_logic_vector(25000000, 32);
- signal caretColor: std_logic_vector(23 downto 0) := x"00FF00";
- signal NewSymbol: std_logic_vector(127 downto 0);
- component vga640_symbols
- port (
- addr: IN std_logic_VECTOR(7 downto 0);
- clk: IN std_logic;
- din: IN std_logic_VECTOR(127 downto 0);
- dout: OUT std_logic_VECTOR(127 downto 0);
- we: IN std_logic);
- end component;
- begin
- process(clk)
- begin
- if rising_edge(clk) then
- if timeCount > blinkTotal then
- timeCount <= (others => '0');
- else
- timeCount <= timeCount + 1;
- end if;
- end if;
- end process;
- vga640_symbols_0: vga640_symbols
- Port map(
- addr => SAddrA,
- clk => clk,
- din => NewSymbol,
- dout => SDataA,
- we => SWeA
- );
- SWeA <= '1' when conv_integer(addr) = 337 and iowr = '1' else '0';
- SAddrA <= conv_std_logic_vector(SAddrWrite, 8) when SWeA = '1' else conv_std_logic_vector(SAddrRead, 8);
- process(clk)
- begin
- if rising_edge(clk) then
- if scrWeB = '1' then
- Screen(scrAddrB) <= scrDinB;
- end if;
- scrDataA <= Screen(scrAddrA);
- scrDataB <= Screen(scrAddrB);
- end if;
- end process;
- scrDinB <= scrDinBLowLevel when isLowLevel = '1' else scrDinBNormal;
- scrWeb <= scrWeBLowLevel when isLowLevel = '1' else scrWebNormal;
- scrAddrB <= scrAddrBLowLevel when isLowLevel = '1' else scrAddrBNormal;
- scrDinBLowLevel <= data(17 downto 0);
- scrWeBLowLevel <= '1' when (conv_integer(addr) = 300 or conv_integer(addr) = 309) and iowr = '1' else '0';
- scrAddrBNormal <= GotoY * 80 + GotoX;
- scrDiNBNormal <= BgColor & Color & data(7 downto 0);
- scrWebNormal <= '1' when conv_integer(addr) = 306 and iowr = '1' else '0';
- process(clk)
- begin
- if rising_edge(clk) then
- div <= not(div);
- if div = '1' then
- if HCounter = 799 then
- HCounter <= 0;
- if VCounter = 520 then
- VCounter <= 0;
- else
- VCounter <= VCounter + 1;
- end if;
- else
- HCounter <= HCounter + 1;
- end if;
- end if;
- end if;
- end process;
- process(clk)
- begin
- if rising_edge(clk) then
- if div = '1' then
- -- 1
- scrX <= conv_std_logic_vector(HCounter - 139, 10);
- scrY <= conv_std_logic_vector(VCounter - 70 , 10);
- -- 2
- textX <= conv_integer(scrX(9 downto 3));
- textY <= conv_integer(scrY(9 downto 4));
- SymbolX <= scrX(2 downto 0) - 1;
- SymbolY <= scrY(3 downto 0);
- -- 3
- if SymbolY > 13 then
- isLowLinePosB <= '1';
- else
- isLowLinePosB <= '0';
- end if;
- if SymbolX < 2 then
- isVertLinePosB <= '1';
- else
- isVertLinePosB <= '0';
- end if;
- scrAddrA <= textY * 80 + textX;
- SymbolPoint <= conv_integer(SymbolY) * 8 + 7 - conv_integer(SymbolX);
- -- 4
- SAddrRead <= conv_integer(scrDataA(7 downto 0));
- scrData <= scrDataA;
- isLowLinePos <= isLowLinePosB;
- isVertLinePos <= isVertLinePosB;
- if scrAddrA = GotoY * 80 + GotoX then
- isCaretPos <= '1';
- else
- isCaretPos <= '0';
- end if;
- -- 5
- if (VCounter > 69) and (VCounter < 470) then
- if isCaretPos = '1' then
- if (isBlackSquare = '1' and isBlinking = '0') or
- (isBlackSquare = '1' and isBlinking = '1' and timeCount < blinkOff) or
- (isVertLine = '1' and isVertLinePos = '1' and isBlinking = '1' and timeCount < blinkOff) or
- (isLowLine = '1' and isLowLinePos = '1' and isBlinking = '1' and timeCount < blinkOff) then
- curColor <= caretColor;
- else
- if SDataA(SymbolPoint) = '1' then
- curColor <= PalleteColor(conv_integer(scrData(12 downto 8)));
- else
- curColor <= PalleteColor(conv_integer(scrData(17 downto 13)));
- end if;
- end if;
- else
- if SDataA(SymbolPoint) = '1' then
- curColor <= PalleteColor(conv_integer(scrData(12 downto 8)));
- else
- curColor <= PalleteColor(conv_integer(scrData(17 downto 13)));
- end if;
- end if;
- else
- curColor <= x"000000";
- end if;
- end if;
- end if;
- end process;
- process(clk)
- begin
- if rising_edge(clk) then
- if conv_integer(addr) = 301 and iowr = '1' then scrAddrBLowLevel <= conv_integer(data(10 downto 0)); end if;
- if conv_integer(addr) = 302 and iowr = '1' then
- if conv_integer(data) > 79 then
- GotoX <= 0;
- else
- GotoX <= conv_integer(data);
- end if;
- end if;
- if conv_integer(addr) = 303 and iowr = '1' then
- if conv_integer(data) > 24 then
- GotoY <= 0;
- else
- GotoY <= conv_integer(data);
- end if;
- end if;
- if conv_integer(addr) = 304 and iowr = '1' then Color <= data(4 downto 0); end if;
- if conv_integer(addr) = 305 and iowr = '1' then BgColor <= data(4 downto 0); end if;
- if conv_integer(addr) = 306 and iowr = '1' then
- if GotoX = 79 then
- if GotoY = 24 then
- GotoY <= 0;
- else
- GotoY <= GotoY + 1;
- end if;
- GotoX <= 0;
- else
- GotoX <= GotoX + 1;
- end if;
- end if;
- if conv_integer(addr) = 307 and iowr = '1' then isLowLevel <= data(0); end if;
- if conv_integer(addr) = 308 and iowr = '1' then
- GotoX <= 0;
- if GotoY = 24 then
- GotoY <= 0;
- else
- GotoY <= GotoY + 1;
- end if;
- end if;
- if conv_integer(addr) = 309 and iowr = '1' then
- if scrAddrBLowLevel = 1999 then
- scrAddrBLowLevel <= 0;
- else
- scrAddrBLowLevel <= scrAddrBLowLevel + 1;
- end if;
- end if;
- if conv_integer(addr) = 310 and iowr = '1' then
- isLowLine <= data(0);
- isBlackSquare <= data(1);
- isBlinking <= data(2);
- isVertLine <= data(3);
- end if;
- if conv_integer(addr) = 311 and iowr = '1' then
- isLowLine <= data(0);
- end if;
- if conv_integer(addr) = 312 and iowr = '1' then
- isBlackSquare <= data(0);
- end if;
- if conv_integer(addr) = 313 and iowr = '1' then
- isBlinking <= data(0);
- end if;
- if conv_integer(addr) = 314 and iowr = '1' then
- isVertLine <= data(0);
- end if;
- if conv_integer(addr) = 320 and iowr = '1' then
- caretColor <= data(23 downto 0);
- end if;
- if conv_integer(addr) = 321 and iowr = '1' then
- blinkTotal <= data;
- end if;
- if conv_integer(addr) = 322 and iowr = '1' then
- blinkOff <= data;
- end if;
- if conv_integer(addr) = 330 and iowr = '1' then
- PalleteAddr <= conv_integer(data(4 downto 0));
- end if;
- if conv_integer(addr) = 331 and iowr = '1' then
- PalleteColor(PalleteAddr) <= data(23 downto 0);
- end if;
- if conv_integer(addr) = 335 and iowr = '1' then
- SAddrWrite <= conv_integer(data(7 downto 0));
- end if;
- -- 337 - for write symbol
- for i in 0 to 3 loop
- if conv_integer(addr) = 340 + i and iowr = '1' then
- NewSymbol((i + 1) * 32 - 1 downto i * 32) <= data(31 downto 0);
- end if;
- end loop;
- end if;
- end process;
- b_in <= curColor(23 downto 16) when ((HCounter > 143) and (HCounter < 784) and (VCounter > 30) and (VCounter < 511)) else "00000000";
- g_in <= curColor(15 downto 8) when ((HCounter > 143) and (HCounter < 784) and (VCounter > 30) and (VCounter < 511)) else "00000000";
- r_in <= curColor( 7 downto 0) when ((HCounter > 143) and (HCounter < 784) and (VCounter > 30) and (VCounter < 511)) else "00000000";
- b <= b_in(7);
- g <= g_in(7);
- r <= r_in(7);
- vsync <= '0' when VCounter < 2 else '1';
- hsync <= '0' when HCounter < 96 else '1';
- vga_blank <= '1' when ((HCounter > 143) and (HCounter < 784) and (VCounter > 30) and (VCounter < 511)) else '0';
- with conv_integer(addr) select
- dout <= "00000000000000" & scrDataB when 300,
- (others => 'Z') when others;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement