OpenCores
URL https://opencores.org/ocsvn/system05/system05/trunk

Subversion Repositories system05

[/] [system05/] [trunk/] [rtl/] [vhdl/] [cpu05.vhd] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dilbert57
--===========================================================================--
2
--
3
--  S Y N T H E Z I A B L E    CPU05   6805 comaptible CPU
4
--
5
--  This core adheres to the GNU public license  
6
--
7
-- File name      : cpu05.vhd
8
--
9
-- Purpose        : 6805 compatible CPU
10
--                  Differences to 6805
11
--                  64 K addressing range
12
--                  stack starts at $00FF and is 128 bytes deep
13
--                  
14
-- Dependencies   : ieee.Std_Logic_1164
15
--                  ieee.std_logic_unsigned
16
--
17
-- Author         : John E. Kent      
18
--
19
--
20
--=====================================================================
21
--
22
-- Revision History
23
--
24
--=====================================================================
25
--
26
-- 0.0   6 Sept 2002 - John Kent - design started
27
-- 0.1  30 May  2004 - John Kent - Initial release
28
--
29
--
30
library ieee;
31
use ieee.std_logic_1164.all;
32
use ieee.std_logic_unsigned.all;
33
 
34
entity cpu05 is
35
        port (
36
         clk       : in  std_logic;
37
    rst       : in  std_logic;
38
    vma       : out std_logic;
39
    rw        : out std_logic;
40
    addr      : out std_logic_vector(15 downto 0);
41
    data_in   : in  std_logic_vector(7 downto 0);
42
         data_out  : out std_logic_vector(7 downto 0);
43
         irq_ext   : in  std_logic;
44
         irq_timer : in  std_logic;
45
         irq_uart  : in  std_logic );
46
end;
47
 
48
architecture cpu_arch of cpu05 is
49
        type state_type is (reset_state, reset1_state, reset2_state,
50
                       fetch_state, decode_state, exec_state, halt_state,
51
                            brbit_state,
52
                                                          branch_state, bsr_state, jsr_state, jsr1_state, jmp_state,
53
                                                          swi_state, stop_state,
54
                                                          rti_state, rti_cc_state, rti_ac_state, rti_ix_state, rti_pch_state, rti_pcl_state,
55
                                                          rts_state, rts_pch_state, rts_pcl_state,
56
                                                          wait_state, wait1_state, wait2_state, wait3_state, wait4_state,
57
                                                          int_state, int1_state, int2_state, int3_state, int4_state, int5_state, int6_state,
58
                       dir_state, ext_state, ix2_state, ix1_state, ix0_state,
59
                                                     write_state );
60
        type addr_type is (reset_addr, idle_addr, fetch_addr, read_addr, write_addr, push_addr, pull_addr, vect_hi_addr, vect_lo_addr );
61
        type data_type is (ac_data, ix_data, cc_data, md_data, pc_lo_data, pc_hi_data );
62
        type pc_type is (reset_pc, latch_pc, inc_pc, jmp_pc, bra_pc, pull_lo_pc, pull_hi_pc );
63
   type ea_type is (reset_ea, latch_ea, fetch_first_ea, fetch_next_ea, loadix_ea, addix_ea, addpc_ea );
64
   type op_type is (reset_op, latch_op, fetch_op );
65
   type ac_type is (reset_ac, latch_ac, load_ac, pull_ac );
66
        type ix_type is (reset_ix, latch_ix, load_ix, pull_ix );
67
        type sp_type is (reset_sp, latch_sp, load_sp, inc_sp, dec_sp );
68
   type cc_type is (reset_cc, latch_cc, load_cc, pull_cc );
69
        type md_type is (reset_md, latch_md, load_md, fetch_md );
70
        type iv_type is (latch_iv, rst_iv, swi_iv, irq_iv, tim_iv, uart_iv );
71
        type left_type  is (ac_left, ix_left, md_left );
72
        type right_type is (md_right, bset_right, bclr_right, zero_right, one_right );
73
   type alu_type   is (alu_add, alu_adc, alu_sub, alu_sbc,
74
                       alu_and, alu_ora, alu_eor,
75
                       alu_tst, alu_inc, alu_dec, alu_clr, alu_neg, alu_com,
76
                                                     alu_lsr, alu_lsl, alu_ror, alu_rol, alu_asr,
77
                                                     alu_sei, alu_cli, alu_sec, alu_clc,
78
                                                          alu_bset, alu_bclr, alu_btst,
79
                                                     alu_ld, alu_st, alu_nop );
80
 
81
  constant HFLAG : integer := 4;
82
  constant IFLAG : integer := 3;
83
  constant NFLAG : integer := 2;
84
  constant ZFLAG : integer := 1;
85
  constant CFLAG : integer := 0;
86
 
87
        --
88
        -- internal registers
89
        --
90
        signal ac:          std_logic_vector(7 downto 0);        -- accumulator
91
        signal ix:          std_logic_vector(7 downto 0);  -- index register
92
        signal sp:          std_logic_vector(6 downto 0);  -- stack pointer
93
        signal cc:          std_logic_vector(4 downto 0);  -- condition codes from alu
94
        signal pc:              std_logic_vector(15 downto 0); -- program counter for opcode access
95
        signal ea:          std_logic_vector(15 downto 0); -- effective addres for memory access
96
        signal op:          std_logic_vector(7 downto 0);  -- opcode register
97
        signal md:          std_logic_vector(7 downto 0);  -- memory data
98
        signal iv:          std_logic_vector(2 downto 0);  -- interrupt vector number
99
        signal state:       state_type;
100
 
101
        --
102
        -- unregistered signals
103
        -- (combinational logic)
104
        --
105
   signal alu_left:    std_logic_vector(8 downto 0);  -- alu left input (bit 8 for carry)
106
   signal alu_right:   std_logic_vector(8 downto 0);  -- alu right input
107
        signal alu_out:     std_logic_vector(8 downto 0);  -- alu result output (unlatched)
108
        signal cc_out:      std_logic_vector(4 downto 0);  -- alu condition code outout (unlatched)
109
        signal bset_data_out: std_logic_vector(7 downto 0);
110
        signal bclr_data_out: std_logic_vector(7 downto 0);
111
        signal next_state:  state_type;
112
 
113
   --
114
        -- Syncronous Register Controls
115
        --
116
        signal ac_ctrl:     ac_type;
117
        signal ix_ctrl:     ix_type;
118
        signal sp_ctrl:     sp_type;
119
        signal cc_ctrl:     cc_type;
120
   signal pc_ctrl:     pc_type;
121
   signal ea_ctrl:     ea_type;
122
   signal op_ctrl:     op_type;
123
        signal md_ctrl:     md_type;
124
   signal iv_ctrl:     iv_type;
125
 
126
        --
127
        -- Asynchronous Multiplexer Controls
128
        --
129
        signal addr_ctrl:   addr_type;       -- address bus mutiplexer
130
        signal data_ctrl: data_type;   -- data output mutiplexer
131
   signal left_ctrl:   left_type;       -- Left ALU input
132
        signal right_ctrl:  right_type;     -- Right ALU input
133
   signal alu_ctrl:    alu_type;        -- ALU opeartion
134
 
135
   --
136
        -- bit set decoder table
137
        --
138
   component bset_rom is
139
     port (
140
       addr     : in  Std_Logic_Vector(2 downto 0);
141
            data     : out Std_Logic_Vector(7 downto 0)
142
     );
143
   end component bset_rom;
144
   --
145
        -- bit clear decoder table
146
        --
147
   component bclr_rom is
148
     port (
149
       addr     : in  Std_Logic_Vector(2 downto 0);
150
            data     : out Std_Logic_Vector(7 downto 0)
151
     );
152
   end component bclr_rom;
153
 
154
begin
155
 
156
   rom_set : bset_rom port map (
157
          addr       => op(3 downto 1),
158
     data       => bset_data_out
159
          );
160
 
161
   rom_clear : bclr_rom port map (
162
          addr       => op(3 downto 1),
163
     data       => bclr_data_out
164
          );
165
 
166
 
167
----------------------------------
168
--
169
-- opcode register
170
--
171
----------------------------------
172
 
173
op_reg: process( clk, op_ctrl, data_in, op )
174
begin
175
  if clk'event and clk = '0' then
176
    case op_ctrl is
177
         when reset_op =>
178
           op <= "10011101";    -- reset with NOP
179
         when fetch_op =>
180
      op <= data_in;
181
         when others =>
182
--       when latch_op =>
183
           op <= op;
184
    end case;
185
  end if;
186
end process;
187
 
188
-----------------------------------
189
--
190
-- accumulator
191
--
192
------------------------------------
193
ac_reg : process( clk, ac_ctrl, alu_out, ac, ix, data_in )
194
begin
195
   if clk'event and clk = '0' then
196
     case ac_ctrl is
197
     when reset_ac =>             -- released from reset
198
            ac <= "00000000";
199
          when load_ac =>               -- single or dual operation
200
            ac <= alu_out(7 downto 0);
201
          when pull_ac =>                -- read acc / increment sp
202
                 ac <= data_in;
203
          when others =>               -- halt on undefine states
204
--        when latch_ac =>             -- no operation on acc
205
            ac <= ac;
206
     end case;
207
  end if;
208
end process;
209
 
210
------------------------------------
211
--
212
-- condition code register
213
--
214
------------------------------------
215
cc_reg : process( clk, cc_ctrl, cc_out  )
216
begin
217
  if clk'event and clk = '0' then
218
     case cc_ctrl is
219
     when reset_cc =>             -- released from reset
220
            cc <= "00000";
221
          when load_cc =>               -- single or dual operation
222
            cc <= cc_out;
223
          when pull_cc =>                -- read cc / increment sp
224
                 cc <= data_in(4 downto 0);
225
          when others =>               -- halt on undefine states
226
--        when latch_cc =>             -- no operation on acc
227
            cc <= cc;
228
     end case;
229
  end if;
230
end process;
231
 
232
------------------------------------
233
--
234
-- index register
235
--
236
------------------------------------
237
ix_reg : process( clk, ix_ctrl, alu_out, ac, ix, data_in )
238
begin
239
  if clk'event and clk = '0' then
240
    case ix_ctrl is
241
     when reset_ix =>                 -- released from reset
242
            ix <= "00000000";
243
          when load_ix =>                   -- execute /  = alu out
244
            ix <= alu_out(7 downto 0);
245
          when pull_ix =>                    -- read ixreg / increment sp
246
                 ix <= data_in;
247
          when others =>
248
--        when latch_ix =>                 -- no change in ix
249
            ix <= ix;
250
    end case;
251
  end if;
252
end process;
253
 
254
 
255
------------------------------------
256
--
257
-- stack pointer
258
--
259
------------------------------------
260
sp_reg : process( clk, sp_ctrl, sp )
261
begin
262
  if clk'event and clk = '0' then
263
    case sp_ctrl is
264
     when reset_sp =>                 -- released from reset
265
       sp <= "1111111";
266
          when inc_sp =>                   -- pop registers
267
            sp <= sp + 1;
268
     when dec_sp =>                   -- push registes
269
                 sp <= sp - 1;
270
          when others =>
271
--        when latch_sp =>                 -- no change in sp
272
            sp <= sp;
273
    end case;
274
  end if;
275
end process;
276
 
277
------------------------------------
278
--
279
-- program counter
280
--
281
------------------------------------
282
pc_reg : process( clk, pc_ctrl, pc, ea, data_in )
283
variable offset : std_logic_vector(15 downto 0);
284
begin
285
  if clk'event and clk = '0' then
286
    case pc_ctrl is
287
     when reset_pc =>                 -- released from reset
288
       pc <= "0000000000000000";
289
          when inc_pc =>                   -- fetch next opcode
290
            pc <= pc + 1;
291
     when jmp_pc =>                   -- load pc with effective address
292
                 pc <= ea;
293
     when bra_pc =>                   -- add effective address to pc
294
            if ea(7) = '0' then                            -- sign extend offset
295
                   offset := "00000000" & ea(7 downto 0);
296
       else
297
                   offset := "11111111" & ea(7 downto 0);
298
                 end if;
299
                 pc <= pc + offset;
300
     when pull_lo_pc =>               -- load pc lo byte from memory
301
                 pc(15 downto 8) <= pc(15 downto 8);
302
                 pc(7 downto 0)  <= data_in;
303
     when pull_hi_pc =>               -- load pc hi byte from memory
304
                 pc(15 downto 8) <= data_in;
305
                 pc(7 downto 0)  <= pc(7 downto 0);
306
          when others =>                   -- halt on undefine states
307
--        when latch_pc =>                 -- no change in pc
308
            pc <= pc;
