OSDN Git Service

merge cpu test all
[motonesfpga/motonesfpga.git] / de1_nes / cpu / decoder.vhd
index c179f08..a2518ad 100644 (file)
@@ -7,9 +7,7 @@ use work.motonesfpga_common.all;
 entity decoder is 
     generic (dsize : integer := 8);
     port (  
---    signal dbg_ea_carry     : out std_logic;
-    
-    
+            --input lines.
             set_clk         : in std_logic;
             trig_clk        : in std_logic;
             res_n           : in std_logic;
@@ -19,28 +17,31 @@ entity decoder is
             instruction     : in std_logic_vector (dsize - 1 downto 0);
             exec_cycle      : in std_logic_vector (5 downto 0);
             next_cycle      : out std_logic_vector (5 downto 0);
+            ea_carry        : in  std_logic;
             status_reg      : inout std_logic_vector (dsize - 1 downto 0);
+
+            --general control.
             inst_we_n       : out std_logic;
             ad_oe_n         : out std_logic;
             dbuf_int_oe_n   : out std_logic;
-            dl_al_we_n      : out std_logic;
-            dl_ah_we_n      : out std_logic;
-            dl_al_oe_n      : out std_logic;
-            dl_ah_oe_n      : out std_logic;
-            dl_dh_oe_n      : out std_logic;
-            pcl_inc_n       : out std_logic;
-            pch_inc_n       : out std_logic;
+            r_nw            : out std_logic;
+
+            ----control line for dual port registers.
+            idl_l_cmd       : out std_logic_vector(3 downto 0);
+            idl_h_cmd       : out std_logic_vector(3 downto 0);
             pcl_cmd         : out std_logic_vector(3 downto 0);
             pch_cmd         : out std_logic_vector(3 downto 0);
             sp_cmd          : out std_logic_vector(3 downto 0);
+            x_cmd           : out std_logic_vector(3 downto 0);
+            y_cmd           : out std_logic_vector(3 downto 0);
+            acc_cmd         : out std_logic_vector(3 downto 0);
+            
+            --addr calc control
+            pcl_inc_n       : out std_logic;
             sp_oe_n         : out std_logic;
             sp_push_n       : out std_logic;
             sp_pop_n        : out std_logic;
-            acc_cmd         : out std_logic_vector(3 downto 0);
-            x_cmd           : out std_logic_vector(3 downto 0);
-            y_cmd           : out std_logic_vector(3 downto 0);
             abs_xy_n        : out std_logic;
-            ea_carry        : in  std_logic;
             pg_next_n       : out std_logic;
             zp_n            : out std_logic;
             zp_xy_n         : out std_logic;
@@ -48,7 +49,9 @@ entity decoder is
             indir_n         : out std_logic;
             indir_x_n       : out std_logic;
             indir_y_n       : out std_logic;
-            arith_en_n      : out std_logic;
+            addr_cycle      : out std_logic_vector(2 downto 0);
+
+            ---status register
             stat_dec_oe_n   : out std_logic;
             stat_bus_oe_n   : out std_logic;
             stat_set_flg_n  : out std_logic;
@@ -56,10 +59,16 @@ entity decoder is
             stat_bus_all_n  : out std_logic;
             stat_bus_nz_n   : out std_logic;
             stat_alu_we_n   : out std_logic;
+            
+            --ALU control
+            arith_en_n      : out std_logic;
+            alu_cycle       : out std_logic_vector(1 downto 0);
+            
+            --reset vectors.
             r_vec_oe_n      : out std_logic;
             n_vec_oe_n      : out std_logic;
-            i_vec_oe_n      : out std_logic;
-            r_nw            : out std_logic
+            i_vec_oe_n      : out std_logic
+
             ;---for parameter check purpose!!!
             check_bit     : out std_logic_vector(1 to 5)
         );
@@ -92,27 +101,40 @@ constant T4 : std_logic_vector (5 downto 0) := "000100";
 constant T5 : std_logic_vector (5 downto 0) := "000101";
 constant T6 : std_logic_vector (5 downto 0) := "000110";
 
---01xxx : reset cycle : R0 > R1 > R2 > R3 > R4 > R5 > T0
+--reset cycle:
+--R0/T0: hold pc
+--R1: hold pc
+--R2: push pch
+--R3: push pcl
+--R4: push p
+--R5: fetch vector low
+--R6: fetch vector high
+--T0: first opcode
+
+--01xxx : reset cycle : R0 > R1 > R2 > R3 > R4 > R5 > R6 > T0
 constant R0 : std_logic_vector (5 downto 0) := "001000";
 constant R1 : std_logic_vector (5 downto 0) := "001001";
 constant R2 : std_logic_vector (5 downto 0) := "001010";
 constant R3 : std_logic_vector (5 downto 0) := "001011";
 constant R4 : std_logic_vector (5 downto 0) := "001100";
 constant R5 : std_logic_vector (5 downto 0) := "001101";
+constant R6 : std_logic_vector (5 downto 0) := "001110";
 
---10xxx : nmi cycle : T0 > N1 > N2 > N3 > N4 > N5 > T0
+--10xxx : nmi cycle : T0 > N1 > N2 > N3 > N4 > N5 > N6 > T0
 constant N1 : std_logic_vector (5 downto 0) := "010001";
 constant N2 : std_logic_vector (5 downto 0) := "010010";
 constant N3 : std_logic_vector (5 downto 0) := "010011";
 constant N4 : std_logic_vector (5 downto 0) := "010100";
 constant N5 : std_logic_vector (5 downto 0) := "010101";
+constant N6 : std_logic_vector (5 downto 0) := "010110";
 
---11xxx : irq cycle : T0 > I1 > I2 > I3 > I4 > I5 > T0
+--11xxx : irq cycle : T0 > I1 > I2 > I3 > I4 > I5 > I6 > T0
 constant I1 : std_logic_vector (5 downto 0) := "011001";
 constant I2 : std_logic_vector (5 downto 0) := "011010";
 constant I3 : std_logic_vector (5 downto 0) := "011011";
 constant I4 : std_logic_vector (5 downto 0) := "011100";
 constant I5 : std_logic_vector (5 downto 0) := "011101";
+constant I6 : std_logic_vector (5 downto 0) := "011110";
 
 constant ERROR_CYCLE : std_logic_vector (5 downto 0) := "111111";
 
@@ -133,50 +155,29 @@ constant st_I : integer := 2;
 constant st_Z : integer := 1;
 constant st_C : integer := 0;
 
----for pch_inc_n.
-signal pch_inc_input : std_logic;
+--Address calcuration (indirect addressing) has several stages
+constant ADDR_Z  : std_logic_vector (2 downto 0) := "000";
+constant ADDR_T2 : std_logic_vector (2 downto 0) := "001";
+constant ADDR_T3 : std_logic_vector (2 downto 0) := "010";
+constant ADDR_T4 : std_logic_vector (2 downto 0) := "011";
+constant ADDR_T5 : std_logic_vector (2 downto 0) := "100";
+
+--ALU cycle (memory to memory operation) has several stages 
+constant MEM_Z  : std_logic_vector (1 downto 0) := "00";
+constant MEM_T1 : std_logic_vector (1 downto 0) := "01";
+constant MEM_T2 : std_logic_vector (1 downto 0) := "10";
+constant MEM_T3 : std_logic_vector (1 downto 0) := "11";
 
 ---for nmi handling
 signal nmi_handled_n : std_logic;
 
--- page boundary handling
-signal wk_next_cycle      : std_logic_vector (5 downto 0);
-signal wk_acc_cmd         : std_logic_vector(3 downto 0);
-signal wk_x_cmd           : std_logic_vector(3 downto 0);
-signal wk_y_cmd           : std_logic_vector(3 downto 0);
-signal wk_stat_alu_we_n   : std_logic;
 signal ea_carry_reg       : std_logic;
 
 begin
 
-    ---pc page next is connected to top bit of exec_cycle
-    pch_inc_input <= not exec_cycle(5);
-    pch_inc_reg : d_flip_flop_bit 
-            port map(set_clk, '1', '1', '0', pch_inc_input, pch_inc_n);
-
     ea_carry_inst: d_flip_flop_bit 
             port map(trig_clk, '1', '1', '0', ea_carry, ea_carry_reg);
 
