2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.conv_std_logic_vector;
4 use ieee.std_logic_unsigned.conv_integer;
7 generic (dsize : integer := 8);
8 port ( set_clk : in std_logic;
9 trig_clk : in std_logic;
14 instruction : in std_logic_vector (dsize - 1 downto 0);
15 exec_cycle : in std_logic_vector (5 downto 0);
16 next_cycle : out std_logic_vector (5 downto 0);
17 status_reg : inout std_logic_vector (dsize - 1 downto 0);
18 inst_we_n : out std_logic;
19 ad_oe_n : out std_logic;
20 dbuf_int_oe_n : out std_logic;
21 dl_al_we_n : out std_logic;
22 dl_ah_we_n : out std_logic;
23 dl_al_oe_n : out std_logic;
24 dl_ah_oe_n : out std_logic;
25 dl_dh_oe_n : out std_logic;
26 pcl_inc_n : out std_logic;
27 pch_inc_n : out std_logic;
28 pcl_cmd : out std_logic_vector(3 downto 0);
29 pch_cmd : out std_logic_vector(3 downto 0);
30 sp_cmd : out std_logic_vector(3 downto 0);
31 sp_oe_n : out std_logic;
32 sp_push_n : out std_logic;
33 sp_pop_n : out std_logic;
34 acc_cmd : out std_logic_vector(3 downto 0);
35 x_cmd : out std_logic_vector(3 downto 0);
36 y_cmd : out std_logic_vector(3 downto 0);
37 abs_xy_n : out std_logic;
38 ea_carry : in std_logic;
39 pg_next_n : out std_logic;
41 zp_xy_n : out std_logic;
42 rel_calc_n : out std_logic;
43 indir_n : out std_logic;
44 indir_x_n : out std_logic;
45 indir_y_n : out std_logic;
46 arith_en_n : out std_logic;
47 stat_dec_oe_n : out std_logic;
48 stat_bus_oe_n : out std_logic;
49 stat_set_flg_n : out std_logic;
50 stat_flg : out std_logic;
51 stat_bus_all_n : out std_logic;
52 stat_bus_nz_n : out std_logic;
53 stat_alu_we_n : out std_logic;
54 r_vec_oe_n : out std_logic;
55 n_vec_oe_n : out std_logic;
56 i_vec_oe_n : out std_logic;
58 ;---for parameter check purpose!!!
59 check_bit : out std_logic_vector(1 to 5)
63 architecture rtl of decoder is
65 component d_flip_flop_bit
76 procedure d_print(msg : string) is
78 use ieee.std_logic_textio.all;
79 variable out_l : line;
82 writeline(output, out_l);
85 ---ival : 0x0000 - 0xffff
86 function conv_hex8(ival : integer) return string is
87 variable tmp1, tmp2 : integer;
88 variable hex_chr: string (1 to 16) := "0123456789abcdef";
90 tmp2 := (ival mod 16 ** 2) / 16 ** 1;
91 tmp1 := ival mod 16 ** 1;
92 return hex_chr(tmp2 + 1) & hex_chr(tmp1 + 1);
96 -- bit 5 : pcl increment carry flag
97 -- bit 4,3 : cycle type: 00 normal, 01 reset , 10 nmi, 11 irq
100 --00xxx : exec cycle : T0 > T1 > T2 > T3 > T4 > T5 > T6 > T0
101 constant T0 : std_logic_vector (5 downto 0) := "000000";
102 constant T1 : std_logic_vector (5 downto 0) := "000001";
103 constant T2 : std_logic_vector (5 downto 0) := "000010";
104 constant T3 : std_logic_vector (5 downto 0) := "000011";
105 constant T4 : std_logic_vector (5 downto 0) := "000100";
106 constant T5 : std_logic_vector (5 downto 0) := "000101";
107 constant T6 : std_logic_vector (5 downto 0) := "000110";
109 --01xxx : reset cycle : R0 > R1 > R2 > R3 > R4 > R5 > T0
110 constant R0 : std_logic_vector (5 downto 0) := "001000";
111 constant R1 : std_logic_vector (5 downto 0) := "001001";
112 constant R2 : std_logic_vector (5 downto 0) := "001010";
113 constant R3 : std_logic_vector (5 downto 0) := "001011";
114 constant R4 : std_logic_vector (5 downto 0) := "001100";
115 constant R5 : std_logic_vector (5 downto 0) := "001101";
117 --10xxx : nmi cycle : T0 > N1 > N2 > N3 > N4 > N5 > T0
118 constant N1 : std_logic_vector (5 downto 0) := "010001";
119 constant N2 : std_logic_vector (5 downto 0) := "010010";
120 constant N3 : std_logic_vector (5 downto 0) := "010011";
121 constant N4 : std_logic_vector (5 downto 0) := "010100";
122 constant N5 : std_logic_vector (5 downto 0) := "010101";
124 --11xxx : irq cycle : T0 > I1 > I2 > I3 > I4 > I5 > T0
125 constant I1 : std_logic_vector (5 downto 0) := "011001";
126 constant I2 : std_logic_vector (5 downto 0) := "011010";
127 constant I3 : std_logic_vector (5 downto 0) := "011011";
128 constant I4 : std_logic_vector (5 downto 0) := "011100";
129 constant I5 : std_logic_vector (5 downto 0) := "011101";
131 constant ERROR_CYCLE : std_logic_vector (5 downto 0) := "111111";
133 -- SR Flags (bit 7 to bit 0):
138 -- 3 D .... Decimal (use BCD for arithmetics)
139 -- 2 I .... Interrupt (IRQ disable)
142 constant st_N : integer := 7;
143 constant st_V : integer := 6;
144 constant st_B : integer := 4;
145 constant st_D : integer := 3;
146 constant st_I : integer := 2;
147 constant st_Z : integer := 1;
148 constant st_C : integer := 0;
151 signal pch_inc_input : std_logic;
154 signal nmi_handled_n : std_logic;
159 ---pc page next is connected to top bit of exec_cycle
160 pch_inc_input <= not exec_cycle(5);
161 pch_inc_reg : d_flip_flop_bit
162 port map(set_clk, '1', '1', '0', pch_inc_input, pch_inc_n);
164 main_p : process (set_clk, res_n, nmi_n)
166 -------------------------------------------------------------
167 -------------------------------------------------------------
168 ----------------------- comon routines ----------------------
169 -------------------------------------------------------------
170 -------------------------------------------------------------
172 ----------gate_cmd format
173 ------3 : front port oe_n
174 ------2 : front port we_n
175 ------1 : back port oe_n
176 ------0 : back port we_n
177 procedure front_oe (signal cmd : out std_logic_vector(3 downto 0);
178 val : in std_logic) is
182 procedure front_we (signal cmd : out std_logic_vector(3 downto 0);
183 val : in std_logic) is
187 procedure back_oe (signal cmd : out std_logic_vector(3 downto 0);
188 val : in std_logic) is
192 procedure back_we (signal cmd : out std_logic_vector(3 downto 0);
193 val : in std_logic) is
198 procedure fetch_next is
201 back_oe(pcl_cmd, '0');
202 back_oe(pch_cmd, '0');
203 back_we(pcl_cmd, '0');
204 back_we(pch_cmd, '1');
207 procedure fetch_stop is
210 back_oe(pcl_cmd, '1');
211 back_oe(pch_cmd, '1');
212 back_we(pcl_cmd, '1');
215 procedure read_status is
217 status_reg <= (others => 'Z');
218 stat_dec_oe_n <= '0';
221 procedure disable_pins is
223 --disable the last opration pins.
224 dbuf_int_oe_n <= '1';
248 stat_bus_oe_n <= '1';
249 stat_set_flg_n <= '1';
251 stat_bus_all_n <= '1';
252 stat_bus_nz_n <= '1';
253 stat_alu_we_n <= '1';
261 procedure fetch_inst is
263 if instruction = conv_std_logic_vector(16#4c#, dsize) then
264 --if prior cycle is jump instruction,
265 --fetch opcode from where the latch is pointing to.
271 --fetch opcode and phc increment.
283 d_print(string'("fetch 1"));
287 ---(along with the page boundary condition, the last
288 ---cycle is bypassed and slided to T0.)
289 procedure t0_cycle is
291 if (nmi_n = '0' and nmi_handled_n = '1') then
305 ---common routine for single byte instruction.
306 procedure single_inst is
312 procedure fetch_imm is
314 d_print("immediate");
316 --send data from data bus buffer.
317 --receiver is instruction dependent.
318 dbuf_int_oe_n <= '0';
322 procedure set_nz_from_bus is
324 --status register n/z bit update.
325 stat_dec_oe_n <= '1';
326 status_reg <= "10000010";
327 stat_bus_nz_n <= '0';
330 procedure set_nzc_from_bus is
332 --status register n,z,c bit update.
333 stat_dec_oe_n <= '1';
334 status_reg <= "10000011";
335 stat_bus_nz_n <= '0';
338 procedure set_nz_from_alu is
340 --status register n/z/c bit update.
341 stat_alu_we_n <= '0';
342 stat_dec_oe_n <= '1';
343 status_reg <= "10000010";
346 procedure set_nzc_from_alu is
348 --status register n/z/c bit update.
349 stat_alu_we_n <= '0';
350 stat_dec_oe_n <= '1';
351 status_reg <= "10000011";
354 procedure set_nvz_from_alu is
356 --status register n/z/v bit update.
357 stat_alu_we_n <= '0';
358 stat_dec_oe_n <= '1';
359 status_reg <= "11000010";
362 procedure set_nvzc_from_alu is
364 stat_alu_we_n <= '0';
365 stat_dec_oe_n <= '1';
366 status_reg <= "11000011";
369 --flag on/off instruction
370 procedure set_flag (int_flg : in integer; val : in std_logic) is
372 stat_dec_oe_n <= '1';
373 stat_set_flg_n <= '0';
374 --specify which to set.
375 status_reg(7 downto int_flg + 1)
377 status_reg(int_flg - 1 downto 0)
379 status_reg(int_flg) <= '1';
384 procedure set_flag0 (val : in std_logic) is
386 stat_dec_oe_n <= '1';
387 stat_set_flg_n <= '0';
388 status_reg <= "00000001";
392 procedure fetch_low is
394 d_print("fetch low 2");
395 --fetch next opcode (abs low).
397 --latch abs low data.
398 dbuf_int_oe_n <= '0';
403 procedure abs_fetch_high is
405 d_print("abs (xy) 3");
410 dbuf_int_oe_n <= '0';
415 procedure abs_latch_out is
426 procedure ea_x_out is
428 -----calucurate and output effective addr
433 procedure ea_y_out is
439 --A.2. internal execution on memory data
443 if exec_cycle = T1 then
445 elsif exec_cycle = T2 then
447 dbuf_int_oe_n <= '0';
459 if exec_cycle = T1 then
461 elsif exec_cycle = T2 then
463 elsif exec_cycle = T3 then
465 dbuf_int_oe_n <= '0';
470 procedure a2_abs_xy (is_x : in boolean) is
472 if exec_cycle = T1 then
474 elsif exec_cycle = T2 then
476 elsif exec_cycle = T3 then
480 if (is_x = true) then
485 dbuf_int_oe_n <= '0';
486 --instruction specific operation wriiten in the caller position.
488 elsif exec_cycle = T4 then
489 if ea_carry = '1' then
490 --case page boundary crossed.
491 d_print("absx 5 (page boudary crossed.)");
493 if (is_x = true) then
498 dbuf_int_oe_n <= '0';
500 pg_next_n <= not ea_carry;
504 --case page boundary not crossed. do the fetch op.
505 d_print("absx 5 (fetch)");
511 procedure a2_indir_y is
513 if exec_cycle = T1 then
518 elsif exec_cycle = T2 then
526 dbuf_int_oe_n <= '0';
529 elsif exec_cycle = T3 then
533 dbuf_int_oe_n <= '0';
536 elsif exec_cycle = T4 then
538 dbuf_int_oe_n <= '1';
544 dbuf_int_oe_n <= '0';
547 elsif exec_cycle = T5 then
548 if ea_carry = '1' then
549 --case page boundary crossed.
550 d_print("(indir), y (page boudary crossed.)");
553 dbuf_int_oe_n <= '0';
554 pg_next_n <= not ea_carry;
557 --case page boundary not crossed. do the fetch op.
558 d_print("(indir), y (next fetch)");
565 --A.3. store operation.
569 if exec_cycle = T1 then
571 elsif exec_cycle = T2 then
573 dbuf_int_oe_n <= '1';
586 if exec_cycle = T1 then
588 elsif exec_cycle = T2 then
590 elsif exec_cycle = T3 then
592 dbuf_int_oe_n <= '1';
598 procedure a3_abs_xy (is_x : in boolean) is
600 if exec_cycle = T1 then
602 elsif exec_cycle = T2 then
604 elsif exec_cycle = T3 then
608 dbuf_int_oe_n <= '1';
609 if (is_x = true) then
615 elsif exec_cycle = T4 then
616 pg_next_n <= not ea_carry;
618 if (is_x = true) then
629 procedure a3_indir_y is
631 if exec_cycle = T1 then
636 elsif exec_cycle = T2 then
644 dbuf_int_oe_n <= '0';
647 elsif exec_cycle = T3 then
651 dbuf_int_oe_n <= '0';
654 elsif exec_cycle = T4 then
656 dbuf_int_oe_n <= '1';
664 elsif exec_cycle = T5 then
669 pg_next_n <= not ea_carry;
676 ---A.4. read-modify-write operation
680 if exec_cycle = T1 then
682 elsif exec_cycle = T2 then
684 dbuf_int_oe_n <= '1';
691 elsif exec_cycle = T3 then
694 --keep data in the alu reg.
696 dbuf_int_oe_n <= '0';
698 elsif exec_cycle = T4 then
699 dbuf_int_oe_n <= '1';
701 --t5 cycle writes modified value.
713 if exec_cycle = T1 then
715 elsif exec_cycle = T2 then
717 elsif exec_cycle = T3 then
718 --T3 cycle do nothing.
721 elsif exec_cycle = T4 then
724 --t4 cycle save data in the alu register only.
725 --hardware maunual says write original data,
726 --but this implementation doesn't write because bus shortage....
729 elsif exec_cycle = T5 then
730 dbuf_int_oe_n <= '1';
732 --t5 cycle writes modified value.
741 procedure a51_push is
743 if exec_cycle = T1 then
746 elsif exec_cycle = T2 then
747 back_oe(sp_cmd, '0');
748 back_we(sp_cmd, '0');
757 procedure a52_pull is
759 if exec_cycle = T1 then
763 elsif exec_cycle = T2 then
764 --stack decrement first.
765 back_oe(sp_cmd, '0');
766 back_we(sp_cmd, '0');
771 elsif exec_cycle = T3 then
773 back_we(sp_cmd, '1');
775 ---pop data from stack.
776 back_oe(sp_cmd, '0');
778 dbuf_int_oe_n <= '0';
784 -- A.5.8 branch operations
786 procedure a58_branch (int_flg : in integer; br_cond : in std_logic) is
788 if exec_cycle = T1 then
790 if status_reg(int_flg) = br_cond then
794 dbuf_int_oe_n <= '0';
798 d_print("no branch");
801 elsif exec_cycle = T2 then
804 dbuf_int_oe_n <= '1';
807 --calc relative addr.
811 back_oe(pcl_cmd, '0');
812 back_oe(pch_cmd, '0');
813 back_we(pcl_cmd, '0');
816 elsif exec_cycle = T3 then
818 if ea_carry = '1' then
819 d_print("page crossed.");
820 --page crossed. adh calc.
821 back_we(pcl_cmd, '1');
822 back_oe(pcl_cmd, '0');
823 back_oe(pch_cmd, '0');
824 back_we(pch_cmd, '0');
828 pg_next_n <= not ea_carry;
832 --fetch cycle is done.
838 -------------------------------------------------------------
839 -------------------------------------------------------------
840 ---------------- main state machine start.... ---------------
841 -------------------------------------------------------------
842 -------------------------------------------------------------
845 if (res_n = '0') then
846 --pc l/h is reset vector.
850 elsif (res_n'event and res_n = '1') then
855 if (nmi_n'event and nmi_n = '1') then
856 --reset nmi handle status
857 nmi_handled_n <= '1';
860 if (set_clk'event and set_clk = '1' and res_n = '1') then
861 d_print(string'("-"));
863 if exec_cycle = T0 then
867 elsif exec_cycle = T1 or exec_cycle = T2 or exec_cycle = T3 or
868 exec_cycle = T4 or exec_cycle = T5 or exec_cycle = T6 then
871 ---asyncronous page change might happen.
872 back_we(pch_cmd, '1');
874 if exec_cycle = T1 then
875 d_print("decode and execute inst: "
876 & conv_hex8(conv_integer(instruction)));
877 --disable pin since jmp instruction
878 --directly enters into t2 cycle.
880 back_we(pcl_cmd, '1');
881 front_we(pch_cmd, '1');
883 --grab instruction register data.
887 --imelementation is wriiten in the order of hardware manual
890 ----------------------------------------
891 --A.1. Single byte instruction.
892 ----------------------------------------
893 if instruction = conv_std_logic_vector(16#0a#, dsize) then
897 elsif instruction = conv_std_logic_vector(16#18#, dsize) then
902 elsif instruction = conv_std_logic_vector(16#d8#, dsize) then
904 set_flag (st_D, '0');
907 elsif instruction = conv_std_logic_vector(16#58#, dsize) then
910 elsif instruction = conv_std_logic_vector(16#b8#, dsize) then
913 elsif instruction = conv_std_logic_vector(16#ca#, dsize) then
917 front_we(x_cmd, '0');
922 elsif instruction = conv_std_logic_vector(16#88#, dsize) then
926 front_we(y_cmd, '0');
931 elsif instruction = conv_std_logic_vector(16#e8#, dsize) then
935 front_we(x_cmd, '0');
940 elsif instruction = conv_std_logic_vector(16#c8#, dsize) then
944 front_we(y_cmd, '0');
948 elsif instruction = conv_std_logic_vector(16#4a#, dsize) then
952 back_oe(acc_cmd, '0');
953 front_we(acc_cmd, '0');
957 elsif instruction = conv_std_logic_vector(16#ea#, dsize) then
961 elsif instruction = conv_std_logic_vector(16#2a#, dsize) then
965 elsif instruction = conv_std_logic_vector(16#38#, dsize) then
970 elsif instruction = conv_std_logic_vector(16#f8#, dsize) then
972 set_flag (st_D, '1');
975 elsif instruction = conv_std_logic_vector(16#78#, dsize) then
977 set_flag (st_I, '1');
980 elsif instruction = conv_std_logic_vector(16#aa#, dsize) then
984 front_oe(acc_cmd, '0');
985 front_we(x_cmd, '0');
987 elsif instruction = conv_std_logic_vector(16#a8#, dsize) then
991 front_oe(acc_cmd, '0');
992 front_we(y_cmd, '0');
994 elsif instruction = conv_std_logic_vector(16#ba#, dsize) then
998 elsif instruction = conv_std_logic_vector(16#8a#, dsize) then
1002 front_oe(x_cmd, '0');
1003 front_we(acc_cmd, '0');
1005 elsif instruction = conv_std_logic_vector(16#9a#, dsize) then
1009 front_oe(x_cmd, '0');
1010 front_we(sp_cmd, '0');
1012 elsif instruction = conv_std_logic_vector(16#98#, dsize) then
1016 front_oe(y_cmd, '0');
1017 front_we(acc_cmd, '0');
1021 ----------------------------------------
1022 --A.2. internal execution on memory data
1023 ----------------------------------------
1024 elsif instruction = conv_std_logic_vector(16#69#, dsize) then
1029 back_oe(acc_cmd, '0');
1030 back_we(acc_cmd, '0');
1033 elsif instruction = conv_std_logic_vector(16#65#, dsize) then
1037 if exec_cycle = T2 then
1039 back_oe(acc_cmd, '0');
1040 back_we(acc_cmd, '0');
1044 elsif instruction = conv_std_logic_vector(16#75#, dsize) then
1048 elsif instruction = conv_std_logic_vector(16#6d#, dsize) then
1052 elsif instruction = conv_std_logic_vector(16#7d#, dsize) then
1056 elsif instruction = conv_std_logic_vector(16#79#, dsize) then
1060 elsif instruction = conv_std_logic_vector(16#61#, dsize) then
1064 elsif instruction = conv_std_logic_vector(16#71#, dsize) then
1068 elsif instruction = conv_std_logic_vector(16#29#, dsize) then
1073 back_oe(acc_cmd, '0');
1074 back_we(acc_cmd, '0');
1077 elsif instruction = conv_std_logic_vector(16#25#, dsize) then
1081 if exec_cycle = T2 then
1083 back_oe(acc_cmd, '0');
1084 back_we(acc_cmd, '0');
1088 elsif instruction = conv_std_logic_vector(16#35#, dsize) then
1092 elsif instruction = conv_std_logic_vector(16#2d#, dsize) then
1096 elsif instruction = conv_std_logic_vector(16#3d#, dsize) then
1100 elsif instruction = conv_std_logic_vector(16#39#, dsize) then
1104 elsif instruction = conv_std_logic_vector(16#21#, dsize) then
1108 elsif instruction = conv_std_logic_vector(16#31#, dsize) then
1112 elsif instruction = conv_std_logic_vector(16#24#, dsize) then
1116 elsif instruction = conv_std_logic_vector(16#2c#, dsize) then
1120 if exec_cycle = T3 then
1125 elsif instruction = conv_std_logic_vector(16#c9#, dsize) then
1130 back_oe(acc_cmd, '0');
1133 elsif instruction = conv_std_logic_vector(16#c5#, dsize) then
1137 if exec_cycle = T2 then
1139 back_oe(acc_cmd, '0');
1143 elsif instruction = conv_std_logic_vector(16#d5#, dsize) then
1147 elsif instruction = conv_std_logic_vector(16#cd#, dsize) then
1151 elsif instruction = conv_std_logic_vector(16#dd#, dsize) then
1155 elsif instruction = conv_std_logic_vector(16#d9#, dsize) then
1159 if exec_cycle = T3 then
1161 back_oe(acc_cmd, '0');
1163 elsif exec_cycle = T4 then
1164 if ea_carry = '1' then
1166 back_oe(acc_cmd, '0');
1171 elsif instruction = conv_std_logic_vector(16#c1#, dsize) then
1175 elsif instruction = conv_std_logic_vector(16#d1#, dsize) then
1179 elsif instruction = conv_std_logic_vector(16#e0#, dsize) then
1184 back_oe(x_cmd, '0');
1187 elsif instruction = conv_std_logic_vector(16#e4#, dsize) then
1191 if exec_cycle = T2 then
1193 back_oe(x_cmd, '0');
1197 elsif instruction = conv_std_logic_vector(16#ec#, dsize) then
1201 elsif instruction = conv_std_logic_vector(16#c0#, dsize) then
1206 back_oe(y_cmd, '0');
1209 elsif instruction = conv_std_logic_vector(16#c4#, dsize) then
1213 elsif instruction = conv_std_logic_vector(16#cc#, dsize) then
1217 elsif instruction = conv_std_logic_vector(16#49#, dsize) then
1222 back_oe(acc_cmd, '0');
1223 back_we(acc_cmd, '0');
1226 elsif instruction = conv_std_logic_vector(16#45#, dsize) then
1230 if exec_cycle = T2 then
1232 back_oe(acc_cmd, '0');
1233 back_we(acc_cmd, '0');
1237 elsif instruction = conv_std_logic_vector(16#55#, dsize) then
1241 elsif instruction = conv_std_logic_vector(16#4d#, dsize) then
1245 elsif instruction = conv_std_logic_vector(16#5d#, dsize) then
1249 elsif instruction = conv_std_logic_vector(16#59#, dsize) then
1253 elsif instruction = conv_std_logic_vector(16#41#, dsize) then
1257 elsif instruction = conv_std_logic_vector(16#51#, dsize) then
1261 elsif instruction = conv_std_logic_vector(16#a9#, dsize) then
1265 front_we(acc_cmd, '0');
1268 elsif instruction = conv_std_logic_vector(16#a5#, dsize) then
1272 if exec_cycle = T2 then
1273 front_we(acc_cmd, '0');
1277 elsif instruction = conv_std_logic_vector(16#b5#, dsize) then
1281 elsif instruction = conv_std_logic_vector(16#ad#, dsize) then
1285 if exec_cycle = T3 then
1287 front_we(acc_cmd, '0');
1290 elsif instruction = conv_std_logic_vector(16#bd#, dsize) then
1294 if exec_cycle = T3 then
1296 front_we(acc_cmd, '0');
1298 elsif exec_cycle = T4 then
1299 if ea_carry = '1' then
1301 front_we(acc_cmd, '0');
1306 elsif instruction = conv_std_logic_vector(16#b9#, dsize) then
1310 if exec_cycle = T3 then
1312 front_we(acc_cmd, '0');
1314 elsif exec_cycle = T4 then
1315 if ea_carry = '1' then
1317 front_we(acc_cmd, '0');
1322 elsif instruction = conv_std_logic_vector(16#a1#, dsize) then
1326 elsif instruction = conv_std_logic_vector(16#b1#, dsize) then
1330 if exec_cycle = T4 then
1332 front_we(acc_cmd, '0');
1334 elsif exec_cycle = T5 then
1335 if ea_carry = '1' then
1337 front_we(acc_cmd, '0');
1342 elsif instruction = conv_std_logic_vector(16#a2#, dsize) then
1347 front_we(x_cmd, '0');
1349 elsif instruction = conv_std_logic_vector(16#a6#, dsize) then
1353 if exec_cycle = T2 then
1354 front_we(x_cmd, '0');
1358 elsif instruction = conv_std_logic_vector(16#b6#, dsize) then
1362 elsif instruction = conv_std_logic_vector(16#ae#, dsize) then
1366 if exec_cycle = T3 then
1368 front_we(x_cmd, '0');
1371 elsif instruction = conv_std_logic_vector(16#be#, dsize) then
1375 if exec_cycle = T3 then
1377 front_we(x_cmd, '0');
1379 elsif exec_cycle = T4 then
1380 if ea_carry = '1' then
1382 front_we(x_cmd, '0');
1387 elsif instruction = conv_std_logic_vector(16#a0#, dsize) then
1392 front_we(y_cmd, '0');
1394 elsif instruction = conv_std_logic_vector(16#a4#, dsize) then
1398 elsif instruction = conv_std_logic_vector(16#b4#, dsize) then
1402 elsif instruction = conv_std_logic_vector(16#ac#, dsize) then
1406 if exec_cycle = T3 then
1408 front_we(y_cmd, '0');
1411 elsif instruction = conv_std_logic_vector(16#bc#, dsize) then
1415 elsif instruction = conv_std_logic_vector(16#09#, dsize) then
1420 back_oe(acc_cmd, '0');
1421 back_we(acc_cmd, '0');
1424 elsif instruction = conv_std_logic_vector(16#05#, dsize) then
1428 if exec_cycle = T2 then
1430 back_oe(acc_cmd, '0');
1431 back_we(acc_cmd, '0');
1435 elsif instruction = conv_std_logic_vector(16#15#, dsize) then
1439 elsif instruction = conv_std_logic_vector(16#0d#, dsize) then
1443 elsif instruction = conv_std_logic_vector(16#1d#, dsize) then
1447 elsif instruction = conv_std_logic_vector(16#19#, dsize) then
1451 elsif instruction = conv_std_logic_vector(16#01#, dsize) then
1455 elsif instruction = conv_std_logic_vector(16#11#, dsize) then
1459 elsif instruction = conv_std_logic_vector(16#e9#, dsize) then
1463 elsif instruction = conv_std_logic_vector(16#e5#, dsize) then
1467 elsif instruction = conv_std_logic_vector(16#f5#, dsize) then
1471 elsif instruction = conv_std_logic_vector(16#ed#, dsize) then
1475 elsif instruction = conv_std_logic_vector(16#fd#, dsize) then
1479 elsif instruction = conv_std_logic_vector(16#f9#, dsize) then
1483 elsif instruction = conv_std_logic_vector(16#e1#, dsize) then
1487 elsif instruction = conv_std_logic_vector(16#f1#, dsize) then
1493 ----------------------------------------
1494 ---A.3. store operation.
1495 ----------------------------------------
1496 elsif instruction = conv_std_logic_vector(16#85#, dsize) then
1500 if exec_cycle = T2 then
1501 front_oe(acc_cmd, '0');
1504 elsif instruction = conv_std_logic_vector(16#95#, dsize) then
1508 elsif instruction = conv_std_logic_vector(16#8d#, dsize) then
1512 if exec_cycle = T3 then
1513 front_oe(acc_cmd, '0');
1516 elsif instruction = conv_std_logic_vector(16#9d#, dsize) then
1520 if exec_cycle = T4 then
1521 front_oe(acc_cmd, '0');
1524 elsif instruction = conv_std_logic_vector(16#99#, dsize) then
1528 if exec_cycle = T4 then
1529 front_oe(acc_cmd, '0');
1532 elsif instruction = conv_std_logic_vector(16#81#, dsize) then
1536 elsif instruction = conv_std_logic_vector(16#91#, dsize) then
1540 if exec_cycle = T5 then
1541 front_oe(acc_cmd, '0');
1544 elsif instruction = conv_std_logic_vector(16#86#, dsize) then
1548 if exec_cycle = T2 then
1549 front_oe(x_cmd, '0');
1552 elsif instruction = conv_std_logic_vector(16#96#, dsize) then
1556 elsif instruction = conv_std_logic_vector(16#8e#, dsize) then
1560 elsif instruction = conv_std_logic_vector(16#84#, dsize) then
1564 if exec_cycle = T2 then
1565 front_oe(y_cmd, '0');
1568 elsif instruction = conv_std_logic_vector(16#94#, dsize) then
1572 elsif instruction = conv_std_logic_vector(16#8c#, dsize) then
1577 ----------------------------------------
1578 ---A.4. read-modify-write operation
1579 ----------------------------------------
1580 elsif instruction = conv_std_logic_vector(16#06#, dsize) then
1584 elsif instruction = conv_std_logic_vector(16#16#, dsize) then
1588 elsif instruction = conv_std_logic_vector(16#0e#, dsize) then
1592 elsif instruction = conv_std_logic_vector(16#1e#, dsize) then
1596 elsif instruction = conv_std_logic_vector(16#c6#, dsize) then
1600 if exec_cycle = T4 then
1604 elsif instruction = conv_std_logic_vector(16#d6#, dsize) then
1608 elsif instruction = conv_std_logic_vector(16#ce#, dsize) then
1612 elsif instruction = conv_std_logic_vector(16#de#, dsize) then
1616 elsif instruction = conv_std_logic_vector(16#e6#, dsize) then
1620 if exec_cycle = T4 then
1624 elsif instruction = conv_std_logic_vector(16#f6#, dsize) then
1628 elsif instruction = conv_std_logic_vector(16#ee#, dsize) then
1632 if exec_cycle = T5 then
1636 elsif instruction = conv_std_logic_vector(16#fe#, dsize) then
1640 elsif instruction = conv_std_logic_vector(16#46#, dsize) then
1644 elsif instruction = conv_std_logic_vector(16#56#, dsize) then
1648 elsif instruction = conv_std_logic_vector(16#4e#, dsize) then
1652 elsif instruction = conv_std_logic_vector(16#5e#, dsize) then
1656 elsif instruction = conv_std_logic_vector(16#26#, dsize) then
1660 elsif instruction = conv_std_logic_vector(16#36#, dsize) then
1664 elsif instruction = conv_std_logic_vector(16#2e#, dsize) then
1668 elsif instruction = conv_std_logic_vector(16#3e#, dsize) then
1672 elsif instruction = conv_std_logic_vector(16#66#, dsize) then
1676 if exec_cycle = T4 then
1680 elsif instruction = conv_std_logic_vector(16#76#, dsize) then
1684 elsif instruction = conv_std_logic_vector(16#6e#, dsize) then
1688 elsif instruction = conv_std_logic_vector(16#7e#, dsize) then
1693 ----------------------------------------
1694 --A.5. miscellaneous oprations.
1695 ----------------------------------------
1698 elsif instruction = conv_std_logic_vector(16#08#, dsize) then
1701 elsif instruction = conv_std_logic_vector(16#48#, dsize) then
1704 if exec_cycle = T2 then
1705 front_oe(acc_cmd, '0');
1708 elsif instruction = conv_std_logic_vector(16#28#, dsize) then
1711 elsif instruction = conv_std_logic_vector(16#68#, dsize) then
1714 if exec_cycle = T3 then
1715 front_we(acc_cmd, '0');
1719 ----------------------------------------
1721 ----------------------------------------
1722 elsif instruction = conv_std_logic_vector(16#20#, dsize) then
1723 if exec_cycle = T1 then
1724 d_print("jsr abs 2");
1727 dbuf_int_oe_n <= '0';
1731 elsif exec_cycle = T2 then
1734 dbuf_int_oe_n <= '1';
1737 --push return addr high into stack.
1740 front_oe(pch_cmd, '0');
1741 back_oe(sp_cmd, '0');
1742 back_we(sp_cmd, '0');
1745 elsif exec_cycle = T3 then
1747 front_oe(pch_cmd, '1');
1749 --push return addr low into stack.
1752 front_oe(pcl_cmd, '0');
1753 back_oe(sp_cmd, '0');
1754 back_we(sp_cmd, '0');
1758 elsif exec_cycle = T4 then
1762 front_oe(pcl_cmd, '1');
1763 back_oe(sp_cmd, '1');
1764 back_we(sp_cmd, '1');
1768 back_oe(pch_cmd, '0');
1769 back_oe(pcl_cmd, '0');
1770 dbuf_int_oe_n <= '0';
1774 elsif exec_cycle = T5 then
1777 back_oe(pch_cmd, '1');
1778 back_oe(pcl_cmd, '1');
1779 dbuf_int_oe_n <= '1';
1785 front_we(pch_cmd, '0');
1789 back_we(pcl_cmd, '0');
1792 end if; --if exec_cycle = T1 then
1795 elsif instruction = conv_std_logic_vector(16#00#, dsize) then
1797 ----------------------------------------
1798 -- A.5.5 return from interrupt
1799 ----------------------------------------
1800 elsif instruction = conv_std_logic_vector(16#40#, dsize) then
1802 ----------------------------------------
1804 ----------------------------------------
1805 elsif instruction = conv_std_logic_vector(16#4c#, dsize) then
1807 if exec_cycle = T1 then
1809 --fetch next opcode (abs low).
1812 --latch abs low data.
1813 dbuf_int_oe_n <= '0';
1816 elsif exec_cycle = T2 then
1824 dbuf_int_oe_n <= '0';
1827 front_we(pch_cmd, '0');
1832 elsif instruction = conv_std_logic_vector(16#6c#, dsize) then
1836 ----------------------------------------
1837 -- A.5.7 return from soubroutine
1838 ----------------------------------------
1839 elsif instruction = conv_std_logic_vector(16#60#, dsize) then
1840 if exec_cycle = T1 then
1844 --pop stack (decrement only)
1845 back_oe(sp_cmd, '0');
1846 back_we(sp_cmd, '0');
1851 elsif exec_cycle = T2 then
1855 back_oe(sp_cmd, '0');
1856 back_we(sp_cmd, '0');
1861 dbuf_int_oe_n <= '0';
1862 front_we(pcl_cmd, '0');
1865 elsif exec_cycle = T3 then
1867 --stack decrement stop.
1868 back_we(sp_cmd, '1');
1870 front_we(pcl_cmd, '1');
1873 back_oe(sp_cmd, '0');
1876 dbuf_int_oe_n <= '0';
1877 front_we(pch_cmd, '0');
1880 elsif exec_cycle = T4 then
1882 back_oe(sp_cmd, '1');
1885 dbuf_int_oe_n <= '1';
1886 front_we(pch_cmd, '1');
1888 --complying h/w manual...
1890 elsif exec_cycle = T5 then
1896 end if; --if exec_cycle = T1 then
1898 ----------------------------------------
1899 -- A.5.8 branch operations
1900 ----------------------------------------
1901 elsif instruction = conv_std_logic_vector(16#90#, dsize) then
1903 elsif instruction = conv_std_logic_vector(16#b0#, dsize) then
1905 a58_branch (st_C, '1');
1907 elsif instruction = conv_std_logic_vector(16#f0#, dsize) then
1909 a58_branch (st_Z, '1');
1911 elsif instruction = conv_std_logic_vector(16#30#, dsize) then
1913 elsif instruction = conv_std_logic_vector(16#d0#, dsize) then
1915 a58_branch (st_Z, '0');
1917 elsif instruction = conv_std_logic_vector(16#10#, dsize) then
1919 a58_branch (st_N, '0');
1921 elsif instruction = conv_std_logic_vector(16#50#, dsize) then
1923 elsif instruction = conv_std_logic_vector(16#70#, dsize) then
1927 ---unknown instruction!!!!
1929 report "======== unknow instruction "
1930 & conv_hex8(conv_integer(instruction))
1932 end if; --if instruction = conv_std_logic_vector(16#0a#, dsize)
1934 elsif exec_cycle = R0 then
1935 d_print(string'("reset"));
1937 front_we(pch_cmd, '1');
1938 back_we(pcl_cmd, '1');
1940 --initialize port...
1943 dbuf_int_oe_n <= '1';
1970 stat_dec_oe_n <= '1';
1971 stat_bus_oe_n <= '1';
1972 stat_set_flg_n <= '1';
1974 stat_bus_all_n <= '1';
1975 stat_bus_nz_n <= '1';
1976 stat_alu_we_n <= '1';
1981 nmi_handled_n <= '1';
1985 elsif exec_cycle = R1 or exec_cycle = N1 then
1991 front_oe(pch_cmd, '0');
1992 back_oe(sp_cmd, '0');
1993 back_we(sp_cmd, '0');
1996 if exec_cycle = R1 then
1998 elsif exec_cycle = N1 then
2002 elsif exec_cycle = R2 or exec_cycle = N2 then
2003 front_oe(pch_cmd, '1');
2008 front_oe(pcl_cmd, '0');
2009 back_oe(sp_cmd, '0');
2010 back_we(sp_cmd, '0');
2013 if exec_cycle = R2 then
2015 elsif exec_cycle = N2 then
2019 elsif exec_cycle = R3 or exec_cycle = N3 then
2020 front_oe(pcl_cmd, '1');
2025 stat_bus_oe_n <= '0';
2026 back_oe(sp_cmd, '0');
2027 back_we(sp_cmd, '0');
2030 if exec_cycle = R3 then
2032 elsif exec_cycle = N3 then
2036 elsif exec_cycle = R4 or exec_cycle = N4 then
2037 stat_bus_oe_n <= '1';
2040 front_oe(pcl_cmd, '1');
2041 back_oe(sp_cmd, '1');
2042 back_we(sp_cmd, '1');
2044 --fetch reset vector low
2046 dbuf_int_oe_n <= '0';
2047 front_we(pcl_cmd, '0');
2049 if exec_cycle = R4 then
2052 elsif exec_cycle = N4 then
2057 elsif exec_cycle = R5 or exec_cycle = N5 then
2058 front_we(pcl_cmd, '1');
2060 --fetch reset vector hi
2061 front_we(pch_cmd, '0');
2064 if exec_cycle = N5 then
2065 nmi_handled_n <= '0';
2067 --start execute cycle.
2070 elsif exec_cycle(5) = '1' then
2071 ---pc increment and next page.
2072 d_print(string'("pch next page..."));
2073 --pcl stop increment
2075 back_we(pcl_cmd, '1');
2077 back_we(pch_cmd, '0');
2079 if ('0' & exec_cycle(4 downto 0) = T1) then
2080 --if fetch cycle, preserve instrution register
2083 back_oe(pch_cmd, '0');
2085 end if; --if exec_cycle = T0 then
2087 end if; --if (set_clk'event and set_clk = '1')