309
    end case;
310
  end if;
311
end process;
312
 
313
------------------------------------
314
--
315
-- effective address register
316
--
317
------------------------------------
318
ea_reg: process( clk, ea_ctrl, ea, pc, ix, data_in )
319
variable offset : std_logic_vector(15 downto 0);
320
begin
321
  if clk'event and clk = '0' then
322
    case ea_ctrl is
323
     when reset_ea =>                     -- released from reset / fetch
324
       ea <= "0000000000000000";
325
          when loadix_ea =>                    -- load ea with index register
326
            ea <= "00000000" & ix;
327
          when addpc_ea =>                     -- add pc to ea
328
            if ea(7) = '0' then                            -- sign extend offset
329
                   offset := "00000000" & ea(7 downto 0);
330
       else
331
                   offset := "11111111" & ea(7 downto 0);
332
                 end if;
333
            ea <= offset + pc;
334
     when addix_ea =>                     -- add index register to ea
335
                 ea <= ea + ("00000000" & ix );
336
     when fetch_first_ea =>               -- load ea lo byte from memory
337
                 ea(15 downto 8) <= "00000000";
338
                 ea(7 downto 0) <= data_in;
339
     when fetch_next_ea =>               -- load ea with second from memory
340
                 ea(15 downto 8) <= ea(7 downto 0);
341
                 ea(7 downto 0) <= data_in;
342
          when others =>                   -- halt on undefine states
343
--        when latch_ea =>                 -- no change in ea
344
            ea <= ea;
345
    end case;
346
  end if;
347
end process;
348
 
349
----------------------------------
350
--
351
-- memory data register 
352
-- latch memory byte input
353
--
354
----------------------------------
355
 
356
md_reg: process( clk, md_ctrl, data_in, md )
357
begin
358
  if clk'event and clk = '0' then
359
    case md_ctrl is
360
         when reset_md =>
361
           md <= "00000000";
362
         when latch_md =>
363
           md <= md;
364
         when load_md =>                  -- latch alu output
365
      md <= alu_out(7 downto 0);
366
         when fetch_md =>
367
      md <= data_in;
368
         when others =>
369
      null;
370
    end case;
371
  end if;
372
end process;
373
 
374
----------------------------------
375
--
376
-- interrupt vector register
377
--
378
----------------------------------
379
 
380
iv_reg: process( clk, iv_ctrl, iv )
381
begin
382
  if clk'event and clk = '0' then
383
    case iv_ctrl is
384
         when rst_iv =>
385
           iv <= "111"; -- $FFFE/$FFFF
386
         when swi_iv =>
387
           iv <= "110"; -- $FFFC/$FFFD
388
         when irq_iv =>
389
      iv <= "101"; -- $FFFA/$FFFB
390
         when tim_iv =>
391
           iv <= "100"; -- $FFF8/$FFF9
392
    when uart_iv =>
393
           iv <= "011"; -- $FFFA/$FFFB
394
         when others =>
395
--       when latch_iv =>
396
           iv <= iv;
397
    end case;
398
  end if;
399
end process;
400
 
401
----------------------------------
402
--
403
-- Address output multiplexer
404
-- Work out which register to apply to the address bus
405
-- Note that the multiplexer output is asyncronous
406
--
407
----------------------------------
408
 
409
mux_addr: process( clk, addr_ctrl, pc, ea, sp, iv )
410
begin
411
   case addr_ctrl is
412
     when reset_addr =>                 -- when held in reset
413
       addr <= "1111111111111111";
414
                 vma  <= '0';
415
                 rw   <= '1';
416
          when fetch_addr =>                 -- fetch opcode from pc
417
                 addr <= pc;
418
                 vma  <= '1';
419
                 rw   <= '1';
420
          when read_addr =>                  -- read from memory
421
            addr <= ea;
422
                 vma  <= '1';
423
                 rw   <= '1';
424
          when write_addr =>                 -- write to memory
425
            addr <= ea;
426
                 vma  <= '1';
427
                 rw   <= '0';
428
          when pull_addr =>                  -- read from stack
429
            addr <= ("000000001" & sp);
430
                 vma  <= '1';
431
                 rw   <= '1';
432
          when push_addr =>                  -- write to stack
433
            addr <= ("000000001" & sp);
434
                 vma  <= '1';
435
                 rw   <= '0';
436
          when vect_hi_addr =>               -- fetch interrupt vector hi
437
            addr <= "111111111111" & iv & "0";
438
                 vma  <= '1';
439
                 rw   <= '1';
440
          when vect_lo_addr =>               -- fetch interrupt vector lo
441
            addr <= "111111111111" & iv & "1";
442
                 vma  <= '1';
443
                 rw   <= '1';
444
          when others =>                   -- undefined all high
445
       addr <= "1111111111111111";
446
                 vma  <= '0';
447
                 rw   <= '1';
448
   end case;
449
end process;
450
 
451
----------------------------------
452
--
453
-- Data Output Multiplexer
454
-- select data to be written to memory
455
-- note that the output is asynchronous
456
--
457
----------------------------------
458
 
459
mux_data: process( clk, data_ctrl, md, pc, cc, ac, ix )
460
variable data_out_v : std_logic_vector(7 downto 0);
461
begin
462
    case data_ctrl is
463
         when cc_data =>                   -- save condition codes
464
      data_out <= "000" & cc;
465
         when ac_data =>                   -- save accumulator
466
      data_out <= ac;
467
         when ix_data =>                   -- save index register
468
      data_out <= ix;
469
         when pc_lo_data =>                  -- save pc low byte
470
      data_out <= pc(7 downto 0);
471
         when pc_hi_data =>
472
      data_out <= pc(15 downto 8); -- save pc high byte
473
         when others =>
474
--       when md_data =>                  -- alu latched output
475
      data_out <= md;
476
    end case;
477
end process;
478
 
479
----------------------------------
480
--
481
-- alu left mux
482
-- asynchronous input as register is already latched
483
--
484
----------------------------------
485
 
486
mux_left: process( clk, left_ctrl, ac, ix, md )
487
begin
488
    case left_ctrl is
489
         when ac_left =>
490
           alu_left <= "0" & ac; -- dual op argument
491
         when ix_left =>
492
           alu_left <= "0" & ix; -- dual op argument
493
         when md_left =>
494
           alu_left <= "0" & md;
495
         when others =>
496
      alu_left <= "000000000";
497
    end case;
498
end process;
499
 
500
 
501
----------------------------------
502
--
503
-- alu right mux
504
-- asynchronous input as register is already latched
505
--
506
----------------------------------
507
 
508
mux_right: process( clk, right_ctrl, data_in, bset_data_out, bclr_data_out, md )
509
begin
510
    case right_ctrl is
511
         when bset_right =>
512
           alu_right <= "0" & bset_data_out;
513
         when bclr_right =>
514
      alu_right <= "0" & bclr_data_out;
515
         when zero_right =>
516
           alu_right <= "000000000";
517
         when one_right =>
518
           alu_right <= "000000001";
519
         when others =>
520
--       when md_right =>
521
           alu_right <= "0" & md; -- dual op argument
522
  end case;
523
end process;
524
 
525
 
526
----------------------------------
527
--
528
-- Arithmetic Logic Unit
529
--
530
----------------------------------
531
 
532
mux_alu: process( clk, alu_ctrl, cc, alu_left, alu_right )
533
variable alu_v   : std_logic_vector(8 downto 0);
534
variable low_v   : std_logic_vector(4 downto 0);
535
variable high_v  : std_logic_vector(4 downto 0);
536
begin
537
 
538
    case alu_ctrl is
539
         when alu_bset =>
540
           alu_v := alu_left or alu_right;      -- bit
541
         when alu_bclr =>
542
           alu_v := alu_left and alu_right;     -- bclr
543
         when alu_btst =>
544
           alu_v := alu_left and alu_right;     -- tst
545
         when alu_add =>
546
                low_v   := ("0" & alu_left(3 downto 0)) + ("0" & alu_right(3 downto 0));
547
                high_v  := ("0" & alu_left(7 downto 4)) + ("0" & alu_right(7 downto 4)) + low_v(4);
548
           alu_v   := high_v(4 downto 0) & low_v(3 downto 0);     -- add
549
         when alu_adc =>
550
                low_v   := ("0" & alu_left(3 downto 0)) + ("0" & alu_right(3 downto 0)) + ("0000" & cc(CFLAG));
551
                high_v  := ("0" & alu_left(7 downto 4)) + ("0" & alu_right(7 downto 4)) + low_v(4);
552
           alu_v   := high_v(4 downto 0) & low_v(3 downto 0);     -- adc
553
         when alu_sub =>
554
           alu_v   := alu_left - alu_right;     -- sub / cmp
555
         when alu_sbc =>
556
           alu_v   := alu_left - alu_right - ("00000000" & cc(CFLAG));  -- sbc
557
         when alu_and =>
558
           alu_v   := alu_left and alu_right;   -- and/bit
559
         when alu_ora =>
560
           alu_v   := alu_left or alu_right;    -- or
561
         when alu_eor =>
562
           alu_v   := alu_left xor alu_right;   -- eor/xor
563
         when alu_lsl =>
564
           alu_v   := alu_left(7 downto 0) & "0";         -- lsl
565
         when alu_lsr =>
566
           alu_v   := alu_left(0) & "0" & alu_left(7 downto 1);   -- lsr
567
         when alu_asr =>
568
           alu_v   := alu_left(0) & alu_left(7) & alu_left(7 downto 1);  -- asr
569
         when alu_rol =>
570
           alu_v   := alu_left(7 downto 0) & cc(CFLAG);  -- rol
571
         when alu_ror =>
572
           alu_v   := alu_left(0) & cc(CFLAG) & alu_left(7 downto 1);    -- ror
573
         when alu_inc =>
574
           alu_v   := alu_left + "000000001";   -- inc
575
         when alu_dec =>
576
           alu_v   := alu_left(8 downto 0) - "000000001"; -- dec
577
         when alu_neg =>
578
           alu_v   := "000000000" - alu_left(8 downto 0);        -- neg
579
         when alu_com =>
580
           alu_v   := not alu_left(8 downto 0);  -- com
581
         when alu_clr =>
582
           alu_v  := "000000000";          -- clr
583
         when alu_ld =>
584
           alu_v  := alu_right(8 downto 0);
585
         when alu_st =>
586
           alu_v  := alu_left(8 downto 0);
587
         when others =>
588
           alu_v  := alu_left(8 downto 0); -- nop
589
    end case;
590
 
591
         --
592
         -- carry bit
593
         --
594
    case alu_ctrl is
595
         when alu_add | alu_adc | alu_sub | alu_sbc |
596
              alu_lsl | alu_lsr | alu_rol | alu_ror | alu_asr |
597
              alu_neg | alu_com =>
598
      cc_out(CFLAG) <= alu_v(8);
599
         when alu_btst =>
600
      cc_out(CFLAG) <= not( alu_v(7) or alu_v(6) or alu_v(5) or alu_v(4) or
601
                           alu_v(3) or alu_v(2) or alu_v(1) or alu_v(0) );
602
         when alu_sec =>
603
      cc_out(CFLAG) <= '1';
604
         when alu_clc =>
605
      cc_out(CFLAG) <= '0';
606
         when others =>
607
      cc_out(CFLAG) <= cc(CFLAG);
608
    end case;
609
 
610
         --
611
         -- Zero flag
612
         --
613
    case alu_ctrl is
614
         when alu_add | alu_adc | alu_sub | alu_sbc |
615
              alu_and | alu_ora | alu_eor |
616
              alu_lsl | alu_lsr | alu_rol | alu_ror | alu_asr |
617
              alu_inc | alu_dec | alu_neg | alu_com | alu_clr |
618
                   alu_ld  | alu_st =>
619
      cc_out(ZFLAG) <= not( alu_v(7) or alu_v(6) or alu_v(5) or alu_v(4) or
620
                                 alu_v(3) or alu_v(2) or alu_v(1) or alu_v(0) );
621
         when others =>
622
      cc_out(ZFLAG) <= cc(ZFLAG);
623
    end case;
624
 
625
    --
626
         -- negative flag
627
         --
628
    case alu_ctrl is
629
         when alu_add | alu_adc | alu_sub | alu_sbc |
630
              alu_and | alu_ora | alu_eor |
631
              alu_lsl | alu_lsr | alu_rol | alu_ror | alu_asr |
632
              alu_inc | alu_dec | alu_neg | alu_com | alu_clr |
633
                        alu_ld  | alu_st =>
634
      cc_out(NFLAG) <= alu_v(7);
635
         when others =>
636
      cc_out(NFLAG) <= cc(NFLAG);
