Line 121... |
Line 121... |
signal UseAluTR: std_logic;
|
signal UseAluTR: std_logic;
|
|
|
--control signals
|
--control signals
|
signal InReset: std_logic;
|
signal InReset: std_logic;
|
signal OpAddress: std_logic_vector(15 downto 0); --memory address to use for operation of an instruction
|
signal OpAddress: std_logic_vector(15 downto 0); --memory address to use for operation of an instruction
|
signal OpData: std_logic_vector(15 downto 0); --data to write or will load to here
|
signal OpDataIn: std_logic_vector(15 downto 0);
|
|
signal OpDataOut: std_logic_vector(15 downto 0);
|
signal OpWW: std_logic;
|
signal OpWW: std_logic;
|
signal OpWE: std_logic;
|
signal OpWE: std_logic;
|
|
signal OpDestReg1: std_logic_vector(3 downto 0);
|
|
signal OpUseReg2: std_logic;
|
|
signal OpDestReg2: std_logic_vector(3 downto 0);
|
|
|
--opcode shortcut signals
|
--opcode shortcut signals
|
signal opmain: std_logic_vector(3 downto 0);
|
signal opmain: std_logic_vector(3 downto 0);
|
signal opimmd: std_logic_vector(7 downto 0);
|
signal opimmd: std_logic_vector(7 downto 0);
|
signal opcond1: std_logic; --first conditional bit
|
signal opcond1: std_logic; --first conditional bit
|
Line 147... |
Line 151... |
signal bankreg3: std_logic_vector(3 downto 0);
|
signal bankreg3: std_logic_vector(3 downto 0);
|
signal FetchMemAddr: std_logic_vector(15 downto 0);
|
signal FetchMemAddr: std_logic_vector(15 downto 0);
|
|
|
signal UsuallySS: std_logic_vector(3 downto 0);
|
signal UsuallySS: std_logic_vector(3 downto 0);
|
signal UsuallyDS: std_logic_vector(3 downto 0);
|
signal UsuallyDS: std_logic_vector(3 downto 0);
|
signal aluregisterout: std_logic_vector(3 downto 0);
|
signal AluRegOut: std_logic_vector(3 downto 0);
|
begin
|
begin
|
reg: registerfile port map(
|
reg: registerfile port map(
|
WriteEnable => regWE,
|
WriteEnable => regWE,
|
DataIn => regIn,
|
DataIn => regIn,
|
Clock => Clock,
|
Clock => Clock,
|
Line 190... |
Line 194... |
DataOut => AluOut,
|
DataOut => AluOut,
|
TR => AluTR
|
TR => AluTR
|
);
|
);
|
fetcheraddress <= regIn(REGCS) & regIn(REGIP);
|
fetcheraddress <= regIn(REGCS) & regIn(REGIP);
|
MemAddr <= OpAddress when state=WaitForMemory else FetchMemAddr;
|
MemAddr <= OpAddress when state=WaitForMemory else FetchMemAddr;
|
MemOut <= OpData when (state=WaitForMemory and OpWE='1') else "ZZZZZZZZZZZZZZZZ" when state=HoldMemory else x"0000";
|
MemOut <= OpDataOut when (state=WaitForMemory and OpWE='1') else "ZZZZZZZZZZZZZZZZ" when state=HoldMemory else x"0000";
|
MemWE <= OpWE when state=WaitForMemory else 'Z' when state=HoldMemory else '0';
|
MemWE <= OpWE when state=WaitForMemory else 'Z' when state=HoldMemory else '0';
|
MemWW <= OpWW when state=WaitForMemory else 'Z' when state=HoldMEmory else '0';
|
MemWW <= OpWW when state=WaitForMemory else 'Z' when state=HoldMEmory else '0';
|
OpData <= MemIn when (state=WaitForMemory and OpWE='0') else "ZZZZZZZZZZZZZZZZ";
|
OpDataIn <= MemIn;
|
--opcode shortcuts
|
--opcode shortcuts
|
opmain <= IR(15 downto 12);
|
opmain <= IR(15 downto 12);
|
opimmd <= IR(7 downto 0);
|
opimmd <= IR(7 downto 0);
|
opcond1 <= IR(8);
|
opcond1 <= IR(8);
|
opcond2 <= IR(7);
|
opcond2 <= IR(7);
|
Line 232... |
Line 236... |
CarryCS <= '1';
|
CarryCS <= '1';
|
CarrySS <= '0';
|
CarrySS <= '0';
|
regWE <= (others => '1');
|
regWE <= (others => '1');
|
regIn <= (others => "00000000");
|
regIn <= (others => "00000000");
|
regIn(REGCS) <= x"01";
|
regIn(REGCS) <= x"01";
|
|
regIn(REGSS) <= x"02";
|
IPAddend <= x"00";
|
IPAddend <= x"00";
|
SPAddend <= x"00";
|
SPAddend <= x"00";
|
AluOp <= "10001"; --reset TR in ALU
|
AluOp <= "10001"; --reset TR in ALU
|
regbank <= '0';
|
regbank <= '0';
|
fetchEN <= '1';
|
fetchEN <= '1';
|
OpData <= "ZZZZZZZZZZZZZZZZ";
|
OpDataOut <= "ZZZZZZZZZZZZZZZZ";
|
OpAddress <= x"0000";
|
OpAddress <= x"0000";
|
OpWE <= '0';
|
OpWE <= '0';
|
opWW <= '0';
|
opWW <= '0';
|
TRData <= '0';
|
TRData <= '0';
|
UseAluTR <= '0';
|
UseAluTR <= '0';
|
|
OpDestReg1<= x"0";
|
|
OpDestReg2 <= x"0";
|
|
OpUseReg2 <= '0';
|
--finish up
|
--finish up
|
elsif InReset='1' and reset='0' and Hold='0' then --reset is done, start executing
|
elsif InReset='1' and reset='0' and Hold='0' then --reset is done, start executing
|
InReset <= '0';
|
InReset <= '0';
|
fetchEN <= '1';
|
fetchEN <= '1';
|
state <= FirstFetch1;
|
state <= FirstFetch1;
|
Line 282... |
Line 290... |
elsif state=WaitForMemory then
|
elsif state=WaitForMemory then
|
state <= Execute;
|
state <= Execute;
|
FetchEn <= '1';
|
FetchEn <= '1';
|
IpAddend <= x"02";
|
IpAddend <= x"02";
|
SpAddend <= x"00";
|
SpAddend <= x"00";
|
|
if OpWE='0' then
|
|
regIn(to_integer(unsigned(OpDestReg1))) <= OpDataIn(7 downto 0);
|
|
regWE(to_integer(unsigned(OpDestReg1))) <= '1';
|
|
if OpUseReg2='1' then
|
|
regIn(to_integer(unsigned(OpDestReg2))) <= OpDataIn(15 downto 8);
|
|
regWE(to_integer(unsigned(OpDestReg2))) <= '1';
|
|
end if;
|
|
end if;
|
elsif state=WaitForAlu then
|
elsif state=WaitForAlu then
|
state <= Execute;
|
state <= Execute;
|
regIn(to_integer(unsigned(AluRegisterOut))) <= AluOut;
|
regIn(to_integer(unsigned(AluRegOut))) <= AluOut;
|
regWE(to_integer(unsigned(AluRegisterOut))) <= '1';
|
regWE(to_integer(unsigned(AluRegOut))) <= '1';
|
FetchEN <= '1';
|
FetchEN <= '1';
|
IPAddend <= x"02";
|
IPAddend <= x"02";
|
SPAddend <= x"00";
|
SPAddend <= x"00";
|
end if;
|
end if;
|
|
|
Line 306... |
Line 322... |
regIn(REGCS) <= CSCarryOut;
|
regIn(REGCS) <= CSCarryOut;
|
regIn(REGSP) <= SPCarryOut; --with addend being 0, it'll just write SP to SP so it won't change, but this makes code easier for me
|
regIn(REGSP) <= SPCarryOut; --with addend being 0, it'll just write SP to SP so it won't change, but this makes code easier for me
|
regIn(REGSS) <= SSCarryOut;
|
regIn(REGSS) <= SSCarryOut;
|
regWE(REGSP) <= '1';
|
regWE(REGSP) <= '1';
|
regWE(REGSS) <= '1';
|
regWE(REGSS) <= '1';
|
|
OpUseReg2 <= '0';
|
OpAddress <= "ZZZZZZZZZZZZZZZZ";
|
OpAddress <= "ZZZZZZZZZZZZZZZZ";
|
if UseAluTR='1' then
|
if UseAluTR='1' then
|
UseAluTR<='0';
|
UseAluTR<='0';
|
end if;
|
end if;
|
--actual decoding
|
--actual decoding
|
Line 319... |
Line 336... |
regIn(to_integer(unsigned(bankreg1))) <= opimmd;
|
regIn(to_integer(unsigned(bankreg1))) <= opimmd;
|
regWE(to_integer(unsigned(bankreg1))) <= '1';
|
regWE(to_integer(unsigned(bankreg1))) <= '1';
|
when "0001" => --mov [reg],imm
|
when "0001" => --mov [reg],imm
|
OpAddress <= regOut(REGDS) & regOut(to_integer(unsigned(bankreg1)));
|
OpAddress <= regOut(REGDS) & regOut(to_integer(unsigned(bankreg1)));
|
OpWE <= '1';
|
OpWE <= '1';
|
OpData <= x"00" & opimmd;
|
OpDataOut <= x"00" & opimmd;
|
OpWW <= '0';
|
OpWW <= '0';
|
state <= WaitForMemory;
|
state <= WaitForMemory;
|
IPAddend <= x"00"; --disable all this because we have to wait a cycle to write memory
|
IPAddend <= x"00"; --disable all this because we have to wait a cycle to write memory
|
FetchEN <= '0';
|
FetchEN <= '0';
|
when "0011" => --group 3 comparisons
|
when "0011" => --group 3 comparisons
|
Line 338... |
Line 355... |
FetchEN <= '0';
|
FetchEN <= '0';
|
IPAddend <= x"00";
|
IPAddend <= x"00";
|
AluOp <= "00" & opreg3; --nothing hard here, ALU does it all for us
|
AluOp <= "00" & opreg3; --nothing hard here, ALU does it all for us
|
AluIn1 <= regOut(to_integer(unsigned(bankreg1)));
|
AluIn1 <= regOut(to_integer(unsigned(bankreg1)));
|
AluIn2 <= regOut(to_integer(unsigned(bankreg2)));
|
AluIn2 <= regOut(to_integer(unsigned(bankreg2)));
|
AluRegisterOut <= bankreg1;
|
AluRegOut <= bankreg1;
|
--regIn(to_integer(unsigned(bankreg1))) <= AluOut;
|
--regIn(to_integer(unsigned(bankreg1))) <= AluOut;
|
--regWE(to_integer(unsigned(bankreg1))) <= '1';
|
--regWE(to_integer(unsigned(bankreg1))) <= '1';
|
when "0101" => --group 5
|
when "0101" => --group 5
|
case opreg3 is
|
case opreg3 is
|
when "000" => --subgroup 5-0
|
when "000" => --subgroup 5-0
|
case opreg2 is
|
case opreg2 is
|
when "000" => --push reg
|
when "000" => --push reg
|
SpAddend <= x"02"; --set SP to increment
|
SpAddend <= x"02"; --set SP to increment
|
OpAddress <= regOut(to_integer(unsigned(UsuallySS))) & regOut(REGSP);
|
OpAddress <= regOut(to_integer(unsigned(UsuallySS))) & regOut(REGSP);
|
OpWE <= '1';
|
OpWE <= '1';
|
OpData <= x"00" & regOut(to_integer(unsigned(bankreg1)));
|
OpDataOut <= x"00" & regOut(to_integer(unsigned(bankreg1)));
|
OpWW <= '1';
|
OpWW <= '1';
|
state <= WaitForMemory;
|
state <= WaitForMemory;
|
IPAddend <= x"00";
|
IPAddend <= x"00";
|
FetchEN <= '0';
|
FetchEN <= '0';
|
when "001" => --pop reg
|
when "001" => --pop reg
|
SPAddend <= x"FE"; --set SP to decrement
|
SPAddend <= x"FE"; --set SP to decrement
|
OpAddress <= regOut(to_integer(unsigned(UsuallySS))) & regOut(REGSP);
|
OpAddress <= regOut(to_integer(unsigned(UsuallySS))) & regOut(REGSP);
|
OpWE <= '0';
|
OpWE <= '0';
|
regIn(to_integer(unsigned(bankreg1))) <= OpData(7 downto 0);
|
OpDestReg1 <= bankreg1;
|
|
--regIn(to_integer(unsigned(bankreg1))) <= OpData(7 downto 0);
|
OpWW <= '0';
|
OpWW <= '0';
|
state <= WaitForMemory;
|
state <= WaitForMemory;
|
IPAddend <= x"00";
|
IPAddend <= x"00";
|
FetchEN <= '0';
|
FetchEN <= '0';
|
when others =>
|
when others =>
|