Project

General

Profile

1009 markw
---------------------------------------------------------------------------
-- (c) 2020 mark watson
-- I am happy for anyone to use this for non-commercial use.
-- If my vhdl files are used commercially or otherwise sold,
-- please contact me for explicit permission at scrameta (gmail).
-- This applies for source and binary form and derived works.
---------------------------------------------------------------------------
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.numeric_std.all;

1036 markw
ENTITY PSG_volume IS
1009 markw
PORT
(
CLK : IN STD_LOGIC;
RESET_N : IN STD_LOGIC;
ENABLE : IN STD_LOGIC;

CHANNEL : IN STD_LOGIC;
FIXED : IN STD_LOGIC_VECTOR(4 downto 0);
1038 markw
ENVELOPE : IN STD_LOGIC_VECTOR(4 downto 0);
1009 markw
1220 markw
VOL_OUT : OUT STD_LOGIC_VECTOR(4 downto 0);
CHANGED : OUT STD_LOGIC
1009 markw
);
1036 markw
END PSG_volume;
1009 markw
1036 markw
ARCHITECTURE vhdl OF PSG_volume IS
1038 markw
signal vol_reg: std_logic_vector(4 downto 0);
signal vol_next: std_logic_vector(4 downto 0);
1220 markw
signal changed_reg: std_logic;
signal changed_next: std_logic;
1009 markw
BEGIN
-- register
process(clk, reset_n)
begin
if (reset_n = '0') then
vol_reg <= (others=>'0');
1220 markw
changed_reg <= '1';
1009 markw
elsif (clk'event and clk='1') then
vol_reg <= vol_next;
1220 markw
changed_reg <= changed_next;
1009 markw
end if;
end process;

-- next state
1220 markw
process(vol_reg,vol_next,enable,channel,fixed,envelope)
1038 markw
variable channelext : std_logic_vector(4 downto 0);
1009 markw
begin
vol_next <= vol_reg;
1220 markw
changed_next <= '0';
if (vol_next /=vol_reg) then
changed_next <= '1';
end if;
1009 markw
if (enable = '1') then
1038 markw
channelext := (others=>channel);
1009 markw
if (fixed(4)='0') then --fixed
1038 markw
vol_next <= fixed(3 downto 0)&fixed(0) and channelext;
1009 markw
else
1038 markw
vol_next <= envelope and channelext;
1009 markw
end if;
end if;
end process;

-- output
vol_out <= vol_reg;
1220 markw
changed <= changed_reg;
1009 markw
END vhdl;