637
    end case;
638
 
639
    --
640
         -- Interrupt mask flag
641
    --
642
    case alu_ctrl is
643
         when alu_sei =>
644
                cc_out(IFLAG) <= '1';               -- set interrupt mask
645
         when alu_cli =>
646
                cc_out(IFLAG) <= '0';               -- clear interrupt mask
647
         when others =>
648
                cc_out(IFLAG) <= cc(IFLAG);             -- interrupt mask
649
    end case;
650
 
651
    --
652
    -- Half Carry flag
653
         --
654
    case alu_ctrl is
655
         when alu_add | alu_adc =>
656
                cc_out(HFLAG) <= low_v(4);
657
         when others =>
658
                cc_out(HFLAG) <= cc(HFLAG);
659
    end case;
660
 
661
         alu_out <= alu_v;
662
 
663
end process;
664
 
665
 
666
------------------------------------
667
--
668
-- state sequencer
669
--
670
------------------------------------
671
 
672
sequencer : process( state, data_in,
673
                     ac, cc, ix, sp, ea, md, pc, op,
674
                     irq_ext, irq_timer, irq_uart )
675
begin
676
                  case state is
677
--
678
-- RESET:
679
-- Here if processor held in reset
680
-- On release of reset go to RESET1
681
--
682
          when reset_state =>        -- release from reset
683
                 ac_ctrl    <= reset_ac;
684
                 cc_ctrl    <= reset_cc;
685
                 ix_ctrl    <= reset_ix;
686
                 sp_ctrl    <= reset_sp;
687
            pc_ctrl    <= reset_pc;
688
            op_ctrl    <= reset_op;
689
            ea_ctrl    <= reset_ea;
690
                 md_ctrl    <= reset_md;
691
                                iv_ctrl    <= rst_iv;
692
            left_ctrl  <= ac_left;        -- Left ALU input
693
                 right_ctrl <= md_right;       -- Right ALU input
694
            alu_ctrl   <= alu_nop;        -- ALU opeartion
695
                 addr_ctrl  <= reset_addr;     -- address bus mutiplexer
696
                 data_ctrl  <= md_data;        -- data output mutiplexer
697
                           next_state <= reset1_state;
698
--
699
-- RESET1:
700
-- address bus = reset vector hi
701
-- Load PC high with high byte
702
-- go to RESET2
703
--
704
          when reset1_state =>        -- fetch hi reset vector
705
                  ac_ctrl    <= latch_ac;
706
                  cc_ctrl    <= latch_cc;
707
                  ix_ctrl    <= latch_ix;
708
                  sp_ctrl    <= latch_sp;
709
                                 pc_ctrl    <= pull_hi_pc;
710
             op_ctrl    <= latch_op;
711
             ea_ctrl    <= latch_ea;
712
                  md_ctrl    <= latch_md;
713
                  iv_ctrl    <= latch_iv;
714
             left_ctrl  <= ac_left;       -- Left ALU input
715
                  right_ctrl <= md_right;      -- Right ALU input
716
             alu_ctrl   <= alu_nop;       -- ALU opeartion
717
                                 addr_ctrl  <= vect_hi_addr;
718
                  data_ctrl  <= md_data;       -- data output mutiplexer
719
                            next_state <= reset2_state;
720
--
721
-- RESET2:
722
-- address bus = reset vector lo
723
-- Load PC low with low byte
724
-- go to FETCH
725
-- 
726
          when reset2_state =>        -- fetch low reset vector
727
                  ac_ctrl    <= latch_ac;
728
                  cc_ctrl    <= latch_cc;
729
                  ix_ctrl    <= latch_ix;
730
                  sp_ctrl    <= latch_sp;
731
                                 pc_ctrl    <= pull_lo_pc;
732
             op_ctrl    <= latch_op;
733
             ea_ctrl    <= latch_ea;
734
                  md_ctrl    <= latch_md;
735
                  iv_ctrl    <= latch_iv;
736
             left_ctrl  <= ac_left;       -- Left ALU input
737
                  right_ctrl <= md_right;      -- Right ALU input
738
             alu_ctrl   <= alu_nop;       -- ALU opeartion
739
                                 addr_ctrl  <= vect_lo_addr;
740
                  data_ctrl  <= md_data;       -- data output mutiplexer
741
                            next_state <= fetch_state;
742
--
743
-- FETCH:
744
-- fetch opcode,
745
-- advance the pc,
746
-- clear the effective address (ea) register
747
-- goto DECODE
748
--
749
          when fetch_state =>         -- fetch instruction
750
             case op(7 downto 4) is
751
--                               when "0000" =>                         -- BRSET/ BRCLR
752
--                                 null;
753
--                               when "0001" =>                         -- BSET/ BCLR
754
--                                 null;
755
--                               when "0010" =>                         -- BR conditional
756
--                                 null;
757
--                               when "0011" =>                         --      single op direct
758
--                                 null;
759
                                 when "0100" =>            -- single op accum
760
                    ac_ctrl    <= load_ac;
761
                                        cc_ctrl    <= load_cc;
762
                    ix_ctrl    <= latch_ix;
763
                    sp_ctrl    <= latch_sp;
764
                                        left_ctrl  <= ac_left;
765
                                   case op( 3 downto 0 ) is
766
                                   when "0000" =>            -- neg
767
                                          right_ctrl <= zero_right;
768
                                          alu_ctrl   <= alu_neg;
769
                                   when "0011" =>            -- com
770
                                          right_ctrl <= zero_right;
771
                                          alu_ctrl   <= alu_com;
772
                                   when "0100" =>            -- lsr
773
                                          right_ctrl <= zero_right;
774
                                          alu_ctrl   <= alu_lsr;
775
                                   when "0110" =>            -- ror
776
                                          right_ctrl <= zero_right;
777
                                          alu_ctrl   <= alu_ror;
778
                                   when "0111" =>            -- asr
779
                                          right_ctrl <= zero_right;
780
                                          alu_ctrl   <= alu_asr;
781
                                   when "1000" =>            -- lsl
782
                                          right_ctrl <= zero_right;
783
                                          alu_ctrl   <= alu_lsl;
784
                                   when "1001" =>            -- rol
785
                                          right_ctrl <= zero_right;
786
                                          alu_ctrl   <= alu_rol;
787
                                   when "1010" =>            -- dec
788
                                          right_ctrl <= one_right;
789
                                          alu_ctrl   <= alu_dec;
790
                                   when "1011" =>            -- undef
791
                                          right_ctrl <= zero_right;
792
                                          alu_ctrl   <= alu_nop;
793
                                   when "1100" =>            -- inc
794
                                          right_ctrl <= one_right;
795
                                          alu_ctrl   <= alu_inc;
796
                                   when "1101" =>            -- tst
797
                                          right_ctrl <= zero_right;
798
                                          alu_ctrl   <= alu_tst;
799
                                   when "1110" =>            -- undef
800
                                          right_ctrl <= zero_right;
801
                                          alu_ctrl   <= alu_nop;
802
                                   when "1111" =>            -- clr
803
                                          right_ctrl <= zero_right;
804
                                          alu_ctrl   <= alu_clr;
805
                                        when others =>
806
                                          right_ctrl <= zero_right;
807
                                          alu_ctrl   <= alu_nop;
808
                                        end case;
809
 
810
                                 when "0101" =>            -- single op ix reg
811
                    ac_ctrl    <= latch_ac;
812
                                        cc_ctrl    <= load_cc;
813
                    ix_ctrl    <= load_ix;
814
                    sp_ctrl    <= latch_sp;
815
                                        left_ctrl  <= ix_left;
816
                                   case op( 3 downto 0 ) is
817
                                   when "0000" =>            -- neg
818
                                          right_ctrl <= zero_right;
819
                                          alu_ctrl   <= alu_neg;
820
                                   when "0011" =>            -- com
821
                                          right_ctrl <= zero_right;
822
                                          alu_ctrl   <= alu_com;
823
                                   when "0100" =>            -- lsr
824
                                          right_ctrl <= zero_right;
825
                                          alu_ctrl   <= alu_lsr;
826
                                   when "0110" =>            -- ror
827
                                          right_ctrl <= zero_right;
828
                                          alu_ctrl   <= alu_ror;
829
                                   when "0111" =>            -- asr
830
                                          right_ctrl <= zero_right;
831
                                          alu_ctrl   <= alu_asr;
832
                                   when "1000" =>            -- lsl
833
                                          right_ctrl <= zero_right;
834
                                          alu_ctrl   <= alu_lsl;
835
                                   when "1001" =>            -- rol
836
                                          right_ctrl <= zero_right;
837
                                          alu_ctrl   <= alu_rol;
838
                                   when "1010" =>            -- dec
839
                                          right_ctrl <= one_right;
840
                                          alu_ctrl   <= alu_dec;
841
                                   when "1011" =>            -- undef
842
                                          right_ctrl <= zero_right;
843
                                          alu_ctrl   <= alu_nop;
844
                                   when "1100" =>            -- inc
845
                                          right_ctrl <= one_right;
846
                                          alu_ctrl   <= alu_inc;
847
                                   when "1101" =>            -- tst
848
                                          right_ctrl <= zero_right;
849
                                          alu_ctrl   <= alu_tst;
850
                                   when "1110" =>            -- undef
851
                                          right_ctrl <= zero_right;
852
                                          alu_ctrl   <= alu_nop;
853
                                   when "1111" =>            -- clr
854
                                          right_ctrl <= zero_right;
855
                                          alu_ctrl   <= alu_clr;
856
                                        when others =>
857
                                          right_ctrl <= zero_right;
858
                                          alu_ctrl   <= alu_nop;
859
                                        end case;
860
--           when "0110" =>            -- single op IX1
861
--             null;
862
--           when "0111" =>            -- single op IX0
863
--             null;
864
--           when "1000" =>            -- inherent stack operators
865
--             null;
866
                                 when "1001" =>            -- inherent operators
867
                                   case op( 3 downto 0 ) is
868
--                                 when "0000" =>            -- undef
869
--                                        null;
870
--                 when "0001" =>            -- undef
871
--                                        null;
872
--                              when "0010" =>            -- undef
873
--                                        null;
874
--                                 when "0011" =>            -- undef
875
--                                        null;
876
--                                 when "0100" =>            -- undef
877
--                                        null;
878
--                                 when "0101" =>            -- undef
879
--                                        null;
880
--                                 when "0110" =>            -- undef
881
--                                        null;
882
                                   when "0111" =>            -- tax
883
                 ac_ctrl    <= latch_ac;
884
                                          cc_ctrl    <= latch_cc;
885
                 ix_ctrl    <= load_ix;
886
                      sp_ctrl    <= latch_sp;
887
                                          left_ctrl  <= ac_left;
888
                                          right_ctrl <= bclr_right;
889
                                          alu_ctrl   <= alu_st;
890
 
891
                                   when "1000" =>            -- clc
892
                 ac_ctrl    <= latch_ac;
893
                                          cc_ctrl    <= load_cc;
894
                 ix_ctrl    <= latch_ix;
895
                      sp_ctrl    <= latch_sp;
896
                                          left_ctrl  <= ac_left;
897
                                          right_ctrl <= bclr_right;
898
                                          alu_ctrl   <= alu_clc;
899
 
900
                                   when "1001" =>            -- sec
901
                 ac_ctrl    <= latch_ac;
902
                                          cc_ctrl    <= load_cc;
903
                 ix_ctrl    <= latch_ix;
904
                      sp_ctrl    <= latch_sp;
905
                                          left_ctrl  <= ac_left;
906
                                          right_ctrl <= bclr_right;
907
                                          alu_ctrl   <= alu_sec;
908
 
909
                                   when "1010" =>            -- cli
910
                 ac_ctrl    <= latch_ac;
911
                                          cc_ctrl    <= load_cc;
912
                 ix_ctrl    <= latch_ix;
913
                      sp_ctrl    <= latch_sp;
914
                                          left_ctrl  <= ac_left;
915
                                          right_ctrl <= bclr_right;
916
                                          alu_ctrl   <= alu_cli;
917
 
918
                                   when "1011" =>            -- sei
919
                 ac_ctrl    <= latch_ac;
920
                                          cc_ctrl    <= load_cc;
921
                 ix_ctrl    <= latch_ix;
922
                      sp_ctrl    <= latch_sp;
923
                                          left_ctrl  <= ac_left;
924
                                          right_ctrl <= bclr_right;
925
                                          alu_ctrl   <= alu_sei;
926
 
927
                                   when "1100" =>            -- rsp
928
                 ac_ctrl    <= latch_ac;
929
                                          cc_ctrl    <= latch_cc;
930
                 ix_ctrl    <= latch_ix;
