signal arith_reg_in : std_logic_vector (dsize - 1 downto 0);
signal arith_reg : std_logic_vector (dsize - 1 downto 0);
-signal arith_buf_we : std_logic;
begin
----------------------------------------
-- arithmatic operation instances ----
----------------------------------------
- arith_buf : d_flip_flop generic map (dsize)
- port map(clk, '1', '1', arith_buf_we, arith_reg_in, arith_reg);
+-- arith_buf : d_flip_flop generic map (dsize)
+-- port map(clk, '1', '1', arith_buf_we, arith_reg_in, arith_reg);
alu_inst : alu_core generic map (dsize)
port map (sel, d1, d2, d_out, c_in, n, z, c, v);
use ieee.std_logic_textio.all;
variable out_l : line;
begin
- write(out_l, msg);
- writeline(output, out_l);
+-- write(out_l, msg);
+-- writeline(output, out_l);
end procedure;
+procedure set_nz is
+begin
+ negative <= n;
+ zero <= z;
+end procedure;
+
begin
if (pcl_inc_n = '0') then
-------------------------------
if (arith_en_n = '0') then
- arith_buf_we <= '0';
-
if instruction = conv_std_logic_vector(16#ca#, dsize) then
--d_print("dex");
sel <= ALU_DEC;
d1 <= index_bus;
- c_in <= '0';
-
- negative <= n;
- zero <= z;
+ set_nz;
output_d_bus;
elsif instruction = conv_std_logic_vector(16#88#, dsize) then
--d_print("dey");
sel <= ALU_DEC;
d1 <= index_bus;
- c_in <= '0';
-
- negative <= n;
- zero <= z;
+ set_nz;
output_d_bus;
elsif instruction = conv_std_logic_vector(16#e8#, dsize) then
--d_print("inx");
sel <= ALU_INC;
d1 <= index_bus;
- c_in <= '0';
-
- negative <= n;
- zero <= z;
+ set_nz;
output_d_bus;
elsif instruction = conv_std_logic_vector(16#c8#, dsize) then
sel <= ALU_CMP;
d1 <= acc_out;
d2 <= int_d_bus;
- negative <= n;
- zero <= z;
+ set_nz;
carry_out <= c;
elsif instruction (7 downto 5) = "111" then
elsif instruction (1 downto 0) = "00" then
if instruction (7 downto 5) = "001" then
d_print("bit");
+ sel <= ALU_BIT;
+ d1 <= acc_out;
+ d2 <= int_d_bus;
+ set_nz;
+ overflow <= v;
elsif instruction (7 downto 5) = "110" then
- d_print("cpy");
+ --d_print("cpy");
+ sel <= ALU_CMP;
+ d1 <= index_bus;
+ d2 <= int_d_bus;
+ set_nz;
+ carry_out <= c;
+
elsif instruction (7 downto 5) = "111" then
-- d_print("cpx");
sel <= ALU_CMP;
d1 <= index_bus;
d2 <= int_d_bus;
- negative <= n;
- zero <= z;
+ set_nz;
carry_out <= c;
end if; --if instruction (7 downto 5) = "001" then
end if; --if instruction = conv_std_logic_vector(16#ca#, dsize)
else
- arith_buf_we <= '1';
+
end if; -- if (arith_en_n = '0') then
end process;
elsif sel = ALU_OR then
res := d1 or d2;
elsif sel = ALU_BIT then
- ----
+ --transfer bit 7 and 6 of memory data to n, v flag.
+ negative <= d2(7);
+ overflow <= d2(6);
+ ----zero bit after A and M.
+ res(dsize - 1 downto 0) := d1 and d2;
+ set_z(res(dsize - 1 downto 0));
elsif sel = ALU_ADC then
res := ('0' & d1) + ('0' & d2) + carry_in;
d_out <= res(dsize - 1 downto 0);
else
overflow <= '0';
end if;
+ set_n(res(dsize - 1 downto 0));
+ set_z(res(dsize - 1 downto 0));
elsif sel = ALU_SBC then
----
elsif sel = ALU_INC then
res := ('0' & d1) + "000000001";
d_out <= res(dsize - 1 downto 0);
- carry_out <= res(dsize);
+ set_n(res(dsize - 1 downto 0));
+ set_z(res(dsize - 1 downto 0));
+
elsif sel = ALU_DEC then
res := ('0' & d1) - "000000001";
d_out <= res(dsize - 1 downto 0);
- carry_out <= res(dsize);
+ set_n(res(dsize - 1 downto 0));
+ set_z(res(dsize - 1 downto 0));
+
end if;
- set_n(res(dsize - 1 downto 0));
- set_z(res(dsize - 1 downto 0));
end process;
stat_bus_nz_n <= '0';
end procedure;
---procedure set_nz_from_alu is
---begin
---end procedure;
---
procedure set_nzc_from_alu is
begin
+ --status register n/z/c bit update.
+ stat_alu_we_n <= '0';
+ stat_dec_oe_n <= '1';
+ status_reg <= "10000011";
+end procedure;
+
+procedure set_nzv_from_alu is
+begin
+ --status register n/z/v bit update.
+ stat_alu_we_n <= '0';
+ stat_dec_oe_n <= '1';
+ status_reg <= "11000010";
end procedure;
--flag on/off instruction
elsif instruction = conv_std_logic_vector(16#2c#, dsize) then
--abs
d_print("bit");
+ a2_abs;
+ if exec_cycle = T3 then
+ arith_en_n <= '0';
+ set_nzv_from_alu;
+ end if;
elsif instruction = conv_std_logic_vector(16#c9#, dsize) then
--imm