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_bus_nz_n <= '0';
328 procedure set_zc_from_alu is
330 --status register n/z bit update.
331 stat_alu_we_n <= '0';
332 stat_dec_oe_n <= '1';
333 status_reg <= "00000011";
336 procedure set_nz_from_alu is
338 --status register n/z/c bit update.
339 stat_alu_we_n <= '0';
340 stat_dec_oe_n <= '1';
341 status_reg <= "10000010";
344 procedure set_nzc_from_alu is
346 --status register n/z/c bit update.
347 stat_alu_we_n <= '0';
348 stat_dec_oe_n <= '1';
349 status_reg <= "10000011";
352 procedure set_nvz_from_alu is
354 --status register n/z/v bit update.
355 stat_alu_we_n <= '0';
356 stat_dec_oe_n <= '1';
357 status_reg <= "11000010";
360 procedure set_nvzc_from_alu is
362 stat_alu_we_n <= '0';
363 stat_dec_oe_n <= '1';
364 status_reg <= "11000011";
367 --flag on/off instruction
368 procedure set_flag (int_flg : in integer; val : in std_logic) is
370 stat_dec_oe_n <= '1';
371 stat_set_flg_n <= '0';
372 --specify which to set.
373 status_reg(7 downto int_flg + 1)
375 status_reg(int_flg - 1 downto 0)
377 status_reg(int_flg) <= '1';
382 procedure set_flag0 (val : in std_logic) is
384 stat_dec_oe_n <= '1';
385 stat_set_flg_n <= '0';
386 status_reg <= "00000001";
390 procedure fetch_low is
392 d_print("fetch low 2");
393 --fetch next opcode (abs low).
395 --latch abs low data.
396 dbuf_int_oe_n <= '0';
401 procedure abs_fetch_high is
403 d_print("abs (xy) 3");
408 dbuf_int_oe_n <= '0';
413 procedure abs_latch_out is
424 procedure ea_x_out is
426 -----calucurate and output effective addr
431 procedure ea_y_out is
437 --A.2. internal execution on memory data
441 if exec_cycle = T1 then
443 elsif exec_cycle = T2 then
445 dbuf_int_oe_n <= '0';
457 if exec_cycle = T1 then
459 elsif exec_cycle = T2 then
461 elsif exec_cycle = T3 then
463 dbuf_int_oe_n <= '0';
468 procedure a2_abs_xy (is_x : in boolean) is
470 if exec_cycle = T1 then
472 elsif exec_cycle = T2 then
474 elsif exec_cycle = T3 then
478 if (is_x = true) then
483 dbuf_int_oe_n <= '0';
484 --instruction specific operation wriiten in the caller position.
486 elsif exec_cycle = T4 then
487 if ea_carry = '1' then
488 --case page boundary crossed.
489 d_print("absx 5 (page boudary crossed.)");
491 if (is_x = true) then
496 dbuf_int_oe_n <= '0';
498 pg_next_n <= not ea_carry;
502 --case page boundary not crossed. do the fetch op.
503 d_print("absx 5 (fetch)");
509 procedure a2_indir_y is
511 if exec_cycle = T1 then
516 elsif exec_cycle = T2 then
524 dbuf_int_oe_n <= '0';
527 elsif exec_cycle = T3 then
531 dbuf_int_oe_n <= '0';
534 elsif exec_cycle = T4 then
536 dbuf_int_oe_n <= '1';
542 dbuf_int_oe_n <= '0';
545 elsif exec_cycle = T5 then
546 if ea_carry = '1' then
547 --case page boundary crossed.
548 d_print("(indir), y (page boudary crossed.)");
551 dbuf_int_oe_n <= '0';
552 pg_next_n <= not ea_carry;
555 --case page boundary not crossed. do the fetch op.
556 d_print("(indir), y (next fetch)");
563 --A.3. store operation.
567 if exec_cycle = T1 then
569 elsif exec_cycle = T2 then
571 dbuf_int_oe_n <= '1';
584 if exec_cycle = T1 then
586 elsif exec_cycle = T2 then
588 elsif exec_cycle = T3 then
590 dbuf_int_oe_n <= '1';
596 procedure a3_abs_xy (is_x : in boolean) is
598 if exec_cycle = T1 then
600 elsif exec_cycle = T2 then
602 elsif exec_cycle = T3 then
606 dbuf_int_oe_n <= '1';
607 if (is_x = true) then
613 elsif exec_cycle = T4 then
614 pg_next_n <= not ea_carry;
616 if (is_x = true) then
627 procedure a3_indir_y is
629 if exec_cycle = T1 then
634 elsif exec_cycle = T2 then
642 dbuf_int_oe_n <= '0';
645 elsif exec_cycle = T3 then
649 dbuf_int_oe_n <= '0';
652 elsif exec_cycle = T4 then
654 dbuf_int_oe_n <= '1';
662 elsif exec_cycle = T5 then
667 pg_next_n <= not ea_carry;
674 ---A.4. read-modify-write operation
678 if exec_cycle = T1 then
680 elsif exec_cycle = T2 then
682 dbuf_int_oe_n <= '1';
689 elsif exec_cycle = T3 then
692 --keep data in the alu reg.
694 dbuf_int_oe_n <= '0';
696 elsif exec_cycle = T4 then
697 dbuf_int_oe_n <= '1';
699 --t5 cycle writes modified value.
711 if exec_cycle = T1 then
713 elsif exec_cycle = T2 then
715 elsif exec_cycle = T3 then
716 --T3 cycle do nothing.
719 elsif exec_cycle = T4 then
722 --t4 cycle save data in the alu register only.
723 --hardware maunual says write original data,
724 --but this implementation doesn't write because bus shortage....
727 elsif exec_cycle = T5 then
728 dbuf_int_oe_n <= '1';
730 --t5 cycle writes modified value.
739 procedure a51_push is
741 if exec_cycle = T1 then
744 elsif exec_cycle = T2 then
745 back_oe(sp_cmd, '0');
746 back_we(sp_cmd, '0');
755 procedure a52_pull is
757 if exec_cycle = T1 then
761 elsif exec_cycle = T2 then
762 --stack decrement first.
763 back_oe(sp_cmd, '0');
764 back_we(sp_cmd, '0');
769 elsif exec_cycle = T3 then
771 back_we(sp_cmd, '1');
773 ---pop data from stack.
774 back_oe(sp_cmd, '0');
776 dbuf_int_oe_n <= '0';
782 -- A.5.8 branch operations
784 procedure a58_branch (int_flg : in integer; br_cond : in std_logic) is
786 if exec_cycle = T1 then
788 if status_reg(int_flg) = br_cond then
792 dbuf_int_oe_n <= '0';
796 d_print("no branch");
799 elsif exec_cycle = T2 then
802 dbuf_int_oe_n <= '1';
805 --calc relative addr.
809 back_oe(pcl_cmd, '0');
810 back_oe(pch_cmd, '0');
811 back_we(pcl_cmd, '0');
814 elsif exec_cycle = T3 then
816 if ea_carry = '1' then
817 d_print("page crossed.");
818 --page crossed. adh calc.
819 back_we(pcl_cmd, '1');
820 back_oe(pcl_cmd, '0');
821 back_oe(pch_cmd, '0');
822 back_we(pch_cmd, '0');
826 pg_next_n <= not ea_carry;
830 --fetch cycle is done.
836 -------------------------------------------------------------
837 -------------------------------------------------------------
838 ---------------- main state machine start.... ---------------
839 -------------------------------------------------------------
840 -------------------------------------------------------------
843 if (res_n = '0') then
844 --pc l/h is reset vector.
848 elsif (res_n'event and res_n = '1') then
853 if (nmi_n'event and nmi_n = '1') then
854 --reset nmi handle status
855 nmi_handled_n <= '1';
858 if (set_clk'event and set_clk = '1' and res_n = '1') then
859 d_print(string'("-"));
861 if exec_cycle = T0 then
865 elsif exec_cycle = T1 or exec_cycle = T2 or exec_cycle = T3 or
866 exec_cycle = T4 or exec_cycle = T5 or exec_cycle = T6 then
869 ---asyncronous page change might happen.
870 back_we(pch_cmd, '1');
872 if exec_cycle = T1 then
873 d_print("decode and execute inst: "
874 & conv_hex8(conv_integer(instruction)));
875 --disable pin since jmp instruction
876 --directly enters into t2 cycle.
878 back_we(pcl_cmd, '1');
879 front_we(pch_cmd, '1');
881 --grab instruction register data.
885 --imelementation is wriiten in the order of hardware manual
888 ----------------------------------------
889 --A.1. Single byte instruction.
890 ----------------------------------------
891 if instruction = conv_std_logic_vector(16#0a#, dsize) then
895 elsif instruction = conv_std_logic_vector(16#18#, dsize) then
900 elsif instruction = conv_std_logic_vector(16#d8#, dsize) then
902 set_flag (st_D, '0');
905 elsif instruction = conv_std_logic_vector(16#58#, dsize) then
908 elsif instruction = conv_std_logic_vector(16#b8#, dsize) then
911 elsif instruction = conv_std_logic_vector(16#ca#, dsize) then
915 front_we(x_cmd, '0');
920 elsif instruction = conv_std_logic_vector(16#88#, dsize) then
924 front_we(y_cmd, '0');
929 elsif instruction = conv_std_logic_vector(16#e8#, dsize) then
933 front_we(x_cmd, '0');
938 elsif instruction = conv_std_logic_vector(16#c8#, dsize) then
942 front_we(y_cmd, '0');
946 elsif instruction = conv_std_logic_vector(16#4a#, dsize) then
950 back_oe(acc_cmd, '0');
951 front_we(acc_cmd, '0');
955 elsif instruction = conv_std_logic_vector(16#ea#, dsize) then
959 elsif instruction = conv_std_logic_vector(16#2a#, dsize) then
963 back_oe(acc_cmd, '0');
964 front_we(acc_cmd, '0');
968 elsif instruction = conv_std_logic_vector(16#38#, dsize) then
973 elsif instruction = conv_std_logic_vector(16#f8#, dsize) then
975 set_flag (st_D, '1');
978 elsif instruction = conv_std_logic_vector(16#78#, dsize) then
980 set_flag (st_I, '1');
983 elsif instruction = conv_std_logic_vector(16#aa#, dsize) then
987 front_oe(acc_cmd, '0');
988 front_we(x_cmd, '0');
990 elsif instruction = conv_std_logic_vector(16#a8#, dsize) then
994 front_oe(acc_cmd, '0');
995 front_we(y_cmd, '0');
997 elsif instruction = conv_std_logic_vector(16#ba#, dsize) then
1001 elsif instruction = conv_std_logic_vector(16#8a#, dsize) then
1005 front_oe(x_cmd, '0');
1006 front_we(acc_cmd, '0');
1008 elsif instruction = conv_std_logic_vector(16#9a#, dsize) then
1012 front_oe(x_cmd, '0');
1013 front_we(sp_cmd, '0');
1015 elsif instruction = conv_std_logic_vector(16#98#, dsize) then
1019 front_oe(y_cmd, '0');
1020 front_we(acc_cmd, '0');
1024 ----------------------------------------
1025 --A.2. internal execution on memory data
1026 ----------------------------------------
1027 elsif instruction = conv_std_logic_vector(16#69#, dsize) then
1032 back_oe(acc_cmd, '0');
1033 back_we(acc_cmd, '0');
1036 elsif instruction = conv_std_logic_vector(16#65#, dsize) then
1040 if exec_cycle = T2 then
1042 back_oe(acc_cmd, '0');
1043 back_we(acc_cmd, '0');
1047 elsif instruction = conv_std_logic_vector(16#75#, dsize) then
1051 elsif instruction = conv_std_logic_vector(16#6d#, dsize) then
1055 elsif instruction = conv_std_logic_vector(16#7d#, dsize) then
1059 elsif instruction = conv_std_logic_vector(16#79#, dsize) then
1063 elsif instruction = conv_std_logic_vector(16#61#, dsize) then
1067 elsif instruction = conv_std_logic_vector(16#71#, dsize) then
1071 elsif instruction = conv_std_logic_vector(16#29#, dsize) then
1076 back_oe(acc_cmd, '0');
1077 back_we(acc_cmd, '0');
1080 elsif instruction = conv_std_logic_vector(16#25#, dsize) then
1084 if exec_cycle = T2 then
1086 back_oe(acc_cmd, '0');
1087 back_we(acc_cmd, '0');
1091 elsif instruction = conv_std_logic_vector(16#35#, dsize) then
1095 elsif instruction = conv_std_logic_vector(16#2d#, dsize) then
1099 elsif instruction = conv_std_logic_vector(16#3d#, dsize) then
1103 if exec_cycle = T3 then
1105 back_oe(acc_cmd, '0');
1106 back_we(acc_cmd, '0');
1108 elsif exec_cycle = T4 then
1109 if ea_carry = '1' then
1111 back_oe(acc_cmd, '0');
1112 back_we(acc_cmd, '0');
1117 elsif instruction = conv_std_logic_vector(16#39#, dsize) then
1121 elsif instruction = conv_std_logic_vector(16#21#, dsize) then
1125 elsif instruction = conv_std_logic_vector(16#31#, dsize) then
1129 elsif instruction = conv_std_logic_vector(16#24#, dsize) then
1133 elsif instruction = conv_std_logic_vector(16#2c#, dsize) then
1137 if exec_cycle = T3 then
1142 elsif instruction = conv_std_logic_vector(16#c9#, dsize) then
1147 back_oe(acc_cmd, '0');
1150 elsif instruction = conv_std_logic_vector(16#c5#, dsize) then
1154 if exec_cycle = T2 then
1156 back_oe(acc_cmd, '0');
1160 elsif instruction = conv_std_logic_vector(16#d5#, dsize) then
1164 elsif instruction = conv_std_logic_vector(16#cd#, dsize) then
1168 elsif instruction = conv_std_logic_vector(16#dd#, dsize) then
1172 elsif instruction = conv_std_logic_vector(16#d9#, dsize) then
1176 if exec_cycle = T3 then
1178 back_oe(acc_cmd, '0');
1180 elsif exec_cycle = T4 then
1181 if ea_carry = '1' then
1183 back_oe(acc_cmd, '0');
1188 elsif instruction = conv_std_logic_vector(16#c1#, dsize) then
1192 elsif instruction = conv_std_logic_vector(16#d1#, dsize) then
1196 elsif instruction = conv_std_logic_vector(16#e0#, dsize) then
1201 back_oe(x_cmd, '0');
1204 elsif instruction = conv_std_logic_vector(16#e4#, dsize) then
1208 if exec_cycle = T2 then
1210 back_oe(x_cmd, '0');
1214 elsif instruction = conv_std_logic_vector(16#ec#, dsize) then
1218 elsif instruction = conv_std_logic_vector(16#c0#, dsize) then
1223 back_oe(y_cmd, '0');
1226 elsif instruction = conv_std_logic_vector(16#c4#, dsize) then
1230 elsif instruction = conv_std_logic_vector(16#cc#, dsize) then
1234 elsif instruction = conv_std_logic_vector(16#49#, dsize) then
1239 back_oe(acc_cmd, '0');
1240 back_we(acc_cmd, '0');
1243 elsif instruction = conv_std_logic_vector(16#45#, dsize) then
1247 if exec_cycle = T2 then
1249 back_oe(acc_cmd, '0');
1250 back_we(acc_cmd, '0');
1254 elsif instruction = conv_std_logic_vector(16#55#, dsize) then
1258 elsif instruction = conv_std_logic_vector(16#4d#, dsize) then
1262 elsif instruction = conv_std_logic_vector(16#5d#, dsize) then
1266 elsif instruction = conv_std_logic_vector(16#59#, dsize) then
1270 elsif instruction = conv_std_logic_vector(16#41#, dsize) then
1274 elsif instruction = conv_std_logic_vector(16#51#, dsize) then
1278 elsif instruction = conv_std_logic_vector(16#a9#, dsize) then
1282 front_we(acc_cmd, '0');
1285 elsif instruction = conv_std_logic_vector(16#a5#, dsize) then
1289 if exec_cycle = T2 then
1290 front_we(acc_cmd, '0');
1294 elsif instruction = conv_std_logic_vector(16#b5#, dsize) then
1298 elsif instruction = conv_std_logic_vector(16#ad#, dsize) then
1302 if exec_cycle = T3 then
1304 front_we(acc_cmd, '0');
1307 elsif instruction = conv_std_logic_vector(16#bd#, dsize) then
1311 if exec_cycle = T3 then
1313 front_we(acc_cmd, '0');
1315 elsif exec_cycle = T4 then
1316 if ea_carry = '1' then
1318 front_we(acc_cmd, '0');
1323 elsif instruction = conv_std_logic_vector(16#b9#, dsize) then
1327 if exec_cycle = T3 then
1329 front_we(acc_cmd, '0');
1331 elsif exec_cycle = T4 then
1332 if ea_carry = '1' then
1334 front_we(acc_cmd, '0');
1339 elsif instruction = conv_std_logic_vector(16#a1#, dsize) then
1343 elsif instruction = conv_std_logic_vector(16#b1#, dsize) then
1347 if exec_cycle = T4 then
1349 front_we(acc_cmd, '0');
1351 elsif exec_cycle = T5 then
1352 if ea_carry = '1' then
1354 front_we(acc_cmd, '0');
1359 elsif instruction = conv_std_logic_vector(16#a2#, dsize) then
1364 front_we(x_cmd, '0');
1366 elsif instruction = conv_std_logic_vector(16#a6#, dsize) then
1370 if exec_cycle = T2 then
1371 front_we(x_cmd, '0');
1375 elsif instruction = conv_std_logic_vector(16#b6#, dsize) then
1379 elsif instruction = conv_std_logic_vector(16#ae#, dsize) then
1383 if exec_cycle = T3 then
1385 front_we(x_cmd, '0');
1388 elsif instruction = conv_std_logic_vector(16#be#, dsize) then
1392 if exec_cycle = T3 then
1394 front_we(x_cmd, '0');
1396 elsif exec_cycle = T4 then
1397 if ea_carry = '1' then
1399 front_we(x_cmd, '0');
1404 elsif instruction = conv_std_logic_vector(16#a0#, dsize) then
1409 front_we(y_cmd, '0');
1411 elsif instruction = conv_std_logic_vector(16#a4#, dsize) then
1415 elsif instruction = conv_std_logic_vector(16#b4#, dsize) then
1419 elsif instruction = conv_std_logic_vector(16#ac#, dsize) then
1423 if exec_cycle = T3 then
1425 front_we(y_cmd, '0');
1428 elsif instruction = conv_std_logic_vector(16#bc#, dsize) then
1432 elsif instruction = conv_std_logic_vector(16#09#, dsize) then
1437 back_oe(acc_cmd, '0');
1438 back_we(acc_cmd, '0');
1441 elsif instruction = conv_std_logic_vector(16#05#, dsize) then
1445 if exec_cycle = T2 then
1447 back_oe(acc_cmd, '0');
1448 back_we(acc_cmd, '0');
1452 elsif instruction = conv_std_logic_vector(16#15#, dsize) then
1456 elsif instruction = conv_std_logic_vector(16#0d#, dsize) then
1460 elsif instruction = conv_std_logic_vector(16#1d#, dsize) then
1464 elsif instruction = conv_std_logic_vector(16#19#, dsize) then
1468 elsif instruction = conv_std_logic_vector(16#01#, dsize) then
1472 elsif instruction = conv_std_logic_vector(16#11#, dsize) then
1476 elsif instruction = conv_std_logic_vector(16#e9#, dsize) then
1480 elsif instruction = conv_std_logic_vector(16#e5#, dsize) then
1484 elsif instruction = conv_std_logic_vector(16#f5#, dsize) then
1488 elsif instruction = conv_std_logic_vector(16#ed#, dsize) then
1492 elsif instruction = conv_std_logic_vector(16#fd#, dsize) then
1496 elsif instruction = conv_std_logic_vector(16#f9#, dsize) then
1500 if exec_cycle = T3 then
1502 back_oe(acc_cmd, '0');
1503 back_we(acc_cmd, '0');
1505 elsif exec_cycle = T4 then
1506 if ea_carry = '1' then
1509 back_oe(acc_cmd, '0');
1510 back_we(acc_cmd, '0');
1515 elsif instruction = conv_std_logic_vector(16#e1#, dsize) then
1519 elsif instruction = conv_std_logic_vector(16#f1#, dsize) then
1525 ----------------------------------------
1526 ---A.3. store operation.
1527 ----------------------------------------
1528 elsif instruction = conv_std_logic_vector(16#85#, dsize) then
1532 if exec_cycle = T2 then
1533 front_oe(acc_cmd, '0');
1536 elsif instruction = conv_std_logic_vector(16#95#, dsize) then
1540 elsif instruction = conv_std_logic_vector(16#8d#, dsize) then
1544 if exec_cycle = T3 then
1545 front_oe(acc_cmd, '0');
1548 elsif instruction = conv_std_logic_vector(16#9d#, dsize) then
1552 if exec_cycle = T4 then
1553 front_oe(acc_cmd, '0');
1556 elsif instruction = conv_std_logic_vector(16#99#, dsize) then
1560 if exec_cycle = T4 then
1561 front_oe(acc_cmd, '0');
1564 elsif instruction = conv_std_logic_vector(16#81#, dsize) then
1568 elsif instruction = conv_std_logic_vector(16#91#, dsize) then
1572 if exec_cycle = T5 then
1573 front_oe(acc_cmd, '0');
1576 elsif instruction = conv_std_logic_vector(16#86#, dsize) then
1580 if exec_cycle = T2 then
1581 front_oe(x_cmd, '0');
1584 elsif instruction = conv_std_logic_vector(16#96#, dsize) then
1588 elsif instruction = conv_std_logic_vector(16#8e#, dsize) then
1592 elsif instruction = conv_std_logic_vector(16#84#, dsize) then
1596 if exec_cycle = T2 then
1597 front_oe(y_cmd, '0');
1600 elsif instruction = conv_std_logic_vector(16#94#, dsize) then
1604 elsif instruction = conv_std_logic_vector(16#8c#, dsize) then
1609 ----------------------------------------
1610 ---A.4. read-modify-write operation
1611 ----------------------------------------
1612 elsif instruction = conv_std_logic_vector(16#06#, dsize) then
1616 elsif instruction = conv_std_logic_vector(16#16#, dsize) then
1620 elsif instruction = conv_std_logic_vector(16#0e#, dsize) then
1624 elsif instruction = conv_std_logic_vector(16#1e#, dsize) then
1628 elsif instruction = conv_std_logic_vector(16#c6#, dsize) then
1632 if exec_cycle = T4 then
1636 elsif instruction = conv_std_logic_vector(16#d6#, dsize) then
1640 elsif instruction = conv_std_logic_vector(16#ce#, dsize) then
1644 elsif instruction = conv_std_logic_vector(16#de#, dsize) then
1648 elsif instruction = conv_std_logic_vector(16#e6#, dsize) then
1652 if exec_cycle = T4 then
1656 elsif instruction = conv_std_logic_vector(16#f6#, dsize) then
1660 elsif instruction = conv_std_logic_vector(16#ee#, dsize) then
1664 if exec_cycle = T5 then
1668 elsif instruction = conv_std_logic_vector(16#fe#, dsize) then
1672 elsif instruction = conv_std_logic_vector(16#46#, dsize) then
1676 elsif instruction = conv_std_logic_vector(16#56#, dsize) then
1680 elsif instruction = conv_std_logic_vector(16#4e#, dsize) then
1684 elsif instruction = conv_std_logic_vector(16#5e#, dsize) then
1688 elsif instruction = conv_std_logic_vector(16#26#, dsize) then
1692 elsif instruction = conv_std_logic_vector(16#36#, dsize) then
1696 elsif instruction = conv_std_logic_vector(16#2e#, dsize) then
1700 elsif instruction = conv_std_logic_vector(16#3e#, dsize) then
1704 elsif instruction = conv_std_logic_vector(16#66#, dsize) then
1708 -- if exec_cycle = T4 then
1709 -- set_nzc_from_alu;
1712 elsif instruction = conv_std_logic_vector(16#76#, dsize) then
1716 elsif instruction = conv_std_logic_vector(16#6e#, dsize) then
1720 elsif instruction = conv_std_logic_vector(16#7e#, dsize) then
1725 ----------------------------------------
1726 --A.5. miscellaneous oprations.
1727 ----------------------------------------
1730 elsif instruction = conv_std_logic_vector(16#08#, dsize) then
1733 elsif instruction = conv_std_logic_vector(16#48#, dsize) then
1736 if exec_cycle = T2 then
1737 front_oe(acc_cmd, '0');
1740 elsif instruction = conv_std_logic_vector(16#28#, dsize) then
1743 elsif instruction = conv_std_logic_vector(16#68#, dsize) then
1746 if exec_cycle = T3 then
1747 front_we(acc_cmd, '0');
1751 ----------------------------------------
1753 ----------------------------------------
1754 elsif instruction = conv_std_logic_vector(16#20#, dsize) then
1755 if exec_cycle = T1 then
1756 d_print("jsr abs 2");
1759 dbuf_int_oe_n <= '0';
1763 elsif exec_cycle = T2 then
1766 dbuf_int_oe_n <= '1';
1769 --push return addr high into stack.
1772 front_oe(pch_cmd, '0');
1773 back_oe(sp_cmd, '0');
1774 back_we(sp_cmd, '0');
1777 elsif exec_cycle = T3 then
1779 front_oe(pch_cmd, '1');
1781 --push return addr low into stack.
1784 front_oe(pcl_cmd, '0');
1785 back_oe(sp_cmd, '0');
1786 back_we(sp_cmd, '0');
1790 elsif exec_cycle = T4 then
1794 front_oe(pcl_cmd, '1');
1795 back_oe(sp_cmd, '1');
1796 back_we(sp_cmd, '1');
1800 back_oe(pch_cmd, '0');
1801 back_oe(pcl_cmd, '0');
1802 dbuf_int_oe_n <= '0';
1806 elsif exec_cycle = T5 then
1809 back_oe(pch_cmd, '1');
1810 back_oe(pcl_cmd, '1');
1811 dbuf_int_oe_n <= '1';
1817 front_we(pch_cmd, '0');
1821 back_we(pcl_cmd, '0');
1824 end if; --if exec_cycle = T1 then
1827 elsif instruction = conv_std_logic_vector(16#00#, dsize) then
1829 ----------------------------------------
1830 -- A.5.5 return from interrupt
1831 ----------------------------------------
1832 elsif instruction = conv_std_logic_vector(16#40#, dsize) then
1834 ----------------------------------------
1836 ----------------------------------------
1837 elsif instruction = conv_std_logic_vector(16#4c#, dsize) then
1839 if exec_cycle = T1 then
1841 --fetch next opcode (abs low).
1844 --latch abs low data.
1845 dbuf_int_oe_n <= '0';
1848 elsif exec_cycle = T2 then
1856 dbuf_int_oe_n <= '0';
1859 front_we(pch_cmd, '0');
1864 elsif instruction = conv_std_logic_vector(16#6c#, dsize) then
1868 ----------------------------------------
1869 -- A.5.7 return from soubroutine
1870 ----------------------------------------
1871 elsif instruction = conv_std_logic_vector(16#60#, dsize) then
1872 if exec_cycle = T1 then
1876 --pop stack (decrement only)
1877 back_oe(sp_cmd, '0');
1878 back_we(sp_cmd, '0');
1883 elsif exec_cycle = T2 then
1887 back_oe(sp_cmd, '0');
1888 back_we(sp_cmd, '0');
1893 dbuf_int_oe_n <= '0';
1894 front_we(pcl_cmd, '0');
1897 elsif exec_cycle = T3 then
1899 --stack decrement stop.
1900 back_we(sp_cmd, '1');
1902 front_we(pcl_cmd, '1');
1905 back_oe(sp_cmd, '0');
1908 dbuf_int_oe_n <= '0';
1909 front_we(pch_cmd, '0');
1912 elsif exec_cycle = T4 then
1914 back_oe(sp_cmd, '1');
1917 dbuf_int_oe_n <= '1';
1918 front_we(pch_cmd, '1');
1920 --complying h/w manual...
1922 elsif exec_cycle = T5 then
1928 end if; --if exec_cycle = T1 then
1930 ----------------------------------------
1931 -- A.5.8 branch operations
1932 ----------------------------------------
1933 elsif instruction = conv_std_logic_vector(16#90#, dsize) then
1935 a58_branch (st_C, '0');
1937 elsif instruction = conv_std_logic_vector(16#b0#, dsize) then
1939 a58_branch (st_C, '1');
1941 elsif instruction = conv_std_logic_vector(16#f0#, dsize) then
1943 a58_branch (st_Z, '1');
1945 elsif instruction = conv_std_logic_vector(16#30#, dsize) then
1947 elsif instruction = conv_std_logic_vector(16#d0#, dsize) then
1949 a58_branch (st_Z, '0');
1951 elsif instruction = conv_std_logic_vector(16#10#, dsize) then
1953 a58_branch (st_N, '0');
1955 elsif instruction = conv_std_logic_vector(16#50#, dsize) then
1957 elsif instruction = conv_std_logic_vector(16#70#, dsize) then
1961 ---unknown instruction!!!!
1963 report "======== unknow instruction "
1964 & conv_hex8(conv_integer(instruction))
1966 end if; --if instruction = conv_std_logic_vector(16#0a#, dsize)
1968 elsif exec_cycle = R0 then
1969 d_print(string'("reset"));
1971 front_we(pch_cmd, '1');
1972 back_we(pcl_cmd, '1');
1974 --initialize port...
1977 dbuf_int_oe_n <= '1';
2004 stat_dec_oe_n <= '1';
2005 stat_bus_oe_n <= '1';
2006 stat_set_flg_n <= '1';
2008 stat_bus_all_n <= '1';
2009 stat_bus_nz_n <= '1';
2010 stat_alu_we_n <= '1';
2015 nmi_handled_n <= '1';
2019 elsif exec_cycle = R1 or exec_cycle = N1 then
2025 front_oe(pch_cmd, '0');
2026 back_oe(sp_cmd, '0');
2027 back_we(sp_cmd, '0');
2030 if exec_cycle = R1 then
2032 elsif exec_cycle = N1 then
2036 elsif exec_cycle = R2 or exec_cycle = N2 then
2037 front_oe(pch_cmd, '1');
2042 front_oe(pcl_cmd, '0');
2043 back_oe(sp_cmd, '0');
2044 back_we(sp_cmd, '0');
2047 if exec_cycle = R2 then
2049 elsif exec_cycle = N2 then
2053 elsif exec_cycle = R3 or exec_cycle = N3 then
2054 front_oe(pcl_cmd, '1');
2059 stat_bus_oe_n <= '0';
2060 back_oe(sp_cmd, '0');
2061 back_we(sp_cmd, '0');
2064 if exec_cycle = R3 then
2066 elsif exec_cycle = N3 then
2070 elsif exec_cycle = R4 or exec_cycle = N4 then
2071 stat_bus_oe_n <= '1';
2074 front_oe(pcl_cmd, '1');
2075 back_oe(sp_cmd, '1');
2076 back_we(sp_cmd, '1');
2078 --fetch reset vector low
2080 dbuf_int_oe_n <= '0';
2081 front_we(pcl_cmd, '0');
2083 if exec_cycle = R4 then
2086 elsif exec_cycle = N4 then
2091 elsif exec_cycle = R5 or exec_cycle = N5 then
2092 front_we(pcl_cmd, '1');
2094 --fetch reset vector hi
2095 front_we(pch_cmd, '0');
2098 if exec_cycle = N5 then
2099 nmi_handled_n <= '0';
2101 --start execute cycle.
2104 elsif exec_cycle(5) = '1' then
2105 ---pc increment and next page.
2106 d_print(string'("pch next page..."));
2107 --pcl stop increment
2109 back_we(pcl_cmd, '1');
2111 back_we(pch_cmd, '0');
2113 if ('0' & exec_cycle(4 downto 0) = T1) then
2114 --if fetch cycle, preserve instrution register
2117 back_oe(pch_cmd, '0');
2119 end if; --if exec_cycle = T0 then
2121 end if; --if (set_clk'event and set_clk = '1')