931
                                          sp_ctrl    <= reset_sp;
932
                                          left_ctrl  <= ac_left;
933
                                          right_ctrl <= bclr_right;
934
                                          alu_ctrl   <= alu_nop;
935
 
936
--                                 when "1101" =>            -- nop
937
--                                        null;
938
--                                 when "1110" =>            -- undef
939
--                                        null;
940
                                   when "1111" =>            -- txa
941
                 ac_ctrl    <= load_ac;
942
                                          cc_ctrl    <= latch_cc;
943
                 ix_ctrl    <= latch_ix;
944
                      sp_ctrl    <= latch_sp;
945
                                          left_ctrl  <= ix_left;
946
                                          right_ctrl <= bclr_right;
947
                                          alu_ctrl   <= alu_st;
948
 
949
                                        when others =>
950
                 ac_ctrl    <= latch_ac;
951
                                          cc_ctrl    <= latch_cc;
952
                 ix_ctrl    <= latch_ix;
953
                      sp_ctrl    <= latch_sp;
954
                                          left_ctrl  <= ix_left;
955
                                          right_ctrl <= bclr_right;
956
                                          alu_ctrl   <= alu_nop;
957
                                        end case;
958
             --
959
                            -- dual operand addressing modes
960
                            --
961
                                 when "1010" |            -- dual op imm
962
                                      "1011" |            -- dual op dir
963
                                      "1100" |            -- dual op ext
964
                                      "1101" |            -- dual op ix2
965
                                      "1110" |            -- dual op ix1
966
                                      "1111" =>           -- dual op ix0
967
                                   case op( 3 downto 0 ) is
968
                                   when "0000" =>            -- sub
969
                 ac_ctrl    <= load_ac;
970
                                          cc_ctrl    <= load_cc;
971
                 ix_ctrl    <= latch_ix;
972
                      sp_ctrl    <= latch_sp;
973
                                          left_ctrl  <= ac_left;
974
                                          right_ctrl <= md_right;
975
                                          alu_ctrl   <= alu_sub;
976
                                   when "0001" =>            -- cmp
977
                 ac_ctrl    <= latch_ac;
978
                                          cc_ctrl    <= load_cc;
979
                 ix_ctrl    <= latch_ix;
980
                      sp_ctrl    <= latch_sp;
981
                                          left_ctrl  <= ac_left;
982
                                          right_ctrl <= md_right;
983
                                          alu_ctrl   <= alu_sub;
984
                                   when "0010" =>            -- sbc
985
                 ac_ctrl    <= load_ac;
986
                                          cc_ctrl    <= load_cc;
987
                 ix_ctrl    <= latch_ix;
988
                      sp_ctrl    <= latch_sp;
989
                                          left_ctrl  <= ac_left;
990
                                          right_ctrl <= md_right;
991
                                          alu_ctrl   <= alu_sbc;
992
                                   when "0011" =>            -- cpx
993
                 ac_ctrl    <= latch_ac;
994
                                          cc_ctrl    <= load_cc;
995
                 ix_ctrl    <= latch_ix;
996
                      sp_ctrl    <= latch_sp;
997
                                          left_ctrl  <= ix_left;
998
                                          right_ctrl <= md_right;
999
                                          alu_ctrl   <= alu_sub;
1000
                                   when "0100" =>            -- and
1001
                 ac_ctrl    <= load_ac;
1002
                                          cc_ctrl    <= load_cc;
1003
                 ix_ctrl    <= latch_ix;
1004
                      sp_ctrl    <= latch_sp;
1005
                                          left_ctrl  <= ac_left;
1006
                                          right_ctrl <= md_right;
1007
                                          alu_ctrl   <= alu_and;
1008
                                   when "0101" =>            -- bit
1009
                 ac_ctrl    <= latch_ac;
1010
                                          cc_ctrl    <= load_cc;
1011
                 ix_ctrl    <= latch_ix;
1012
                      sp_ctrl    <= latch_sp;
1013
                                          left_ctrl  <= ac_left;
1014
                                          right_ctrl <= md_right;
1015
                                          alu_ctrl   <= alu_and;
1016
                                   when "0110" =>            -- lda
1017
                 ac_ctrl    <= load_ac;
1018
                                          cc_ctrl    <= load_cc;
1019
                 ix_ctrl    <= latch_ix;
1020
                      sp_ctrl    <= latch_sp;
1021
                                          left_ctrl  <= ac_left;
1022
                                          right_ctrl <= md_right;
1023
                                          alu_ctrl   <= alu_ld;
1024
                                   when "0111" =>            -- sta
1025
                 ac_ctrl    <= latch_ac;
1026
                                          cc_ctrl    <= load_cc;
1027
                 ix_ctrl    <= latch_ix;
1028
                      sp_ctrl    <= latch_sp;
1029
                                          left_ctrl  <= ac_left;
1030
                                          right_ctrl <= md_right;
1031
                                          alu_ctrl   <= alu_st;
1032
                                   when "1000" =>            -- eor
1033
                 ac_ctrl    <= load_ac;
1034
                                          cc_ctrl    <= load_cc;
1035
                 ix_ctrl    <= latch_ix;
1036
                      sp_ctrl    <= latch_sp;
1037
                                          left_ctrl  <= ac_left;
1038
                                          right_ctrl <= md_right;
1039
                                          alu_ctrl   <= alu_eor;
1040
                                   when "1001" =>            -- adc
1041
                 ac_ctrl    <= load_ac;
1042
                                          cc_ctrl    <= load_cc;
1043
                 ix_ctrl    <= latch_ix;
1044
                      sp_ctrl    <= latch_sp;
1045
                                          left_ctrl  <= ac_left;
1046
                                          right_ctrl <= md_right;
1047
                                          alu_ctrl   <= alu_adc;
1048
                                   when "1010" =>            -- ora
1049
                 ac_ctrl    <= load_ac;
1050
                                          cc_ctrl    <= load_cc;
1051
                 ix_ctrl    <= latch_ix;
1052
                      sp_ctrl    <= latch_sp;
1053
                                          left_ctrl  <= ac_left;
1054
                                          right_ctrl <= md_right;
1055
                                          alu_ctrl   <= alu_ora;
1056
                                   when "1011" =>            -- add
1057
                 ac_ctrl    <= load_ac;
1058
                                          cc_ctrl    <= load_cc;
1059
                 ix_ctrl    <= latch_ix;
1060
                      sp_ctrl    <= latch_sp;
1061
                                          left_ctrl  <= ac_left;
1062
                                          right_ctrl <= md_right;
1063
                                          alu_ctrl   <= alu_add;
1064
--                                 when "1100" =>            -- jmp
1065
--                                        null;
1066
--                                 when "1101" =>            -- jsr
1067
--                                        null;
1068
                                   when "1110" =>            -- ldx
1069
                 ac_ctrl    <= latch_ac;
1070
                                          cc_ctrl    <= load_cc;
1071
                 ix_ctrl    <= load_ix;
1072
                      sp_ctrl    <= latch_sp;
1073
                                          left_ctrl  <= ix_left;
1074
                                          right_ctrl <= md_right;
1075
                                          alu_ctrl   <= alu_ld;
1076
                                   when "1111" =>            -- stx
1077
                 ac_ctrl    <= latch_ac;
1078
                                          cc_ctrl    <= load_cc;
1079
                 ix_ctrl    <= latch_ix;
1080
                      sp_ctrl    <= latch_sp;
1081
                                          left_ctrl  <= ix_left;
1082
                                          right_ctrl <= md_right;
1083
                                          alu_ctrl   <= alu_st;
1084
                                        when others =>
1085
                 ac_ctrl    <= latch_ac;
1086
                                          cc_ctrl    <= latch_cc;
1087
                 ix_ctrl    <= latch_ix;
1088
                      sp_ctrl    <= latch_sp;
1089
                                          left_ctrl  <= ac_left;
1090
                                          right_ctrl <= md_right;
1091
                                          alu_ctrl   <= alu_nop;
1092
                                        end case;
1093
                                 when others =>
1094
               ac_ctrl    <= latch_ac;
1095
                                        cc_ctrl    <= latch_cc;
1096
               ix_ctrl    <= latch_ix;
1097
                    sp_ctrl    <= latch_sp;
1098
                                        left_ctrl  <= ac_left;
1099
                                        right_ctrl <= md_right;
1100
                                        alu_ctrl   <= alu_nop;
1101
                                 end case;
1102
 
1103
             ea_ctrl    <= latch_ea;
1104
             md_ctrl    <= latch_md;
1105
                                 pc_ctrl    <= inc_pc;
1106
             op_ctrl    <= fetch_op;
1107
                                 addr_ctrl  <= fetch_addr;
1108
                  data_ctrl  <= md_data;       -- data output mutiplexer
1109
             if irq_ext = '1' and cc(IFLAG) = '0' then
1110
                                   iv_ctrl    <= irq_iv;
1111
                                        next_state <= int_state;
1112
                                 elsif irq_timer = '1' and cc(IFLAG) = '0' then
1113
                                   iv_ctrl    <= tim_iv;
1114
                                        next_state <= int_state;
1115
                                 elsif irq_uart = '1' and cc(IFLAG) = '0' then
1116
                                   iv_ctrl    <= uart_iv;
1117
                                        next_state <= int_state;
1118
                                 else
1119
                    iv_ctrl    <= latch_iv;
1120
                              next_state <= decode_state;
1121
                                 end if;
1122
--
1123
-- DECODE:
1124
-- decode the new opcode, 
1125
-- fetch the next byte into the low byte of the ea ,
1126
-- work out if you need to advance the pc, (two or three byte op)
1127
-- work out the next state based on the addressing mode.
1128
-- evaluate conditional branch execution
1129
--
1130
          when decode_state =>             -- decode instruction / fetch next byte
1131
                  ac_ctrl    <= latch_ac;
1132
                  cc_ctrl    <= latch_cc;
1133
                  ix_ctrl    <= latch_ix;
1134
                  sp_ctrl    <= latch_sp;
1135
             ea_ctrl    <= fetch_first_ea;
1136
                  md_ctrl    <= fetch_md;
1137
             op_ctrl    <= latch_op;
1138
                  iv_ctrl    <= latch_iv;
1139
             left_ctrl  <= ac_left;       -- Left ALU input
1140
                  right_ctrl <= md_right;      -- Right ALU input
1141
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1142
                                 addr_ctrl  <= fetch_addr;
1143
                  data_ctrl  <= md_data;       -- data output mutiplexer
1144
                         case op(7 downto 4) is -- addressing modes
1145
                                 --
1146
                                 -- branch on bit set / clear
1147
                                 --
1148
                         when "0000" =>
1149
                                   pc_ctrl    <= inc_pc;     -- advance the pc
1150
                                   next_state <= dir_state;
1151
                                 --
1152
                                 -- bit set / clear direct page
1153
                                 --
1154
                                 when "0001" =>
1155
                                   pc_ctrl    <= inc_pc;     -- advance the pc
1156
                                   next_state <= dir_state;
1157
                                 --
1158
                                 -- branch on condition codes
1159
             --   if condtion = true
1160
             --       go to "branch" state
1161
             --   if conition = false
1162
             --       go to "fetch" state
1163
                                 --
1164
                                 when "0010" =>
1165
                                   pc_ctrl    <= inc_pc;     -- advance the pc
1166
                                   case op(3 downto 0) is
1167
                                        when "0000" => -- bra
1168
                                          next_state <= branch_state;
1169
                                        when "0001" => -- brn
1170
                                          next_state <= fetch_state;
1171
                                        when "0010" => -- bhi
1172
                                          if cc(CFLAG) = '0' and cc(ZFLAG) = '0' then
1173
                                            next_state <= branch_state;
1174
                                          else
1175
                                            next_state <= fetch_state;
1176
                                          end if;
1177
                                        when "0011" => -- bls
1178
                                          if cc(CFLAG) = '1' or cc(ZFLAG) = '1' then
1179
                                            next_state <= branch_state;
1180
                                          else
1181
                                            next_state <= fetch_state;
1182
                                          end if;
1183
                                        when "0100" => -- bcc
1184
                                          if cc(CFLAG) = '0' then
1185
                                            next_state <= branch_state;
1186
                                          else
1187
                                            next_state <= fetch_state;
1188
                                          end if;
1189
                                        when "0101" => -- bcs
1190
                                          if cc(CFLAG) = '1' then
1191
                                            next_state <= branch_state;
1192
                                          else
1193
                                            next_state <= fetch_state;
1194
                                          end if;
1195
                                        when "0110" => -- bne
1196
                                          if cc(ZFLAG) = '0' then
1197
                                            next_state <= branch_state;