-    --acc,x,y next cycle is changed when it goes page across.
-    --The conditional branch instructions all have the form xxy10000
-    next_cycle <= wk_next_cycle;
-    acc_cmd <= wk_acc_cmd(3) & '1' & wk_acc_cmd(1) & '1'
-                    when ea_carry = '1' and 
-                         wk_next_cycle = T0 and instruction(4 downto 0) = "10000" else
-               wk_acc_cmd;
-
-    x_cmd <= wk_x_cmd(3) & '1' & wk_x_cmd(1 downto 0)
-                when ea_carry = '1' and 
-                         wk_next_cycle = T0 and instruction(4 downto 0) = "10000" else
-             wk_x_cmd;
-    y_cmd <= wk_y_cmd(3) & '1' & wk_y_cmd(1 downto 0)
-                when ea_carry = '1' and 
-                         wk_next_cycle = T0 and instruction(4 downto 0) = "10000" else
-             wk_y_cmd;
-    stat_alu_we_n <= '1' when ea_carry = '1' and 
-                         wk_next_cycle = T0 and instruction(4 downto 0) = "10000" else
-                     wk_stat_alu_we_n;
-
     main_p : process (set_clk, res_n, nmi_n)
 
 -------------------------------------------------------------
@@ -217,7 +218,13 @@ begin
     back_oe(pcl_cmd, '0');
     back_oe(pch_cmd, '0');
     back_we(pcl_cmd, '0');
-    back_we(pch_cmd, '1');
+    back_we(pch_cmd, '0');
+    if exec_cycle = T1 then
+        front_we(idl_l_cmd, '0');
+    elsif exec_cycle = T2 then
+        front_we(idl_l_cmd, '1');
+        front_we(idl_h_cmd, '0');
+    end if;
 end procedure;
 
 procedure fetch_stop is
@@ -226,6 +233,9 @@ begin
     back_oe(pcl_cmd, '1');
     back_oe(pch_cmd, '1');
     back_we(pcl_cmd, '1');
+    back_we(pch_cmd, '1');
+    front_we(idl_l_cmd, '1');
+    front_we(idl_h_cmd, '1');
 end procedure;
 
 procedure read_status is
@@ -234,31 +244,79 @@ begin
     stat_dec_oe_n <= '0';
 end  procedure;
 
+procedure init_all_pins is
+begin
+    --initialize port...
+    inst_we_n <= '1';
+    ad_oe_n <= '1';
+    dbuf_int_oe_n <= '1';
+    r_nw <= '1';
+
+    idl_l_cmd <= "1111";
+    idl_h_cmd <= "1111";
+    pcl_cmd <= "1111";
+    pch_cmd <= "1111";
+    sp_cmd <= "1111";
+    x_cmd <= "1111";
+    y_cmd <= "1111";
+    acc_cmd <= "1111";
+
+    pcl_inc_n <= '1';
+    sp_oe_n <= '1';
+    sp_push_n <= '1';
+    sp_pop_n <= '1';
+    abs_xy_n <= '1';
+    pg_next_n <= '1';
+    zp_n <= '1';
+    zp_xy_n <= '1';
+    rel_calc_n <= '1';
+    indir_n <= '1';
+    indir_x_n <= '1';
+    indir_y_n <= '1';
+    addr_cycle <= ADDR_Z;
+
+    read_status;
+    stat_bus_oe_n <= '1';
+    stat_set_flg_n <= '1';
+    stat_flg <= '1';
+    stat_bus_all_n <= '1';
+    stat_bus_nz_n <= '1';
+    stat_alu_we_n <= '1';
+
+    arith_en_n <= '1';
+    addr_cycle <= ADDR_Z;
+
+    r_vec_oe_n <= '1';
+    n_vec_oe_n <= '1';
+    i_vec_oe_n <= '1';
+
+    nmi_handled_n <= '1';
+
+end  procedure;
+
 procedure disable_pins is
 begin
 --following pins are not set in this function.
 --            inst_we_n       : out std_logic;
 --            ad_oe_n         : out std_logic;
---            dl_al_oe_n      : out std_logic;
 --            pcl_inc_n       : out std_logic;
---            pcl_cmd         : out std_logic_vector(3 downto 0);
---            pch_cmd         : out std_logic_vector(3 downto 0);
 --            r_nw            : out std_logic
 
     --disable the last opration pins.
     dbuf_int_oe_n <= '1';
-    dl_al_we_n <= '1';
-    dl_ah_we_n <= '1';
-    dl_ah_oe_n <= '1';
-    dl_dh_oe_n <= '1';
+
+    idl_l_cmd <= "1111";
+    idl_h_cmd <= "1111";
+    pcl_cmd   <= "1111";
+    pch_cmd   <= "1111";
     sp_cmd <= "1111";
+    x_cmd <= "1111";
+    y_cmd <= "1111";
+    acc_cmd <= "1111";
+
     sp_oe_n <= '1';
     sp_push_n <= '1';
     sp_pop_n <= '1';
-    wk_acc_cmd <= "1111";
-    wk_x_cmd <= "1111";
-    wk_y_cmd <= "1111";
-
     abs_xy_n <= '1';
     pg_next_n <= '1';
     zp_n <= '1';
@@ -267,7 +325,7 @@ begin
     indir_n <= '1';
     indir_x_n <= '1';
     indir_y_n <= '1';
-    arith_en_n <= '1';
+    addr_cycle <= ADDR_Z;
 
     read_status;
     stat_bus_oe_n <= '1';
@@ -275,7 +333,10 @@ begin
     stat_flg <= '1';
     stat_bus_all_n <= '1';
     stat_bus_nz_n <= '1';
-    wk_stat_alu_we_n <= '1';
+    stat_alu_we_n <= '1';
+
+    arith_en_n <= '1';
+    alu_cycle <= MEM_Z;
 
     r_vec_oe_n <= '1';
     n_vec_oe_n <= '1';
@@ -283,25 +344,25 @@ begin
 
 end  procedure;
 
