Код:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity spectrum is
port(
clock_14: in std_logic;
clock_cpu: out std_logic;
CSync: out std_logic;
R: out std_logic;
G: out std_logic;
B: out std_logic;
Y: out std_logic;
VRD: out std_logic;
VWR: out std_logic;
VCS: out std_logic;
VA: out std_logic_vector (13 downto 0);
VD: inout std_logic_vector (7 downto 0);
D: inout std_logic_vector (7 downto 0);
RD: in std_logic;
WR: in std_logic;
A: in std_logic_vector (15 downto 0);
IOREQ: in std_logic;
MREQ: in std_logic;
ROM: out std_logic;
RAM: out std_logic;
VRAM: buffer std_logic;
CPU_ACC: out std_logic;
Spkr: out std_logic;
Wait1: out std_logic;
INT: out std_logic;
Key: in std_logic_vector (4 downto 0)
);
end spectrum;
architecture spectrum_arch of spectrum is
signal HSync: std_logic;
signal VSync: std_logic;
signal clock_count: std_logic_vector (1 downto 0); -- clock_count(0) - pixel_clock (7 MHz), clock_count(1) - cpu_clock (3,5 MHz)
signal pixel_clock: std_logic;
signal H_count: std_logic_vector (8 downto 0);
signal V_count: std_logic_vector (8 downto 0);
signal Blank: std_logic;
signal Border: std_logic;
---------------------------------------------------
signal Flash_count: std_logic_vector (4 downto 0); --!!!!!!!!!!!!!!!!!!!!!!!!
---------------------------------------------------
signal Pix_adr: std_logic_vector (13 downto 0);
signal Atr_adr: std_logic_vector (13 downto 0);
signal Pix_reg0: std_logic_vector (7 downto 0);
signal Atr_reg0: std_logic_vector (7 downto 0);
signal Pix_reg1: std_logic_vector (7 downto 0);
signal Atr_reg1: std_logic_vector (7 downto 0);
signal Pix: std_logic;
signal Port_FE: std_logic_vector (7 downto 0);
signal IOWR: std_logic;
signal IORD: std_logic;
signal V_ACC: std_logic;
begin
clock_cpu <= clock_count(1);
pixel_clock <= clock_count(0);
CSync <= not (HSync xor VSync);
D <= VD when (V_ACC = '1' and VRAM = '0' and RD = '0') else "ZZZZZZZZ";
VD <= D when (V_ACC = '1' and VRAM = '0' and WR = '0') else "ZZZZZZZZ";
Port_FE <= D when (IOWR'event and IOWR = '0');
D(4 downto 0) <= Key when (IORD = '0') else "ZZZZZ";
CPU_ACC <= '0' when (V_ACC = '1') else '1';
VRD <= '0' when (V_ACC = '0') else RD;
VWR <= '0' when (V_ACC = '1' and VRAM = '0' and WR = '0') else '1';
VCS <= '0' when (V_ACC = '0') else VRAM;
ROM <= '0' when (A(15) = '0' and A(14) = '0' and MREQ = '0') else '1';
VRAM <= '0' when (A(15) = '0' and A(14) = '1' and MREQ = '0') else '1';
RAM <= '0' when (A(15) = '1' and MREQ = '0') else '1';
IORD <= '0' when (RD = '0' and A(0) = '0' and IOREQ = '0') else '1';
IOWR <= '0' when (WR = '0' and A(0) = '0' and IOREQ = '0') else '1';
Spkr <= Port_FE(4);
INT <= '0' when (V_count = 249 and (H_count >= 316 and H_count < 388)) else '1';
process (H_count(2 downto 1), pixel_clock)
begin
if (pixel_clock'event and pixel_clock = '1') then
if H_count(2 downto 1) = "00" then
V_ACC <= '0';
Wait1 <= '0';
else
V_ACC <= '1';
Wait1 <= '1';
end if;
end if;
end process;
--clock_count
process (clock_14)
begin
if (clock_14'event and clock_14 = '0') then
clock_count <= clock_count + 1;
end if;
end process;
--H_count
process (pixel_clock)
begin
if (pixel_clock'event and pixel_clock = '0') then
if H_count < 448 then
H_count <= H_count + 1;
else
H_count <= "000000000";
end if;
end if;
end process;
--HSync
process (pixel_clock, H_count)
begin
if (pixel_clock'event and pixel_clock = '0') then
if (H_count >= 304 and H_count < 332) then --331
HSync <= '0';
else
Hsync <= '1';
end if;
end if;
end process;
--V_count
process (HSync)
begin
if (HSync'event and HSync = '1') then
if (V_count < 312) then
V_count <= V_count + 1;
else
V_count <= "000000000";
end if;
end if;
end process;
--VSync
process (pixel_clock, V_count)
begin
if (pixel_clock'event and pixel_clock = '0') then
if (V_count >= 248 and V_count < 255) then
VSync <= '0';
else
Vsync <= '1';
end if;
end if;
end process;
--Flash
process (Vsync)
begin
if (Vsync'event and Vsync = '1') then
Flash_count <= Flash_count + 1;
end if;
end process;
--Blank
process (pixel_clock, V_count, Vsync)
begin
if (pixel_clock'event and pixel_clock = '0') then
if (H_count >= 304 and H_count < 399) or Vsync = '0' then
Blank <= '1';
else
Blank <= '0';
end if;
end if;
end process;
--Border
process (pixel_clock, V_count, H_count)
begin
if (pixel_clock'event and pixel_clock = '0') then
if (H_count >= 256 and H_count < 448) or (V_count >= 192 and V_count < 312) then
Border <= '1';
else
Border <= '0';
end if;
end if;
end process;
--
process (H_count, V_count, V_ACC, Pix_adr, Atr_adr, A(13 downto 0))
begin
if (V_ACC = '0') then
case H_count(0) is
when '0' => VA <= "0" & V_count(7 downto 6) & V_count(2 downto 0) & V_count(5 downto 3) & H_count(7 downto 3);
when '1' => VA <= "0110" & V_count(7 downto 3) & H_count(7 downto 3);
end case;
else VA <= A(13 downto 0);
end if;
end process;
--Load Pixel byte
process (H_count, Pix_adr, VD, pixel_clock)
begin
if (H_count(2 downto 0) = "000") then
if (pixel_clock'event and pixel_clock = '0') then
Pix_reg0 <= VD;
end if;
end if;
end process;
--Load Atribute byte
process (H_count, Atr_adr, VD, pixel_clock)
begin
if (pixel_clock'event and pixel_clock = '0') then
if (H_count(2 downto 0) = "001") then
Atr_reg0 <= VD;
end if;
end if;
end process;
--
process (H_count, pixel_clock)
begin
if (pixel_clock'event and pixel_clock = '0') then
if (H_count(2 downto 0) = "111" ) then
Pix_reg1 <= Pix_reg0;
Atr_reg1 <= Atr_reg0;
end if;
end if;
end process;
--Pixel shift
process (H_count(2 downto 0), Pix_reg1)
begin
case H_count(2 downto 0) is
when "000" => Pix <= Pix_reg1(7);
when "001" => Pix <= Pix_reg1(6);
when "010" => Pix <= Pix_reg1(5);
when "011" => Pix <= Pix_reg1(4);
when "100" => Pix <= Pix_reg1(3);
when "101" => Pix <= Pix_reg1(2);
when "110" => Pix <= Pix_reg1(1);
when "111" => Pix <= Pix_reg1(0);
end case;
end process;
--RGB Out
process (pixel_clock, Border, Blank)
begin
if (pixel_clock'event and pixel_clock = '1') then
if (Blank = '0') then
if (Border = '0') then
if ((Flash_count(4) and Atr_reg1(7)) xor Pix) = '1' then
B <= Atr_reg1(0);
R <= Atr_reg1(1);
G <= Atr_reg1(2);
Y <= Atr_reg1(6);
else
B <= Atr_reg1(3);
R <= Atr_reg1(4);
G <= Atr_reg1(5);
Y <= Atr_reg1(6);
end if;
else
B <= Port_FE(0);
R <= Port_FE(1);
G <= Port_FE(2);
end if;
else
B <= '0';
R <= '0';
G <= '0';
end if;
end if;
end process;
end spectrum_arch;