1198
                                          else
1199
                                            next_state <= fetch_state;
1200
                                          end if;
1201
                                        when "0111" => -- beq
1202
                                          if cc(ZFLAG) = '1' then
1203
                                            next_state <= branch_state;
1204
                                          else
1205
                                            next_state <= fetch_state;
1206
                                          end if;
1207
                                        when "1000" => -- bhcc
1208
                                          if cc(HFLAG) = '0' then
1209
                                            next_state <= branch_state;
1210
                                          else
1211
                                            next_state <= fetch_state;
1212
                                          end if;
1213
                                        when "1001" => -- bhcs
1214
                                          if cc(HFLAG) = '1' then
1215
                                            next_state <= branch_state;
1216
                                          else
1217
                                            next_state <= fetch_state;
1218
                                          end if;
1219
                                        when "1010" => -- bpl
1220
                                          if cc(NFLAG) = '0' then
1221
                                            next_state <= branch_state;
1222
                                          else
1223
                                            next_state <= fetch_state;
1224
                                          end if;
1225
                                        when "1011" => -- bmi
1226
                                          if cc(NFLAG) = '1' then
1227
                                            next_state <= branch_state;
1228
                                          else
1229
                                            next_state <= fetch_state;
1230
                                          end if;
1231
                                        when "1100" => -- bmc
1232
                                          if cc(IFLAG) = '0' then
1233
                                            next_state <= branch_state;
1234
                                          else
1235
                                            next_state <= fetch_state;
1236
                                          end if;
1237
                                        when "1101" => -- bms
1238
                                          if cc(IFLAG) = '1' then
1239
                                            next_state <= branch_state;
1240
                                          else
1241
                                            next_state <= fetch_state;
1242
                                          end if;
1243
                                        when "1110" => -- bil
1244
                                          if irq_ext = '0' then
1245
                                            next_state <= branch_state;
1246
                                          else
1247
                                            next_state <= fetch_state;
1248
                                          end if;
1249
                                        when "1111" => -- bih
1250
                                          if irq_ext = '1' then
1251
                                            next_state <= branch_state;
1252
                                          else
1253
                                            next_state <= fetch_state;
1254
                                          end if;
1255
                                        when others =>
1256
                                          null;
1257
                                        end case; -- end of conditional branch decode
1258
                                 --
1259
                                 -- Single Operand direct addressing
1260
                                 --
1261
                                 when "0011" =>
1262
                                   pc_ctrl    <= inc_pc;     -- advance the pc (2 byte instruction)
1263
                                   next_state <= dir_state;
1264
                                 --
1265
                                 -- Single Operand accumulator
1266
                                 --
1267
                                 when "0100" =>
1268
                                   pc_ctrl    <= latch_pc;
1269
                                   next_state <= fetch_state;
1270
                                 --
1271
                                 -- Single Operand index register
1272
                                 --
1273
                                 when "0101" =>
1274
                                   pc_ctrl    <= latch_pc;
1275
                                   next_state <= fetch_state;
1276
                                 --
1277
                                 -- Single Operand memory 8 bit indexed
1278
                                 --
1279
                                 when "0110" =>
1280
                                   pc_ctrl    <= inc_pc;     -- advance the pc (2 byte instruction)
1281
                                   next_state <= ix1_state;
1282
                                 --
1283
                                 -- Single Operand memory 0 bit indexed
1284
                                 --
1285
                                 when "0111" =>
1286
                                   pc_ctrl    <= latch_pc;     -- hold the pc (1 byte instruction)
1287
                                   next_state <= ix0_state;
1288
             --
1289
                                 -- stack and interrupt operators
1290
                                 --
1291
                                 when "1000" =>
1292
                                   pc_ctrl    <= latch_pc;
1293
                                   case op(3 downto 0) is
1294
                                        when "0000" =>
1295
                                          next_state <= rti_state;
1296
                                        when "0001" =>
1297
                                          next_state <= rts_state;
1298
               when "0011" =>
1299
                                          next_state <= swi_state;
1300
                                   when "1110" =>
1301
                                          next_state <= stop_state;
1302
                                        when "1111" =>
1303
                                          next_state <= wait_state;
1304
                                        when others =>
1305
                                          next_state <= fetch_state;
1306
                                        end case; -- end of stack decode
1307
                                 --
1308
                                 -- Inherent operators
1309
                                 --
1310
                                 when "1001" =>
1311
                                   pc_ctrl    <= latch_pc;
1312
                                        next_state <= fetch_state;
1313
                                 --
1314
                                 -- dual operand immediate addressing
1315
                                 --
1316
                  when "1010" =>
1317
                                   pc_ctrl   <= inc_pc;     -- advance the pc (2 byte instruction)
1318
                                   case op(3 downto 0) is
1319
                                        when "1101" => -- bsr
1320
                                          next_state <= bsr_state;
1321
                                        when others =>
1322
                                          next_state <= fetch_state;
1323
                                        end case;
1324
                                 --
1325
                                 -- dual operand direct addressing
1326
                                 --
1327
                                 when "1011" =>
1328
                                   pc_ctrl    <= inc_pc;     -- advance the pc (2 byte instruction)
1329
                                        next_state <= dir_state;
1330
                                 --
1331
                                 -- dual operand extended addressing
1332
                                 --
1333
                            when "1100" =>
1334
                                   pc_ctrl    <= inc_pc;     -- advance the pc (3 byte instruction)
1335
                                   next_state <= ext_state;
1336
                                 --
1337
                                 -- dual operand 16 bit indexed addressing
1338
                                 --
1339
                                 when "1101" =>
1340
                                   pc_ctrl    <= inc_pc;     -- advance the pc (3 byte instruction)
1341
                                        next_state <= ix2_state;
1342
                                 --
1343
                                 -- dual operand 8 bit indexed addressing
1344
                                 --
1345
                            when "1110" =>
1346
                                   pc_ctrl    <= inc_pc;     -- advance the pc (3 byte instruction)
1347
                                        next_state <= ix1_state;
1348
                                 --
1349
                                 -- dual operand direct page indexed addressing
1350
                                 --
1351
                                 when "1111" =>
1352
                                   pc_ctrl    <= latch_pc;
1353
                                        next_state <= ix0_state;
1354
             --
1355
                                 -- catch undefined states
1356
                                 --
1357
                                 when others =>
1358
                                   pc_ctrl    <= latch_pc;
1359
                                   next_state <= fetch_state;
1360
                                 end case;
1361
                                 -- end of instruction decode state
1362
                          --
1363
                          -- perform addressing state sequence
1364
                          --
1365
                          when ext_state => -- fetch second address byte
1366
                  ac_ctrl    <= latch_ac;
1367
                  ix_ctrl    <= latch_ix;
1368
                  sp_ctrl    <= latch_sp;
1369
                  cc_ctrl    <= latch_cc;
1370
                                 pc_ctrl    <= inc_pc;
1371
             ea_ctrl    <= fetch_next_ea;
1372
             op_ctrl    <= latch_op;
1373
                  md_ctrl    <= latch_md;
1374
                  iv_ctrl    <= latch_iv;
1375
             left_ctrl  <= ac_left;       -- Left ALU input
1376
                  right_ctrl <= md_right;      -- Right ALU input
1377
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1378
                                 addr_ctrl  <= fetch_addr;     -- read effective address
1379
                  data_ctrl  <= pc_lo_data;       -- read memory data
1380
                            next_state <= dir_state;
1381
 
1382
                          when ix2_state => -- fetch second index offest byte
1383
                  ac_ctrl    <= latch_ac;
1384
                  ix_ctrl    <= latch_ix;
1385
                  sp_ctrl    <= latch_sp;
1386
                  cc_ctrl    <= latch_cc;
1387
                                 pc_ctrl    <= inc_pc;
1388
             ea_ctrl    <= fetch_next_ea;
1389
             op_ctrl    <= latch_op;
1390
                  md_ctrl    <= fetch_md;
1391
                  iv_ctrl    <= latch_iv;
1392
             left_ctrl  <= ac_left;       -- Left ALU input
1393
                  right_ctrl <= md_right;      -- Right ALU input
1394
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1395
                                 addr_ctrl  <= fetch_addr;
1396
                  data_ctrl  <= pc_lo_data;
1397
                            next_state <= ix1_state;
1398
 
1399
                          when ix1_state => -- add ixreg to effective address
1400
                  ac_ctrl    <= latch_ac;
1401
                  ix_ctrl    <= latch_ix;
1402
                  sp_ctrl    <= latch_sp;
1403
                  cc_ctrl    <= latch_cc;
1404
                                 pc_ctrl    <= latch_pc;
1405
             ea_ctrl    <= addix_ea;
1406
             op_ctrl    <= latch_op;
1407
                  md_ctrl    <= latch_md;
1408
                  iv_ctrl    <= latch_iv;
1409
             left_ctrl  <= ac_left;       -- Left ALU input
1410
                  right_ctrl <= md_right;      -- Right ALU input
1411
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1412
                                 addr_ctrl  <= idle_addr;
1413
                  data_ctrl  <= pc_lo_data;
1414
                            next_state <= dir_state;
1415
 
1416
                          when ix0_state => -- load effective address with ixreg
1417
                  ac_ctrl    <= latch_ac;
1418
                  cc_ctrl    <= latch_cc;
1419
                  ix_ctrl    <= latch_ix;
1420
                  sp_ctrl    <= latch_sp;
1421
             ea_ctrl    <= loadix_ea;
1422
                  md_ctrl    <= latch_md;
1423
                                 pc_ctrl    <= latch_pc;
1424
             op_ctrl    <= latch_op;
1425
                  iv_ctrl    <= latch_iv;
1426
             left_ctrl  <= ac_left;       -- Left ALU input
1427
                  right_ctrl <= md_right;      -- Right ALU input
1428
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1429
                                 addr_ctrl  <= idle_addr;
1430
                  data_ctrl  <= pc_lo_data;
1431
                            next_state <= dir_state;
1432
 
1433
                          when dir_state => -- read memory cycle
1434
                  ac_ctrl    <= latch_ac;
1435
                  ix_ctrl    <= latch_ix;
1436
                  sp_ctrl    <= latch_sp;
1437
                  cc_ctrl    <= latch_cc;
1438
             ea_ctrl    <= latch_ea;
1439
                                 pc_ctrl    <= latch_pc;
1440
             op_ctrl    <= latch_op;
1441
                  iv_ctrl    <= latch_iv;
1442
                  data_ctrl  <= pc_lo_data;
1443
                                 case op(7 downto 4) is
1444
                                 when "0000" |  -- BRSET / BRCLR
1445
                                      "0001" |  -- BSET / BCLR
1446
                                      "0011" |  -- single op DIR
1447
                                      "0110" |  -- single op IX1
1448
                                                "0111" => -- single op IX0
1449
                    md_ctrl    <= fetch_md;
1450
               left_ctrl  <= ac_left;       -- Left ALU input
1451
                    right_ctrl <= md_right;      -- Right ALU input
1452
               alu_ctrl   <= alu_nop;       -- ALU opeartion
1453
                                   addr_ctrl  <= read_addr;     -- read effective address
1454
                              next_state <= exec_state;
1455
                                 when "1011" |     -- dual op direct
1456
                                      "1100" |     -- dual op extended
1457
                                      "1101" |     -- dual op ix2
1458
                                      "1110" |     -- dual op ix1
1459
                                      "1111" =>    -- dual op ix0
1460
                                   case op(3 downto 0) is
1461
                                        when "0111" =>   -- sta
1462
                      md_ctrl    <= load_md;
1463
                 left_ctrl  <= ac_left;       -- Left ALU input
1464
                      right_ctrl <= md_right;      -- Right ALU input
1465
                 alu_ctrl   <= alu_st;        -- ALU opeartion
1466
                                     addr_ctrl  <= idle_addr;     -- read effective address
1467
                                          next_state <= write_state;
1468
               when "1100" =>  -- jmp
1469
                      md_ctrl    <= latch_md;
1470
                 left_ctrl  <= ac_left;       -- Left ALU input
1471
                      right_ctrl <= md_right;      -- Right ALU input
1472
                 alu_ctrl   <= alu_nop;       -- ALU opeartion
1473
                                     addr_ctrl  <= idle_addr;     -- idle address
1474
                                          next_state <= jmp_state;
1475
               when "1101" =>  -- jsr
1476
                      md_ctrl    <= latch_md;
1477
                 left_ctrl  <= ac_left;       -- Left ALU input
1478
                      right_ctrl <= md_right;      -- Right ALU input
1479
                 alu_ctrl   <= alu_nop;       -- ALU opeartion
1480
                                     addr_ctrl  <= idle_addr;     -- idle address