-procedure fetch_inst (inc_pcl : in std_logic) is
+procedure fetch_inst (pm_pcl_inc_n : in std_logic) is
 begin
     if instruction = conv_std_logic_vector(16#4c#, dsize) then
         --if prior cycle is jump instruction, 
         --fetch opcode from where the latch is pointing to.
 
         --latch > al.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         pcl_cmd <= "1110";
     else
         --fetch opcode and pcl increment.
         pcl_cmd <= "1100";
-        dl_al_oe_n <= '1';
     end if;
 
+    idl_h_cmd <= "1111";
     ad_oe_n <= '0';
-    pch_cmd <= "1101";
+    pch_cmd <= "1100";
     inst_we_n <= '0';
-    pcl_inc_n <= inc_pcl;
+    pcl_inc_n <= pm_pcl_inc_n;
     r_nw <= '1';
 
     d_print(string'("fetch 1"));
@@ -316,10 +377,10 @@ begin
     if (nmi_n = '0' and nmi_handled_n = '1') then
         --start nmi handling...
         fetch_inst('1');
-        wk_next_cycle <= N1;
+        next_cycle <= N1;
     else
         fetch_inst('0');
-        wk_next_cycle <= T1;
+        next_cycle <= T1;
     end if;
 end  procedure;
 
@@ -327,7 +388,7 @@ end  procedure;
 procedure single_inst is
 begin
     fetch_stop;
-    wk_next_cycle <= T0;
+    next_cycle <= T0;
 end  procedure;
 
 procedure fetch_imm is
@@ -337,7 +398,7 @@ begin
     --send data from data bus buffer.
     --receiver is instruction dependent.
     dbuf_int_oe_n <= '0';
-    wk_next_cycle <= T0;
+    next_cycle <= T0;
 end  procedure;
 
 procedure set_nz_from_bus is
@@ -349,7 +410,7 @@ end  procedure;
 procedure set_zc_from_alu is
 begin
     --status register n/z bit update.
-    wk_stat_alu_we_n <= '0';
+    stat_alu_we_n <= '0';
     stat_dec_oe_n <= '1';
     status_reg <= "00000011";
 end  procedure;
@@ -357,7 +418,7 @@ end  procedure;
 procedure set_nz_from_alu is
 begin
     --status register n/z/c bit update.
-    wk_stat_alu_we_n <= '0';
+    stat_alu_we_n <= '0';
     stat_dec_oe_n <= '1';
     status_reg <= "10000010";
 end  procedure;
@@ -365,7 +426,7 @@ end  procedure;
 procedure set_nzc_from_alu is
 begin
     --status register n/z/c bit update.
-    wk_stat_alu_we_n <= '0';
+    stat_alu_we_n <= '0';
     stat_dec_oe_n <= '1';
     status_reg <= "10000011";
 end  procedure;
@@ -373,14 +434,14 @@ end  procedure;
 procedure set_nvz_from_alu is
 begin
     --status register n/z/v bit update.
-    wk_stat_alu_we_n <= '0';
+    stat_alu_we_n <= '0';
     stat_dec_oe_n <= '1';
     status_reg <= "11000010";
 end  procedure;
 
 procedure set_nvzc_from_alu is
 begin
-    wk_stat_alu_we_n <= '0';
+    stat_alu_we_n <= '0';
     stat_dec_oe_n <= '1';
     status_reg <= "11000011";
 end  procedure;
@@ -415,43 +476,39 @@ begin
     fetch_next;
     --latch abs low data.
     dbuf_int_oe_n <= '0';
-    dl_al_we_n <= '0';
-    wk_next_cycle <= T2;
+    next_cycle <= T2;
 end  procedure;
 
 procedure abs_fetch_high is
 begin
     d_print("abs (xy) 3");
-    dl_al_we_n <= '1';
 
     --latch abs hi data.
     fetch_next;
     dbuf_int_oe_n <= '0';
-    dl_ah_we_n <= '0';
-    wk_next_cycle <= T3;
+    next_cycle <= T3;
 end  procedure;
 
 procedure abs_latch_out is
 begin
     --d_print("abs 4");
-    dl_ah_we_n <= '1';
     fetch_stop;
 
     --latch > al/ah.
-    dl_al_oe_n <= '0';
-    dl_ah_oe_n <= '0';
+    back_oe(idl_l_cmd, '0');
+    back_oe(idl_h_cmd, '0');
 end  procedure;
 
 procedure ea_x_out is
 begin
     -----calucurate and output effective addr
-    back_oe(wk_x_cmd, '0');
+    back_oe(x_cmd, '0');
     abs_xy_n <= '0';
 end  procedure;
 
 procedure ea_y_out is
 begin
-    back_oe(wk_y_cmd, '0');
+    back_oe(y_cmd, '0');
     abs_xy_n <= '0';
 end  procedure;
 
@@ -464,12 +521,11 @@ begin
     elsif exec_cycle = T2 then
         fetch_stop;
         dbuf_int_oe_n <= '0';
-        dl_al_we_n <= '1';
 
         --calc zp.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -482,20 +538,10 @@ begin
     elsif exec_cycle = T3 then
         abs_latch_out;
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
-procedure a2_page_next is
-begin
-    --close open gate if page boundary crossed.
-    back_we(wk_acc_cmd, '1');
-    front_we(wk_acc_cmd, '1');
-    front_we(wk_x_cmd, '1');
-    front_we(wk_y_cmd, '1');
-    wk_stat_alu_we_n <= '1';
-end  procedure;
-
 procedure a2_abs_xy (is_x : in boolean) is
 begin
     if exec_cycle = T1 then
@@ -513,7 +559,7 @@ begin
         end if;
         dbuf_int_oe_n <= '0';
 
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
         d_print("absx step 1");
     elsif (exec_cycle = T0 and ea_carry_reg = '1') then
         --case page boundary crossed.
@@ -521,7 +567,7 @@ begin
         d_print("absx 5 (page boudary crossed.)");
         --next page.
         pg_next_n <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -533,21 +579,20 @@ begin
         fetch_stop;
         --output BAL only
         dbuf_int_oe_n <= '0';
-        dl_al_we_n <= '1';
 
         --calc zp.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
     elsif exec_cycle = T3 then
         --t3 zp, xy 
         zp_xy_n <= '0';
         if (is_x = true) then
-            back_oe(wk_x_cmd, '0');
+            back_oe(x_cmd, '0');
         else
-            back_oe(wk_y_cmd, '0');
+            back_oe(y_cmd, '0');
         end if;
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -556,48 +601,47 @@ begin
     if exec_cycle = T1 then
         fetch_low;
         --get IAL
-        dl_al_we_n <= '0';
 
     elsif exec_cycle = T2 then
         fetch_stop;
-        dl_al_we_n <= '1';
 
         ---address is 00:IAL
         --output BAL @IAL
         indir_y_n <= '0';
-        dl_al_oe_n <= '0';
+        addr_cycle <= ADDR_T2;
+        back_oe(idl_l_cmd, '0');
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
 
     elsif exec_cycle = T3 then
         indir_y_n <= '0';
-        dl_al_oe_n <= '0';
+        addr_cycle <= ADDR_T3;
+        back_oe(idl_l_cmd, '0');
         --output BAH @IAL+1
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
 
     elsif exec_cycle = T4 then
-        dl_al_oe_n <= '1';
+        back_oe(idl_l_cmd, '1');
         dbuf_int_oe_n <= '1';
 
         --add index y.
         pg_next_n <= '1';
-        back_oe(wk_y_cmd, '0');
+        back_oe(y_cmd, '0');
         indir_y_n <= '0';
+        addr_cycle <= ADDR_T4;
         dbuf_int_oe_n <= '0';
 
-        if (ea_carry = '1') then
-            wk_next_cycle <= T5;
-        else
-            wk_next_cycle <= T0;
-        end if;
-    elsif (exec_cycle = T5) then
+        next_cycle <= T0;
+    elsif (exec_cycle = T0) then
         --case page boundary crossed.
         --redo inst.
         d_print("(indir), y (page boudary crossed.)");
         --next page.
+        indir_y_n <= '0';
         pg_next_n <= '0';
-        wk_next_cycle <= T0;
+        addr_cycle <= ADDR_T5;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -606,38 +650,40 @@ begin
     if exec_cycle = T1 then
         fetch_low;
         --get IAL
-        dl_al_we_n <= '0';
 
     elsif exec_cycle = T2 then
         fetch_stop;
-        dl_al_we_n <= '1';
 
         ---address is 00:IAL
         --output BAL @IAL, but cycle #2 is discarded
         indir_x_n <= '0';
-        dl_al_oe_n <= '0';
-        wk_next_cycle <= T3;
+        addr_cycle <= ADDR_T2;
+        back_oe(idl_l_cmd, '0');
+        next_cycle <= T3;
 
     elsif exec_cycle = T3 then
         indir_x_n <= '0';
-        dl_al_oe_n <= '1';
+        addr_cycle <= ADDR_T3;
+        back_oe(idl_l_cmd, '1');
 
         --output BAH @IAL+x
         dbuf_int_oe_n <= '0';
-        back_oe(wk_x_cmd, '0');
-        wk_next_cycle <= T4;
+        back_oe(x_cmd, '0');
+        next_cycle <= T4;
 
     elsif exec_cycle = T4 then
         indir_x_n <= '0';
+        addr_cycle <= ADDR_T4;
 
         --output BAH @IAL+x+1
         dbuf_int_oe_n <= '0';
-        back_oe(wk_x_cmd, '0');
+        back_oe(x_cmd, '0');
 
-        wk_next_cycle <= T5;
+        next_cycle <= T5;
     elsif (exec_cycle = T5) then
         indir_x_n <= '0';
-        wk_next_cycle <= T0;
+        addr_cycle <= ADDR_T5;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -650,13 +696,12 @@ begin
     elsif exec_cycle = T2 then
         fetch_stop;
         dbuf_int_oe_n <= '1';
-        dl_al_we_n <= '1';
 
         --calc zp.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -667,26 +712,25 @@ begin
     elsif exec_cycle = T2 then
         fetch_stop;
         dbuf_int_oe_n <= '1';
-        dl_al_we_n <= '1';
 
         --calc zp.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
     elsif exec_cycle = T3 then
         --calc zp + index.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         zp_xy_n <= '0';
         if (is_x = true) then
-            back_oe(wk_x_cmd, '0');
+            back_oe(x_cmd, '0');
         else
-            back_oe(wk_y_cmd, '0');
+            back_oe(y_cmd, '0');
         end if;
 
         --write data
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -700,7 +744,7 @@ begin
         abs_latch_out;
         dbuf_int_oe_n <= '1';
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -720,7 +764,7 @@ begin
         else
             ea_y_out;
         end if;
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
     elsif exec_cycle = T4 then
         if (ea_carry_reg = '1') then
             pg_next_n <= '0';
@@ -734,7 +778,7 @@ begin
             ea_y_out;
         end if;
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -744,49 +788,50 @@ begin
     if exec_cycle = T1 then
         fetch_low;
         --get IAL
-        dl_al_we_n <= '0';
 
     elsif exec_cycle = T2 then
         fetch_stop;
-        dl_al_we_n <= '1';
 
         ---address is 00:IAL
         --output BAL @IAL
         indir_y_n <= '0';
-        dl_al_oe_n <= '0';
+        addr_cycle <= ADDR_T2;
+        back_oe(idl_l_cmd, '0');
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
 
     elsif exec_cycle = T3 then
         indir_y_n <= '0';
-        dl_al_oe_n <= '0';
+        addr_cycle <= ADDR_T3;
+        back_oe(idl_l_cmd, '0');
         --output BAH @IAL+1
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
 
     elsif exec_cycle = T4 then
-        dl_al_oe_n <= '1';
+        back_oe(idl_l_cmd, '1');
         dbuf_int_oe_n <= '1';
 
         --add index y.
         pg_next_n <= '1';
-        back_oe(wk_y_cmd, '0');
+        back_oe(y_cmd, '0');
         indir_y_n <= '0';
-        wk_next_cycle <= T5;
+        addr_cycle <= ADDR_T4;
+        next_cycle <= T5;
 
     elsif exec_cycle = T5 then
         --page handling.
-        back_oe(wk_y_cmd, '1');
+        back_oe(y_cmd, '1');
         indir_y_n <= '0';
+        addr_cycle <= ADDR_T5;
         
-        --ea_carry reg is suspicious. timing is not garanteed...
         if (ea_carry_reg = '1') then
             pg_next_n <= '0';
         else
             pg_next_n <= '1';
         end if;
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -795,40 +840,42 @@ begin
     if exec_cycle = T1 then
         fetch_low;
         --get IAL
-        dl_al_we_n <= '0';
 
     elsif exec_cycle = T2 then
         fetch_stop;
-        dl_al_we_n <= '1';
 
         ---address is 00:IAL
         --output BAL @IAL, but cycle #2 is discarded
         indir_x_n <= '0';
-        dl_al_oe_n <= '0';
-        wk_next_cycle <= T3;
+        addr_cycle <= ADDR_T2;
+        back_oe(idl_l_cmd, '0');
+        next_cycle <= T3;
 
     elsif exec_cycle = T3 then
         indir_x_n <= '0';
-        dl_al_oe_n <= '1';
+        addr_cycle <= ADDR_T3;
+        back_oe(idl_l_cmd, '1');
 
         --output BAH @IAL+x
         dbuf_int_oe_n <= '0';
-        back_oe(wk_x_cmd, '0');
-        wk_next_cycle <= T4;
+        back_oe(x_cmd, '0');
+        next_cycle <= T4;
 
     elsif exec_cycle = T4 then
         indir_x_n <= '0';
+        addr_cycle <= ADDR_T4;
 
         --output BAH @IAL+x+1
         dbuf_int_oe_n <= '0';
-        back_oe(wk_x_cmd, '0');
+        back_oe(x_cmd, '0');
 
-        wk_next_cycle <= T5;
+        next_cycle <= T5;
     elsif (exec_cycle = T5) then
         indir_x_n <= '0';
+        addr_cycle <= ADDR_T5;
         dbuf_int_oe_n <= '1';
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -840,29 +887,31 @@ begin
         fetch_low;
     elsif exec_cycle = T2 then
         fetch_stop;
-        dl_al_we_n <= '1';
 
         --t2 cycle read and,
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         --keep data in the alu reg.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T1;
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
     elsif exec_cycle = T3 then
         --t3 fix alu internal register.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         arith_en_n <= '0';
+        alu_cycle <= MEM_T2;
         dbuf_int_oe_n <= '1';
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
     elsif exec_cycle = T4 then
         --t5 cycle writes modified value.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         r_nw <= '0';
         arith_en_n <= '0';
-        wk_next_cycle <= T0;
+        alu_cycle <= MEM_T3;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -873,45 +922,47 @@ begin
     elsif exec_cycle = T2 then
         fetch_stop;
         dbuf_int_oe_n <= '1';
-        dl_al_we_n <= '1';
 
         --t2 cycle read bal only.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
     elsif exec_cycle = T3 then
         --t3 cycle read bal + x
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         zp_xy_n <= '0';
-        back_oe(wk_x_cmd, '0');
+        back_oe(x_cmd, '0');
 
         --keep data in the alu reg.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T1;
         dbuf_int_oe_n <= '0';
 
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
     elsif exec_cycle = T4 then
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         zp_xy_n <= '0';
-        back_oe(wk_x_cmd, '0');
+        back_oe(x_cmd, '0');
 
         --fix alu internal register.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T2;
         dbuf_int_oe_n <= '1';
-        wk_next_cycle <= T5;
+        next_cycle <= T5;
     elsif exec_cycle = T5 then
         dbuf_int_oe_n <= '1';
 
         --t5 cycle writes modified value.
-        dl_al_oe_n <= '0';
+        back_oe(idl_l_cmd, '0');
         zp_n <= '0';
         zp_xy_n <= '0';
-        back_oe(wk_x_cmd, '0');
+        back_oe(x_cmd, '0');
         r_nw <= '0';
         arith_en_n <= '0';
-        wk_next_cycle <= T0;
+        alu_cycle <= MEM_T3;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -927,22 +978,25 @@ begin
 
         --keep data in the alu reg.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T1;
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
     elsif exec_cycle = T4 then
         abs_latch_out;
 
         --fix alu internal register.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T2;
         dbuf_int_oe_n <= '1';
-        wk_next_cycle <= T5;
+        next_cycle <= T5;
     elsif exec_cycle = T5 then
         dbuf_int_oe_n <= '1';
 
         --t5 cycle writes modified value.
         r_nw <= '0';
         arith_en_n <= '0';
-        wk_next_cycle <= T0;
+        alu_cycle <= MEM_T3;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -958,7 +1012,7 @@ begin
         abs_latch_out;
         ea_x_out;
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T4;
+        next_cycle <= T4;
 
     elsif exec_cycle = T4 then
         abs_latch_out;
@@ -971,20 +1025,23 @@ begin
 
         --keep data in the alu reg.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T1;
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T5;
+        next_cycle <= T5;
 
     elsif exec_cycle = T5 then
         --fix alu internal register.
         arith_en_n <= '0';
+        alu_cycle <= MEM_T2;
         dbuf_int_oe_n <= '1';
-        wk_next_cycle <= T6;
+        next_cycle <= T6;
 
     elsif exec_cycle = T6 then
         --t5 cycle writes modified value.
         r_nw <= '0';
         arith_en_n <= '0';
-        wk_next_cycle <= T0;
+        alu_cycle <= MEM_T3;
+        next_cycle <= T0;
 
     end if;
 end  procedure;
@@ -995,14 +1052,14 @@ procedure a51_push is
 begin
     if exec_cycle = T1 then
         fetch_stop;
-        wk_next_cycle <= T2;
+        next_cycle <= T2;
     elsif exec_cycle = T2 then
         back_oe(sp_cmd, '0');
         back_we(sp_cmd, '0');
         sp_push_n <= '0';
         sp_oe_n <= '0';
         r_nw <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end procedure;
 
@@ -1011,7 +1068,7 @@ procedure a52_pull is
 begin
     if exec_cycle = T1 then
         fetch_stop;
-        wk_next_cycle <= T2;
+        next_cycle <= T2;
 
     elsif exec_cycle = T2 then
         --stack decrement first.
@@ -1019,7 +1076,7 @@ begin
         back_we(sp_cmd, '0');
         sp_pop_n <= '0';
         sp_oe_n <= '0';
-        wk_next_cycle <= T3;
+        next_cycle <= T3;
 
     elsif exec_cycle = T3 then
         sp_pop_n <= '1';
@@ -1029,7 +1086,7 @@ begin
         back_oe(sp_cmd, '0');
         sp_oe_n <= '0';
         dbuf_int_oe_n <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end procedure;
 
@@ -1045,27 +1102,27 @@ begin
 
             --latch rel value.
             dbuf_int_oe_n <= '0';
-            dl_ah_we_n <= '0';
-            wk_next_cycle <= T2;
+            front_we(idl_h_cmd, '0');
+            next_cycle <= T2;
         else
             d_print("no branch");
-            wk_next_cycle <= T0;
+            next_cycle <= T0;
         end if;
     elsif exec_cycle = T2 then
         d_print("rel ea");
         fetch_stop;
         dbuf_int_oe_n <= '1';
-        dl_ah_we_n <= '1';
+        front_we(idl_h_cmd, '1');
 
         --calc relative addr.
         rel_calc_n <= '0';
         pg_next_n <= '1';
-        dl_dh_oe_n <= '0';
+        front_oe(idl_h_cmd, '0');
         back_oe(pcl_cmd, '0');
         back_oe(pch_cmd, '0');
         back_we(pcl_cmd, '0');
 
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     elsif (exec_cycle = T0 and ea_carry = '1') then
         d_print("page crossed.");
         --page crossed. adh calc.
@@ -1073,11 +1130,11 @@ begin
         back_oe(pcl_cmd, '0');
         back_oe(pch_cmd, '0');
         back_we(pch_cmd, '0');
-        dl_dh_oe_n <= '0';
+        front_oe(idl_h_cmd, '0');
 
         rel_calc_n <= '0';
         pg_next_n <= '0';
-        wk_next_cycle <= T0;
+        next_cycle <= T0;
     end if;
 end  procedure;
 
@@ -1096,12 +1153,12 @@ end  procedure;
             stat_flg <= '1';
             stat_bus_all_n <= '1';
             stat_bus_nz_n <= '1';
-            wk_stat_alu_we_n <= '1';
+            stat_alu_we_n <= '1';
 
             --pc l/h is reset vector.
             pcl_cmd <= "1110";
             pch_cmd <= "1110";
-            wk_next_cycle <= R0;
+            next_cycle <= R0;
 
         elsif (rising_edge(set_clk)) then
             d_print(string'("-"));
@@ -1116,11 +1173,12 @@ end  procedure;
                 disable_pins;
                 inst_we_n <= '1';
                 ad_oe_n <= '1';
-                dl_al_oe_n <= '1';
+                back_oe(idl_l_cmd, '1');
                 pcl_inc_n <= '1';
                 pcl_cmd <= "1111";
                 pch_cmd <= "1111";
                 r_nw <= 'Z';
+
             elsif (exec_cycle = T0 and ea_carry = '0') then
                 --cycle #1
                 t0_cycle;
@@ -1137,7 +1195,7 @@ end  procedure;
                     d_print("decode and execute inst: " 
                             & conv_hex8(conv_integer(instruction)));
                     --disable pin for jmp instruction 
-                    dl_al_oe_n <= '1';
+                    back_oe(idl_l_cmd, '1');
                     back_we(pcl_cmd, '1');
                     front_we(pch_cmd, '1');
 
@@ -1155,8 +1213,8 @@ end  procedure;
                     --asl acc mode.
                     d_print("asl");
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    front_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    front_we(acc_cmd, '0');
                     set_nzc_from_alu;
                     single_inst;
 
@@ -1183,8 +1241,8 @@ end  procedure;
                 elsif instruction = conv_std_logic_vector(16#ca#, dsize) then
                     d_print("dex");
                     arith_en_n <= '0';
-                    back_oe(wk_x_cmd, '0');
-                    front_we(wk_x_cmd, '0');
+                    back_oe(x_cmd, '0');
+                    front_we(x_cmd, '0');
                     --set nz bit.
                     set_nz_from_bus;
                     single_inst;
@@ -1192,8 +1250,8 @@ end  procedure;
                 elsif instruction = conv_std_logic_vector(16#88#, dsize) then
                     d_print("dey");
                     arith_en_n <= '0';
-                    back_oe(wk_y_cmd, '0');
-                    front_we(wk_y_cmd, '0');
+                    back_oe(y_cmd, '0');
+                    front_we(y_cmd, '0');
                     --set nz bit.
                     set_nz_from_bus;
                     single_inst;
@@ -1201,8 +1259,8 @@ end  procedure;
                 elsif instruction = conv_std_logic_vector(16#e8#, dsize) then
                     d_print("inx");
                     arith_en_n <= '0';
-                    back_oe(wk_x_cmd, '0');
-                    front_we(wk_x_cmd, '0');
+                    back_oe(x_cmd, '0');
+                    front_we(x_cmd, '0');
                     --set nz bit.
                     set_nz_from_bus;
                     single_inst;
@@ -1210,8 +1268,8 @@ end  procedure;
                 elsif instruction = conv_std_logic_vector(16#c8#, dsize) then
                     d_print("iny");
                     arith_en_n <= '0';
-                    back_oe(wk_y_cmd, '0');
-                    front_we(wk_y_cmd, '0');
+                    back_oe(y_cmd, '0');
+                    front_we(y_cmd, '0');
                     set_nz_from_bus;
                     single_inst;
 
@@ -1219,8 +1277,8 @@ end  procedure;
                     --lsr acc mode
                     d_print("lsr");
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    front_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    front_we(acc_cmd, '0');
                     set_zc_from_alu;
                     single_inst;
 
@@ -1232,8 +1290,8 @@ end  procedure;
                     --rol acc
                     d_print("rol");
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    front_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    front_we(acc_cmd, '0');
                     set_nzc_from_alu;
                     single_inst;
 
@@ -1241,8 +1299,8 @@ end  procedure;
                     --ror acc
                     d_print("ror");
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    front_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    front_we(acc_cmd, '0');
                     set_nzc_from_alu;
                     single_inst;
 
@@ -1265,43 +1323,43 @@ end  procedure;
                     d_print("tax");
                     set_nz_from_bus;
                     single_inst;
-                    front_oe(wk_acc_cmd, '0');
-                    front_we(wk_x_cmd, '0');
+                    front_oe(acc_cmd, '0');
+                    front_we(x_cmd, '0');
 
                 elsif instruction = conv_std_logic_vector(16#a8#, dsize) then
                     d_print("tay");
                     set_nz_from_bus;
                     single_inst;
-                    front_oe(wk_acc_cmd, '0');
-                    front_we(wk_y_cmd, '0');
+                    front_oe(acc_cmd, '0');
+                    front_we(y_cmd, '0');
 
                 elsif instruction = conv_std_logic_vector(16#ba#, dsize) then
                     d_print("tsx");
                     set_nz_from_bus;
                     single_inst;
                     front_oe(sp_cmd, '0');
-                    front_we(wk_x_cmd, '0');
+                    front_we(x_cmd, '0');
 
                 elsif instruction = conv_std_logic_vector(16#8a#, dsize) then
                     d_print("txa");
                     set_nz_from_bus;
                     single_inst;
-                    front_oe(wk_x_cmd, '0');
-                    front_we(wk_acc_cmd, '0');
+                    front_oe(x_cmd, '0');
+                    front_we(acc_cmd, '0');
 
                 elsif instruction = conv_std_logic_vector(16#9a#, dsize) then
                     d_print("txs");
                     set_nz_from_bus;
                     single_inst;
-                    front_oe(wk_x_cmd, '0');
+                    front_oe(x_cmd, '0');
                     front_we(sp_cmd, '0');
 
                 elsif instruction = conv_std_logic_vector(16#98#, dsize) then
                     d_print("tya");
                     set_nz_from_bus;
                     single_inst;
-                    front_oe(wk_y_cmd, '0');
-                    front_we(wk_acc_cmd, '0');
+                    front_oe(y_cmd, '0');
+                    front_we(acc_cmd, '0');
 
 
 
@@ -1313,8 +1371,8 @@ end  procedure;
                     d_print("adc");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    back_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    back_we(acc_cmd, '0');
                     set_nvzc_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#65#, dsize) then
@@ -1323,8 +1381,8 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1334,8 +1392,8 @@ end  procedure;
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1345,8 +1403,8 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1356,8 +1414,8 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1367,8 +1425,8 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1378,8 +1436,8 @@ end  procedure;
                     a2_indir_x;
                     if exec_cycle = T5 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1389,8 +1447,8 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1399,8 +1457,8 @@ end  procedure;
                     d_print("and");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    back_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    back_we(acc_cmd, '0');
                     set_nz_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#25#, dsize) then
@@ -1409,8 +1467,8 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1420,8 +1478,8 @@ end  procedure;
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1431,8 +1489,8 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1442,8 +1500,8 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1453,8 +1511,8 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1464,8 +1522,8 @@ end  procedure;
                     a2_indir_x;
                     if exec_cycle = T5 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1475,8 +1533,8 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1486,7 +1544,7 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nvz_from_alu;
                     end if;
 
@@ -1496,7 +1554,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nvz_from_alu;
                     end if;
 
@@ -1505,7 +1563,7 @@ end  procedure;
                     d_print("cmp");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
                     set_nzc_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#c5#, dsize) then
@@ -1514,7 +1572,7 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1524,7 +1582,7 @@ end  procedure;
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1534,7 +1592,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1544,7 +1602,7 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1554,7 +1612,7 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1564,7 +1622,7 @@ end  procedure;
                     a2_indir_x;
                     if exec_cycle = T5 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1574,7 +1632,7 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1583,7 +1641,7 @@ end  procedure;
                     d_print("cpx");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_x_cmd, '0');
+                    back_oe(x_cmd, '0');
                     set_nzc_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#e4#, dsize) then
@@ -1592,7 +1650,7 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_x_cmd, '0');
+                        back_oe(x_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1602,7 +1660,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_x_cmd, '0');
+                        back_oe(x_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1611,7 +1669,7 @@ end  procedure;
                     d_print("cpy");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_y_cmd, '0');
+                    back_oe(y_cmd, '0');
                     set_nzc_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#c4#, dsize) then
@@ -1620,7 +1678,7 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_y_cmd, '0');
+                        back_oe(y_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1630,7 +1688,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_y_cmd, '0');
+                        back_oe(y_cmd, '0');
                         set_nzc_from_alu;
                     end if;
 
@@ -1639,8 +1697,8 @@ end  procedure;
                     d_print("eor");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    back_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    back_we(acc_cmd, '0');
                     set_nz_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#45#, dsize) then
@@ -1649,8 +1707,8 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1660,8 +1718,8 @@ end  procedure;
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1671,8 +1729,8 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1682,8 +1740,8 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1693,8 +1751,8 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1704,8 +1762,8 @@ end  procedure;
                     a2_indir_x;
                     if exec_cycle = T5 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1715,8 +1773,8 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1724,7 +1782,7 @@ end  procedure;
                     --imm
                     d_print("lda");
                     fetch_imm;
-                    front_we(wk_acc_cmd, '0');
+                    front_we(acc_cmd, '0');
                     set_nz_from_bus;
 
                 elsif instruction  = conv_std_logic_vector(16#a5#, dsize) then
@@ -1732,7 +1790,7 @@ end  procedure;
                     d_print("lda");
                     a2_zp;
                     if exec_cycle = T2 then
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1741,7 +1799,7 @@ end  procedure;
                     d_print("lda");
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1751,7 +1809,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         set_nz_from_bus;
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#bd#, dsize) then
@@ -1760,7 +1818,7 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         --lda.
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1770,7 +1828,7 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         --lda.
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1779,7 +1837,7 @@ end  procedure;
                     d_print("lda");
                     a2_indir_x;
                     if exec_cycle = T5 then
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1789,7 +1847,7 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         --lda.
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1798,14 +1856,14 @@ end  procedure;
                     d_print("ldx");
                     fetch_imm;
                     set_nz_from_bus;
-                    front_we(wk_x_cmd, '0');
+                    front_we(x_cmd, '0');
 
                 elsif instruction  = conv_std_logic_vector(16#a6#, dsize) then
                     --zp
                     d_print("ldx");
                     a2_zp;
                     if exec_cycle = T2 then
-                        front_we(wk_x_cmd, '0');
+                        front_we(x_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1814,7 +1872,7 @@ end  procedure;
                     d_print("ldx");
                     a2_zp_xy(false);
                     if exec_cycle = T3 then
-                        front_we(wk_x_cmd, '0');
+                        front_we(x_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1824,7 +1882,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         set_nz_from_bus;
-                        front_we(wk_x_cmd, '0');
+                        front_we(x_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#be#, dsize) then
@@ -1832,7 +1890,7 @@ end  procedure;
                     d_print("ldx");
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
-                        front_we(wk_x_cmd, '0');
+                        front_we(x_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1841,14 +1899,14 @@ end  procedure;
                     d_print("ldy");
                     fetch_imm;
                     set_nz_from_bus;
-                    front_we(wk_y_cmd, '0');
+                    front_we(y_cmd, '0');
 
                 elsif instruction  = conv_std_logic_vector(16#a4#, dsize) then
                     --zp
                     d_print("ldy");
                     a2_zp;
                     if exec_cycle = T2 then
-                        front_we(wk_y_cmd, '0');
+                        front_we(y_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1857,7 +1915,7 @@ end  procedure;
                     d_print("ldy");
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
-                        front_we(wk_y_cmd, '0');
+                        front_we(y_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -1867,7 +1925,7 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         set_nz_from_bus;
-                        front_we(wk_y_cmd, '0');
+                        front_we(y_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#bc#, dsize) then
@@ -1876,7 +1934,7 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         set_nz_from_bus;
-                        front_we(wk_y_cmd, '0');
+                        front_we(y_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#09#, dsize) then
@@ -1884,8 +1942,8 @@ end  procedure;
                     d_print("ora");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    back_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    back_we(acc_cmd, '0');
                     set_nz_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#05#, dsize) then
@@ -1894,8 +1952,8 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1905,8 +1963,8 @@ end  procedure;
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1916,8 +1974,8 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1927,8 +1985,8 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1938,8 +1996,8 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1949,8 +2007,8 @@ end  procedure;
                     a2_indir_x;
                     if exec_cycle = T5 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1960,8 +2018,8 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nz_from_alu;
                     end if;
 
@@ -1970,8 +2028,8 @@ end  procedure;
                     d_print("sbc");
                     fetch_imm;
                     arith_en_n <= '0';
-                    back_oe(wk_acc_cmd, '0');
-                    back_we(wk_acc_cmd, '0');
+                    back_oe(acc_cmd, '0');
+                    back_we(acc_cmd, '0');
                     set_nvzc_from_alu;
 
                 elsif instruction  = conv_std_logic_vector(16#e5#, dsize) then
@@ -1980,8 +2038,8 @@ end  procedure;
                     a2_zp;
                     if exec_cycle = T2 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -1991,8 +2049,8 @@ end  procedure;
                     a2_zp_xy(true);
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -2002,8 +2060,8 @@ end  procedure;
                     a2_abs;
                     if exec_cycle = T3 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -2013,8 +2071,8 @@ end  procedure;
                     a2_abs_xy(true);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -2024,8 +2082,8 @@ end  procedure;
                     a2_abs_xy(false);
                     if exec_cycle = T3 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -2035,8 +2093,8 @@ end  procedure;
                     a2_indir_x;
                     if exec_cycle = T5 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -2046,8 +2104,8 @@ end  procedure;
                     a2_indir_y;
                     if exec_cycle = T4 or exec_cycle = T0 then
                         arith_en_n <= '0';
-                        back_oe(wk_acc_cmd, '0');
-                        back_we(wk_acc_cmd, '0');
+                        back_oe(acc_cmd, '0');
+                        back_we(acc_cmd, '0');
                         set_nvzc_from_alu;
                     end if;
 
@@ -2061,7 +2119,7 @@ end  procedure;
                     d_print("sta");
                     a3_zp;
                     if exec_cycle = T2 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#95#, dsize) then
@@ -2069,7 +2127,7 @@ end  procedure;
                     d_print("sta");
                     a3_zp_xy(true);
                     if exec_cycle = T2 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#8d#, dsize) then
@@ -2077,7 +2135,7 @@ end  procedure;
                     d_print("sta");
                     a3_abs;
                     if exec_cycle = T3 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#9d#, dsize) then
@@ -2085,7 +2143,7 @@ end  procedure;
                     d_print("sta");
                     a3_abs_xy (true);
                     if exec_cycle = T4 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#99#, dsize) then
@@ -2093,7 +2151,7 @@ end  procedure;
                     d_print("sta");
                     a3_abs_xy (false);
                     if exec_cycle = T4 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#81#, dsize) then
@@ -2101,7 +2159,7 @@ end  procedure;
                     d_print("sta");
                     a3_indir_x;
                     if exec_cycle = T5 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#91#, dsize) then
@@ -2109,7 +2167,7 @@ end  procedure;
                     d_print("sta");
                     a3_indir_y;
                     if exec_cycle = T5 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#86#, dsize) then
@@ -2117,7 +2175,7 @@ end  procedure;
                     d_print("stx");
                     a3_zp;
                     if exec_cycle = T2 then
-                        front_oe(wk_x_cmd, '0');
+                        front_oe(x_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#96#, dsize) then
@@ -2125,7 +2183,7 @@ end  procedure;
                     d_print("stx");
                     a3_zp_xy(false);
                     if exec_cycle = T2 then
-                        front_oe(wk_x_cmd, '0');
+                        front_oe(x_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#8e#, dsize) then
@@ -2133,7 +2191,7 @@ end  procedure;
                     d_print("stx");
                     a3_abs;
                     if exec_cycle = T3 then
-                        front_oe(wk_x_cmd, '0');
+                        front_oe(x_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#84#, dsize) then
@@ -2141,7 +2199,7 @@ end  procedure;
                     d_print("sty");
                     a3_zp;
                     if exec_cycle = T2 then
-                        front_oe(wk_y_cmd, '0');
+                        front_oe(y_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#94#, dsize) then
@@ -2149,7 +2207,7 @@ end  procedure;
                     d_print("sty");
                     a3_zp_xy(true);
                     if exec_cycle = T2 then
-                        front_oe(wk_y_cmd, '0');
+                        front_oe(y_cmd, '0');
                     end if;
 
                 elsif instruction  = conv_std_logic_vector(16#8c#, dsize) then
@@ -2157,7 +2215,7 @@ end  procedure;
                     d_print("sty");
                     a3_abs;
                     if exec_cycle = T3 then
-                        front_oe(wk_y_cmd, '0');
+                        front_oe(y_cmd, '0');
                     end if;
 
 
@@ -2373,7 +2431,7 @@ end  procedure;
                     d_print("pha");
                     a51_push;
                     if exec_cycle = T2 then
-                        front_oe(wk_acc_cmd, '0');
+                        front_oe(acc_cmd, '0');
                     end if;
 
                 elsif instruction = conv_std_logic_vector(16#28#, dsize) then
@@ -2388,7 +2446,7 @@ end  procedure;
                     d_print("pla");
                     a52_pull;
                     if exec_cycle = T3 then
-                        front_we(wk_acc_cmd, '0');
+                        front_we(acc_cmd, '0');
                         set_nz_from_bus;
                     end if;
 
@@ -2403,13 +2461,11 @@ end  procedure;
                         fetch_next;
                         dbuf_int_oe_n <= '0';
                         --latch adl
-                        dl_al_we_n <= '0';
-                        wk_next_cycle <= T2;
+                        next_cycle <= T2;
                     elsif exec_cycle = T2 then
                         d_print("jsr 3");
                         fetch_stop;
                         dbuf_int_oe_n <= '1';
-                        dl_al_we_n <= '1';
 
                        --push return addr high into stack.
                         sp_push_n <= '0';
@@ -2418,7 +2474,7 @@ end  procedure;
                         back_oe(sp_cmd, '0');
                         back_we(sp_cmd, '0');
                         r_nw <= '0';
-                        wk_next_cycle <= T3;
+                        next_cycle <= T3;
                     elsif exec_cycle = T3 then
                         d_print("jsr 4");
                         front_oe(pch_cmd, '1');
@@ -2431,7 +2487,7 @@ end  procedure;
                         back_we(sp_cmd, '0');
                         r_nw <= '0';
 
-                        wk_next_cycle <= T4;
+                        next_cycle <= T4;
                     elsif exec_cycle = T4 then
                         d_print("jsr 5");
                         sp_push_n <= '1';
@@ -2445,27 +2501,28 @@ end  procedure;
                         back_oe(pch_cmd, '0');
                         back_oe(pcl_cmd, '0');
                         dbuf_int_oe_n <= '0';
-                        dl_ah_we_n <= '0';
+                        front_we(idl_h_cmd, '0');
 
-                        wk_next_cycle <= T5;
+                        next_cycle <= T5;
                     elsif exec_cycle = T5 then
                         d_print("jsr 6");
 
                         back_oe(pch_cmd, '1');
                         back_oe(pcl_cmd, '1');
                         dbuf_int_oe_n <= '1';
-                        dl_ah_we_n <= '1';
+                        front_we(idl_h_cmd, '1');
+
 
                         --load/output  pch
                         ad_oe_n <= '1';
-                        dl_dh_oe_n <= '0';
+                        front_oe(idl_h_cmd, '0');
                         front_we(pch_cmd, '0');
 
                         --load pcl.
-                        dl_al_oe_n <= '0';
+                        back_oe(idl_l_cmd, '0');
                         back_we(pcl_cmd, '0');
 
-                        wk_next_cycle <= T0;
+                        next_cycle <= T0;
                     end if; --if exec_cycle = T1 then
 
                 -- A.5.4 break
@@ -2485,7 +2542,7 @@ end  procedure;
                         sp_pop_n <= '0';
                         sp_oe_n <= '0';
 
-                        wk_next_cycle <= T2;
+                        next_cycle <= T2;
                     elsif exec_cycle = T2 then
                         d_print("rti 3");
 
@@ -2500,7 +2557,7 @@ end  procedure;
                         dbuf_int_oe_n <= '0';
                         stat_bus_all_n <= '0';
 
-                        wk_next_cycle <= T3;
+                        next_cycle <= T3;
                     elsif exec_cycle = T3 then
                         d_print("rti 4");
                         stat_bus_all_n <= '1';
@@ -2515,7 +2572,7 @@ end  procedure;
                         dbuf_int_oe_n <= '0';
                         front_we(pcl_cmd, '0');
 
-                        wk_next_cycle <= T4;
+                        next_cycle <= T4;
                     elsif exec_cycle = T4 then
                         d_print("rti 5");
                         --stack decrement stop.
@@ -2530,7 +2587,7 @@ end  procedure;
                         dbuf_int_oe_n <= '0';
                         front_we(pch_cmd, '0');
 
-                        wk_next_cycle <= T5;
+                        next_cycle <= T5;
                     elsif exec_cycle = T5 then
                         d_print("rti 6");
                         back_oe(sp_cmd, '1');
@@ -2540,7 +2597,7 @@ end  procedure;
                         front_we(pch_cmd, '1');
 
                         --increment pc.
-                        wk_next_cycle <= T0;
+                        next_cycle <= T0;
                     end if; --if exec_cycle = T1 then
 
                 ----------------------------------------
@@ -2555,22 +2612,19 @@ end  procedure;
 
                         --latch abs low data.
                         dbuf_int_oe_n <= '0';
-                        dl_al_we_n <= '0';
-                        wk_next_cycle <= T2;
+                        next_cycle <= T2;
                     elsif exec_cycle = T2 then
                         d_print("jmp 3");
-                        dl_al_we_n <= '1';
 
                         --fetch abs hi
                         fetch_next;
 
                         --latch  in dlh
                         dbuf_int_oe_n <= '0';
-                        dl_ah_we_n <= '0';
                         ---load pch.
                         front_we(pch_cmd, '0');
 
-                        wk_next_cycle <= T0;
+                        next_cycle <= T0;
                     end if;
 
                 elsif instruction = conv_std_logic_vector(16#6c#, dsize) then
@@ -2582,40 +2636,36 @@ end  procedure;
 
                         --latch abs low data.
                         dbuf_int_oe_n <= '0';
-                        dl_al_we_n <= '0';
-                        wk_next_cycle <= T2;
+                        next_cycle <= T2;
                     elsif exec_cycle = T2 then
                         d_print("jmp 3");
-                        dl_al_we_n <= '1';
 
                         --fetch abs hi
                         fetch_next;
 
                         --latch  in dlh
                         dbuf_int_oe_n <= '0';
-                        dl_ah_we_n <= '0';
-                        wk_next_cycle <= T3;
+                        next_cycle <= T3;
 
                     elsif exec_cycle = T3 then
                         fetch_stop;
-                        dl_ah_we_n <= '1';
 
                         --IAH/IAL > ADL
-                        dl_ah_oe_n <= '0';
-                        dl_al_oe_n <= '0';
+                        back_oe(idl_h_cmd, '0');
+                        back_oe(idl_l_cmd, '0');
                         front_we(pcl_cmd, '0');
-                        wk_next_cycle <= T4;
+                        next_cycle <= T4;
 
                     elsif exec_cycle = T4 then
-                        dl_ah_oe_n <= '0';
-                        dl_al_oe_n <= '0';
+                        back_oe(idl_h_cmd, '0');
+                        back_oe(idl_l_cmd, '0');
                         front_we(pcl_cmd, '1');
 
                         --IAH/IAL+1 > ADH
                         front_we(pch_cmd, '0');
                         indir_n <= '0';
 
-                        wk_next_cycle <= T0;
+                        next_cycle <= T0;
 
                     end if;
 
@@ -2634,7 +2684,7 @@ end  procedure;
                         sp_pop_n <= '0';
                         sp_oe_n <= '0';
 
-                        wk_next_cycle <= T2;
+                        next_cycle <= T2;
                     elsif exec_cycle = T2 then
                         d_print("rts 3");
 
@@ -2648,7 +2698,7 @@ end  procedure;
                         dbuf_int_oe_n <= '0';
                         front_we(pcl_cmd, '0');
 
-                        wk_next_cycle <= T3;
+                        next_cycle <= T3;
                     elsif exec_cycle = T3 then
                         d_print("rts 4");
                         --stack decrement stop.
@@ -2663,7 +2713,7 @@ end  procedure;
                         dbuf_int_oe_n <= '0';
                         front_we(pch_cmd, '0');
 
-                        wk_next_cycle <= T4;
+                        next_cycle <= T4;
                     elsif exec_cycle = T4 then
                         d_print("rts 5");
                         back_oe(sp_cmd, '1');
@@ -2673,13 +2723,13 @@ end  procedure;
                         front_we(pch_cmd, '1');
                         --empty cycle.
                         --complying h/w manual...
-                        wk_next_cycle <= T5;
+                        next_cycle <= T5;
                     elsif exec_cycle = T5 then
                         d_print("rts 6");
 
                         --increment pc.
                         fetch_next;
-                        wk_next_cycle <= T0;
+                        next_cycle <= T0;
                     end if; --if exec_cycle = T1 then
 
                 ----------------------------------------
@@ -2727,60 +2777,25 @@ end  procedure;
 
             elsif exec_cycle = R0 then
                 d_print(string'("reset"));
+                init_all_pins;
 
-                --initialize port...
-                inst_we_n <= '1';
-                ad_oe_n <= '1';
-                dbuf_int_oe_n <= '1';
-                dl_al_we_n <= '1';
-                dl_ah_we_n <= '1';
-                dl_al_oe_n <= '1';
-                dl_ah_oe_n <= '1';
-                dl_dh_oe_n <= '1';
-                pcl_inc_n <= '1';
-                pcl_cmd <= "1111";
-                pch_cmd <= "1111";
-                sp_cmd <= "1111";
-                sp_oe_n <= '1';
-                sp_push_n <= '1';
-                sp_pop_n <= '1';
-                wk_acc_cmd <= "1111";
-                wk_x_cmd <= "1111";
-                wk_y_cmd <= "1111";
-
-                abs_xy_n <= '1';
-                pg_next_n <= '1';
-                zp_n <= '1';
-                zp_xy_n <= '1';
-                rel_calc_n <= '1';
-                indir_n <= '1';
-                indir_x_n <= '1';
-                indir_y_n <= '1';
-                arith_en_n <= '1';
-
-                stat_dec_oe_n <= '0';
-                stat_bus_oe_n <= '1';
-                stat_set_flg_n <= '1';
-                stat_flg <= '1';
-                stat_bus_all_n <= '1';
-                stat_bus_nz_n <= '1';
-                wk_stat_alu_we_n <= '1';
-
-                r_vec_oe_n <= '1';
-                n_vec_oe_n <= '1';
-                i_vec_oe_n <= '1';
-                nmi_handled_n <= '1';
-                r_nw <= '1';
-
-                wk_next_cycle <= R1;
+                next_cycle <= R1;
             elsif exec_cycle = R1 or exec_cycle = N1 then
+                init_all_pins;
+                
+                if exec_cycle = R1 then
+                    next_cycle <= R2;
+                elsif exec_cycle = N1 then
+                    next_cycle <= N2;
+                end if;
+            elsif exec_cycle = R2 or exec_cycle = N2 then
                 pcl_cmd <= "1111";
                 pcl_inc_n <= '1';
                 inst_we_n <= '1';
-                dl_al_oe_n <= '1';
+                back_oe(idl_l_cmd, '1');
 
                 --push pch.
-                d_print("R1");
+                d_print("R2");
                 ad_oe_n <= '0';
                 sp_push_n <= '0';
                 sp_oe_n <= '0';
@@ -2790,13 +2805,13 @@ end  procedure;
                 back_we(sp_cmd, '0');
                 r_nw <= '0';
 
-                if exec_cycle = R1 then
-                    wk_next_cycle <= R2;
-                elsif exec_cycle = N1 then
-                    wk_next_cycle <= N2;
+                if exec_cycle = R2 then
+                    next_cycle <= R3;
+                elsif exec_cycle = N2 then
+                    next_cycle <= N3;
                 end if;
 
-            elsif exec_cycle = R2 or exec_cycle = N2 then
+            elsif exec_cycle = R3 or exec_cycle = N3 then
                 front_oe(pch_cmd, '1');
 
                --push pcl.
@@ -2807,13 +2822,13 @@ end  procedure;
                 back_we(sp_cmd, '0');
                 r_nw <= '0';
 
-                if exec_cycle = R2 then
-                    wk_next_cycle <= R3;
-                elsif exec_cycle = N2 then
-                    wk_next_cycle <= N3;
+                if exec_cycle = R3 then
+                    next_cycle <= R4;
+                elsif exec_cycle = N3 then
+                    next_cycle <= N4;
                 end if;
 
-            elsif exec_cycle = R3 or exec_cycle = N3 then
+            elsif exec_cycle = R4 or exec_cycle = N4 then
                 front_oe(pcl_cmd, '1');
 
                --push status.
@@ -2824,13 +2839,13 @@ end  procedure;
                 back_we(sp_cmd, '0');
                 r_nw <= '0';
 
-                if exec_cycle = R3 then
-                    wk_next_cycle <= R4;
-                elsif exec_cycle = N3 then
-                    wk_next_cycle <= N4;
+                if exec_cycle = R4 then
+                    next_cycle <= R5;
+                elsif exec_cycle = N4 then
+                    next_cycle <= N5;
                 end if;
 
-            elsif exec_cycle = R4 or exec_cycle = N4 then
+            elsif exec_cycle = R5 or exec_cycle = N5 then
                 stat_bus_oe_n <= '1';
                 sp_push_n <= '1';
                 sp_oe_n <= '1';
@@ -2842,20 +2857,20 @@ end  procedure;
                 r_nw <= '1';
                 dbuf_int_oe_n <= '0';
                 front_we(pcl_cmd, '0');
-                dl_al_oe_n <= '1';
-                dl_ah_oe_n <= '1';
+                back_oe(idl_l_cmd, '1');
+                back_oe(idl_h_cmd, '1');
 
-                if exec_cycle = R4 then
+                if exec_cycle = R5 then
                     r_vec_oe_n <= '0';
                     n_vec_oe_n <= '1';
-                    wk_next_cycle <= R5;
-                elsif exec_cycle = N4 then
+                    next_cycle <= R6;
+                elsif exec_cycle = N5 then
                     r_vec_oe_n <= '1';
                     n_vec_oe_n <= '0';
-                    wk_next_cycle <= N5;
+                    next_cycle <= N6;
                 end if;
                 
-            elsif exec_cycle = R5 or exec_cycle = N5 then
+            elsif exec_cycle = R6 or exec_cycle = N6 then
                 front_we(pcl_cmd, '1');
 
                 --fetch reset vector hi
@@ -2864,49 +2879,11 @@ end  procedure;
                 front_we(pch_cmd, '0');
                 indir_n <= '0';
 
-                if exec_cycle = N5 then
+                if exec_cycle = N6 then
                     nmi_handled_n <= '0';
                 end if;
                 --start execute cycle.
-                wk_next_cycle <= T0;
-
-            elsif exec_cycle(5) = '1' then
-                ---pc increment and next page.
-                d_print(string'("pch next page..."));
-                --pcl stop increment
-                pcl_inc_n <= '1';
-                back_we(pcl_cmd, '1');
-
-                if ('0' & exec_cycle(4 downto 0) = T0 and
-                    instruction = conv_std_logic_vector(16#4c#, dsize) ) then
-                    --jmp instruction t0 cycle discards pch increment.
-                    back_we(pch_cmd, '1');
-                    front_we(pch_cmd, '1');
-                else
-                    --pch increment
-                    back_we(pch_cmd, '0');
-                    back_oe(pch_cmd, '0');
-                end if;
-
-                if ('0' & exec_cycle(4 downto 0) = T0) then
-                    --do the t0 identical routine.
-                    disable_pins;
-                    inst_we_n <= '1';
-                    r_nw <= '1';
-
-                elsif ('0' & exec_cycle(4 downto 0) = T1) then
-                    --if fetch cycle, preserve instrution register
-                    inst_we_n <= '1';
-
-                elsif ('0' & exec_cycle(4 downto 0) = T2) then
-                    --disable previous we_n gate.
-                    --t1 cycle is fetch low oprand.
-                    dl_al_we_n <= '1';
-                    dl_ah_we_n <= '1';
-                elsif ('0' & exec_cycle(4 downto 0) = T3) then
-                    --t2 cycle is fetch high oprand.
-                    dl_ah_we_n <= '1';
-                end if;
+                next_cycle <= T0;
 
             end if; --if rdy = '0' then