--************************************************--
--**      Dekoder NZVC bitu pro MC Mazard       **--
--**   Autor: Leos Marsalek    (c) 2002-2003    **--
--**     E-mail: Leos.Marsalek@tiscali.cz       **--
--**      Spolupracovali : Lukas Vaculík,       **--
--**              Miroslav Copian               **--
--************************************************--

library IEEE; -- Zviditelneni knihovny
use IEEE.std_logic_1164.all; -- Vyuziti knihovny

entity dekoder_NZVC is 
    
port(D,A,B,IR:in STD_logic_vector15 downto 0);Carry:in STD_logic;PSW:out STD_LOGIC_vector(15 downto 0));
end;

Architecture DekNZVC of dekoder_nzvc is   -- Architektura entity

Alias instr:STD_LOGIC_vector (downto 0is IR(15 downto 12);
Alias subinstr:STD_LOGIC_vector(downto 0is IR(11 downto 6);
Alias C:Std_logic is PSW(15);
Alias Z:Std_logic is PSW (14);
Alias N:STD_logic is PSw(13);
Alias V:STD_Logic is PSW (12);
begin 
    
det
:process (A(15),B(15),D,IR,Carry)                        -- vlastni proces dekodovani NZVC bitù
        
begin   
            
N
<=D(15);
            
if d="0000000000000000" then
                Z
<='1';
            
else
                
Z
<='0';
            
end if;
            
case instr is 
   
-----------------------------------------------------------------------------------------
            
when "1100" =>         --subb
                    
C<=not carry;  
                    
if (A(15)='0' and B(15)='1' and D(15)='1'
                        
or ((A(15)='1' and B(15)='0' and D(15)='0')) then
                        V
<='1';
                    
else
                        
V
<='0';    
                    
end if;
            
When "0000" =>
                    
case subinstr is
   
---------------------------------------------------------------------------------------
                    
when "111100" =>      --dec
                            
C<=not carry;
                            
if (A(15)='0' and B(15)='1' and D(15)='1'
                                
or ((A(15)='1' and B(15)='0' and D(15)='0')) then
                                V
<='1';
                            
else
                                
V
<='0';    
                            
end if
              
--------------------------------------------
                    
When "111111" =>  -- inc
                            
if (A(15)='0' and B(15)='0' and D(15)='1'
                            
or ((A(15)='1' and B(15)='1' and D(15)='0')) then
                                V
<='1';
                            
else
                                
V
<='0';    
                            
end if;           
             
-------------------------------------
                    
when others => c<=carry;
                    
end case;
     
---------------------------------------------------------------------------------------
            
when "1011" =>        -- compare
                    
C<=not carry
                    
if (A(15)='0' and B(15)='1' and D(15)='1'
                        
or ((A(15)='1' and B(15)='0' and D(15)='0')) then
                        V
<='1';
                    
else
                        
V
<='0';    
                    
end if;       
     
---------------------------------------------------------------------------------------
            
when "1101" =>       -- addc
                    
if (A(15)='0' and B(15)='0' and D(15)='1'
                        
or ((A(15)='1' and B(15)='1' and D(15)='0')) then
                        V
<='1';
                    
else
                        
V
<='0';    
                    
end if;       
      
-------------------------------------------------------------------------------------
            
when others => C<=carry;
            
end case
        
end process det;
end dekNZVC;