1481
                                          next_state <= jsr_state;
1482
                                        when "1111" =>  -- stx
1483
                      md_ctrl    <= load_md;
1484
                 left_ctrl  <= ix_left;       -- Left ALU input
1485
                      right_ctrl <= md_right;      -- Right ALU input
1486
                 alu_ctrl   <= alu_st;       -- ALU opeartion
1487
                                     addr_ctrl  <= idle_addr;     -- read effective address
1488
                                          next_state <= write_state;
1489
                                        when others =>
1490
                      md_ctrl    <= fetch_md;
1491
                 left_ctrl  <= ac_left;       -- Left ALU input
1492
                      right_ctrl <= md_right;      -- Right ALU input
1493
                 alu_ctrl   <= alu_nop;       -- ALU opeartion
1494
                                     addr_ctrl  <= read_addr;     -- read effective address
1495
                                          next_state <= fetch_state;
1496
                                        end case;
1497
                            when others =>
1498
                    md_ctrl    <= fetch_md;
1499
               left_ctrl  <= ac_left;       -- Left ALU input
1500
                    right_ctrl <= md_right;      -- Right ALU input
1501
               alu_ctrl   <= alu_nop;       -- ALU opeartion
1502
                                   addr_ctrl  <= read_addr;     -- read effective address
1503
                                   next_state <= fetch_state;
1504
             end case;
1505
 
1506
           --
1507
                          -- EXECUTE:
1508
                          -- decode opcode
1509
           -- to determine if output of the ALU is transfered to a register
1510
                          -- or if alu output is written back to memory
1511
           --
1512
                          -- if opcode = dual operand                 or
1513
                          --    opcode = single operand accum / ixreg or
1514
                          --    opcode = branch on bit                then
1515
                          --    goto fetch_state
1516
                          --
1517
                          -- if opcode = single operand memory        or
1518
                          --    opcode = bit set / clear              or
1519
                          --    goto write_state
1520
                          --
1521
                          when exec_state => -- execute alu operation
1522
                                 pc_ctrl    <= latch_pc;
1523
             ea_ctrl    <= latch_ea;
1524
             op_ctrl    <= latch_op;
1525
                  iv_ctrl    <= latch_iv;
1526
                                 addr_ctrl  <= idle_addr;
1527
                  data_ctrl  <= md_data;
1528
 
1529
             case op(7 downto 4) is
1530
                                 when "0000" =>            -- branch set / clear
1531
                    ac_ctrl    <= latch_ac;
1532
                    ix_ctrl    <= latch_ix;
1533
                    sp_ctrl    <= latch_sp;
1534
                                        left_ctrl  <= md_left;
1535
                                        right_ctrl <= bset_right;
1536
                                        alu_ctrl   <= alu_btst;
1537
               md_ctrl    <= load_md;
1538
                                        cc_ctrl    <= load_cc;
1539
                                   next_state <= brbit_state;
1540
 
1541
                                 when "0001" =>            -- bit set / clear
1542
                    ac_ctrl    <= latch_ac;
1543
                    ix_ctrl    <= latch_ix;
1544
                    sp_ctrl    <= latch_sp;
1545
                                   case op(0) is
1546
                                        when '0' =>             -- bset
1547
                                          left_ctrl  <= md_left;
1548
                                          right_ctrl <= bset_right;
1549
                                          alu_ctrl   <= alu_ora;
1550
                 md_ctrl    <= load_md;
1551
                                          cc_ctrl    <= load_cc;
1552
 
1553
                                        when '1' =>             -- bclr
1554
                                          left_ctrl  <= md_left;
1555
                                          right_ctrl <= bclr_right;
1556
                                          alu_ctrl   <= alu_and;
1557
                 md_ctrl    <= load_md;
1558
                                          cc_ctrl    <= load_cc;
1559
 
1560
                                        when others =>
1561
                                          left_ctrl  <= md_left;
1562
                                          right_ctrl <= bclr_right;
1563
                                          alu_ctrl   <= alu_nop;
1564
                 md_ctrl    <= latch_md;
1565
                                          cc_ctrl    <= latch_cc;
1566
                                        end case;
1567
                                   next_state <= write_state;
1568
 
1569
                                 when "0011" |            -- single op direct
1570
                                      "0110" |            -- single op ix1
1571
                                      "0111" =>           -- single op ix0
1572
                    ac_ctrl    <= latch_ac;
1573
                    ix_ctrl    <= latch_ix;
1574
                    sp_ctrl    <= latch_sp;
1575
                                        left_ctrl  <= md_left;
1576
               md_ctrl    <= load_md;
1577
                                        cc_ctrl    <= load_cc;
1578
                                   case op( 3 downto 0 ) is
1579
                                   when "0000" =>            -- neg
1580
                                          right_ctrl <= zero_right;
1581
                                          alu_ctrl   <= alu_neg;
1582
                                   when "0011" =>            -- com
1583
                                          right_ctrl <= zero_right;
1584
                                          alu_ctrl   <= alu_com;
1585
                                   when "0100" =>            -- lsr
1586
                                          right_ctrl <= zero_right;
1587
                                          alu_ctrl   <= alu_lsr;
1588
                                   when "0110" =>            -- ror
1589
                                          right_ctrl <= zero_right;
1590
                                          alu_ctrl   <= alu_ror;
1591
                                   when "0111" =>            -- asr
1592
                                          right_ctrl <= zero_right;
1593
                                          alu_ctrl   <= alu_asr;
1594
                                   when "1000" =>            -- lsl
1595
                                          right_ctrl <= zero_right;
1596
                                          alu_ctrl   <= alu_lsl;
1597
                                   when "1001" =>            -- rol
1598
                                          right_ctrl <= zero_right;
1599
                                          alu_ctrl   <= alu_rol;
1600
                                   when "1010" =>            -- dec
1601
                                          right_ctrl <= one_right;
1602
                                          alu_ctrl   <= alu_dec;
1603
                                   when "1011" =>            -- undef
1604
                                          right_ctrl <= zero_right;
1605
                                          alu_ctrl   <= alu_nop;
1606
                                   when "1100" =>            -- inc
1607
                                          right_ctrl <= one_right;
1608
                                          alu_ctrl   <= alu_inc;
1609
                                   when "1101" =>            -- tst
1610
                                          right_ctrl <= zero_right;
1611
                                          alu_ctrl   <= alu_tst;
1612
                                   when "1110" =>            -- undef
1613
                                          right_ctrl <= zero_right;
1614
                                          alu_ctrl   <= alu_nop;
1615
                                   when "1111" =>            -- clr
1616
                                          right_ctrl <= zero_right;
1617
                                          alu_ctrl   <= alu_clr;
1618
                                        when others =>
1619
                                          right_ctrl <= zero_right;
1620
                                          alu_ctrl   <= alu_nop;
1621
                                        end case;
1622
                                   next_state <= write_state;
1623
 
1624
                            when others =>
1625
                    ac_ctrl    <= latch_ac;
1626
                                        cc_ctrl    <= latch_cc;
1627
                    ix_ctrl    <= latch_ix;
1628
                    sp_ctrl    <= latch_sp;
1629
               md_ctrl    <= latch_md;
1630
                                        left_ctrl  <= md_left;
1631
                                        right_ctrl <= zero_right;
1632
                                        alu_ctrl   <= alu_nop;
1633
                                        next_state <= fetch_state;
1634
                            end case;
1635
           --
1636
                          -- WRITE:
1637
                          -- write latched alu output to memory pointed to by ea register
1638
                          -- go to fetch state
1639
                          --
1640
                          when write_state => -- write alu output to memory
1641
                  ac_ctrl    <= latch_ac;
1642
                            cc_ctrl    <= latch_cc;
1643
                  ix_ctrl    <= latch_ix;
1644
                  sp_ctrl    <= latch_sp;
1645
             ea_ctrl    <= latch_ea;
1646
             md_ctrl    <= latch_md;
1647
                                 pc_ctrl    <= latch_pc;
1648
             op_ctrl    <= latch_op;
1649
                  iv_ctrl    <= latch_iv;
1650
                            left_ctrl  <= md_left;
1651
                            right_ctrl <= zero_right;
1652
                                 alu_ctrl   <= alu_nop;
1653
                                 addr_ctrl  <= write_addr;
1654
                            data_ctrl  <= md_data;        -- select latched alu output to data bus
1655
                            next_state <= fetch_state;
1656
                          --
1657
                          -- BRBIT
1658
                          -- Branch on condition of bit
1659
                          -- fetch the address offset
1660
                          -- advance the pc
1661
           -- evaluate the carry bit to determine if we take the branch
1662
                          -- Carry = 0 if tested bit set
1663
                          -- Carry = 1 if tested bit clear
1664
                          -- op(0) = 0 if BRSET
1665
                          -- op(0) = 1 if BRCLR
1666
                          -- if carry = '1'
1667
                          --   goto branch state
1668
                          -- else
1669
                          --   goto execute state
1670
                          -- 
1671
                          when brbit_state => -- fetch address offset
1672
                  ac_ctrl    <= latch_ac;
1673
                            cc_ctrl    <= latch_cc;
1674
                  ix_ctrl    <= latch_ix;
1675
                  sp_ctrl    <= latch_sp;
1676
                                 ea_ctrl    <= fetch_first_ea;
1677
             md_ctrl    <= latch_md;
1678
                                 pc_ctrl    <= inc_pc;
1679
             op_ctrl    <= latch_op;
1680
                  iv_ctrl    <= latch_iv;
1681
                            left_ctrl  <= md_left;
1682
                            right_ctrl <= zero_right;
1683
                                 alu_ctrl   <= alu_nop;
1684
                                 addr_ctrl  <= fetch_addr;
1685
                            data_ctrl  <= md_data;        -- select latched alu output to data bus
1686
                            if (cc(CFLAG) xor op(0)) = '0' then -- check this ... I think it's right
1687
                              next_state <= branch_state;
1688
                                 else
1689
                                   next_state <= fetch_state;
1690
                                 end if;
1691
 
1692
           --
1693
                          -- BRANCH:
1694
                          -- take conditional branch
1695
                          -- branch (pc relative addressing)
1696
           -- add effective address (ea register) to pc
1697
           -- go to "fetch" state
1698
           ---
1699
                          when branch_state => -- calculate branch address
1700
                  ac_ctrl    <= latch_ac;
1701
                  cc_ctrl    <= latch_cc;
1702
                  ix_ctrl    <= latch_ix;
1703
                  sp_ctrl    <= latch_sp;
1704
             ea_ctrl    <= latch_ea;
1705
                  md_ctrl    <= latch_md;
1706
                                 pc_ctrl    <= bra_pc;
1707
             op_ctrl    <= latch_op;
1708
                  iv_ctrl    <= latch_iv;
1709
             left_ctrl  <= ac_left;       -- Left ALU input
1710
                  right_ctrl <= md_right;      -- Right ALU input
1711
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1712
                                 addr_ctrl  <= idle_addr;     -- idle address bus
1713
                  data_ctrl  <= md_data;       -- read memory data
1714
                  next_state <= fetch_state;
1715
                          --
1716
                          -- jump to subroutine
1717
                          --
1718
                          when bsr_state =>     -- calculate effective jump address
1719
                  ac_ctrl    <= latch_ac;
1720
                  cc_ctrl    <= latch_cc;
1721
                  ix_ctrl    <= latch_ix;
1722
                  sp_ctrl    <= latch_sp;
1723
             ea_ctrl    <= addpc_ea;
1724
                  md_ctrl    <= latch_md;
1725
                                 pc_ctrl    <= latch_pc;
1726
             op_ctrl    <= latch_op;
1727
                  iv_ctrl    <= latch_iv;
1728
             left_ctrl  <= ac_left;       -- Left ALU input
1729
                  right_ctrl <= md_right;      -- Right ALU input
1730
             alu_ctrl   <= alu_nop;       -- ALU operation
1731
                                 addr_ctrl  <= idle_addr;
1732
                  data_ctrl  <= md_data;
1733
                            next_state <= jsr_state;
1734
 
1735
                          when jsr_state =>     -- store pc low / decrement sp
1736
                  ac_ctrl    <= latch_ac;
1737
                  cc_ctrl    <= latch_cc;
1738
                  ix_ctrl    <= latch_ix;
1739
                  sp_ctrl    <= dec_sp;
1740
             ea_ctrl    <= latch_ea;
1741
                  md_ctrl    <= latch_md;
1742
                                 pc_ctrl    <= latch_pc;
1743
             op_ctrl    <= latch_op;
1744
                  iv_ctrl    <= latch_iv;
1745
             left_ctrl  <= ac_left;       -- Left ALU input
