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

Subversion Repositories System09

[/] [System09/] [rev_86/] [rtl/] [VHDL/] [cpu09_dummy_firq.vhd] - Blame information for rev 138

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

Line No. Rev Author Line
1 65 davidgb
-- $Id: cpu09_dummy_firq.vhd,v 1.1 2009-03-02 21:34:22 davidgb Exp $
2
--===========================================================================----
3
--
4
--  S Y N T H E Z I A B L E    CPU09 - 6809 compatible CPU Core
5
--
6
--  www.OpenCores.Org - September 2003
7
--  This core adheres to the GNU public license  
8
--
9
-- File name      : cpu09.vhd
10
--
11
-- Purpose        : 6809 CPU core
12
--
13
-- Dependencies   : ieee.Std_Logic_1164
14
--                  ieee.std_logic_unsigned
15
--
16
-- Uses           : None
17
--
18
-- Author         : John E. Kent
19
--                  dilbert57@opencores.org      
20
--
21
--===========================================================================----
22
--
23
-- Revision History:
24
--===========================================================================--
25
--
26
-- Version 0.1 - 26 June 2003 - John Kent
27
-- Added extra level in state stack
28
-- fixed some calls to the extended addressing state
29
--
30
-- Version 0.2 - 5 Sept 2003 - John Kent
31
-- Fixed 16 bit indexed offset (was doing read rather than fetch)
32
-- Added/Fixed STY and STS instructions.
33
-- ORCC_STATE ANDed CC state rather than ORed it - Now fixed
34
-- CMPX Loaded ACCA and ACCB - Now fixed 
35
--
36
-- Version 1.0 - 6 Sep 2003 - John Kent 
37
-- Initial release to Open Cores
38
-- reversed clock edge
39
--
40
-- Version 1.1 - 29 November 2003 John kent
41
--      ACCA and ACCB indexed offsets are 2's complement.
42
-- ALU Right Mux now sign extends ACCA & ACCB offsets
43
-- Absolute Indirect addressing performed a read on the
44
-- second byte of the address rather than a fetch
45
-- so it formed an incorrect address. Now fixed. 
46
--
47
-- Version 1.2 - 29 November 2003 John Kent
48
-- LEAX and LEAY affect the Z bit only
49
--      LEAS and LEAU do not affect any condition codes
50
-- added an extra ALU control for LEA.
51
--
52
-- Version 1.3 - 12 December 2003 John Kent
53
-- CWAI did not work, was missed a PUSH_ST on calling
54
-- the ANDCC_STATE. Thanks go to Ghassan Kraidy for
55
-- finding this fault.
56
--
57
-- Version 1.4 - 12 December 2003 John Kent
58
-- Missing cc_ctrl assignment in otherwise case of 
59
-- lea_state resulted in cc_ctrl being latched in
60
-- that state.  
61
-- The otherwise statement should never be reached,
62
-- and has been fixed simply to resolve synthesis warnings.
63
--
64
-- Version 1.5 - 17 january 2004 John kent
65
-- The clear instruction used "alu_ld8" to control the ALU
66
-- rather than "alu_clr". This mean the Carry was not being
67
-- cleared correctly.
68
--
69
-- Version 1.6 - 24 January 2004 John Kent
70
-- Fixed problems in PSHU instruction
71
--
72
-- Version 1.7 - 25 January 2004 John Kent
73
-- removed redundant "alu_inx" and "alu_dex'
74
-- Removed "test_alu" and "test_cc"
75
-- STD instruction did not set condition codes
76
-- JMP direct was not decoded properly
77
-- CLR direct performed an unwanted read cycle
78
-- Bogus "latch_md" in Page2 indexed addressing
79
--
80
-- Version 1.8 - 27 January 2004 John Kent
81
-- CWAI in decode1_state should increment the PC.
82
-- ABX is supposed to be an unsigned addition.
83
-- Added extra ALU function
84
-- ASR8 slightly changed in the ALU.
85
--
86
--      Version 1.9 - 20 August 2005
87
-- LSR8 is now handled in ASR8 and ROR8 case in the ALU,
88
-- rather than LSR16. There was a problem with single 
89
-- operand instructions using the MD register which is
90
-- sign extended on the first 8 bit fetch.
91
--
92
-- Version 1.10 - 13 September 2005
93
-- TFR & EXG instructions did not work for the Condition Code Register
94
-- An extra case has been added to the ALU for the alu_tfr control 
95
-- to assign the left ALU input (alu_left) to the condition code
96
-- outputs (cc_out). 
97
--
98
-- Version 1.11 - 16 September 2005
99
-- JSR ,X should not predecrement S before calculating the jump address.
100
-- The reason is that JSR [0,S] needs S to point to the top of the stack
101
-- to fetch a valid vector address. The solution is to have the addressing
102
-- mode microcode called before decrementing S and then decrementing S in
103
-- JSR_STATE. JSR_STATE in turn calls PUSH_RETURN_LO_STATE rather than
104
-- PUSH_RETURN_HI_STATE so that both the High & Low halves of the PC are
105
-- pushed on the stack. This adds one extra bus cycle, but resolves the
106
-- addressing conflict. I've also removed the pre-decement S in 
107
-- JSR EXTENDED as it also calls JSR_STATE.
108
--
109
-- Version 1.12 - 6th June 2006
110
-- 6809 Programming reference manual says V is not affected by ASR, LSR and ROR
111
-- This is different to the 6800. CLR should reset the V bit.
112
--
113
-- Version 1.13 - 7th July 2006
114
-- Disable NMI on reset until S Stack pointer has been loaded.
115
-- Added nmi_enable signal in sp_reg process and nmi_handler process.
116
--
117
-- Version 1.14 - 11th July 2006
118
-- 1. Added new state to RTI called rti_entire_state.
119
-- This state tests the CC register after it has been loaded
120
-- from the stack. Previously the current CC was tested which
121
-- was incorrect. The Entire Flag should be set before the
122
-- interrupt stacks the CC.
123
-- 2. On bogus Interrupts, int_cc_state went to rti_state,
124
-- which was an enumerated state, but not defined anywhere.
125
-- rti_state has been changed to rti_cc_state so that bogus interrupt
126
-- will perform an RTI after entering that state.
127
-- 3. Sync should generate an interrupt if the interrupt masks
128
-- are cleared. If the interrupt masks are set, then an interrupt
129
-- will cause the the PC to advance to the next instruction.
130
-- Note that I don't wait for an interrupt to be asserted for
131
-- three clock cycles.
132
-- 4. Added new ALU control state "alu_mul". "alu_mul" is used in
133
-- the Multiply instruction replacing "alu_add16". This is similar 
134
-- to "alu_add16" except it sets the Carry bit to B7 of the result
135
-- in ACCB, sets the Zero bit if the 16 bit result is zero, but
136
-- does not affect The Half carry (H), Negative (N) or Overflow (V)
137
-- flags. The logic was re-arranged so that it adds md or zero so 
138
-- that the Carry condition code is set on zero multiplicands.
139
-- 5. DAA (Decimal Adjust Accumulator) should set the Negative (N)
140
-- and Zero Flags. It will also affect the Overflow (V) flag although
141
-- the operation is undefined. It's anyones guess what DAA does to V.
142
--
143
-- Version 1.15 - 25th Feb 2007 - John Kent
144
-- line 9672 changed "if Halt <= '1' then" to "if Halt = '1' then"
145
-- Changed sensitivity lists.
146
--
147
-- Version 1.16 - 5th February 2008 - John Kent
148
-- FIRQ interrupts should take priority over IRQ Interrupts.
149
-- This presumably means they should be tested for before IRQ
150
-- when they happen concurrently.
151
--
152
-- Version 1.17 - 18th February 2008 - John Kent
153
-- NMI in CWAI should mask IRQ and FIRQ interrupts
154
--
155
-- Version 1.18 Dummy - 21st February 2008 -John Kent
156
-- patched FIRQ to return from interrupt
157
--
158
library ieee;
159
use ieee.std_logic_1164.all;
160
use ieee.std_logic_unsigned.all;
161
 
162
entity cpu09 is
163
        port (
164
                clk:        in  std_logic;
165
                rst:        in  std_logic;
166
                rw:         out std_logic;
167
                vma:        out std_logic;
168
                address:         out std_logic_vector(15 downto 0);
169
           data_in:      in  std_logic_vector(7 downto 0);
170
           data_out: out std_logic_vector(7 downto 0);
171
                halt:     in  std_logic;
172
                hold:     in  std_logic;
173
                irq:      in  std_logic;
174
                firq:     in  std_logic;
175
                nmi:      in  std_logic
176
                );
177
end cpu09;
178
 
179
architecture rtl of cpu09 is
180
 
181
  constant EBIT : integer := 7;
182
  constant FBIT : integer := 6;
183
  constant HBIT : integer := 5;
184
  constant IBIT : integer := 4;
185
  constant NBIT : integer := 3;
186
  constant ZBIT : integer := 2;
187
  constant VBIT : integer := 1;
188
  constant CBIT : integer := 0;
189
 
190
  --
191
  -- Interrupt vector modifiers
192
  --
193
  constant RST_VEC  : std_logic_vector(2 downto 0) := "111";
194
  constant NMI_VEC  : std_logic_vector(2 downto 0) := "110";
195
  constant SWI_VEC  : std_logic_vector(2 downto 0) := "101";
196
  constant IRQ_VEC  : std_logic_vector(2 downto 0) := "100";
197
  constant FIRQ_VEC : std_logic_vector(2 downto 0) := "011";
198
  constant SWI2_VEC : std_logic_vector(2 downto 0) := "010";
199
  constant SWI3_VEC : std_logic_vector(2 downto 0) := "001";
200
  constant RESV_VEC : std_logic_vector(2 downto 0) := "000";
201
 
202
        type state_type is (-- Start off in Reset
203
                            reset_state,
204
                                                          -- Fetch Interrupt Vectors (including reset)
205
                                                          vect_lo_state, vect_hi_state,
206
                       -- Fetch Instruction Cycle
207
                       fetch_state,
208
                                                          -- Decode Instruction Cycles
209
                       decode1_state, decode2_state, decode3_state,
210
                                                          -- Calculate Effective Address
211
                                                     imm16_state,
212
                                 indexed_state, index8_state, index16_state, index16_2_state,
213
                                                          pcrel8_state, pcrel16_state, pcrel16_2_state,
214
                                                          indexaddr_state, indexaddr2_state,
215
                                                     postincr1_state, postincr2_state,
216
                                                          indirect_state, indirect2_state, indirect3_state,
217
                       extended_state,
218
                                                          -- single ops
219
                                                          single_op_read_state,
220
                                                     single_op_exec_state,
221
                            single_op_write_state,
222
                                                          -- Dual op states
223
                                                          dual_op_read8_state, dual_op_read16_state, dual_op_read16_2_state,
224
                                                     dual_op_write8_state, dual_op_write16_state,
225
                       -- 
226
                                                     sync_state, halt_state, error_state,
227
                                                          --
228
                                                          andcc_state, orcc_state,
229
                                                          tfr_state, exg_state, exg1_state,
230
                                                          lea_state,
231
                                                          -- Multiplication
232
                                                     mul_state, mulea_state, muld_state,
233
                                                     mul0_state, mul1_state, mul2_state, mul3_state,
234
                                                     mul4_state, mul5_state, mul6_state, mul7_state,
235
                                                          --  Branches
236
                                                          lbranch_state, sbranch_state,
237
                                                          -- Jumps, Subroutine Calls and Returns
238
                       jsr_state, jmp_state,
239
                       push_return_hi_state, push_return_lo_state,
240
                       pull_return_hi_state, pull_return_lo_state,
241
                                                          -- Interrupt cycles
242
                                                          int_decr_state,
243
                                                          int_entire_state,
244
                                                          int_pcl_state,  int_pch_state,
245
                                                     int_upl_state,  int_uph_state,
246
                                                     int_iyl_state,  int_iyh_state,
247
                                                     int_ixl_state,  int_ixh_state,
248
                                                     int_cc_state,
249
                                           int_acca_state, int_accb_state,
250
                                                     int_dp_state,
251
                                                     int_cwai_state,  int_mask_state,
252
                                                          -- Return From Interrupt
253
                                                     rti_cc_state,   rti_entire_state,
254
                                                          rti_acca_state, rti_accb_state,
255
                                                     rti_dp_state,
256
                                                     rti_ixl_state,  rti_ixh_state,
257
                                                     rti_iyl_state,  rti_iyh_state,
258
                                                     rti_upl_state,  rti_uph_state,
259
                                                     rti_pcl_state,  rti_pch_state,
260
                                                          -- Push Registers using SP
261
                                                          pshs_state,
262
                                                     pshs_pcl_state,  pshs_pch_state,
263
                                                     pshs_upl_state,  pshs_uph_state,
264
                                                     pshs_iyl_state,  pshs_iyh_state,
265
                                                     pshs_ixl_state,  pshs_ixh_state,
266
                                                     pshs_dp_state,
267
                                                     pshs_acca_state, pshs_accb_state,
268
                                                     pshs_cc_state,
269
                                                          -- Pull Registers using SP
270
                                                          puls_state,
271
                                                          puls_cc_state,
272
                                                          puls_acca_state, puls_accb_state,
273
                                                          puls_dp_state,
274
                                                     puls_ixl_state,  puls_ixh_state,
275
                                                     puls_iyl_state,  puls_iyh_state,
276
                                                     puls_upl_state,  puls_uph_state,
277
                                                     puls_pcl_state,  puls_pch_state,
278
                                                          -- Push Registers using UP
279
                                                          pshu_state,
280
                                                     pshu_pcl_state,  pshu_pch_state,
281
                                                     pshu_spl_state,  pshu_sph_state,
282
                                                     pshu_iyl_state,  pshu_iyh_state,
283
                                                     pshu_ixl_state,  pshu_ixh_state,
284
                                                     pshu_dp_state,
285
                                                     pshu_acca_state, pshu_accb_state,
286
                                                     pshu_cc_state,
287
                                                          -- Pull Registers using UP
288
                                                          pulu_state,
289
                                                          pulu_cc_state,
290
                                                          pulu_acca_state, pulu_accb_state,
291
                                                          pulu_dp_state,
292
                                                     pulu_ixl_state,  pulu_ixh_state,
293
                                                     pulu_iyl_state,  pulu_iyh_state,
294
                                                     pulu_spl_state,  pulu_sph_state,
295
                                                     pulu_pcl_state,  pulu_pch_state );
296
 
297
        type stack_type is array(2 downto 0) of state_type;
298
        type st_type    is (idle_st, push_st, pull_st );
299
        type addr_type  is (idle_ad, fetch_ad, read_ad, write_ad, pushu_ad, pullu_ad, pushs_ad, pulls_ad, int_hi_ad, int_lo_ad );
300
        type dout_type  is (cc_dout, acca_dout, accb_dout, dp_dout,
301
                       ix_lo_dout, ix_hi_dout, iy_lo_dout, iy_hi_dout,
302
                       up_lo_dout, up_hi_dout, sp_lo_dout, sp_hi_dout,
303
                       pc_lo_dout, pc_hi_dout, md_lo_dout, md_hi_dout );
304
   type op_type    is (reset_op, fetch_op, latch_op );
305
   type pre_type   is (reset_pre, fetch_pre, latch_pre );
306
   type cc_type    is (reset_cc, load_cc, pull_cc, latch_cc );
307
   type acca_type  is (reset_acca, load_acca, load_hi_acca, pull_acca, latch_acca );
308
   type accb_type  is (reset_accb, load_accb, pull_accb, latch_accb );
309
   type dp_type    is (reset_dp, load_dp, pull_dp, latch_dp );
310
        type ix_type    is (reset_ix, load_ix, pull_lo_ix, pull_hi_ix, latch_ix );
311
        type iy_type    is (reset_iy, load_iy, pull_lo_iy, pull_hi_iy, latch_iy );
312
        type sp_type    is (reset_sp, latch_sp, load_sp, pull_hi_sp, pull_lo_sp );
313
        type up_type    is (reset_up, latch_up, load_up, pull_hi_up, pull_lo_up );
314
        type pc_type    is (reset_pc, latch_pc, load_pc, pull_lo_pc, pull_hi_pc, incr_pc );
315
   type md_type    is (reset_md, latch_md, load_md, fetch_first_md, fetch_next_md, shiftl_md );
316
   type ea_type    is (reset_ea, latch_ea, load_ea, fetch_first_ea, fetch_next_ea );
317
        type iv_type    is (reset_iv, latch_iv, nmi_iv, irq_iv, firq_iv, swi_iv, swi2_iv, swi3_iv, resv_iv);
318
        type nmi_type   is (reset_nmi, set_nmi, latch_nmi );
319
        type left_type  is (cc_left, acca_left, accb_left, dp_left,
320
                                                          ix_left, iy_left, up_left, sp_left,
321
                       accd_left, md_left, pc_left, ea_left );
322
        type right_type is (ea_right, zero_right, one_right, two_right,
323
                       acca_right, accb_right, accd_right,
324
                                                          md_right, md_sign5_right, md_sign8_right );
325
   type alu_type   is (alu_add8, alu_sub8, alu_add16, alu_sub16, alu_adc, alu_sbc,
326
                       alu_and, alu_ora, alu_eor,
327
                       alu_tst, alu_inc, alu_dec, alu_clr, alu_neg, alu_com,
328
                                                     alu_lsr16, alu_lsl16,
329
                                                     alu_ror8, alu_rol8, alu_mul,
330
                                                     alu_asr8, alu_asl8, alu_lsr8,
331
                                                     alu_andcc, alu_orcc, alu_sex, alu_tfr, alu_abx,
332
                                                          alu_seif, alu_sei, alu_see, alu_cle,
333
                                                     alu_ld8, alu_st8, alu_ld16, alu_st16, alu_lea, alu_nop, alu_daa );
334
 
335
        signal op_code:     std_logic_vector(7 downto 0);
336
        signal pre_code:    std_logic_vector(7 downto 0);
337
        signal acca:        std_logic_vector(7 downto 0);
338
        signal accb:        std_logic_vector(7 downto 0);
339
   signal cc:          std_logic_vector(7 downto 0);
340
        signal cc_out:      std_logic_vector(7 downto 0);
341
        signal dp:          std_logic_vector(7 downto 0);
342
        signal xreg:        std_logic_vector(15 downto 0);
343
        signal yreg:        std_logic_vector(15 downto 0);
344
        signal sp:          std_logic_vector(15 downto 0);
345
        signal up:          std_logic_vector(15 downto 0);
346
        signal ea:          std_logic_vector(15 downto 0);
347
        signal pc:              std_logic_vector(15 downto 0);
348
        signal md:          std_logic_vector(15 downto 0);
349
   signal left:        std_logic_vector(15 downto 0);
350
   signal right:       std_logic_vector(15 downto 0);
351
        signal out_alu:     std_logic_vector(15 downto 0);
352
        signal iv:          std_logic_vector(2 downto 0);
353
        signal nmi_req:     std_logic;
354
        signal nmi_ack:     std_logic;
355
        signal nmi_enable:  std_logic;
356
 
357
        signal state:        state_type;
358
        signal next_state:   state_type;
359
        signal saved_state:  state_type;
360
        signal return_state: state_type;
361
        signal state_stack:  stack_type;
362
        signal st_ctrl:      st_type;
363
   signal pc_ctrl:      pc_type;
364
   signal ea_ctrl:      ea_type;
365
   signal op_ctrl:      op_type;
366
        signal pre_ctrl:     pre_type;
367
        signal md_ctrl:      md_type;
368
        signal acca_ctrl:    acca_type;
369
        signal accb_ctrl:    accb_type;
370
        signal ix_ctrl:      ix_type;
371
        signal iy_ctrl:      iy_type;
372
        signal cc_ctrl:      cc_type;
373
        signal dp_ctrl:      dp_type;
374
        signal sp_ctrl:      sp_type;
375
        signal up_ctrl:      up_type;
376
        signal iv_ctrl:      iv_type;
377
        signal left_ctrl:    left_type;
378
        signal right_ctrl:   right_type;
379
   signal alu_ctrl:     alu_type;
380
   signal addr_ctrl:    addr_type;
381
   signal dout_ctrl:    dout_type;
382
   signal nmi_ctrl:     nmi_type;
383
 
384
 
385
begin
386
 
387
----------------------------------
388
--
389
-- State machine stack
390
--
391
----------------------------------
392
--state_stack_proc: process( clk, hold, state_stack, st_ctrl, 
393
--                           return_state, fetch_state  )
394
state_stack_proc: process( clk, state_stack )
395
begin
396
  if clk'event and clk = '0' then
397
    if hold= '1' then
398
           state_stack(0) <= state_stack(0);
399
           state_stack(1) <= state_stack(1);
400
           state_stack(2) <= state_stack(2);
401
         else
402
           case st_ctrl is
403
                when idle_st =>
404
                  state_stack(0) <= state_stack(0);
405
             state_stack(1) <= state_stack(1);
406
             state_stack(2) <= state_stack(2);
407
      when push_st =>
408
                  state_stack(0) <= return_state;
409
             state_stack(1) <= state_stack(0);
410
             state_stack(2) <= state_stack(1);
411
      when pull_st =>
412
                  state_stack(0) <= state_stack(1);
413
             state_stack(1) <= state_stack(2);
414
             state_stack(2) <= fetch_state;
415
                when others =>
416
                  state_stack(0) <= state_stack(0);
417
             state_stack(1) <= state_stack(1);
418
             state_stack(2) <= state_stack(2);
419
           end case;
420
    end if;
421
  end if;
422
  saved_state <= state_stack(0);
423
end process;
424
 
425
----------------------------------
426
--
427
-- Program Counter Control
428
--
429
----------------------------------
430
 
431
--pc_reg: process( clk, pc_ctrl, hold, pc, out_alu, data_in )
432
pc_reg: process( clk )
433
begin
434
  if clk'event and clk = '0' then
435
    if hold= '1' then
436
           pc <= pc;
437
         else
438
    case pc_ctrl is
439
         when reset_pc =>
440
           pc <= "0000000000000000";
441
         when load_pc =>
442
           pc <= out_alu(15 downto 0);
443
         when pull_lo_pc =>
444
           pc(7 downto 0) <= data_in;
445
         when pull_hi_pc =>
446
           pc(15 downto 8) <= data_in;
447
         when incr_pc =>
448
           pc <= pc + 1;
449
         when others =>
450
--       when latch_pc =>
451
      pc <= pc;
452
    end case;
453
         end if;
454
  end if;
455
end process;
456
 
457
----------------------------------
458
--
459
-- Effective Address  Control
460
--
461
----------------------------------
462
 
463
--ea_reg: process( clk, ea_ctrl, hold, ea, out_alu, data_in, dp )
464
ea_reg: process( clk )
465
begin
466
 
467
  if clk'event and clk = '0' then
468
    if hold= '1' then
469
           ea <= ea;
470
         else
471
    case ea_ctrl is
472
         when reset_ea =>
473
           ea <= "0000000000000000";
474
         when fetch_first_ea =>
475
           ea(7 downto 0) <= data_in;
476
      ea(15 downto 8) <= dp;
477
         when fetch_next_ea =>
478
           ea(15 downto 8) <= ea(7 downto 0);
479
      ea(7 downto 0)  <= data_in;
480
         when load_ea =>
481
           ea <= out_alu(15 downto 0);
482
         when others =>
483
--       when latch_ea =>
484
      ea <= ea;
485
    end case;
486
         end if;
487
  end if;
488
end process;
489
 
490
--------------------------------
491
--
492
-- Accumulator A
493
--
494
--------------------------------
495
--acca_reg : process( clk, acca_ctrl, hold, out_alu, acca, data_in )
496
acca_reg : process( clk )
497
begin
498
  if clk'event and clk = '0' then
499
    if hold= '1' then
500
           acca <= acca;
501
         else
502
    case acca_ctrl is
503
    when reset_acca =>
504
           acca <= "00000000";
505
         when load_acca =>
506
           acca <= out_alu(7 downto 0);
507
         when load_hi_acca =>
508
           acca <= out_alu(15 downto 8);
509
         when pull_acca =>
510
           acca <= data_in;
511
         when others =>
512
--       when latch_acca =>
513
           acca <= acca;
514
    end case;
515
         end if;
516
  end if;
517
end process;
518
 
519
--------------------------------
520
--
521
-- Accumulator B
522
--
523
--------------------------------
524
--accb_reg : process( clk, accb_ctrl, hold, out_alu, accb, data_in )
525
accb_reg : process( clk )
526
begin
527
  if clk'event and clk = '0' then
528
    if hold= '1' then
529
           accb <= accb;
530
         else
531
    case accb_ctrl is
532
    when reset_accb =>
533
           accb <= "00000000";
534
         when load_accb =>
535
           accb <= out_alu(7 downto 0);
536
         when pull_accb =>
537
           accb <= data_in;
538
         when others =>
539
--       when latch_accb =>
540
           accb <= accb;
541
    end case;
542
         end if;
543
  end if;
544
end process;
545
 
546
--------------------------------
547
--
548
-- X Index register
549
--
550
--------------------------------
551
--ix_reg : process( clk, ix_ctrl, hold, out_alu, xreg, data_in )
552
ix_reg : process( clk )
553
begin
554
  if clk'event and clk = '0' then
555
    if hold= '1' then
556
           xreg <= xreg;
557
         else
558
    case ix_ctrl is
559
    when reset_ix =>
560
           xreg <= "0000000000000000";
561
         when load_ix =>
562
           xreg <= out_alu(15 downto 0);
563
         when pull_hi_ix =>
564
           xreg(15 downto 8) <= data_in;
565
         when pull_lo_ix =>
566
           xreg(7 downto 0) <= data_in;
567
         when others =>
568
--       when latch_ix =>
569
           xreg <= xreg;
570
    end case;
571
         end if;
572
  end if;
573
end process;
574
 
575
--------------------------------
576
--
577
-- Y Index register
578
--
579
--------------------------------
580
--iy_reg : process( clk, iy_ctrl, hold, out_alu, yreg, data_in )
581
iy_reg : process( clk )
582
begin
583
  if clk'event and clk = '0' then
584
    if hold= '1' then
585
           yreg <= yreg;
586
         else
587
    case iy_ctrl is
588
    when reset_iy =>
589
           yreg <= "0000000000000000";
590
         when load_iy =>
591
           yreg <= out_alu(15 downto 0);
592
         when pull_hi_iy =>
593
           yreg(15 downto 8) <= data_in;
594
         when pull_lo_iy =>
595
           yreg(7 downto 0) <= data_in;
596
         when others =>
597
--       when latch_iy =>
598
           yreg <= yreg;
599
    end case;
600
         end if;
601
  end if;
602
end process;
603
 
604
--------------------------------
605
--
606
-- S stack pointer
607
--
608
--------------------------------
609
--sp_reg : process( clk, sp_ctrl, hold, sp, out_alu, data_in, nmi_enable )
610
sp_reg : process( clk )
611
begin
612
  if clk'event and clk = '0' then
613
    if hold= '1' then
614
           sp <= sp;
615
                nmi_enable <= nmi_enable;
616
         else
617
    case sp_ctrl is
618
    when reset_sp =>
619
           sp <= "0000000000000000";
620
                nmi_enable <= '0';
621
         when load_sp =>
622
           sp <= out_alu(15 downto 0);
623
                nmi_enable <= '1';
624
         when pull_hi_sp =>
625
           sp(15 downto 8) <= data_in;
626
                nmi_enable <= nmi_enable;
627
         when pull_lo_sp =>
628
           sp(7 downto 0) <= data_in;
629
                nmi_enable <= '1';
630
         when others =>
631
--       when latch_sp =>
632
           sp <= sp;
633
                nmi_enable <= nmi_enable;
634
    end case;
635
         end if;
636
  end if;
637
end process;
638
 
639
--------------------------------
640
--
641
-- U stack pointer
642
--
643
--------------------------------
644
--up_reg : process( clk, up_ctrl, hold, up, out_alu, data_in )
645
up_reg : process( clk )
646
begin
647
  if clk'event and clk = '0' then
648
    if hold= '1' then
649
           up <= up;
650
         else
651
    case up_ctrl is
652
    when reset_up =>
653
           up <= "0000000000000000";
654
         when load_up =>
655
           up <= out_alu(15 downto 0);
656
         when pull_hi_up =>
657
           up(15 downto 8) <= data_in;
658
         when pull_lo_up =>
659
           up(7 downto 0) <= data_in;
660
         when others =>
661
--       when latch_up =>
662
           up <= up;
663
    end case;
664
         end if;
665
  end if;
666
end process;
667
 
668
--------------------------------
669
--
670
-- Memory Data
671
--
672
--------------------------------
673
--md_reg : process( clk, md_ctrl, hold, out_alu, data_in, md )
674
md_reg : process( clk )
675
begin
676
  if clk'event and clk = '0' then
677
    if hold= '1' then
678
           md <= md;
679
         else
680
    case md_ctrl is
681
    when reset_md =>
682
           md <= "0000000000000000";
683
         when load_md =>
684
           md <= out_alu(15 downto 0);
685
         when fetch_first_md => -- sign extend md for branches
686
           md(15 downto 8) <= data_in(7) & data_in(7) & data_in(7) & data_in(7) &
687
                              data_in(7) & data_in(7) & data_in(7) & data_in(7) ;
688
           md(7 downto 0) <= data_in;
689
         when fetch_next_md =>
690
           md(15 downto 8) <= md(7 downto 0);
691
                md(7 downto 0) <= data_in;
692
         when shiftl_md =>
693
           md(15 downto 1) <= md(14 downto 0);
694
                md(0) <= '0';
695
         when others =>
696
--       when latch_md =>
697
           md <= md;
698
    end case;
699
         end if;
700
  end if;
701
end process;
702
 
703
 
704
----------------------------------
705
--
706
-- Condition Codes
707
--
708
----------------------------------
709
 
710
--cc_reg: process( clk, cc_ctrl, hold, cc_out, cc, data_in )
711
cc_reg: process( clk )
712
begin
713
  if clk'event and clk = '0' then
714
    if hold= '1' then
715
           cc <= cc;
716
         else
717
    case cc_ctrl is
718
         when reset_cc =>
719
           cc <= "11010000"; -- set EBIT, FBIT & IBIT
720
         when load_cc =>
721
           cc <= cc_out;
722
         when pull_cc =>
723
      cc <= data_in;
724
         when others =>
725
--  when latch_cc =>
726
      cc <= cc;
727
    end case;
728
         end if;
729
  end if;
730
end process;
731
 
732
----------------------------------
733
--
734
-- Direct Page register
735
--
736
----------------------------------
737
 
738
--dp_reg: process( clk, dp_ctrl, hold, out_alu, dp, data_in )
739
dp_reg: process( clk )
740
begin
741
  if clk'event and clk = '0' then
742
    if hold= '1' then
743
           dp <= dp;
744
         else
745
    case dp_ctrl is
746
         when reset_dp =>
747
           dp <= "00000000";
748
         when load_dp =>
749
           dp <= out_alu(7 downto 0);
750
         when pull_dp =>
751
      dp <= data_in;
752
         when others =>
753
--  when latch_dp =>
754
      dp <= dp;
755
    end case;
756
         end if;
757
  end if;
758
end process;
759
 
760
----------------------------------
761
--
762
-- interrupt vector
763
--
764
----------------------------------
765
 
766
--iv_mux: process( clk, iv_ctrl, hold, iv )
767
iv_mux: process( clk )
768
begin
769
  if clk'event and clk = '0' then
770
    if hold= '1' then
771
           iv <= iv;
772
         else
773
    case iv_ctrl is
774
         when reset_iv =>
775
           iv <= RST_VEC;
776
         when nmi_iv =>
777
      iv <= NMI_VEC;
778
         when swi_iv =>
779
      iv <= SWI_VEC;
780
         when irq_iv =>
781
      iv <= IRQ_VEC;
782
         when firq_iv =>
783
           iv <= FIRQ_VEC;
784
         when swi2_iv =>
785
      iv <= SWI2_VEC;
786
         when swi3_iv =>
787
      iv <= SWI3_VEC;
788
         when resv_iv =>
789
      iv <= RESV_VEC;
790
         when others =>
791
           iv <= iv;
792
    end case;
793
         end if;
794
  end if;
795
end process;
796
 
797
 
798
----------------------------------
799
--
800
-- op code register
801
--
802
----------------------------------
803
 
804
--op_reg: process( clk, op_ctrl, hold, op_code, data_in )
805
op_reg: process( clk )
806
begin
807
  if clk'event and clk = '0' then
808
    if hold= '1' then
809
           op_code <= op_code;
810
         else
811
    case op_ctrl is
812
         when reset_op =>
813
           op_code <= "00010010";
814
         when fetch_op =>
815
      op_code <= data_in;
816
         when others =>
817
--       when latch_op =>
818
           op_code <= op_code;
819
    end case;
820
         end if;
821
  end if;
822
end process;
823
 
824
 
825
----------------------------------
826
--
827
-- pre byte op code register
828
--
829
----------------------------------
830
 
831
--pre_reg: process( clk, pre_ctrl, hold, pre_code, data_in )
832
pre_reg: process( clk )
833
begin
834
  if clk'event and clk = '0' then
835
    if hold= '1' then
836
           pre_code <= pre_code;
837
         else
838
    case pre_ctrl is
839
         when reset_pre =>
840
           pre_code <= "00000000";
841
         when fetch_pre =>
842
      pre_code <= data_in;
843
         when others =>
844
--       when latch_pre =>
845
           pre_code <= pre_code;
846
    end case;
847
         end if;
848
  end if;
849
end process;
850
 
851
--------------------------------
852
--
853
-- state machine
854
--
855
--------------------------------
856
 
857
--change_state: process( clk, rst, state, hold, next_state )
858
change_state: process( clk )
859
begin
860
  if clk'event and clk = '0' then
861
    if rst = '1' then
862
           state <= reset_state;
863
    else
864
           if hold = '1' then
865
                  state <= state;
866
                else
867
        state <= next_state;
868
                end if;
869
         end if;
870
  end if;
871
end process;
872
        -- output
873
 
874
------------------------------------
875
--
876
-- Nmi register
877
--
878
------------------------------------
879
 
880
--nmi_reg: process( clk, nmi_ctrl, hold, nmi_ack )
881
nmi_reg: process( clk )
882
begin
883
  if clk'event and clk='0' then
884
    if hold = '1' then
885
      nmi_ack <= nmi_ack;
886
    else
887
    case nmi_ctrl is
888
         when set_nmi =>
889
      nmi_ack <= '1';
890
         when reset_nmi =>
891
           nmi_ack <= '0';
892
         when others =>
893
--  when latch_nmi =>
894
           nmi_ack <= nmi_ack;
895
         end case;
896
         end if;
897
  end if;
898
end process;
899
 
900
------------------------------------
901
--
902
-- Detect Edge of NMI interrupt
903
--
904
------------------------------------
905
 
906
--nmi_handler : process( clk, rst, nmi, nmi_ack, nmi_req, nmi_enable )
907
nmi_handler : process( clk )
908
begin
909
  if clk'event and clk='0' then
910
    if rst='1' then
911
           nmi_req <= '0';
912
    else
913
           if (nmi='1') and (nmi_ack='0') and (nmi_enable='1') then
914
             nmi_req <= '1';
915
           else
916
                  if (nmi='0') and (nmi_ack='1') then
917
               nmi_req <= '0';
918
             else
919
               nmi_req <= nmi_req;
920
                  end if;
921
                end if;
922
         end if;
923
  end if;
924
end process;
925
 
926
 
927
----------------------------------
928
--
929
-- Address output multiplexer
930
--
931
----------------------------------
932
 
933
addr_mux: process( addr_ctrl, pc, ea, up, sp, iv )
934
begin
935
  case addr_ctrl is
936
    when idle_ad =>
937
           address <= "1111111111111111";
938
                vma     <= '0';
939
                rw      <= '1';
940
    when fetch_ad =>
941
           address <= pc;
942
                vma     <= '1';
943
                rw      <= '1';
944
         when read_ad =>
945
           address <= ea;
946
                vma     <= '1';
947
                rw      <= '1';
948
    when write_ad =>
949
           address <= ea;
950
                vma     <= '1';
951
                rw      <= '0';
952
         when pushs_ad =>
953
           address <= sp;
954
                vma     <= '1';
955
                rw      <= '0';
956
    when pulls_ad =>
957
           address <= sp;
958
                vma     <= '1';
959
                rw      <= '1';
960
         when pushu_ad =>
961
           address <= up;
962
                vma     <= '1';
963
                rw      <= '0';
964
    when pullu_ad =>
965
           address <= up;
966
                vma     <= '1';
967
                rw      <= '1';
968
         when int_hi_ad =>
969
           address <= "111111111111" & iv & "0";
970
                vma     <= '1';
971
                rw      <= '1';
972
    when int_lo_ad =>
973
           address <= "111111111111" & iv & "1";
974
                vma     <= '1';
975
                rw      <= '1';
976
         when others =>
977
           address <= "1111111111111111";
978
                vma     <= '0';
979
                rw      <= '1';
980
  end case;
981
end process;
982
 
983
--------------------------------
984
--
985
-- Data Bus output
986
--
987
--------------------------------
988
dout_mux : process( dout_ctrl, md, acca, accb, dp, xreg, yreg, sp, up, pc, cc )
989
begin
990
    case dout_ctrl is
991
         when md_hi_dout => -- alu output
992
           data_out <= md(15 downto 8);
993
         when md_lo_dout => -- alu output
994
           data_out <= md(7 downto 0);
995
         when acca_dout => -- accumulator a
996
           data_out <= acca;
997
         when accb_dout => -- accumulator b
998
           data_out <= accb;
999
         when ix_lo_dout => -- index reg
1000
           data_out <= xreg(7 downto 0);
1001
         when ix_hi_dout => -- index reg
1002
           data_out <= xreg(15 downto 8);
1003
         when iy_lo_dout => -- index reg
1004
           data_out <= yreg(7 downto 0);
1005
         when iy_hi_dout => -- index reg
1006
           data_out <= yreg(15 downto 8);
1007
         when sp_lo_dout => -- s stack pointer
1008
           data_out <= sp(7 downto 0);
1009
         when sp_hi_dout => -- s stack pointer
1010
           data_out <= sp(15 downto 8);
1011
         when up_lo_dout => -- u stack pointer
1012
           data_out <= up(7 downto 0);
1013
         when up_hi_dout => -- u stack pointer
1014
           data_out <= up(15 downto 8);
1015
         when cc_dout => -- condition code register
1016
           data_out <= cc;
1017
         when dp_dout => -- direct page register
1018
           data_out <= dp;
1019
         when pc_lo_dout => -- low order pc
1020
           data_out <= pc(7 downto 0);
1021
         when pc_hi_dout => -- high order pc
1022
           data_out <= pc(15 downto 8);
1023
         when others =>
1024
           data_out <= "00000000";
1025
    end case;
1026
end process;
1027
 
1028
----------------------------------
1029
--
1030
-- Left Mux
1031
--
1032
----------------------------------
1033
 
1034
left_mux: process( left_ctrl, acca, accb, cc, dp, xreg, yreg, up, sp, pc, ea, md )
1035
begin
1036
  case left_ctrl is
1037
         when cc_left =>
1038
           left(15 downto 8) <= "00000000";
1039
                left(7 downto 0)  <= cc;
1040
         when acca_left =>
1041
           left(15 downto 8) <= "00000000";
1042
                left(7 downto 0)  <= acca;
1043
         when accb_left =>
1044
           left(15 downto 8) <= "00000000";
1045
                left(7 downto 0)  <= accb;
1046
         when dp_left =>
1047
           left(15 downto 8) <= "00000000";
1048
                left(7 downto 0)  <= dp;
1049
         when accd_left =>
1050
           left(15 downto 8) <= acca;
1051
                left(7 downto 0)  <= accb;
1052
         when md_left =>
1053
           left <= md;
1054
         when ix_left =>
1055
           left <= xreg;
1056
         when iy_left =>
1057
           left <= yreg;
1058
         when sp_left =>
1059
           left <= sp;
1060
         when up_left =>
1061
           left <= up;
1062
         when pc_left =>
1063
           left <= pc;
1064
         when others =>
1065
--       when ea_left =>
1066
           left <= ea;
1067
    end case;
1068
end process;
1069
 
1070
----------------------------------
1071
--
1072
-- Right Mux
1073
--
1074
----------------------------------
1075
 
1076
right_mux: process( right_ctrl, md, acca, accb, ea )
1077
begin
1078
  case right_ctrl is
1079
         when ea_right =>
1080
           right <= ea;
1081
         when zero_right =>
1082
           right <= "0000000000000000";
1083
         when one_right =>
1084
           right <= "0000000000000001";
1085
         when two_right =>
1086
           right <= "0000000000000010";
1087
         when acca_right =>
1088
           if acca(7) = '0' then
1089
             right <= "00000000" & acca(7 downto 0);
1090
                else
1091
                  right <= "11111111" & acca(7 downto 0);
1092
                end if;
1093
         when accb_right =>
1094
           if accb(7) = '0' then
1095
             right <= "00000000" & accb(7 downto 0);
1096
                else
1097
                  right <= "11111111" & accb(7 downto 0);
1098
                end if;
1099
         when accd_right =>
1100
           right <= acca & accb;
1101
         when md_sign5_right =>
1102
           if md(4) = '0' then
1103
             right <= "00000000000" & md(4 downto 0);
1104
                else
1105
                  right <= "11111111111" & md(4 downto 0);
1106
                end if;
1107
         when md_sign8_right =>
1108
           if md(7) = '0' then
1109
             right <= "00000000" & md(7 downto 0);
1110
                else
1111
                  right <= "11111111" & md(7 downto 0);
1112
                end if;
1113
         when others =>
1114
--       when md_right =>
1115
           right <= md;
1116
    end case;
1117
end process;
1118
 
1119
----------------------------------
1120
--
1121
-- Arithmetic Logic Unit
1122
--
1123
----------------------------------
1124
 
1125
alu: process( alu_ctrl, cc, left, right, out_alu, cc_out )
1126
variable valid_lo, valid_hi : boolean;
1127
variable carry_in : std_logic;
1128
variable daa_reg : std_logic_vector(7 downto 0);
1129
begin
1130
 
1131
  case alu_ctrl is
1132
         when alu_adc | alu_sbc |
1133
              alu_rol8 | alu_ror8 =>
1134
           carry_in := cc(CBIT);
1135
    when alu_asr8 =>
1136
           carry_in := left(7);
1137
         when others =>
1138
           carry_in := '0';
1139
  end case;
1140
 
1141
  valid_lo := left(3 downto 0) <= 9;
1142
  valid_hi := left(7 downto 4) <= 9;
1143
 
1144
  if (cc(CBIT) = '0') then
1145
    if( cc(HBIT) = '1' ) then
1146
                if valid_hi then
1147
                  daa_reg := "00000110";
1148
                else
1149
                  daa_reg := "01100110";
1150
           end if;
1151
    else
1152
                if valid_lo then
1153
                  if valid_hi then
1154
                    daa_reg := "00000000";
1155
                  else
1156
                    daa_reg := "01100000";
1157
                  end if;
1158
                else
1159
             if( left(7 downto 4) <= 8 ) then
1160
                    daa_reg := "00000110";
1161
                  else
1162
                         daa_reg := "01100110";
1163
                  end if;
1164
                end if;
1165
         end if;
1166
  else
1167
    if ( cc(HBIT) = '1' )then
1168
                daa_reg := "01100110";
1169
         else
1170
                if valid_lo then
1171
                  daa_reg := "01100000";
1172
           else
1173
                  daa_reg := "01100110";
1174
                end if;
1175
         end if;
1176
  end if;
1177
 
1178
  case alu_ctrl is
1179
         when alu_add8 | alu_inc |
1180
              alu_add16 | alu_adc | alu_mul =>
1181
                out_alu <= left + right + ("000000000000000" & carry_in);
1182
         when alu_sub8 | alu_dec |
1183
              alu_sub16 | alu_sbc =>
1184
           out_alu <= left - right - ("000000000000000" & carry_in);
1185
    when alu_abx =>
1186
           out_alu <= left + ("00000000" & right(7 downto 0)) ;
1187
         when alu_and =>
1188
           out_alu   <= left and right;         -- and/bit
1189
         when alu_ora =>
1190
           out_alu   <= left or right;  -- or
1191
         when alu_eor =>
1192
           out_alu   <= left xor right;         -- eor/xor
1193
         when alu_lsl16 | alu_asl8 | alu_rol8 =>
1194
           out_alu   <= left(14 downto 0) & carry_in;    -- rol8/asl8/lsl16
1195
         when alu_lsr16 =>
1196
           out_alu   <= carry_in & left(15 downto 1);   -- lsr16
1197
         when alu_lsr8 | alu_asr8 | alu_ror8 =>
1198
           out_alu   <= "00000000" & carry_in & left(7 downto 1);       -- ror8/asr8/lsr8
1199
         when alu_neg =>
1200
           out_alu   <= right - left;   -- neg (right=0)
1201
         when alu_com =>
1202
           out_alu   <= not left;
1203
         when alu_clr | alu_ld8 | alu_ld16 | alu_lea =>
1204
           out_alu   <= right;           -- clr, ld
1205
         when alu_st8 | alu_st16 | alu_andcc | alu_orcc | alu_tfr =>
1206
           out_alu   <= left;
1207
         when alu_daa =>
1208
           out_alu   <= left + ("00000000" & daa_reg);
1209
         when alu_sex =>
1210
           if left(7) = '0' then
1211
              out_alu <= "00000000" & left(7 downto 0);
1212
                else
1213
                   out_alu <= "11111111" & left(7 downto 0);
1214
                end if;
1215
         when others =>
1216
           out_alu   <= left; -- nop
1217
    end case;
1218
 
1219
         --
1220
         -- carry bit
1221
         --
1222
    case alu_ctrl is
1223
         when alu_add8 | alu_adc  =>
1224
      cc_out(CBIT) <= (left(7) and right(7)) or
1225
                                (left(7) and not out_alu(7)) or
1226
                                                   (right(7) and not out_alu(7));
1227
         when alu_sub8 | alu_sbc =>
1228
      cc_out(CBIT) <= ((not left(7)) and right(7)) or
1229
                                ((not left(7)) and out_alu(7)) or
1230
                                                         (right(7) and out_alu(7));
1231
         when alu_add16  =>
1232
      cc_out(CBIT) <= (left(15) and right(15)) or
1233
                                (left(15) and not out_alu(15)) or
1234
                                                   (right(15) and not out_alu(15));
1235
         when alu_sub16 =>
1236
      cc_out(CBIT) <= ((not left(15)) and right(15)) or
1237
                                ((not left(15)) and out_alu(15)) or
1238
                                                         (right(15) and out_alu(15));
1239
         when alu_ror8 | alu_lsr16 | alu_lsr8 | alu_asr8 =>
1240
           cc_out(CBIT) <= left(0);
1241
         when alu_rol8 | alu_asl8 =>
1242
           cc_out(CBIT) <= left(7);
1243
         when alu_lsl16 =>
1244
           cc_out(CBIT) <= left(15);
1245
         when alu_com =>
1246
           cc_out(CBIT) <= '1';
1247
         when alu_neg | alu_clr =>
1248
           cc_out(CBIT) <= out_alu(7) or out_alu(6) or out_alu(5) or out_alu(4) or
1249
                                out_alu(3) or out_alu(2) or out_alu(1) or out_alu(0);
1250
    when alu_mul =>
1251
                cc_out(CBIT) <= out_alu(7);
1252
    when alu_daa =>
1253
           if ( daa_reg(7 downto 4) = "0110" ) then
1254
                  cc_out(CBIT) <= '1';
1255
                else
1256
                  cc_out(CBIT) <= '0';
1257
           end if;
1258
         when alu_andcc =>
1259
      cc_out(CBIT) <= left(CBIT) and cc(CBIT);
1260
         when alu_orcc =>
1261
      cc_out(CBIT) <= left(CBIT) or cc(CBIT);
1262
         when alu_tfr =>
1263
      cc_out(CBIT) <= left(CBIT);
1264
         when others =>
1265
      cc_out(CBIT) <= cc(CBIT);
1266
    end case;
1267
         --
1268
         -- Zero flag
1269
         --
1270
    case alu_ctrl is
1271
         when alu_add8 | alu_sub8 |
1272
              alu_adc | alu_sbc |
1273
              alu_and | alu_ora | alu_eor |
1274
              alu_inc | alu_dec |
1275
                        alu_neg | alu_com | alu_clr |
1276
                        alu_rol8 | alu_ror8 | alu_asr8 | alu_asl8 | alu_lsr8 |
1277
                   alu_ld8  | alu_st8 | alu_sex | alu_daa =>
1278
      cc_out(ZBIT) <= not( out_alu(7)  or out_alu(6)  or out_alu(5)  or out_alu(4)  or
1279
                                out_alu(3)  or out_alu(2)  or out_alu(1)  or out_alu(0) );
1280
         when alu_add16 | alu_sub16 | alu_mul |
1281
              alu_lsl16 | alu_lsr16 |
1282
                   alu_ld16  | alu_st16 | alu_lea =>
1283
      cc_out(ZBIT) <= not( out_alu(15) or out_alu(14) or out_alu(13) or out_alu(12) or
1284
                                out_alu(11) or out_alu(10) or out_alu(9)  or out_alu(8)  or
1285
                                out_alu(7)  or out_alu(6)  or out_alu(5)  or out_alu(4)  or
1286
                                out_alu(3)  or out_alu(2)  or out_alu(1)  or out_alu(0) );
1287
         when alu_andcc =>
1288
      cc_out(ZBIT) <= left(ZBIT) and cc(ZBIT);
1289
         when alu_orcc =>
1290
      cc_out(ZBIT) <= left(ZBIT) or cc(ZBIT);
1291
         when alu_tfr =>
1292
      cc_out(ZBIT) <= left(ZBIT);
1293
         when others =>
1294
      cc_out(ZBIT) <= cc(ZBIT);
1295
    end case;
1296
 
1297
    --
1298
         -- negative flag
1299
         --
1300
    case alu_ctrl is
1301
         when alu_add8 | alu_sub8 |
1302
              alu_adc | alu_sbc |
1303
              alu_and | alu_ora | alu_eor |
1304
              alu_rol8 | alu_ror8 | alu_asr8 | alu_asl8 | alu_lsr8 |
1305
              alu_inc | alu_dec | alu_neg | alu_com | alu_clr |
1306
                        alu_ld8  | alu_st8 | alu_sex | alu_daa =>
1307
      cc_out(NBIT) <= out_alu(7);
1308
         when alu_add16 | alu_sub16 |
1309
              alu_lsl16 | alu_lsr16 |
1310
                        alu_ld16 | alu_st16 =>
1311
                cc_out(NBIT) <= out_alu(15);
1312
         when alu_andcc =>
1313
      cc_out(NBIT) <= left(NBIT) and cc(NBIT);
1314
         when alu_orcc =>
1315
      cc_out(NBIT) <= left(NBIT) or cc(NBIT);
1316
         when alu_tfr =>
1317
      cc_out(NBIT) <= left(NBIT);
1318
         when others =>
1319
      cc_out(NBIT) <= cc(NBIT);
1320
    end case;
1321
 
1322
    --
1323
         -- Interrupt mask flag
1324
    --
1325
    case alu_ctrl is
1326
         when alu_andcc =>
1327
      cc_out(IBIT) <= left(IBIT) and cc(IBIT);
1328
         when alu_orcc =>
1329
      cc_out(IBIT) <= left(IBIT) or cc(IBIT);
1330
         when alu_tfr =>
1331
      cc_out(IBIT) <= left(IBIT);
1332
    when alu_seif | alu_sei =>
1333
           cc_out(IBIT) <= '1';
1334
         when others =>
1335
                cc_out(IBIT) <= cc(IBIT);             -- interrupt mask
1336
    end case;
1337
 
1338
    --
1339
    -- Half Carry flag
1340
         --
1341
    case alu_ctrl is
1342
         when alu_add8 | alu_adc =>
1343
      cc_out(HBIT) <= (left(3) and right(3)) or
1344
                     (right(3) and not out_alu(3)) or
1345
                      (left(3) and not out_alu(3));
1346
         when alu_andcc =>
1347
      cc_out(HBIT) <= left(HBIT) and cc(HBIT);
1348
         when alu_orcc =>
1349
      cc_out(HBIT) <= left(HBIT) or cc(HBIT);
1350
         when alu_tfr =>
1351
      cc_out(HBIT) <= left(HBIT);
1352
         when others =>
1353
                cc_out(HBIT) <= cc(HBIT);
1354
    end case;
1355
 
1356
    --
1357
    -- Overflow flag
1358
         --
1359
    case alu_ctrl is
1360
         when alu_add8 | alu_adc =>
1361
      cc_out(VBIT) <= (left(7)  and      right(7)  and (not out_alu(7))) or
1362
                 ((not left(7)) and (not right(7)) and      out_alu(7));
1363
         when alu_sub8 | alu_sbc =>
1364
      cc_out(VBIT) <= (left(7)  and (not right(7)) and (not out_alu(7))) or
1365
                 ((not left(7)) and      right(7)  and      out_alu(7));
1366
         when alu_add16 =>
1367
      cc_out(VBIT) <= (left(15)  and      right(15)  and (not out_alu(15))) or
1368
                 ((not left(15)) and (not right(15)) and      out_alu(15));
1369
         when alu_sub16 =>
1370
      cc_out(VBIT) <= (left(15)  and (not right(15)) and (not out_alu(15))) or
1371
                 ((not left(15)) and      right(15) and       out_alu(15));
1372
         when alu_inc =>
1373
           cc_out(VBIT) <= ((not left(7)) and left(6) and left(5) and left(4) and
1374
                                      left(3)  and left(2) and left(1) and left(0));
1375
         when alu_dec | alu_neg =>
1376
           cc_out(VBIT) <= (left(7)  and (not left(6)) and (not left(5)) and (not left(4)) and
1377
                            (not left(3)) and (not left(2)) and (not left(1)) and (not left(0)));
1378
-- 6809 Programming reference manual says
1379
-- V not affected by ASR, LSR and ROR
1380
-- This is different to the 6800
1381
-- John Kent 6th June 2006
1382
--       when alu_asr8 =>
1383
--         cc_out(VBIT) <= left(0) xor left(7);
1384
--       when alu_lsr8 | alu_lsr16 =>
1385
--         cc_out(VBIT) <= left(0);
1386
--       when alu_ror8 =>
1387
--      cc_out(VBIT) <= left(0) xor cc(CBIT);
1388
    when alu_lsl16 =>
1389
      cc_out(VBIT) <= left(15) xor left(14);
1390
         when alu_rol8 | alu_asl8 =>
1391
      cc_out(VBIT) <= left(7) xor left(6);
1392
--
1393
-- 11th July 2006 - John Kent
1394
-- What DAA does with V is anyones guess
1395
-- It is undefined in the 6809 programming manual
1396
--
1397
         when alu_daa =>
1398
      cc_out(VBIT) <= left(7) xor out_alu(7) xor cc(CBIT);
1399
-- CLR resets V Bit
1400
-- John Kent 6th June 2006
1401
         when alu_and | alu_ora | alu_eor | alu_com | alu_clr |
1402
              alu_st8 | alu_st16 | alu_ld8 | alu_ld16 | alu_sex =>
1403
      cc_out(VBIT) <= '0';
1404
         when alu_andcc =>
1405
      cc_out(VBIT) <= left(VBIT) and cc(VBIT);
1406
         when alu_orcc =>
1407
      cc_out(VBIT) <= left(VBIT) or cc(VBIT);
1408
         when alu_tfr =>
1409
      cc_out(VBIT) <= left(VBIT);
1410
         when others =>
1411
                cc_out(VBIT) <= cc(VBIT);
1412
    end case;
1413
 
1414
         case alu_ctrl is
1415
         when alu_andcc =>
1416
      cc_out(FBIT) <= left(FBIT) and cc(FBIT);
1417
         when alu_orcc =>
1418
      cc_out(FBIT) <= left(FBIT) or cc(FBIT);
1419
         when alu_tfr =>
1420
      cc_out(FBIT) <= left(FBIT);
1421
    when alu_seif =>
1422
           cc_out(FBIT) <= '1';
1423
         when others =>
1424
      cc_out(FBIT) <= cc(FBIT);
1425
         end case;
1426
 
1427
         case alu_ctrl is
1428
         when alu_andcc =>
1429
      cc_out(EBIT) <= left(EBIT) and cc(EBIT);
1430
         when alu_orcc =>
1431
      cc_out(EBIT) <= left(EBIT) or cc(EBIT);
1432
         when alu_tfr =>
1433
      cc_out(EBIT) <= left(EBIT);
1434
    when alu_see =>
1435
           cc_out(EBIT) <= '1';
1436
    when alu_cle =>
1437
           cc_out(EBIT) <= '0';
1438
         when others =>
1439
           cc_out(EBIT) <= cc(EBIT);
1440
         end case;
1441
end process;
1442
 
1443
------------------------------------
1444
--
1445
-- state sequencer
1446
--
1447
------------------------------------
1448
process( state, saved_state,
1449
         op_code, pre_code,
1450
                        cc, ea, md, iv,
1451
                        irq, firq, nmi_req, nmi_ack, halt )
1452
variable cond_true : boolean;  -- variable used to evaluate coditional branches
1453
begin
1454
                  case state is
1455
          when reset_state =>        --  released from reset
1456
                            -- reset the registers
1457
             op_ctrl    <= reset_op;
1458
             pre_ctrl   <= reset_pre;
1459
                                 acca_ctrl  <= reset_acca;
1460
                                 accb_ctrl  <= reset_accb;
1461
                                 ix_ctrl    <= reset_ix;
1462
                                 iy_ctrl    <= reset_iy;
1463
                       sp_ctrl    <= reset_sp;
1464
                       up_ctrl    <= reset_up;
1465
                       pc_ctrl    <= reset_pc;
1466
                            ea_ctrl    <= reset_ea;
1467
                                 md_ctrl    <= reset_md;
1468
                                 iv_ctrl    <= reset_iv;
1469
                                 nmi_ctrl   <= reset_nmi;
1470
                                 -- idle the ALU
1471
             left_ctrl  <= pc_left;
1472
                                 right_ctrl <= zero_right;
1473
                                 alu_ctrl   <= alu_nop;
1474
             cc_ctrl    <= reset_cc;
1475
             dp_ctrl    <= reset_dp;
1476
                                 -- idle the bus
1477
                                 dout_ctrl  <= md_lo_dout;
1478
             addr_ctrl  <= idle_ad;
1479
                                 st_ctrl    <= idle_st;
1480
                                 return_state <= vect_hi_state;
1481
                       next_state <= vect_hi_state;
1482
 
1483
                         --
1484
                         -- Jump via interrupt vector
1485
                         -- iv holds interrupt type
1486
                         -- fetch PC hi from vector location
1487
                         --
1488
          when vect_hi_state =>
1489
                            -- default the registers
1490
             op_ctrl    <= latch_op;
1491
             pre_ctrl   <= latch_pre;
1492
                                 nmi_ctrl   <= latch_nmi;
1493
             acca_ctrl  <= latch_acca;
1494
             accb_ctrl  <= latch_accb;
1495
             ix_ctrl    <= latch_ix;
1496
             iy_ctrl    <= latch_iy;
1497
             sp_ctrl    <= latch_sp;
1498
             up_ctrl    <= latch_up;
1499
             md_ctrl    <= latch_md;
1500
             ea_ctrl    <= latch_ea;
1501
             iv_ctrl    <= latch_iv;
1502
                                 -- idle the ALU
1503
             left_ctrl  <= pc_left;
1504
             right_ctrl <= zero_right;
1505
             alu_ctrl   <= alu_nop;
1506
             cc_ctrl    <= latch_cc;
1507
             dp_ctrl    <= latch_dp;
1508
                                 -- fetch pc low interrupt vector
1509
                       pc_ctrl    <= pull_hi_pc;
1510
             addr_ctrl  <= int_hi_ad;
1511
             dout_ctrl  <= pc_hi_dout;
1512
                                 st_ctrl    <= idle_st;
1513
                                 return_state <= vect_lo_state;
1514
                       next_state <= vect_lo_state;
1515
                         --
1516
                         -- jump via interrupt vector
1517
                         -- iv holds vector type
1518
                         -- fetch PC lo from vector location
1519
                         --
1520
          when vect_lo_state =>
1521
                            -- default the registers
1522
             op_ctrl    <= latch_op;
1523
             pre_ctrl   <= latch_pre;
1524
                                 nmi_ctrl   <= latch_nmi;
1525
             acca_ctrl  <= latch_acca;
1526
             accb_ctrl  <= latch_accb;
1527
             ix_ctrl    <= latch_ix;
1528
             iy_ctrl    <= latch_iy;
1529
             sp_ctrl    <= latch_sp;
1530
             up_ctrl    <= latch_up;
1531
             md_ctrl    <= latch_md;
1532
             ea_ctrl    <= latch_ea;
1533
             iv_ctrl    <= latch_iv;
1534
                                 -- idle the ALU
1535
             left_ctrl  <= pc_left;
1536
             right_ctrl <= zero_right;
1537
             alu_ctrl   <= alu_nop;
1538
             cc_ctrl    <= latch_cc;
1539
             dp_ctrl    <= latch_dp;
1540
                                 -- fetch the vector low byte
1541
                       pc_ctrl    <= pull_lo_pc;
1542
             addr_ctrl  <= int_lo_ad;
1543
             dout_ctrl  <= pc_lo_dout;
1544
                                 st_ctrl    <= idle_st;
1545
                                 return_state <= fetch_state;
1546
                                 --
1547
                                 -- Patch to nobble FIRQ
1548
                                 -- Should cause a RTI on an FIRQ
1549
                                 --
1550
                                 if iv = FIRQ_VEC then
1551
                                   next_state <= rti_cc_state;
1552
                                 else
1553
                         next_state <= fetch_state;
1554
             end if;
1555
                         --
1556
                         -- Here to fetch an instruction
1557
                         -- PC points to opcode
1558
                         -- Should service interrupt requests at this point
1559
                         -- either from the timer
1560
                         -- or from the external input.
1561
                         --
1562
          when fetch_state =>
1563
                                   -- fetch the op code
1564
                              op_ctrl    <= fetch_op;
1565
               pre_ctrl   <= fetch_pre;
1566
               ea_ctrl    <= reset_ea;
1567
               md_ctrl    <= latch_md;
1568
                                   -- Fetch op code
1569
               addr_ctrl  <= fetch_ad;
1570
               dout_ctrl  <= md_lo_dout;
1571
               dp_ctrl    <= latch_dp;
1572
                                   --
1573
                                        case op_code(7 downto 6) is
1574
                                        when "10" => -- acca
1575
                                     case op_code(3 downto 0) is
1576
                                          when "0000" => -- suba
1577
                                            left_ctrl  <= acca_left;
1578
                                            right_ctrl <= md_right;
1579
                                            alu_ctrl   <= alu_sub8;
1580
                                                 cc_ctrl    <= load_cc;
1581
                                            acca_ctrl  <= load_acca;
1582
                   accb_ctrl  <= latch_accb;
1583
                   ix_ctrl    <= latch_ix;
1584
                   iy_ctrl    <= latch_iy;
1585
                   up_ctrl    <= latch_up;
1586
                   sp_ctrl    <= latch_sp;
1587
                                          when "0001" => -- cmpa
1588
                                            left_ctrl   <= acca_left;
1589
                                            right_ctrl  <= md_right;
1590
                                            alu_ctrl    <= alu_sub8;
1591
                                                 cc_ctrl     <= load_cc;
1592
                                            acca_ctrl   <= latch_acca;
1593
                   accb_ctrl   <= latch_accb;
1594
                   ix_ctrl     <= latch_ix;
1595
                   iy_ctrl     <= latch_iy;
1596
                   up_ctrl     <= latch_up;
1597
                   sp_ctrl     <= latch_sp;
1598
                                          when "0010" => -- sbca
1599
                                            left_ctrl   <= acca_left;
1600
                                            right_ctrl  <= md_right;
1601
                                            alu_ctrl    <= alu_sbc;
1602
                                                 cc_ctrl     <= load_cc;
1603
                                            acca_ctrl   <= load_acca;
1604
                   accb_ctrl   <= latch_accb;
1605
                   ix_ctrl     <= latch_ix;
1606
                   iy_ctrl     <= latch_iy;
1607
                   up_ctrl     <= latch_up;
1608
                   sp_ctrl     <= latch_sp;
1609
                                          when "0011" =>
1610
                                            case pre_code is
1611
                                                 when "00010000" => -- page 2 -- cmpd
1612
                                              left_ctrl   <= accd_left;
1613
                                              right_ctrl  <= md_right;
1614
                                              alu_ctrl    <= alu_sub16;
1615
                                                   cc_ctrl     <= load_cc;
1616
                                              acca_ctrl   <= latch_acca;
1617
                     accb_ctrl   <= latch_accb;
1618
                     ix_ctrl     <= latch_ix;
1619
                     iy_ctrl     <= latch_iy;
1620
                     up_ctrl     <= latch_up;
1621
                     sp_ctrl     <= latch_sp;
1622
                                                 when "00010001" => -- page 3 -- cmpu
1623
                                              left_ctrl   <= up_left;
1624
                                              right_ctrl  <= md_right;
1625
                                              alu_ctrl    <= alu_sub16;
1626
                                                   cc_ctrl     <= load_cc;
1627
                                              acca_ctrl   <= latch_acca;
1628
                     accb_ctrl   <= latch_accb;
1629
                     ix_ctrl     <= latch_ix;
1630
                     iy_ctrl     <= latch_iy;
1631
                     up_ctrl     <= latch_up;
1632
                     sp_ctrl     <= latch_sp;
1633
                                                 when others => -- page 1 -- subd
1634
                                              left_ctrl   <= accd_left;
1635
                                              right_ctrl  <= md_right;
1636
                                              alu_ctrl    <= alu_sub16;
1637
                                                   cc_ctrl     <= load_cc;
1638
                                              acca_ctrl   <= load_hi_acca;
1639
                                                   accb_ctrl   <= load_accb;
1640
                     ix_ctrl     <= latch_ix;
1641
                     iy_ctrl     <= latch_iy;
1642
                     up_ctrl     <= latch_up;
1643
                     sp_ctrl     <= latch_sp;
1644
                                                 end case;
1645
                                          when "0100" => -- anda
1646
                                            left_ctrl   <= acca_left;
1647
                                            right_ctrl  <= md_right;
1648
                                            alu_ctrl    <= alu_and;
1649
                                                 cc_ctrl     <= load_cc;
1650
                                            acca_ctrl   <= load_acca;
1651
                   accb_ctrl   <= latch_accb;
1652
                   ix_ctrl     <= latch_ix;
1653
                   iy_ctrl     <= latch_iy;
1654
                   up_ctrl     <= latch_up;
1655
                   sp_ctrl     <= latch_sp;
1656
                                          when "0101" => -- bita
1657
                                            left_ctrl   <= acca_left;
1658
                                            right_ctrl  <= md_right;
1659
                                            alu_ctrl    <= alu_and;
1660
                                                 cc_ctrl     <= load_cc;
1661
                                            acca_ctrl   <= latch_acca;
1662
                   accb_ctrl   <= latch_accb;
1663
                   ix_ctrl     <= latch_ix;
1664
                   iy_ctrl     <= latch_iy;
1665
                   up_ctrl     <= latch_up;
1666
                   sp_ctrl     <= latch_sp;
1667
                                          when "0110" => -- ldaa
1668
                                            left_ctrl   <= acca_left;
1669
                                            right_ctrl  <= md_right;
1670
                                            alu_ctrl    <= alu_ld8;
1671
                                                 cc_ctrl     <= load_cc;
1672
                                            acca_ctrl   <= load_acca;
1673
                   accb_ctrl   <= latch_accb;
1674
                   ix_ctrl     <= latch_ix;
1675
                   iy_ctrl     <= latch_iy;
1676
                   up_ctrl     <= latch_up;
1677
                   sp_ctrl     <= latch_sp;
1678
                                          when "0111" => -- staa
1679
                                            left_ctrl   <= acca_left;
1680
                                            right_ctrl  <= md_right;
1681
                                            alu_ctrl    <= alu_st8;
1682
                                                 cc_ctrl     <= load_cc;
1683
                                            acca_ctrl   <= latch_acca;
1684
                   accb_ctrl   <= latch_accb;
1685
                   ix_ctrl     <= latch_ix;
1686
                   iy_ctrl     <= latch_iy;
1687
                   up_ctrl     <= latch_up;
1688
                   sp_ctrl     <= latch_sp;
1689
                                          when "1000" => -- eora
1690
                                            left_ctrl   <= acca_left;
1691
                                            right_ctrl  <= md_right;
1692
                                            alu_ctrl    <= alu_eor;
1693
                                                 cc_ctrl     <= load_cc;
1694
                                            acca_ctrl   <= load_acca;
1695
                   accb_ctrl   <= latch_accb;
1696
                   ix_ctrl     <= latch_ix;
1697
                   iy_ctrl     <= latch_iy;
1698
                   up_ctrl     <= latch_up;
1699
                   sp_ctrl     <= latch_sp;
1700
                                          when "1001" => -- adca
1701
                                            left_ctrl   <= acca_left;
1702
                                            right_ctrl  <= md_right;
1703
                                            alu_ctrl    <= alu_adc;
1704
                                                 cc_ctrl     <= load_cc;
1705
                                            acca_ctrl   <= load_acca;
1706
                   accb_ctrl   <= latch_accb;
1707
                   ix_ctrl     <= latch_ix;
1708
                   iy_ctrl     <= latch_iy;
1709
                   up_ctrl     <= latch_up;
1710
                   sp_ctrl     <= latch_sp;
1711
                                          when "1010" => -- oraa
1712
                                            left_ctrl   <= acca_left;
1713
                                            right_ctrl  <= md_right;
1714
                                            alu_ctrl    <= alu_ora;
1715
                                                 cc_ctrl     <= load_cc;
1716
                                            acca_ctrl   <= load_acca;
1717
                   accb_ctrl   <= latch_accb;
1718
                   ix_ctrl     <= latch_ix;
1719
                   iy_ctrl     <= latch_iy;
1720
                   up_ctrl     <= latch_up;
1721
                   sp_ctrl     <= latch_sp;
1722
                                          when "1011" => -- adda
1723
                                            left_ctrl   <= acca_left;
1724
                                            right_ctrl  <= md_right;
1725
                                            alu_ctrl    <= alu_add8;
1726
                                                 cc_ctrl     <= load_cc;
1727
                                            acca_ctrl   <= load_acca;
1728
                   accb_ctrl   <= latch_accb;
1729
                   ix_ctrl     <= latch_ix;
1730
                   iy_ctrl     <= latch_iy;
1731
                   up_ctrl     <= latch_up;
1732
                   sp_ctrl     <= latch_sp;
1733
                                          when "1100" =>
1734
                                            case pre_code is
1735
                                                 when "00010000" => -- page 2 -- cmpy
1736
                                              left_ctrl   <= iy_left;
1737
                                              right_ctrl  <= md_right;
1738
                                              alu_ctrl    <= alu_sub16;
1739
                                                   cc_ctrl     <= load_cc;
1740
                                              acca_ctrl   <= latch_acca;
1741
                     accb_ctrl   <= latch_accb;
1742
                     ix_ctrl     <= latch_ix;
1743
                     iy_ctrl     <= latch_iy;
1744
                     up_ctrl     <= latch_up;
1745
                     sp_ctrl     <= latch_sp;
1746
                                                 when "00010001" => -- page 3 -- cmps
1747
                                              left_ctrl   <= sp_left;
1748
                                              right_ctrl  <= md_right;
1749
                                              alu_ctrl    <= alu_sub16;
1750
                                                   cc_ctrl     <= load_cc;
1751
                                              acca_ctrl   <= latch_acca;
1752
                     accb_ctrl   <= latch_accb;
1753
                     ix_ctrl     <= latch_ix;
1754
                     iy_ctrl     <= latch_iy;
1755
                     up_ctrl     <= latch_up;
1756
                     sp_ctrl     <= latch_sp;
1757
                                                 when others => -- page 1 -- cmpx
1758
                                              left_ctrl   <= ix_left;
1759
                                              right_ctrl  <= md_right;
1760
                                              alu_ctrl    <= alu_sub16;
1761
                                                   cc_ctrl     <= load_cc;
1762
                                              acca_ctrl   <= latch_acca;
1763
                                                   accb_ctrl   <= latch_accb;
1764
                     ix_ctrl     <= latch_ix;
1765
                     iy_ctrl     <= latch_iy;
1766
                     up_ctrl     <= latch_up;
1767
                     sp_ctrl     <= latch_sp;
1768
                                                 end case;
1769
                                          when "1101" => -- bsr / jsr
1770
                                            left_ctrl   <= pc_left;
1771
                                            right_ctrl  <= md_right;
1772
                                            alu_ctrl    <= alu_nop;
1773
                                                 cc_ctrl     <= latch_cc;
1774
                                            acca_ctrl   <= latch_acca;
1775
                   accb_ctrl   <= latch_accb;
1776
                   ix_ctrl     <= latch_ix;
1777
                   iy_ctrl     <= latch_iy;
1778
                   up_ctrl     <= latch_up;
1779
                   sp_ctrl     <= latch_sp;
1780
                                          when "1110" => -- ldx
1781
                                            case pre_code is
1782
                                                 when "00010000" => -- page 2 -- ldy
1783
                                              left_ctrl   <= iy_left;
1784
                                              right_ctrl  <= md_right;
1785
                                              alu_ctrl    <= alu_ld16;
1786
                                                   cc_ctrl     <= load_cc;
1787
                                              acca_ctrl   <= latch_acca;
1788
                     accb_ctrl   <= latch_accb;
1789
                     ix_ctrl     <= latch_ix;
1790
                     iy_ctrl     <= load_iy;
1791
                     up_ctrl     <= latch_up;
1792
                                                   sp_ctrl     <= latch_sp;
1793
                                                 when others =>   -- page 1 -- ldx
1794
                                              left_ctrl   <= ix_left;
1795
                                              right_ctrl  <= md_right;
1796
                                              alu_ctrl    <= alu_ld16;
1797
                                                   cc_ctrl     <= load_cc;
1798
                                              acca_ctrl   <= latch_acca;
1799
                     accb_ctrl   <= latch_accb;
1800
                     ix_ctrl     <= load_ix;
1801
                     iy_ctrl     <= latch_iy;
1802
                     up_ctrl     <= latch_up;
1803
                                                   sp_ctrl     <= latch_sp;
1804
                                                 end case;
1805
                                          when "1111" => -- stx
1806
                                            case pre_code is
1807
                                                 when "00010000" => -- page 2 -- sty
1808
                                              left_ctrl   <= iy_left;
1809
                                              right_ctrl  <= md_right;
1810
                                              alu_ctrl    <= alu_st16;
1811
                                                   cc_ctrl     <= load_cc;
1812
                                              acca_ctrl   <= latch_acca;
1813
                     accb_ctrl   <= latch_accb;
1814
                     ix_ctrl     <= latch_ix;
1815
                     iy_ctrl     <= latch_iy;
1816
                     up_ctrl     <= latch_up;
1817
                     sp_ctrl     <= latch_sp;
1818
                                                 when others =>     -- page 1 -- stx
1819
                                              left_ctrl   <= ix_left;
1820
                                              right_ctrl  <= md_right;
1821
                                              alu_ctrl    <= alu_st16;
1822
                                                   cc_ctrl     <= load_cc;
1823
                                              acca_ctrl   <= latch_acca;
1824
                     accb_ctrl   <= latch_accb;
1825
                     ix_ctrl     <= latch_ix;
1826
                     iy_ctrl     <= latch_iy;
1827
                     up_ctrl     <= latch_up;
1828
                     sp_ctrl     <= latch_sp;
1829
                                                 end case;
1830
                                          when others =>
1831
                                            null;
1832
--                                          left_ctrl   <= acca_left;
1833
--                                          right_ctrl  <= md_right;
1834
--                                          alu_ctrl    <= alu_nop;
1835
--                                               cc_ctrl     <= latch_cc;
1836
--                                          acca_ctrl   <= latch_acca;
1837
--                   accb_ctrl   <= latch_accb;
1838
--                   ix_ctrl     <= latch_ix;
1839
--                   iy_ctrl     <= latch_iy;
1840
--                   up_ctrl     <= latch_up;
1841
--                   sp_ctrl     <= latch_sp;
1842
                                          end case;
1843
                                        when "11" => -- accb dual op
1844
                                     case op_code(3 downto 0) is
1845
                                          when "0000" => -- subb
1846
                                            left_ctrl   <= accb_left;
1847
                                            right_ctrl  <= md_right;
1848
                                            alu_ctrl    <= alu_sub8;
1849
                                                 cc_ctrl     <= load_cc;
1850
                                            acca_ctrl   <= latch_acca;
1851
                   accb_ctrl   <= load_accb;
1852
                   ix_ctrl     <= latch_ix;
1853
                   iy_ctrl     <= latch_iy;
1854
                   up_ctrl     <= latch_up;
1855
                   sp_ctrl     <= latch_sp;
1856
                                          when "0001" => -- cmpb
1857
                                            left_ctrl   <= accb_left;
1858
                                            right_ctrl  <= md_right;
1859
                                            alu_ctrl    <= alu_sub8;
1860
                                                 cc_ctrl     <= load_cc;
1861
                                            acca_ctrl   <= latch_acca;
1862
                   accb_ctrl   <= latch_accb;
1863
                   ix_ctrl     <= latch_ix;
1864
                   iy_ctrl     <= latch_iy;
1865
                   up_ctrl     <= latch_up;
1866
                   sp_ctrl     <= latch_sp;
1867
                                          when "0010" => -- sbcb
1868
                                            left_ctrl   <= accb_left;
1869
                                            right_ctrl  <= md_right;
1870
                                            alu_ctrl    <= alu_sbc;
1871
                                                 cc_ctrl     <= load_cc;
1872
                                            acca_ctrl   <= latch_acca;
1873
                   accb_ctrl   <= load_accb;
1874
                   ix_ctrl     <= latch_ix;
1875
                   iy_ctrl     <= latch_iy;
1876
                   up_ctrl     <= latch_up;
1877
                   sp_ctrl     <= latch_sp;
1878
                                          when "0011" => -- addd
1879
                                            left_ctrl   <= accd_left;
1880
                                            right_ctrl  <= md_right;
1881
                                            alu_ctrl    <= alu_add16;
1882
                                                 cc_ctrl     <= load_cc;
1883
                                            acca_ctrl   <= load_hi_acca;
1884
                                                 accb_ctrl   <= load_accb;
1885
                   ix_ctrl     <= latch_ix;
1886
                   iy_ctrl     <= latch_iy;
1887
                   up_ctrl     <= latch_up;
1888
                   sp_ctrl     <= latch_sp;
1889
                                          when "0100" => -- andb
1890
                                            left_ctrl   <= accb_left;
1891
                                            right_ctrl  <= md_right;
1892
                                            alu_ctrl    <= alu_and;
1893
                                                 cc_ctrl     <= load_cc;
1894
                                            acca_ctrl   <= latch_acca;
1895
                   accb_ctrl   <= load_accb;
1896
                   ix_ctrl     <= latch_ix;
1897
                   iy_ctrl     <= latch_iy;
1898
                   up_ctrl     <= latch_up;
1899
                   sp_ctrl     <= latch_sp;
1900
                                          when "0101" => -- bitb
1901
                                            left_ctrl   <= accb_left;
1902
                                            right_ctrl  <= md_right;
1903
                                            alu_ctrl    <= alu_and;
1904
                                                 cc_ctrl     <= load_cc;
1905
                                            acca_ctrl   <= latch_acca;
1906
                   accb_ctrl   <= latch_accb;
1907
                   ix_ctrl     <= latch_ix;
1908
                   iy_ctrl     <= latch_iy;
1909
                   up_ctrl     <= latch_up;
1910
                   sp_ctrl     <= latch_sp;
1911
                                          when "0110" => -- ldab
1912
                                            left_ctrl   <= accb_left;
1913
                                            right_ctrl  <= md_right;
1914
                                            alu_ctrl    <= alu_ld8;
1915
                                                 cc_ctrl     <= load_cc;
1916
                                            acca_ctrl   <= latch_acca;
1917
                   accb_ctrl   <= load_accb;
1918
                   ix_ctrl     <= latch_ix;
1919
                   iy_ctrl     <= latch_iy;
1920
                   up_ctrl     <= latch_up;
1921
                   sp_ctrl     <= latch_sp;
1922
                                          when "0111" => -- stab
1923
                                            left_ctrl   <= accb_left;
1924
                                            right_ctrl  <= md_right;
1925
                                            alu_ctrl    <= alu_st8;
1926
                                                 cc_ctrl     <= load_cc;
1927
                                            acca_ctrl   <= latch_acca;
1928
                   accb_ctrl   <= latch_accb;
1929
                   ix_ctrl     <= latch_ix;
1930
                   iy_ctrl     <= latch_iy;
1931
                   up_ctrl     <= latch_up;
1932
                   sp_ctrl     <= latch_sp;
1933
                                          when "1000" => -- eorb
1934
                                            left_ctrl   <= accb_left;
1935
                                            right_ctrl  <= md_right;
1936
                                            alu_ctrl    <= alu_eor;
1937
                                                 cc_ctrl     <= load_cc;
1938
                                            acca_ctrl   <= latch_acca;
1939
                   accb_ctrl   <= load_accb;
1940
                   ix_ctrl     <= latch_ix;
1941
                   iy_ctrl     <= latch_iy;
1942
                   up_ctrl     <= latch_up;
1943
                   sp_ctrl     <= latch_sp;
1944
                                          when "1001" => -- adcb
1945
                                            left_ctrl   <= accb_left;
1946
                                            right_ctrl  <= md_right;
1947
                                            alu_ctrl    <= alu_adc;
1948
                                                 cc_ctrl     <= load_cc;
1949
                                            acca_ctrl   <= latch_acca;
1950
                   accb_ctrl   <= load_accb;
1951
                   ix_ctrl     <= latch_ix;
1952
                   iy_ctrl     <= latch_iy;
1953
                   up_ctrl     <= latch_up;
1954
                   sp_ctrl     <= latch_sp;
1955
                                          when "1010" => -- orab
1956
                                            left_ctrl   <= accb_left;
1957
                                            right_ctrl  <= md_right;
1958
                                            alu_ctrl    <= alu_ora;
1959
                                                 cc_ctrl     <= load_cc;
1960
                                            acca_ctrl   <= latch_acca;
1961
                   accb_ctrl   <= load_accb;
1962
                   ix_ctrl     <= latch_ix;
1963
                   iy_ctrl     <= latch_iy;
1964
                   up_ctrl     <= latch_up;
1965
                   sp_ctrl     <= latch_sp;
1966
                                          when "1011" => -- addb
1967
                                            left_ctrl   <= accb_left;
1968
                                            right_ctrl  <= md_right;
1969
                                            alu_ctrl    <= alu_add8;
1970
                                                 cc_ctrl     <= load_cc;
1971
                                            acca_ctrl   <= latch_acca;
1972
                   accb_ctrl   <= load_accb;
1973
                   ix_ctrl     <= latch_ix;
1974
                   iy_ctrl     <= latch_iy;
1975
                   up_ctrl     <= latch_up;
1976
                   sp_ctrl     <= latch_sp;
1977
                                          when "1100" => -- ldd
1978
                                            left_ctrl   <= accd_left;
1979
                                            right_ctrl  <= md_right;
1980
                                            alu_ctrl    <= alu_ld16;
1981
                                                 cc_ctrl     <= load_cc;
1982
                                            acca_ctrl   <= load_hi_acca;
1983
                   accb_ctrl   <= load_accb;
1984
                   ix_ctrl     <= latch_ix;
1985
                   iy_ctrl     <= latch_iy;
1986
                   up_ctrl     <= latch_up;
1987
                   sp_ctrl     <= latch_sp;
1988
                                          when "1101" => -- std
1989
                                            left_ctrl   <= accd_left;
1990
                                            right_ctrl  <= md_right;
1991
                                            alu_ctrl    <= alu_st16;
1992
                                                 cc_ctrl     <= load_cc;
1993
                                            acca_ctrl   <= latch_acca;
1994
                   accb_ctrl   <= latch_accb;
1995
                   ix_ctrl     <= latch_ix;
1996
                   iy_ctrl     <= latch_iy;
1997
                   up_ctrl     <= latch_up;
1998
                   sp_ctrl     <= latch_sp;
1999
                                          when "1110" => -- ldu
2000
                                            case pre_code is
2001
                                                 when "00010000" => -- page 2 -- lds
2002
                                              left_ctrl   <= sp_left;
2003
                                              right_ctrl  <= md_right;
2004
                                              alu_ctrl    <= alu_ld16;
2005
                                                   cc_ctrl     <= load_cc;
2006
                                              acca_ctrl   <= latch_acca;
2007
                     accb_ctrl   <= latch_accb;
2008
                     ix_ctrl     <= latch_ix;
2009
                     iy_ctrl     <= latch_iy;
2010
                     up_ctrl     <= latch_up;
2011
                                                   sp_ctrl     <= load_sp;
2012
                                                 when others => -- page 1 -- ldu
2013
                                              left_ctrl   <= up_left;
2014
                                              right_ctrl  <= md_right;
2015
                                              alu_ctrl    <= alu_ld16;
2016
                                                   cc_ctrl     <= load_cc;
2017
                                              acca_ctrl   <= latch_acca;
2018
                     accb_ctrl   <= latch_accb;
2019
                     ix_ctrl     <= latch_ix;
2020
                     iy_ctrl     <= latch_iy;
2021
                     up_ctrl     <= load_up;
2022
                                                   sp_ctrl     <= latch_sp;
2023
                                                 end case;
2024
                                          when "1111" =>
2025
                                            case pre_code is
2026
                                                 when "00010000" => -- page 2 -- sts
2027
                                              left_ctrl   <= sp_left;
2028
                                              right_ctrl  <= md_right;
2029
                                              alu_ctrl    <= alu_st16;
2030
                                                   cc_ctrl     <= load_cc;
2031
                                              acca_ctrl   <= latch_acca;
2032
                     accb_ctrl   <= latch_accb;
2033
                     ix_ctrl     <= latch_ix;
2034
                     iy_ctrl     <= latch_iy;
2035
                     up_ctrl     <= latch_up;
2036
                     sp_ctrl     <= latch_sp;
2037
                                                 when others =>     -- page 1 -- stu
2038
                                              left_ctrl   <= up_left;
2039
                                              right_ctrl  <= md_right;
2040
                                              alu_ctrl    <= alu_st16;
2041
                                                   cc_ctrl     <= load_cc;
2042
                                              acca_ctrl   <= latch_acca;
2043
                     accb_ctrl   <= latch_accb;
2044
                     ix_ctrl     <= latch_ix;
2045
                     iy_ctrl     <= latch_iy;
2046
                     up_ctrl     <= latch_up;
2047
                     sp_ctrl     <= latch_sp;
2048
                                                 end case;
2049
                                          when others =>
2050
                                            null;
2051
--                                          left_ctrl   <= accb_left;
2052
--                                          right_ctrl  <= md_right;
2053
--                                          alu_ctrl    <= alu_nop;
2054
--                                               cc_ctrl     <= latch_cc;
2055
--                                          acca_ctrl   <= latch_acca;
2056
--                   accb_ctrl   <= latch_accb;
2057
--                   ix_ctrl     <= latch_ix;
2058
--                   iy_ctrl     <= latch_iy;
2059
--                   up_ctrl     <= latch_up;
2060
--                   sp_ctrl     <= latch_sp;
2061
                                          end case;
2062
                                        when others =>
2063
                                            left_ctrl   <= acca_left;
2064
                                            right_ctrl  <= md_right;
2065
                                            alu_ctrl    <= alu_nop;
2066
                                                 cc_ctrl     <= latch_cc;
2067
                                            acca_ctrl   <= latch_acca;
2068
                   accb_ctrl   <= latch_accb;
2069
                   ix_ctrl     <= latch_ix;
2070
                   iy_ctrl     <= latch_iy;
2071
                   up_ctrl     <= latch_up;
2072
                   sp_ctrl     <= latch_sp;
2073
                                        end case;
2074
                                 if halt = '1' then
2075
                              iv_ctrl    <= reset_iv;
2076
               pc_ctrl    <= latch_pc;
2077
                                   nmi_ctrl   <= latch_nmi;
2078
                                   st_ctrl    <= push_st;
2079
                                   return_state <= fetch_state;
2080
                              next_state <= halt_state;
2081
                                 -- service non maskable interrupts
2082
                            elsif (nmi_req = '1') and (nmi_ack = '0') then
2083
                              iv_ctrl    <= nmi_iv;
2084
               pc_ctrl    <= latch_pc;
2085
                                   nmi_ctrl   <= set_nmi;
2086
                                   st_ctrl    <= idle_st;
2087
                                   return_state <= fetch_state;
2088
                              next_state <= int_decr_state;
2089
                                 -- service maskable interrupts
2090
                            else
2091
                                   --
2092
                                        -- nmi request is not cleared until nmi input goes low
2093
                                        --
2094
                                   if(nmi_req = '0') and (nmi_ack='1') then
2095
                                     nmi_ctrl <= reset_nmi;
2096
                                        else
2097
                                          nmi_ctrl <= latch_nmi;
2098
                                        end if;
2099
                                        --
2100
                                        -- FIRQ & IRQ are level sensitive
2101
                                        --
2102
               if (firq = '1') and (cc(FBIT) = '0') then
2103
                                iv_ctrl    <= firq_iv;
2104
                 pc_ctrl    <= latch_pc;
2105
                                     st_ctrl    <= idle_st;
2106
                                     return_state <= fetch_state;
2107
                                next_state <= int_decr_state;
2108
                                   elsif (irq = '1') and (cc(IBIT) = '0') then
2109
                                iv_ctrl    <= irq_iv;
2110
                 pc_ctrl    <= latch_pc;
2111
                                     st_ctrl    <= idle_st;
2112
                                     return_state <= fetch_state;
2113
                                next_state <= int_decr_state;
2114
               else
2115
                                   -- Advance the PC to fetch next instruction byte
2116
                                iv_ctrl    <= reset_iv; -- default to reset
2117
                 pc_ctrl    <= incr_pc;
2118
                                     st_ctrl    <= idle_st;
2119
                                     return_state <= fetch_state;
2120
                                next_state <= decode1_state;
2121
               end if;
2122
                                 end if;
2123
                         --
2124
                         -- Here to decode instruction
2125
                         -- and fetch next byte of intruction
2126
                         -- whether it be necessary or not
2127
                         --
2128
          when decode1_state =>
2129
             pre_ctrl   <= latch_pre;
2130
                                 -- fetch first byte of address or immediate data
2131
             ea_ctrl    <= fetch_first_ea;
2132
                                 md_ctrl    <= fetch_first_md;
2133
             addr_ctrl  <= fetch_ad;
2134
             dout_ctrl  <= md_lo_dout;
2135
                                 nmi_ctrl   <= latch_nmi;
2136
             dp_ctrl    <= latch_dp;
2137
                            case op_code(7 downto 4) is
2138
                                 --
2139
                                 -- direct single op (2 bytes)
2140
                                 -- 6809 => 6 cycles
2141
                                 -- cpu09 => 5 cycles
2142
                            -- 1 op=(pc) / pc=pc+1
2143
                                 -- 2 ea_hi=dp / ea_lo=(pc) / pc=pc+1
2144
                                 -- 3 md_lo=(ea) / pc=pc
2145
                                 -- 4 alu_left=md / md=alu_out / pc=pc
2146
                                 -- 5 (ea)=md_lo / pc=pc
2147
                                 --
2148
                                 -- Exception is JMP
2149
                            -- 6809 => 3 cycles
2150
                                 -- cpu09 => 3 cycles
2151
                                 -- 1 op=(pc) / pc=pc+1
2152
                                 -- 2 ea_hi=dp / ea_lo=(pc) / pc=pc+1
2153
                                 -- 3 pc=ea
2154
                                 --
2155
                  when "0000" =>
2156
                              op_ctrl    <= latch_op;
2157
               acca_ctrl  <= latch_acca;
2158
                                        accb_ctrl  <= latch_accb;
2159
                                   ix_ctrl    <= latch_ix;
2160
                                   iy_ctrl    <= latch_iy;
2161
                                   sp_ctrl    <= latch_sp;
2162
                                   up_ctrl    <= latch_up;
2163
               iv_ctrl    <= latch_iv;
2164
                                        -- idle ALU
2165
               left_ctrl  <= pc_left;
2166
               right_ctrl <= one_right;
2167
               alu_ctrl   <= alu_add16;
2168
                                        cc_ctrl    <= latch_cc;
2169
                                        -- advance the PC
2170
               pc_ctrl    <= incr_pc;
2171
                                        --
2172
                                   st_ctrl      <= idle_st;
2173
                                   return_state <= fetch_state;
2174
                                        case op_code(3 downto 0) is
2175
                                   when "1110" => -- jmp
2176
                                     next_state <= jmp_state;
2177
                                        when "1111" => -- clr
2178
                                     next_state <= single_op_exec_state;
2179
                                        when others =>
2180
                                     next_state <= single_op_read_state;
2181
                                        end case;
2182
 
2183
                                 -- acca / accb inherent instructions
2184
                  when "0001" =>
2185
               accb_ctrl  <= latch_accb;
2186
               ix_ctrl    <= latch_ix;
2187
               iy_ctrl    <= latch_iy;
2188
               up_ctrl    <= latch_up;
2189
               iv_ctrl    <= latch_iv;
2190
                    case op_code(3 downto 0) is
2191
                                        --
2192
                                        -- Page2 pre byte
2193
                                        -- pre=(pc) / pc=pc+1
2194
                                        -- op=(pc) / pc=pc+1
2195
                                        --
2196
                         when "0000" => -- page2
2197
                                op_ctrl    <= fetch_op;
2198
                                          acca_ctrl  <= latch_acca;
2199
                                          --
2200
                                          left_ctrl  <= pc_left;
2201
                      right_ctrl <= zero_right;
2202
                                          alu_ctrl   <= alu_nop;
2203
                 cc_ctrl    <= latch_cc;
2204
                 sp_ctrl    <= latch_sp;
2205
                                          -- advance pc
2206
                 pc_ctrl    <= incr_pc;
2207
                                          --
2208
                                     st_ctrl      <= idle_st;
2209
                                     return_state <= fetch_state;
2210
                                          next_state   <= decode2_state;
2211
 
2212
                                        --
2213
                                        -- Page3 pre byte
2214
                                        -- pre=(pc) / pc=pc+1
2215
                                        -- op=(pc) / pc=pc+1
2216
                                        --
2217
                         when "0001" => -- page3
2218
                                op_ctrl    <= fetch_op;
2219
                                          acca_ctrl  <= latch_acca;
2220
                                          -- idle ALU
2221
                                          left_ctrl  <= pc_left;
2222
                      right_ctrl <= zero_right;
2223
                                          alu_ctrl   <= alu_nop;
2224
                 cc_ctrl    <= latch_cc;
2225
                 sp_ctrl    <= latch_sp;
2226
                                          -- advance pc
2227
                 pc_ctrl    <= incr_pc;
2228
                                          -- Next state
2229
                                     st_ctrl      <= idle_st;
2230
                                     return_state <= fetch_state;
2231
                                          next_state   <= decode3_state;
2232
 
2233
                                        --
2234
                                        -- nop - No operation ( 1 byte )
2235
                                        -- 6809 => 2 cycles
2236
                                        -- cpu09 => 2 cycles
2237
                                        -- 1 op=(pc) / pc=pc+1
2238
                                        -- 2 decode
2239
                                        -- 
2240
                         when "0010" => -- nop
2241
                                op_ctrl    <= latch_op;
2242
                                          acca_ctrl  <= latch_acca;
2243
                                          --
2244
                                          left_ctrl  <= acca_left;
2245
                      right_ctrl <= zero_right;
2246
                                          alu_ctrl   <= alu_nop;
2247
                 cc_ctrl    <= latch_cc;
2248
                 sp_ctrl    <= latch_sp;
2249
                                          --
2250
                 pc_ctrl    <= latch_pc;
2251
                                          --
2252
                                     st_ctrl      <= idle_st;
2253
                                     return_state <= fetch_state;
2254
                                          next_state   <= fetch_state;
2255
 
2256
                                        --
2257
                                        -- sync - halt execution until an interrupt is received
2258
                                        -- interrupt may be NMI, IRQ or FIRQ
2259
                                        -- program execution continues if the 
2260
                                        -- interrupt is asserted for 3 clock cycles
2261
                                        -- note that registers are not pushed onto the stack
2262
                                        -- CPU09 => Interrupts need only be asserted for one clock cycle
2263
                                        --
2264
                         when "0011" => -- sync
2265
                                op_ctrl    <= latch_op;
2266
                                          acca_ctrl  <= latch_acca;
2267
                                          --
2268
                                          left_ctrl  <= acca_left;
2269
                      right_ctrl <= zero_right;
2270
                                          alu_ctrl   <= alu_nop;
2271
                 cc_ctrl    <= latch_cc;
2272
                 sp_ctrl    <= latch_sp;
2273
                                          --
2274
                 pc_ctrl    <= latch_pc;
2275
                                          --
2276
                                     st_ctrl      <= idle_st;
2277
                                     return_state <= fetch_state;
2278
                                          next_state   <= sync_state;
2279
 
2280
                                        --
2281
                                        -- lbra -- long branch (3 bytes)
2282
                                        -- 6809 => 5 cycles
2283
                                        -- cpu09 => 4 cycles
2284
                                        -- 1 op=(pc) / pc=pc+1
2285
                                        -- 2 md_hi=sign(pc) / md_lo=(pc) / pc=pc+1
2286
                                        -- 3 md_hi=md_lo / md_lo=(pc) / pc=pc+1
2287
                                        -- 4 pc=pc+md
2288
                                        --
2289
                         when "0110" =>
2290
                                op_ctrl    <= latch_op;
2291
                                          acca_ctrl  <= latch_acca;
2292
                                          -- idle ALU
2293
                 left_ctrl  <= pc_left;
2294
                 right_ctrl <= zero_right;
2295
                 alu_ctrl   <= alu_nop;
2296
                                          cc_ctrl    <= latch_cc;
2297
                 sp_ctrl    <= latch_sp;
2298
                                          -- increment the pc
2299
                 pc_ctrl    <= incr_pc;
2300
                                          --
2301
                                     st_ctrl      <= idle_st;
2302
                                     return_state <= fetch_state;
2303
                                          next_state   <= lbranch_state;
2304
 
2305
                                        --
2306
                                        -- lbsr - long branch to subroutine (3 bytes)
2307
                                        -- 6809 => 9 cycles
2308
                                        -- cpu09 => 6 cycles
2309
                                        -- 1 op=(pc) /pc=pc+1
2310
                                        -- 2 md_hi=sign(pc) / md_lo=(pc) / pc=pc+1 / sp=sp-1
2311
                                        -- 3 md_hi=md_lo / md_lo=(pc) / pc=pc+1
2312
                                        -- 4 (sp)= pc_lo / sp=sp-1 / pc=pc
2313
                                        -- 5 (sp)=pc_hi / pc=pc
2314
                                        -- 6 pc=pc+md
2315
                                        --
2316
                         when "0111" =>
2317
                                op_ctrl    <= latch_op;
2318
                                          acca_ctrl  <= latch_acca;
2319
                                          -- pre decrement sp
2320
                 left_ctrl  <= sp_left;
2321
                 right_ctrl <= one_right;
2322
                 alu_ctrl   <= alu_sub16;
2323
                                          cc_ctrl    <= latch_cc;
2324
                 sp_ctrl    <= load_sp;
2325
                                          -- increment the pc
2326
                 pc_ctrl    <= incr_pc;
2327
                                          --
2328
                                     st_ctrl      <= idle_st;
2329
                                     return_state <= fetch_state;
2330
                                          next_state   <= lbranch_state;
2331
 
2332
                         when "1001" => -- daa
2333
                                op_ctrl    <= latch_op;
2334
                                          --
2335
                                          left_ctrl  <= acca_left;
2336
                      right_ctrl <= accb_right;
2337
                                          alu_ctrl   <= alu_daa;
2338
                 cc_ctrl    <= load_cc;
2339
                                          acca_ctrl  <= load_acca;
2340
                 sp_ctrl    <= latch_sp;
2341
                                          -- idle pc
2342
                 pc_ctrl    <= latch_pc;
2343
                                          --
2344
                                     st_ctrl      <= idle_st;
2345
                                     return_state <= fetch_state;
2346
                                          next_state   <= fetch_state;
2347
 
2348
                         when "1010" => -- orcc
2349
                                op_ctrl    <= latch_op;
2350
                                          acca_ctrl  <= latch_acca;
2351
                                          -- idle ALU
2352
                 left_ctrl  <= pc_left;
2353
                 right_ctrl <= zero_right;
2354
                 alu_ctrl   <= alu_nop;
2355
                                          cc_ctrl    <= latch_cc;
2356
                 sp_ctrl    <= latch_sp;
2357
                                          -- increment the pc
2358
                 pc_ctrl    <= incr_pc;
2359
                                          -- next state
2360
                                     st_ctrl      <= push_st;
2361
                                     return_state <= fetch_state;
2362
                                          next_state   <= orcc_state;
2363
 
2364
                         when "1100" => -- andcc
2365
                                op_ctrl    <= latch_op;
2366
                                          acca_ctrl  <= latch_acca;
2367
                                          -- idle ALU
2368
                 left_ctrl  <= pc_left;
2369
                 right_ctrl <= zero_right;
2370
                 alu_ctrl   <= alu_nop;
2371
                                          cc_ctrl    <= latch_cc;
2372
                 sp_ctrl    <= latch_sp;
2373
                                          -- increment the pc
2374
                 pc_ctrl    <= incr_pc;
2375
                                          --
2376
                                     st_ctrl      <= push_st;
2377
                                     return_state <= fetch_state;
2378
                                          next_state   <= andcc_state;
2379
 
2380
                         when "1101" => -- sex
2381
                                op_ctrl    <= latch_op;
2382
                                          -- have sex
2383
                 left_ctrl  <= accb_left;
2384
                 right_ctrl <= zero_right;
2385
                 alu_ctrl   <= alu_sex;
2386
                                          cc_ctrl    <= load_cc;
2387
                                          acca_ctrl  <= load_hi_acca;
2388
                 sp_ctrl    <= latch_sp;
2389
                                          -- idle PC
2390
                 pc_ctrl    <= latch_pc;
2391
                                          --
2392
                                     st_ctrl      <= idle_st;
2393
                                     return_state <= fetch_state;
2394
                                          next_state   <= fetch_state;
2395
 
2396
                         when "1110" => -- exg
2397
                                op_ctrl    <= latch_op;
2398
                                          acca_ctrl  <= latch_acca;
2399
                                          -- idle ALU
2400
                 left_ctrl  <= pc_left;
2401
                 right_ctrl <= zero_right;
2402
                 alu_ctrl   <= alu_nop;
2403
                                          cc_ctrl    <= latch_cc;
2404
                 sp_ctrl    <= latch_sp;
2405
                                          -- increment the pc
2406
                 pc_ctrl    <= incr_pc;
2407
                                          --
2408
                                     st_ctrl      <= idle_st;
2409
                                     return_state <= fetch_state;
2410
                                          next_state   <= exg_state;
2411
 
2412
                         when "1111" => -- tfr
2413
                                op_ctrl    <= latch_op;
2414
                                          acca_ctrl  <= latch_acca;
2415
                                          -- idle ALU
2416
                 left_ctrl  <= pc_left;
2417
                 right_ctrl <= zero_right;
2418
                 alu_ctrl   <= alu_nop;
2419
                                          cc_ctrl    <= latch_cc;
2420
                 sp_ctrl    <= latch_sp;
2421
                                          -- increment the pc
2422
                 pc_ctrl    <= incr_pc;
2423
                                          -- call transfer as a subroutine
2424
                                     st_ctrl      <= push_st;
2425
                                     return_state <= fetch_state;
2426
                                          next_state   <= tfr_state;
2427
 
2428
                         when others =>
2429
                                op_ctrl    <= latch_op;
2430
                                          acca_ctrl  <= latch_acca;
2431
                                          -- idle ALU
2432
                 left_ctrl  <= pc_left;
2433
                 right_ctrl <= zero_right;
2434
                 alu_ctrl   <= alu_nop;
2435
                                          cc_ctrl    <= latch_cc;
2436
                 sp_ctrl    <= latch_sp;
2437
                                          -- increment the pc
2438
                 pc_ctrl    <= incr_pc;
2439
                                          --
2440
                                     st_ctrl      <= idle_st;
2441
                                     return_state <= fetch_state;
2442
                                          next_state   <= fetch_state;
2443
                         end case;
2444
             --
2445
                                 -- Short branch conditional
2446
                                 -- 6809 => always 3 cycles
2447
                                 -- cpu09 => always = 3 cycles
2448
                                 -- 1 op=(pc) / pc=pc+1
2449
                                 -- 2 md_hi=sign(pc) / md_lo=(pc) / pc=pc+1 / test cc
2450
                                 -- 3 if cc tru pc=pc+md else pc=pc
2451
                                 --
2452
                  when "0010" => -- branch conditional
2453
                              op_ctrl    <= latch_op;
2454
                                        acca_ctrl  <= latch_acca;
2455
               accb_ctrl  <= latch_accb;
2456
               ix_ctrl    <= latch_ix;
2457
               iy_ctrl    <= latch_iy;
2458
               sp_ctrl    <= latch_sp;
2459
               up_ctrl    <= latch_up;
2460
               iv_ctrl    <= latch_iv;
2461
                                        -- idle ALU
2462
               left_ctrl  <= pc_left;
2463
               right_ctrl <= one_right;
2464
               alu_ctrl   <= alu_add16;
2465
                                        cc_ctrl    <= latch_cc;
2466
                                        -- increment the pc
2467
               pc_ctrl    <= incr_pc;
2468
                                        --
2469
                                   st_ctrl      <= idle_st;
2470
                                   return_state <= fetch_state;
2471
               next_state   <= sbranch_state;
2472
                                 --
2473
                                 -- Single byte stack operators
2474
                                 -- Do not advance PC
2475
                                 --
2476
                  when "0011" =>
2477
                              op_ctrl    <= latch_op;
2478
                                        acca_ctrl  <= latch_acca;
2479
               accb_ctrl  <= latch_accb;
2480
                                        --
2481
                                        -- lea - load effective address (2+ bytes)
2482
                                        -- 6809 => 4 cycles + addressing mode
2483
                                        -- cpu09 => 4 cycles + addressing mode
2484
                                        -- 1 op=(pc) / pc=pc+1
2485
                                        -- 2 md_lo=(pc) / pc=pc+1
2486
                                        -- 3 calculate ea
2487
                                        -- 4 ix/iy/sp/up = ea
2488
                                        --
2489
                    case op_code(3 downto 0) is
2490
                         when "0000" |  -- leax
2491
                              "0001" |  -- leay
2492
                              "0010" |  -- leas
2493
                              "0011" => -- leau
2494
                            left_ctrl  <= pc_left;
2495
                            right_ctrl <= one_right;
2496
                                                alu_ctrl   <= alu_add16;
2497
                                           cc_ctrl    <= latch_cc;
2498
                                                -- advance PC
2499
                  pc_ctrl    <= incr_pc;
2500
                                                --
2501
                                                ix_ctrl    <= latch_ix;
2502
                                      iy_ctrl    <= latch_iy;
2503
                                                sp_ctrl    <= latch_sp;
2504
                  up_ctrl    <= latch_up;
2505
                  iv_ctrl    <= latch_iv;
2506
                                                --
2507
                                      st_ctrl      <= push_st;
2508
                                      return_state <= lea_state;
2509
                                                next_state   <= indexed_state;
2510
 
2511
                                        --
2512
                                        -- pshs - push registers onto sp stack
2513
                                        -- 6809 => 5 cycles + registers
2514
                                        -- cpu09 => 3 cycles + registers
2515
                                        --  1 op=(pc) / pc=pc+1
2516
                                        --  2 ea_lo=(pc) / pc=pc+1 
2517
                                        --  3 if ea(7 downto 0) != "00000000" then sp=sp-1
2518
                                        --  4 if ea(7) = 1 (sp)=pcl, sp=sp-1
2519
                                        --  5 if ea(7) = 1 (sp)=pch
2520
                                        --    if ea(6 downto 0) != "0000000" then sp=sp-1
2521
                                        --  6 if ea(6) = 1 (sp)=upl, sp=sp-1
2522
                                        --  7 if ea(6) = 1 (sp)=uph
2523
                                        --    if ea(5 downto 0) != "000000" then sp=sp-1
2524
                                        --  8 if ea(5) = 1 (sp)=iyl, sp=sp-1
2525
                                        --  9 if ea(5) = 1 (sp)=iyh
2526
                                        --    if ea(4 downto 0) != "00000" then sp=sp-1
2527
                                        -- 10 if ea(4) = 1 (sp)=ixl, sp=sp-1
2528
                                        -- 11 if ea(4) = 1 (sp)=ixh
2529
                                        --    if ea(3 downto 0) != "0000" then sp=sp-1
2530
                                        -- 12 if ea(3) = 1 (sp)=dp
2531
                                        --    if ea(2 downto 0) != "000" then sp=sp-1
2532
                                        -- 13 if ea(2) = 1 (sp)=accb
2533
                                        --    if ea(1 downto 0) != "00" then sp=sp-1
2534
                                        -- 14 if ea(1) = 1 (sp)=acca
2535
                                        --    if ea(0 downto 0) != "0" then sp=sp-1
2536
                                        -- 15 if ea(0) = 1 (sp)=cc
2537
                                        --
2538
                         when "0100" => -- pshs
2539
                                           --
2540
                            left_ctrl  <= sp_left;
2541
                            right_ctrl <= one_right;
2542
                                                alu_ctrl   <= alu_nop;
2543
                                           cc_ctrl    <= latch_cc;
2544
                                                -- advance PC
2545
                  pc_ctrl    <= incr_pc;
2546
                                                --
2547
                                                ix_ctrl    <= latch_ix;
2548
                                      iy_ctrl    <= latch_iy;
2549
                                                sp_ctrl    <= latch_sp;
2550
                  up_ctrl    <= latch_up;
2551
                  iv_ctrl    <= latch_iv;
2552
                                                --
2553
                                      st_ctrl      <= idle_st;
2554
                                      return_state <= fetch_state;
2555
                                                next_state   <= pshs_state;
2556
 
2557
                                        --
2558
                                        -- puls - pull registers of sp stack
2559
                                        -- 6809 => 5 cycles + registers
2560
                                        -- cpu09 => 3 cycles + registers
2561
                                        --
2562
                         when "0101" => -- puls
2563
                  left_ctrl  <= pc_left;
2564
                  right_ctrl <= one_right;
2565
                  alu_ctrl   <= alu_add16;
2566
                                           cc_ctrl    <= latch_cc;
2567
                                                -- advance PC
2568
                  pc_ctrl    <= incr_pc;
2569
                                                --
2570
                                                ix_ctrl    <= latch_ix;
2571
                                      iy_ctrl    <= latch_iy;
2572
                  sp_ctrl    <= latch_sp;
2573
                  up_ctrl    <= latch_up;
2574
                  iv_ctrl    <= latch_iv;
2575
                                                --
2576
                                      st_ctrl      <= idle_st;
2577
                                      return_state <= fetch_state;
2578
                                                next_state   <= puls_state;
2579
 
2580
                                        --
2581
                                        -- pshu - push registers onto up stack
2582
                                        -- 6809 => 5 cycles + registers
2583
                                        -- cpu09 => 3 cycles + registers
2584
                                        --
2585
                         when "0110" => -- pshu
2586
                                           -- idle UP
2587
                            left_ctrl  <= up_left;
2588
                            right_ctrl <= one_right;
2589
                                                alu_ctrl   <= alu_nop;
2590
                                           cc_ctrl    <= latch_cc;
2591
                                                -- advance PC
2592
                  pc_ctrl    <= incr_pc;
2593
                                                --
2594
                                                ix_ctrl    <= latch_ix;
2595
                                      iy_ctrl    <= latch_iy;
2596
                                                sp_ctrl    <= latch_sp;
2597
                  up_ctrl    <= latch_up;
2598
                  iv_ctrl    <= latch_iv;
2599
                                                --
2600
                                      st_ctrl      <= idle_st;
2601
                                      return_state <= fetch_state;
2602
                                                next_state   <= pshu_state;
2603
 
2604
                                        --
2605
                                        -- pulu - pull registers of up stack
2606
                                        -- 6809 => 5 cycles + registers
2607
                                        -- cpu09 => 3 cycles + registers
2608
                                        --
2609
                         when "0111" => -- pulu
2610
                  left_ctrl  <= pc_left;
2611
                  right_ctrl <= one_right;
2612
                  alu_ctrl   <= alu_add16;
2613
                                           cc_ctrl    <= latch_cc;
2614
                                                -- advance PC
2615
                  pc_ctrl    <= incr_pc;
2616
                                                --
2617
                                                ix_ctrl    <= latch_ix;
2618
                                      iy_ctrl    <= latch_iy;
2619
                  sp_ctrl    <= latch_sp;
2620
                  up_ctrl    <= latch_up;
2621
                  iv_ctrl    <= latch_iv;
2622
                                                --
2623
                                      st_ctrl    <= idle_st;
2624
                                      return_state <= fetch_state;
2625
                                                next_state <= pulu_state;
2626
 
2627
                                        --
2628
                                        -- rts - return from subroutine
2629
                                        -- 6809 => 5 cycles
2630
                                        -- cpu09 => 4 cycles 
2631
                                        -- 1 op=(pc) / pc=pc+1
2632
                                        -- 2 decode op
2633
                                        -- 3 pc_hi = (sp) / sp=sp+1
2634
                                        -- 4 pc_lo = (sp) / sp=sp+1
2635
                                        --
2636
                         when "1001" =>
2637
                  left_ctrl  <= sp_left;
2638
                  right_ctrl <= zero_right;
2639
                  alu_ctrl   <= alu_nop;
2640
                                           cc_ctrl    <= latch_cc;
2641
                                                -- idle PC
2642
                  pc_ctrl    <= latch_pc;
2643
                                                --
2644
                                                ix_ctrl    <= latch_ix;
2645
                                      iy_ctrl    <= latch_iy;
2646
                  sp_ctrl    <= latch_sp;
2647
                  up_ctrl    <= latch_up;
2648
                  iv_ctrl    <= latch_iv;
2649
                                                --
2650
                                      st_ctrl    <= push_st;
2651
                                      return_state <= fetch_state;
2652
                                                next_state <= pull_return_hi_state;
2653
 
2654
                                        --
2655
                                        -- add accb to index register
2656
                                        -- *** Note: this is an unsigned addition.
2657
                                        --           does not affect any condition codes
2658
                                        -- 6809 => 3 cycles
2659
                                        -- cpu09 => 2 cycles
2660
                                        -- 1 op=(pc) / pc=pc+1
2661
                                        -- 2 alu_left=ix / alu_right=accb / ix=alu_out / pc=pc
2662
                                        --
2663
                         when "1010" => -- abx
2664
                            left_ctrl  <= ix_left;
2665
                            right_ctrl <= accb_right;
2666
                                                alu_ctrl   <= alu_abx;
2667
                                           cc_ctrl    <= latch_cc;
2668
                                                ix_ctrl    <= load_ix;
2669
                                                --
2670
                  pc_ctrl    <= latch_pc;
2671
                                      iy_ctrl    <= latch_iy;
2672
                  sp_ctrl    <= latch_sp;
2673
                  up_ctrl    <= latch_up;
2674
                  iv_ctrl    <= latch_iv;
2675
                                                --
2676
                                      st_ctrl    <= idle_st;
2677
                                      return_state <= fetch_state;
2678
                                                next_state <= fetch_state;
2679
 
2680
                         when "1011" => -- rti
2681
                                           -- idle ALU
2682
                  left_ctrl  <= sp_left;
2683
                  right_ctrl <= zero_right;
2684
                  alu_ctrl   <= alu_nop;
2685
                                           cc_ctrl    <= latch_cc;
2686
                                                --
2687
                  pc_ctrl    <= latch_pc;
2688
                                                ix_ctrl    <= latch_ix;
2689
                                      iy_ctrl    <= latch_iy;
2690
                  sp_ctrl    <= latch_sp;
2691
                  up_ctrl    <= latch_up;
2692
                  iv_ctrl    <= latch_iv;
2693
                                                --
2694
                                      st_ctrl    <= idle_st;
2695
                                      return_state <= fetch_state;
2696
                                                next_state <= rti_cc_state;
2697
 
2698
                         when "1100" => -- cwai #$<cc_mask>
2699
                                           -- pre decrement sp
2700
                            left_ctrl  <= sp_left;
2701
                            right_ctrl <= one_right;
2702
                                                alu_ctrl   <= alu_sub16;
2703
                                           cc_ctrl    <= latch_cc;
2704
                                                sp_ctrl    <= load_sp;
2705
                                                --
2706
                  pc_ctrl    <= incr_pc;
2707
                                                ix_ctrl    <= latch_ix;
2708
                                      iy_ctrl    <= latch_iy;
2709
                  up_ctrl    <= latch_up;
2710
                  iv_ctrl    <= latch_iv;
2711
                                                --
2712
                                      st_ctrl    <= push_st;
2713
                                      return_state <= int_entire_state; -- set entire flag
2714
                                                next_state <= andcc_state;
2715
 
2716
                         when "1101" => -- mul
2717
                            left_ctrl  <= acca_left;
2718
                            right_ctrl <= zero_right;
2719
                                                alu_ctrl   <= alu_nop;
2720
                                           cc_ctrl    <= latch_cc;
2721
                                                --
2722
                  pc_ctrl    <= latch_pc;
2723
                                                ix_ctrl    <= latch_ix;
2724
                                      iy_ctrl    <= latch_iy;
2725
                                                sp_ctrl    <= latch_sp;
2726
                  up_ctrl    <= latch_up;
2727
                  iv_ctrl    <= latch_iv;
2728
                                                --
2729
                                      st_ctrl    <= idle_st;
2730
                                      return_state <= fetch_state;
2731
                                                next_state <= mul_state;
2732
 
2733
                         when "1111" => -- swi
2734
                                           -- predecrement SP
2735
                            left_ctrl  <= sp_left;
2736
                            right_ctrl <= one_right;
2737
                                                alu_ctrl   <= alu_sub16;
2738
                                           cc_ctrl    <= latch_cc;
2739
                                                sp_ctrl    <= load_sp;
2740
                                                --
2741
                  pc_ctrl    <= latch_pc;
2742
                                                ix_ctrl    <= latch_ix;
2743
                                      iy_ctrl    <= latch_iy;
2744
                  up_ctrl    <= latch_up;
2745
                  iv_ctrl    <= swi_iv;
2746
                                                --
2747
                                      st_ctrl      <= idle_st;
2748
                                      return_state <= fetch_state;
2749
                                                next_state   <= int_entire_state;
2750
 
2751
                         when others =>
2752
                                           -- idle ALU
2753
                            left_ctrl  <= pc_left;
2754
                            right_ctrl <= zero_right;
2755
                                                alu_ctrl   <= alu_nop;
2756
                                           cc_ctrl    <= latch_cc;
2757
                                                -- idle PC
2758
                  pc_ctrl    <= latch_pc;
2759
                                                --
2760
                                                ix_ctrl    <= latch_ix;
2761
                                      iy_ctrl    <= latch_iy;
2762
                                                sp_ctrl    <= latch_sp;
2763
                  up_ctrl    <= latch_up;
2764
                  iv_ctrl    <= latch_iv;
2765
                                                --
2766
                                      st_ctrl    <= idle_st;
2767
                                      return_state <= fetch_state;
2768
                                                next_state <= fetch_state;
2769
 
2770
                         end case;
2771
                                 --
2772
                                 -- Accumulator A Single operand
2773
                                 -- source = acca, dest = acca
2774
                                 -- Do not advance PC
2775
                                 -- Typically 2 cycles 1 bytes
2776
                                 -- 1 opcode fetch
2777
                                 -- 2 post byte fetch / instruction decode
2778
                                 -- Note that there is no post byte
2779
                                 -- so do not advance PC in decode cycle
2780
                                 -- Re-run opcode fetch cycle after decode
2781
                                 -- 
2782
                  when "0100" => -- acca single op
2783
                              op_ctrl    <= latch_op;
2784
               accb_ctrl  <= latch_accb;
2785
               pc_ctrl    <= latch_pc;
2786
                                   ix_ctrl    <= latch_ix;
2787
               iy_ctrl    <= latch_iy;
2788
               up_ctrl    <= latch_up;
2789
                                   sp_ctrl    <= latch_sp;
2790
               iv_ctrl    <= latch_iv;
2791
                         left_ctrl  <= acca_left;
2792
                    case op_code(3 downto 0) is
2793
                         when "0000" => -- neg
2794
                                          right_ctrl <= zero_right;
2795
                                          alu_ctrl   <= alu_neg;
2796
                                          acca_ctrl  <= load_acca;
2797
                                          cc_ctrl    <= load_cc;
2798
                    when "0011" => -- com
2799
                           right_ctrl <= zero_right;
2800
                                          alu_ctrl   <= alu_com;
2801
                                          acca_ctrl  <= load_acca;
2802
                                          cc_ctrl    <= load_cc;
2803
                         when "0100" => -- lsr
2804
                           right_ctrl <= zero_right;
2805
                                          alu_ctrl   <= alu_lsr8;
2806
                                          acca_ctrl  <= load_acca;
2807
                                          cc_ctrl    <= load_cc;
2808
                         when "0110" => -- ror
2809
                           right_ctrl <= zero_right;
2810
                                          alu_ctrl   <= alu_ror8;
2811
                                          acca_ctrl  <= load_acca;
2812
                                          cc_ctrl    <= load_cc;
2813
                         when "0111" => -- asr
2814
                           right_ctrl <= zero_right;
2815
                                          alu_ctrl   <= alu_asr8;
2816
                                          acca_ctrl  <= load_acca;
2817
                                          cc_ctrl    <= load_cc;
2818
                         when "1000" => -- asl
2819
                           right_ctrl <= zero_right;
2820
                                          alu_ctrl   <= alu_asl8;
2821
                                          acca_ctrl  <= load_acca;
2822
                                          cc_ctrl    <= load_cc;
2823
                         when "1001" => -- rol
2824
                           right_ctrl <= zero_right;
2825
                                          alu_ctrl   <= alu_rol8;
2826
                                          acca_ctrl  <= load_acca;
2827
                                          cc_ctrl    <= load_cc;
2828
                         when "1010" => -- dec
2829
                           right_ctrl <= one_right;
2830
                                          alu_ctrl   <= alu_dec;
2831
                                          acca_ctrl  <= load_acca;
2832
                                          cc_ctrl    <= load_cc;
2833
                         when "1011" => -- undefined
2834
                           right_ctrl <= zero_right;
2835
                                          alu_ctrl   <= alu_nop;
2836
                                          acca_ctrl  <= latch_acca;
2837
                                          cc_ctrl    <= latch_cc;
2838
                         when "1100" => -- inc
2839
                           right_ctrl <= one_right;
2840
                                          alu_ctrl   <= alu_inc;
2841
                                          acca_ctrl  <= load_acca;
2842
                                          cc_ctrl    <= load_cc;
2843
                         when "1101" => -- tst
2844
                           right_ctrl <= zero_right;
2845
                                          alu_ctrl   <= alu_st8;
2846
                                          acca_ctrl  <= latch_acca;
2847
                                          cc_ctrl    <= load_cc;
2848
                         when "1110" => -- jmp (not defined)
2849
                           right_ctrl <= zero_right;
2850
                                          alu_ctrl   <= alu_nop;
2851
                                          acca_ctrl  <= latch_acca;
2852
                                          cc_ctrl    <= latch_cc;
2853
                         when "1111" => -- clr
2854
                           right_ctrl <= zero_right;
2855
                                          alu_ctrl   <= alu_clr;
2856
                                          acca_ctrl  <= load_acca;
2857
                                          cc_ctrl    <= load_cc;
2858
                         when others =>
2859
                           right_ctrl <= zero_right;
2860
                                          alu_ctrl   <= alu_nop;
2861
                                          acca_ctrl  <= latch_acca;
2862
                                          cc_ctrl    <= latch_cc;
2863
                         end case;
2864
                                   st_ctrl    <= idle_st;
2865
                                   return_state <= fetch_state;
2866
                                   next_state <= fetch_state;
2867
                                 --
2868
                                 -- Single Operand accb
2869
                                 -- source = accb, dest = accb
2870
                                 -- Typically 2 cycles 1 bytes
2871
                                 -- 1 opcode fetch
2872
                                 -- 2 post byte fetch / instruction decode
2873
                                 -- Note that there is no post byte
2874
                                 -- so do not advance PC in decode cycle
2875
                                 -- Re-run opcode fetch cycle after decode
2876
                                 --
2877
                  when "0101" =>
2878
                              op_ctrl    <= latch_op;
2879
               acca_ctrl  <= latch_acca;
2880
               pc_ctrl    <= latch_pc;
2881
                                   ix_ctrl    <= latch_ix;
2882
               iy_ctrl    <= latch_iy;
2883
               up_ctrl    <= latch_up;
2884
                                   sp_ctrl    <= latch_sp;
2885
               iv_ctrl    <= latch_iv;
2886
                         left_ctrl  <= accb_left;
2887
                    case op_code(3 downto 0) is
2888
                         when "0000" => -- neg
2889
                                          right_ctrl <= zero_right;
2890
                                          alu_ctrl   <= alu_neg;
2891
                                          accb_ctrl  <= load_accb;
2892
                                          cc_ctrl    <= load_cc;
2893
                    when "0011" => -- com
2894
                           right_ctrl <= zero_right;
2895
                                          alu_ctrl   <= alu_com;
2896
                                          accb_ctrl  <= load_accb;
2897
                                          cc_ctrl    <= load_cc;
2898
                         when "0100" => -- lsr
2899
                           right_ctrl <= zero_right;
2900
                                          alu_ctrl   <= alu_lsr8;
2901
                                          accb_ctrl  <= load_accb;
2902
                                          cc_ctrl    <= load_cc;
2903
                         when "0110" => -- ror
2904
                           right_ctrl <= zero_right;
2905
                                          alu_ctrl   <= alu_ror8;
2906
                                          accb_ctrl  <= load_accb;
2907
                                          cc_ctrl    <= load_cc;
2908
                         when "0111" => -- asr
2909
                           right_ctrl <= zero_right;
2910
                                          alu_ctrl   <= alu_asr8;
2911
                                          accb_ctrl  <= load_accb;
2912
                                          cc_ctrl    <= load_cc;
2913
                         when "1000" => -- asl
2914
                           right_ctrl <= zero_right;
2915
                                          alu_ctrl   <= alu_asl8;
2916
                                          accb_ctrl  <= load_accb;
2917
                                          cc_ctrl    <= load_cc;
2918
                         when "1001" => -- rol
2919
                           right_ctrl <= zero_right;
2920
                                          alu_ctrl   <= alu_rol8;
2921
                                          accb_ctrl  <= load_accb;
2922
                                          cc_ctrl    <= load_cc;
2923
                         when "1010" => -- dec
2924
                           right_ctrl <= one_right;
2925
                                          alu_ctrl   <= alu_dec;
2926
                                          accb_ctrl  <= load_accb;
2927
                                          cc_ctrl    <= load_cc;
2928
                         when "1011" => -- undefined
2929
                           right_ctrl <= zero_right;
2930
                                          alu_ctrl   <= alu_nop;
2931
                                          accb_ctrl  <= latch_accb;
2932
                                          cc_ctrl    <= latch_cc;
2933
                         when "1100" => -- inc
2934
                           right_ctrl <= one_right;
2935
                                          alu_ctrl   <= alu_inc;
2936
                                          accb_ctrl  <= load_accb;
2937
                                          cc_ctrl    <= load_cc;
2938
                         when "1101" => -- tst
2939
                           right_ctrl <= zero_right;
2940
                                          alu_ctrl   <= alu_st8;
2941
                                          accb_ctrl  <= latch_accb;
2942
                                          cc_ctrl    <= load_cc;
2943
                         when "1110" => -- jmp (undefined)
2944
                           right_ctrl <= zero_right;
2945
                                          alu_ctrl   <= alu_nop;
2946
                                          accb_ctrl  <= latch_accb;
2947
                                          cc_ctrl    <= latch_cc;
2948
                         when "1111" => -- clr
2949
                           right_ctrl <= zero_right;
2950
                                          alu_ctrl   <= alu_clr;
2951
                                          accb_ctrl  <= load_accb;
2952
                                          cc_ctrl    <= load_cc;
2953
                         when others =>
2954
                           right_ctrl <= zero_right;
2955
                                          alu_ctrl   <= alu_nop;
2956
                                          accb_ctrl  <= latch_accb;
2957
                                          cc_ctrl    <= latch_cc;
2958
                         end case;
2959
                                   st_ctrl    <= idle_st;
2960
                                   return_state <= fetch_state;
2961
                                   next_state <= fetch_state;
2962
                                 --
2963
                                 -- Single operand indexed
2964
                                 -- Two byte instruction so advance PC
2965
                                 -- EA should hold index offset
2966
                                 --
2967
                  when "0110" => -- indexed single op
2968
                              op_ctrl    <= latch_op;
2969
               acca_ctrl  <= latch_acca;
2970
                                        accb_ctrl  <= latch_accb;
2971
                                   ix_ctrl    <= latch_ix;
2972
               iy_ctrl    <= latch_iy;
2973
               up_ctrl    <= latch_up;
2974
                                   sp_ctrl    <= latch_sp;
2975
               iv_ctrl    <= latch_iv;
2976
                                        -- idle ALU
2977
               left_ctrl  <= pc_left;
2978
               right_ctrl <= one_right;
2979
               alu_ctrl   <= alu_add16;
2980
                                        cc_ctrl    <= latch_cc;
2981
                                        -- increment the pc 
2982
               pc_ctrl    <= incr_pc;
2983
                                        -- next state
2984
                                        case op_code(3 downto 0) is
2985
                                   when "1110" => -- jmp
2986
                                     return_state <= jmp_state;
2987
                                        when "1111" => -- clr
2988
                                     return_state <= single_op_exec_state;
2989
                                        when others =>
2990
                                     return_state <= single_op_read_state;
2991
                                        end case;
2992
                                   st_ctrl    <= push_st;
2993
                                   next_state <= indexed_state;
2994
             --
2995
                                 -- Single operand extended addressing
2996
                                 -- three byte instruction so advance the PC
2997
                                 -- Low order EA holds high order address
2998
                                 --
2999
                  when "0111" => -- extended single op
3000
                              op_ctrl    <= latch_op;
3001
               acca_ctrl  <= latch_acca;
3002
                                        accb_ctrl  <= latch_accb;
3003
                                   ix_ctrl    <= latch_ix;
3004
               iy_ctrl    <= latch_iy;
3005
               up_ctrl    <= latch_up;
3006
                                   sp_ctrl    <= latch_sp;
3007
               iv_ctrl    <= latch_iv;
3008
                                        -- idle ALU
3009
               left_ctrl  <= pc_left;
3010
               right_ctrl <= one_right;
3011
               alu_ctrl   <= alu_add16;
3012
                                        cc_ctrl    <= latch_cc;
3013
                                        -- increment PC
3014
               pc_ctrl    <= incr_pc;
3015
                                        --
3016
                                        case op_code(3 downto 0) is
3017
                                   when "1110" => -- jmp
3018
                                     return_state <= jmp_state;
3019
                                        when "1111" => -- clr
3020
                                     return_state <= single_op_exec_state;
3021
                                        when others =>
3022
                                     return_state <= single_op_read_state;
3023
                                        end case;
3024
                                   st_ctrl    <= push_st;
3025
                                   next_state <= extended_state;
3026
 
3027
                  when "1000" => -- acca immediate
3028
                              op_ctrl    <= latch_op;
3029
               acca_ctrl  <= latch_acca;
3030
                                        accb_ctrl  <= latch_accb;
3031
                                   ix_ctrl    <= latch_ix;
3032
               iy_ctrl    <= latch_iy;
3033
               up_ctrl    <= latch_up;
3034
               iv_ctrl    <= latch_iv;
3035
                                   -- increment the pc
3036
               pc_ctrl    <= incr_pc;
3037
                                        case op_code(3 downto 0) is
3038
               when "0011" | -- subd #
3039
                                             "1100" | -- cmpx #
3040
                                             "1110" => -- ldx #
3041
                                          -- idle ALU
3042
                 left_ctrl  <= pc_left;
3043
                 right_ctrl <= zero_right;
3044
                 alu_ctrl   <= alu_add16;
3045
                                          cc_ctrl    <= latch_cc;
3046
                                     sp_ctrl    <= latch_sp;
3047
                                          --
3048
                                     st_ctrl      <= push_st;
3049
                                     return_state <= fetch_state;
3050
                                          next_state   <= imm16_state;
3051
 
3052
                                        --
3053
                                        -- bsr offset - Branch to subroutine (2 bytes)
3054
                                        -- 6809 => 7 cycles
3055
                                        -- cpu09 => 5 cycles
3056
                                        -- 1 op=(pc) / pc=pc+1
3057
                                   -- 2 md_hi=sign(pc) / md_lo=(pc) / sp=sp-1 / pc=pc+1
3058
                                        -- 3 (sp)=pc_lo / sp=sp-1
3059
                                        -- 4 (sp)=pc_hi
3060
                                        -- 5 pc=pc+md
3061
                                        --
3062
                                        when "1101" => -- bsr
3063
                                          -- pre decrement SP
3064
                 left_ctrl  <= sp_left;
3065
                 right_ctrl <= one_right;
3066
                 alu_ctrl   <= alu_sub16;
3067
                                          cc_ctrl    <= latch_cc;
3068
                                     sp_ctrl    <= load_sp;
3069
                                          --
3070
                                     st_ctrl      <= push_st;
3071
                                     return_state <= sbranch_state;
3072
                                          next_state   <= push_return_lo_state;
3073
 
3074
                                        when others =>
3075
                                          -- idle ALU
3076
                 left_ctrl  <= pc_left;
3077
                 right_ctrl <= zero_right;
3078
                 alu_ctrl   <= alu_add16;
3079
                                          cc_ctrl    <= latch_cc;
3080
                                     sp_ctrl    <= latch_sp;
3081
                                          --
3082
                                     st_ctrl      <= idle_st;
3083
                                     return_state <= fetch_state;
3084
                                     next_state   <= fetch_state;
3085
               end case;
3086
 
3087
                  when "1001" => -- acca direct
3088
                              op_ctrl    <= latch_op;
3089
               acca_ctrl  <= latch_acca;
3090
                                        accb_ctrl  <= latch_accb;
3091
                                   ix_ctrl    <= latch_ix;
3092
               iy_ctrl    <= latch_iy;
3093
               up_ctrl    <= latch_up;
3094
               iv_ctrl    <= latch_iv;
3095
                                        -- increment the pc
3096
               pc_ctrl    <= incr_pc;
3097
                                        case op_code(3 downto 0) is
3098
               when "0011" | -- subd
3099
                                             "1100" | -- cmpx
3100
                                             "1110" => -- ldx
3101
                                          -- idle ALU
3102
                 left_ctrl  <= pc_left;
3103
                 right_ctrl <= one_right;
3104
                 alu_ctrl   <= alu_add16;
3105
                                          cc_ctrl    <= latch_cc;
3106
                                     sp_ctrl    <= latch_sp;
3107
                                          --
3108
                                     st_ctrl      <= idle_st;
3109
                                     return_state <= fetch_state;
3110
                                     next_state   <= dual_op_read16_state;
3111
 
3112
                                        when "0111" =>  -- sta direct
3113
                                          -- idle ALU
3114
                 left_ctrl  <= acca_left;
3115
                 right_ctrl <= zero_right;
3116
                 alu_ctrl   <= alu_nop;
3117
                                          cc_ctrl    <= latch_cc;
3118
                                     sp_ctrl    <= latch_sp;
3119
                                          --
3120
                                     st_ctrl      <= idle_st;
3121
                                     return_state <= fetch_state;
3122
                                     next_state   <= dual_op_write8_state;
3123
 
3124
                                        when "1111" => -- stx direct
3125
                                          -- idle ALU
3126
                 left_ctrl  <= ix_left;
3127
                 right_ctrl <= zero_right;
3128
                 alu_ctrl   <= alu_nop;
3129
                                          cc_ctrl    <= latch_cc;
3130
                                     sp_ctrl    <= latch_sp;
3131
                                          --
3132
                                     st_ctrl      <= idle_st;
3133
                                     return_state <= fetch_state;
3134
                                     next_state   <= dual_op_write16_state;
3135
 
3136
                                        --
3137
                                        -- jsr direct - Jump to subroutine in direct page (2 bytes)
3138
                                        -- 6809 => 7 cycles
3139
                                        -- cpu09 => 5 cycles
3140
                                        -- 1 op=(pc) / pc=pc+1
3141
                                   -- 2 ea_hi=0 / ea_lo=(pc) / sp=sp-1 / pc=pc+1
3142
                                        -- 3 (sp)=pc_lo / sp=sp-1
3143
                                        -- 4 (sp)=pc_hi
3144
                                        -- 5 pc=ea
3145
                                        --
3146
                                        when "1101" => -- jsr direct
3147
                                          -- pre decrement sp
3148
                 left_ctrl  <= sp_left;
3149
                 right_ctrl <= one_right;
3150
                 alu_ctrl   <= alu_sub16;
3151
                                          cc_ctrl    <= latch_cc;
3152
                                     sp_ctrl    <= load_sp;
3153
                                          --
3154
                                     st_ctrl      <= push_st;
3155
                                     return_state <= jmp_state;
3156
                                          next_state   <= push_return_lo_state;
3157
 
3158
                                        when others =>
3159
                                          -- idle ALU
3160
                 left_ctrl  <= acca_left;
3161
                 right_ctrl <= zero_right;
3162
                 alu_ctrl   <= alu_nop;
3163
                                          cc_ctrl    <= latch_cc;
3164
                                     sp_ctrl    <= latch_sp;
3165
                                          --
3166
                                     st_ctrl      <= idle_st;
3167
                                     return_state <= fetch_state;
3168
                                     next_state   <= dual_op_read8_state;
3169
               end case;
3170
 
3171
                  when "1010" => -- acca indexed
3172
                              op_ctrl    <= latch_op;
3173
               acca_ctrl  <= latch_acca;
3174
                                        accb_ctrl  <= latch_accb;
3175
                                   ix_ctrl    <= latch_ix;
3176
               iy_ctrl    <= latch_iy;
3177
               up_ctrl    <= latch_up;
3178
               iv_ctrl    <= latch_iv;
3179
                                        -- increment the pc
3180
               pc_ctrl    <= incr_pc;
3181
                                        case op_code(3 downto 0) is
3182
               when "0011" | -- subd
3183
                                             "1100" | -- cmpx
3184
                                             "1110" => -- ldx
3185
                                          -- idle ALU
3186
                 left_ctrl  <= pc_left;
3187
                 right_ctrl <= zero_right;
3188
                 alu_ctrl   <= alu_add16;
3189
                                          cc_ctrl    <= latch_cc;
3190
                                     sp_ctrl    <= latch_sp;
3191
                                          --
3192
                                     st_ctrl    <= push_st;
3193
                                     return_state <= dual_op_read16_state;
3194
                                     next_state <= indexed_state;
3195
 
3196
                                        when "0111" =>  -- staa ,x
3197
                                          -- idle ALU
3198
                 left_ctrl  <= acca_left;
3199
                 right_ctrl <= zero_right;
3200
                 alu_ctrl   <= alu_nop;
3201
                                          cc_ctrl    <= latch_cc;
3202
                                     sp_ctrl    <= latch_sp;
3203
                                          --
3204
                                     st_ctrl      <= push_st;
3205
                                     return_state <= dual_op_write8_state;
3206
                                     next_state   <= indexed_state;
3207
 
3208
                                        when "1111" => -- stx ,x
3209
                                          -- idle ALU
3210
                 left_ctrl  <= ix_left;
3211
                 right_ctrl <= zero_right;
3212
                 alu_ctrl   <= alu_nop;
3213
                                          cc_ctrl    <= latch_cc;
3214
                                     sp_ctrl    <= latch_sp;
3215
                                          --
3216
                                     st_ctrl      <= push_st;
3217
                                     return_state <= dual_op_write16_state;
3218
                                     next_state   <= indexed_state;
3219
 
3220
                                        when "1101" => -- jsr ,x
3221
                                          -- DO NOT pre decrement SP
3222
                 left_ctrl  <= sp_left;
3223
                 right_ctrl <= one_right;
3224
                 alu_ctrl   <= alu_sub16;
3225
                                          cc_ctrl    <= latch_cc;
3226
                                     sp_ctrl    <= latch_sp;
3227
                                          --
3228
                                     st_ctrl      <= push_st;
3229
                                     return_state <= jsr_state;
3230
                                          next_state   <= indexed_state;
3231
 
3232
                                        when others =>
3233
                                          -- idle ALU
3234
                 left_ctrl  <= pc_left;
3235
                 right_ctrl <= one_right;
3236
                 alu_ctrl   <= alu_add16;
3237
                                          cc_ctrl    <= latch_cc;
3238
                                     sp_ctrl    <= latch_sp;
3239
                                          --
3240
                                     st_ctrl      <= push_st;
3241
                                     return_state <= dual_op_read8_state;
3242
                                     next_state   <= indexed_state;
3243
               end case;
3244
 
3245
             when "1011" => -- acca extended
3246
                              op_ctrl    <= latch_op;
3247
               acca_ctrl  <= latch_acca;
3248
                                        accb_ctrl  <= latch_accb;
3249
                                   ix_ctrl    <= latch_ix;
3250
               iy_ctrl    <= latch_iy;
3251
               up_ctrl    <= latch_up;
3252
               iv_ctrl    <= latch_iv;
3253
                                        -- increment the pc
3254
               pc_ctrl    <= incr_pc;
3255
                                        case op_code(3 downto 0) is
3256
               when "0011" | -- subd
3257
                                             "1100" | -- cmpx
3258
                                             "1110" => -- ldx
3259
                                          -- idle ALU
3260
                 left_ctrl  <= pc_left;
3261
                 right_ctrl <= one_right;
3262
                 alu_ctrl   <= alu_add16;
3263
                                          cc_ctrl    <= latch_cc;
3264
                                     sp_ctrl    <= latch_sp;
3265
                                          --
3266
                                     st_ctrl    <= push_st;
3267
                                     return_state <= dual_op_read16_state;
3268
                                     next_state <= extended_state;
3269
 
3270
                                        when "0111" =>  -- staa >
3271
                                          -- idle ALU
3272
                 left_ctrl  <= acca_left;
3273
                 right_ctrl <= zero_right;
3274
                 alu_ctrl   <= alu_nop;
3275
                                          cc_ctrl    <= latch_cc;
3276
                                     sp_ctrl    <= latch_sp;
3277
                                          --
3278
                                     st_ctrl      <= push_st;
3279
                                     return_state <= dual_op_write8_state;
3280
                                     next_state   <= extended_state;
3281
 
3282
                                        when "1111" => -- stx >
3283
                                          -- idle ALU
3284
                 left_ctrl  <= ix_left;
3285
                 right_ctrl <= zero_right;
3286
                 alu_ctrl   <= alu_nop;
3287
                                          cc_ctrl    <= latch_cc;
3288
                                     sp_ctrl    <= latch_sp;
3289
                                          --
3290
                                     st_ctrl      <= push_st;
3291
                                     return_state <= dual_op_write16_state;
3292
                                     next_state   <= extended_state;
3293
 
3294
                                        when "1101" => -- jsr >extended
3295
                                          -- DO NOT pre decrement sp
3296
                 left_ctrl  <= sp_left;
3297
                 right_ctrl <= one_right;
3298
                 alu_ctrl   <= alu_sub16;
3299
                                          cc_ctrl    <= latch_cc;
3300
                                     sp_ctrl    <= latch_sp;
3301
                                          --
3302
                                     st_ctrl      <= push_st;
3303
                                     return_state <= jsr_state;
3304
                                          next_state   <= extended_state;
3305
 
3306
                                        when others =>
3307
                                          -- idle ALU
3308
                 left_ctrl  <= acca_left;
3309
                 right_ctrl <= zero_right;
3310
                 alu_ctrl   <= alu_st8;
3311
                                          cc_ctrl    <= latch_cc;
3312
                                     sp_ctrl    <= latch_sp;
3313
                                          --
3314
                                     st_ctrl      <= push_st;
3315
                                     return_state <= dual_op_read8_state;
3316
                                     next_state   <= extended_state;
3317
               end case;
3318
 
3319
                  when "1100" => -- accb immediate
3320
                              op_ctrl    <= latch_op;
3321
               acca_ctrl  <= latch_acca;
3322
                                        accb_ctrl  <= latch_accb;
3323
                                   ix_ctrl    <= latch_ix;
3324
               iy_ctrl    <= latch_iy;
3325
               up_ctrl    <= latch_up;
3326
                                   sp_ctrl    <= latch_sp;
3327
               iv_ctrl    <= latch_iv;
3328
                                        --
3329
               left_ctrl  <= pc_left;
3330
               right_ctrl <= one_right;
3331
               alu_ctrl   <= alu_add16;
3332
                                        cc_ctrl    <= latch_cc;
3333
                                        -- increment the pc
3334
               pc_ctrl    <= incr_pc;
3335
                                        case op_code(3 downto 0) is
3336
               when "0011" | -- addd #
3337
                                             "1100" | -- ldd #
3338
                                             "1110" => -- ldu #
3339
                                     st_ctrl    <= push_st;
3340
                                     return_state <= fetch_state;
3341
                                          next_state <= imm16_state;
3342
 
3343
                                        when others =>
3344
                                     st_ctrl    <= idle_st;
3345
                                     return_state <= fetch_state;
3346
                                     next_state <= fetch_state;
3347
 
3348
               end case;
3349
 
3350
 
3351
                  when "1101" => -- accb direct
3352
                              op_ctrl    <= latch_op;
3353
               acca_ctrl  <= latch_acca;
3354
                                        accb_ctrl  <= latch_accb;
3355
                                   ix_ctrl    <= latch_ix;
3356
               iy_ctrl    <= latch_iy;
3357
               up_ctrl    <= latch_up;
3358
                                   sp_ctrl    <= latch_sp;
3359
               iv_ctrl    <= latch_iv;
3360
                                        -- increment the pc
3361
               pc_ctrl    <= incr_pc;
3362
                                        --
3363
               left_ctrl  <= pc_left;
3364
               right_ctrl <= zero_right;
3365
               alu_ctrl   <= alu_nop;
3366
                                        cc_ctrl    <= latch_cc;
3367
                                        --
3368
                                        case op_code(3 downto 0) is
3369
               when "0011" | -- addd
3370
                                             "1100" | -- ldd
3371
                                             "1110" => -- ldu
3372
                                     st_ctrl      <= idle_st;
3373
                                     return_state <= fetch_state;
3374
                                     next_state   <= dual_op_read16_state;
3375
 
3376
                                        when "0111" =>  -- stab direct
3377
                                     st_ctrl      <= idle_st;
3378
                                     return_state <= fetch_state;
3379
                                     next_state   <= dual_op_write8_state;
3380
 
3381
                                        when "1101" =>  -- std direct
3382
                                     st_ctrl      <= idle_st;
3383
                                     return_state <= fetch_state;
3384
                                     next_state   <= dual_op_write16_state;
3385
 
3386
                                        when "1111" => -- stu direct
3387
                                     st_ctrl      <= idle_st;
3388
                                     return_state <= fetch_state;
3389
                                     next_state   <= dual_op_write16_state;
3390
 
3391
                                        when others =>
3392
                                     st_ctrl      <= idle_st;
3393
                                     return_state <= fetch_state;
3394
                                     next_state   <= dual_op_read8_state;
3395
               end case;
3396
 
3397
                  when "1110" => -- accb indexed
3398
                              op_ctrl    <= latch_op;
3399
               acca_ctrl  <= latch_acca;
3400
                                        accb_ctrl  <= latch_accb;
3401
                                   ix_ctrl    <= latch_ix;
3402
               iy_ctrl    <= latch_iy;
3403
               up_ctrl    <= latch_up;
3404
                                   sp_ctrl    <= latch_sp;
3405
               iv_ctrl    <= latch_iv;
3406
                                        -- increment the pc
3407
               pc_ctrl    <= incr_pc;
3408
                                        --
3409
               left_ctrl  <= pc_left;
3410
               right_ctrl <= zero_right;
3411
               alu_ctrl   <= alu_nop;
3412
                                        cc_ctrl    <= latch_cc;
3413
                                        --
3414
                                        case op_code(3 downto 0) is
3415
               when "0011" | -- addd
3416
                                             "1100" | -- ldd
3417
                                             "1110" => -- ldu
3418
                                     st_ctrl    <= push_st;
3419
                                     return_state <= dual_op_read16_state;
3420
                                     next_state <= indexed_state;
3421
 
3422
                                        when "0111" =>  -- stab indexed
3423
                                     st_ctrl      <= push_st;
3424
                                     return_state <= dual_op_write8_state;
3425
                                     next_state   <= indexed_state;
3426
 
3427
                                        when "1101" =>  -- std indexed
3428
                                     st_ctrl      <= push_st;
3429
                                     return_state <= dual_op_write16_state;
3430
                                     next_state   <= indexed_state;
3431
 
3432
                                        when "1111" => -- stu indexed
3433
                                     st_ctrl      <= push_st;
3434
                                     return_state <= dual_op_write16_state;
3435
                                     next_state   <= indexed_state;
3436
 
3437
                                        when others =>
3438
                                     st_ctrl      <= push_st;
3439
                                     return_state <= dual_op_read8_state;
3440
                                     next_state   <= indexed_state;
3441
               end case;
3442
 
3443
             when "1111" => -- accb extended
3444
                              op_ctrl    <= latch_op;
3445
               acca_ctrl  <= latch_acca;
3446
                                        accb_ctrl  <= latch_accb;
3447
                                   ix_ctrl    <= latch_ix;
3448
               iy_ctrl    <= latch_iy;
3449
               up_ctrl    <= latch_up;
3450
                                   sp_ctrl    <= latch_sp;
3451
               iv_ctrl    <= latch_iv;
3452
                                        -- increment the pc
3453
               pc_ctrl    <= incr_pc;
3454
                                        --
3455
               left_ctrl  <= pc_left;
3456
               right_ctrl <= zero_right;
3457
               alu_ctrl   <= alu_nop;
3458
                                        cc_ctrl    <= latch_cc;
3459
                                          --
3460
                                        case op_code(3 downto 0) is
3461
               when "0011" | -- addd
3462
                                             "1100" | -- ldd
3463
                                             "1110" => -- ldu
3464
                                     st_ctrl      <= push_st;
3465
                                     return_state <= dual_op_read16_state;
3466
                                     next_state   <= extended_state;
3467
 
3468
                                        when "0111" =>  -- stab extended
3469
                                     st_ctrl      <= push_st;
3470
                                     return_state <= dual_op_write8_state;
3471
                                     next_state   <= extended_state;
3472
 
3473
                                        when "1101" =>  -- std extended
3474
                                     st_ctrl      <= push_st;
3475
                                     return_state <= dual_op_write16_state;
3476
                                     next_state   <= extended_state;
3477
 
3478
                                        when "1111" => -- stu  extended
3479
                                     st_ctrl      <= push_st;
3480
                                     return_state <= dual_op_write16_state;
3481
                                     next_state   <= extended_state;
3482
 
3483
                                        when others =>
3484
                                     st_ctrl      <= push_st;
3485
                                     return_state <= dual_op_read8_state;
3486
                                     next_state   <= extended_state;
3487
               end case;
3488
 
3489
                  when others =>
3490
                                   null;
3491
--                            op_ctrl    <= latch_op;
3492
--               acca_ctrl  <= latch_acca;
3493
--                                      accb_ctrl  <= latch_accb;
3494
--                                 ix_ctrl    <= latch_ix;
3495
--               iy_ctrl    <= latch_iy;
3496
--               up_ctrl    <= latch_up;
3497
--                                 sp_ctrl    <= latch_sp;
3498
--               iv_ctrl    <= latch_iv;
3499
--                                      -- idle the ALU
3500
--               left_ctrl  <= pc_left;
3501
--               right_ctrl <= zero_right;
3502
--               alu_ctrl   <= alu_nop;
3503
--                                      cc_ctrl    <= latch_cc;
3504
--                                      -- idle the pc
3505
--               pc_ctrl    <= latch_pc;
3506
--                                      --
3507
--                                 st_ctrl      <= idle_st;
3508
--                                 return_state <= fetch_state;
3509
--                       next_state   <= fetch_state;
3510
             end case;
3511
 
3512
                         --
3513
                         -- Here to decode prefix 2 instruction
3514
                         -- and fetch next byte of intruction
3515
                         -- whether it be necessary or not
3516
                         --
3517
          when decode2_state =>
3518
                            op_ctrl    <= latch_op;
3519
             pre_ctrl   <= latch_pre;
3520
                                 -- fetch first byte of address or immediate data
3521
             ea_ctrl    <= fetch_first_ea;
3522
                                 md_ctrl    <= fetch_first_md;
3523
             addr_ctrl  <= fetch_ad;
3524
             dout_ctrl  <= md_lo_dout;
3525
                                 nmi_ctrl   <= latch_nmi;
3526
             dp_ctrl    <= latch_dp;
3527
                            case op_code(7 downto 4) is
3528
                                 --
3529
                                 -- lbcc -- long branch conditional
3530
                                 -- 6809 => branch 6 cycles, no branch 5 cycles
3531
                                 -- cpu09 => always 5 cycles
3532
                                 -- 1 pre=(pc) / pc=pc+1
3533
                                 -- 2 op=(pc) / pc=pc+1
3534
                                 -- 3 md_hi=sign(pc) / md_lo=(pc) / pc=pc+1
3535
             -- 4 md_hi=md_lo / md_lo=(pc) / pc=pc+1
3536
                                 -- 5 if cond pc=pc+md else pc=pc
3537
                                 --
3538
                  when "0010" =>
3539
                                        acca_ctrl  <= latch_acca;
3540
               accb_ctrl  <= latch_accb;
3541
               ix_ctrl    <= latch_ix;
3542
               iy_ctrl    <= latch_iy;
3543
               sp_ctrl    <= latch_sp;
3544
               up_ctrl    <= latch_up;
3545
               iv_ctrl    <= latch_iv;
3546
                                        -- increment the pc
3547
               left_ctrl  <= pc_left;
3548
               right_ctrl <= zero_right;
3549
               alu_ctrl   <= alu_nop;
3550
                                        cc_ctrl    <= latch_cc;
3551
               pc_ctrl    <= incr_pc;
3552
                                        --
3553
                                        st_ctrl      <= idle_st;
3554
               return_state <= fetch_state;
3555
                                        next_state   <= lbranch_state;
3556
 
3557
                                 --
3558
                                 -- Single byte stack operators
3559
                                 -- Do not advance PC
3560
                                 --
3561
                  when "0011" =>
3562
                                        acca_ctrl  <= latch_acca;
3563
               accb_ctrl  <= latch_accb;
3564
                                   ix_ctrl    <= latch_ix;
3565
                                   iy_ctrl    <= latch_iy;
3566
               up_ctrl    <= latch_up;
3567
               pc_ctrl    <= latch_pc;
3568
                    case op_code(3 downto 0) is
3569
                         when "1111" => -- swi 2
3570
                                           -- predecrement sp
3571
                            left_ctrl  <= sp_left;
3572
                            right_ctrl <= one_right;
3573
                                                alu_ctrl   <= alu_sub16;
3574
                                           cc_ctrl    <= latch_cc;
3575
                                                sp_ctrl    <= load_sp;
3576
                  iv_ctrl    <= swi2_iv;
3577
                                                --
3578
                                      st_ctrl      <= idle_st;
3579
                                      return_state <= fetch_state;
3580
                                                next_state   <= int_entire_state;
3581
 
3582
                         when others =>
3583
                            left_ctrl  <= sp_left;
3584
                            right_ctrl <= zero_right;
3585
                                                alu_ctrl   <= alu_nop;
3586
                                           cc_ctrl    <= latch_cc;
3587
                                                sp_ctrl    <= latch_sp;
3588
                  iv_ctrl    <= latch_iv;
3589
                                                --
3590
                                      st_ctrl      <= idle_st;
3591
                                      return_state <= fetch_state;
3592
                                                next_state   <= fetch_state;
3593
                         end case;
3594
 
3595
                  when "1000" => -- acca immediate
3596
               acca_ctrl  <= latch_acca;
3597
                                        accb_ctrl  <= latch_accb;
3598
                                   ix_ctrl    <= latch_ix;
3599
               iy_ctrl    <= latch_iy;
3600
               up_ctrl    <= latch_up;
3601
                                   sp_ctrl    <= latch_sp;
3602
               iv_ctrl    <= latch_iv;
3603
                                   -- Idle the ALU
3604
               left_ctrl  <= pc_left;
3605
               right_ctrl <= one_right;
3606
               alu_ctrl   <= alu_add16;
3607
                                        cc_ctrl    <= latch_cc;
3608
                                   -- increment the pc
3609
               pc_ctrl    <= incr_pc;
3610
                                        case op_code(3 downto 0) is
3611
               when "0011" | -- cmpd #
3612
                                             "1100" | -- cmpy #
3613
                                             "1110" => -- ldy #
3614
                                     st_ctrl      <= push_st;
3615
                                     return_state <= fetch_state;
3616
                                          next_state   <= imm16_state;
3617
 
3618
                                        when others =>
3619
                                     st_ctrl      <= idle_st;
3620
                                     return_state <= fetch_state;
3621
                                     next_state   <= fetch_state;
3622
 
3623
               end case;
3624
 
3625
                  when "1001" => -- acca direct
3626
               acca_ctrl  <= latch_acca;
3627
                                        accb_ctrl  <= latch_accb;
3628
                                   ix_ctrl    <= latch_ix;
3629
               iy_ctrl    <= latch_iy;
3630
               up_ctrl    <= latch_up;
3631
                                   sp_ctrl    <= latch_sp;
3632
               iv_ctrl    <= latch_iv;
3633
                                        -- idle the ALU
3634
               left_ctrl  <= pc_left;
3635
               right_ctrl <= zero_right;
3636
               alu_ctrl   <= alu_nop;
3637
                                        cc_ctrl    <= latch_cc;
3638
                                        -- increment the pc
3639
               pc_ctrl    <= incr_pc;
3640
                                        case op_code(3 downto 0) is
3641
               when "0011" | -- cmpd <
3642
                                             "1100" | -- cmpy <
3643
                                             "1110" => -- ldy <
3644
                                     st_ctrl      <= idle_st;
3645
                                     return_state <= fetch_state;
3646
                                          next_state   <= dual_op_read16_state;
3647
 
3648
                                        when "1111" => -- sty <
3649
                                     st_ctrl      <= idle_st;
3650
                                     return_state <= fetch_state;
3651
                                     next_state   <= dual_op_write16_state;
3652
 
3653
                                        when others =>
3654
                                     st_ctrl      <= idle_st;
3655
                                     return_state <= fetch_state;
3656
                                     next_state   <= fetch_state;
3657
 
3658
               end case;
3659
 
3660
                  when "1010" => -- acca indexed
3661
               acca_ctrl  <= latch_acca;
3662
                                        accb_ctrl  <= latch_accb;
3663
                                   ix_ctrl    <= latch_ix;
3664
               iy_ctrl    <= latch_iy;
3665
               up_ctrl    <= latch_up;
3666
                                   sp_ctrl    <= latch_sp;
3667
               iv_ctrl    <= latch_iv;
3668
                                        -- idle the ALU
3669
               left_ctrl  <= pc_left;
3670
               right_ctrl <= zero_right;
3671
               alu_ctrl   <= alu_nop;
3672
                                        cc_ctrl    <= latch_cc;
3673
                                        -- increment the pc
3674
               pc_ctrl    <= incr_pc;
3675
                                        case op_code(3 downto 0) is
3676
               when "0011" | -- cmpd ,ind
3677
                                             "1100" | -- cmpy ,ind
3678
                                             "1110" => -- ldy ,ind
3679
                                     st_ctrl      <= push_st;
3680
                                     return_state <= dual_op_read16_state;
3681
                                          next_state   <= indexed_state;
3682
 
3683
                                        when "1111" => -- sty ,ind
3684
                                     st_ctrl      <= push_st;
3685
                                     return_state <= dual_op_write16_state;
3686
                                     next_state   <= indexed_state;
3687
 
3688
                                        when others =>
3689
                                     st_ctrl      <= idle_st;
3690
                                     return_state <= fetch_state;
3691
                                     next_state   <= fetch_state;
3692
               end case;
3693
 
3694
             when "1011" => -- acca extended
3695
               acca_ctrl  <= latch_acca;
3696
                                        accb_ctrl  <= latch_accb;
3697
                                   ix_ctrl    <= latch_ix;
3698
               iy_ctrl    <= latch_iy;
3699
               up_ctrl    <= latch_up;
3700
                                   sp_ctrl    <= latch_sp;
3701
               iv_ctrl    <= latch_iv;
3702
                                        -- idle the ALU
3703
               left_ctrl  <= pc_left;
3704
               right_ctrl <= zero_right;
3705
               alu_ctrl   <= alu_nop;
3706
                                        cc_ctrl    <= latch_cc;
3707
                                        -- increment the pc
3708
               pc_ctrl    <= incr_pc;
3709
                                        case op_code(3 downto 0) is
3710
               when "0011" | -- cmpd <
3711
                                             "1100" | -- cmpy <
3712
                                             "1110" => -- ldy <
3713
                                     st_ctrl      <= push_st;
3714
                                     return_state <= dual_op_read16_state;
3715
                                          next_state   <= extended_state;
3716
 
3717
                                        when "1111" => -- sty >
3718
                                     st_ctrl      <= push_st;
3719
                                     return_state <= dual_op_write16_state;
3720
                                     next_state   <= extended_state;
3721
 
3722
                                        when others =>
3723
                                     st_ctrl      <= idle_st;
3724
                                     return_state <= fetch_state;
3725
                                     next_state   <= fetch_state;
3726
 
3727
               end case;
3728
 
3729
                  when "1100" => -- accb immediate
3730
               acca_ctrl  <= latch_acca;
3731
                                        accb_ctrl  <= latch_accb;
3732
                                   ix_ctrl    <= latch_ix;
3733
               iy_ctrl    <= latch_iy;
3734
               up_ctrl    <= latch_up;
3735
                                   sp_ctrl    <= latch_sp;
3736
               iv_ctrl    <= latch_iv;
3737
                                        -- idle the alu
3738
               left_ctrl  <= pc_left;
3739
               right_ctrl <= zero_right;
3740
               alu_ctrl   <= alu_nop;
3741
                                        cc_ctrl    <= latch_cc;
3742
                                        -- increment the pc
3743
               pc_ctrl    <= incr_pc;
3744
                                        case op_code(3 downto 0) is
3745
               when "0011" | -- undef #
3746
                                             "1100" | -- undef #
3747
                                             "1110" => -- lds #
3748
                                     st_ctrl      <= push_st;
3749
                                     return_state <= fetch_state;
3750
                                          next_state   <= imm16_state;
3751
 
3752
                                        when others =>
3753
                                     st_ctrl      <= idle_st;
3754
                                     return_state <= fetch_state;
3755
                                     next_state   <= fetch_state;
3756
 
3757
               end case;
3758
 
3759
                  when "1101" => -- accb direct
3760
               acca_ctrl  <= latch_acca;
3761
                                        accb_ctrl  <= latch_accb;
3762
                                   ix_ctrl    <= latch_ix;
3763
               iy_ctrl    <= latch_iy;
3764
               up_ctrl    <= latch_up;
3765
                                   sp_ctrl    <= latch_sp;
3766
               iv_ctrl    <= latch_iv;
3767
                                        -- idle the alu
3768
               left_ctrl  <= pc_left;
3769
               right_ctrl <= zero_right;
3770
               alu_ctrl   <= alu_nop;
3771
                                        cc_ctrl    <= latch_cc;
3772
                                        -- increment the pc
3773
               pc_ctrl    <= incr_pc;
3774
                                        case op_code(3 downto 0) is
3775
               when "0011" | -- undef <
3776
                                             "1100" | -- undef <
3777
                                             "1110" => -- lds <
3778
                                     st_ctrl      <= idle_st;
3779
                                     return_state <= fetch_state;
3780
                                          next_state   <= dual_op_read16_state;
3781
 
3782
                                        when "1111" => -- sts <
3783
                                     st_ctrl      <= idle_st;
3784
                                     return_state <= fetch_state;
3785
                                     next_state   <= dual_op_write16_state;
3786
 
3787
                                        when others =>
3788
                                     st_ctrl      <= idle_st;
3789
                                     return_state <= fetch_state;
3790
                                     next_state   <= fetch_state;
3791
 
3792
               end case;
3793
 
3794
                  when "1110" => -- accb indexed
3795
               acca_ctrl  <= latch_acca;
3796
                                        accb_ctrl  <= latch_accb;
3797
                                   ix_ctrl    <= latch_ix;
3798
               iy_ctrl    <= latch_iy;
3799
               up_ctrl    <= latch_up;
3800
                                   sp_ctrl    <= latch_sp;
3801
               iv_ctrl    <= latch_iv;
3802
                                        -- idle the alu
3803
               left_ctrl  <= pc_left;
3804
               right_ctrl <= zero_right;
3805
               alu_ctrl   <= alu_nop;
3806
                                        cc_ctrl    <= latch_cc;
3807
                                        -- increment the pc
3808
               pc_ctrl    <= incr_pc;
3809
                                        case op_code(3 downto 0) is
3810
               when "0011" | -- undef ,ind
3811
                                             "1100" | -- undef ,ind
3812
                                             "1110" => -- lds ,ind
3813
                                     st_ctrl      <= push_st;
3814
                                     return_state <= dual_op_read16_state;
3815
                                          next_state   <= indexed_state;
3816
 
3817
                                        when "1111" => -- sts ,ind
3818
                                     st_ctrl      <= push_st;
3819
                                     return_state <= dual_op_write16_state;
3820
                                     next_state   <= indexed_state;
3821
 
3822
                                        when others =>
3823
                                     st_ctrl      <= idle_st;
3824
                                     return_state <= fetch_state;
3825
                                     next_state   <= fetch_state;
3826
 
3827
               end case;
3828
 
3829
             when "1111" => -- accb extended
3830
               acca_ctrl  <= latch_acca;
3831
                                        accb_ctrl  <= latch_accb;
3832
                                   ix_ctrl    <= latch_ix;
3833
               iy_ctrl    <= latch_iy;
3834
               up_ctrl    <= latch_up;
3835
                                   sp_ctrl    <= latch_sp;
3836
               iv_ctrl    <= latch_iv;
3837
                                        -- idle the alu
3838
               left_ctrl  <= pc_left;
3839
               right_ctrl <= zero_right;
3840
               alu_ctrl   <= alu_nop;
3841
                                        cc_ctrl    <= latch_cc;
3842
                                        -- increment the pc
3843
               pc_ctrl    <= incr_pc;
3844
                                        case op_code(3 downto 0) is
3845
               when "0011" | -- undef >
3846
                                             "1100" | -- undef >
3847
                                             "1110" => -- lds >
3848
                                     st_ctrl      <= push_st;
3849
                                     return_state <= dual_op_read16_state;
3850
                                          next_state   <= extended_state;
3851
 
3852
                                        when "1111" => -- sts >
3853
                                     st_ctrl      <= push_st;
3854
                                     return_state <= dual_op_write16_state;
3855
                                     next_state   <= extended_state;
3856
 
3857
                                        when others =>
3858
                                     st_ctrl      <= idle_st;
3859
                                     return_state <= fetch_state;
3860
                                     next_state   <= fetch_state;
3861
 
3862
               end case;
3863
 
3864
                  when others =>
3865
               acca_ctrl  <= latch_acca;
3866
                                        accb_ctrl  <= latch_accb;
3867
                                   ix_ctrl    <= latch_ix;
3868
               iy_ctrl    <= latch_iy;
3869
               up_ctrl    <= latch_up;
3870
                                   sp_ctrl    <= latch_sp;
3871
               iv_ctrl    <= latch_iv;
3872
                                        -- idle the alu
3873
               left_ctrl  <= pc_left;
3874
               right_ctrl <= zero_right;
3875
               alu_ctrl   <= alu_nop;
3876
                                        cc_ctrl    <= latch_cc;
3877
                                        -- idle the pc
3878
               pc_ctrl    <= latch_pc;
3879
                                   st_ctrl      <= idle_st;
3880
                                   return_state <= fetch_state;
3881
                         next_state   <= fetch_state;
3882
             end case;
3883
                         --
3884
                         -- Here to decode instruction
3885
                         -- and fetch next byte of intruction
3886
                         -- whether it be necessary or not
3887
                         --
3888
          when decode3_state =>
3889
                            op_ctrl    <= latch_op;
3890
             pre_ctrl   <= latch_pre;
3891
             ea_ctrl    <= fetch_first_ea;
3892
                                 md_ctrl    <= fetch_first_md;
3893
             addr_ctrl  <= fetch_ad;
3894
             dout_ctrl  <= md_lo_dout;
3895
                                 nmi_ctrl   <= latch_nmi;
3896
             dp_ctrl    <= latch_dp;
3897
                            case op_code(7 downto 4) is
3898
                                 --
3899
                                 -- Single byte stack operators
3900
                                 -- Do not advance PC
3901
                                 --
3902
                  when "0011" =>
3903
                                        acca_ctrl  <= latch_acca;
3904
               accb_ctrl  <= latch_accb;
3905
                                   ix_ctrl    <= latch_ix;
3906
                                   iy_ctrl    <= latch_iy;
3907
               up_ctrl    <= latch_up;
3908
               pc_ctrl    <= latch_pc;
3909
                                        --
3910
                    case op_code(3 downto 0) is
3911
                         when "1111" => -- swi3
3912
                                           -- predecrement sp
3913
                            left_ctrl  <= sp_left;
3914
                            right_ctrl <= one_right;
3915
                                                alu_ctrl   <= alu_sub16;
3916
                                           cc_ctrl    <= latch_cc;
3917
                                                sp_ctrl    <= load_sp;
3918
                  iv_ctrl    <= swi3_iv;
3919
                                                --
3920
                                      st_ctrl      <= idle_st;
3921
                                      return_state <= fetch_state;
3922
                                                next_state   <= int_entire_state;
3923
                         when others =>
3924
                            left_ctrl  <= sp_left;
3925
                            right_ctrl <= zero_right;
3926
                                                alu_ctrl   <= alu_nop;
3927
                                           cc_ctrl    <= latch_cc;
3928
                                                sp_ctrl    <= latch_sp;
3929
                  iv_ctrl    <= latch_iv;
3930
                                                --
3931
                                      st_ctrl      <= idle_st;
3932
                                      return_state <= fetch_state;
3933
                                                next_state   <= fetch_state;
3934
                         end case;
3935
 
3936
                  when "1000" => -- acca immediate
3937
               acca_ctrl  <= latch_acca;
3938
                                        accb_ctrl  <= latch_accb;
3939
                                   ix_ctrl    <= latch_ix;
3940
               iy_ctrl    <= latch_iy;
3941
               up_ctrl    <= latch_up;
3942
                                   sp_ctrl    <= latch_sp;
3943
               iv_ctrl    <= latch_iv;
3944
                                   -- idle the alu
3945
               left_ctrl  <= pc_left;
3946
               right_ctrl <= zero_right;
3947
               alu_ctrl   <= alu_nop;
3948
                                        cc_ctrl    <= latch_cc;
3949
                                   -- increment the pc
3950
               pc_ctrl    <= incr_pc;
3951
                                        case op_code(3 downto 0) is
3952
               when "0011" | -- cmpu #
3953
                                             "1100" | -- cmps #
3954
                                             "1110" => -- undef #
3955
                                     st_ctrl      <= push_st;
3956
                                     return_state <= fetch_state;
3957
                                          next_state   <= imm16_state;
3958
                                        when others =>
3959
                                     st_ctrl      <= idle_st;
3960
                                     return_state <= fetch_state;
3961
                                     next_state   <= fetch_state;
3962
               end case;
3963
 
3964
                  when "1001" => -- acca direct
3965
               acca_ctrl  <= latch_acca;
3966
                                        accb_ctrl  <= latch_accb;
3967
                                   ix_ctrl    <= latch_ix;
3968
               iy_ctrl    <= latch_iy;
3969
               up_ctrl    <= latch_up;
3970
                                   sp_ctrl    <= latch_sp;
3971
               iv_ctrl    <= latch_iv;
3972
                                        -- idle the alu
3973
               left_ctrl  <= pc_left;
3974
               right_ctrl <= zero_right;
3975
               alu_ctrl   <= alu_nop;
3976
                                        cc_ctrl    <= latch_cc;
3977
                                        -- increment the pc
3978
               pc_ctrl    <= incr_pc;
3979
                                        case op_code(3 downto 0) is
3980
               when "0011" | -- cmpu <
3981
                                             "1100" | -- cmps <
3982
                                             "1110" => -- undef <
3983
                                     st_ctrl      <= idle_st;
3984
                                     return_state <= fetch_state;
3985
                                          next_state   <= dual_op_read16_state;
3986
 
3987
                                        when others =>
3988
                                     st_ctrl      <= idle_st;
3989
                                     return_state <= fetch_state;
3990
                                     next_state   <= fetch_state;
3991
 
3992
               end case;
3993
 
3994
                  when "1010" => -- acca indexed
3995
               acca_ctrl  <= latch_acca;
3996
                                        accb_ctrl  <= latch_accb;
3997
                                   ix_ctrl    <= latch_ix;
3998
               iy_ctrl    <= latch_iy;
3999
               up_ctrl    <= latch_up;
4000
                                   sp_ctrl    <= latch_sp;
4001
               iv_ctrl    <= latch_iv;
4002
                                        -- idle the alu
4003
               left_ctrl  <= pc_left;
4004
               right_ctrl <= zero_right;
4005
               alu_ctrl   <= alu_nop;
4006
                                        cc_ctrl    <= latch_cc;
4007
                                        -- increment the pc
4008
               pc_ctrl    <= incr_pc;
4009
                                        case op_code(3 downto 0) is
4010
               when "0011" | -- cmpu ,X
4011
                                             "1100" | -- cmps ,X
4012
                                             "1110" => -- undef ,X
4013
                                     st_ctrl      <= push_st;
4014
                                     return_state <= dual_op_read16_state;
4015
                                          next_state   <= indexed_state;
4016
 
4017
                                        when others =>
4018
                                     st_ctrl      <= idle_st;
4019
                                     return_state <= fetch_state;
4020
                                     next_state   <= fetch_state;
4021
 
4022
               end case;
4023
 
4024
             when "1011" => -- acca extended
4025
               acca_ctrl  <= latch_acca;
4026
                                        accb_ctrl  <= latch_accb;
4027
                                   ix_ctrl    <= latch_ix;
4028
               iy_ctrl    <= latch_iy;
4029
               up_ctrl    <= latch_up;
4030
                                   sp_ctrl    <= latch_sp;
4031
               iv_ctrl    <= latch_iv;
4032
                                        -- idle the alu
4033
               left_ctrl  <= pc_left;
4034
               right_ctrl <= zero_right;
4035
               alu_ctrl   <= alu_nop;
4036
                                        cc_ctrl    <= latch_cc;
4037
                                        -- increment the pc
4038
               pc_ctrl    <= incr_pc;
4039
                                        case op_code(3 downto 0) is
4040
               when "0011" | -- cmpu >
4041
                                             "1100" | -- cmps >
4042
                                             "1110" => -- undef >
4043
                                     st_ctrl      <= push_st;
4044
                                     return_state <= dual_op_read16_state;
4045
                                          next_state   <= extended_state;
4046
                                        when others =>
4047
                                     st_ctrl      <= idle_st;
4048
                                     return_state <= fetch_state;
4049
                                     next_state   <= fetch_state;
4050
               end case;
4051
 
4052
                  when others =>
4053
               acca_ctrl  <= latch_acca;
4054
                                        accb_ctrl  <= latch_accb;
4055
                                   ix_ctrl    <= latch_ix;
4056
               iy_ctrl    <= latch_iy;
4057
               up_ctrl    <= latch_up;
4058
                                   sp_ctrl    <= latch_sp;
4059
               iv_ctrl    <= latch_iv;
4060
                                        -- idle the alu
4061
               left_ctrl  <= pc_left;
4062
               right_ctrl <= zero_right;
4063
               alu_ctrl   <= alu_nop;
4064
                                        cc_ctrl    <= latch_cc;
4065
                                        -- idle the pc
4066
               pc_ctrl    <= latch_pc;
4067
                                   st_ctrl      <= idle_st;
4068
                                   return_state <= fetch_state;
4069
                         next_state   <= fetch_state;
4070
             end case;
4071
 
4072
           --
4073
                          -- here if ea holds low byte
4074
                          -- Direct
4075
                          -- Extended
4076
                          -- Indexed
4077
                          -- read memory location
4078
                          --
4079
                          when single_op_read_state =>
4080
                              op_ctrl    <= latch_op;
4081
               pre_ctrl   <= latch_pre;
4082
               acca_ctrl  <= latch_acca;
4083
               accb_ctrl  <= latch_accb;
4084
               ix_ctrl    <= latch_ix;
4085
               iy_ctrl    <= latch_iy;
4086
               up_ctrl    <= latch_up;
4087
               sp_ctrl    <= latch_sp;
4088
               pc_ctrl    <= latch_pc;
4089
               iv_ctrl    <= latch_iv;
4090
               dp_ctrl    <= latch_dp;
4091
                                   nmi_ctrl   <= latch_nmi;
4092
                                        -- idle ALU
4093
                                        left_ctrl  <= ea_left;
4094
                                        right_ctrl <= zero_right;
4095
                                        alu_ctrl   <= alu_nop;
4096
               cc_ctrl    <= latch_cc;
4097
                                        ea_ctrl    <= latch_ea;
4098
                                        -- read memory into md
4099
                                   md_ctrl    <= fetch_first_md;
4100
               addr_ctrl  <= read_ad;
4101
                                        dout_ctrl  <= md_lo_dout;
4102
                                        --
4103
                                        st_ctrl    <= idle_st;
4104
                                        return_state <= fetch_state;
4105
                                        next_state <= single_op_exec_state;
4106
 
4107
                when single_op_exec_state =>
4108
                              op_ctrl    <= latch_op;
4109
               pre_ctrl   <= latch_pre;
4110
               acca_ctrl  <= latch_acca;
4111
               accb_ctrl  <= latch_accb;
4112
               ix_ctrl    <= latch_ix;
4113
               iy_ctrl    <= latch_iy;
4114
               up_ctrl    <= latch_up;
4115
               sp_ctrl    <= latch_sp;
4116
               dp_ctrl    <= latch_dp;
4117
                                   nmi_ctrl   <= latch_nmi;
4118
               iv_ctrl    <= latch_iv;
4119
               ea_ctrl    <= latch_ea;
4120
                                          -- idle the bus
4121
               addr_ctrl  <= idle_ad;
4122
               dout_ctrl  <= md_lo_dout;
4123
                                        st_ctrl    <= idle_st;
4124
                                        return_state <= fetch_state;
4125
                    case op_code(3 downto 0) is
4126
                         when "0000" => -- neg
4127
                   left_ctrl  <= md_left;
4128
                                            right_ctrl <= zero_right;
4129
                                            alu_ctrl   <= alu_neg;
4130
                                            cc_ctrl    <= load_cc;
4131
                                       md_ctrl    <= load_md;
4132
                   pc_ctrl    <= latch_pc;
4133
                                       next_state <= single_op_write_state;
4134
                    when "0011" => -- com
4135
                   left_ctrl  <= md_left;
4136
                             right_ctrl <= zero_right;
4137
                                            alu_ctrl   <= alu_com;
4138
                                            cc_ctrl    <= load_cc;
4139
                                       md_ctrl    <= load_md;
4140
                   pc_ctrl    <= latch_pc;
4141
                                       next_state <= single_op_write_state;
4142
                         when "0100" => -- lsr
4143
                   left_ctrl  <= md_left;
4144
                                                 right_ctrl <= zero_right;
4145
                                            alu_ctrl   <= alu_lsr8;
4146
                                            cc_ctrl    <= load_cc;
4147
                                       md_ctrl    <= load_md;
4148
                   pc_ctrl    <= latch_pc;
4149
                                       next_state <= single_op_write_state;
4150
                         when "0110" => -- ror
4151
                   left_ctrl  <= md_left;
4152
                                                 right_ctrl <= zero_right;
4153
                                            alu_ctrl   <= alu_ror8;
4154
                                            cc_ctrl    <= load_cc;
4155
                                       md_ctrl    <= load_md;
4156
                   pc_ctrl    <= latch_pc;
4157
                                       next_state <= single_op_write_state;
4158
                         when "0111" => -- asr
4159
                   left_ctrl  <= md_left;
4160
                                                 right_ctrl <= zero_right;
4161
                                            alu_ctrl   <= alu_asr8;
4162
                                            cc_ctrl    <= load_cc;
4163
                                       md_ctrl    <= load_md;
4164
                   pc_ctrl    <= latch_pc;
4165
                                       next_state <= single_op_write_state;
4166
                         when "1000" => -- asl
4167
                   left_ctrl  <= md_left;
4168
                                                 right_ctrl <= zero_right;
4169
                                            alu_ctrl   <= alu_asl8;
4170
                                            cc_ctrl    <= load_cc;
4171
                                       md_ctrl    <= load_md;
4172
                   pc_ctrl    <= latch_pc;
4173
                                       next_state <= single_op_write_state;
4174
                         when "1001" => -- rol
4175
                   left_ctrl  <= md_left;
4176
                                                 right_ctrl <= zero_right;
4177
                                            alu_ctrl   <= alu_rol8;
4178
                                            cc_ctrl    <= load_cc;
4179
                                       md_ctrl    <= load_md;
4180
                   pc_ctrl    <= latch_pc;
4181
                                       next_state <= single_op_write_state;
4182
                         when "1010" => -- dec
4183
                   left_ctrl  <= md_left;
4184
                             right_ctrl <= one_right;
4185
                                            alu_ctrl   <= alu_dec;
4186
                                            cc_ctrl    <= load_cc;
4187
                                       md_ctrl    <= load_md;
4188
                   pc_ctrl    <= latch_pc;
4189
                                       next_state <= single_op_write_state;
4190
                         when "1011" => -- undefined
4191
                   left_ctrl  <= md_left;
4192
                                                 right_ctrl <= zero_right;
4193
                                            alu_ctrl   <= alu_nop;
4194
                                            cc_ctrl    <= latch_cc;
4195
                                       md_ctrl    <= latch_md;
4196
                   pc_ctrl    <= latch_pc;
4197
                                       next_state <= fetch_state;
4198
                         when "1100" => -- inc
4199
                   left_ctrl  <= md_left;
4200
                             right_ctrl <= one_right;
4201
                                            alu_ctrl   <= alu_inc;
4202
                                            cc_ctrl    <= load_cc;
4203
                                       md_ctrl    <= load_md;
4204
                   pc_ctrl    <= latch_pc;
4205
                                       next_state <= single_op_write_state;
4206
                         when "1101" => -- tst
4207
                   left_ctrl  <= md_left;
4208
                             right_ctrl <= zero_right;
4209
                                            alu_ctrl   <= alu_st8;
4210
                                            cc_ctrl    <= load_cc;
4211
                                       md_ctrl    <= latch_md;
4212
                   pc_ctrl    <= latch_pc;
4213
                                       next_state <= fetch_state;
4214
                         when "1110" => -- jmp
4215
                   left_ctrl  <= md_left;
4216
                                                 right_ctrl <= zero_right;
4217
                                            alu_ctrl   <= alu_ld16;
4218
                                            cc_ctrl    <= latch_cc;
4219
                                       md_ctrl    <= latch_md;
4220
                   pc_ctrl    <= load_pc;
4221
                                       next_state <= fetch_state;
4222
                         when "1111" => -- clr
4223
                   left_ctrl  <= md_left;
4224
                                                 right_ctrl <= zero_right;
4225
                                            alu_ctrl   <= alu_clr;
4226
                                            cc_ctrl    <= load_cc;
4227
                                       md_ctrl    <= load_md;
4228
                   pc_ctrl    <= latch_pc;
4229
                                       next_state <= single_op_write_state;
4230
                         when others =>
4231
                   left_ctrl  <= md_left;
4232
                                                 right_ctrl <= zero_right;
4233
                                            alu_ctrl   <= alu_nop;
4234
                                            cc_ctrl    <= latch_cc;
4235
                                       md_ctrl    <= latch_md;
4236
                   pc_ctrl    <= latch_pc;
4237
                                       next_state <= fetch_state;
4238
                         end case;
4239
           --
4240
                          -- single operand 8 bit write
4241
                          -- Write low 8 bits of ALU output
4242
                          -- EA holds address
4243
                          -- MD holds data
4244
                          --
4245
                          when single_op_write_state =>
4246
                            op_ctrl    <= latch_op;
4247
             pre_ctrl   <= latch_pre;
4248
             acca_ctrl  <= latch_acca;
4249
             accb_ctrl  <= latch_accb;
4250
             ix_ctrl    <= latch_ix;
4251
             iy_ctrl    <= latch_iy;
4252
             up_ctrl    <= latch_up;
4253
             sp_ctrl    <= latch_sp;
4254
             pc_ctrl    <= latch_pc;
4255
             md_ctrl    <= latch_md;
4256
             iv_ctrl    <= latch_iv;
4257
             dp_ctrl    <= latch_dp;
4258
                                 nmi_ctrl   <= latch_nmi;
4259
             ea_ctrl    <= latch_ea;
4260
                                 -- idle the ALU
4261
             left_ctrl  <= acca_left;
4262
             right_ctrl <= zero_right;
4263
             alu_ctrl   <= alu_nop;
4264
             cc_ctrl    <= latch_cc;
4265
                                 -- write ALU low byte output
4266
             addr_ctrl  <= write_ad;
4267
             dout_ctrl  <= md_lo_dout;
4268
                                 --
4269
                            st_ctrl      <= idle_st;
4270
                            return_state <= fetch_state;
4271
                                 next_state <= fetch_state;
4272
 
4273
           --
4274
                          -- here if ea holds address of low byte
4275
                          -- read memory location
4276
                          --
4277
                          when dual_op_read8_state =>
4278
                              op_ctrl    <= latch_op;
4279
               pre_ctrl   <= latch_pre;
4280
               acca_ctrl  <= latch_acca;
4281
               accb_ctrl  <= latch_accb;
4282
               ix_ctrl    <= latch_ix;
4283
               iy_ctrl    <= latch_iy;
4284
               up_ctrl    <= latch_up;
4285
               sp_ctrl    <= latch_sp;
4286
               pc_ctrl    <= latch_pc;
4287
               iv_ctrl    <= latch_iv;
4288
               dp_ctrl    <= latch_dp;
4289
                                   nmi_ctrl   <= latch_nmi;
4290
                                        left_ctrl  <= ea_left;
4291
                                        -- Leave the ea alone
4292
                                        right_ctrl <= zero_right;
4293
                                        alu_ctrl   <= alu_nop;
4294
               cc_ctrl    <= latch_cc;
4295
                                        ea_ctrl    <= latch_ea;
4296
                                   -- read first data byte from ea
4297
                                   md_ctrl    <= fetch_first_md;
4298
               addr_ctrl  <= read_ad;
4299
                                        dout_ctrl  <= md_lo_dout;
4300
                                        --
4301
                                        st_ctrl      <= idle_st;
4302
                                        return_state <= fetch_state;
4303
                                        next_state   <= fetch_state;
4304
 
4305
                                --
4306
                                -- Here to read a 16 bit value into MD
4307
                                -- pointed to by the EA register
4308
                                -- The first byte is read
4309
                                -- and the EA is incremented
4310
                                --
4311
                           when dual_op_read16_state =>
4312
                              op_ctrl    <= latch_op;
4313
               pre_ctrl   <= latch_pre;
4314
               acca_ctrl  <= latch_acca;
4315
               accb_ctrl  <= latch_accb;
4316
               cc_ctrl    <= latch_cc;
4317
               dp_ctrl    <= latch_dp;
4318
               ix_ctrl    <= latch_ix;
4319
               iy_ctrl    <= latch_iy;
4320
               up_ctrl    <= latch_up;
4321
               sp_ctrl    <= latch_sp;
4322
               pc_ctrl    <= latch_pc;
4323
               iv_ctrl    <= latch_iv;
4324
                                   nmi_ctrl   <= latch_nmi;
4325
                                        -- increment the effective address
4326
               left_ctrl  <= ea_left;
4327
               right_ctrl <= one_right;
4328
               alu_ctrl   <= alu_add16;
4329
               ea_ctrl    <= load_ea;
4330
                                        -- read the low byte of the 16 bit data
4331
                                   md_ctrl    <= fetch_first_md;
4332
               addr_ctrl  <= read_ad;
4333
               dout_ctrl  <= md_lo_dout;
4334
                                        --
4335
                                        st_ctrl      <= idle_st;
4336
                                        return_state <= fetch_state;
4337
                                        next_state   <= dual_op_read16_2_state;
4338
 
4339
                                --
4340
                                -- here to read the second byte
4341
                           -- pointed to by EA into MD
4342
                                --
4343
                           when dual_op_read16_2_state =>
4344
                              op_ctrl    <= latch_op;
4345
               pre_ctrl   <= latch_pre;
4346
               acca_ctrl  <= latch_acca;
4347
               accb_ctrl  <= latch_accb;
4348
               cc_ctrl    <= latch_cc;
4349
               dp_ctrl    <= latch_dp;
4350
               ix_ctrl    <= latch_ix;
4351
               iy_ctrl    <= latch_iy;
4352
               up_ctrl    <= latch_up;
4353
               sp_ctrl    <= latch_sp;
4354
               pc_ctrl    <= latch_pc;
4355
               iv_ctrl    <= latch_iv;
4356
                                   nmi_ctrl   <= latch_nmi;
4357
                                        -- idle the effective address
4358
               left_ctrl  <= ea_left;
4359
               right_ctrl <= one_right;
4360
               alu_ctrl   <= alu_nop;
4361
               ea_ctrl    <= latch_ea;
4362
                                        -- read the low byte of the 16 bit data
4363
                                   md_ctrl    <= fetch_next_md;
4364
               addr_ctrl  <= read_ad;
4365
               dout_ctrl  <= md_lo_dout;
4366
                                        --
4367
                                        st_ctrl      <= idle_st;
4368
                                        return_state <= fetch_state;
4369
                                        next_state   <= fetch_state;
4370
 
4371
           --
4372
                          -- 16 bit Write state
4373
                          -- EA hold address of memory to write to
4374
                          -- Advance the effective address in ALU
4375
                          -- decode op_code to determine which
4376
                          -- register to write
4377
                          --
4378
                          when dual_op_write16_state =>
4379
                            op_ctrl    <= latch_op;
4380
             pre_ctrl   <= latch_pre;
4381
             acca_ctrl  <= latch_acca;
4382
             accb_ctrl  <= latch_accb;
4383
             ix_ctrl    <= latch_ix;
4384
             iy_ctrl    <= latch_iy;
4385
             up_ctrl    <= latch_up;
4386
             sp_ctrl    <= latch_sp;
4387
             pc_ctrl    <= latch_pc;
4388
             md_ctrl    <= latch_md;
4389
             iv_ctrl    <= latch_iv;
4390
             dp_ctrl    <= latch_dp;
4391
                                 nmi_ctrl   <= latch_nmi;
4392
                                 -- increment the effective address
4393
                                 left_ctrl  <= ea_left;
4394
                                 right_ctrl <= one_right;
4395
                                 alu_ctrl   <= alu_add16;
4396
             cc_ctrl    <= latch_cc;
4397
                            ea_ctrl    <= load_ea;
4398
                                 -- write the ALU hi byte at ea
4399
             addr_ctrl  <= write_ad;
4400
                                 if op_code(6) = '0' then
4401
                                   case op_code(3 downto 0) is
4402
                                        when "1111" => -- stx / sty
4403
                                          case pre_code is
4404
                                          when "00010000" => -- page 2 -- sty
4405
                        dout_ctrl  <= iy_hi_dout;
4406
                                     when others =>     -- page 1 -- stx
4407
                   dout_ctrl  <= ix_hi_dout;
4408
                                          end case;
4409
                                        when others =>
4410
                 dout_ctrl  <= md_hi_dout;
4411
                                        end case;
4412
                                 else
4413
                                   case op_code(3 downto 0) is
4414
                                        when "1101" => -- std
4415
                 dout_ctrl  <= acca_dout; -- acca is high byte of ACCD
4416
                                        when "1111" => -- stu / sts
4417
                                          case pre_code is
4418
                                          when "00010000" => -- page 2 -- sts
4419
                        dout_ctrl  <= sp_hi_dout;
4420
                                          when others =>     -- page 1 -- stu
4421
                        dout_ctrl  <= up_hi_dout;
4422
                                          end case;
4423
                                        when others =>
4424
                 dout_ctrl  <= md_hi_dout;
4425
                                        end case;
4426
                                 end if;
4427
                            st_ctrl      <= idle_st;
4428
                            return_state <= fetch_state;
4429
                                 next_state   <= dual_op_write8_state;
4430
 
4431
           --
4432
                          -- Dual operand 8 bit write
4433
           -- Write 8 bit accumulator
4434
                          -- or low byte of 16 bit register
4435
                          -- EA holds address
4436
                          -- decode opcode to determine
4437
                          -- which register to apply to the bus
4438
                          -- Also set the condition codes here
4439
                          --
4440
                          when dual_op_write8_state =>
4441
                            op_ctrl    <= latch_op;
4442
             pre_ctrl   <= latch_pre;
4443
             acca_ctrl  <= latch_acca;
4444
             accb_ctrl  <= latch_accb;
4445
             ix_ctrl    <= latch_ix;
4446
             iy_ctrl    <= latch_iy;
4447
             up_ctrl    <= latch_up;
4448
             sp_ctrl    <= latch_sp;
4449
             pc_ctrl    <= latch_pc;
4450
             iv_ctrl    <= latch_iv;
4451
             dp_ctrl    <= latch_dp;
4452
                                 nmi_ctrl   <= latch_nmi;
4453
             md_ctrl    <= latch_md;
4454
                                 -- idle ALU
4455
             left_ctrl  <= ea_left;
4456
             right_ctrl <= zero_right;
4457
             alu_ctrl   <= alu_nop;
4458
             cc_ctrl    <= latch_cc;
4459
             ea_ctrl    <= latch_ea;
4460
                                 --
4461
                                 if op_code(6) = '0' then -- '0' = acca line
4462
                                   case op_code(3 downto 0) is
4463
                                        when "0111" => -- sta
4464
                 dout_ctrl  <= acca_dout;
4465
                                        when "1111" => -- stx / sty
4466
                                          case pre_code is
4467
                                          when "00010000" => -- page 2 -- sty
4468
                        dout_ctrl  <= iy_lo_dout;
4469
                                     when others =>     -- page 1 -- stx
4470
                   dout_ctrl  <= ix_lo_dout;
4471
                                          end case;
4472
                                        when others =>
4473
                 dout_ctrl  <= md_lo_dout;
4474
                                        end case;
4475
                                 else                    -- '1' = accb line
4476
                                   case op_code(3 downto 0) is
4477
                                        when "0111" => -- stb
4478
                 dout_ctrl  <= accb_dout;
4479
                                        when "1101" => -- std
4480
                 dout_ctrl  <= accb_dout; -- accb is low byte of accd
4481
                                        when "1111" => -- stu / sts
4482
                                          case pre_code is
4483
                                          when "00010000" => -- page 2 -- sts
4484
                        dout_ctrl  <= sp_lo_dout;
4485
                                          when others =>     -- page 1 -- stu
4486
                        dout_ctrl  <= up_lo_dout;
4487
                                          end case;
4488
                                        when others =>
4489
                 dout_ctrl  <= md_lo_dout;
4490
                                        end case;
4491
                                 end if;
4492
                                 -- write ALU low byte output
4493
             addr_ctrl    <= write_ad;
4494
                                 --
4495
                            st_ctrl      <= idle_st;
4496
                            return_state <= fetch_state;
4497
                                 next_state   <= fetch_state;
4498
 
4499
                          --
4500
                          -- 16 bit immediate addressing mode
4501
                          --
4502
                          when imm16_state =>
4503
                              op_ctrl    <= latch_op;
4504
               pre_ctrl   <= latch_pre;
4505
               acca_ctrl  <= latch_acca;
4506
               accb_ctrl  <= latch_accb;
4507
               cc_ctrl    <= latch_cc;
4508
               dp_ctrl    <= latch_dp;
4509
                                        --
4510
               ix_ctrl    <= latch_ix;
4511
               iy_ctrl    <= latch_iy;
4512
               up_ctrl    <= latch_up;
4513
               sp_ctrl    <= latch_sp;
4514
                                        --
4515
               iv_ctrl    <= latch_iv;
4516
                                   nmi_ctrl   <= latch_nmi;
4517
               ea_ctrl    <= latch_ea;
4518
                                   -- increment pc
4519
               left_ctrl  <= pc_left;
4520
               right_ctrl <= zero_right;
4521
               alu_ctrl   <= alu_nop;
4522
               pc_ctrl    <= incr_pc;
4523
                                   -- fetch next immediate byte
4524
                              md_ctrl    <= fetch_next_md;
4525
               addr_ctrl  <= fetch_ad;
4526
               dout_ctrl  <= md_lo_dout;
4527
                                   -- return to caller
4528
                              st_ctrl      <= pull_st;
4529
                              return_state <= fetch_state;
4530
                                   next_state   <= saved_state;
4531
 
4532
           --
4533
                          -- md & ea holds 8 bit index offset
4534
                          -- calculate the effective memory address
4535
                          -- using the alu
4536
                          --
4537
           when indexed_state =>
4538
                            op_ctrl    <= latch_op;
4539
             pre_ctrl   <= latch_pre;
4540
             acca_ctrl  <= latch_acca;
4541
             accb_ctrl  <= latch_accb;
4542
             iv_ctrl    <= latch_iv;
4543
             dp_ctrl    <= latch_dp;
4544
                                 nmi_ctrl   <= latch_nmi;
4545
             dout_ctrl  <= md_lo_dout;
4546
                                 --
4547
                                 -- decode indexing mode
4548
                                 --
4549
                                 if md(7) = '0' then
4550
               ix_ctrl    <= latch_ix;
4551
               iy_ctrl    <= latch_iy;
4552
               up_ctrl    <= latch_up;
4553
               sp_ctrl    <= latch_sp;
4554
                                   case md(6 downto 5) is
4555
                                        when "00" =>
4556
                                left_ctrl  <= ix_left;
4557
                                        when "01" =>
4558
                                left_ctrl  <= iy_left;
4559
                                        when "10" =>
4560
                                left_ctrl  <= up_left;
4561
                                        when others =>
4562
                                        -- when "11" =>
4563
                                left_ctrl  <= sp_left;
4564
                                        end case;
4565
                                   right_ctrl <= md_sign5_right;
4566
                                   alu_ctrl   <= alu_add16;
4567
               cc_ctrl    <= latch_cc;
4568
               ea_ctrl    <= load_ea;
4569
                                        --
4570
               md_ctrl    <= latch_md;
4571
               addr_ctrl  <= idle_ad;
4572
               pc_ctrl    <= latch_pc;
4573
                                        --
4574
                                        st_ctrl      <= pull_st;
4575
                                        return_state <= fetch_state;
4576
                                        next_state   <= saved_state;
4577
 
4578
                                 else
4579
                                   case md(3 downto 0) is
4580
                                        when "0000" =>     -- ,R+
4581
                 ix_ctrl    <= latch_ix;
4582
                 iy_ctrl    <= latch_iy;
4583
                 up_ctrl    <= latch_up;
4584
                 sp_ctrl    <= latch_sp;
4585
                                     case md(6 downto 5) is
4586
                                          when "00" =>
4587
                                  left_ctrl  <= ix_left;
4588
                                          when "01" =>
4589
                                  left_ctrl  <= iy_left;
4590
                                          when "10" =>
4591
                                  left_ctrl  <= up_left;
4592
                                          when others =>
4593
                                  left_ctrl  <= sp_left;
4594
                                          end case;
4595
                                          --
4596
                                     right_ctrl <= zero_right;
4597
                                     alu_ctrl   <= alu_st16;
4598
                 cc_ctrl    <= latch_cc;
4599
                 ea_ctrl    <= load_ea;
4600
                                          --
4601
                 md_ctrl    <= latch_md;
4602
                 addr_ctrl  <= idle_ad;
4603
                 pc_ctrl    <= latch_pc;
4604
                                          --
4605
                                          st_ctrl      <= idle_st;
4606
                                          return_state <= fetch_state;
4607
                 next_state   <= postincr1_state;
4608
 
4609
                                        when "0001" =>     -- ,R++
4610
                 ix_ctrl    <= latch_ix;
4611
                 iy_ctrl    <= latch_iy;
4612
                 up_ctrl    <= latch_up;
4613
                 sp_ctrl    <= latch_sp;
4614
                                     case md(6 downto 5) is
4615
                                          when "00" =>
4616
                                  left_ctrl  <= ix_left;
4617
                                          when "01" =>
4618
                                  left_ctrl  <= iy_left;
4619
                                          when "10" =>
4620
                                  left_ctrl  <= up_left;
4621
                                          when others =>
4622
                                          -- when "11" =>
4623
                                  left_ctrl  <= sp_left;
4624
                                          end case;
4625
                                     right_ctrl <= zero_right;
4626
                                     alu_ctrl   <= alu_st16;
4627
                 cc_ctrl    <= latch_cc;
4628
                 ea_ctrl    <= load_ea;
4629
                                          --
4630
                 md_ctrl    <= latch_md;
4631
                 addr_ctrl  <= idle_ad;
4632
                 pc_ctrl    <= latch_pc;
4633
                                          --
4634
                                          st_ctrl      <= idle_st;
4635
                                          return_state <= fetch_state;
4636
                 next_state   <= postincr2_state;
4637
 
4638
                                        when "0010" =>     -- ,-R
4639
                                     case md(6 downto 5) is
4640
                                          when "00" =>
4641
                                  left_ctrl  <= ix_left;
4642
                   ix_ctrl    <= load_ix;
4643
                   iy_ctrl    <= latch_iy;
4644
                   up_ctrl    <= latch_up;
4645
                   sp_ctrl    <= latch_sp;
4646
                                          when "01" =>
4647
                                  left_ctrl  <= iy_left;
4648
                   ix_ctrl    <= latch_ix;
4649
                   iy_ctrl    <= load_iy;
4650
                   up_ctrl    <= latch_up;
4651
                   sp_ctrl    <= latch_sp;
4652
                                          when "10" =>
4653
                                  left_ctrl  <= up_left;
4654
                   ix_ctrl    <= latch_ix;
4655
                   iy_ctrl    <= latch_iy;
4656
                   up_ctrl    <= load_up;
4657
                   sp_ctrl    <= latch_sp;
4658
                                          when others =>
4659
                                          -- when "11" =>
4660
                                  left_ctrl  <= sp_left;
4661
                   ix_ctrl    <= latch_ix;
4662
                   iy_ctrl    <= latch_iy;
4663
                   up_ctrl    <= latch_up;
4664
                   sp_ctrl    <= load_sp;
4665
                                          end case;
4666
                                     right_ctrl <= one_right;
4667
                                     alu_ctrl   <= alu_sub16;
4668
                 cc_ctrl    <= latch_cc;
4669
                 ea_ctrl    <= load_ea;
4670
                                          --
4671
                 md_ctrl    <= latch_md;
4672
                 addr_ctrl  <= idle_ad;
4673
                 pc_ctrl    <= latch_pc;
4674
                                          --
4675
                                          st_ctrl      <= pull_st;
4676
                                          return_state <= fetch_state;
4677
                                          next_state   <= saved_state;
4678
 
4679
                                        when "0011" =>     -- ,--R
4680
                                     case md(6 downto 5) is
4681
                                          when "00" =>
4682
                                  left_ctrl  <= ix_left;
4683
                   ix_ctrl    <= load_ix;
4684
                   iy_ctrl    <= latch_iy;
4685
                   up_ctrl    <= latch_up;
4686
                   sp_ctrl    <= latch_sp;
4687
                                          when "01" =>
4688
                                  left_ctrl  <= iy_left;
4689
                   ix_ctrl    <= latch_ix;
4690
                   iy_ctrl    <= load_iy;
4691
                   up_ctrl    <= latch_up;
4692
                   sp_ctrl    <= latch_sp;
4693
                                          when "10" =>
4694
                                  left_ctrl  <= up_left;
4695
                   ix_ctrl    <= latch_ix;
4696
                   iy_ctrl    <= latch_iy;
4697
                   up_ctrl    <= load_up;
4698
                   sp_ctrl    <= latch_sp;
4699
                                          when others =>
4700
                                          -- when "11" =>
4701
                                  left_ctrl  <= sp_left;
4702
                   ix_ctrl    <= latch_ix;
4703
                   iy_ctrl    <= latch_iy;
4704
                   up_ctrl    <= latch_up;
4705
                   sp_ctrl    <= load_sp;
4706
                                          end case;
4707
                                     right_ctrl <= two_right;
4708
                                     alu_ctrl   <= alu_sub16;
4709
                 cc_ctrl    <= latch_cc;
4710
                 ea_ctrl    <= load_ea;
4711
                                          --
4712
                 md_ctrl    <= latch_md;
4713
                 addr_ctrl  <= idle_ad;
4714
                 pc_ctrl    <= latch_pc;
4715
                                          --
4716
                                          if md(4) = '0' then
4717
                                            st_ctrl      <= pull_st;
4718
                                            return_state <= fetch_state;
4719
                                            next_state   <= saved_state;
4720
                                          else
4721
                                            st_ctrl      <= idle_st;
4722
                                            return_state <= fetch_state;
4723
                                            next_state   <= indirect_state;
4724
                                          end if;
4725
 
4726
                                        when "0100" =>     -- ,R (zero offset)
4727
                 ix_ctrl    <= latch_ix;
4728
                 iy_ctrl    <= latch_iy;
4729
                 up_ctrl    <= latch_up;
4730
                 sp_ctrl    <= latch_sp;
4731
                                     case md(6 downto 5) is
4732
                                          when "00" =>
4733
                                  left_ctrl  <= ix_left;
4734
                                          when "01" =>
4735
                                  left_ctrl  <= iy_left;
4736
                                          when "10" =>
4737
                                  left_ctrl  <= up_left;
4738
                                          when others =>
4739
                                          -- when "11" =>
4740
                                  left_ctrl  <= sp_left;
4741
                                          end case;
4742
                                     right_ctrl <= zero_right;
4743
                                     alu_ctrl   <= alu_st16;
4744
                 cc_ctrl    <= latch_cc;
4745
                 ea_ctrl    <= load_ea;
4746
                                          --
4747
                 md_ctrl    <= latch_md;
4748
                 addr_ctrl  <= idle_ad;
4749
                 pc_ctrl    <= latch_pc;
4750
                                          --
4751
                                          if md(4) = '0' then
4752
                                            st_ctrl      <= pull_st;
4753
                                            return_state <= fetch_state;
4754
                                            next_state   <= saved_state;
4755
                                          else
4756
                                            st_ctrl      <= idle_st;
4757
                                            return_state <= fetch_state;
4758
                                            next_state   <= indirect_state;
4759
                                          end if;
4760
 
4761
                                        when "0101" =>     -- ACCB,R
4762
                 ix_ctrl    <= latch_ix;
4763
                 iy_ctrl    <= latch_iy;
4764
                 up_ctrl    <= latch_up;
4765
                 sp_ctrl    <= latch_sp;
4766
                                     case md(6 downto 5) is
4767
                                          when "00" =>
4768
                                  left_ctrl  <= ix_left;
4769
                                          when "01" =>
4770
                                  left_ctrl  <= iy_left;
4771
                                          when "10" =>
4772
                                  left_ctrl  <= up_left;
4773
                                          when others =>
4774
                                          -- when "11" =>
4775
                                  left_ctrl  <= sp_left;
4776
                                          end case;
4777
                                     right_ctrl <= accb_right;
4778
                                     alu_ctrl   <= alu_add16;
4779
                 cc_ctrl    <= latch_cc;
4780
                 ea_ctrl    <= load_ea;
4781
                                          --
4782
                 md_ctrl    <= latch_md;
4783
                 addr_ctrl  <= idle_ad;
4784
                 pc_ctrl    <= latch_pc;
4785
                                          --
4786
                                          if md(4) = '0' then
4787
                                            st_ctrl      <= pull_st;
4788
                                            return_state <= fetch_state;
4789
                                            next_state   <= saved_state;
4790
                                          else
4791
                                            st_ctrl      <= idle_st;
4792
                                            return_state <= fetch_state;
4793
                                            next_state   <= indirect_state;
4794
                                          end if;
4795
 
4796
                                        when "0110" =>     -- ACCA,R
4797
                 ix_ctrl    <= latch_ix;
4798
                 iy_ctrl    <= latch_iy;
4799
                 up_ctrl    <= latch_up;
4800
                 sp_ctrl    <= latch_sp;
4801
                                     case md(6 downto 5) is
4802
                                          when "00" =>
4803
                                  left_ctrl  <= ix_left;
4804
                                          when "01" =>
4805
                                  left_ctrl  <= iy_left;
4806
                                          when "10" =>
4807
                                  left_ctrl  <= up_left;
4808
                                          when others =>
4809
                                          -- when "11" =>
4810
                                  left_ctrl  <= sp_left;
4811
                                          end case;
4812
                                     right_ctrl <= acca_right;
4813
                                     alu_ctrl   <= alu_add16;
4814
                 cc_ctrl    <= latch_cc;
4815
                 ea_ctrl    <= load_ea;
4816
                                          --
4817
                 md_ctrl    <= latch_md;
4818
                 addr_ctrl  <= idle_ad;
4819
                 pc_ctrl    <= latch_pc;
4820
                                          --
4821
                                          if md(4) = '0' then
4822
                                            st_ctrl      <= pull_st;
4823
                                            return_state <= fetch_state;
4824
                                            next_state   <= saved_state;
4825
                                          else
4826
                                            st_ctrl      <= idle_st;
4827
                                            return_state <= fetch_state;
4828
                                            next_state   <= indirect_state;
4829
                                          end if;
4830
 
4831
                                        when "0111" =>     -- undefined
4832
                 ix_ctrl    <= latch_ix;
4833
                 iy_ctrl    <= latch_iy;
4834
                 up_ctrl    <= latch_up;
4835
                 sp_ctrl    <= latch_sp;
4836
                                     case md(6 downto 5) is
4837
                                          when "00" =>
4838
                                  left_ctrl  <= ix_left;
4839
                                          when "01" =>
4840
                                  left_ctrl  <= iy_left;
4841
                                          when "10" =>
4842
                                  left_ctrl  <= up_left;
4843
                                          when others =>
4844
                                          -- when "11" =>
4845
                                  left_ctrl  <= sp_left;
4846
                                          end case;
4847
                                     right_ctrl <= zero_right;
4848
                                     alu_ctrl   <= alu_nop;
4849
                 cc_ctrl    <= latch_cc;
4850
                 ea_ctrl    <= latch_ea;
4851
                                          --
4852
                 md_ctrl    <= latch_md;
4853
                 addr_ctrl  <= idle_ad;
4854
                 pc_ctrl    <= latch_pc;
4855
                                          --
4856
                                          if md(4) = '0' then
4857
                                            st_ctrl      <= pull_st;
4858
                                            return_state <= fetch_state;
4859
                                            next_state   <= saved_state;
4860
                                          else
4861
                                            st_ctrl      <= idle_st;
4862
                                            return_state <= fetch_state;
4863
                                            next_state   <= indirect_state;
4864
                                          end if;
4865
 
4866
                                        when "1000" =>     -- offset8,R
4867
                 ix_ctrl    <= latch_ix;
4868
                 iy_ctrl    <= latch_iy;
4869
                 up_ctrl    <= latch_up;
4870
                 sp_ctrl    <= latch_sp;
4871
                                          --
4872
                                left_ctrl  <= pc_left;
4873
                                     right_ctrl <= zero_right;
4874
                                     alu_ctrl   <= alu_nop;
4875
                 cc_ctrl    <= latch_cc;
4876
                 ea_ctrl    <= latch_ea;
4877
                                          --
4878
                 md_ctrl    <= fetch_first_md; -- pick up 8 bit offset
4879
                 addr_ctrl  <= fetch_ad;
4880
                 pc_ctrl    <= incr_pc;
4881
                                          --
4882
                                          st_ctrl      <= idle_st;
4883
                                          return_state <= fetch_state;
4884
                 next_state   <= index8_state;
4885
 
4886
                                        when "1001" =>     -- offset16,R
4887
                 ix_ctrl    <= latch_ix;
4888
                 iy_ctrl    <= latch_iy;
4889
                 up_ctrl    <= latch_up;
4890
                 sp_ctrl    <= latch_sp;
4891
                                          --
4892
                                left_ctrl  <= pc_left;
4893
                                     right_ctrl <= zero_right;
4894
                                     alu_ctrl   <= alu_nop;
4895
                 cc_ctrl    <= latch_cc;
4896
                                          ea_ctrl    <= latch_ea;
4897
                                          --
4898
                 md_ctrl    <= fetch_first_md; -- pick up first byte of 16 bit offset
4899
                 addr_ctrl  <= fetch_ad;
4900
                 pc_ctrl    <= incr_pc;
4901
                                          --
4902
                                          st_ctrl      <= idle_st;
4903
                                          return_state <= fetch_state;
4904
                 next_state   <= index16_state;
4905
 
4906
                                        when "1010" =>     -- undefined
4907
                 ix_ctrl    <= latch_ix;
4908
                 iy_ctrl    <= latch_iy;
4909
                 up_ctrl    <= latch_up;
4910
                 sp_ctrl    <= latch_sp;
4911
                                     case md(6 downto 5) is
4912
                                          when "00" =>
4913
                                  left_ctrl  <= ix_left;
4914
                                          when "01" =>
4915
                                  left_ctrl  <= iy_left;
4916
                                          when "10" =>
4917
                                  left_ctrl  <= up_left;
4918
                                          when others =>
4919
                                          -- when "11" =>
4920
                                  left_ctrl  <= sp_left;
4921
                                          end case;
4922
                                     right_ctrl <= zero_right;
4923
                                     alu_ctrl   <= alu_nop;
4924
                 cc_ctrl    <= latch_cc;
4925
                 ea_ctrl    <= latch_ea;
4926
                                          --
4927
                 md_ctrl    <= latch_md;
4928
                 addr_ctrl  <= idle_ad;
4929
                 pc_ctrl    <= latch_pc;
4930
                                          --
4931
                                          if md(4) = '0' then
4932
                                            st_ctrl      <= pull_st;
4933
                                            return_state <= fetch_state;
4934
                                            next_state   <= saved_state;
4935
                                          else
4936
                                            st_ctrl      <= idle_st;
4937
                                            return_state <= fetch_state;
4938
                                            next_state   <= indirect_state;
4939
                                          end if;
4940
 
4941
                                        when "1011" =>     -- ACCD,R
4942
                 ix_ctrl    <= latch_ix;
4943
                 iy_ctrl    <= latch_iy;
4944
                 up_ctrl    <= latch_up;
4945
                 sp_ctrl    <= latch_sp;
4946
                                     case md(6 downto 5) is
4947
                                          when "00" =>
4948
                                  left_ctrl  <= ix_left;
4949
                                          when "01" =>
4950
                                  left_ctrl  <= iy_left;
4951
                                          when "10" =>
4952
                                  left_ctrl  <= up_left;
4953
                                          when others =>
4954
                                          -- when "11" =>
4955
                                  left_ctrl  <= sp_left;
4956
                                          end case;
4957
                                     right_ctrl <= accd_right;
4958
                                     alu_ctrl   <= alu_add16;
4959
                 cc_ctrl    <= latch_cc;
4960
                 ea_ctrl    <= load_ea;
4961
                                          --
4962
                 md_ctrl    <= latch_md;
4963
                 addr_ctrl  <= idle_ad;
4964
                 pc_ctrl    <= latch_pc;
4965
                                          --
4966
                                          if md(4) = '0' then
4967
                                            st_ctrl      <= pull_st;
4968
                                            return_state <= fetch_state;
4969
                                            next_state   <= saved_state;
4970
                                          else
4971
                                            st_ctrl      <= idle_st;
4972
                                            return_state <= fetch_state;
4973
                                            next_state   <= indirect_state;
4974
                                          end if;
4975
 
4976
                                        when "1100" =>     -- offset8,PC
4977
                 ix_ctrl    <= latch_ix;
4978
                 iy_ctrl    <= latch_iy;
4979
                 up_ctrl    <= latch_up;
4980
                 sp_ctrl    <= latch_sp;
4981
                                          --
4982
                                left_ctrl  <= pc_left;
4983
                                     right_ctrl <= zero_right;
4984
                                     alu_ctrl   <= alu_nop;
4985
                 cc_ctrl    <= latch_cc;
4986
                                          ea_ctrl    <= latch_ea;
4987
                                          -- fetch 8 bit offset
4988
                 md_ctrl    <= fetch_first_md;
4989
                 addr_ctrl  <= fetch_ad;
4990
                 pc_ctrl    <= incr_pc;
4991
                                          --
4992
                                          st_ctrl      <= idle_st;
4993
                                          return_state <= fetch_state;
4994
                 next_state   <= pcrel8_state;
4995
 
4996
                                        when "1101" =>     -- offset16,PC
4997
                 ix_ctrl    <= latch_ix;
4998
                 iy_ctrl    <= latch_iy;
4999
                 up_ctrl    <= latch_up;
5000
                 sp_ctrl    <= latch_sp;
5001
                                          --
5002
                                left_ctrl  <= pc_left;
5003
                                     right_ctrl <= zero_right;
5004
                                     alu_ctrl   <= alu_nop;
5005
                 cc_ctrl    <= latch_cc;
5006
                                          ea_ctrl    <= latch_ea;
5007
                                          -- fetch offset
5008
                 md_ctrl    <= fetch_first_md;
5009
                 addr_ctrl  <= fetch_ad;
5010
                 pc_ctrl    <= incr_pc;
5011
                                          --
5012
                                          st_ctrl      <= idle_st;
5013
                                          return_state <= fetch_state;
5014
                 next_state   <= pcrel16_state;
5015
 
5016
                                        when "1110" =>     -- undefined
5017
                 ix_ctrl    <= latch_ix;
5018
                 iy_ctrl    <= latch_iy;
5019
                 up_ctrl    <= latch_up;
5020
                 sp_ctrl    <= latch_sp;
5021
                                     case md(6 downto 5) is
5022
                                          when "00" =>
5023
                                  left_ctrl  <= ix_left;
5024
                                          when "01" =>
5025
                                  left_ctrl  <= iy_left;
5026
                                          when "10" =>
5027
                                  left_ctrl  <= up_left;
5028
                                          when others =>
5029
                                          -- when "11" =>
5030
                                  left_ctrl  <= sp_left;
5031
                                          end case;
5032
                                     right_ctrl <= zero_right;
5033
                                     alu_ctrl   <= alu_nop;
5034
                 cc_ctrl    <= latch_cc;
5035
                 ea_ctrl    <= load_ea;
5036
                                          --
5037
                 md_ctrl    <= latch_md;
5038
                 addr_ctrl  <= idle_ad;
5039
                 pc_ctrl    <= latch_pc;
5040
                                          --
5041
                                          if md(4) = '0' then
5042
                                            st_ctrl      <= pull_st;
5043
                                            return_state <= fetch_state;
5044
                                            next_state   <= saved_state;
5045
                                          else
5046
                                            st_ctrl      <= idle_st;
5047
                                            return_state <= fetch_state;
5048
                                            next_state   <= indirect_state;
5049
                                          end if;
5050
 
5051
               when others =>
5052
--                      when "1111" =>     -- [,address]
5053
                 ix_ctrl    <= latch_ix;
5054
                 iy_ctrl    <= latch_iy;
5055
                 up_ctrl    <= latch_up;
5056
                 sp_ctrl    <= latch_sp;
5057
                                          -- idle ALU
5058
                                left_ctrl  <= pc_left;
5059
                                     right_ctrl <= zero_right;
5060
                                     alu_ctrl   <= alu_nop;
5061
                 cc_ctrl    <= latch_cc;
5062
                 ea_ctrl    <= latch_ea;
5063
                                          -- advance PC to pick up address
5064
                 md_ctrl    <= fetch_first_md;
5065
                 addr_ctrl  <= fetch_ad;
5066
                                          pc_ctrl    <= incr_pc;
5067
                                          --
5068
                                          st_ctrl      <= idle_st;
5069
                                          return_state <= fetch_state;
5070
                 next_state   <= indexaddr_state;
5071
                                        end case;
5072
                                 end if;
5073
 
5074
                          -- load index register with ea plus one
5075
                          when postincr1_state =>
5076
                            op_ctrl    <= latch_op;
5077
             pre_ctrl   <= latch_pre;
5078
             acca_ctrl  <= latch_acca;
5079
             accb_ctrl  <= latch_accb;
5080
             cc_ctrl    <= latch_cc;
5081
             dp_ctrl    <= latch_dp;
5082
             iv_ctrl    <= latch_iv;
5083
                                 nmi_ctrl   <= latch_nmi;
5084
             pc_ctrl    <= latch_pc;
5085
             md_ctrl    <= latch_md;
5086
             ea_ctrl    <= latch_ea;
5087
                                 --
5088
                            left_ctrl  <= ea_left;
5089
                            right_ctrl <= one_right;
5090
                            alu_ctrl   <= alu_add16;
5091
                                 case md(6 downto 5) is
5092
                            when "00" =>
5093
               ix_ctrl    <= load_ix;
5094
               iy_ctrl    <= latch_iy;
5095
               up_ctrl    <= latch_up;
5096
               sp_ctrl    <= latch_sp;
5097
                                 when "01" =>
5098
               ix_ctrl    <= latch_ix;
5099
               iy_ctrl    <= load_iy;
5100
               up_ctrl    <= latch_up;
5101
               sp_ctrl    <= latch_sp;
5102
                                 when "10" =>
5103
               ix_ctrl    <= latch_ix;
5104
               iy_ctrl    <= latch_iy;
5105
               up_ctrl    <= load_up;
5106
               sp_ctrl    <= latch_sp;
5107
                                 when others =>
5108
                                 -- when "11" =>
5109
               ix_ctrl    <= latch_ix;
5110
               iy_ctrl    <= latch_iy;
5111
               up_ctrl    <= latch_up;
5112
               sp_ctrl    <= load_sp;
5113
                            end case;
5114
             addr_ctrl  <= idle_ad;
5115
             dout_ctrl  <= md_lo_dout;
5116
                                 -- return to previous state
5117
                            if md(4) = '0' then
5118
                                         st_ctrl      <= pull_st;
5119
                                         return_state <= fetch_state;
5120
                                         next_state   <= saved_state;
5121
                                 else
5122
                                         st_ctrl      <= idle_st;
5123
                                         return_state <= fetch_state;
5124
                                         next_state   <= indirect_state;
5125
                                 end if;
5126
 
5127
                          -- load index register with ea plus two
5128
                          when postincr2_state =>
5129
                            op_ctrl    <= latch_op;
5130
             pre_ctrl   <= latch_pre;
5131
             acca_ctrl  <= latch_acca;
5132
             accb_ctrl  <= latch_accb;
5133
             cc_ctrl    <= latch_cc;
5134
             dp_ctrl    <= latch_dp;
5135
             iv_ctrl    <= latch_iv;
5136
                                 nmi_ctrl   <= latch_nmi;
5137
             pc_ctrl    <= latch_pc;
5138
             md_ctrl    <= latch_md;
5139
             ea_ctrl    <= latch_ea;
5140
                                 -- increment register by two (address)
5141
                            left_ctrl  <= ea_left;
5142
                            right_ctrl <= two_right;
5143
                            alu_ctrl   <= alu_add16;
5144
                                 case md(6 downto 5) is
5145
                            when "00" =>
5146
               ix_ctrl    <= load_ix;
5147
               iy_ctrl    <= latch_iy;
5148
               up_ctrl    <= latch_up;
5149
               sp_ctrl    <= latch_sp;
5150
                                 when "01" =>
5151
               ix_ctrl    <= latch_ix;
5152
               iy_ctrl    <= load_iy;
5153
               up_ctrl    <= latch_up;
5154
               sp_ctrl    <= latch_sp;
5155
                                 when "10" =>
5156
               ix_ctrl    <= latch_ix;
5157
               iy_ctrl    <= latch_iy;
5158
               up_ctrl    <= load_up;
5159
               sp_ctrl    <= latch_sp;
5160
                                 when others =>
5161
                                 -- when "11" =>
5162
               ix_ctrl    <= latch_ix;
5163
               iy_ctrl    <= latch_iy;
5164
               up_ctrl    <= latch_up;
5165
               sp_ctrl    <= load_sp;
5166
                            end case;
5167
             addr_ctrl  <= idle_ad;
5168
             dout_ctrl  <= md_lo_dout;
5169
                                 -- return to previous state
5170
                            if md(4) = '0' then
5171
                                         st_ctrl      <= pull_st;
5172
                                         return_state <= fetch_state;
5173
                                         next_state   <= saved_state;
5174
                                 else
5175
                                         st_ctrl      <= idle_st;
5176
                                         return_state <= fetch_state;
5177
                                         next_state   <= indirect_state;
5178
                                 end if;
5179
           --
5180
                          -- ea = index register + md (8 bit signed offset)
5181
                          -- ea holds post byte
5182
                          --
5183
                          when index8_state =>
5184
                            op_ctrl    <= latch_op;
5185
             pre_ctrl   <= latch_pre;
5186
             acca_ctrl  <= latch_acca;
5187
             accb_ctrl  <= latch_accb;
5188
             cc_ctrl    <= latch_cc;
5189
             dp_ctrl    <= latch_dp;
5190
             ix_ctrl    <= latch_ix;
5191
             iy_ctrl    <= latch_iy;
5192
             up_ctrl    <= latch_up;
5193
             sp_ctrl    <= latch_sp;
5194
             iv_ctrl    <= latch_iv;
5195
                                 nmi_ctrl   <= latch_nmi;
5196
             pc_ctrl    <= latch_pc;
5197
             md_ctrl    <= latch_md;
5198
                                 case ea(6 downto 5) is
5199
                            when "00" =>
5200
                              left_ctrl  <= ix_left;
5201
                            when "01" =>
5202
                              left_ctrl  <= iy_left;
5203
                                 when "10" =>
5204
                              left_ctrl  <= up_left;
5205
                                 when others =>
5206
                                 -- when "11" =>
5207
                              left_ctrl  <= sp_left;
5208
                                 end case;
5209
                                 -- ea = index reg + md
5210
                            right_ctrl <= md_sign8_right;
5211
                            alu_ctrl   <= alu_add16;
5212
             ea_ctrl    <= load_ea;
5213
                                 -- idle bus
5214
             addr_ctrl  <= idle_ad;
5215
             dout_ctrl  <= md_lo_dout;
5216
                                 -- return to previous state
5217
                            if ea(4) = '0' then
5218
                                         st_ctrl      <= pull_st;
5219
                                         return_state <= fetch_state;
5220
                                         next_state   <= saved_state;
5221
                                 else
5222
                                         st_ctrl      <= idle_st;
5223
                                         return_state <= fetch_state;
5224
                                         next_state   <= indirect_state;
5225
                                 end if;
5226
 
5227
                          -- fetch low byte of 16 bit indexed offset
5228
                          when index16_state =>
5229
                            op_ctrl    <= latch_op;
5230
             pre_ctrl   <= latch_pre;
5231
             acca_ctrl  <= latch_acca;
5232
             accb_ctrl  <= latch_accb;
5233
             cc_ctrl    <= latch_cc;
5234
             dp_ctrl    <= latch_dp;
5235
             ix_ctrl    <= latch_ix;
5236
             iy_ctrl    <= latch_iy;
5237
             up_ctrl    <= latch_up;
5238
             sp_ctrl    <= latch_sp;
5239
             iv_ctrl    <= latch_iv;
5240
                                 nmi_ctrl   <= latch_nmi;
5241
                                 -- advance pc
5242
                            left_ctrl  <= pc_left;
5243
                            right_ctrl <= one_right;
5244
                            alu_ctrl   <= alu_add16;
5245
             pc_ctrl    <= incr_pc;
5246
                                 -- fetch low byte
5247
             ea_ctrl    <= latch_ea;
5248
             md_ctrl    <= fetch_next_md;
5249
             addr_ctrl  <= fetch_ad;
5250
             dout_ctrl  <= md_lo_dout;
5251
                                 --
5252
                            st_ctrl      <= idle_st;
5253
                            return_state <= fetch_state;
5254
                                 next_state   <= index16_2_state;
5255
 
5256
                          -- ea = index register + md (16 bit offset)
5257
                          -- ea holds post byte
5258
                          when index16_2_state =>
5259
                            op_ctrl    <= latch_op;
5260
             pre_ctrl   <= latch_pre;
5261
             acca_ctrl  <= latch_acca;
5262
             accb_ctrl  <= latch_accb;
5263
             cc_ctrl    <= latch_cc;
5264
             dp_ctrl    <= latch_dp;
5265
             ix_ctrl    <= latch_ix;
5266
             iy_ctrl    <= latch_iy;
5267
             up_ctrl    <= latch_up;
5268
             sp_ctrl    <= latch_sp;
5269
             iv_ctrl    <= latch_iv;
5270
                                 nmi_ctrl   <= latch_nmi;
5271
             pc_ctrl    <= latch_pc;
5272
             md_ctrl    <= latch_md;
5273
                                 case ea(6 downto 5) is
5274
                            when "00" =>
5275
                              left_ctrl  <= ix_left;
5276
                            when "01" =>
5277
                              left_ctrl  <= iy_left;
5278
                                 when "10" =>
5279
                              left_ctrl  <= up_left;
5280
                                 when others =>
5281
                                 -- when "11" =>
5282
                              left_ctrl  <= sp_left;
5283
                                 end case;
5284
                                 -- ea = index reg + md
5285
                            right_ctrl <= md_right;
5286
                            alu_ctrl   <= alu_add16;
5287
             ea_ctrl    <= load_ea;
5288
                                 -- idle bus
5289
             addr_ctrl  <= idle_ad;
5290
             dout_ctrl  <= md_lo_dout;
5291
                                 -- return to previous state
5292
                            if ea(4) = '0' then
5293
                                         st_ctrl      <= pull_st;
5294
                                         return_state <= fetch_state;
5295
                                         next_state   <= saved_state;
5296
                                 else
5297
                                         st_ctrl      <= idle_st;
5298
                                         return_state <= fetch_state;
5299
                                         next_state   <= indirect_state;
5300
                                 end if;
5301
           --
5302
                          -- pc relative with 8 bit signed offest
5303
                          -- md holds signed offset
5304
                          --
5305
                          when pcrel8_state =>
5306
                            op_ctrl    <= latch_op;
5307
             pre_ctrl   <= latch_pre;
5308
             acca_ctrl  <= latch_acca;
5309
             accb_ctrl  <= latch_accb;
5310
             cc_ctrl    <= latch_cc;
5311
             dp_ctrl    <= latch_dp;
5312
             ix_ctrl    <= latch_ix;
5313
             iy_ctrl    <= latch_iy;
5314
             up_ctrl    <= latch_up;
5315
             sp_ctrl    <= latch_sp;
5316
             iv_ctrl    <= latch_iv;
5317
                                 nmi_ctrl   <= latch_nmi;
5318
             pc_ctrl    <= latch_pc;
5319
             md_ctrl    <= latch_md;
5320
                                 -- ea = pc + signed md
5321
                            left_ctrl  <= pc_left;
5322
                            right_ctrl <= md_sign8_right;
5323
                            alu_ctrl   <= alu_add16;
5324
             ea_ctrl    <= load_ea;
5325
                                 -- idle bus
5326
             addr_ctrl  <= idle_ad;
5327
             dout_ctrl  <= md_lo_dout;
5328
                                 -- return to previous state
5329
                            if ea(4) = '0' then
5330
                                         st_ctrl      <= pull_st;
5331
                                         return_state <= fetch_state;
5332
                                         next_state   <= saved_state;
5333
                                 else
5334
                                         st_ctrl      <= idle_st;
5335
                                         return_state <= fetch_state;
5336
                                         next_state   <= indirect_state;
5337
                                 end if;
5338
 
5339
                          -- pc relative addressing with 16 bit offset
5340
                          -- pick up the low byte of the offset in md
5341
                          -- advance the pc
5342
                          when pcrel16_state =>
5343
                            op_ctrl    <= latch_op;
5344
             pre_ctrl   <= latch_pre;
5345
             acca_ctrl  <= latch_acca;
5346
             accb_ctrl  <= latch_accb;
5347
             cc_ctrl    <= latch_cc;
5348
             dp_ctrl    <= latch_dp;
5349
             ix_ctrl    <= latch_ix;
5350
             iy_ctrl    <= latch_iy;
5351
             up_ctrl    <= latch_up;
5352
             sp_ctrl    <= latch_sp;
5353
             iv_ctrl    <= latch_iv;
5354
                                 nmi_ctrl   <= latch_nmi;
5355
             ea_ctrl    <= latch_ea;
5356
                                 -- advance pc
5357
                            left_ctrl  <= pc_left;
5358
                            right_ctrl <= zero_right;
5359
                            alu_ctrl   <= alu_nop;
5360
             pc_ctrl    <= incr_pc;
5361
                                 -- fetch low byte
5362
             ea_ctrl    <= latch_ea;
5363
             md_ctrl    <= fetch_next_md;
5364
             addr_ctrl  <= fetch_ad;
5365
             dout_ctrl  <= md_lo_dout;
5366
                                 --
5367
                                 st_ctrl      <= idle_st;
5368
                                 return_state <= fetch_state;
5369
                                 next_state <= pcrel16_2_state;
5370
 
5371
                          -- pc relative with16 bit signed offest
5372
                          -- md holds signed offset
5373
                          when pcrel16_2_state =>
5374
                            op_ctrl    <= latch_op;
5375
             pre_ctrl   <= latch_pre;
5376
             acca_ctrl  <= latch_acca;
5377
             accb_ctrl  <= latch_accb;
5378
             cc_ctrl    <= latch_cc;
5379
             dp_ctrl    <= latch_dp;
5380
             ix_ctrl    <= latch_ix;
5381
             iy_ctrl    <= latch_iy;
5382
             up_ctrl    <= latch_up;
5383
             sp_ctrl    <= latch_sp;
5384
             iv_ctrl    <= latch_iv;
5385
                                 nmi_ctrl   <= latch_nmi;
5386
             pc_ctrl    <= latch_pc;
5387
                                 -- ea = pc +  md
5388
                            left_ctrl  <= pc_left;
5389
                            right_ctrl <= md_right;
5390
                            alu_ctrl   <= alu_add16;
5391
             ea_ctrl    <= load_ea;
5392
             md_ctrl    <= latch_md;
5393
                                 -- idle bus
5394
             addr_ctrl  <= idle_ad;
5395
             dout_ctrl  <= md_lo_dout;
5396
                                 -- return to previous state
5397
                            if ea(4) = '0' then
5398
                                         st_ctrl      <= pull_st;
5399
                                         return_state <= fetch_state;
5400
                                         next_state   <= saved_state;
5401
                                 else
5402
                                         st_ctrl      <= idle_st;
5403
                                         return_state <= fetch_state;
5404
                                         next_state   <= indirect_state;
5405
                                 end if;
5406
 
5407
                          -- indexed to address
5408
                          -- pick up the low byte of the address
5409
                          -- advance the pc
5410
                          when indexaddr_state =>
5411
             acca_ctrl  <= latch_acca;
5412
             accb_ctrl  <= latch_accb;
5413
             cc_ctrl    <= latch_cc;
5414
             dp_ctrl    <= latch_dp;
5415
             ix_ctrl    <= latch_ix;
5416
             iy_ctrl    <= latch_iy;
5417
             up_ctrl    <= latch_up;
5418
             sp_ctrl    <= latch_sp;
5419
             iv_ctrl    <= latch_iv;
5420
                            op_ctrl    <= latch_op;
5421
             pre_ctrl   <= latch_pre;
5422
                                 nmi_ctrl   <= latch_nmi;
5423
                                 -- advance pc
5424
                            left_ctrl  <= pc_left;
5425
                            right_ctrl <= zero_right;
5426
                            alu_ctrl   <= alu_nop;
5427
             pc_ctrl    <= incr_pc;
5428
                                 -- fetch low byte
5429
             ea_ctrl    <= latch_ea;
5430
             md_ctrl    <= fetch_next_md;
5431
             addr_ctrl  <= fetch_ad;
5432
             dout_ctrl  <= md_lo_dout;
5433
                                 --
5434
                                 st_ctrl      <= idle_st;
5435
                                 return_state <= fetch_state;
5436
                                 next_state   <= indexaddr2_state;
5437
 
5438
                          -- indexed to absolute address
5439
                          -- md holds address
5440
                          -- ea hold indexing mode byte
5441
                          when indexaddr2_state =>
5442
                            op_ctrl    <= latch_op;
5443
             pre_ctrl   <= latch_pre;
5444
             acca_ctrl  <= latch_acca;
5445
             accb_ctrl  <= latch_accb;
5446
             cc_ctrl    <= latch_cc;
5447
             dp_ctrl    <= latch_dp;
5448
             ix_ctrl    <= latch_ix;
5449
             iy_ctrl    <= latch_iy;
5450
             up_ctrl    <= latch_up;
5451
             sp_ctrl    <= latch_sp;
5452
             iv_ctrl    <= latch_iv;
5453
                                 nmi_ctrl   <= latch_nmi;
5454
             pc_ctrl    <= latch_pc;
5455
                                 -- ea = md
5456
                            left_ctrl  <= pc_left;
5457
                            right_ctrl <= md_right;
5458
                            alu_ctrl   <= alu_ld16;
5459
             ea_ctrl    <= load_ea;
5460
             md_ctrl    <= latch_md;
5461
                                 -- idle bus
5462
             addr_ctrl  <= idle_ad;
5463
             dout_ctrl  <= md_lo_dout;
5464
                                 -- return to previous state
5465
                            if ea(4) = '0' then
5466
                                         st_ctrl      <= pull_st;
5467
                                         return_state <= fetch_state;
5468
                                         next_state   <= saved_state;
5469
                                 else
5470
                                         st_ctrl      <= idle_st;
5471
                                         return_state <= fetch_state;
5472
                                         next_state   <= indirect_state;
5473
                                 end if;
5474
 
5475
           --
5476
                          -- load md with high byte of indirect address
5477
                          -- pointed to by ea
5478
                          -- increment ea
5479
                          --
5480
                          when indirect_state =>
5481
             acca_ctrl  <= latch_acca;
5482
             accb_ctrl  <= latch_accb;
5483
             cc_ctrl    <= latch_cc;
5484
             dp_ctrl    <= latch_dp;
5485
             ix_ctrl    <= latch_ix;
5486
             iy_ctrl    <= latch_iy;
5487
             up_ctrl    <= latch_up;
5488
             sp_ctrl    <= latch_sp;
5489
             iv_ctrl    <= latch_iv;
5490
                            op_ctrl    <= latch_op;
5491
             pre_ctrl   <= latch_pre;
5492
                                 nmi_ctrl   <= latch_nmi;
5493
             pc_ctrl    <= latch_pc;
5494
                                 -- increment ea
5495
                            left_ctrl  <= ea_left;
5496
                            right_ctrl <= one_right;
5497
                            alu_ctrl   <= alu_add16;
5498
             ea_ctrl    <= load_ea;
5499
                                 -- fetch high byte
5500
             md_ctrl    <= fetch_first_md;
5501
             addr_ctrl  <= read_ad;
5502
             dout_ctrl  <= md_lo_dout;
5503
                                 --
5504
                                 st_ctrl      <= idle_st;
5505
                                 return_state <= fetch_state;
5506
                                 next_state <= indirect2_state;
5507
           --
5508
                          -- load md with low byte of indirect address
5509
                          -- pointed to by ea
5510
                          -- ea has previously been incremented
5511
                          --
5512
                          when indirect2_state =>
5513
             acca_ctrl  <= latch_acca;
5514
             accb_ctrl  <= latch_accb;
5515
             cc_ctrl    <= latch_cc;
5516
             dp_ctrl    <= latch_dp;
5517
             ix_ctrl    <= latch_ix;
5518
             iy_ctrl    <= latch_iy;
5519
             up_ctrl    <= latch_up;
5520
             sp_ctrl    <= latch_sp;
5521
             iv_ctrl    <= latch_iv;
5522
                            op_ctrl    <= latch_op;
5523
             pre_ctrl   <= latch_pre;
5524
                                 nmi_ctrl   <= latch_nmi;
5525
             pc_ctrl    <= latch_pc;
5526
                                 -- idle ea
5527
                            left_ctrl  <= ea_left;
5528
                            right_ctrl <= zero_right;
5529
                            alu_ctrl   <= alu_nop;
5530
             ea_ctrl    <= latch_ea;
5531
                                 -- fetch high byte
5532
             md_ctrl    <= fetch_next_md;
5533
             addr_ctrl  <= read_ad;
5534
             dout_ctrl  <= md_lo_dout;
5535
                                 --
5536
                                 st_ctrl      <= idle_st;
5537
                                 return_state <= fetch_state;
5538
                                 next_state <= indirect3_state;
5539
                          --
5540
                          -- complete idirect addressing
5541
                          -- by loading ea with md
5542
                          --
5543
                          when indirect3_state =>
5544
             acca_ctrl  <= latch_acca;
5545
             accb_ctrl  <= latch_accb;
5546
             cc_ctrl    <= latch_cc;
5547
             dp_ctrl    <= latch_dp;
5548
             ix_ctrl    <= latch_ix;
5549
             iy_ctrl    <= latch_iy;
5550
             up_ctrl    <= latch_up;
5551
             sp_ctrl    <= latch_sp;
5552
             iv_ctrl    <= latch_iv;
5553
                            op_ctrl    <= latch_op;
5554
             pre_ctrl   <= latch_pre;
5555
                                 nmi_ctrl   <= latch_nmi;
5556
             pc_ctrl    <= latch_pc;
5557
                                 -- load ea with md
5558
                            left_ctrl  <= ea_left;
5559
                            right_ctrl <= md_right;
5560
                            alu_ctrl   <= alu_ld16;
5561
             ea_ctrl    <= load_ea;
5562
                                 -- idle cycle
5563
             md_ctrl    <= latch_md;
5564
             addr_ctrl  <= idle_ad;
5565
             dout_ctrl  <= md_lo_dout;
5566
                                 -- return to previous state
5567
                                 st_ctrl      <= pull_st;
5568
                                 return_state <= fetch_state;
5569
                                 next_state   <= saved_state;
5570
 
5571
           --
5572
                          -- ea holds the low byte of the absolute address
5573
                          -- Move ea low byte into ea high byte
5574
                          -- load new ea low byte to for absolute 16 bit address
5575
                          -- advance the program counter
5576
                          --
5577
                          when extended_state => -- fetch ea low byte
5578
               acca_ctrl  <= latch_acca;
5579
               accb_ctrl  <= latch_accb;
5580
               ix_ctrl    <= latch_ix;
5581
               iy_ctrl    <= latch_iy;
5582
               up_ctrl    <= latch_up;
5583
               sp_ctrl    <= latch_sp;
5584
               md_ctrl    <= latch_md;
5585
               iv_ctrl    <= latch_iv;
5586
               dp_ctrl    <= latch_dp;
5587
                              op_ctrl    <= latch_op;
5588
               pre_ctrl   <= latch_pre;
5589
                                   nmi_ctrl   <= latch_nmi;
5590
                                        -- increment pc
5591
               left_ctrl  <= pc_left;
5592
               right_ctrl <= zero_right;
5593
               alu_ctrl   <= alu_nop;
5594
               cc_ctrl    <= latch_cc;
5595
               pc_ctrl    <= incr_pc;
5596
                                        -- fetch next effective address bytes
5597
                                        ea_ctrl    <= fetch_next_ea;
5598
               addr_ctrl  <= fetch_ad;
5599
                                        dout_ctrl  <= md_lo_dout;
5600
                                   -- return to previous state
5601
                                   st_ctrl      <= pull_st;
5602
                                   return_state <= fetch_state;
5603
                                   next_state   <= saved_state;
5604
 
5605
                                when lea_state => -- here on load effective address
5606
                              op_ctrl    <= latch_op;
5607
               acca_ctrl  <= latch_acca;
5608
               accb_ctrl  <= latch_accb;
5609
               dp_ctrl    <= latch_dp;
5610
               iv_ctrl    <= latch_iv;
5611
               pre_ctrl   <= latch_pre;
5612
                                   nmi_ctrl   <= latch_nmi;
5613
               md_ctrl    <= latch_md;
5614
               ea_ctrl    <= latch_ea;
5615
                                        pc_ctrl    <= latch_pc;
5616
                                        -- load index register with effective address
5617
               left_ctrl  <= pc_left;
5618
                                        right_ctrl <= ea_right;
5619
                                   alu_ctrl   <= alu_lea;
5620
                                        case op_code(3 downto 0) is
5621
                                        when "0000" => -- leax
5622
                   cc_ctrl    <= load_cc;
5623
                   ix_ctrl    <= load_ix;
5624
                   iy_ctrl    <= latch_iy;
5625
                   up_ctrl    <= latch_up;
5626
                   sp_ctrl    <= latch_sp;
5627
                                        when "0001" => -- leay
5628
                   cc_ctrl    <= load_cc;
5629
                   ix_ctrl    <= latch_ix;
5630
                   iy_ctrl    <= load_iy;
5631
                   up_ctrl    <= latch_up;
5632
                   sp_ctrl    <= latch_sp;
5633
                                        when "0010" => -- leas
5634
                   cc_ctrl    <= latch_cc;
5635
                   ix_ctrl    <= latch_ix;
5636
                   iy_ctrl    <= latch_iy;
5637
                   up_ctrl    <= latch_up;
5638
                   sp_ctrl    <= load_sp;
5639
                                        when "0011" => -- leau
5640
                   cc_ctrl    <= latch_cc;
5641
                   ix_ctrl    <= latch_ix;
5642
                   iy_ctrl    <= latch_iy;
5643
                   up_ctrl    <= load_up;
5644
                   sp_ctrl    <= latch_sp;
5645
                                        when others =>
5646
                   cc_ctrl    <= latch_cc;
5647
                   ix_ctrl    <= latch_ix;
5648
                   iy_ctrl    <= latch_iy;
5649
                   up_ctrl    <= latch_up;
5650
                   sp_ctrl    <= latch_sp;
5651
                                        end case;
5652
                                        -- idle the bus
5653
               addr_ctrl  <= idle_ad;
5654
               dout_ctrl  <= md_lo_dout;
5655
                                        --
5656
                                        st_ctrl      <= idle_st;
5657
                                        return_state <= fetch_state;
5658
               next_state   <= fetch_state;
5659
 
5660
                                --
5661
                                -- jump to subroutine
5662
                                -- sp=sp-1
5663
                                -- call push_return_lo_state to save pc
5664
                                -- return to jmp_state
5665
                                --
5666
                                when jsr_state =>
5667
               acca_ctrl  <= latch_acca;
5668
               accb_ctrl  <= latch_accb;
5669
               cc_ctrl    <= latch_cc;
5670
               dp_ctrl    <= latch_dp;
5671
               ix_ctrl    <= latch_ix;
5672
               iy_ctrl    <= latch_iy;
5673
               up_ctrl    <= latch_up;
5674
               iv_ctrl    <= latch_iv;
5675
                              op_ctrl    <= latch_op;
5676
               pre_ctrl   <= latch_pre;
5677
                                   nmi_ctrl   <= latch_nmi;
5678
               md_ctrl    <= latch_md;
5679
               ea_ctrl    <= latch_ea;
5680
                                        pc_ctrl    <= latch_pc;
5681
                                        -- decrement sp
5682
               left_ctrl  <= sp_left;
5683
                                        right_ctrl <= one_right;
5684
                                   alu_ctrl   <= alu_sub16;
5685
               sp_ctrl    <= load_sp;
5686
                                        -- idle bus
5687
               addr_ctrl  <= idle_ad;
5688
               dout_ctrl  <= pc_lo_dout;
5689
                                        -- call push_return_state
5690
                                        st_ctrl      <= push_st;
5691
                                        return_state <= jmp_state;
5692
               next_state   <= push_return_lo_state;
5693
 
5694
                                --
5695
                                -- Load pc with ea
5696
                                -- (JMP)
5697
                                --
5698
                                when jmp_state =>
5699
               acca_ctrl  <= latch_acca;
5700
               accb_ctrl  <= latch_accb;
5701
               cc_ctrl    <= latch_cc;
5702
               dp_ctrl    <= latch_dp;
5703
               ix_ctrl    <= latch_ix;
5704
               iy_ctrl    <= latch_iy;
5705
               up_ctrl    <= latch_up;
5706
               sp_ctrl    <= latch_sp;
5707
               iv_ctrl    <= latch_iv;
5708
                              op_ctrl    <= latch_op;
5709
               pre_ctrl   <= latch_pre;
5710
                                   nmi_ctrl   <= latch_nmi;
5711
               md_ctrl    <= latch_md;
5712
               ea_ctrl    <= latch_ea;
5713
                                        -- load PC with effective address
5714
               left_ctrl  <= pc_left;
5715
                                        right_ctrl <= ea_right;
5716
                                   alu_ctrl   <= alu_ld16;
5717
                                        pc_ctrl    <= load_pc;
5718
                                        -- idle the bus
5719
               addr_ctrl  <= idle_ad;
5720
               dout_ctrl  <= md_lo_dout;
5721
                                        --
5722
                                        st_ctrl      <= idle_st;
5723
                                        return_state <= fetch_state;
5724
               next_state   <= fetch_state;
5725
 
5726
                                --
5727
                                -- long branch or branch to subroutine
5728
                                -- pick up next md byte
5729
                                -- md_hi = md_lo
5730
                                -- md_lo = (pc)
5731
                                -- pc=pc+1
5732
                                -- if a lbsr push return address
5733
                                -- continue to sbranch_state
5734
                                -- to evaluate conditional branches
5735
                                --
5736
                                when lbranch_state =>
5737
               acca_ctrl  <= latch_acca;
5738
               accb_ctrl  <= latch_accb;
5739
               cc_ctrl    <= latch_cc;
5740
               dp_ctrl    <= latch_dp;
5741
               ix_ctrl    <= latch_ix;
5742
               iy_ctrl    <= latch_iy;
5743
               up_ctrl    <= latch_up;
5744
               sp_ctrl    <= latch_sp;
5745
               iv_ctrl    <= latch_iv;
5746
                              op_ctrl    <= latch_op;
5747
               pre_ctrl   <= latch_pre;
5748
                                   nmi_ctrl   <= latch_nmi;
5749
               ea_ctrl    <= latch_ea;
5750
                                        --
5751
               left_ctrl  <= pc_left;
5752
                                        right_ctrl <= ea_right;
5753
                                   alu_ctrl   <= alu_ld16;
5754
                                        pc_ctrl    <= incr_pc;
5755
                                        -- fetch the next byte into md_lo
5756
               md_ctrl    <= fetch_next_md;
5757
               addr_ctrl  <= fetch_ad;
5758
               dout_ctrl  <= md_lo_dout;
5759
                                        -- if lbsr - push return address
5760
                                        -- then continue on to short branch
5761
                                        if op_code = "00010111" then
5762
                                          st_ctrl      <= push_st;
5763
                                          return_state <= sbranch_state;
5764
                 next_state   <= push_return_lo_state;
5765
                                        else
5766
                                          st_ctrl      <= idle_st;
5767
                                          return_state <= fetch_state;
5768
                 next_state   <= sbranch_state;
5769
                                        end if;
5770
 
5771
                                 --
5772
                                 -- here to execute conditional branch
5773
                                 -- short conditional branch md = signed 8 bit offset
5774
                                 -- long branch md = 16 bit offset
5775
                                 -- 
5776
                  when sbranch_state =>
5777
               acca_ctrl  <= latch_acca;
5778
               accb_ctrl  <= latch_accb;
5779
               cc_ctrl    <= latch_cc;
5780
               dp_ctrl    <= latch_dp;
5781
               ix_ctrl    <= latch_ix;
5782
               iy_ctrl    <= latch_iy;
5783
               up_ctrl    <= latch_up;
5784
               sp_ctrl    <= latch_sp;
5785
               iv_ctrl    <= latch_iv;
5786
                              op_ctrl    <= latch_op;
5787
               pre_ctrl   <= latch_pre;
5788
                                   nmi_ctrl   <= latch_nmi;
5789
               ea_ctrl    <= latch_ea;
5790
               md_ctrl    <= latch_md;
5791
                                        --
5792
               left_ctrl  <= pc_left;
5793
                                        right_ctrl <= md_right;
5794
                                   alu_ctrl   <= alu_add16;
5795
                                        --
5796
               addr_ctrl  <= idle_ad;
5797
               dout_ctrl  <= md_lo_dout;
5798
                                        --
5799
                                   st_ctrl      <= idle_st;
5800
                                   return_state <= fetch_state;
5801
                                        next_state   <= fetch_state;
5802
                              if op_code(7 downto 4) = "0010" then -- conditional branch
5803
                 case op_code(3 downto 0) is
5804
                           when "0000" => -- bra
5805
                                            cond_true := (1 = 1);
5806
                           when "0001" => -- brn
5807
                                            cond_true := (1 = 0);
5808
                           when "0010" => -- bhi
5809
                                            cond_true := ((cc(CBIT) or cc(ZBIT)) = '0');
5810
                           when "0011" => -- bls
5811
                                            cond_true := ((cc(CBIT) or cc(ZBIT)) = '1');
5812
                           when "0100" => -- bcc/bhs
5813
                                            cond_true := (cc(CBIT) = '0');
5814
                           when "0101" => -- bcs/blo
5815
                                            cond_true := (cc(CBIT) = '1');
5816
                           when "0110" => -- bne
5817
                             cond_true := (cc(ZBIT) = '0');
5818
                           when "0111" => -- beq
5819
                                            cond_true := (cc(ZBIT) = '1');
5820
                           when "1000" => -- bvc
5821
                                            cond_true := (cc(VBIT) = '0');
5822
                           when "1001" => -- bvs
5823
                                            cond_true := (cc(VBIT) = '1');
5824
                           when "1010" => -- bpl
5825
                                            cond_true := (cc(NBIT) = '0');
5826
                           when "1011" => -- bmi
5827
                                            cond_true := (cc(NBIT) = '1');
5828
                           when "1100" => -- bge
5829
                                            cond_true := ((cc(NBIT) xor cc(VBIT)) = '0');
5830
                           when "1101" => -- blt
5831
                                            cond_true := ((cc(NBIT) xor cc(VBIT)) = '1');
5832
                           when "1110" => -- bgt
5833
                                            cond_true := ((cc(ZBIT) or (cc(NBIT) xor cc(VBIT))) = '0');
5834
                           when "1111" => -- ble
5835
                                            cond_true := ((cc(ZBIT) or (cc(NBIT) xor cc(VBIT))) = '1');
5836
                           when others =>
5837
                                            null;
5838
--                   cond_true := (1 = 1);
5839
                           end case;
5840
                                        else
5841
                                          cond_true := (1 = 1); -- lbra, lbsr, bsr
5842
                                   end if;
5843
                                        if cond_true then
5844
                                          pc_ctrl    <= load_pc;
5845
                                        else
5846
                                          pc_ctrl    <= latch_pc;
5847
               end if;
5848
 
5849
                                 --
5850
                                 -- push return address onto the S stack
5851
                                 --
5852
                                 -- (sp) = pc_lo
5853
                                 -- sp = sp - 1
5854
                                 --
5855
                                 when push_return_lo_state =>
5856
                                     -- default
5857
                 acca_ctrl  <= latch_acca;
5858
                 accb_ctrl  <= latch_accb;
5859
                 ix_ctrl    <= latch_ix;
5860
                 iy_ctrl    <= latch_iy;
5861
                 up_ctrl    <= latch_up;
5862
                 md_ctrl    <= latch_md;
5863
                 iv_ctrl    <= latch_iv;
5864
                 dp_ctrl    <= latch_dp;
5865
                                op_ctrl    <= latch_op;
5866
                 pre_ctrl   <= latch_pre;
5867
                                     nmi_ctrl   <= latch_nmi;
5868
                 ea_ctrl    <= latch_ea;
5869
                                          -- decrement the sp
5870
                 left_ctrl  <= sp_left;
5871
                 right_ctrl <= one_right;
5872
                 alu_ctrl   <= alu_sub16;
5873
                 cc_ctrl    <= latch_cc;
5874
                 sp_ctrl    <= load_sp;
5875
                 -- write PC low
5876
                 pc_ctrl    <= latch_pc;
5877
                 addr_ctrl  <= pushs_ad;
5878
                 dout_ctrl  <= pc_lo_dout;
5879
                                          --
5880
                                          st_ctrl      <= idle_st;
5881
                                          return_state <= fetch_state;
5882
                 next_state   <= push_return_hi_state;
5883
 
5884
                                --
5885
                                -- push program counter hi byte onto the stack
5886
                                -- (sp) = pc_hi
5887
                                -- sp = sp
5888
                                -- return to originating state
5889
                                --
5890
                                when push_return_hi_state =>
5891
                                     -- default
5892
                 acca_ctrl  <= latch_acca;
5893
                 accb_ctrl  <= latch_accb;
5894
                 ix_ctrl    <= latch_ix;
5895
                 iy_ctrl    <= latch_iy;
5896
                 up_ctrl    <= latch_up;
5897
                 md_ctrl    <= latch_md;
5898
                 iv_ctrl    <= latch_iv;
5899
                 dp_ctrl    <= latch_dp;
5900
                                op_ctrl    <= latch_op;
5901
                 pre_ctrl   <= latch_pre;
5902
                                     nmi_ctrl   <= latch_nmi;
5903
                 ea_ctrl    <= latch_ea;
5904
                                          -- idle the SP
5905
                 left_ctrl  <= sp_left;
5906
                 right_ctrl <= one_right;
5907
                 alu_ctrl   <= alu_sub16;
5908
                 cc_ctrl    <= latch_cc;
5909
                 sp_ctrl    <= latch_sp;
5910
                                          -- write pc hi bytes
5911
                                          pc_ctrl    <= latch_pc;
5912
                 addr_ctrl  <= pushs_ad;
5913
                 dout_ctrl  <= pc_hi_dout;
5914
                                          --
5915
                                          st_ctrl      <= pull_st;
5916
                                          return_state <= fetch_state;
5917
                 next_state   <= saved_state;
5918
 
5919
                                 when pull_return_hi_state =>
5920
                                     -- default
5921
                 acca_ctrl  <= latch_acca;
5922
                 accb_ctrl  <= latch_accb;
5923
                 ix_ctrl    <= latch_ix;
5924
                 iy_ctrl    <= latch_iy;
5925
                 up_ctrl    <= latch_up;
5926
                 md_ctrl    <= latch_md;
5927
                 iv_ctrl    <= latch_iv;
5928
                 dp_ctrl    <= latch_dp;
5929
                                op_ctrl    <= latch_op;
5930
                 pre_ctrl   <= latch_pre;
5931
                                     nmi_ctrl   <= latch_nmi;
5932
                 ea_ctrl    <= latch_ea;
5933
                                          -- increment the sp
5934
                 left_ctrl  <= sp_left;
5935
                 right_ctrl <= one_right;
5936
                 alu_ctrl   <= alu_add16;
5937
                 cc_ctrl    <= latch_cc;
5938
                 sp_ctrl    <= load_sp;
5939
                 -- read pc hi
5940
                                          pc_ctrl    <= pull_hi_pc;
5941
                 addr_ctrl  <= pulls_ad;
5942
                 dout_ctrl  <= pc_hi_dout;
5943
                                          --
5944
                                          st_ctrl      <= idle_st;
5945
                                          return_state <= fetch_state;
5946
                 next_state   <= pull_return_lo_state;
5947
 
5948
                                when pull_return_lo_state =>
5949
                                     -- default
5950
                 acca_ctrl  <= latch_acca;
5951
                 accb_ctrl  <= latch_accb;
5952
                 ix_ctrl    <= latch_ix;
5953
                 iy_ctrl    <= latch_iy;
5954
                 up_ctrl    <= latch_up;
5955
                 md_ctrl    <= latch_md;
5956
                 iv_ctrl    <= latch_iv;
5957
                 dp_ctrl    <= latch_dp;
5958
                                op_ctrl    <= latch_op;
5959
                 pre_ctrl   <= latch_pre;
5960
                                     nmi_ctrl   <= latch_nmi;
5961
                 ea_ctrl    <= latch_ea;
5962
                                          -- increment the SP
5963
                 left_ctrl  <= sp_left;
5964
                 right_ctrl <= one_right;
5965
                 alu_ctrl   <= alu_add16;
5966
                 cc_ctrl    <= latch_cc;
5967
                 sp_ctrl    <= load_sp;
5968
                                          -- read pc low
5969
                                          pc_ctrl    <= pull_lo_pc;
5970
                 addr_ctrl  <= pulls_ad;
5971
                 dout_ctrl  <= pc_lo_dout;
5972
                                          --
5973
                                          st_ctrl      <= pull_st;
5974
                                          return_state <= fetch_state;
5975
                 next_state   <= saved_state;
5976
 
5977
                                 when andcc_state =>
5978
                                     -- default
5979
                 acca_ctrl  <= latch_acca;
5980
                 accb_ctrl  <= latch_accb;
5981
                 ix_ctrl    <= latch_ix;
5982
                 iy_ctrl    <= latch_iy;
5983
                 up_ctrl    <= latch_up;
5984
                 sp_ctrl    <= latch_sp;
5985
                 pc_ctrl    <= latch_pc;
5986
                 iv_ctrl    <= latch_iv;
5987
                 dp_ctrl    <= latch_dp;
5988
                                op_ctrl    <= latch_op;
5989
                 pre_ctrl   <= latch_pre;
5990
                                     nmi_ctrl   <= latch_nmi;
5991
                 ea_ctrl    <= latch_ea;
5992
                 md_ctrl    <= latch_md;
5993
                                          -- AND CC with md
5994
                 left_ctrl  <= md_left;
5995
                 right_ctrl <= zero_right;
5996
                 alu_ctrl   <= alu_andcc;
5997
                 cc_ctrl    <= load_cc;
5998
                                          -- idle bus
5999
                 addr_ctrl  <= idle_ad;
6000
                 dout_ctrl  <= md_lo_dout;
6001
                                          --
6002
                                          st_ctrl      <= pull_st;
6003
                                          return_state <= fetch_state;
6004
                                     next_state   <= saved_state;
6005
 
6006
                                 when orcc_state =>
6007
                                     -- default
6008
                 acca_ctrl  <= latch_acca;
6009
                 accb_ctrl  <= latch_accb;
6010
                 ix_ctrl    <= latch_ix;
6011
                 iy_ctrl    <= latch_iy;
6012
                 up_ctrl    <= latch_up;
6013
                 sp_ctrl    <= latch_sp;
6014
                 pc_ctrl    <= latch_pc;
6015
                 iv_ctrl    <= latch_iv;
6016
                 dp_ctrl    <= latch_dp;
6017
                                op_ctrl    <= latch_op;
6018
                 pre_ctrl   <= latch_pre;
6019
                                     nmi_ctrl   <= latch_nmi;
6020
                 ea_ctrl    <= latch_ea;
6021
                 md_ctrl    <= latch_md;
6022
                                          -- OR CC with md
6023
                 left_ctrl  <= md_left;
6024
                 right_ctrl <= zero_right;
6025
                 alu_ctrl   <= alu_orcc;
6026
                 cc_ctrl    <= load_cc;
6027
                                          -- idle bus
6028
                 addr_ctrl  <= idle_ad;
6029
                 dout_ctrl  <= md_lo_dout;
6030
                                          --
6031
                                          st_ctrl      <= pull_st;
6032
                                          return_state <= fetch_state;
6033
                                     next_state   <= saved_state;
6034
 
6035
                                 when tfr_state =>
6036
                                     -- default
6037
                 iv_ctrl    <= latch_iv;
6038
                                op_ctrl    <= latch_op;
6039
                 pre_ctrl   <= latch_pre;
6040
                                     nmi_ctrl   <= latch_nmi;
6041
                 ea_ctrl    <= latch_ea;
6042
                 md_ctrl    <= latch_md;
6043
                                          -- select source register
6044
                                          case md(7 downto 4) is
6045
                                          when "0000" =>
6046
                                            left_ctrl <= accd_left;
6047
                                          when "0001" =>
6048
                                            left_ctrl <= ix_left;
6049
                                          when "0010" =>
6050
                                            left_ctrl <= iy_left;
6051
                                          when "0011" =>
6052
                                            left_ctrl <= up_left;
6053
                                          when "0100" =>
6054
                                            left_ctrl <= sp_left;
6055
                                          when "0101" =>
6056
                                            left_ctrl <= pc_left;
6057
                                          when "1000" =>
6058
                                            left_ctrl <= acca_left;
6059
                                          when "1001" =>
6060
                                            left_ctrl <= accb_left;
6061
                                          when "1010" =>
6062
                                            left_ctrl <= cc_left;
6063
                                          when "1011" =>
6064
                                            left_ctrl <= dp_left;
6065
                                          when others =>
6066
                   left_ctrl  <= md_left;
6067
                                          end case;
6068
                 right_ctrl <= zero_right;
6069
                 alu_ctrl   <= alu_tfr;
6070
                                          -- select destination register
6071
                                          case md(3 downto 0) is
6072
                                          when "0000" => -- accd
6073
                   ix_ctrl    <= latch_ix;
6074
                   iy_ctrl    <= latch_iy;
6075
                   up_ctrl    <= latch_up;
6076
                   sp_ctrl    <= latch_sp;
6077
                   pc_ctrl    <= latch_pc;
6078
                   acca_ctrl  <= load_hi_acca;
6079
                   accb_ctrl  <= load_accb;
6080
                   cc_ctrl    <= latch_cc;
6081
                   dp_ctrl    <= latch_dp;
6082
                                          when "0001" => -- ix
6083
                   ix_ctrl    <= load_ix;
6084
                   iy_ctrl    <= latch_iy;
6085
                   up_ctrl    <= latch_up;
6086
                   sp_ctrl    <= latch_sp;
6087
                   pc_ctrl    <= latch_pc;
6088
                   acca_ctrl  <= latch_acca;
6089
                   accb_ctrl  <= latch_accb;
6090
                   cc_ctrl    <= latch_cc;
6091
                   dp_ctrl    <= latch_dp;
6092
                                          when "0010" => -- iy
6093
                   ix_ctrl    <= latch_ix;
6094
                   iy_ctrl    <= load_iy;
6095
                   up_ctrl    <= latch_up;
6096
                   sp_ctrl    <= latch_sp;
6097
                   pc_ctrl    <= latch_pc;
6098
                   acca_ctrl  <= latch_acca;
6099
                   accb_ctrl  <= latch_accb;
6100
                   cc_ctrl    <= latch_cc;
6101
                   dp_ctrl    <= latch_dp;
6102
                                          when "0011" => -- up
6103
                   ix_ctrl    <= latch_ix;
6104
                   iy_ctrl    <= latch_iy;
6105
                   up_ctrl    <= load_up;
6106
                   sp_ctrl    <= latch_sp;
6107
                   pc_ctrl    <= latch_pc;
6108
                   acca_ctrl  <= latch_acca;
6109
                   accb_ctrl  <= latch_accb;
6110
                   cc_ctrl    <= latch_cc;
6111
                   dp_ctrl    <= latch_dp;
6112
                                          when "0100" => -- sp
6113
                   ix_ctrl    <= latch_ix;
6114
                   iy_ctrl    <= latch_iy;
6115
                   up_ctrl    <= latch_up;
6116
                   sp_ctrl    <= load_sp;
6117
                   pc_ctrl    <= latch_pc;
6118
                   acca_ctrl  <= latch_acca;
6119
                   accb_ctrl  <= latch_accb;
6120
                   cc_ctrl    <= latch_cc;
6121
                   dp_ctrl    <= latch_dp;
6122
                                          when "0101" => -- pc
6123
                   ix_ctrl    <= latch_ix;
6124
                   iy_ctrl    <= latch_iy;
6125
                   up_ctrl    <= latch_up;
6126
                   sp_ctrl    <= latch_sp;
6127
                   pc_ctrl    <= load_pc;
6128
                   acca_ctrl  <= latch_acca;
6129
                   accb_ctrl  <= latch_accb;
6130
                   cc_ctrl    <= latch_cc;
6131
                   dp_ctrl    <= latch_dp;
6132
                                          when "1000" => -- acca
6133
                   ix_ctrl    <= latch_ix;
6134
                   iy_ctrl    <= latch_iy;
6135
                   up_ctrl    <= latch_up;
6136
                   sp_ctrl    <= latch_sp;
6137
                   pc_ctrl    <= latch_pc;
6138
                   acca_ctrl  <= load_acca;
6139
                   accb_ctrl  <= latch_accb;
6140
                   cc_ctrl    <= latch_cc;
6141
                   dp_ctrl    <= latch_dp;
6142
                                          when "1001" => -- accb
6143
                   ix_ctrl    <= latch_ix;
6144
                   iy_ctrl    <= latch_iy;
6145
                   up_ctrl    <= latch_up;
6146
                   sp_ctrl    <= latch_sp;
6147
                   pc_ctrl    <= latch_pc;
6148
                   acca_ctrl  <= latch_acca;
6149
                   accb_ctrl  <= load_accb;
6150
                   cc_ctrl    <= latch_cc;
6151
                   dp_ctrl    <= latch_dp;
6152
                                          when "1010" => -- cc
6153
                   ix_ctrl    <= latch_ix;
6154
                   iy_ctrl    <= latch_iy;
6155
                   up_ctrl    <= latch_up;
6156
                   sp_ctrl    <= latch_sp;
6157
                   pc_ctrl    <= latch_pc;
6158
                   acca_ctrl  <= latch_acca;
6159
                   accb_ctrl  <= latch_accb;
6160
                   cc_ctrl    <= load_cc;
6161
                   dp_ctrl    <= latch_dp;
6162
                                          when "1011" => --dp
6163
                   ix_ctrl    <= latch_ix;
6164
                   iy_ctrl    <= latch_iy;
6165
                   up_ctrl    <= latch_up;
6166
                   sp_ctrl    <= latch_sp;
6167
                   pc_ctrl    <= latch_pc;
6168
                   acca_ctrl  <= latch_acca;
6169
                   accb_ctrl  <= latch_accb;
6170
                   cc_ctrl    <= latch_cc;
6171
                   dp_ctrl    <= load_dp;
6172
                                          when others =>
6173
                   ix_ctrl    <= latch_ix;
6174
                   iy_ctrl    <= latch_iy;
6175
                   up_ctrl    <= latch_up;
6176
                   sp_ctrl    <= latch_sp;
6177
                   pc_ctrl    <= latch_pc;
6178
                   acca_ctrl  <= latch_acca;
6179
                   accb_ctrl  <= latch_accb;
6180
                   cc_ctrl    <= latch_cc;
6181
                   dp_ctrl    <= latch_dp;
6182
                                          end case;
6183
                                          -- idle bus
6184
                 addr_ctrl  <= idle_ad;
6185
                 dout_ctrl  <= md_lo_dout;
6186
                                          --
6187
                                          st_ctrl      <= pull_st;
6188
                                          return_state <= fetch_state;
6189
                                     next_state   <= saved_state;
6190
 
6191
                                 when exg_state =>
6192
                                     -- default
6193
                 iv_ctrl    <= latch_iv;
6194
                                op_ctrl    <= latch_op;
6195
                 pre_ctrl   <= latch_pre;
6196
                                     nmi_ctrl   <= latch_nmi;
6197
                 md_ctrl    <= latch_md;
6198
                                          -- save destination register
6199
                                          case md(3 downto 0) is
6200
                                          when "0000" =>
6201
                                            left_ctrl <= accd_left;
6202
                                          when "0001" =>
6203
                                            left_ctrl <= ix_left;
6204
                                          when "0010" =>
6205
                                            left_ctrl <= iy_left;
6206
                                          when "0011" =>
6207
                                            left_ctrl <= up_left;
6208
                                          when "0100" =>
6209
                                            left_ctrl <= sp_left;
6210
                                          when "0101" =>
6211
                                            left_ctrl <= pc_left;
6212
                                          when "1000" =>
6213
                                            left_ctrl <= acca_left;
6214
                                          when "1001" =>
6215
                                            left_ctrl <= accb_left;
6216
                                          when "1010" =>
6217
                                            left_ctrl <= cc_left;
6218
                                          when "1011" =>
6219
                                            left_ctrl <= dp_left;
6220
                                          when others =>
6221
                   left_ctrl  <= md_left;
6222
                                          end case;
6223
                 right_ctrl <= zero_right;
6224
                 alu_ctrl   <= alu_tfr;
6225
                 ea_ctrl    <= load_ea;
6226
 
6227
                 ix_ctrl    <= latch_ix;
6228
                 iy_ctrl    <= latch_iy;
6229
                 up_ctrl    <= latch_up;
6230
                 sp_ctrl    <= latch_sp;
6231
                 pc_ctrl    <= latch_pc;
6232
                 acca_ctrl  <= latch_acca;
6233
                 accb_ctrl  <= latch_accb;
6234
                 cc_ctrl    <= latch_cc;
6235
                 dp_ctrl    <= latch_dp;
6236
                                          -- idle bus
6237
                 addr_ctrl  <= idle_ad;
6238
                 dout_ctrl  <= md_lo_dout;
6239
                                          -- call tranfer microcode
6240
                                          st_ctrl      <= push_st;
6241
                                          return_state <= exg1_state;
6242
                                     next_state   <= tfr_state;
6243
 
6244
                                 when exg1_state =>
6245
                                     -- default
6246
                 iv_ctrl    <= latch_iv;
6247
                                op_ctrl    <= latch_op;
6248
                 pre_ctrl   <= latch_pre;
6249
                                     nmi_ctrl   <= latch_nmi;
6250
                 ea_ctrl    <= latch_ea;
6251
                 md_ctrl    <= latch_md;
6252
                                          -- restore destination
6253
                 left_ctrl  <= ea_left;
6254
                 right_ctrl <= zero_right;
6255
                 alu_ctrl   <= alu_tfr;
6256
                                          -- save as source register
6257
                                          case md(7 downto 4) is
6258
                                          when "0000" => -- accd
6259
                   ix_ctrl    <= latch_ix;
6260
                   iy_ctrl    <= latch_iy;
6261
                   up_ctrl    <= latch_up;
6262
                   sp_ctrl    <= latch_sp;
6263
                   pc_ctrl    <= latch_pc;
6264
                   acca_ctrl  <= load_hi_acca;
6265
                   accb_ctrl  <= load_accb;
6266
                   cc_ctrl    <= latch_cc;
6267
                   dp_ctrl    <= latch_dp;
6268
                                          when "0001" => -- ix
6269
                   ix_ctrl    <= load_ix;
6270
                   iy_ctrl    <= latch_iy;
6271
                   up_ctrl    <= latch_up;
6272
                   sp_ctrl    <= latch_sp;
6273
                   pc_ctrl    <= latch_pc;
6274
                   acca_ctrl  <= latch_acca;
6275
                   accb_ctrl  <= latch_accb;
6276
                   cc_ctrl    <= latch_cc;
6277
                   dp_ctrl    <= latch_dp;
6278
                                          when "0010" => -- iy
6279
                   ix_ctrl    <= latch_ix;
6280
                   iy_ctrl    <= load_iy;
6281
                   up_ctrl    <= latch_up;
6282
                   sp_ctrl    <= latch_sp;
6283
                   pc_ctrl    <= latch_pc;
6284
                   acca_ctrl  <= latch_acca;
6285
                   accb_ctrl  <= latch_accb;
6286
                   cc_ctrl    <= latch_cc;
6287
                   dp_ctrl    <= latch_dp;
6288
                                          when "0011" => -- up
6289
                   ix_ctrl    <= latch_ix;
6290
                   iy_ctrl    <= latch_iy;
6291
                   up_ctrl    <= load_up;
6292
                   sp_ctrl    <= latch_sp;
6293
                   pc_ctrl    <= latch_pc;
6294
                   acca_ctrl  <= latch_acca;
6295
                   accb_ctrl  <= latch_accb;
6296
                   cc_ctrl    <= latch_cc;
6297
                   dp_ctrl    <= latch_dp;
6298
                                          when "0100" => -- sp
6299
                   ix_ctrl    <= latch_ix;
6300
                   iy_ctrl    <= latch_iy;
6301
                   up_ctrl    <= latch_up;
6302
                   sp_ctrl    <= load_sp;
6303
                   pc_ctrl    <= latch_pc;
6304
                   acca_ctrl  <= latch_acca;
6305
                   accb_ctrl  <= latch_accb;
6306
                   cc_ctrl    <= latch_cc;
6307
                   dp_ctrl    <= latch_dp;
6308
                                          when "0101" => -- pc
6309
                   ix_ctrl    <= latch_ix;
6310
                   iy_ctrl    <= latch_iy;
6311
                   up_ctrl    <= latch_up;
6312
                   sp_ctrl    <= latch_sp;
6313
                   pc_ctrl    <= load_pc;
6314
                   acca_ctrl  <= latch_acca;
6315
                   accb_ctrl  <= latch_accb;
6316
                   cc_ctrl    <= latch_cc;
6317
                   dp_ctrl    <= latch_dp;
6318
                                          when "1000" => -- acca
6319
                   ix_ctrl    <= latch_ix;
6320
                   iy_ctrl    <= latch_iy;
6321
                   up_ctrl    <= latch_up;
6322
                   sp_ctrl    <= latch_sp;
6323
                   pc_ctrl    <= latch_pc;
6324
                   acca_ctrl  <= load_acca;
6325
                   accb_ctrl  <= latch_accb;
6326
                   cc_ctrl    <= latch_cc;
6327
                   dp_ctrl    <= latch_dp;
6328
                                          when "1001" => -- accb
6329
                   ix_ctrl    <= latch_ix;
6330
                   iy_ctrl    <= latch_iy;
6331
                   up_ctrl    <= latch_up;
6332
                   sp_ctrl    <= latch_sp;
6333
                   pc_ctrl    <= latch_pc;
6334
                   acca_ctrl  <= latch_acca;
6335
                   accb_ctrl  <= load_accb;
6336
                   cc_ctrl    <= latch_cc;
6337
                   dp_ctrl    <= latch_dp;
6338
                                          when "1010" => -- cc
6339
                   acca_ctrl  <= latch_acca;
6340
                   accb_ctrl  <= latch_accb;
6341
                   ix_ctrl    <= latch_ix;
6342
                   iy_ctrl    <= latch_iy;
6343
                   up_ctrl    <= latch_up;
6344
                   sp_ctrl    <= latch_sp;
6345
                   pc_ctrl    <= latch_pc;
6346
                   acca_ctrl  <= latch_acca;
6347
                   accb_ctrl  <= latch_accb;
6348
                   cc_ctrl    <= load_cc;
6349
                   dp_ctrl    <= latch_dp;
6350
                                          when "1011" => --dp
6351
                   acca_ctrl  <= latch_acca;
6352
                   accb_ctrl  <= latch_accb;
6353
                   ix_ctrl    <= latch_ix;
6354
                   iy_ctrl    <= latch_iy;
6355
                   up_ctrl    <= latch_up;
6356
                   sp_ctrl    <= latch_sp;
6357
                   pc_ctrl    <= latch_pc;
6358
                   acca_ctrl  <= latch_acca;
6359
                   accb_ctrl  <= latch_accb;
6360
                   cc_ctrl    <= latch_cc;
6361
                   dp_ctrl    <= load_dp;
6362
                                          when others =>
6363
                   acca_ctrl  <= latch_acca;
6364
                   accb_ctrl  <= latch_accb;
6365
                   ix_ctrl    <= latch_ix;
6366
                   iy_ctrl    <= latch_iy;
6367
                   up_ctrl    <= latch_up;
6368
                   sp_ctrl    <= latch_sp;
6369
                   pc_ctrl    <= latch_pc;
6370
                   acca_ctrl  <= latch_acca;
6371
                   accb_ctrl  <= latch_accb;
6372
                   cc_ctrl    <= latch_cc;
6373
                   dp_ctrl    <= latch_dp;
6374
                                          end case;
6375
                                          -- idle bus
6376
                 addr_ctrl  <= idle_ad;
6377
                 dout_ctrl  <= md_lo_dout;
6378
                                          --
6379
                                          st_ctrl      <= idle_st;
6380
                                          return_state <= fetch_state;
6381
                                     next_state   <= fetch_state;
6382
 
6383
                                 when mul_state =>
6384
                                     -- default
6385
                 acca_ctrl  <= latch_acca;
6386
                 accb_ctrl  <= latch_accb;
6387
                 ix_ctrl    <= latch_ix;
6388
                 iy_ctrl    <= latch_iy;
6389
                 up_ctrl    <= latch_up;
6390
                 sp_ctrl    <= latch_sp;
6391
                 pc_ctrl    <= latch_pc;
6392
                 iv_ctrl    <= latch_iv;
6393
                 dp_ctrl    <= latch_dp;
6394
                                op_ctrl    <= latch_op;
6395
                 pre_ctrl   <= latch_pre;
6396
                                     nmi_ctrl   <= latch_nmi;
6397
                 ea_ctrl    <= latch_ea;
6398
                                          -- move acca to md
6399
                 left_ctrl  <= acca_left;
6400
                 right_ctrl <= zero_right;
6401
                 alu_ctrl   <= alu_st16;
6402
                 cc_ctrl    <= latch_cc;
6403
                 md_ctrl    <= load_md;
6404
                                          -- idle bus
6405
                 addr_ctrl  <= idle_ad;
6406
                 dout_ctrl  <= md_lo_dout;
6407
                                          --
6408
                                          st_ctrl      <= idle_st;
6409
                                          return_state <= fetch_state;
6410
                                     next_state   <= mulea_state;
6411
 
6412
                                 when mulea_state =>
6413
                                     -- default
6414
                 acca_ctrl  <= latch_acca;
6415
                 accb_ctrl  <= latch_accb;
6416
                 ix_ctrl    <= latch_ix;
6417
                 iy_ctrl    <= latch_iy;
6418
                 up_ctrl    <= latch_up;
6419
                 sp_ctrl    <= latch_sp;
6420
                 pc_ctrl    <= latch_pc;
6421
                 iv_ctrl    <= latch_iv;
6422
                 dp_ctrl    <= latch_dp;
6423
                                op_ctrl    <= latch_op;
6424
                 pre_ctrl   <= latch_pre;
6425
                                     nmi_ctrl   <= latch_nmi;
6426
                 md_ctrl    <= latch_md;
6427
                                          -- move accb to ea
6428
                 left_ctrl  <= accb_left;
6429
                 right_ctrl <= zero_right;
6430
                 alu_ctrl   <= alu_st16;
6431
                 cc_ctrl    <= latch_cc;
6432
                 ea_ctrl    <= load_ea;
6433
                                          -- idle bus
6434
                 addr_ctrl  <= idle_ad;
6435
                 dout_ctrl  <= md_lo_dout;
6436
                                          --
6437
                                          st_ctrl      <= idle_st;
6438
                                          return_state <= fetch_state;
6439
                                     next_state   <= muld_state;
6440
 
6441
                                 when muld_state =>
6442
                                     -- default
6443
                 ix_ctrl    <= latch_ix;
6444
                 iy_ctrl    <= latch_iy;
6445
                 up_ctrl    <= latch_up;
6446
                 sp_ctrl    <= latch_sp;
6447
                 pc_ctrl    <= latch_pc;
6448
                 iv_ctrl    <= latch_iv;
6449
                 dp_ctrl    <= latch_dp;
6450
                                op_ctrl    <= latch_op;
6451
                 pre_ctrl   <= latch_pre;
6452
                                     nmi_ctrl   <= latch_nmi;
6453
                 ea_ctrl    <= latch_ea;
6454
                 md_ctrl    <= latch_md;
6455
                                          -- clear accd
6456
                 left_ctrl  <= acca_left;
6457
                 right_ctrl <= zero_right;
6458
                 alu_ctrl   <= alu_ld8;
6459
                 cc_ctrl    <= latch_cc;
6460
                 acca_ctrl  <= load_hi_acca;
6461
                 accb_ctrl  <= load_accb;
6462
                                          -- idle bus
6463
                 addr_ctrl  <= idle_ad;
6464
                 dout_ctrl  <= md_lo_dout;
6465
                                          --
6466
                                          st_ctrl      <= idle_st;
6467
                                          return_state <= fetch_state;
6468
                                     next_state   <= mul0_state;
6469
 
6470
                                 when mul0_state =>
6471
                                     -- default
6472
                 ix_ctrl    <= latch_ix;
6473
                 iy_ctrl    <= latch_iy;
6474
                 up_ctrl    <= latch_up;
6475
                 sp_ctrl    <= latch_sp;
6476
                 pc_ctrl    <= latch_pc;
6477
                 iv_ctrl    <= latch_iv;
6478
                 dp_ctrl    <= latch_dp;
6479
                                op_ctrl    <= latch_op;
6480
                 pre_ctrl   <= latch_pre;
6481
                                     nmi_ctrl   <= latch_nmi;
6482
                 ea_ctrl    <= latch_ea;
6483
                                          -- if bit 0 of ea set, add accd to md
6484
                 left_ctrl  <= accd_left;
6485
                                          if ea(0) = '1' then
6486
                   right_ctrl <= md_right;
6487
                                          else
6488
                   right_ctrl <= zero_right;
6489
                                          end if;
6490
                 alu_ctrl   <= alu_mul;
6491
                 cc_ctrl    <= load_cc;
6492
                 acca_ctrl  <= load_hi_acca;
6493
                 accb_ctrl  <= load_accb;
6494
                 md_ctrl    <= shiftl_md;
6495
                                          -- idle bus
6496
                 addr_ctrl  <= idle_ad;
6497
                 dout_ctrl  <= md_lo_dout;
6498
                                          --
6499
                                          st_ctrl      <= idle_st;
6500
                                          return_state <= fetch_state;
6501
                                     next_state   <= mul1_state;
6502
 
6503
                                 when mul1_state =>
6504
                                     -- default
6505
                 ix_ctrl    <= latch_ix;
6506
                 iy_ctrl    <= latch_iy;
6507
                 up_ctrl    <= latch_up;
6508
                 sp_ctrl    <= latch_sp;
6509
                 pc_ctrl    <= latch_pc;
6510
                 iv_ctrl    <= latch_iv;
6511
                 dp_ctrl    <= latch_dp;
6512
                                op_ctrl    <= latch_op;
6513
                 pre_ctrl   <= latch_pre;
6514
                                     nmi_ctrl   <= latch_nmi;
6515
                 ea_ctrl    <= latch_ea;
6516
                                          -- if bit 1 of ea set, add accd to md
6517
                 left_ctrl  <= accd_left;
6518
                                          if ea(1) = '1' then
6519
                   right_ctrl <= md_right;
6520
                                          else
6521
                   right_ctrl <= zero_right;
6522
                                          end if;
6523
                 alu_ctrl   <= alu_mul;
6524
                 cc_ctrl    <= load_cc;
6525
                 acca_ctrl  <= load_hi_acca;
6526
                 accb_ctrl  <= load_accb;
6527
                 md_ctrl    <= shiftl_md;
6528
                                          -- idle bus
6529
                 addr_ctrl  <= idle_ad;
6530
                 dout_ctrl  <= md_lo_dout;
6531
                                          --
6532
                                          st_ctrl      <= idle_st;
6533
                                          return_state <= fetch_state;
6534
                                     next_state   <= mul2_state;
6535
 
6536
                                 when mul2_state =>
6537
                                     -- default
6538
                 ix_ctrl    <= latch_ix;
6539
                 iy_ctrl    <= latch_iy;
6540
                 up_ctrl    <= latch_up;
6541
                 sp_ctrl    <= latch_sp;
6542
                 pc_ctrl    <= latch_pc;
6543
                 iv_ctrl    <= latch_iv;
6544
                 dp_ctrl    <= latch_dp;
6545
                                op_ctrl    <= latch_op;
6546
                 pre_ctrl   <= latch_pre;
6547
                                     nmi_ctrl   <= latch_nmi;
6548
                 ea_ctrl    <= latch_ea;
6549
                                          -- if bit 2 of ea set, add accd to md
6550
                 left_ctrl  <= accd_left;
6551
                                          if ea(2) = '1' then
6552
                   right_ctrl <= md_right;
6553
                                          else
6554
                   right_ctrl <= zero_right;
6555
                                          end if;
6556
                 alu_ctrl   <= alu_mul;
6557
                 cc_ctrl    <= load_cc;
6558
                 acca_ctrl  <= load_hi_acca;
6559
                 accb_ctrl  <= load_accb;
6560
                 md_ctrl    <= shiftl_md;
6561
                                          -- idle bus
6562
                 addr_ctrl  <= idle_ad;
6563
                 dout_ctrl  <= md_lo_dout;
6564
                                          --
6565
                                          st_ctrl      <= idle_st;
6566
                                          return_state <= fetch_state;
6567
                                     next_state   <= mul3_state;
6568
 
6569
                                 when mul3_state =>
6570
                                     -- default
6571
                 ix_ctrl    <= latch_ix;
6572
                 iy_ctrl    <= latch_iy;
6573
                 up_ctrl    <= latch_up;
6574
                 sp_ctrl    <= latch_sp;
6575
                 pc_ctrl    <= latch_pc;
6576
                 iv_ctrl    <= latch_iv;
6577
                 dp_ctrl    <= latch_dp;
6578
                                op_ctrl    <= latch_op;
6579
                 pre_ctrl   <= latch_pre;
6580
                                     nmi_ctrl   <= latch_nmi;
6581
                 ea_ctrl    <= latch_ea;
6582
                                          -- if bit 3 of ea set, add accd to md
6583
                 left_ctrl  <= accd_left;
6584
                                          if ea(3) = '1' then
6585
                   right_ctrl <= md_right;
6586
                                          else
6587
                   right_ctrl <= zero_right;
6588
                                          end if;
6589
                 alu_ctrl   <= alu_mul;
6590
                 cc_ctrl    <= load_cc;
6591
                 acca_ctrl  <= load_hi_acca;
6592
                 accb_ctrl  <= load_accb;
6593
                 md_ctrl    <= shiftl_md;
6594
                                          -- idle bus
6595
                 addr_ctrl  <= idle_ad;
6596
                 dout_ctrl  <= md_lo_dout;
6597
                                          --
6598
                                          st_ctrl      <= idle_st;
6599
                                          return_state <= fetch_state;
6600
                                     next_state   <= mul4_state;
6601
 
6602
                                 when mul4_state =>
6603
                                     -- default
6604
                 ix_ctrl    <= latch_ix;
6605
                 iy_ctrl    <= latch_iy;
6606
                 up_ctrl    <= latch_up;
6607
                 sp_ctrl    <= latch_sp;
6608
                 pc_ctrl    <= latch_pc;
6609
                 iv_ctrl    <= latch_iv;
6610
                 dp_ctrl    <= latch_dp;
6611
                                op_ctrl    <= latch_op;
6612
                                     nmi_ctrl   <= latch_nmi;
6613
                 pre_ctrl   <= latch_pre;
6614
                 ea_ctrl    <= latch_ea;
6615
                                          -- if bit 4 of ea set, add accd to md
6616
                 left_ctrl  <= accd_left;
6617
                                          if ea(4) = '1' then
6618
                   right_ctrl <= md_right;
6619
                                          else
6620
                   right_ctrl <= zero_right;
6621
                                          end if;
6622
                 alu_ctrl   <= alu_mul;
6623
                 cc_ctrl    <= load_cc;
6624
                 acca_ctrl  <= load_hi_acca;
6625
                 accb_ctrl  <= load_accb;
6626
                 md_ctrl    <= shiftl_md;
6627
                                          -- idle bus
6628
                 addr_ctrl  <= idle_ad;
6629
                 dout_ctrl  <= md_lo_dout;
6630
                                          --
6631
                                          st_ctrl      <= idle_st;
6632
                                          return_state <= fetch_state;
6633
                                     next_state   <= mul5_state;
6634
 
6635
                                 when mul5_state =>
6636
                                     -- default
6637
                 ix_ctrl    <= latch_ix;
6638
                 iy_ctrl    <= latch_iy;
6639
                 up_ctrl    <= latch_up;
6640
                 sp_ctrl    <= latch_sp;
6641
                 pc_ctrl    <= latch_pc;
6642
                 iv_ctrl    <= latch_iv;
6643
                 dp_ctrl    <= latch_dp;
6644
                                op_ctrl    <= latch_op;
6645
                 pre_ctrl   <= latch_pre;
6646
                                     nmi_ctrl   <= latch_nmi;
6647
                 ea_ctrl    <= latch_ea;
6648
                                          -- if bit 5 of ea set, add accd to md
6649
                 left_ctrl  <= accd_left;
6650
                                          if ea(5) = '1' then
6651
                   right_ctrl <= md_right;
6652
                                          else
6653
                   right_ctrl <= zero_right;
6654
                                          end if;
6655
                 alu_ctrl   <= alu_mul;
6656
                 cc_ctrl    <= load_cc;
6657
                 acca_ctrl  <= load_hi_acca;
6658
                 accb_ctrl  <= load_accb;
6659
                 md_ctrl    <= shiftl_md;
6660
                                          -- idle bus
6661
                 addr_ctrl  <= idle_ad;
6662
                 dout_ctrl  <= md_lo_dout;
6663
                                          --
6664
                                          st_ctrl      <= idle_st;
6665
                                          return_state <= fetch_state;
6666
                                     next_state   <= mul6_state;
6667
 
6668
                                 when mul6_state =>
6669
                                     -- default
6670
                 ix_ctrl    <= latch_ix;
6671
                 iy_ctrl    <= latch_iy;
6672
                 up_ctrl    <= latch_up;
6673
                 sp_ctrl    <= latch_sp;
6674
                 pc_ctrl    <= latch_pc;
6675
                 iv_ctrl    <= latch_iv;
6676
                 dp_ctrl    <= latch_dp;
6677
                                op_ctrl    <= latch_op;
6678
                 pre_ctrl   <= latch_pre;
6679
                                     nmi_ctrl   <= latch_nmi;
6680
                 ea_ctrl    <= latch_ea;
6681
                                          -- if bit 6 of ea set, add accd to md
6682
                 left_ctrl  <= accd_left;
6683
                                          if ea(6) = '1' then
6684
                   right_ctrl <= md_right;
6685
                                          else
6686
                   right_ctrl <= zero_right;
6687
                                          end if;
6688
                 alu_ctrl   <= alu_mul;
6689
                 cc_ctrl    <= load_cc;
6690
                 acca_ctrl  <= load_hi_acca;
6691
                 accb_ctrl  <= load_accb;
6692
                 md_ctrl    <= shiftl_md;
6693
                                          -- idle bus
6694
                 addr_ctrl  <= idle_ad;
6695
                 dout_ctrl  <= md_lo_dout;
6696
                                          --
6697
                                          st_ctrl      <= idle_st;
6698
                                          return_state <= fetch_state;
6699
                                     next_state   <= mul7_state;
6700
 
6701
                                 when mul7_state =>
6702
                                     -- default
6703
                 ix_ctrl    <= latch_ix;
6704
                 iy_ctrl    <= latch_iy;
6705
                 up_ctrl    <= latch_up;
6706
                 sp_ctrl    <= latch_sp;
6707
                 pc_ctrl    <= latch_pc;
6708
                 iv_ctrl    <= latch_iv;
6709
                 dp_ctrl    <= latch_dp;
6710
                                op_ctrl    <= latch_op;
6711
                 pre_ctrl   <= latch_pre;
6712
                                     nmi_ctrl   <= latch_nmi;
6713
                 ea_ctrl    <= latch_ea;
6714
                                          -- if bit 7 of ea set, add accd to md
6715
                 left_ctrl  <= accd_left;
6716
                                          if ea(7) = '1' then
6717
                   right_ctrl <= md_right;
6718
                                          else
6719
                   right_ctrl <= zero_right;
6720
                                          end if;
6721
                 alu_ctrl   <= alu_mul;
6722
                 cc_ctrl    <= load_cc;
6723
                 acca_ctrl  <= load_hi_acca;
6724
                 accb_ctrl  <= load_accb;
6725
                 md_ctrl    <= shiftl_md;
6726
                                          -- idle bus
6727
                 addr_ctrl  <= idle_ad;
6728
                 dout_ctrl  <= md_lo_dout;
6729
                                          --
6730
                                          st_ctrl      <= idle_st;
6731
                                          return_state <= fetch_state;
6732
                                     next_state   <= fetch_state;
6733
 
6734
                          --
6735
                          -- Enter here on pushs
6736
                          -- ea holds post byte
6737
                          --
6738
                          when pshs_state =>
6739
                                 -- default
6740
             cc_ctrl    <= latch_cc;
6741
             acca_ctrl  <= latch_acca;
6742
             accb_ctrl  <= latch_accb;
6743
             dp_ctrl    <= latch_dp;
6744
             ix_ctrl    <= latch_ix;
6745
             iy_ctrl    <= latch_iy;
6746
             up_ctrl    <= latch_up;
6747
             pc_ctrl    <= latch_pc;
6748
             md_ctrl    <= latch_md;
6749
             iv_ctrl    <= latch_iv;
6750
             dp_ctrl    <= latch_dp;
6751
                            op_ctrl    <= latch_op;
6752
             pre_ctrl   <= latch_pre;
6753
                                 nmi_ctrl   <= latch_nmi;
6754
             ea_ctrl    <= latch_ea;
6755
             -- decrement sp if any registers to be pushed
6756
             left_ctrl  <= sp_left;
6757
             right_ctrl <= one_right;
6758
             alu_ctrl   <= alu_sub16;
6759
                                 if ea(7 downto 0) = "00000000" then
6760
               sp_ctrl    <= latch_sp;
6761
                                 else
6762
               sp_ctrl    <= load_sp;
6763
                                 end if;
6764
                                 -- write idle bus
6765
             addr_ctrl  <= idle_ad;
6766
                            dout_ctrl  <= md_lo_dout;
6767
                                 --
6768
                                 st_ctrl      <= idle_st;
6769
                                 return_state <= fetch_state;
6770
                                 if ea(7) = '1' then
6771
               next_state <= pshs_pcl_state;
6772
                                 elsif ea(6) = '1' then
6773
               next_state <= pshs_upl_state;
6774
                                 elsif ea(5) = '1' then
6775
                                   next_state <= pshs_iyl_state;
6776
                                 elsif ea(4) = '1' then
6777
                                   next_state <= pshs_ixl_state;
6778
                                 elsif ea(3) = '1' then
6779
                                   next_state <= pshs_dp_state;
6780
                                 elsif ea(2) = '1' then
6781
                                   next_state <= pshs_accb_state;
6782
                                 elsif ea(1) = '1' then
6783
                                   next_state <= pshs_acca_state;
6784
                                 elsif ea(0) = '1' then
6785
                                   next_state <= pshs_cc_state;
6786
                                 else
6787
                                   next_state <= fetch_state;
6788
                                 end if;
6789
 
6790
                          when pshs_pcl_state =>
6791
                                 -- default
6792
             cc_ctrl    <= latch_cc;
6793
             acca_ctrl  <= latch_acca;
6794
             accb_ctrl  <= latch_accb;
6795
             dp_ctrl    <= latch_dp;
6796
             ix_ctrl    <= latch_ix;
6797
             iy_ctrl    <= latch_iy;
6798
             up_ctrl    <= latch_up;
6799
             pc_ctrl    <= latch_pc;
6800
             md_ctrl    <= latch_md;
6801
             iv_ctrl    <= latch_iv;
6802
             dp_ctrl    <= latch_dp;
6803
                            op_ctrl    <= latch_op;
6804
             pre_ctrl   <= latch_pre;
6805
                                 nmi_ctrl   <= latch_nmi;
6806
             ea_ctrl    <= latch_ea;
6807
             -- decrement sp
6808
             left_ctrl  <= sp_left;
6809
             right_ctrl <= one_right;
6810
             alu_ctrl   <= alu_sub16;
6811
             sp_ctrl    <= load_sp;
6812
                                 -- write pc low
6813
             addr_ctrl  <= pushs_ad;
6814
                            dout_ctrl  <= pc_lo_dout;
6815
                                 --
6816
                                 st_ctrl      <= idle_st;
6817
                                 return_state <= fetch_state;
6818
             next_state   <= pshs_pch_state;
6819
 
6820
                          when pshs_pch_state =>
6821
             cc_ctrl    <= latch_cc;
6822
             acca_ctrl  <= latch_acca;
6823
             accb_ctrl  <= latch_accb;
6824
             dp_ctrl    <= latch_dp;
6825
             ix_ctrl    <= latch_ix;
6826
             iy_ctrl    <= latch_iy;
6827
             up_ctrl    <= latch_up;
6828
             pc_ctrl    <= latch_pc;
6829
             md_ctrl    <= latch_md;
6830
             iv_ctrl    <= latch_iv;
6831
             dp_ctrl    <= latch_dp;
6832
                            op_ctrl    <= latch_op;
6833
             pre_ctrl   <= latch_pre;
6834
                                 nmi_ctrl   <= latch_nmi;
6835
             ea_ctrl    <= latch_ea;
6836
             -- decrement sp
6837
             left_ctrl  <= sp_left;
6838
             right_ctrl <= one_right;
6839
             alu_ctrl   <= alu_sub16;
6840
                                 if ea(6 downto 0) = "0000000" then
6841
               sp_ctrl    <= latch_sp;
6842
                                 else
6843
               sp_ctrl    <= load_sp;
6844
                                 end if;
6845
                                 -- write pc hi
6846
             addr_ctrl  <= pushs_ad;
6847
                            dout_ctrl  <= pc_hi_dout;
6848
                                 --
6849
                                 st_ctrl      <= idle_st;
6850
                                 return_state <= fetch_state;
6851
                                 if ea(6) = '1' then
6852
               next_state <= pshs_upl_state;
6853
                                 elsif ea(5) = '1' then
6854
                                   next_state <= pshs_iyl_state;
6855
                                 elsif ea(4) = '1' then
6856
                                   next_state <= pshs_ixl_state;
6857
                                 elsif ea(3) = '1' then
6858
                                   next_state <= pshs_dp_state;
6859
                                 elsif ea(2) = '1' then
6860
                                   next_state <= pshs_accb_state;
6861
                                 elsif ea(1) = '1' then
6862
                                   next_state <= pshs_acca_state;
6863
                                 elsif ea(0) = '1' then
6864
                                   next_state <= pshs_cc_state;
6865
                                 else
6866
                                   next_state <= fetch_state;
6867
                                 end if;
6868
 
6869
 
6870
                          when pshs_upl_state =>
6871
                                 -- default
6872
             cc_ctrl    <= latch_cc;
6873
             acca_ctrl  <= latch_acca;
6874
             accb_ctrl  <= latch_accb;
6875
             dp_ctrl    <= latch_dp;
6876
             ix_ctrl    <= latch_ix;
6877
             iy_ctrl    <= latch_iy;
6878
             up_ctrl    <= latch_up;
6879
             pc_ctrl    <= latch_pc;
6880
             md_ctrl    <= latch_md;
6881
             iv_ctrl    <= latch_iv;
6882
                            op_ctrl    <= latch_op;
6883
             pre_ctrl   <= latch_pre;
6884
                                 nmi_ctrl   <= latch_nmi;
6885
             ea_ctrl    <= latch_ea;
6886
             -- decrement sp
6887
             left_ctrl  <= sp_left;
6888
             right_ctrl <= one_right;
6889
             alu_ctrl   <= alu_sub16;
6890
             sp_ctrl    <= load_sp;
6891
                                 -- write pc low
6892
             addr_ctrl  <= pushs_ad;
6893
                            dout_ctrl  <= up_lo_dout;
6894
                                 --
6895
                                 st_ctrl      <= idle_st;
6896
                                 return_state <= fetch_state;
6897
             next_state   <= pshs_uph_state;
6898
 
6899
                          when pshs_uph_state =>
6900
             cc_ctrl    <= latch_cc;
6901
             acca_ctrl  <= latch_acca;
6902
             accb_ctrl  <= latch_accb;
6903
             dp_ctrl    <= latch_dp;
6904
             ix_ctrl    <= latch_ix;
6905
             iy_ctrl    <= latch_iy;
6906
             up_ctrl    <= latch_up;
6907
             pc_ctrl    <= latch_pc;
6908
             md_ctrl    <= latch_md;
6909
             iv_ctrl    <= latch_iv;
6910
                            op_ctrl    <= latch_op;
6911
             pre_ctrl   <= latch_pre;
6912
                                 nmi_ctrl   <= latch_nmi;
6913
             ea_ctrl    <= latch_ea;
6914
             -- decrement sp
6915
             left_ctrl  <= sp_left;
6916
             right_ctrl <= one_right;
6917
             alu_ctrl   <= alu_sub16;
6918
                                 if ea(5 downto 0) = "000000" then
6919
               sp_ctrl    <= latch_sp;
6920
                                 else
6921
               sp_ctrl    <= load_sp;
6922
                                 end if;
6923
                                 -- write pc hi
6924
             addr_ctrl  <= pushs_ad;
6925
                            dout_ctrl  <= up_hi_dout;
6926
                                 --
6927
                                 st_ctrl      <= idle_st;
6928
                                 return_state <= fetch_state;
6929
                                 if ea(5) = '1' then
6930
                                   next_state   <= pshs_iyl_state;
6931
                                 elsif ea(4) = '1' then
6932
                                   next_state   <= pshs_ixl_state;
6933
                                 elsif ea(3) = '1' then
6934
                                   next_state   <= pshs_dp_state;
6935
                                 elsif ea(2) = '1' then
6936
                                   next_state   <= pshs_accb_state;
6937
                                 elsif ea(1) = '1' then
6938
                                   next_state   <= pshs_acca_state;
6939
                                 elsif ea(0) = '1' then
6940
                                   next_state   <= pshs_cc_state;
6941
                                 else
6942
                                   next_state   <= fetch_state;
6943
                                 end if;
6944
 
6945
                          when pshs_iyl_state =>
6946
                                 -- default
6947
             cc_ctrl    <= latch_cc;
6948
             acca_ctrl  <= latch_acca;
6949
             accb_ctrl  <= latch_accb;
6950
             dp_ctrl    <= latch_dp;
6951
             ix_ctrl    <= latch_ix;
6952
             iy_ctrl    <= latch_iy;
6953
             up_ctrl    <= latch_up;
6954
             pc_ctrl    <= latch_pc;
6955
             md_ctrl    <= latch_md;
6956
             iv_ctrl    <= latch_iv;
6957
                            op_ctrl    <= latch_op;
6958
             pre_ctrl   <= latch_pre;
6959
                                 nmi_ctrl   <= latch_nmi;
6960
             ea_ctrl    <= latch_ea;
6961
             -- decrement sp
6962
             left_ctrl  <= sp_left;
6963
             right_ctrl <= one_right;
6964
             alu_ctrl   <= alu_sub16;
6965
             sp_ctrl    <= load_sp;
6966
                                 -- write iy low
6967
             addr_ctrl  <= pushs_ad;
6968
                            dout_ctrl  <= iy_lo_dout;
6969
                                 --
6970
                                 st_ctrl      <= idle_st;
6971
                                 return_state <= fetch_state;
6972
             next_state   <= pshs_iyh_state;
6973
 
6974
                          when pshs_iyh_state =>
6975
                                 -- default registers
6976
             cc_ctrl    <= latch_cc;
6977
             acca_ctrl  <= latch_acca;
6978
             accb_ctrl  <= latch_accb;
6979
             dp_ctrl    <= latch_dp;
6980
             ix_ctrl    <= latch_ix;
6981
             iy_ctrl    <= latch_iy;
6982
             up_ctrl    <= latch_up;
6983
             pc_ctrl    <= latch_pc;
6984
             md_ctrl    <= latch_md;
6985
             iv_ctrl    <= latch_iv;
6986
                            op_ctrl    <= latch_op;
6987
             pre_ctrl   <= latch_pre;
6988
                                 nmi_ctrl   <= latch_nmi;
6989
             ea_ctrl    <= latch_ea;
6990
             -- decrement sp
6991
             left_ctrl  <= sp_left;
6992
             right_ctrl <= one_right;
6993
             alu_ctrl   <= alu_sub16;
6994
                                 if ea(4 downto 0) = "00000" then
6995
               sp_ctrl    <= latch_sp;
6996
                                 else
6997
               sp_ctrl    <= load_sp;
6998
                                 end if;
6999
                                 -- write iy hi
7000
             addr_ctrl  <= pushs_ad;
7001
                            dout_ctrl  <= iy_hi_dout;
7002
                                 --
7003
                                 st_ctrl      <= idle_st;
7004
                                 return_state <= fetch_state;
7005
                                 if ea(4) = '1' then
7006
                                   next_state   <= pshs_ixl_state;
7007
                                 elsif ea(3) = '1' then
7008
                                   next_state   <= pshs_dp_state;
7009
                                 elsif ea(2) = '1' then
7010
                                   next_state   <= pshs_accb_state;
7011
                                 elsif ea(1) = '1' then
7012
                                   next_state   <= pshs_acca_state;
7013
                                 elsif ea(0) = '1' then
7014
                                   next_state   <= pshs_cc_state;
7015
                                 else
7016
                                   next_state   <= fetch_state;
7017
                                 end if;
7018
 
7019
                          when pshs_ixl_state =>
7020
                                 -- default
7021
             cc_ctrl    <= latch_cc;
7022
             acca_ctrl  <= latch_acca;
7023
             accb_ctrl  <= latch_accb;
7024
             dp_ctrl    <= latch_dp;
7025
             ix_ctrl    <= latch_ix;
7026
             iy_ctrl    <= latch_iy;
7027
             up_ctrl    <= latch_up;
7028
             pc_ctrl    <= latch_pc;
7029
             md_ctrl    <= latch_md;
7030
             iv_ctrl    <= latch_iv;
7031
                            op_ctrl    <= latch_op;
7032
             pre_ctrl   <= latch_pre;
7033
                                 nmi_ctrl   <= latch_nmi;
7034
             ea_ctrl    <= latch_ea;
7035
             -- decrement sp
7036
             left_ctrl  <= sp_left;
7037
             right_ctrl <= one_right;
7038
             alu_ctrl   <= alu_sub16;
7039
             sp_ctrl    <= load_sp;
7040
                                 -- write ix low
7041
             addr_ctrl  <= pushs_ad;
7042
                            dout_ctrl  <= ix_lo_dout;
7043
                                 --
7044
                                 st_ctrl      <= idle_st;
7045
                                 return_state <= fetch_state;
7046
             next_state   <= pshs_ixh_state;
7047
 
7048
                          when pshs_ixh_state =>
7049
                                 -- default registers
7050
             cc_ctrl    <= latch_cc;
7051
             acca_ctrl  <= latch_acca;
7052
             accb_ctrl  <= latch_accb;
7053
             dp_ctrl    <= latch_dp;
7054
             ix_ctrl    <= latch_ix;
7055
             iy_ctrl    <= latch_iy;
7056
             up_ctrl    <= latch_up;
7057
             pc_ctrl    <= latch_pc;
7058
             md_ctrl    <= latch_md;
7059
             iv_ctrl    <= latch_iv;
7060
                            op_ctrl    <= latch_op;
7061
             pre_ctrl   <= latch_pre;
7062
                                 nmi_ctrl   <= latch_nmi;
7063
             ea_ctrl    <= latch_ea;
7064
             -- decrement sp
7065
             left_ctrl  <= sp_left;
7066
             right_ctrl <= one_right;
7067
             alu_ctrl   <= alu_sub16;
7068
                                 if ea(3 downto 0) = "0000" then
7069
               sp_ctrl    <= latch_sp;
7070
                                 else
7071
               sp_ctrl    <= load_sp;
7072
                                 end if;
7073
                                 -- write ix hi
7074
             addr_ctrl  <= pushs_ad;
7075
                            dout_ctrl  <= ix_hi_dout;
7076
                                 --
7077
                                 st_ctrl      <= idle_st;
7078
                                 return_state <= fetch_state;
7079
                                 if ea(3) = '1' then
7080
                                   next_state   <= pshs_dp_state;
7081
                                 elsif ea(2) = '1' then
7082
                                   next_state   <= pshs_accb_state;
7083
                                 elsif ea(1) = '1' then
7084
                                   next_state   <= pshs_acca_state;
7085
                                 elsif ea(0) = '1' then
7086
                                   next_state   <= pshs_cc_state;
7087
                                 else
7088
                                   next_state   <= fetch_state;
7089
                                 end if;
7090
 
7091
                          when pshs_dp_state =>
7092
                                 -- default registers
7093
             cc_ctrl    <= latch_cc;
7094
             acca_ctrl  <= latch_acca;
7095
             accb_ctrl  <= latch_accb;
7096
             dp_ctrl    <= latch_dp;
7097
             ix_ctrl    <= latch_ix;
7098
             iy_ctrl    <= latch_iy;
7099
             up_ctrl    <= latch_up;
7100
             pc_ctrl    <= latch_pc;
7101
             md_ctrl    <= latch_md;
7102
             iv_ctrl    <= latch_iv;
7103
                            op_ctrl    <= latch_op;
7104
             pre_ctrl   <= latch_pre;
7105
                                 nmi_ctrl   <= latch_nmi;
7106
             ea_ctrl    <= latch_ea;
7107
             -- decrement sp
7108
             left_ctrl  <= sp_left;
7109
             right_ctrl <= one_right;
7110
             alu_ctrl   <= alu_sub16;
7111
                                 if ea(2 downto 0) = "000" then
7112
               sp_ctrl    <= latch_sp;
7113
                                 else
7114
               sp_ctrl    <= load_sp;
7115
                                 end if;
7116
                                 -- write dp
7117
             addr_ctrl  <= pushs_ad;
7118
                            dout_ctrl  <= dp_dout;
7119
                                 --
7120
                                 st_ctrl      <= idle_st;
7121
                                 return_state <= fetch_state;
7122
                                 if ea(2) = '1' then
7123
                                   next_state   <= pshs_accb_state;
7124
                                 elsif ea(1) = '1' then
7125
                                   next_state   <= pshs_acca_state;
7126
                                 elsif ea(0) = '1' then
7127
                                   next_state   <= pshs_cc_state;
7128
                                 else
7129
                                   next_state   <= fetch_state;
7130
                                 end if;
7131
 
7132
                          when pshs_accb_state =>
7133
                                 -- default registers
7134
             cc_ctrl    <= latch_cc;
7135
             acca_ctrl  <= latch_acca;
7136
             accb_ctrl  <= latch_accb;
7137
             dp_ctrl    <= latch_dp;
7138
             ix_ctrl    <= latch_ix;
7139
             iy_ctrl    <= latch_iy;
7140
             up_ctrl    <= latch_up;
7141
             pc_ctrl    <= latch_pc;
7142
             md_ctrl    <= latch_md;
7143
             iv_ctrl    <= latch_iv;
7144
                            op_ctrl    <= latch_op;
7145
             pre_ctrl   <= latch_pre;
7146
                                 nmi_ctrl   <= latch_nmi;
7147
             ea_ctrl    <= latch_ea;
7148
             -- decrement sp
7149
             left_ctrl  <= sp_left;
7150
             right_ctrl <= one_right;
7151
             alu_ctrl   <= alu_sub16;
7152
                                 if ea(1 downto 0) = "00" then
7153
               sp_ctrl    <= latch_sp;
7154
                                 else
7155
               sp_ctrl    <= load_sp;
7156
                                 end if;
7157
                                 -- write accb
7158
             addr_ctrl  <= pushs_ad;
7159
                            dout_ctrl  <= accb_dout;
7160
                                 --
7161
                                 st_ctrl      <= idle_st;
7162
                                 return_state <= fetch_state;
7163
                                 if ea(1) = '1' then
7164
                                   next_state   <= pshs_acca_state;
7165
                                 elsif ea(0) = '1' then
7166
                                   next_state   <= pshs_cc_state;
7167
                                 else
7168
                                   next_state   <= fetch_state;
7169
                                 end if;
7170
 
7171
                          when pshs_acca_state =>
7172
                                 -- default registers
7173
             cc_ctrl    <= latch_cc;
7174
             acca_ctrl  <= latch_acca;
7175
             accb_ctrl  <= latch_accb;
7176
                                 dp_ctrl    <= latch_dp;
7177
             ix_ctrl    <= latch_ix;
7178
             iy_ctrl    <= latch_iy;
7179
             up_ctrl    <= latch_up;
7180
             pc_ctrl    <= latch_pc;
7181
             md_ctrl    <= latch_md;
7182
             iv_ctrl    <= latch_iv;
7183
                            op_ctrl    <= latch_op;
7184
             pre_ctrl   <= latch_pre;
7185
                                 nmi_ctrl   <= latch_nmi;
7186
             ea_ctrl    <= latch_ea;
7187
             -- decrement sp
7188
             left_ctrl  <= sp_left;
7189
             right_ctrl <= one_right;
7190
             alu_ctrl   <= alu_sub16;
7191
                                 if ea(0) = '1' then
7192
               sp_ctrl    <= load_sp;
7193
                                 else
7194
               sp_ctrl    <= latch_sp;
7195
                                 end if;
7196
                                 -- write acca
7197
             addr_ctrl  <= pushs_ad;
7198
                            dout_ctrl  <= acca_dout;
7199
                                 --
7200
                                 st_ctrl      <= idle_st;
7201
                                 return_state <= fetch_state;
7202
                                 if ea(0) = '1' then
7203
                                   next_state   <= pshs_cc_state;
7204
                                 else
7205
                                   next_state   <= fetch_state;
7206
                                 end if;
7207
 
7208
                          when pshs_cc_state =>
7209
                                 -- default registers
7210
             cc_ctrl    <= latch_cc;
7211
             acca_ctrl  <= latch_acca;
7212
             accb_ctrl  <= latch_accb;
7213
                                 dp_ctrl    <= latch_dp;
7214
             ix_ctrl    <= latch_ix;
7215
             iy_ctrl    <= latch_iy;
7216
             up_ctrl    <= latch_up;
7217
             pc_ctrl    <= latch_pc;
7218
             md_ctrl    <= latch_md;
7219
             iv_ctrl    <= latch_iv;
7220
                            op_ctrl    <= latch_op;
7221
             pre_ctrl   <= latch_pre;
7222
                                 nmi_ctrl   <= latch_nmi;
7223
             ea_ctrl    <= latch_ea;
7224
             -- idle sp
7225
             left_ctrl  <= sp_left;
7226
             right_ctrl <= one_right;
7227
             alu_ctrl   <= alu_nop;
7228
             sp_ctrl    <= latch_sp;
7229
                                 -- write cc
7230
             addr_ctrl  <= pushs_ad;
7231
                            dout_ctrl  <= cc_dout;
7232
                                 --
7233
                                 st_ctrl      <= idle_st;
7234
                                 return_state <= fetch_state;
7235
             next_state   <= fetch_state;
7236
 
7237
                          --
7238
                          -- enter here on PULS
7239
                          -- ea hold register mask
7240
                          --
7241
                          when puls_state =>
7242
                                 -- default registers
7243
             cc_ctrl    <= latch_cc;
7244
             acca_ctrl  <= latch_acca;
7245
             accb_ctrl  <= latch_accb;
7246
                                 dp_ctrl    <= latch_dp;
7247
             ix_ctrl    <= latch_ix;
7248
             iy_ctrl    <= latch_iy;
7249
             up_ctrl    <= latch_up;
7250
             pc_ctrl    <= latch_pc;
7251
             md_ctrl    <= latch_md;
7252
             iv_ctrl    <= latch_iv;
7253
                            op_ctrl    <= latch_op;
7254
             pre_ctrl   <= latch_pre;
7255
                                 nmi_ctrl   <= latch_nmi;
7256
             ea_ctrl    <= latch_ea;
7257
                                 -- idle SP
7258
             left_ctrl  <= sp_left;
7259
             right_ctrl <= one_right;
7260
             alu_ctrl   <= alu_add16;
7261
             sp_ctrl    <= latch_sp;
7262
                                 -- idle bus
7263
             addr_ctrl  <= idle_ad;
7264
             dout_ctrl  <= md_lo_dout;
7265
                                 --
7266
                                 st_ctrl      <= idle_st;
7267
                                 return_state <= fetch_state;
7268
                                 if ea(0) = '1' then
7269
                                   next_state <= puls_cc_state;
7270
                                 elsif ea(1) = '1' then
7271
                                   next_state <= puls_acca_state;
7272
                                 elsif ea(2) = '1' then
7273
                                   next_state <= puls_accb_state;
7274
                                 elsif ea(3) = '1' then
7275
                                   next_state <= puls_dp_state;
7276
                                 elsif ea(4) = '1' then
7277
                                   next_state <= puls_ixh_state;
7278
                                 elsif ea(5) = '1' then
7279
                                   next_state <= puls_iyh_state;
7280
                                 elsif ea(6) = '1' then
7281
               next_state <= puls_uph_state;
7282
                                 elsif ea(7) = '1' then
7283
               next_state <= puls_pch_state;
7284
                                 else
7285
                                   next_state <= fetch_state;
7286
                                 end if;
7287
 
7288
                          when puls_cc_state =>
7289
                                 -- default registers
7290
             acca_ctrl  <= latch_acca;
7291
             accb_ctrl  <= latch_accb;
7292
                                 dp_ctrl    <= latch_dp;
7293
             ix_ctrl    <= latch_ix;
7294
             iy_ctrl    <= latch_iy;
7295
             up_ctrl    <= latch_up;
7296
             pc_ctrl    <= latch_pc;
7297
             md_ctrl    <= latch_md;
7298
             iv_ctrl    <= latch_iv;
7299
                            op_ctrl    <= latch_op;
7300
             pre_ctrl   <= latch_pre;
7301
                                 nmi_ctrl   <= latch_nmi;
7302
             ea_ctrl    <= latch_ea;
7303
                                 -- Increment SP
7304
             left_ctrl  <= sp_left;
7305
             right_ctrl <= one_right;
7306
             alu_ctrl   <= alu_add16;
7307
             sp_ctrl    <= load_sp;
7308
                                 -- read cc
7309
             cc_ctrl    <= pull_cc;
7310
             addr_ctrl  <= pulls_ad;
7311
             dout_ctrl  <= cc_dout;
7312
                                 --
7313
                                 st_ctrl      <= idle_st;
7314
                                 return_state <= fetch_state;
7315
                                 if ea(1) = '1' then
7316
                                   next_state <= puls_acca_state;
7317
                                 elsif ea(2) = '1' then
7318
                                   next_state <= puls_accb_state;
7319
                                 elsif ea(3) = '1' then
7320
                                   next_state <= puls_dp_state;
7321
                                 elsif ea(4) = '1' then
7322
                                   next_state <= puls_ixh_state;
7323
                                 elsif ea(5) = '1' then
7324
                                   next_state <= puls_iyh_state;
7325
                                 elsif ea(6) = '1' then
7326
               next_state <= puls_uph_state;
7327
                                 elsif ea(7) = '1' then
7328
               next_state <= puls_pch_state;
7329
                                 else
7330
                                   next_state <= fetch_state;
7331
                                 end if;
7332
 
7333
                          when puls_acca_state =>
7334
                                 -- default registers
7335
             cc_ctrl    <= latch_cc;
7336
             accb_ctrl  <= latch_accb;
7337
                                 dp_ctrl    <= latch_dp;
7338
             ix_ctrl    <= latch_ix;
7339
             iy_ctrl    <= latch_iy;
7340
             up_ctrl    <= latch_up;
7341
             pc_ctrl    <= latch_pc;
7342
             md_ctrl    <= latch_md;
7343
             iv_ctrl    <= latch_iv;
7344
                            op_ctrl    <= latch_op;
7345
             pre_ctrl   <= latch_pre;
7346
                                 nmi_ctrl   <= latch_nmi;
7347
             ea_ctrl    <= latch_ea;
7348
                                 -- Increment SP
7349
             left_ctrl  <= sp_left;
7350
             right_ctrl <= one_right;
7351
             alu_ctrl   <= alu_add16;
7352
             sp_ctrl    <= load_sp;
7353
                                 -- read acca
7354
                                 acca_ctrl  <= pull_acca;
7355
             addr_ctrl  <= pulls_ad;
7356
             dout_ctrl  <= acca_dout;
7357
                                 --
7358
                                 st_ctrl      <= idle_st;
7359
                                 return_state <= fetch_state;
7360
                                 if ea(2) = '1' then
7361
                                   next_state <= puls_accb_state;
7362
                                 elsif ea(3) = '1' then
7363
                                   next_state <= puls_dp_state;
7364
                                 elsif ea(4) = '1' then
7365
                                   next_state <= puls_ixh_state;
7366
                                 elsif ea(5) = '1' then
7367
                                   next_state <= puls_iyh_state;
7368
                                 elsif ea(6) = '1' then
7369
               next_state <= puls_uph_state;
7370
                                 elsif ea(7) = '1' then
7371
               next_state <= puls_pch_state;
7372
                                 else
7373
                                   next_state <= fetch_state;
7374
                                 end if;
7375
 
7376
                          when puls_accb_state =>
7377
                                 -- default
7378
             cc_ctrl    <= latch_cc;
7379
             acca_ctrl  <= latch_acca;
7380
                                 dp_ctrl    <= latch_dp;
7381
             ix_ctrl    <= latch_ix;
7382
             iy_ctrl    <= latch_iy;
7383
             up_ctrl    <= latch_up;
7384
             pc_ctrl    <= latch_pc;
7385
             md_ctrl    <= latch_md;
7386
             iv_ctrl    <= latch_iv;
7387
                            op_ctrl    <= latch_op;
7388
             pre_ctrl   <= latch_pre;
7389
                                 nmi_ctrl   <= latch_nmi;
7390
             ea_ctrl    <= latch_ea;
7391
                                 -- Increment SP
7392
             left_ctrl  <= sp_left;
7393
             right_ctrl <= one_right;
7394
             alu_ctrl   <= alu_add16;
7395
             sp_ctrl    <= load_sp;
7396
                                 -- read accb
7397
                                 accb_ctrl  <= pull_accb;
7398
             addr_ctrl  <= pulls_ad;
7399
             dout_ctrl  <= accb_dout;
7400
                                 --
7401
                                 st_ctrl      <= idle_st;
7402
                                 return_state <= fetch_state;
7403
                                 if ea(3) = '1' then
7404
                                   next_state <= puls_dp_state;
7405
                                 elsif ea(4) = '1' then
7406
                                   next_state <= puls_ixh_state;
7407
                                 elsif ea(5) = '1' then
7408
                                   next_state <= puls_iyh_state;
7409
                                 elsif ea(6) = '1' then
7410
               next_state <= puls_uph_state;
7411
                                 elsif ea(7) = '1' then
7412
               next_state <= puls_pch_state;
7413
                                 else
7414
                                   next_state <= fetch_state;
7415
                                 end if;
7416
 
7417
                          when puls_dp_state =>
7418
                                 -- default
7419
             cc_ctrl    <= latch_cc;
7420
             acca_ctrl  <= latch_acca;
7421
             accb_ctrl  <= latch_accb;
7422
             ix_ctrl    <= latch_ix;
7423
             iy_ctrl    <= latch_iy;
7424
             up_ctrl    <= latch_up;
7425
             pc_ctrl    <= latch_pc;
7426
             md_ctrl    <= latch_md;
7427
             iv_ctrl    <= latch_iv;
7428
                            op_ctrl    <= latch_op;
7429
             pre_ctrl   <= latch_pre;
7430
                                 nmi_ctrl   <= latch_nmi;
7431
             ea_ctrl    <= latch_ea;
7432
                                 -- idle sp
7433
             left_ctrl  <= sp_left;
7434
             right_ctrl <= one_right;
7435
             alu_ctrl   <= alu_add16;
7436
             sp_ctrl    <= load_sp;
7437
                                 -- read dp
7438
                                 dp_ctrl    <= pull_dp;
7439
             addr_ctrl  <= pulls_ad;
7440
             dout_ctrl  <= dp_dout;
7441
                                 --
7442
                                 st_ctrl      <= idle_st;
7443
                                 return_state <= fetch_state;
7444
                                 if ea(4) = '1' then
7445
                                   next_state <= puls_ixh_state;
7446
                                 elsif ea(5) = '1' then
7447
                                   next_state <= puls_iyh_state;
7448
                                 elsif ea(6) = '1' then
7449
               next_state <= puls_uph_state;
7450
                                 elsif ea(7) = '1' then
7451
               next_state <= puls_pch_state;
7452
                                 else
7453
                                   next_state <= fetch_state;
7454
                                 end if;
7455
 
7456
                          when puls_ixh_state =>
7457
                                 -- default
7458
             cc_ctrl    <= latch_cc;
7459
             acca_ctrl  <= latch_acca;
7460
             accb_ctrl  <= latch_accb;
7461
                                 dp_ctrl    <= latch_dp;
7462
             iy_ctrl    <= latch_iy;
7463
             up_ctrl    <= latch_up;
7464
             pc_ctrl    <= latch_pc;
7465
             md_ctrl    <= latch_md;
7466
             iv_ctrl    <= latch_iv;
7467
                            op_ctrl    <= latch_op;
7468
             pre_ctrl   <= latch_pre;
7469
                                 nmi_ctrl   <= latch_nmi;
7470
             ea_ctrl    <= latch_ea;
7471
             -- increment sp
7472
             left_ctrl  <= sp_left;
7473
             right_ctrl <= one_right;
7474
             alu_ctrl   <= alu_add16;
7475
             sp_ctrl    <= load_sp;
7476
                                 -- pull ix hi
7477
                                 ix_ctrl    <= pull_hi_ix;
7478
             addr_ctrl  <= pulls_ad;
7479
             dout_ctrl  <= ix_hi_dout;
7480
                                 --
7481
                                 st_ctrl      <= idle_st;
7482
                                 return_state <= fetch_state;
7483
             next_state   <= puls_ixl_state;
7484
 
7485
                          when puls_ixl_state =>
7486
                                 -- default
7487
             cc_ctrl    <= latch_cc;
7488
             acca_ctrl  <= latch_acca;
7489
             accb_ctrl  <= latch_accb;
7490
                                 dp_ctrl    <= latch_dp;
7491
             iy_ctrl    <= latch_iy;
7492
             up_ctrl    <= latch_up;
7493
             pc_ctrl    <= latch_pc;
7494
             md_ctrl    <= latch_md;
7495
             iv_ctrl    <= latch_iv;
7496
                            op_ctrl    <= latch_op;
7497
             pre_ctrl   <= latch_pre;
7498
                                 nmi_ctrl   <= latch_nmi;
7499
             ea_ctrl    <= latch_ea;
7500
                                 -- idle sp
7501
             left_ctrl  <= sp_left;
7502
             right_ctrl <= one_right;
7503
             alu_ctrl   <= alu_add16;
7504
             sp_ctrl    <= load_sp;
7505
                                 -- read ix low
7506
                                 ix_ctrl    <= pull_lo_ix;
7507
             addr_ctrl  <= pulls_ad;
7508
             dout_ctrl  <= ix_lo_dout;
7509
                                 --
7510
                                 st_ctrl      <= idle_st;
7511
                                 return_state <= fetch_state;
7512
                                 if ea(5) = '1' then
7513
                                   next_state <= puls_iyh_state;
7514
                                 elsif ea(6) = '1' then
7515
               next_state <= puls_uph_state;
7516
                                 elsif ea(7) = '1' then
7517
               next_state <= puls_pch_state;
7518
                                 else
7519
                                   next_state <= fetch_state;
7520
                                 end if;
7521
 
7522
                          when puls_iyh_state =>
7523
                                 -- default
7524
             cc_ctrl    <= latch_cc;
7525
             acca_ctrl  <= latch_acca;
7526
             accb_ctrl  <= latch_accb;
7527
                                 dp_ctrl    <= latch_dp;
7528
             ix_ctrl    <= latch_ix;
7529
             up_ctrl    <= latch_up;
7530
             pc_ctrl    <= latch_pc;
7531
             md_ctrl    <= latch_md;
7532
             iv_ctrl    <= latch_iv;
7533
                            op_ctrl    <= latch_op;
7534
             pre_ctrl   <= latch_pre;
7535
                                 nmi_ctrl   <= latch_nmi;
7536
             ea_ctrl    <= latch_ea;
7537
             -- increment sp
7538
             left_ctrl  <= sp_left;
7539
             right_ctrl <= one_right;
7540
             alu_ctrl   <= alu_add16;
7541
             sp_ctrl    <= load_sp;
7542
                                 -- pull iy hi
7543
                                 iy_ctrl    <= pull_hi_iy;
7544
             addr_ctrl  <= pulls_ad;
7545
             dout_ctrl  <= iy_hi_dout;
7546
                                 --
7547
                                 st_ctrl      <= idle_st;
7548
                                 return_state <= fetch_state;
7549
             next_state   <= puls_iyl_state;
7550
 
7551
                          when puls_iyl_state =>
7552
                                 -- default
7553
             cc_ctrl    <= latch_cc;
7554
             acca_ctrl  <= latch_acca;
7555
             accb_ctrl  <= latch_accb;
7556
                                 dp_ctrl    <= latch_dp;
7557
             ix_ctrl    <= latch_ix;
7558
             up_ctrl    <= latch_up;
7559
             pc_ctrl    <= latch_pc;
7560
             md_ctrl    <= latch_md;
7561
             iv_ctrl    <= latch_iv;
7562
                            op_ctrl    <= latch_op;
7563
             pre_ctrl   <= latch_pre;
7564
                                 nmi_ctrl   <= latch_nmi;
7565
             ea_ctrl    <= latch_ea;
7566
             -- increment sp
7567
             left_ctrl  <= sp_left;
7568
             right_ctrl <= one_right;
7569
             alu_ctrl   <= alu_add16;
7570
             sp_ctrl    <= load_sp;
7571
                                 -- read iy low
7572
                                 iy_ctrl    <= pull_lo_iy;
7573
             addr_ctrl  <= pulls_ad;
7574
             dout_ctrl  <= iy_lo_dout;
7575
                                 --
7576
                                 st_ctrl      <= idle_st;
7577
                                 return_state <= fetch_state;
7578
                                 if ea(6) = '1' then
7579
               next_state <= puls_uph_state;
7580
                                 elsif ea(7) = '1' then
7581
               next_state <= puls_pch_state;
7582
                                 else
7583
                                   next_state <= fetch_state;
7584
                                 end if;
7585
 
7586
                          when puls_uph_state =>
7587
                                 -- default
7588
             cc_ctrl    <= latch_cc;
7589
             acca_ctrl  <= latch_acca;
7590
             accb_ctrl  <= latch_accb;
7591
                                 dp_ctrl    <= latch_dp;
7592
             ix_ctrl    <= latch_ix;
7593
             iy_ctrl    <= latch_iy;
7594
             pc_ctrl    <= latch_pc;
7595
             md_ctrl    <= latch_md;
7596
             iv_ctrl    <= latch_iv;
7597
                            op_ctrl    <= latch_op;
7598
             pre_ctrl   <= latch_pre;
7599
                                 nmi_ctrl   <= latch_nmi;
7600
             ea_ctrl    <= latch_ea;
7601
             -- increment sp
7602
             left_ctrl  <= sp_left;
7603
             right_ctrl <= one_right;
7604
             alu_ctrl   <= alu_add16;
7605
             sp_ctrl    <= load_sp;
7606
                                 -- pull up hi
7607
                                 up_ctrl    <= pull_hi_up;
7608
             addr_ctrl  <= pulls_ad;
7609
             dout_ctrl  <= up_hi_dout;
7610
                                 --
7611
                                 st_ctrl      <= idle_st;
7612
                                 return_state <= fetch_state;
7613
             next_state   <= puls_upl_state;
7614
 
7615
                          when puls_upl_state =>
7616
                                 -- default
7617
             cc_ctrl    <= latch_cc;
7618
             acca_ctrl  <= latch_acca;
7619
             accb_ctrl  <= latch_accb;
7620
                                 dp_ctrl    <= latch_dp;
7621
             ix_ctrl    <= latch_ix;
7622
             iy_ctrl    <= latch_iy;
7623
             pc_ctrl    <= latch_pc;
7624
             md_ctrl    <= latch_md;
7625
             iv_ctrl    <= latch_iv;
7626
                            op_ctrl    <= latch_op;
7627
             pre_ctrl   <= latch_pre;
7628
                                 nmi_ctrl   <= latch_nmi;
7629
             ea_ctrl    <= latch_ea;
7630
                                 -- increment sp
7631
             left_ctrl  <= sp_left;
7632
             right_ctrl <= one_right;
7633
             alu_ctrl   <= alu_add16;
7634
             sp_ctrl    <= load_sp;
7635
                                 -- read up low
7636
                                 up_ctrl    <= pull_lo_up;
7637
             addr_ctrl  <= pulls_ad;
7638
             dout_ctrl  <= up_lo_dout;
7639
                                 --
7640
                                 st_ctrl      <= idle_st;
7641
                                 return_state <= fetch_state;
7642
                                 if ea(7) = '1' then
7643
               next_state <= puls_pch_state;
7644
                                 else
7645
                                   next_state <= fetch_state;
7646
                                 end if;
7647
 
7648
                          when puls_pch_state =>
7649
                                 -- default
7650
             cc_ctrl    <= latch_cc;
7651
             acca_ctrl  <= latch_acca;
7652
             accb_ctrl  <= latch_accb;
7653
                                 dp_ctrl    <= latch_dp;
7654
             ix_ctrl    <= latch_ix;
7655
             iy_ctrl    <= latch_iy;
7656
             up_ctrl    <= latch_up;
7657
             md_ctrl    <= latch_md;
7658
             iv_ctrl    <= latch_iv;
7659
                            op_ctrl    <= latch_op;
7660
             pre_ctrl   <= latch_pre;
7661
                                 nmi_ctrl   <= latch_nmi;
7662
             ea_ctrl    <= latch_ea;
7663
             -- increment sp
7664
             left_ctrl  <= sp_left;
7665
             right_ctrl <= one_right;
7666
             alu_ctrl   <= alu_add16;
7667
             sp_ctrl    <= load_sp;
7668
                                 -- pull pc hi
7669
                                 pc_ctrl    <= pull_hi_pc;
7670
             addr_ctrl  <= pulls_ad;
7671
             dout_ctrl  <= pc_hi_dout;
7672
                                 --
7673
                                 st_ctrl      <= idle_st;
7674
                                 return_state <= fetch_state;
7675
             next_state   <= puls_pcl_state;
7676
 
7677
                          when puls_pcl_state =>
7678
                                 -- default
7679
             cc_ctrl    <= latch_cc;
7680
             acca_ctrl  <= latch_acca;
7681
             accb_ctrl  <= latch_accb;
7682
                                 dp_ctrl    <= latch_dp;
7683
             ix_ctrl    <= latch_ix;
7684
             iy_ctrl    <= latch_iy;
7685
             up_ctrl    <= latch_up;
7686
             md_ctrl    <= latch_md;
7687
             iv_ctrl    <= latch_iv;
7688
                            op_ctrl    <= latch_op;
7689
             pre_ctrl   <= latch_pre;
7690
                                 nmi_ctrl   <= latch_nmi;
7691
             ea_ctrl    <= latch_ea;
7692
                                 -- increment sp
7693
             left_ctrl  <= sp_left;
7694
             right_ctrl <= one_right;
7695
             alu_ctrl   <= alu_add16;
7696
             sp_ctrl    <= load_sp;
7697
                                 -- read pc low
7698
                                 pc_ctrl    <= pull_lo_pc;
7699
             addr_ctrl  <= pulls_ad;
7700
             dout_ctrl  <= pc_lo_dout;
7701
                                 --
7702
                                 st_ctrl      <= idle_st;
7703
                                 return_state <= fetch_state;
7704
             next_state   <= fetch_state;
7705
 
7706
                          --
7707
                          -- Enter here on pshu
7708
                          -- ea holds post byte
7709
                          --
7710
                          when pshu_state =>
7711
                                 -- default
7712
             cc_ctrl    <= latch_cc;
7713
             acca_ctrl  <= latch_acca;
7714
             accb_ctrl  <= latch_accb;
7715
             dp_ctrl    <= latch_dp;
7716
             ix_ctrl    <= latch_ix;
7717
             iy_ctrl    <= latch_iy;
7718
             sp_ctrl    <= latch_sp;
7719
             pc_ctrl    <= latch_pc;
7720
             md_ctrl    <= latch_md;
7721
             iv_ctrl    <= latch_iv;
7722
             dp_ctrl    <= latch_dp;
7723
                            op_ctrl    <= latch_op;
7724
             pre_ctrl   <= latch_pre;
7725
                                 nmi_ctrl   <= latch_nmi;
7726
             ea_ctrl    <= latch_ea;
7727
             -- decrement up if any registers to be pushed
7728
             left_ctrl  <= up_left;
7729
             right_ctrl <= one_right;
7730
             alu_ctrl   <= alu_sub16;
7731
                                 if ea(7 downto 0) = "00000000" then
7732
               up_ctrl    <= latch_up;
7733
                                 else
7734
               up_ctrl    <= load_up;
7735
                                 end if;
7736
                                 -- write idle bus
7737
             addr_ctrl  <= idle_ad;
7738
                            dout_ctrl  <= md_lo_dout;
7739
                                 --
7740
                                 st_ctrl      <= idle_st;
7741
                                 return_state <= fetch_state;
7742
                                 if ea(7) = '1' then
7743
               next_state   <= pshu_pcl_state;
7744
                                 elsif ea(6) = '1' then
7745
               next_state   <= pshu_spl_state;
7746
                                 elsif ea(5) = '1' then
7747
                                   next_state   <= pshu_iyl_state;
7748
                                 elsif ea(4) = '1' then
7749
                                   next_state   <= pshu_ixl_state;
7750
                                 elsif ea(3) = '1' then
7751
                                   next_state   <= pshu_dp_state;
7752
                                 elsif ea(2) = '1' then
7753
                                   next_state   <= pshu_accb_state;
7754
                                 elsif ea(1) = '1' then
7755
                                   next_state   <= pshu_acca_state;
7756
                                 elsif ea(0) = '1' then
7757
                                   next_state   <= pshu_cc_state;
7758
                                 else
7759
                                   next_state   <= fetch_state;
7760
                                 end if;
7761
                          --
7762
                          -- push PC onto U stack
7763
                          --
7764
                          when pshu_pcl_state =>
7765
                                 -- default
7766
             cc_ctrl    <= latch_cc;
7767
             acca_ctrl  <= latch_acca;
7768
             accb_ctrl  <= latch_accb;
7769
                                 dp_ctrl    <= latch_dp;
7770
             ix_ctrl    <= latch_ix;
7771
             iy_ctrl    <= latch_iy;
7772
             sp_ctrl    <= latch_sp;
7773
             pc_ctrl    <= latch_pc;
7774
             md_ctrl    <= latch_md;
7775
             iv_ctrl    <= latch_iv;
7776
                            op_ctrl    <= latch_op;
7777
             pre_ctrl   <= latch_pre;
7778
                                 nmi_ctrl   <= latch_nmi;
7779
             ea_ctrl    <= latch_ea;
7780
             -- decrement up
7781
             left_ctrl  <= up_left;
7782
             right_ctrl <= one_right;
7783
             alu_ctrl   <= alu_sub16;
7784
             up_ctrl    <= load_up;
7785
                                 -- write pc low
7786
             addr_ctrl  <= pushu_ad;
7787
                            dout_ctrl  <= pc_lo_dout;
7788
                                 --
7789
                                 st_ctrl      <= idle_st;
7790
                                 return_state <= fetch_state;
7791
             next_state   <= pshu_pch_state;
7792
 
7793
                          when pshu_pch_state =>
7794
             cc_ctrl    <= latch_cc;
7795
             acca_ctrl  <= latch_acca;
7796
             accb_ctrl  <= latch_accb;
7797
                                 dp_ctrl    <= latch_dp;
7798
             ix_ctrl    <= latch_ix;
7799
             iy_ctrl    <= latch_iy;
7800
             sp_ctrl    <= latch_sp;
7801
             pc_ctrl    <= latch_pc;
7802
             md_ctrl    <= latch_md;
7803
             iv_ctrl    <= latch_iv;
7804
                            op_ctrl    <= latch_op;
7805
             pre_ctrl   <= latch_pre;
7806
                                 nmi_ctrl   <= latch_nmi;
7807
             ea_ctrl    <= latch_ea;
7808
             -- decrement up
7809
             left_ctrl  <= up_left;
7810
             right_ctrl <= one_right;
7811
             alu_ctrl   <= alu_sub16;
7812
                                 if ea(6 downto 0) = "0000000" then
7813
               up_ctrl    <= latch_up;
7814
                                 else
7815
               up_ctrl    <= load_up;
7816
                                 end if;
7817
                                 -- write pc hi
7818
             addr_ctrl  <= pushu_ad;
7819
                            dout_ctrl  <= pc_hi_dout;
7820
                                 --
7821
                                 st_ctrl      <= idle_st;
7822
                                 return_state <= fetch_state;
7823
                                 if ea(6) = '1' then
7824
               next_state   <= pshu_spl_state;
7825
                                 elsif ea(5) = '1' then
7826
                                   next_state   <= pshu_iyl_state;
7827
                                 elsif ea(4) = '1' then
7828
                                   next_state   <= pshu_ixl_state;
7829
                                 elsif ea(3) = '1' then
7830
                                   next_state   <= pshu_dp_state;
7831
                                 elsif ea(2) = '1' then
7832
                                   next_state   <= pshu_accb_state;
7833
                                 elsif ea(1) = '1' then
7834
                                   next_state   <= pshu_acca_state;
7835
                                 elsif ea(0) = '1' then
7836
                                   next_state   <= pshu_cc_state;
7837
                                 else
7838
                                   next_state   <= fetch_state;
7839
                                 end if;
7840
 
7841
                          when pshu_spl_state =>
7842
                                 -- default
7843
             cc_ctrl    <= latch_cc;
7844
             acca_ctrl  <= latch_acca;
7845
             accb_ctrl  <= latch_accb;
7846
                                 dp_ctrl    <= latch_dp;
7847
             ix_ctrl    <= latch_ix;
7848
             iy_ctrl    <= latch_iy;
7849
             sp_ctrl    <= latch_sp;
7850
             pc_ctrl    <= latch_pc;
7851
             md_ctrl    <= latch_md;
7852
             iv_ctrl    <= latch_iv;
7853
                            op_ctrl    <= latch_op;
7854
             pre_ctrl   <= latch_pre;
7855
                                 nmi_ctrl   <= latch_nmi;
7856
             ea_ctrl    <= latch_ea;
7857
             -- decrement sp
7858
             left_ctrl  <= up_left;
7859
             right_ctrl <= one_right;
7860
             alu_ctrl   <= alu_sub16;
7861
             up_ctrl    <= load_up;
7862
                                 -- write pc low
7863
             addr_ctrl  <= pushu_ad;
7864
                            dout_ctrl  <= sp_lo_dout;
7865
                                 --
7866
                                 st_ctrl      <= idle_st;
7867
                                 return_state <= fetch_state;
7868
             next_state   <= pshu_sph_state;
7869
 
7870
                          when pshu_sph_state =>
7871
             cc_ctrl    <= latch_cc;
7872
             acca_ctrl  <= latch_acca;
7873
             accb_ctrl  <= latch_accb;
7874
                                 dp_ctrl    <= latch_dp;
7875
             ix_ctrl    <= latch_ix;
7876
             iy_ctrl    <= latch_iy;
7877
             sp_ctrl    <= latch_sp;
7878
             pc_ctrl    <= latch_pc;
7879
             md_ctrl    <= latch_md;
7880
             iv_ctrl    <= latch_iv;
7881
                            op_ctrl    <= latch_op;
7882
             pre_ctrl   <= latch_pre;
7883
                                 nmi_ctrl   <= latch_nmi;
7884
             ea_ctrl    <= latch_ea;
7885
             -- decrement sp
7886
             left_ctrl  <= up_left;
7887
             right_ctrl <= one_right;
7888
             alu_ctrl   <= alu_sub16;
7889
                                 if ea(5 downto 0) = "000000" then
7890
               up_ctrl    <= latch_up;
7891
                                 else
7892
               up_ctrl    <= load_up;
7893
                                 end if;
7894
                                 -- write sp hi
7895
             addr_ctrl  <= pushu_ad;
7896
                            dout_ctrl  <= sp_hi_dout;
7897
                                 --
7898
                                 st_ctrl      <= idle_st;
7899
                                 return_state <= fetch_state;
7900
                                 if ea(5) = '1' then
7901
                                   next_state   <= pshu_iyl_state;
7902
                                 elsif ea(4) = '1' then
7903
                                   next_state   <= pshu_ixl_state;
7904
                                 elsif ea(3) = '1' then
7905
                                   next_state   <= pshu_dp_state;
7906
                                 elsif ea(2) = '1' then
7907
                                   next_state   <= pshu_accb_state;
7908
                                 elsif ea(1) = '1' then
7909
                                   next_state   <= pshu_acca_state;
7910
                                 elsif ea(0) = '1' then
7911
                                   next_state   <= pshu_cc_state;
7912
                                 else
7913
                                   next_state   <= fetch_state;
7914
                                 end if;
7915
 
7916
                          when pshu_iyl_state =>
7917
                                 -- default
7918
             cc_ctrl    <= latch_cc;
7919
             acca_ctrl  <= latch_acca;
7920
             accb_ctrl  <= latch_accb;
7921
                                 dp_ctrl    <= latch_dp;
7922
             ix_ctrl    <= latch_ix;
7923
             iy_ctrl    <= latch_iy;
7924
             sp_ctrl    <= latch_sp;
7925
             pc_ctrl    <= latch_pc;
7926
             md_ctrl    <= latch_md;
7927
             iv_ctrl    <= latch_iv;
7928
                            op_ctrl    <= latch_op;
7929
             pre_ctrl   <= latch_pre;
7930
                                 nmi_ctrl   <= latch_nmi;
7931
             ea_ctrl    <= latch_ea;
7932
             -- decrement sp
7933
             left_ctrl  <= up_left;
7934
             right_ctrl <= one_right;
7935
             alu_ctrl   <= alu_sub16;
7936
             up_ctrl    <= load_up;
7937
                                 -- write iy low
7938
             addr_ctrl  <= pushu_ad;
7939
                            dout_ctrl  <= iy_lo_dout;
7940
                                 --
7941
                                 st_ctrl      <= idle_st;
7942
                                 return_state <= fetch_state;
7943
             next_state   <= pshu_iyh_state;
7944
 
7945
                          when pshu_iyh_state =>
7946
                                 -- default registers
7947
             cc_ctrl    <= latch_cc;
7948
             acca_ctrl  <= latch_acca;
7949
             accb_ctrl  <= latch_accb;
7950
                                 dp_ctrl    <= latch_dp;
7951
             ix_ctrl    <= latch_ix;
7952
             iy_ctrl    <= latch_iy;
7953
             sp_ctrl    <= latch_sp;
7954
             pc_ctrl    <= latch_pc;
7955
             md_ctrl    <= latch_md;
7956
             iv_ctrl    <= latch_iv;
7957
                            op_ctrl    <= latch_op;
7958
             pre_ctrl   <= latch_pre;
7959
                                 nmi_ctrl   <= latch_nmi;
7960
             ea_ctrl    <= latch_ea;
7961
             -- decrement sp
7962
             left_ctrl  <= up_left;
7963
             right_ctrl <= one_right;
7964
             alu_ctrl   <= alu_sub16;
7965
                                 if ea(4 downto 0) = "00000" then
7966
               up_ctrl    <= latch_up;
7967
                                 else
7968
               up_ctrl    <= load_up;
7969
                                 end if;
7970
                                 -- write iy hi
7971
             addr_ctrl  <= pushu_ad;
7972
                            dout_ctrl  <= iy_hi_dout;
7973
                                 --
7974
                                 st_ctrl      <= idle_st;
7975
                                 return_state <= fetch_state;
7976
                                 if ea(4) = '1' then
7977
                                   next_state   <= pshu_ixl_state;
7978
                                 elsif ea(3) = '1' then
7979
                                   next_state   <= pshu_dp_state;
7980
                                 elsif ea(2) = '1' then
7981
                                   next_state   <= pshu_accb_state;
7982
                                 elsif ea(1) = '1' then
7983
                                   next_state   <= pshu_acca_state;
7984
                                 elsif ea(0) = '1' then
7985
                                   next_state   <= pshu_cc_state;
7986
                                 else
7987
                                   next_state   <= fetch_state;
7988
                                 end if;
7989
 
7990
                          when pshu_ixl_state =>
7991
                                 -- default
7992
             cc_ctrl    <= latch_cc;
7993
             acca_ctrl  <= latch_acca;
7994
             accb_ctrl  <= latch_accb;
7995
                                 dp_ctrl    <= latch_dp;
7996
             ix_ctrl    <= latch_ix;
7997
             iy_ctrl    <= latch_iy;
7998
             sp_ctrl    <= latch_sp;
7999
             pc_ctrl    <= latch_pc;
8000
             md_ctrl    <= latch_md;
8001
             iv_ctrl    <= latch_iv;
8002
                            op_ctrl    <= latch_op;
8003
             pre_ctrl   <= latch_pre;
8004
                                 nmi_ctrl   <= latch_nmi;
8005
             ea_ctrl    <= latch_ea;
8006
             -- decrement sp
8007
             left_ctrl  <= up_left;
8008
             right_ctrl <= one_right;
8009
             alu_ctrl   <= alu_sub16;
8010
             up_ctrl    <= load_up;
8011
                                 -- write ix low
8012
             addr_ctrl  <= pushu_ad;
8013
                            dout_ctrl  <= ix_lo_dout;
8014
                                 --
8015
                                 st_ctrl      <= idle_st;
8016
                                 return_state <= fetch_state;
8017
             next_state   <= pshu_ixh_state;
8018
 
8019
                          when pshu_ixh_state =>
8020
                                 -- default registers
8021
             cc_ctrl    <= latch_cc;
8022
             acca_ctrl  <= latch_acca;
8023
             accb_ctrl  <= latch_accb;
8024
                                 dp_ctrl    <= latch_dp;
8025
             ix_ctrl    <= latch_ix;
8026
             iy_ctrl    <= latch_iy;
8027
             sp_ctrl    <= latch_sp;
8028
             pc_ctrl    <= latch_pc;
8029
             md_ctrl    <= latch_md;
8030
             iv_ctrl    <= latch_iv;
8031
                            op_ctrl    <= latch_op;
8032
             pre_ctrl   <= latch_pre;
8033
                                 nmi_ctrl   <= latch_nmi;
8034
             ea_ctrl    <= latch_ea;
8035
             -- decrement sp
8036
             left_ctrl  <= up_left;
8037
             right_ctrl <= one_right;
8038
             alu_ctrl   <= alu_sub16;
8039
                                 if ea(3 downto 0) = "0000" then
8040
               up_ctrl    <= latch_up;
8041
                                 else
8042
               up_ctrl    <= load_up;
8043
                                 end if;
8044
                                 -- write ix hi
8045
             addr_ctrl  <= pushu_ad;
8046
                            dout_ctrl  <= ix_hi_dout;
8047
                                 --
8048
                                 st_ctrl      <= idle_st;
8049
                                 return_state <= fetch_state;
8050
                                 if ea(3) = '1' then
8051
                                   next_state   <= pshu_dp_state;
8052
                                 elsif ea(2) = '1' then
8053
                                   next_state   <= pshu_accb_state;
8054
                                 elsif ea(1) = '1' then
8055
                                   next_state   <= pshu_acca_state;
8056
                                 elsif ea(0) = '1' then
8057
                                   next_state   <= pshu_cc_state;
8058
                                 else
8059
                                   next_state   <= fetch_state;
8060
                                 end if;
8061
 
8062
                          when pshu_dp_state =>
8063
                                 -- default registers
8064
             cc_ctrl    <= latch_cc;
8065
             acca_ctrl  <= latch_acca;
8066
             accb_ctrl  <= latch_accb;
8067
                                 dp_ctrl    <= latch_dp;
8068
             ix_ctrl    <= latch_ix;
8069
             iy_ctrl    <= latch_iy;
8070
             sp_ctrl    <= latch_sp;
8071
             pc_ctrl    <= latch_pc;
8072
             md_ctrl    <= latch_md;
8073
             iv_ctrl    <= latch_iv;
8074
                            op_ctrl    <= latch_op;
8075
             pre_ctrl   <= latch_pre;
8076
                                 nmi_ctrl   <= latch_nmi;
8077
             ea_ctrl    <= latch_ea;
8078
             -- decrement sp
8079
             left_ctrl  <= up_left;
8080
             right_ctrl <= one_right;
8081
             alu_ctrl   <= alu_sub16;
8082
                                 if ea(2 downto 0) = "000" then
8083
               up_ctrl    <= latch_up;
8084
                                 else
8085
               up_ctrl    <= load_up;
8086
                                 end if;
8087
                                 -- write accb
8088
             addr_ctrl  <= pushu_ad;
8089
                            dout_ctrl  <= dp_dout;
8090
                                 --
8091
                                 st_ctrl      <= idle_st;
8092
                                 return_state <= fetch_state;
8093
                                 if ea(2) = '1' then
8094
                                   next_state   <= pshu_accb_state;
8095
                                 elsif ea(1) = '1' then
8096
                                   next_state   <= pshu_acca_state;
8097
                                 elsif ea(0) = '1' then
8098
                                   next_state   <= pshu_cc_state;
8099
                                 else
8100
                                   next_state   <= fetch_state;
8101
                                 end if;
8102
 
8103
                          when pshu_accb_state =>
8104
                                 -- default registers
8105
             cc_ctrl    <= latch_cc;
8106
             acca_ctrl  <= latch_acca;
8107
             accb_ctrl  <= latch_accb;
8108
                                 dp_ctrl    <= latch_dp;
8109
             ix_ctrl    <= latch_ix;
8110
             iy_ctrl    <= latch_iy;
8111
             sp_ctrl    <= latch_sp;
8112
             pc_ctrl    <= latch_pc;
8113
             md_ctrl    <= latch_md;
8114
             iv_ctrl    <= latch_iv;
8115
                            op_ctrl    <= latch_op;
8116
             pre_ctrl   <= latch_pre;
8117
                                 nmi_ctrl   <= latch_nmi;
8118
             ea_ctrl    <= latch_ea;
8119
             -- decrement up
8120
             left_ctrl  <= up_left;
8121
             right_ctrl <= one_right;
8122
             alu_ctrl   <= alu_sub16;
8123
                                 if ea(1 downto 0) = "00" then
8124
               up_ctrl    <= latch_up;
8125
                                 else
8126
               up_ctrl    <= load_up;
8127
                                 end if;
8128
                                 -- write accb
8129
             addr_ctrl  <= pushu_ad;
8130
                            dout_ctrl  <= accb_dout;
8131
                                 --
8132
                                 st_ctrl      <= idle_st;
8133
                                 return_state <= fetch_state;
8134
                                 if ea(1) = '1' then
8135
                                   next_state   <= pshu_acca_state;
8136
                                 elsif ea(0) = '1' then
8137
                                   next_state   <= pshu_cc_state;
8138
                                 else
8139
                                   next_state   <= fetch_state;
8140
                                 end if;
8141
 
8142
                          when pshu_acca_state =>
8143
                                 -- default registers
8144
             cc_ctrl    <= latch_cc;
8145
             acca_ctrl  <= latch_acca;
8146
             accb_ctrl  <= latch_accb;
8147
                                 dp_ctrl    <= latch_dp;
8148
             ix_ctrl    <= latch_ix;
8149
             iy_ctrl    <= latch_iy;
8150
             sp_ctrl    <= latch_sp;
8151
             pc_ctrl    <= latch_pc;
8152
             md_ctrl    <= latch_md;
8153
             iv_ctrl    <= latch_iv;
8154
                            op_ctrl    <= latch_op;
8155
             pre_ctrl   <= latch_pre;
8156
                                 nmi_ctrl   <= latch_nmi;
8157
             ea_ctrl    <= latch_ea;
8158
             -- decrement sp
8159
             left_ctrl  <= up_left;
8160
             right_ctrl <= one_right;
8161
             alu_ctrl   <= alu_sub16;
8162
                                 if ea(0) = '0' then
8163
               up_ctrl    <= latch_up;
8164
                                 else
8165
               up_ctrl    <= load_up;
8166
                                 end if;
8167
                                 -- write acca
8168
             addr_ctrl  <= pushu_ad;
8169
                            dout_ctrl  <= acca_dout;
8170
                                 --
8171
                                 st_ctrl      <= idle_st;
8172
                                 return_state <= fetch_state;
8173
                                 if ea(0) = '1' then
8174
                                   next_state   <= pshu_cc_state;
8175
                                 else
8176
                                   next_state   <= fetch_state;
8177
                                 end if;
8178
 
8179
                          when pshu_cc_state =>
8180
                                 -- default registers
8181
             acca_ctrl  <= latch_acca;
8182
             accb_ctrl  <= latch_accb;
8183
                                 dp_ctrl    <= latch_dp;
8184
             ix_ctrl    <= latch_ix;
8185
             iy_ctrl    <= latch_iy;
8186
             sp_ctrl    <= latch_sp;
8187
             pc_ctrl    <= latch_pc;
8188
             md_ctrl    <= latch_md;
8189
             iv_ctrl    <= latch_iv;
8190
                            op_ctrl    <= latch_op;
8191
             pre_ctrl   <= latch_pre;
8192
                                 nmi_ctrl   <= latch_nmi;
8193
             ea_ctrl    <= latch_ea;
8194
             -- idle up
8195
             left_ctrl  <= up_left;
8196
             right_ctrl <= one_right;
8197
             cc_ctrl    <= latch_cc;
8198
             alu_ctrl   <= alu_nop;
8199
             up_ctrl    <= latch_up;
8200
                                 -- write cc
8201
             addr_ctrl  <= pushu_ad;
8202
                            dout_ctrl  <= cc_dout;
8203
                                 --
8204
                                 st_ctrl      <= idle_st;
8205
                                 return_state <= fetch_state;
8206
             next_state   <= fetch_state;
8207
 
8208
                          --
8209
                          -- enter here on PULU
8210
                          -- ea hold register mask
8211
                          --
8212
                          when pulu_state =>
8213
                                 -- default registers
8214
             cc_ctrl    <= latch_cc;
8215
             acca_ctrl  <= latch_acca;
8216
             accb_ctrl  <= latch_accb;
8217
                                 dp_ctrl    <= latch_dp;
8218
             ix_ctrl    <= latch_ix;
8219
             iy_ctrl    <= latch_iy;
8220
             sp_ctrl    <= latch_sp;
8221
             pc_ctrl    <= latch_pc;
8222
             md_ctrl    <= latch_md;
8223
             iv_ctrl    <= latch_iv;
8224
                            op_ctrl    <= latch_op;
8225
             pre_ctrl   <= latch_pre;
8226
                                 nmi_ctrl   <= latch_nmi;
8227
             ea_ctrl    <= latch_ea;
8228
                                 -- idle UP
8229
             left_ctrl  <= up_left;
8230
             right_ctrl <= one_right;
8231
             alu_ctrl   <= alu_add16;
8232
             up_ctrl    <= latch_up;
8233
                                 -- idle bus
8234
             addr_ctrl  <= idle_ad;
8235
             dout_ctrl  <= md_lo_dout;
8236
                                 --
8237
                                 st_ctrl      <= idle_st;
8238
                                 return_state <= fetch_state;
8239
                                 if ea(0) = '1' then
8240
                                   next_state <= pulu_cc_state;
8241
                                 elsif ea(1) = '1' then
8242
                                   next_state <= pulu_acca_state;
8243
                                 elsif ea(2) = '1' then
8244
                                   next_state <= pulu_accb_state;
8245
                                 elsif ea(3) = '1' then
8246
                                   next_state <= pulu_dp_state;
8247
                                 elsif ea(4) = '1' then
8248
                                   next_state <= pulu_ixh_state;
8249
                                 elsif ea(5) = '1' then
8250
                                   next_state <= pulu_iyh_state;
8251
                                 elsif ea(6) = '1' then
8252
               next_state <= pulu_sph_state;
8253
                                 elsif ea(7) = '1' then
8254
               next_state <= pulu_pch_state;
8255
                                 else
8256
                                   next_state <= fetch_state;
8257
                                 end if;
8258
 
8259
                          when pulu_cc_state =>
8260
                                 -- default registers
8261
             acca_ctrl  <= latch_acca;
8262
             accb_ctrl  <= latch_accb;
8263
                                 dp_ctrl    <= latch_dp;
8264
             ix_ctrl    <= latch_ix;
8265
             iy_ctrl    <= latch_iy;
8266
             sp_ctrl    <= latch_sp;
8267
             pc_ctrl    <= latch_pc;
8268
             md_ctrl    <= latch_md;
8269
             iv_ctrl    <= latch_iv;
8270
                            op_ctrl    <= latch_op;
8271
             pre_ctrl   <= latch_pre;
8272
                                 nmi_ctrl   <= latch_nmi;
8273
             ea_ctrl    <= latch_ea;
8274
                                 -- increment up
8275
             left_ctrl  <= up_left;
8276
             right_ctrl <= one_right;
8277
             alu_ctrl   <= alu_add16;
8278
             up_ctrl    <= load_up;
8279
                                 -- read cc
8280
             cc_ctrl    <= pull_cc;
8281
             addr_ctrl  <= pullu_ad;
8282
             dout_ctrl  <= cc_dout;
8283
                                 --
8284
                                 st_ctrl      <= idle_st;
8285
                                 return_state <= fetch_state;
8286
                                 if ea(1) = '1' then
8287
                                   next_state <= pulu_acca_state;
8288
                                 elsif ea(2) = '1' then
8289
                                   next_state <= pulu_accb_state;
8290
                                 elsif ea(3) = '1' then
8291
                                   next_state <= pulu_dp_state;
8292
                                 elsif ea(4) = '1' then
8293
                                   next_state <= pulu_ixh_state;
8294
                                 elsif ea(5) = '1' then
8295
                                   next_state <= pulu_iyh_state;
8296
                                 elsif ea(6) = '1' then
8297
               next_state <= pulu_sph_state;
8298
                                 elsif ea(7) = '1' then
8299
               next_state <= pulu_pch_state;
8300
                                 else
8301
                                   next_state <= fetch_state;
8302
                                 end if;
8303
 
8304
                          when pulu_acca_state =>
8305
                                 -- default registers
8306
             cc_ctrl    <= latch_cc;
8307
             accb_ctrl  <= latch_accb;
8308
                                 dp_ctrl    <= latch_dp;
8309
             ix_ctrl    <= latch_ix;
8310
             iy_ctrl    <= latch_iy;
8311
             sp_ctrl    <= latch_sp;
8312
             pc_ctrl    <= latch_pc;
8313
             md_ctrl    <= latch_md;
8314
             iv_ctrl    <= latch_iv;
8315
                            op_ctrl    <= latch_op;
8316
             pre_ctrl   <= latch_pre;
8317
                                 nmi_ctrl   <= latch_nmi;
8318
             ea_ctrl    <= latch_ea;
8319
                                 -- increment up
8320
             left_ctrl  <= up_left;
8321
             right_ctrl <= one_right;
8322
             alu_ctrl   <= alu_add16;
8323
             up_ctrl    <= load_up;
8324
                                 -- read acca
8325
                                 acca_ctrl  <= pull_acca;
8326
             addr_ctrl  <= pullu_ad;
8327
             dout_ctrl  <= acca_dout;
8328
                                 --
8329
                                 st_ctrl      <= idle_st;
8330
                                 return_state <= fetch_state;
8331
                                 if ea(2) = '1' then
8332
                                   next_state <= pulu_accb_state;
8333
                                 elsif ea(3) = '1' then
8334
                                   next_state <= pulu_dp_state;
8335
                                 elsif ea(4) = '1' then
8336
                                   next_state <= pulu_ixh_state;
8337
                                 elsif ea(5) = '1' then
8338
                                   next_state <= pulu_iyh_state;
8339
                                 elsif ea(6) = '1' then
8340
               next_state <= pulu_sph_state;
8341
                                 elsif ea(7) = '1' then
8342
               next_state <= pulu_pch_state;
8343
                                 else
8344
                                   next_state <= fetch_state;
8345
                                 end if;
8346
 
8347
                          when pulu_accb_state =>
8348
                                 -- default
8349
             cc_ctrl    <= latch_cc;
8350
             acca_ctrl  <= latch_acca;
8351
                                 dp_ctrl    <= latch_dp;
8352
             ix_ctrl    <= latch_ix;
8353
             iy_ctrl    <= latch_iy;
8354
             sp_ctrl    <= latch_sp;
8355
             pc_ctrl    <= latch_pc;
8356
             md_ctrl    <= latch_md;
8357
             iv_ctrl    <= latch_iv;
8358
                            op_ctrl    <= latch_op;
8359
             pre_ctrl   <= latch_pre;
8360
                                 nmi_ctrl   <= latch_nmi;
8361
             ea_ctrl    <= latch_ea;
8362
                                 -- increment up
8363
             left_ctrl  <= up_left;
8364
             right_ctrl <= one_right;
8365
             alu_ctrl   <= alu_add16;
8366
             up_ctrl    <= load_up;
8367
                                 -- read accb
8368
                                 accb_ctrl  <= pull_accb;
8369
             addr_ctrl  <= pullu_ad;
8370
             dout_ctrl  <= accb_dout;
8371
                                 --
8372
                                 st_ctrl      <= idle_st;
8373
                                 return_state <= fetch_state;
8374
                                 if ea(3) = '1' then
8375
                                   next_state <= pulu_dp_state;
8376
                                 elsif ea(4) = '1' then
8377
                                   next_state <= pulu_ixh_state;
8378
                                 elsif ea(5) = '1' then
8379
                                   next_state <= pulu_iyh_state;
8380
                                 elsif ea(6) = '1' then
8381
               next_state <= pulu_sph_state;
8382
                                 elsif ea(7) = '1' then
8383
               next_state <= pulu_pch_state;
8384
                                 else
8385
                                   next_state <= fetch_state;
8386
                                 end if;
8387
 
8388
                          when pulu_dp_state =>
8389
                                 -- default
8390
             cc_ctrl    <= latch_cc;
8391
             acca_ctrl  <= latch_acca;
8392
             accb_ctrl  <= latch_accb;
8393
             ix_ctrl    <= latch_ix;
8394
             iy_ctrl    <= latch_iy;
8395
             sp_ctrl    <= latch_sp;
8396
             pc_ctrl    <= latch_pc;
8397
             md_ctrl    <= latch_md;
8398
             iv_ctrl    <= latch_iv;
8399
                            op_ctrl    <= latch_op;
8400
             pre_ctrl   <= latch_pre;
8401
                                 nmi_ctrl   <= latch_nmi;
8402
             ea_ctrl    <= latch_ea;
8403
                                 -- increment up
8404
             left_ctrl  <= up_left;
8405
             right_ctrl <= one_right;
8406
             alu_ctrl   <= alu_add16;
8407
             up_ctrl    <= load_up;
8408
                                 -- read dp
8409
                                 dp_ctrl    <= pull_dp;
8410
             addr_ctrl  <= pullu_ad;
8411
             dout_ctrl  <= dp_dout;
8412
                                 --
8413
                                 st_ctrl      <= idle_st;
8414
                                 return_state <= fetch_state;
8415
                                 if ea(4) = '1' then
8416
                                   next_state <= pulu_ixh_state;
8417
                                 elsif ea(5) = '1' then
8418
                                   next_state <= pulu_iyh_state;
8419
                                 elsif ea(6) = '1' then
8420
               next_state <= pulu_sph_state;
8421
                                 elsif ea(7) = '1' then
8422
               next_state <= pulu_pch_state;
8423
                                 else
8424
                                   next_state <= fetch_state;
8425
                                 end if;
8426
 
8427
                          when pulu_ixh_state =>
8428
                                 -- default
8429
             cc_ctrl    <= latch_cc;
8430
             acca_ctrl  <= latch_acca;
8431
             accb_ctrl  <= latch_accb;
8432
                                 dp_ctrl    <= latch_dp;
8433
             iy_ctrl    <= latch_iy;
8434
             sp_ctrl    <= latch_sp;
8435
             pc_ctrl    <= latch_pc;
8436
             md_ctrl    <= latch_md;
8437
             iv_ctrl    <= latch_iv;
8438
                            op_ctrl    <= latch_op;
8439
             pre_ctrl   <= latch_pre;
8440
                                 nmi_ctrl   <= latch_nmi;
8441
             ea_ctrl    <= latch_ea;
8442
             -- increment up
8443
             left_ctrl  <= up_left;
8444
             right_ctrl <= one_right;
8445
             alu_ctrl   <= alu_add16;
8446
             up_ctrl    <= load_up;
8447
                                 -- pull ix hi
8448
                                 ix_ctrl    <= pull_hi_ix;
8449
             addr_ctrl  <= pullu_ad;
8450
             dout_ctrl  <= ix_hi_dout;
8451
                                 --
8452
                                 st_ctrl      <= idle_st;
8453
                                 return_state <= fetch_state;
8454
             next_state   <= pulu_ixl_state;
8455
 
8456
                          when pulu_ixl_state =>
8457
                                 -- default
8458
             cc_ctrl    <= latch_cc;
8459
             acca_ctrl  <= latch_acca;
8460
             accb_ctrl  <= latch_accb;
8461
                                 dp_ctrl    <= latch_dp;
8462
             iy_ctrl    <= latch_iy;
8463
             sp_ctrl    <= latch_sp;
8464
             pc_ctrl    <= latch_pc;
8465
             md_ctrl    <= latch_md;
8466
             iv_ctrl    <= latch_iv;
8467
                            op_ctrl    <= latch_op;
8468
             pre_ctrl   <= latch_pre;
8469
                                 nmi_ctrl   <= latch_nmi;
8470
             ea_ctrl    <= latch_ea;
8471
                                 -- increment up
8472
             left_ctrl  <= up_left;
8473
             right_ctrl <= one_right;
8474
             alu_ctrl   <= alu_add16;
8475
             up_ctrl    <= load_up;
8476
                                 -- read ix low
8477
                                 ix_ctrl    <= pull_lo_ix;
8478
             addr_ctrl  <= pullu_ad;
8479
             dout_ctrl  <= ix_lo_dout;
8480
                                 --
8481
                                 st_ctrl      <= idle_st;
8482
                                 return_state <= fetch_state;
8483
                                 if ea(5) = '1' then
8484
                                   next_state <= pulu_iyh_state;
8485
                                 elsif ea(6) = '1' then
8486
               next_state <= pulu_sph_state;
8487
                                 elsif ea(7) = '1' then
8488
               next_state <= pulu_pch_state;
8489
                                 else
8490
                                   next_state <= fetch_state;
8491
                                 end if;
8492
 
8493
                          when pulu_iyh_state =>
8494
                                 -- default
8495
             cc_ctrl    <= latch_cc;
8496
             acca_ctrl  <= latch_acca;
8497
             accb_ctrl  <= latch_accb;
8498
                                 dp_ctrl    <= latch_dp;
8499
             ix_ctrl    <= latch_ix;
8500
             sp_ctrl    <= latch_sp;
8501
             pc_ctrl    <= latch_pc;
8502
             md_ctrl    <= latch_md;
8503
             iv_ctrl    <= latch_iv;
8504
                            op_ctrl    <= latch_op;
8505
             pre_ctrl   <= latch_pre;
8506
                                 nmi_ctrl   <= latch_nmi;
8507
             ea_ctrl    <= latch_ea;
8508
             -- increment up
8509
             left_ctrl  <= up_left;
8510
             right_ctrl <= one_right;
8511
             alu_ctrl   <= alu_add16;
8512
             up_ctrl    <= load_up;
8513
                                 -- pull iy hi
8514
                                 iy_ctrl    <= pull_hi_iy;
8515
             addr_ctrl  <= pullu_ad;
8516
             dout_ctrl  <= iy_hi_dout;
8517
                                 --
8518
                                 st_ctrl      <= idle_st;
8519
                                 return_state <= fetch_state;
8520
             next_state   <= pulu_iyl_state;
8521
 
8522
                          when pulu_iyl_state =>
8523
                                 -- default
8524
             cc_ctrl    <= latch_cc;
8525
             acca_ctrl  <= latch_acca;
8526
             accb_ctrl  <= latch_accb;
8527
                                 dp_ctrl    <= latch_dp;
8528
             ix_ctrl    <= latch_ix;
8529
             sp_ctrl    <= latch_sp;
8530
             pc_ctrl    <= latch_pc;
8531
             md_ctrl    <= latch_md;
8532
             iv_ctrl    <= latch_iv;
8533
                            op_ctrl    <= latch_op;
8534
             pre_ctrl   <= latch_pre;
8535
                                 nmi_ctrl   <= latch_nmi;
8536
             ea_ctrl    <= latch_ea;
8537
             -- increment up
8538
             left_ctrl  <= up_left;
8539
             right_ctrl <= one_right;
8540
             alu_ctrl   <= alu_add16;
8541
             up_ctrl    <= load_up;
8542
                                 -- read iy low
8543
                                 iy_ctrl    <= pull_lo_iy;
8544
             addr_ctrl  <= pullu_ad;
8545
             dout_ctrl  <= iy_lo_dout;
8546
                                 --
8547
                                 st_ctrl      <= idle_st;
8548
                                 return_state <= fetch_state;
8549
                                 if ea(6) = '1' then
8550
               next_state <= pulu_sph_state;
8551
                                 elsif ea(7) = '1' then
8552
               next_state <= pulu_pch_state;
8553
                                 else
8554
                                   next_state <= fetch_state;
8555
                                 end if;
8556
 
8557
                          when pulu_sph_state =>
8558
                                 -- default
8559
             cc_ctrl    <= latch_cc;
8560
             acca_ctrl  <= latch_acca;
8561
             accb_ctrl  <= latch_accb;
8562
                                 dp_ctrl    <= latch_dp;
8563
             ix_ctrl    <= latch_ix;
8564
             iy_ctrl    <= latch_iy;
8565
             pc_ctrl    <= latch_pc;
8566
             md_ctrl    <= latch_md;
8567
             iv_ctrl    <= latch_iv;
8568
                            op_ctrl    <= latch_op;
8569
             pre_ctrl   <= latch_pre;
8570
                                 nmi_ctrl   <= latch_nmi;
8571
             ea_ctrl    <= latch_ea;
8572
             -- increment up
8573
             left_ctrl  <= up_left;
8574
             right_ctrl <= one_right;
8575
             alu_ctrl   <= alu_add16;
8576
             up_ctrl    <= load_up;
8577
                                 -- pull sp hi
8578
                                 sp_ctrl    <= pull_hi_sp;
8579
             addr_ctrl  <= pullu_ad;
8580
             dout_ctrl  <= up_hi_dout;
8581
                                 --
8582
                                 st_ctrl      <= idle_st;
8583
                                 return_state <= fetch_state;
8584
             next_state   <= pulu_spl_state;
8585
 
8586
                          when pulu_spl_state =>
8587
                                 -- default
8588
             cc_ctrl    <= latch_cc;
8589
             acca_ctrl  <= latch_acca;
8590
             accb_ctrl  <= latch_accb;
8591
                                 dp_ctrl    <= latch_dp;
8592
             ix_ctrl    <= latch_ix;
8593
             iy_ctrl    <= latch_iy;
8594
             pc_ctrl    <= latch_pc;
8595
             md_ctrl    <= latch_md;
8596
             iv_ctrl    <= latch_iv;
8597
                            op_ctrl    <= latch_op;
8598
             pre_ctrl   <= latch_pre;
8599
                                 nmi_ctrl   <= latch_nmi;
8600
             ea_ctrl    <= latch_ea;
8601
                                 -- increment up
8602
             left_ctrl  <= up_left;
8603
             right_ctrl <= one_right;
8604
             alu_ctrl   <= alu_add16;
8605
             up_ctrl    <= load_up;
8606
                                 -- read sp low
8607
                                 sp_ctrl    <= pull_lo_sp;
8608
             addr_ctrl  <= pullu_ad;
8609
             dout_ctrl  <= up_lo_dout;
8610
                                 --
8611
                                 st_ctrl      <= idle_st;
8612
                                 return_state <= fetch_state;
8613
                                 if ea(7) = '1' then
8614
               next_state <= pulu_pch_state;
8615
                                 else
8616
                                   next_state <= fetch_state;
8617
                                 end if;
8618
 
8619
                          when pulu_pch_state =>
8620
                                 -- default
8621
             cc_ctrl    <= latch_cc;
8622
             acca_ctrl  <= latch_acca;
8623
             accb_ctrl  <= latch_accb;
8624
                                 dp_ctrl    <= latch_dp;
8625
             ix_ctrl    <= latch_ix;
8626
             iy_ctrl    <= latch_iy;
8627
             sp_ctrl    <= latch_sp;
8628
             md_ctrl    <= latch_md;
8629
             iv_ctrl    <= latch_iv;
8630
                            op_ctrl    <= latch_op;
8631
             pre_ctrl   <= latch_pre;
8632
                                 nmi_ctrl   <= latch_nmi;
8633
             ea_ctrl    <= latch_ea;
8634
             -- increment up
8635
             left_ctrl  <= up_left;
8636
             right_ctrl <= one_right;
8637
             alu_ctrl   <= alu_add16;
8638
             up_ctrl    <= load_up;
8639
                                 -- pull pc hi
8640
                                 pc_ctrl    <= pull_hi_pc;
8641
             addr_ctrl  <= pullu_ad;
8642
             dout_ctrl  <= pc_hi_dout;
8643
                                 --
8644
                                 st_ctrl      <= idle_st;
8645
                                 return_state <= fetch_state;
8646
             next_state   <= pulu_pcl_state;
8647
 
8648
                          when pulu_pcl_state =>
8649
                                 -- default
8650
             cc_ctrl    <= latch_cc;
8651
             acca_ctrl  <= latch_acca;
8652
             accb_ctrl  <= latch_accb;
8653
                                 dp_ctrl    <= latch_dp;
8654
             ix_ctrl    <= latch_ix;
8655
             iy_ctrl    <= latch_iy;
8656
             sp_ctrl    <= latch_sp;
8657
             md_ctrl    <= latch_md;
8658
             iv_ctrl    <= latch_iv;
8659
                            op_ctrl    <= latch_op;
8660
             pre_ctrl   <= latch_pre;
8661
                                 nmi_ctrl   <= latch_nmi;
8662
             ea_ctrl    <= latch_ea;
8663
                                 -- increment up
8664
             left_ctrl  <= up_left;
8665
             right_ctrl <= one_right;
8666
             alu_ctrl   <= alu_add16;
8667
             up_ctrl    <= load_up;
8668
                                 -- read pc low
8669
                                 pc_ctrl    <= pull_lo_pc;
8670
             addr_ctrl  <= pullu_ad;
8671
             dout_ctrl  <= pc_lo_dout;
8672
                                 --
8673
                                 st_ctrl      <= idle_st;
8674
                                 return_state <= fetch_state;
8675
             next_state   <= fetch_state;
8676
 
8677
                          --
8678
                          -- pop the Condition codes
8679
                          --
8680
                          when rti_cc_state =>
8681
                                 -- default registers
8682
             acca_ctrl  <= latch_acca;
8683
             accb_ctrl  <= latch_accb;
8684
                                 dp_ctrl    <= latch_dp;
8685
             ix_ctrl    <= latch_ix;
8686
             iy_ctrl    <= latch_iy;
8687
             up_ctrl    <= latch_up;
8688
             pc_ctrl    <= latch_pc;
8689
             md_ctrl    <= latch_md;
8690
             iv_ctrl    <= latch_iv;
8691
                            op_ctrl    <= latch_op;
8692
             pre_ctrl   <= latch_pre;
8693
                                 nmi_ctrl   <= latch_nmi;
8694
             ea_ctrl    <= latch_ea;
8695
                                 -- increment sp
8696
             left_ctrl  <= sp_left;
8697
             right_ctrl <= one_right;
8698
             alu_ctrl   <= alu_add16;
8699
             sp_ctrl    <= load_sp;
8700
                                 -- read cc
8701
             cc_ctrl    <= pull_cc;
8702
             addr_ctrl  <= pulls_ad;
8703
             dout_ctrl  <= cc_dout;
8704
                                 --
8705
                                 st_ctrl      <= idle_st;
8706
                                 return_state <= fetch_state;
8707
             next_state   <= rti_entire_state;
8708
 
8709
                          --
8710
                          -- Added RTI cycle 11th July 2006 John Kent.
8711
                          -- test the "Entire" Flag
8712
                          -- that has just been popped off the stack
8713
                          --
8714
                          when rti_entire_state =>
8715
                                 -- default registers
8716
             acca_ctrl  <= latch_acca;
8717
             accb_ctrl  <= latch_accb;
8718
                                 dp_ctrl    <= latch_dp;
8719
             ix_ctrl    <= latch_ix;
8720
             iy_ctrl    <= latch_iy;
8721
             up_ctrl    <= latch_up;
8722
             pc_ctrl    <= latch_pc;
8723
             md_ctrl    <= latch_md;
8724
             iv_ctrl    <= latch_iv;
8725
                            op_ctrl    <= latch_op;
8726
             pre_ctrl   <= latch_pre;
8727
                                 nmi_ctrl   <= latch_nmi;
8728
             ea_ctrl    <= latch_ea;
8729
                                 -- idle sp
8730
             left_ctrl  <= sp_left;
8731
             right_ctrl <= one_right;
8732
             alu_ctrl   <= alu_nop;
8733
             sp_ctrl    <= latch_sp;
8734
                                 -- idle cc
8735
             cc_ctrl    <= latch_cc;
8736
             addr_ctrl  <= idle_ad;
8737
             dout_ctrl  <= cc_dout;
8738
                                 --
8739
                                 st_ctrl      <= idle_st;
8740
                                 return_state <= fetch_state;
8741
                                 --
8742
                                 -- The Entire flag must be recovered from the stack
8743
                                 -- before testing.
8744
                                 --
8745
                                 if cc(EBIT) = '1' then
8746
               next_state   <= rti_acca_state;
8747
                                 else
8748
               next_state   <= rti_pch_state;
8749
                                 end if;
8750
 
8751
                          when rti_acca_state =>
8752
                                 -- default registers
8753
             cc_ctrl    <= latch_cc;
8754
             accb_ctrl  <= latch_accb;
8755
                                 dp_ctrl    <= latch_dp;
8756
             ix_ctrl    <= latch_ix;
8757
             iy_ctrl    <= latch_iy;
8758
             up_ctrl    <= latch_up;
8759
             pc_ctrl    <= latch_pc;
8760
             md_ctrl    <= latch_md;
8761
             iv_ctrl    <= latch_iv;
8762
                            op_ctrl    <= latch_op;
8763
             pre_ctrl   <= latch_pre;
8764
                                 nmi_ctrl   <= latch_nmi;
8765
             ea_ctrl    <= latch_ea;
8766
                                 -- increment sp
8767
             left_ctrl  <= sp_left;
8768
             right_ctrl <= one_right;
8769
             alu_ctrl   <= alu_add16;
8770
             sp_ctrl    <= load_sp;
8771
                                 -- read acca
8772
                                 acca_ctrl  <= pull_acca;
8773
             addr_ctrl  <= pulls_ad;
8774
             dout_ctrl  <= acca_dout;
8775
                                 --
8776
                                 st_ctrl      <= idle_st;
8777
                                 return_state <= fetch_state;
8778
             next_state   <= rti_accb_state;
8779
 
8780
                          when rti_accb_state =>
8781
                                 -- default registers
8782
             cc_ctrl    <= latch_cc;
8783
             acca_ctrl  <= latch_acca;
8784
                                 dp_ctrl    <= latch_dp;
8785
             ix_ctrl    <= latch_ix;
8786
             iy_ctrl    <= latch_iy;
8787
             up_ctrl    <= latch_up;
8788
             pc_ctrl    <= latch_pc;
8789
             md_ctrl    <= latch_md;
8790
             iv_ctrl    <= latch_iv;
8791
                            op_ctrl    <= latch_op;
8792
             pre_ctrl   <= latch_pre;
8793
                                 nmi_ctrl   <= latch_nmi;
8794
             ea_ctrl    <= latch_ea;
8795
                                 -- increment sp
8796
             left_ctrl  <= sp_left;
8797
             right_ctrl <= one_right;
8798
             alu_ctrl   <= alu_add16;
8799
             sp_ctrl    <= load_sp;
8800
                                 -- read accb
8801
                                 accb_ctrl  <= pull_accb;
8802
             addr_ctrl  <= pulls_ad;
8803
             dout_ctrl  <= accb_dout;
8804
                                 --
8805
                                 st_ctrl      <= idle_st;
8806
                                 return_state <= fetch_state;
8807
             next_state   <= rti_dp_state;
8808
 
8809
                          when rti_dp_state =>
8810
                                 -- default registers
8811
             cc_ctrl    <= latch_cc;
8812
             acca_ctrl  <= latch_acca;
8813
                                 accb_ctrl  <= latch_accb;
8814
             ix_ctrl    <= latch_ix;
8815
             iy_ctrl    <= latch_iy;
8816
             up_ctrl    <= latch_up;
8817
             pc_ctrl    <= latch_pc;
8818
             md_ctrl    <= latch_md;
8819
             iv_ctrl    <= latch_iv;
8820
                            op_ctrl    <= latch_op;
8821
             pre_ctrl   <= latch_pre;
8822
                                 nmi_ctrl   <= latch_nmi;
8823
             ea_ctrl    <= latch_ea;
8824
                                 -- increment sp
8825
             left_ctrl  <= sp_left;
8826
             right_ctrl <= one_right;
8827
             alu_ctrl   <= alu_add16;
8828
             sp_ctrl    <= load_sp;
8829
                                 -- read dp
8830
                                 dp_ctrl    <= pull_dp;
8831
             addr_ctrl  <= pulls_ad;
8832
             dout_ctrl  <= dp_dout;
8833
                                 --
8834
                                 st_ctrl      <= idle_st;
8835
                                 return_state <= fetch_state;
8836
             next_state   <= rti_ixh_state;
8837
 
8838
                          when rti_ixh_state =>
8839
                                 -- default
8840
             cc_ctrl    <= latch_cc;
8841
             acca_ctrl  <= latch_acca;
8842
             accb_ctrl  <= latch_accb;
8843
                                 dp_ctrl    <= latch_dp;
8844
             iy_ctrl    <= latch_iy;
8845
             up_ctrl    <= latch_up;
8846
             pc_ctrl    <= latch_pc;
8847
             md_ctrl    <= latch_md;
8848
             iv_ctrl    <= latch_iv;
8849
                            op_ctrl    <= latch_op;
8850
             pre_ctrl   <= latch_pre;
8851
                                 nmi_ctrl   <= latch_nmi;
8852
             ea_ctrl    <= latch_ea;
8853
                                 -- increment sp
8854
             left_ctrl  <= sp_left;
8855
             right_ctrl <= one_right;
8856
             alu_ctrl   <= alu_add16;
8857
             sp_ctrl    <= load_sp;
8858
                                 -- read ix hi
8859
                                 ix_ctrl    <= pull_hi_ix;
8860
             addr_ctrl  <= pulls_ad;
8861
             dout_ctrl  <= ix_hi_dout;
8862
                                 --
8863
                                 st_ctrl      <= idle_st;
8864
                                 return_state <= fetch_state;
8865
             next_state   <= rti_ixl_state;
8866
 
8867
                          when rti_ixl_state =>
8868
                                 -- default
8869
             cc_ctrl    <= latch_cc;
8870
             acca_ctrl  <= latch_acca;
8871
             accb_ctrl  <= latch_accb;
8872
                                 dp_ctrl    <= latch_dp;
8873
             iy_ctrl    <= latch_iy;
8874
             up_ctrl    <= latch_up;
8875
             pc_ctrl    <= latch_pc;
8876
             md_ctrl    <= latch_md;
8877
             iv_ctrl    <= latch_iv;
8878
                            op_ctrl    <= latch_op;
8879
             pre_ctrl   <= latch_pre;
8880
                                 nmi_ctrl   <= latch_nmi;
8881
             ea_ctrl    <= latch_ea;
8882
                                 -- increment sp
8883
             left_ctrl  <= sp_left;
8884
             right_ctrl <= one_right;
8885
             alu_ctrl   <= alu_add16;
8886
             sp_ctrl    <= load_sp;
8887
                                 -- read ix low
8888
                                 ix_ctrl    <= pull_lo_ix;
8889
             addr_ctrl  <= pulls_ad;
8890
             dout_ctrl  <= ix_lo_dout;
8891
                                 --
8892
                                 st_ctrl      <= idle_st;
8893
                                 return_state <= fetch_state;
8894
             next_state   <= rti_iyh_state;
8895
 
8896
                          when rti_iyh_state =>
8897
                                 -- default
8898
             cc_ctrl    <= latch_cc;
8899
             acca_ctrl  <= latch_acca;
8900
             accb_ctrl  <= latch_accb;
8901
                                 dp_ctrl    <= latch_dp;
8902
             ix_ctrl    <= latch_ix;
8903
             up_ctrl    <= latch_up;
8904
             pc_ctrl    <= latch_pc;
8905
             md_ctrl    <= latch_md;
8906
             iv_ctrl    <= latch_iv;
8907
                            op_ctrl    <= latch_op;
8908
             pre_ctrl   <= latch_pre;
8909
                                 nmi_ctrl   <= latch_nmi;
8910
             ea_ctrl    <= latch_ea;
8911
                                 -- increment sp
8912
             left_ctrl  <= sp_left;
8913
             right_ctrl <= one_right;
8914
             alu_ctrl   <= alu_add16;
8915
             sp_ctrl    <= load_sp;
8916
                                 -- read iy hi
8917
                                 iy_ctrl    <= pull_hi_iy;
8918
             addr_ctrl  <= pulls_ad;
8919
             dout_ctrl  <= iy_hi_dout;
8920
                                 --
8921
                                 st_ctrl      <= idle_st;
8922
                                 return_state <= fetch_state;
8923
             next_state   <= rti_iyl_state;
8924
 
8925
                          when rti_iyl_state =>
8926
                                 -- default
8927
             cc_ctrl    <= latch_cc;
8928
             acca_ctrl  <= latch_acca;
8929
             accb_ctrl  <= latch_accb;
8930
                                 dp_ctrl    <= latch_dp;
8931
             ix_ctrl    <= latch_ix;
8932
             up_ctrl    <= latch_up;
8933
             pc_ctrl    <= latch_pc;
8934
             md_ctrl    <= latch_md;
8935
             iv_ctrl    <= latch_iv;
8936
                            op_ctrl    <= latch_op;
8937
             pre_ctrl   <= latch_pre;
8938
                                 nmi_ctrl   <= latch_nmi;
8939
             ea_ctrl    <= latch_ea;
8940
                                 -- increment sp
8941
             left_ctrl  <= sp_left;
8942
             right_ctrl <= one_right;
8943
             alu_ctrl   <= alu_add16;
8944
             sp_ctrl    <= load_sp;
8945
                                 -- read iy low
8946
                                 iy_ctrl    <= pull_lo_iy;
8947
             addr_ctrl  <= pulls_ad;
8948
             dout_ctrl  <= iy_lo_dout;
8949
                                 --
8950
                                 st_ctrl      <= idle_st;
8951
                                 return_state <= fetch_state;
8952
             next_state   <= rti_uph_state;
8953
 
8954
 
8955
                          when rti_uph_state =>
8956
                                 -- default
8957
             cc_ctrl    <= latch_cc;
8958
             acca_ctrl  <= latch_acca;
8959
             accb_ctrl  <= latch_accb;
8960
                                 dp_ctrl    <= latch_dp;
8961
             ix_ctrl    <= latch_ix;
8962
             iy_ctrl    <= latch_iy;
8963
             pc_ctrl    <= latch_pc;
8964
             md_ctrl    <= latch_md;
8965
             iv_ctrl    <= latch_iv;
8966
                            op_ctrl    <= latch_op;
8967
             pre_ctrl   <= latch_pre;
8968
                                 nmi_ctrl   <= latch_nmi;
8969
             ea_ctrl    <= latch_ea;
8970
                                 -- increment sp
8971
             left_ctrl  <= sp_left;
8972
             right_ctrl <= one_right;
8973
             alu_ctrl   <= alu_add16;
8974
             sp_ctrl    <= load_sp;
8975
                                 -- read up hi
8976
                                 up_ctrl    <= pull_hi_up;
8977
             addr_ctrl  <= pulls_ad;
8978
             dout_ctrl  <= up_hi_dout;
8979
                                 --
8980
                                 st_ctrl      <= idle_st;
8981
                                 return_state <= fetch_state;
8982
             next_state   <= rti_upl_state;
8983
 
8984
                          when rti_upl_state =>
8985
                                 -- default
8986
             cc_ctrl    <= latch_cc;
8987
             acca_ctrl  <= latch_acca;
8988
             accb_ctrl  <= latch_accb;
8989
                                 dp_ctrl    <= latch_dp;
8990
             iy_ctrl    <= latch_iy;
8991
                                 ix_ctrl    <= latch_ix;
8992
             pc_ctrl    <= latch_pc;
8993
             md_ctrl    <= latch_md;
8994
             iv_ctrl    <= latch_iv;
8995
                            op_ctrl    <= latch_op;
8996
             pre_ctrl   <= latch_pre;
8997
                                 nmi_ctrl   <= latch_nmi;
8998
             ea_ctrl    <= latch_ea;
8999
                                 -- increment sp
9000
             left_ctrl  <= sp_left;
9001
             right_ctrl <= one_right;
9002
             alu_ctrl   <= alu_add16;
9003
             sp_ctrl    <= load_sp;
9004
                                 -- read up low
9005
             up_ctrl    <= pull_lo_up;
9006
             addr_ctrl  <= pulls_ad;
9007
             dout_ctrl  <= up_lo_dout;
9008
                                 --
9009
                                 st_ctrl      <= idle_st;
9010
                                 return_state <= fetch_state;
9011
             next_state   <= rti_pch_state;
9012
 
9013
                          when rti_pch_state =>
9014
                                 -- default
9015
             cc_ctrl    <= latch_cc;
9016
             acca_ctrl  <= latch_acca;
9017
             accb_ctrl  <= latch_accb;
9018
                                 dp_ctrl    <= latch_dp;
9019
             ix_ctrl    <= latch_ix;
9020
             iy_ctrl    <= latch_iy;
9021
             up_ctrl    <= latch_up;
9022
             pc_ctrl    <= latch_pc;
9023
             md_ctrl    <= latch_md;
9024
             iv_ctrl    <= latch_iv;
9025
                            op_ctrl    <= latch_op;
9026
             pre_ctrl   <= latch_pre;
9027
                                 nmi_ctrl   <= latch_nmi;
9028
             ea_ctrl    <= latch_ea;
9029
                  -- increment sp
9030
             left_ctrl  <= sp_left;
9031
             right_ctrl <= one_right;
9032
             alu_ctrl   <= alu_add16;
9033
             sp_ctrl    <= load_sp;
9034
                                 -- pull pc hi
9035
                                 pc_ctrl    <= pull_hi_pc;
9036
             addr_ctrl  <= pulls_ad;
9037
             dout_ctrl  <= pc_hi_dout;
9038
                                 --
9039
                                 st_ctrl      <= idle_st;
9040
                                 return_state <= fetch_state;
9041
             next_state   <= rti_pcl_state;
9042
 
9043
                          when rti_pcl_state =>
9044
                                 -- default
9045
             cc_ctrl    <= latch_cc;
9046
             acca_ctrl  <= latch_acca;
9047
             accb_ctrl  <= latch_accb;
9048
                                 dp_ctrl    <= latch_dp;
9049
             ix_ctrl    <= latch_ix;
9050
             iy_ctrl    <= latch_iy;
9051
             up_ctrl    <= latch_up;
9052
             md_ctrl    <= latch_md;
9053
             iv_ctrl    <= latch_iv;
9054
                            op_ctrl    <= latch_op;
9055
             pre_ctrl   <= latch_pre;
9056
                                 nmi_ctrl   <= latch_nmi;
9057
             ea_ctrl    <= latch_ea;
9058
                                 -- increment sp
9059
             left_ctrl  <= sp_left;
9060
             right_ctrl <= one_right;
9061
             alu_ctrl   <= alu_add16;
9062
             sp_ctrl    <= load_sp;
9063
                  -- pull pc low
9064
                                 pc_ctrl    <= pull_lo_pc;
9065
             addr_ctrl  <= pulls_ad;
9066
             dout_ctrl  <= pc_lo_dout;
9067
                                 --
9068
                                 st_ctrl      <= idle_st;
9069
                                 return_state <= fetch_state;
9070
             next_state   <= fetch_state;
9071
 
9072
                          --
9073
                          -- here on IRQ, NMI or FIRQ interrupt
9074
                          -- pre decrement the sp
9075
                          --
9076
                          when int_decr_state =>
9077
                                 -- default
9078
             cc_ctrl    <= latch_cc;
9079
             acca_ctrl  <= latch_acca;
9080
             accb_ctrl  <= latch_accb;
9081
                                 dp_ctrl    <= latch_dp;
9082
             ix_ctrl    <= latch_ix;
9083
             iy_ctrl    <= latch_iy;
9084
             up_ctrl    <= latch_up;
9085
             pc_ctrl    <= latch_pc;
9086
             md_ctrl    <= latch_md;
9087
             iv_ctrl    <= latch_iv;
9088
                            op_ctrl    <= latch_op;
9089
             pre_ctrl   <= latch_pre;
9090
                                 nmi_ctrl   <= latch_nmi;
9091
             ea_ctrl    <= latch_ea;
9092
             -- decrement sp
9093
             left_ctrl  <= sp_left;
9094
             right_ctrl <= one_right;
9095
             alu_ctrl   <= alu_sub16;
9096
             sp_ctrl    <= load_sp;
9097
                                 -- idle bus
9098
             addr_ctrl  <= idle_ad;
9099
                            dout_ctrl  <= pc_lo_dout;
9100
                                 --
9101
                                 st_ctrl      <= idle_st;
9102
                                 return_state <= fetch_state;
9103
             next_state   <= int_entire_state;
9104
 
9105
                          --
9106
                          -- set Entire Flag on SWI, SWI2, SWI3 and CWAI, IRQ and NMI
9107
                          -- clear Entire Flag on FIRQ
9108
                          -- before stacking all registers
9109
                          --
9110
                          when int_entire_state =>
9111
                                 -- default
9112
             acca_ctrl  <= latch_acca;
9113
             accb_ctrl  <= latch_accb;
9114
                                 dp_ctrl    <= latch_dp;
9115
             ix_ctrl    <= latch_ix;
9116
             iy_ctrl    <= latch_iy;
9117
             up_ctrl    <= latch_up;
9118
             sp_ctrl    <= latch_sp;
9119
             pc_ctrl    <= latch_pc;
9120
             md_ctrl    <= latch_md;
9121
             iv_ctrl    <= latch_iv;
9122
                            op_ctrl    <= latch_op;
9123
             pre_ctrl   <= latch_pre;
9124
                                 nmi_ctrl   <= latch_nmi;
9125
             ea_ctrl    <= latch_ea;
9126
                                 --
9127
             left_ctrl  <= sp_left;
9128
             right_ctrl <= zero_right;
9129
                                 if iv = FIRQ_VEC then
9130
               -- clear entire flag
9131
               alu_ctrl   <= alu_cle;
9132
                                 else
9133
               -- set entire flag
9134
               alu_ctrl   <= alu_see;
9135
                                 end if;
9136
             cc_ctrl    <= load_cc;
9137
                                 -- idle bus
9138
             addr_ctrl  <= idle_ad;
9139
                            dout_ctrl  <= pc_lo_dout;
9140
                                 --
9141
                                 st_ctrl      <= idle_st;
9142
                                 return_state <= fetch_state;
9143
             next_state   <= int_pcl_state;
9144
 
9145
                          when int_pcl_state =>
9146
                                 -- default
9147
             cc_ctrl    <= latch_cc;
9148
             acca_ctrl  <= latch_acca;
9149
             accb_ctrl  <= latch_accb;
9150
                                 dp_ctrl    <= latch_dp;
9151
             ix_ctrl    <= latch_ix;
9152
             iy_ctrl    <= latch_iy;
9153
             up_ctrl    <= latch_up;
9154
             pc_ctrl    <= latch_pc;
9155
             md_ctrl    <= latch_md;
9156
             iv_ctrl    <= latch_iv;
9157
                            op_ctrl    <= latch_op;
9158
             pre_ctrl   <= latch_pre;
9159
                                 nmi_ctrl   <= latch_nmi;
9160
             ea_ctrl    <= latch_ea;
9161
             -- decrement sp
9162
             left_ctrl  <= sp_left;
9163
             right_ctrl <= one_right;
9164
             alu_ctrl   <= alu_sub16;
9165
             sp_ctrl    <= load_sp;
9166
                                 -- write pc low
9167
             addr_ctrl  <= pushs_ad;
9168
                            dout_ctrl  <= pc_lo_dout;
9169
                                 --
9170
                                 st_ctrl      <= idle_st;
9171
                                 return_state <= fetch_state;
9172
             next_state   <= int_pch_state;
9173
 
9174
                          when int_pch_state =>
9175
                                 -- default
9176
             cc_ctrl    <= latch_cc;
9177
             acca_ctrl  <= latch_acca;
9178
             accb_ctrl  <= latch_accb;
9179
                                 dp_ctrl    <= latch_dp;
9180
             ix_ctrl    <= latch_ix;
9181
             iy_ctrl    <= latch_iy;
9182
             up_ctrl    <= latch_up;
9183
             pc_ctrl    <= latch_pc;
9184
             md_ctrl    <= latch_md;
9185
             iv_ctrl    <= latch_iv;
9186
                            op_ctrl    <= latch_op;
9187
             pre_ctrl   <= latch_pre;
9188
                                 nmi_ctrl   <= latch_nmi;
9189
             ea_ctrl    <= latch_ea;
9190
             -- decrement sp
9191
             left_ctrl  <= sp_left;
9192
             right_ctrl <= one_right;
9193
             alu_ctrl   <= alu_sub16;
9194
             sp_ctrl    <= load_sp;
9195
                                 -- write pc hi
9196
             addr_ctrl  <= pushs_ad;
9197
                            dout_ctrl  <= pc_hi_dout;
9198
                                 --
9199
                                 st_ctrl      <= idle_st;
9200
                                 return_state <= fetch_state;
9201
                                 if cc(EBIT) = '1' then
9202
               next_state   <= int_upl_state;
9203
                                 else
9204
               next_state   <= int_cc_state;
9205
                                 end if;
9206
 
9207
                          when int_upl_state =>
9208
                                 -- default
9209
             cc_ctrl    <= latch_cc;
9210
             acca_ctrl  <= latch_acca;
9211
             accb_ctrl  <= latch_accb;
9212
                                 dp_ctrl    <= latch_dp;
9213
             ix_ctrl    <= latch_ix;
9214
             iy_ctrl    <= latch_iy;
9215
             up_ctrl    <= latch_up;
9216
             pc_ctrl    <= latch_pc;
9217
             md_ctrl    <= latch_md;
9218
             iv_ctrl    <= latch_iv;
9219
                            op_ctrl    <= latch_op;
9220
             pre_ctrl   <= latch_pre;
9221
                                 nmi_ctrl   <= latch_nmi;
9222
             ea_ctrl    <= latch_ea;
9223
             -- decrement sp
9224
             left_ctrl  <= sp_left;
9225
             right_ctrl <= one_right;
9226
             alu_ctrl   <= alu_sub16;
9227
             sp_ctrl    <= load_sp;
9228
                                 -- write up low
9229
             addr_ctrl  <= pushs_ad;
9230
                            dout_ctrl  <= up_lo_dout;
9231
                                 --
9232
                                 st_ctrl      <= idle_st;
9233
                                 return_state <= fetch_state;
9234
             next_state   <= int_uph_state;
9235
 
9236
                          when int_uph_state =>
9237
                                 -- default
9238
             cc_ctrl    <= latch_cc;
9239
             acca_ctrl  <= latch_acca;
9240
             accb_ctrl  <= latch_accb;
9241
                                 dp_ctrl    <= latch_dp;
9242
             ix_ctrl    <= latch_ix;
9243
             iy_ctrl    <= latch_iy;
9244
             up_ctrl    <= latch_up;
9245
             pc_ctrl    <= latch_pc;
9246
             md_ctrl    <= latch_md;
9247
             iv_ctrl    <= latch_iv;
9248
                            op_ctrl    <= latch_op;
9249
             pre_ctrl   <= latch_pre;
9250
                                 nmi_ctrl   <= latch_nmi;
9251
             ea_ctrl    <= latch_ea;
9252
             -- decrement sp
9253
             left_ctrl  <= sp_left;
9254
             right_ctrl <= one_right;
9255
             alu_ctrl   <= alu_sub16;
9256
             sp_ctrl    <= load_sp;
9257
                                 -- write ix hi
9258
             addr_ctrl  <= pushs_ad;
9259
                            dout_ctrl  <= up_hi_dout;
9260
                                 --
9261
                                 st_ctrl      <= idle_st;
9262
                                 return_state <= fetch_state;
9263
             next_state   <= int_iyl_state;
9264
 
9265
                          when int_iyl_state =>
9266
                                 -- default
9267
             cc_ctrl    <= latch_cc;
9268
             acca_ctrl  <= latch_acca;
9269
             accb_ctrl  <= latch_accb;
9270
                                 dp_ctrl    <= latch_dp;
9271
             ix_ctrl    <= latch_ix;
9272
             iy_ctrl    <= latch_iy;
9273
             up_ctrl    <= latch_up;
9274
             pc_ctrl    <= latch_pc;
9275
             md_ctrl    <= latch_md;
9276
             iv_ctrl    <= latch_iv;
9277
                            op_ctrl    <= latch_op;
9278
             pre_ctrl   <= latch_pre;
9279
                                 nmi_ctrl   <= latch_nmi;
9280
             ea_ctrl    <= latch_ea;
9281
             -- decrement sp
9282
             left_ctrl  <= sp_left;
9283
             right_ctrl <= one_right;
9284
             alu_ctrl   <= alu_sub16;
9285
             sp_ctrl    <= load_sp;
9286
                                 -- write ix low
9287
             addr_ctrl  <= pushs_ad;
9288
                            dout_ctrl  <= iy_lo_dout;
9289
                                 --
9290
                                 st_ctrl      <= idle_st;
9291
                                 return_state <= fetch_state;
9292
             next_state   <= int_iyh_state;
9293
 
9294
                          when int_iyh_state =>
9295
                                 -- default
9296
             cc_ctrl    <= latch_cc;
9297
             acca_ctrl  <= latch_acca;
9298
             accb_ctrl  <= latch_accb;
9299
                                 dp_ctrl    <= latch_dp;
9300
             ix_ctrl    <= latch_ix;
9301
             iy_ctrl    <= latch_iy;
9302
             up_ctrl    <= latch_up;
9303
             pc_ctrl    <= latch_pc;
9304
             md_ctrl    <= latch_md;
9305
             iv_ctrl    <= latch_iv;
9306
                            op_ctrl    <= latch_op;
9307
             pre_ctrl   <= latch_pre;
9308
                                 nmi_ctrl   <= latch_nmi;
9309
             ea_ctrl    <= latch_ea;
9310
             -- decrement sp
9311
             left_ctrl  <= sp_left;
9312
             right_ctrl <= one_right;
9313
             alu_ctrl   <= alu_sub16;
9314
             sp_ctrl    <= load_sp;
9315
                                 -- write ix hi
9316
             addr_ctrl  <= pushs_ad;
9317
                            dout_ctrl  <= iy_hi_dout;
9318
                                 --
9319
                                 st_ctrl      <= idle_st;
9320
                                 return_state <= fetch_state;
9321
             next_state   <= int_ixl_state;
9322
 
9323
                          when int_ixl_state =>
9324
                                 -- default
9325
             cc_ctrl    <= latch_cc;
9326
             acca_ctrl  <= latch_acca;
9327
             accb_ctrl  <= latch_accb;
9328
                                 dp_ctrl    <= latch_dp;
9329
             ix_ctrl    <= latch_ix;
9330
             iy_ctrl    <= latch_iy;
9331
             up_ctrl    <= latch_up;
9332
             pc_ctrl    <= latch_pc;
9333
             md_ctrl    <= latch_md;
9334
             iv_ctrl    <= latch_iv;
9335
                            op_ctrl    <= latch_op;
9336
             pre_ctrl   <= latch_pre;
9337
                                 nmi_ctrl   <= latch_nmi;
9338
             ea_ctrl    <= latch_ea;
9339
             -- decrement sp
9340
             left_ctrl  <= sp_left;
9341
             right_ctrl <= one_right;
9342
             alu_ctrl   <= alu_sub16;
9343
             sp_ctrl    <= load_sp;
9344
                                 -- write ix low
9345
             addr_ctrl  <= pushs_ad;
9346
                            dout_ctrl  <= ix_lo_dout;
9347
                                 --
9348
                                 st_ctrl      <= idle_st;
9349
                                 return_state <= fetch_state;
9350
             next_state   <= int_ixh_state;
9351
 
9352
                          when int_ixh_state =>
9353
                                 -- default
9354
             cc_ctrl    <= latch_cc;
9355
             acca_ctrl  <= latch_acca;
9356
             accb_ctrl  <= latch_accb;
9357
                                 dp_ctrl    <= latch_dp;
9358
             ix_ctrl    <= latch_ix;
9359
             iy_ctrl    <= latch_iy;
9360
             up_ctrl    <= latch_up;
9361
             pc_ctrl    <= latch_pc;
9362
             md_ctrl    <= latch_md;
9363
             iv_ctrl    <= latch_iv;
9364
                            op_ctrl    <= latch_op;
9365
             pre_ctrl   <= latch_pre;
9366
                                 nmi_ctrl   <= latch_nmi;
9367
             ea_ctrl    <= latch_ea;
9368
             -- decrement sp
9369
             left_ctrl  <= sp_left;
9370
             right_ctrl <= one_right;
9371
             alu_ctrl   <= alu_sub16;
9372
             sp_ctrl    <= load_sp;
9373
                                 -- write ix hi
9374
             addr_ctrl  <= pushs_ad;
9375
                            dout_ctrl  <= ix_hi_dout;
9376
                                 --
9377
                                 st_ctrl      <= idle_st;
9378
                                 return_state <= fetch_state;
9379
             next_state   <= int_dp_state;
9380
 
9381
                          when int_dp_state =>
9382
                                 -- default
9383
             cc_ctrl    <= latch_cc;
9384
             acca_ctrl  <= latch_acca;
9385
             accb_ctrl  <= latch_accb;
9386
                                 dp_ctrl    <= latch_dp;
9387
             ix_ctrl    <= latch_ix;
9388
             iy_ctrl    <= latch_iy;
9389
             up_ctrl    <= latch_up;
9390
             pc_ctrl    <= latch_pc;
9391
             md_ctrl    <= latch_md;
9392
             iv_ctrl    <= latch_iv;
9393
                            op_ctrl    <= latch_op;
9394
             pre_ctrl   <= latch_pre;
9395
                                 nmi_ctrl   <= latch_nmi;
9396
             ea_ctrl    <= latch_ea;
9397
             -- decrement sp
9398
             left_ctrl  <= sp_left;
9399
             right_ctrl <= one_right;
9400
             alu_ctrl   <= alu_sub16;
9401
             sp_ctrl    <= load_sp;
9402
                                 -- write accb
9403
             addr_ctrl  <= pushs_ad;
9404
                            dout_ctrl  <= dp_dout;
9405
                                 --
9406
                                 st_ctrl      <= idle_st;
9407
                                 return_state <= fetch_state;
9408
             next_state   <= int_accb_state;
9409
 
9410
                          when int_accb_state =>
9411
                                 -- default
9412
             cc_ctrl    <= latch_cc;
9413
             acca_ctrl  <= latch_acca;
9414
             accb_ctrl  <= latch_accb;
9415
                                 dp_ctrl    <= latch_dp;
9416
             ix_ctrl    <= latch_ix;
9417
             iy_ctrl    <= latch_iy;
9418
             up_ctrl    <= latch_up;
9419
             pc_ctrl    <= latch_pc;
9420
             md_ctrl    <= latch_md;
9421
             iv_ctrl    <= latch_iv;
9422
                            op_ctrl    <= latch_op;
9423
             pre_ctrl   <= latch_pre;
9424
                                 nmi_ctrl   <= latch_nmi;
9425
             ea_ctrl    <= latch_ea;
9426
             -- decrement sp
9427
             left_ctrl  <= sp_left;
9428
             right_ctrl <= one_right;
9429
             alu_ctrl   <= alu_sub16;
9430
             sp_ctrl    <= load_sp;
9431
                                 -- write accb
9432
             addr_ctrl  <= pushs_ad;
9433
                            dout_ctrl  <= accb_dout;
9434
                                 --
9435
                                 st_ctrl      <= idle_st;
9436
                                 return_state <= fetch_state;
9437
             next_state   <= int_acca_state;
9438
 
9439
                          when int_acca_state =>
9440
                                 -- default
9441
             cc_ctrl    <= latch_cc;
9442
             acca_ctrl  <= latch_acca;
9443
             accb_ctrl  <= latch_accb;
9444
                                 dp_ctrl    <= latch_dp;
9445
             ix_ctrl    <= latch_ix;
9446
             iy_ctrl    <= latch_iy;
9447
             up_ctrl    <= latch_up;
9448
             pc_ctrl    <= latch_pc;
9449
             md_ctrl    <= latch_md;
9450
             iv_ctrl    <= latch_iv;
9451
                            op_ctrl    <= latch_op;
9452
             pre_ctrl   <= latch_pre;
9453
                                 nmi_ctrl   <= latch_nmi;
9454
             ea_ctrl    <= latch_ea;
9455
             -- decrement sp
9456
             left_ctrl  <= sp_left;
9457
             right_ctrl <= one_right;
9458
             alu_ctrl   <= alu_sub16;
9459
             sp_ctrl    <= load_sp;
9460
                                 -- write acca
9461
             addr_ctrl  <= pushs_ad;
9462
                            dout_ctrl  <= acca_dout;
9463
                                 --
9464
                                 st_ctrl      <= idle_st;
9465
                                 return_state <= fetch_state;
9466
             next_state   <= int_cc_state;
9467
 
9468
                          when int_cc_state =>
9469
                                 -- default
9470
             cc_ctrl    <= latch_cc;
9471
             acca_ctrl  <= latch_acca;
9472
             accb_ctrl  <= latch_accb;
9473
                                 dp_ctrl    <= latch_dp;
9474
             ix_ctrl    <= latch_ix;
9475
             iy_ctrl    <= latch_iy;
9476
             up_ctrl    <= latch_up;
9477
             pc_ctrl    <= latch_pc;
9478
             md_ctrl    <= latch_md;
9479
                            op_ctrl    <= latch_op;
9480
             pre_ctrl   <= latch_pre;
9481
                                 nmi_ctrl   <= latch_nmi;
9482
             iv_ctrl    <= latch_iv;
9483
             ea_ctrl    <= latch_ea;
9484
             -- idle sp
9485
             left_ctrl  <= sp_left;
9486
             right_ctrl <= zero_right;
9487
             alu_ctrl   <= alu_nop;
9488
             sp_ctrl    <= latch_sp;
9489
                                 -- write cc
9490
             addr_ctrl  <= pushs_ad;
9491
                            dout_ctrl  <= cc_dout;
9492
                                 nmi_ctrl   <= latch_nmi;
9493
                                 --
9494
                                 st_ctrl      <= idle_st;
9495
                                 return_state <= fetch_state;
9496
                                 case iv is
9497
                                 when NMI_VEC =>
9498
                              next_state <= int_mask_state;
9499
                                 when SWI_VEC =>
9500
                              next_state <= int_mask_state;
9501
                                 when IRQ_VEC =>
9502
                              next_state <= int_mask_state;
9503
                                 when SWI2_VEC =>
9504
                    next_state <= vect_hi_state;
9505
                                 when FIRQ_VEC =>
9506
                              next_state <= int_mask_state;
9507
                                 when SWI3_VEC =>
9508
                    next_state <= vect_hi_state;
9509
                                 when others =>
9510
                                   if op_code = "00111100" then -- CWAI
9511
                                          next_state <= int_cwai_state;
9512
                                        else
9513
                      next_state <= rti_cc_state; -- spurious interrupt, do a RTI
9514
                                        end if;
9515
                                 end case;
9516
 
9517
                          --
9518
                          -- wait here for an inteerupt
9519
                          --
9520
                          when int_cwai_state =>
9521
                                 -- default
9522
             acca_ctrl  <= latch_acca;
9523
             accb_ctrl  <= latch_accb;
9524
                                 dp_ctrl    <= latch_dp;
9525
             ix_ctrl    <= latch_ix;
9526
             iy_ctrl    <= latch_iy;
9527
             up_ctrl    <= latch_up;
9528
             pc_ctrl    <= latch_pc;
9529
             md_ctrl    <= latch_md;
9530
                            op_ctrl    <= latch_op;
9531
             pre_ctrl   <= latch_pre;
9532
             ea_ctrl    <= latch_ea;
9533
             --
9534
             left_ctrl  <= sp_left;
9535
             right_ctrl <= one_right;
9536
             alu_ctrl   <= alu_nop;
9537
             cc_ctrl    <= latch_cc;
9538
             sp_ctrl    <= latch_sp;
9539
                                 -- idle bus
9540
             addr_ctrl  <= idle_ad;
9541
                            dout_ctrl  <= cc_dout;
9542
                                 --
9543
                                 st_ctrl    <= idle_st;
9544
                                 return_state <= fetch_state;
9545
                                 --
9546
                            if (nmi_req = '1') and (nmi_ack='0') then
9547
                                        iv_ctrl    <= nmi_iv;
9548
                                   nmi_ctrl   <= set_nmi;
9549
--
9550
-- John Kent 18th Feb 2008
9551
-- 
9552
--                            next_state <= vect_hi_state;
9553
                              next_state <= int_mask_state;
9554
                            else
9555
                                   --
9556
                                        -- nmi request is not cleared until nmi input goes low
9557
                                        --
9558
                                   if (nmi_req = '0') and (nmi_ack='1') then
9559
                                     nmi_ctrl <= reset_nmi;
9560
                                        else
9561
                                          nmi_ctrl <= latch_nmi;
9562
                                        end if;
9563
                                        --
9564
                                        -- FIRQ is level sensitive
9565
                                        --
9566
               if (firq = '1') and (cc(FBIT) = '0') then
9567
                                          iv_ctrl    <= firq_iv;
9568
                                next_state <= int_mask_state;
9569
                                        --
9570
                                        -- IRQ is level sensitive
9571
                                        --
9572
                                   elsif (irq = '1') and (cc(IBIT) = '0') then
9573
                                          iv_ctrl    <= irq_iv;
9574
                                next_state <= int_mask_state;
9575
               else
9576
                 iv_ctrl    <= latch_iv;
9577
                      next_state <= int_cwai_state;
9578
                                        end if;
9579
                                 end if;
9580
 
9581
                          when int_mask_state =>
9582
                                 -- default
9583
             acca_ctrl  <= latch_acca;
9584
             accb_ctrl  <= latch_accb;
9585
                                 dp_ctrl    <= latch_dp;
9586
             ix_ctrl    <= latch_ix;
9587
             iy_ctrl    <= latch_iy;
9588
             up_ctrl    <= latch_up;
9589
             pc_ctrl    <= latch_pc;
9590
             md_ctrl    <= latch_md;
9591
             iv_ctrl    <= latch_iv;
9592
                            op_ctrl    <= latch_op;
9593
             pre_ctrl   <= latch_pre;
9594
                                 nmi_ctrl   <= latch_nmi;
9595
             ea_ctrl    <= latch_ea;
9596
                                 -- Mask IRQ and FIRQ
9597
             left_ctrl  <= sp_left;
9598
             right_ctrl <= zero_right;
9599
                                 --
9600
                                 -- FIRQ can interrupt an IRQ service routine
9601
                                 --
9602
                                 if iv = IRQ_VEC then
9603
                                   alu_ctrl   <= alu_sei;
9604
                                 else
9605
                              alu_ctrl   <= alu_seif;
9606
                                 end if;
9607
                                 cc_ctrl    <= load_cc;
9608
             sp_ctrl    <= latch_sp;
9609
                                 -- idle bus cycle
9610
             addr_ctrl  <= idle_ad;
9611
             dout_ctrl  <= md_lo_dout;
9612
                                 --
9613
                                 st_ctrl      <= idle_st;
9614
                                 return_state <= fetch_state;
9615
             next_state   <= vect_hi_state;
9616
 
9617
                          --
9618
                          -- According to the 6809 programming manual:
9619
                          -- If an interrupt is received and is masked 
9620
                          -- or lasts for less than three cycles, the PC 
9621
                          -- will advance to the next instruction.
9622
                          -- If an interrupt is unmasked and lasts
9623
                          -- for more than three cycles, an interrupt
9624
                          -- will be generated.
9625
                          -- Note that I don't wait 3 clock cycles.
9626
                          -- John Kent 11th July 2006
9627
                          --
9628
                          when sync_state =>
9629
             cc_ctrl    <= latch_cc;
9630
             acca_ctrl  <= latch_acca;
9631
             accb_ctrl  <= latch_accb;
9632
                                 dp_ctrl    <= latch_dp;
9633
             ix_ctrl    <= latch_ix;
9634
             iy_ctrl    <= latch_iy;
9635
             up_ctrl    <= latch_up;
9636
             sp_ctrl    <= latch_sp;
9637
             pc_ctrl    <= latch_pc;
9638
             md_ctrl    <= latch_md;
9639
                            op_ctrl    <= latch_op;
9640
             pre_ctrl   <= latch_pre;
9641
             ea_ctrl    <= latch_ea;
9642
             --
9643
             left_ctrl  <= pc_left;
9644
             right_ctrl <= one_right;
9645
             alu_ctrl   <= alu_nop;
9646
                                 -- idle bus
9647
             addr_ctrl  <= idle_ad;
9648
                            dout_ctrl  <= cc_dout;
9649
                                 --
9650
                                 st_ctrl    <= idle_st;
9651
                                 return_state <= fetch_state;
9652
                                 --
9653
                            if (nmi_req = '1') and (nmi_ack='0') then
9654
                                        iv_ctrl    <= nmi_iv;
9655
                                   nmi_ctrl   <= set_nmi;
9656
                              next_state <= int_decr_state;
9657
                            else
9658
                                   --
9659
                                        -- nmi request is not cleared until nmi input goes low
9660
                                        --
9661
                                   if (nmi_req = '0') and (nmi_ack='1') then
9662
                                     nmi_ctrl <= reset_nmi;
9663
                                        else
9664
                                          nmi_ctrl <= latch_nmi;
9665
                                        end if;
9666
                                        --
9667
                                        -- FIRQ is level sensitive
9668
                                        --
9669
               if (firq = '1') then
9670
                                          iv_ctrl    <= firq_iv;
9671
                                          if (cc(FBIT) = '0') then
9672
                                  next_state <= int_decr_state;
9673
                                          else
9674
                                  next_state <= fetch_state;
9675
                                          end if;
9676
                                        --
9677
                                        -- IRQ is level sensitive
9678
                                        --
9679
                                   elsif (irq = '1') then
9680
                                          iv_ctrl    <= irq_iv;
9681
                                          if (cc(IBIT) = '0') then
9682
                                            next_state <= int_decr_state;
9683
                                          else
9684
                                  next_state <= fetch_state;
9685
                                          end if;
9686
               else
9687
                 iv_ctrl    <= latch_iv;
9688
                      next_state <= sync_state;
9689
                                        end if;
9690
                                 end if;
9691
 
9692
 
9693
                          when halt_state =>
9694
                                 -- default
9695
                                 cc_ctrl    <= latch_cc;
9696
             acca_ctrl  <= latch_acca;
9697
             accb_ctrl  <= latch_accb;
9698
                                 dp_ctrl    <= latch_dp;
9699
             ix_ctrl    <= latch_ix;
9700
             iy_ctrl    <= latch_iy;
9701
             up_ctrl    <= latch_up;
9702
             pc_ctrl    <= latch_pc;
9703
             md_ctrl    <= latch_md;
9704
             iv_ctrl    <= latch_iv;
9705
                            op_ctrl    <= latch_op;
9706
             pre_ctrl   <= latch_pre;
9707
                                 nmi_ctrl   <= latch_nmi;
9708
             ea_ctrl    <= latch_ea;
9709
                                 -- idle ALU
9710
             left_ctrl  <= acca_left;
9711
             right_ctrl <= zero_right;
9712
                            alu_ctrl   <= alu_nop;
9713
             sp_ctrl    <= latch_sp;
9714
                                 -- idle bus cycle
9715
             addr_ctrl  <= idle_ad;
9716
             dout_ctrl  <= md_lo_dout;
9717
                                 --
9718
                                 if halt = '1' then
9719
                                   st_ctrl      <= idle_st;
9720
                                   return_state <= fetch_state;
9721
               next_state   <= halt_state;
9722
                                 else
9723
                                   st_ctrl      <= pull_st;
9724
                                   return_state <= fetch_state;
9725
                                   next_state   <= saved_state;
9726
                                 end if;
9727
 
9728
                          when others => -- halt on undefine states
9729
                                 -- default
9730
             cc_ctrl    <= latch_cc;
9731
             acca_ctrl  <= latch_acca;
9732
             accb_ctrl  <= latch_accb;
9733
                                 dp_ctrl    <= latch_dp;
9734
             ix_ctrl    <= latch_ix;
9735
             iy_ctrl    <= latch_iy;
9736
             up_ctrl    <= latch_up;
9737
             sp_ctrl    <= latch_sp;
9738
             pc_ctrl    <= latch_pc;
9739
             md_ctrl    <= latch_md;
9740
             iv_ctrl    <= latch_iv;
9741
                            op_ctrl    <= latch_op;
9742
             pre_ctrl   <= latch_pre;
9743
                                 nmi_ctrl   <= latch_nmi;
9744
             ea_ctrl    <= latch_ea;
9745
                                 -- do nothing in ALU
9746
             left_ctrl  <= acca_left;
9747
             right_ctrl <= zero_right;
9748
             alu_ctrl   <= alu_nop;
9749
                                 -- idle bus cycle
9750
             addr_ctrl  <= idle_ad;
9751
             dout_ctrl  <= md_lo_dout;
9752
                                 --
9753
                                 st_ctrl    <= idle_st;
9754
                                 return_state <= fetch_state;
9755
                            next_state <= error_state;
9756
                  end case;
9757
end process;
9758
 
9759
end rtl;
9760
 

powered by: WebSVN 2.1.0

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