1746
                  right_ctrl <= md_right;      -- Right ALU input
1747
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1748
                                 addr_ctrl  <= push_addr;     -- write stack address
1749
                  data_ctrl  <= pc_lo_data;    -- write PC low
1750
                            next_state <= jsr1_state;
1751
 
1752
                          when jsr1_state =>    -- store pc high / decrement sp
1753
                  ac_ctrl    <= latch_ac;
1754
                  cc_ctrl    <= latch_cc;
1755
                  ix_ctrl    <= latch_ix;
1756
                  sp_ctrl    <= dec_sp;
1757
             ea_ctrl    <= latch_ea;
1758
                  md_ctrl    <= latch_md;
1759
                                 pc_ctrl    <= latch_pc;
1760
             op_ctrl    <= latch_op;
1761
                  iv_ctrl    <= latch_iv;
1762
             left_ctrl  <= ac_left;       -- Left ALU input
1763
                  right_ctrl <= md_right;      -- Right ALU input
1764
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1765
                                 addr_ctrl  <= push_addr;     -- write stack address
1766
                  data_ctrl  <= pc_hi_data;    -- write PC high
1767
                            next_state <= jmp_state;
1768
                          --
1769
                          -- jump to address
1770
                          --
1771
                          when jmp_state =>     -- load pc with effective address
1772
                  ac_ctrl    <= latch_ac;
1773
                  cc_ctrl    <= latch_cc;
1774
                  ix_ctrl    <= latch_ix;
1775
                  sp_ctrl    <= latch_sp;
1776
             ea_ctrl    <= latch_ea;
1777
                  md_ctrl    <= latch_md;
1778
                                 pc_ctrl    <= jmp_pc;
1779
             op_ctrl    <= latch_op;
1780
                  iv_ctrl    <= latch_iv;
1781
             left_ctrl  <= ac_left;       -- Left ALU input
1782
                  right_ctrl <= md_right;      -- Right ALU input
1783
             alu_ctrl   <= alu_nop;       -- ALU opeartion (do nothing)
1784
                                 addr_ctrl  <= idle_addr;     -- idle address
1785
                  data_ctrl  <= pc_lo_data;    -- 
1786
                            next_state <= fetch_state;
1787
                          --
1788
                          -- return from subroutine
1789
                          --
1790
                          when rts_state => -- increment stack pointer
1791
                  ac_ctrl    <= latch_ac;
1792
                  cc_ctrl    <= latch_cc;
1793
                  ix_ctrl    <= latch_ix;
1794
                  sp_ctrl    <= inc_sp;
1795
             ea_ctrl    <= latch_ea;
1796
                  md_ctrl    <= latch_md;
1797
                                 pc_ctrl    <= latch_pc;
1798
             op_ctrl    <= latch_op;
1799
                  iv_ctrl    <= latch_iv;
1800
             left_ctrl  <= ac_left;       -- Left ALU input
1801
                  right_ctrl <= md_right;      -- Right ALU input
1802
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1803
                                 addr_ctrl  <= idle_addr;
1804
                  data_ctrl  <= md_data;
1805
                            next_state <= rts_pch_state;
1806
 
1807
                          when rts_pch_state => -- load pc high return address / increment sp
1808
                  ac_ctrl    <= latch_ac;
1809
                  cc_ctrl    <= latch_cc;
1810
                  ix_ctrl    <= latch_ix;
1811
                  sp_ctrl    <= inc_sp;
1812
             ea_ctrl    <= latch_ea;
1813
                  md_ctrl    <= latch_md;
1814
                                 pc_ctrl    <= pull_hi_pc;
1815
             op_ctrl    <= latch_op;
1816
                  iv_ctrl    <= latch_iv;
1817
             left_ctrl  <= ac_left;       -- Left ALU input
1818
                  right_ctrl <= md_right;      -- Right ALU input
1819
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1820
                                 addr_ctrl  <= pull_addr;
1821
                  data_ctrl  <= pc_hi_data;
1822
                            next_state <= rts_pcl_state;
1823
 
1824
                          when rts_pcl_state => -- load pc low return address
1825
                  ac_ctrl    <= latch_ac;
1826
                  cc_ctrl    <= latch_cc;
1827
                  ix_ctrl    <= latch_ix;
1828
                  sp_ctrl    <= latch_sp;
1829
             ea_ctrl    <= latch_ea;
1830
                  md_ctrl    <= latch_md;
1831
                                 pc_ctrl    <= pull_lo_pc;
1832
             op_ctrl    <= latch_op;
1833
                  iv_ctrl    <= latch_iv;
1834
             left_ctrl  <= ac_left;       -- Left ALU input
1835
                  right_ctrl <= md_right;      -- Right ALU input
1836
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1837
                                 addr_ctrl  <= pull_addr;
1838
                  data_ctrl  <= pc_lo_data;
1839
                            next_state <= fetch_state;
1840
 
1841
                          --
1842
                          --
1843
                          -- return from interrupt
1844
                          --
1845
                          when rti_state => -- increment sp
1846
                  ac_ctrl    <= latch_ac;
1847
                  cc_ctrl    <= latch_cc;
1848
                  ix_ctrl    <= latch_ix;
1849
                  sp_ctrl    <= inc_sp;
1850
             ea_ctrl    <= latch_ea;
1851
                  md_ctrl    <= fetch_md;
1852
                                 pc_ctrl    <= latch_pc;
1853
             op_ctrl    <= latch_op;
1854
                  iv_ctrl    <= latch_iv;
1855
             left_ctrl  <= ac_left;       -- Left ALU input
1856
                  right_ctrl <= md_right;      -- Right ALU input
1857
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1858
                                 addr_ctrl  <= idle_addr;
1859
                  data_ctrl  <= md_data;
1860
                            next_state <= rti_cc_state;
1861
 
1862
                          when rti_cc_state => -- read cc / increment sp
1863
                  ac_ctrl    <= latch_ac;
1864
                  cc_ctrl    <= pull_cc;                        -- read Condition codes
1865
                  ix_ctrl    <= latch_ix;
1866
                  sp_ctrl    <= inc_sp;
1867
             ea_ctrl    <= latch_ea;
1868
                  md_ctrl    <= latch_md;
1869
                                 pc_ctrl    <= latch_pc;
1870
             op_ctrl    <= latch_op;
1871
                  iv_ctrl    <= latch_iv;
1872
             left_ctrl  <= ac_left;       -- Left ALU input
1873
                  right_ctrl <= md_right;      -- Right ALU input
1874
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1875
                                 addr_ctrl  <= pull_addr;     -- read stack address
1876
                  data_ctrl  <= cc_data;       -- output old CC
1877
                            next_state <= rti_ac_state;
1878
 
1879
                          when rti_ac_state => -- read acc / increment sp
1880
                  ac_ctrl    <= pull_ac;
1881
                  cc_ctrl    <= latch_cc;
1882
                  ix_ctrl    <= latch_ix;
1883
                  sp_ctrl    <= inc_sp;
1884
             ea_ctrl    <= latch_ea;
1885
                  md_ctrl    <= latch_md;
1886
                                 pc_ctrl    <= latch_pc;
1887
             op_ctrl    <= latch_op;
1888
                  iv_ctrl    <= latch_iv;
1889
             left_ctrl  <= ac_left;       -- Left ALU input
1890
                  right_ctrl <= md_right;      -- Right ALU input
1891
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1892
                                 addr_ctrl  <= pull_addr;     -- read stack address
1893
                  data_ctrl  <= ac_data;       -- output Accumulator
1894
                            next_state <= rti_ix_state;
1895
 
1896
                          when rti_ix_state => -- read ix / increment sp
1897
                  ac_ctrl    <= latch_ac;
1898
                  cc_ctrl    <= latch_cc;
1899
                  ix_ctrl    <= pull_ix;                  -- read IX register
1900
                  sp_ctrl    <= inc_sp;
1901
             ea_ctrl    <= latch_ea;
1902
                  md_ctrl    <= latch_md;
1903
                                 pc_ctrl    <= latch_pc;
1904
             op_ctrl    <= latch_op;
1905
                  iv_ctrl    <= latch_iv;
1906
             left_ctrl  <= ac_left;       -- Left ALU input
1907
                  right_ctrl <= md_right;      -- Right ALU input
1908
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1909
                                 addr_ctrl  <= pull_addr;     -- read stack address
1910
                  data_ctrl  <= ix_data;       -- output old ix register
1911
                            next_state <= rti_pch_state;
1912
 
1913
                          when rti_pch_state => -- read pc hi / increment sp
1914
                  ac_ctrl    <= latch_ac;
1915
                  cc_ctrl    <= latch_cc;
1916
                  ix_ctrl    <= latch_ix;
1917
                  sp_ctrl    <= inc_sp;
1918
             ea_ctrl    <= latch_ea;
1919
                  md_ctrl    <= latch_md;
1920
                                 pc_ctrl    <= pull_hi_pc;         -- read PC high
1921
             op_ctrl    <= latch_op;
1922
                  iv_ctrl    <= latch_iv;
1923
             left_ctrl  <= ac_left;       -- Left ALU input
1924
                  right_ctrl <= md_right;      -- Right ALU input
1925
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1926
                                 addr_ctrl  <= pull_addr;               -- read stack address
1927
                  data_ctrl  <= pc_hi_data;             -- output old PC high
1928
                            next_state <= rti_pcl_state;
1929
 
1930
                          when rti_pcl_state => -- read pc lo
1931
                  ac_ctrl    <= latch_ac;
1932
                  cc_ctrl    <= latch_cc;
1933
                  ix_ctrl    <= latch_ix;
1934
                  sp_ctrl    <= latch_sp;
1935
             ea_ctrl    <= latch_ea;
1936
                  md_ctrl    <= latch_md;
1937
                                 pc_ctrl    <= pull_lo_pc;              -- read PC low
1938
             op_ctrl    <= latch_op;
1939
                  iv_ctrl    <= latch_iv;
1940
             left_ctrl  <= ac_left;       -- Left ALU input
1941
                  right_ctrl <= md_right;      -- Right ALU input
1942
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1943
                                 addr_ctrl  <= pull_addr;               -- read stack address
1944
                  data_ctrl  <= pc_lo_data;             -- output old PC Low
1945
                            next_state <= fetch_state;
1946
           --
1947
                          -- sofwtare interrupt (or any others interrupt state)
1948
                          --
1949
                          when swi_state =>
1950
                  ac_ctrl    <= latch_ac;
1951
                  cc_ctrl    <= latch_cc;
1952
                  ix_ctrl    <= latch_ix;
1953
                  sp_ctrl    <= latch_sp;
1954
             ea_ctrl    <= latch_ea;
1955
                  md_ctrl    <= latch_md;
1956
                                 pc_ctrl    <= latch_pc;
1957
             op_ctrl    <= latch_op;
1958
                  iv_ctrl    <= swi_iv;
1959
             left_ctrl  <= ac_left;       -- Left ALU input
1960
                  right_ctrl <= md_right;      -- Right ALU input
1961
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1962
                                 addr_ctrl  <= idle_addr;
1963
                  data_ctrl  <= md_data;
1964
                            next_state <= int_state;
1965
 
1966
                          --
1967
                          -- any sort of interrupt
1968
                          --
1969
                          when int_state =>  -- store pc low / decrement sp
1970
                  ac_ctrl    <= latch_ac;
1971
                  cc_ctrl    <= latch_cc;
1972
                  ix_ctrl    <= latch_ix;
1973
                  sp_ctrl    <= dec_sp;
1974
             ea_ctrl    <= latch_ea;
1975
                  md_ctrl    <= latch_md;
1976
                                 pc_ctrl    <= latch_pc;
1977
             op_ctrl    <= latch_op;
1978
                  iv_ctrl    <= latch_iv;
1979
             left_ctrl  <= ac_left;       -- Left ALU input
1980
                  right_ctrl <= md_right;      -- Right ALU input
1981
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1982
                                 addr_ctrl  <= push_addr;
1983
                  data_ctrl  <= pc_lo_data;
1984
                            next_state <= int1_state;
1985
 
1986
                          when int1_state => -- store pc hi / decrement sp
1987
                  ac_ctrl    <= latch_ac;
1988
                  cc_ctrl    <= latch_cc;
1989
                  ix_ctrl    <= latch_ix;
1990
                  sp_ctrl    <= dec_sp;
1991
             ea_ctrl    <= latch_ea;
1992
                  md_ctrl    <= latch_md;
1993
                                 pc_ctrl    <= latch_pc;
1994
             op_ctrl    <= latch_op;
1995
                  iv_ctrl    <= latch_iv;
1996
             left_ctrl  <= ac_left;       -- Left ALU input
1997
                  right_ctrl <= md_right;      -- Right ALU input
1998
             alu_ctrl   <= alu_nop;       -- ALU opeartion
1999
                                 addr_ctrl  <= push_addr;
2000
                  data_ctrl  <= pc_hi_data;
2001
                            next_state <= int2_state;
2002
 
2003
           when int2_state => -- store ix / decrement sp
2004
                  ac_ctrl    <= latch_ac;
2005
                  cc_ctrl    <= latch_cc;
2006
                  ix_ctrl    <= latch_ix;
2007
                  sp_ctrl    <= dec_sp;
2008
             ea_ctrl    <= latch_ea;
2009
                  md_ctrl    <= latch_md;
2010
                                 pc_ctrl    <= latch_pc;
2011
             op_ctrl    <= latch_op;
2012
                  iv_ctrl    <= latch_iv;
2013
             left_ctrl  <= ac_left;       -- Left ALU input
2014
                  right_ctrl <= md_right;      -- Right ALU input
2015
             alu_ctrl   <= alu_nop;       -- ALU opeartion
2016
                                 addr_ctrl  <= push_addr;
2017
                  data_ctrl  <= ix_data;
2018
                                 next_state <= int3_state;
2019
 
2020
           when int3_state => -- store ac / decrement sp
2021
                  ac_ctrl    <= latch_ac;
2022
                  cc_ctrl    <= latch_cc;
2023
                  ix_ctrl    <= latch_ix;
2024
                  sp_ctrl    <= dec_sp;
2025
             ea_ctrl    <= latch_ea;
2026
                  md_ctrl    <= latch_md;
2027
                                 pc_ctrl    <= latch_pc;
2028
             op_ctrl    <= latch_op;
2029
                  iv_ctrl    <= latch_iv;
2030
             left_ctrl  <= ac_left;       -- Left ALU input
2031
                  right_ctrl <= md_right;      -- Right ALU input
2032
             alu_ctrl   <= alu_nop;       -- ALU opeartion
2033
                                 addr_ctrl  <= push_addr;
2034
                  data_ctrl  <= ac_data;
2035
                                 next_state <= int4_state;
2036
 
2037
           when int4_state => -- store cc / decrement sp
2038
                  ac_ctrl    <= latch_ac;
2039
                  cc_ctrl    <= latch_cc;
2040
                  ix_ctrl    <= latch_ix;
2041
                  sp_ctrl    <= dec_sp;
2042
             ea_ctrl    <= latch_ea;
2043
                  md_ctrl    <= latch_md;
2044
                                 pc_ctrl    <= latch_pc;
2045
             op_ctrl    <= latch_op;
2046
                  iv_ctrl    <= latch_iv;
2047
             left_ctrl  <= ac_left;       -- Left ALU input
2048
                  right_ctrl <= md_right;      -- Right ALU input
2049
             alu_ctrl   <= alu_nop;       -- ALU opeartion
2050
                                 addr_ctrl  <= push_addr;
2051
                  data_ctrl  <= cc_data;
2052
                                 next_state <= int5_state;
2053
 
2054
           when int5_state => -- fetch pc hi = int vector hi
2055
                  ac_ctrl    <= latch_ac;
2056
                  cc_ctrl    <= load_cc;
2057
                  ix_ctrl    <= latch_ix;
2058
                  sp_ctrl    <= latch_sp;
2059
             ea_ctrl    <= latch_ea;
2060
                  md_ctrl    <= latch_md;
2061
                                 pc_ctrl    <= pull_hi_pc;
2062
             op_ctrl    <= latch_op;
2063
                  iv_ctrl    <= latch_iv;
2064
             left_ctrl  <= ac_left;       -- Left ALU input
2065
                  right_ctrl <= md_right;      -- Right ALU input
2066
             alu_ctrl   <= alu_sei;       -- ALU operation
2067
                                 addr_ctrl  <= vect_hi_addr;
2068
                  data_ctrl  <= pc_hi_data;
2069
                                 next_state <= int6_state;
2070
 
2071
           when int6_state => -- fetch pc low = int vector low
2072
                  ac_ctrl    <= latch_ac;
2073
                  cc_ctrl    <= load_cc;
2074
                  ix_ctrl    <= latch_ix;
2075
                  sp_ctrl    <= latch_sp;
2076
             ea_ctrl    <= latch_ea;
2077
                  md_ctrl    <= latch_md;
2078
                                 pc_ctrl    <= pull_lo_pc;
2079
             op_ctrl    <= latch_op;
2080
                  iv_ctrl    <= latch_iv;
2081
             left_ctrl  <= ac_left;       -- Left ALU input
2082
                  right_ctrl <= md_right;      -- Right ALU input
2083
             alu_ctrl   <= alu_sei;       -- ALU operation
2084
                                 addr_ctrl  <= vect_lo_addr;
2085
                  data_ctrl  <= pc_lo_data;
2086
                                 next_state <= fetch_state;
2087
                          --
2088
                          -- stop the processor
2089
                          --
2090
                          when stop_state =>
2091
                  ac_ctrl    <= latch_ac;
2092
                  cc_ctrl    <= latch_cc;
2093
                  ix_ctrl    <= latch_ix;
2094
                  sp_ctrl    <= latch_sp;
2095
             ea_ctrl    <= latch_ea;
2096
                  md_ctrl    <= latch_md;
2097
                                 pc_ctrl    <= latch_pc;
2098
             op_ctrl    <= latch_op;
2099
                  iv_ctrl    <= latch_iv;
2100
             left_ctrl  <= ac_left;       -- Left ALU input
2101
                  right_ctrl <= md_right;      -- Right ALU input
2102
             alu_ctrl   <= alu_nop;       -- ALU operation
2103
                                 addr_ctrl  <= idle_addr;
2104
                  data_ctrl  <= md_data;
2105
                            next_state <= stop_state;
2106
           --
2107
                          -- wait for interrupt
2108
                          --
2109
                          when wait_state => -- push pclow / decrement sp
2110
                  ac_ctrl    <= latch_ac;
2111
                  cc_ctrl    <= latch_cc;
2112
                  ix_ctrl    <= latch_ix;
2113
                  sp_ctrl    <= dec_sp;
2114
             ea_ctrl    <= latch_ea;
2115
                  md_ctrl    <= latch_md;
2116
                                 pc_ctrl    <= latch_pc;
2117
             op_ctrl    <= latch_op;
2118
                  iv_ctrl    <= latch_iv;
2119
             left_ctrl  <= ac_left;       -- Left ALU input
2120
                  right_ctrl <= md_right;      -- Right ALU input
2121
             alu_ctrl   <= alu_nop;       -- ALU operation
2122
                                 addr_ctrl  <= push_addr;
2123
                  data_ctrl  <= pc_lo_data;
2124
                            next_state <= wait1_state;
2125
 
2126
                          when wait1_state => -- push pchi / decrement sp
2127
                  ac_ctrl    <= latch_ac;
2128
                  cc_ctrl    <= latch_cc;
2129
                  ix_ctrl    <= latch_ix;
2130
                  sp_ctrl    <= dec_sp;
2131
             ea_ctrl    <= latch_ea;
2132
                  md_ctrl    <= latch_md;
2133
                                 pc_ctrl    <= latch_pc;
2134
             op_ctrl    <= latch_op;
2135
                  iv_ctrl    <= latch_iv;
2136
             left_ctrl  <= ac_left;       -- Left ALU input
2137
                  right_ctrl <= md_right;      -- Right ALU input
2138
             alu_ctrl   <= alu_nop;       -- ALU operation
2139
                                 addr_ctrl  <= push_addr;
2140
                  data_ctrl  <= pc_hi_data;
2141
                            next_state <= wait2_state;
2142
 
2143
           when wait2_state => -- push ix / decrement sp
2144
                  ac_ctrl    <= latch_ac;
2145
                  cc_ctrl    <= latch_cc;
2146
                  ix_ctrl    <= latch_ix;
2147
                  sp_ctrl    <= dec_sp;
2148
             ea_ctrl    <= latch_ea;
2149
                  md_ctrl    <= latch_md;
2150
                                 pc_ctrl    <= latch_pc;
2151
             op_ctrl    <= latch_op;
2152
                  iv_ctrl    <= latch_iv;
2153
             left_ctrl  <= ac_left;       -- Left ALU input
2154
                  right_ctrl <= md_right;      -- Right ALU input
2155
             alu_ctrl   <= alu_nop;       -- ALU operation
2156
                                 addr_ctrl  <= push_addr;
2157
                  data_ctrl  <= ix_data;
2158
                                 next_state <= wait3_state;
2159
 
2160
           when wait3_state => -- push ac / decrement sp
2161
                  ac_ctrl    <= latch_ac;
2162
                  cc_ctrl    <= latch_cc;
2163
                  ix_ctrl    <= latch_ix;
2164
                  sp_ctrl    <= dec_sp;
2165
             ea_ctrl    <= latch_ea;
2166
                  md_ctrl    <= latch_md;
2167
                                 pc_ctrl    <= latch_pc;
2168
             op_ctrl    <= latch_op;
2169
                  iv_ctrl    <= latch_iv;
2170
             left_ctrl  <= ac_left;       -- Left ALU input
2171
                  right_ctrl <= md_right;      -- Right ALU input
2172
             alu_ctrl   <= alu_nop;       -- ALU operation
2173
                                 addr_ctrl  <= push_addr;
2174
                  data_ctrl  <= ac_data;
2175
                                 next_state <= wait4_state;
2176
 
2177
           when wait4_state => -- push cc / decrement sp
2178
                  ac_ctrl    <= latch_ac;
2179
                  cc_ctrl    <= latch_cc;
2180
                  ix_ctrl    <= latch_ix;
2181
                  sp_ctrl    <= dec_sp;
2182
             ea_ctrl    <= latch_ea;
2183
                  md_ctrl    <= latch_md;
2184
                                 pc_ctrl    <= latch_pc;
2185
             op_ctrl    <= latch_op;
2186
                  iv_ctrl    <= latch_iv;
2187
             left_ctrl  <= ac_left;       -- Left ALU input
2188
                  right_ctrl <= md_right;      -- Right ALU input
2189
             alu_ctrl   <= alu_nop;       -- ALU operation
2190
                                 addr_ctrl  <= push_addr;
2191
                  data_ctrl  <= cc_data;
2192
                                 next_state <= halt_state;
2193
           --
2194
                          -- halt cpu
2195
                          --
2196
                          when halt_state => -- halt on halt
2197
                  ac_ctrl    <= latch_ac;
2198
                            cc_ctrl    <= latch_cc;
2199
                  ix_ctrl    <= latch_ix;
2200
                  sp_ctrl    <= latch_sp;
2201
             ea_ctrl    <= latch_ea;
2202
             md_ctrl    <= latch_md;
2203
                                 pc_ctrl    <= latch_pc;
2204
             op_ctrl    <= latch_op;
2205
                  iv_ctrl    <= latch_iv;
2206
                            left_ctrl  <= md_left;
2207
                            right_ctrl <= zero_right;
2208
                                 alu_ctrl   <= alu_nop;
2209
                                 addr_ctrl  <= idle_addr;
2210
                            data_ctrl  <= md_data;        -- select latched alu output to data bus
2211
                            next_state <= halt_state;
2212
           --
2213
                          -- undefined instruction
2214
                     --
2215
                          when others => -- halt on undefine states
2216
                  ac_ctrl    <= latch_ac;
2217
                            cc_ctrl    <= latch_cc;
2218
                  ix_ctrl    <= latch_ix;
2219
                  sp_ctrl    <= latch_sp;
2220
             ea_ctrl    <= latch_ea;
2221
             md_ctrl    <= latch_md;
2222
                                 pc_ctrl    <= latch_pc;
2223
             op_ctrl    <= latch_op;
2224
                  iv_ctrl    <= latch_iv;
2225
                            left_ctrl  <= md_left;
2226
                            right_ctrl <= zero_right;
2227
                                 alu_ctrl   <= alu_nop;
2228
                                 addr_ctrl  <= idle_addr;
2229
                            data_ctrl  <= md_data;        -- select latched alu output to data bus
2230
                            next_state <= halt_state;
2231
 
2232
                  end case;
2233
 
2234
end process;
2235
--------------------------------
2236
--
2237
-- state machine
2238
--
2239
--------------------------------
2240
 
2241
change_state: process( clk, rst, state )
2242
begin
2243
  if rst = '1' then
2244
         state <= reset_state;
2245
  elsif clk'event and clk = '0' then
2246
    state <= next_state;
2247
  end if;
2248
end process;
2249
        -- output
2250
 
2251
end CPU_ARCH;
2252
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.