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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_0/] [rtl/] [vhdl/] [decoder.vhd] - Blame information for rev 204

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

Line No. Rev Author Line
1 4 arniml
-------------------------------------------------------------------------------
2
--
3
-- The Decoder unit.
4
-- It decodes the instruction opcodes and executes them.
5
--
6 204 arniml
-- $Id: decoder.vhd,v 1.22 2005-11-01 21:25:37 arniml Exp $
7 4 arniml
--
8
-- Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
9
--
10
-- All rights reserved
11
--
12
-- Redistribution and use in source and synthezised forms, with or without
13
-- modification, are permitted provided that the following conditions are met:
14
--
15
-- Redistributions of source code must retain the above copyright notice,
16
-- this list of conditions and the following disclaimer.
17
--
18
-- Redistributions in synthesized form must reproduce the above copyright
19
-- notice, this list of conditions and the following disclaimer in the
20
-- documentation and/or other materials provided with the distribution.
21
--
22
-- Neither the name of the author nor the names of other contributors may
23
-- be used to endorse or promote products derived from this software without
24
-- specific prior written permission.
25
--
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
28
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
-- POSSIBILITY OF SUCH DAMAGE.
37
--
38
-- Please report bugs to the author, but before you do so, please
39
-- make sure that this is not a derivative work and that
40
-- you have the latest version of this file.
41
--
42
-- The latest version of this file can be found at:
43
--      http://www.opencores.org/cvsweb.shtml/t48/
44
--
45
-------------------------------------------------------------------------------
46
 
47
library ieee;
48
use ieee.std_logic_1164.all;
49
 
50
use work.t48_pack.word_t;
51
use work.t48_pack.mstate_t;
52 179 arniml
use work.t48_alu_pack.alu_op_t;
53
use work.t48_cond_branch_pack.all;
54
use work.t48_dmem_ctrl_pack.all;
55
use work.t48_pmem_ctrl_pack.all;
56 4 arniml
 
57 179 arniml
entity t48_decoder is
58 4 arniml
 
59
  generic (
60
    -- store mnemonic in flip-flops (registered-out)
61
    register_mnemonic_g   : integer := 1
62
  );
63
 
64
  port (
65
    -- Global Interface -------------------------------------------------------
66
    clk_i                  : in  std_logic;
67
    res_i                  : in  std_logic;
68
    en_clk_i               : in  boolean;
69 204 arniml
    xtal_i                 : in  std_logic;
70 4 arniml
    ea_i                   : in  std_logic;
71
    ale_i                  : in  boolean;
72
    int_n_i                : in  std_logic;
73
    t0_dir_o               : out std_logic;
74
    -- T48 Bus Interface ------------------------------------------------------
75
    data_i                 : in  word_t;
76
    data_o                 : out word_t;
77
    alu_write_accu_o       : out boolean;
78
    alu_write_shadow_o     : out boolean;
79
    alu_write_temp_reg_o   : out boolean;
80
    alu_read_alu_o         : out boolean;
81
    bus_write_bus_o        : out boolean;
82
    bus_read_bus_o         : out boolean;
83
    dm_write_dmem_addr_o   : out boolean;
84
    dm_write_dmem_o        : out boolean;
85
    dm_read_dmem_o         : out boolean;
86
    p1_write_p1_o          : out boolean;
87
    p1_read_p1_o           : out boolean;
88
    p2_write_p2_o          : out boolean;
89
    p2_write_exp_o         : out boolean;
90
    p2_read_p2_o           : out boolean;
91 21 arniml
    p2_read_exp_o          : out boolean;
92 4 arniml
    pm_write_pcl_o         : out boolean;
93
    pm_read_pcl_o          : out boolean;
94
    pm_write_pch_o         : out boolean;
95
    pm_read_pch_o          : out boolean;
96
    pm_read_pmem_o         : out boolean;
97
    psw_read_psw_o         : out boolean;
98
    psw_read_sp_o          : out boolean;
99
    psw_write_psw_o        : out boolean;
100
    psw_write_sp_o         : out boolean;
101
    -- ALU Interface ----------------------------------------------------------
102
    alu_carry_i            : in  std_logic;
103
    alu_op_o               : out alu_op_t;
104
    alu_use_carry_o        : out boolean;
105 27 arniml
    alu_da_high_o          : out boolean;
106 38 arniml
    alu_accu_low_o         : out boolean;
107 27 arniml
    alu_p06_temp_reg_o     : out boolean;
108
    alu_p60_temp_reg_o     : out boolean;
109
    alu_da_overflow_i      : in  boolean;
110 4 arniml
    -- BUS Interface ----------------------------------------------------------
111
    bus_output_pcl_o       : out boolean;
112
    bus_bidir_bus_o        : out boolean;
113
    -- Clock Controller Interface ---------------------------------------------
114
    clk_multi_cycle_o      : out boolean;
115
    clk_assert_psen_o      : out boolean;
116
    clk_assert_prog_o      : out boolean;
117
    clk_assert_rd_o        : out boolean;
118
    clk_assert_wr_o        : out boolean;
119
    clk_mstate_i           : in  mstate_t;
120
    clk_second_cycle_i     : in  boolean;
121
    -- Conditional Branch Logic Interface -------------------------------------
122
    cnd_compute_take_o     : out boolean;
123
    cnd_branch_cond_o      : out branch_conditions_t;
124
    cnd_take_branch_i      : in  boolean;
125
    cnd_comp_value_o       : out comp_value_t;
126
    cnd_f1_o               : out std_logic;
127
    cnd_tf_o               : out std_logic;
128
    -- Data Memory Controller Interface ---------------------------------------
129
    dm_addr_type_o         : out dmem_addr_ident_t;
130
    -- Port 1 Interface -------------------------------------------------------
131
    p1_read_reg_o          : out boolean;
132
    -- Port 2 Interface -------------------------------------------------------
133
    p2_read_reg_o          : out boolean;
134
    p2_output_pch_o        : out boolean;
135
    -- Program Memory Controller Interface ------------------------------------
136
    pm_inc_pc_o            : out boolean;
137
    pm_write_pmem_addr_o   : out boolean;
138
    pm_addr_type_o         : out pmem_addr_ident_t;
139
    -- Program Status Word Interface ------------------------------------------
140
    psw_special_data_o     : out std_logic;
141
    psw_carry_i            : in  std_logic;
142 27 arniml
    psw_aux_carry_i        : in  std_logic;
143 4 arniml
    psw_f0_i               : in  std_logic;
144
    psw_inc_stackp_o       : out boolean;
145
    psw_dec_stackp_o       : out boolean;
146
    psw_write_carry_o      : out boolean;
147
    psw_write_aux_carry_o  : out boolean;
148
    psw_write_f0_o         : out boolean;
149
    psw_write_bs_o         : out boolean;
150
    -- Timer Interface --------------------------------------------------------
151
    tim_read_timer_o       : out boolean;
152
    tim_write_timer_o      : out boolean;
153
    tim_start_t_o          : out boolean;
154
    tim_start_cnt_o        : out boolean;
155
    tim_stop_tcnt_o        : out boolean;
156
    tim_overflow_i         : in  boolean
157
  );
158
 
159 179 arniml
end t48_decoder;
160 4 arniml
 
161
 
162
use work.t48_pack.all;
163 179 arniml
use work.t48_alu_pack.all;
164
use work.t48_decoder_pack.all;
165 4 arniml
 
166 179 arniml
use work.t48_comp_pack.t48_opc_decoder;
167
use work.t48_comp_pack.t48_int;
168 4 arniml
 
169 53 arniml
-- pragma translate_off
170
use work.t48_tb_pack.tb_istrobe_s;
171
-- pragma translate_on
172
 
173 179 arniml
architecture rtl of t48_decoder is
174 4 arniml
 
175 92 arniml
  -- Enable fixing a bug of Quartus II 4.0
176
  constant enable_quartus_bugfix_c : boolean := true;
177
 
178 4 arniml
  -- Opcode Decoder
179
  signal opc_multi_cycle_s : boolean;
180
  signal opc_read_bus_s    : boolean;
181
  signal opc_inj_int_s     : boolean;
182
  signal opc_opcode_s      : word_t;
183
  signal opc_mnemonic_s    : mnemonic_t;
184
  signal last_cycle_s      : boolean;
185
 
186
  -- state translators
187
  signal assert_psen_s     : boolean;
188
 
189
  -- branch taken handshake
190
  signal branch_taken_s,
191
         branch_taken_q        : boolean;
192
  signal pm_inc_pc_s           : boolean;
193
  signal pm_write_pmem_addr_s  : boolean;
194
  -- additional signal to increment PC during CALL
195
  signal add_inc_pc_s          : boolean;
196
  -- addtional signal to set PC during RET(R)
197
  signal add_write_pmem_addr_s : boolean;
198
 
199
  -- Flag 1
200
  signal clear_f1_s,
201
         cpl_f1_s          : boolean;
202
  signal f1_q              : std_logic;
203
  -- memory bank select
204
  signal clear_mb_s,
205
         set_mb_s          : boolean;
206
  signal mb_q              : std_logic;
207
 
208
  -- T0 direction selection
209
  signal ent0_clk_s        : boolean;
210
  signal t0_dir_q          : std_logic;
211
 
212
  signal data_s            : word_t;
213
  signal read_dec_s        : boolean;
214
 
215
  signal tf_s              : std_logic;
216
 
217
  signal bus_read_bus_s    : boolean;
218
  signal add_read_bus_s    : boolean;
219
 
220
  signal dm_write_dmem_s   : boolean;
221
 
222 204 arniml
  signal p2_output_exp_s   : boolean;
223
 
224 4 arniml
  -- interrupt handling
225
  signal jtf_executed_s    : boolean;
226
  signal en_tcnti_s        : boolean;
227
  signal dis_tcnti_s       : boolean;
228
  signal en_i_s            : boolean;
229
  signal dis_i_s           : boolean;
230
  signal tim_int_s         : boolean;
231
  signal retr_executed_s   : boolean;
232
  signal int_executed_s    : boolean;
233
  signal int_pending_s     : boolean;
234 120 arniml
  signal int_in_progress_s : boolean;
235 4 arniml
 
236 38 arniml
  -- pragma translate_off
237 64 arniml
  signal istrobe_res_q     : std_logic;
238
  signal istrobe_q         : std_logic;
239 60 arniml
  signal injected_int_q    : std_logic;
240 38 arniml
  -- pragma translate_on
241
 
242 4 arniml
begin
243
 
244
  -----------------------------------------------------------------------------
245
  -- Opcode Decoder
246
  -----------------------------------------------------------------------------
247 179 arniml
  opc_decoder_b : t48_opc_decoder
248 4 arniml
    generic map (
249
      register_mnemonic_g => register_mnemonic_g
250
    )
251
    port map (
252
      clk_i         => clk_i,
253
      res_i         => res_i,
254
      en_clk_i      => en_clk_i,
255
      data_i        => data_i,
256
      read_bus_i    => opc_read_bus_s,
257
      inj_int_i     => opc_inj_int_s,
258
      opcode_o      => opc_opcode_s,
259
      mnemonic_o    => opc_mnemonic_s,
260
      multi_cycle_o => opc_multi_cycle_s
261
    );
262
 
263
 
264
  -----------------------------------------------------------------------------
265
  -- Interrupt Controller.
266
  -----------------------------------------------------------------------------
267 179 arniml
  int_b : t48_int
268 4 arniml
    port map (
269 120 arniml
      clk_i             => clk_i,
270
      res_i             => res_i,
271
      en_clk_i          => en_clk_i,
272 204 arniml
      xtal_i            => xtal_i,
273 120 arniml
      clk_mstate_i      => clk_mstate_i,
274
      jtf_executed_i    => jtf_executed_s,
275
      tim_overflow_i    => tim_overflow_i,
276
      tf_o              => tf_s,
277
      en_tcnti_i        => en_tcnti_s,
278
      dis_tcnti_i       => dis_tcnti_s,
279
      int_n_i           => int_n_i,
280
      ale_i             => ale_i,
281
      last_cycle_i      => last_cycle_s,
282
      en_i_i            => en_i_s,
283
      dis_i_i           => dis_i_s,
284
      ext_int_o         => open,
285
      tim_int_o         => tim_int_s,
286
      retr_executed_i   => retr_executed_s,
287
      int_executed_i    => int_executed_s,
288
      int_pending_o     => int_pending_s,
289
      int_in_progress_o => int_in_progress_s
290 4 arniml
    );
291
 
292
  last_cycle_s <= not opc_multi_cycle_s or
293
                  (opc_multi_cycle_s and clk_second_cycle_i);
294
 
295
  -----------------------------------------------------------------------------
296
  -- Process machine_cycle
297
  --
298
  -- Purpose:
299
  --   Generates the control signals that are basically needed for the
300
  --   handling of a machine cycle.
301
  --
302
  machine_cycle: process (clk_mstate_i,
303
                          clk_second_cycle_i,
304 64 arniml
                          last_cycle_s,
305 4 arniml
                          ea_i,
306
                          assert_psen_s,
307
                          branch_taken_q,
308
                          int_pending_s)
309
 
310
   variable need_address_v      : boolean;
311
 
312
  begin
313
    -- default assignments
314
    clk_assert_psen_o    <= false;
315
    pm_inc_pc_s          <= false;
316
    pm_write_pmem_addr_s <= false;
317
    pm_read_pmem_o       <= false;
318
    bus_output_pcl_o     <= false;
319
    p2_output_pch_o      <= false;
320
    opc_read_bus_s       <= false;
321
    opc_inj_int_s        <= false;
322
    bus_read_bus_s       <= false;
323
 
324
    need_address_v    := not clk_second_cycle_i or
325
                         (clk_second_cycle_i and assert_psen_s);
326
 
327
    case clk_mstate_i is
328
      when MSTATE1 =>
329 188 arniml
        if need_address_v then
330 4 arniml
          if ea_i = '0' then
331 188 arniml
            if not int_pending_s then
332
              pm_read_pmem_o <= true;
333
            end if;
334
 
335 4 arniml
          else
336 195 arniml
            if not int_pending_s then
337
              bus_read_bus_s <= true;
338
            end if;
339 188 arniml
            p2_output_pch_o  <= true;
340 4 arniml
          end if;
341 188 arniml
 
342 4 arniml
        end if;
343
 
344
        if not clk_second_cycle_i then
345
          if not int_pending_s then
346
            opc_read_bus_s  <= true;
347
          else
348
            opc_inj_int_s   <= true;    -- inject interrupt call
349
          end if;
350
        end if;
351
 
352
      when MSTATE2 =>
353
        if need_address_v and not branch_taken_q and
354
           not int_pending_s then
355
          pm_inc_pc_s       <= true;
356
        end if;
357
 
358
      when MSTATE3 =>
359
        if need_address_v then
360 106 arniml
          -- Theory of operation:
361
          -- Program Memory address is updated at end of State 3 (or end of
362
          -- State 2 in case of a RET). Address information is thus available
363
          -- latest with State 4.
364
          -- This is the time where we need information about access target
365
          -- (internal or external = EA). EA information needs to be stable
366
          -- until end of State 1.
367 4 arniml
          pm_write_pmem_addr_s <= true;
368 64 arniml
        end if;
369 4 arniml
 
370
      when MSTATE4 =>
371 64 arniml
        if ea_i = '1' and
372 134 arniml
           ((not clk_second_cycle_i and assert_psen_s)
373
            or last_cycle_s) then
374 4 arniml
          clk_assert_psen_o <= true;
375 64 arniml
          p2_output_pch_o   <= true;
376
          bus_output_pcl_o  <= true;
377 4 arniml
        end if;
378
 
379
      when MSTATE5 =>
380 64 arniml
        if ea_i = '1' and
381 204 arniml
           (need_address_v or last_cycle_s) and
382
           not p2_output_exp_s then
383 64 arniml
          p2_output_pch_o   <= true;
384 4 arniml
        end if;
385
 
386
      when others =>
387
        -- pragma translate_off
388
        assert false
389
          report "Unkown machine state!"
390
          severity error;
391
        -- pragma translate_on
392
 
393
    end case;
394
 
395
  end process machine_cycle;
396
  --
397
  -----------------------------------------------------------------------------
398
 
399
 
400
  -----------------------------------------------------------------------------
401
  -- Process decode
402
  --
403
  -- Purpose:
404
  --   Indentifies each single instruction and steps through the related
405
  --   execution sequence.
406
  --
407
  decode: process (alu_carry_i,
408 27 arniml
                   psw_aux_carry_i,
409
                   alu_da_overflow_i,
410 4 arniml
                   clk_mstate_i,
411
                   clk_second_cycle_i,
412
                   cnd_take_branch_i,
413
                   opc_opcode_s,
414
                   opc_mnemonic_s,
415
                   psw_carry_i,
416
                   psw_f0_i,
417
                   f1_q,
418
                   mb_q,
419
                   tim_int_s,
420 120 arniml
                   int_pending_s,
421
                   int_in_progress_s)
422 4 arniml
 
423
    procedure address_indirect_3_f is
424
    begin
425
      -- apply dmem address from selected register for indirect mode
426 92 arniml
      if opc_opcode_s(3) = '0' or enable_quartus_bugfix_c then
427 4 arniml
        dm_read_dmem_o       <= true;
428
        dm_write_dmem_addr_o <= true;
429
        dm_addr_type_o       <= DM_PLAIN;
430
      end if;
431
    end;
432
 
433
    procedure and_or_xor_add_4_f is
434
    begin
435
      -- write dmem contents to Temp Reg
436
      dm_read_dmem_o         <= true;
437
      alu_write_temp_reg_o   <= true;
438
    end;
439
 
440
    procedure and_or_xor_add_5_f (alu_op : alu_op_t) is
441
    begin
442
      -- perform ALU operation and store in Accumulator
443
      alu_op_o               <= alu_op;
444
      alu_read_alu_o         <= true;
445
      alu_write_accu_o       <= true;
446
    end;
447
 
448
    procedure cond_jump_c2_m1_f is
449
    begin
450
      -- store address in Program Counter low byte if branch has to
451
      -- be taken
452 92 arniml
--      if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
453 4 arniml
        pm_write_pcl_o       <= true;
454
        branch_taken_s       <= true;
455 92 arniml
--      end if;
456 4 arniml
    end;
457
 
458 120 arniml
    -- intermediate value of the Program Memory Bank Flag
459
    variable mb_v : std_logic;
460
 
461 4 arniml
  begin
462
    -- default assignments
463
    data_s                 <= (others => '-');
464
    read_dec_s             <= false;
465
    branch_taken_s         <= false;
466
    clear_f1_s             <= false;
467
    cpl_f1_s               <= false;
468
    clear_mb_s             <= false;
469
    set_mb_s               <= false;
470
    add_inc_pc_s           <= false;
471
    assert_psen_s          <= false;
472
    alu_write_accu_o       <= false;
473
    alu_write_shadow_o     <= false;
474
    alu_write_temp_reg_o   <= false;
475 27 arniml
    alu_p06_temp_reg_o     <= false;
476
    alu_p60_temp_reg_o     <= false;
477 4 arniml
    alu_read_alu_o         <= false;
478
    bus_write_bus_o        <= false;
479
    bus_bidir_bus_o        <= false;
480
    dm_write_dmem_addr_o   <= false;
481
    dm_write_dmem_s        <= false;
482
    dm_read_dmem_o         <= false;
483
    pm_write_pcl_o         <= false;
484
    pm_read_pcl_o          <= false;
485
    pm_write_pch_o         <= false;
486
    pm_read_pch_o          <= false;
487
    pm_addr_type_o         <= PM_PC;
488
    psw_read_psw_o         <= false;
489
    psw_read_sp_o          <= false;
490
    psw_write_psw_o        <= false;
491
    psw_write_sp_o         <= false;
492
    alu_op_o               <= ALU_NOP;
493
    alu_use_carry_o        <= false;
494 27 arniml
    alu_da_high_o          <= false;
495 38 arniml
    alu_accu_low_o         <= false;
496 4 arniml
    clk_assert_prog_o      <= false;
497
    clk_assert_rd_o        <= false;
498
    clk_assert_wr_o        <= false;
499
    cnd_branch_cond_o      <= COND_ON_BIT;
500
    cnd_compute_take_o     <= false;
501
    cnd_comp_value_o       <= opc_opcode_s(7 downto 5);
502
    dm_addr_type_o         <= DM_REG;
503
    tim_read_timer_o       <= false;
504
    tim_write_timer_o      <= false;
505
    tim_start_t_o          <= false;
506
    tim_start_cnt_o        <= false;
507
    tim_stop_tcnt_o        <= false;
508
    p1_write_p1_o          <= false;
509
    p1_read_p1_o           <= false;
510
    p1_read_reg_o          <= false;
511
    p2_write_p2_o          <= false;
512
    p2_write_exp_o         <= false;
513
    p2_read_p2_o           <= false;
514
    p2_read_reg_o          <= false;
515 21 arniml
    p2_read_exp_o          <= false;
516 204 arniml
    p2_output_exp_s        <= false;
517 4 arniml
    psw_special_data_o     <= '0';
518
    psw_inc_stackp_o       <= false;
519
    psw_dec_stackp_o       <= false;
520
    psw_write_carry_o      <= false;
521
    psw_write_aux_carry_o  <= false;
522
    psw_write_f0_o         <= false;
523
    psw_write_bs_o         <= false;
524
    jtf_executed_s         <= false;
525
    en_tcnti_s             <= false;
526
    dis_tcnti_s            <= false;
527
    en_i_s                 <= false;
528
    dis_i_s                <= false;
529
    retr_executed_s        <= false;
530
    int_executed_s         <= false;
531
    add_write_pmem_addr_s  <= false;
532
    ent0_clk_s             <= false;
533
    add_read_bus_s         <= false;
534
 
535 120 arniml
    -- the Program Memory Bank Flag is held low when interrupts are in progress
536
    -- according to the MCS-48 User's Manual
537
    if int_in_progress_s then
538
      mb_v := '0';
539
    else
540
      mb_v := mb_q;
541
    end if;
542
 
543 4 arniml
    -- prepare potential register indirect address mode
544
    if not clk_second_cycle_i and clk_mstate_i = MSTATE2 then
545
      data_s               <= (others => '0');
546
      if opc_opcode_s(3) = '1' then
547
        data_s(2 downto 0) <= opc_opcode_s(2 downto 0);
548
      else
549
        data_s(2 downto 0) <= "00" & opc_opcode_s(0);
550
      end if;
551
 
552
      read_dec_s           <= true;
553
      dm_write_dmem_addr_o <= true;
554
      dm_addr_type_o       <= DM_REG;
555
    end if;
556
 
557
    case opc_mnemonic_s is
558
 
559
      -- Mnemonic ADD ---------------------------------------------------------
560
      when MN_ADD =>
561
        case clk_mstate_i is
562
          -- read RAM once for indirect address mode
563
          when MSTATE3 =>
564 92 arniml
            if not enable_quartus_bugfix_c or
565
               opc_opcode_s(3) = '0' then
566
              address_indirect_3_f;
567
            end if;
568 4 arniml
 
569
          -- store data from RAM to Temp Reg
570
          when MSTATE4 =>
571
            and_or_xor_add_4_f;
572
 
573
          -- perform ADD and store in Accumulator
574
          when MSTATE5 =>
575
            and_or_xor_add_5_f(alu_op => ALU_ADD);
576
 
577
            if opc_opcode_s(4) = '1' then
578 27 arniml
              alu_use_carry_o     <= true;
579 4 arniml
            end if;
580
 
581 27 arniml
            psw_special_data_o    <= alu_carry_i;
582
            psw_write_carry_o     <= true;
583
            psw_write_aux_carry_o <= true;
584 4 arniml
 
585
          when others =>
586
            null;
587
 
588
        end case;
589
 
590
      -- Mnemonic ADD_A_DATA --------------------------------------------------
591
      when MN_ADD_A_DATA =>
592 27 arniml
        assert_psen_s               <= true;
593 4 arniml
 
594
        if clk_second_cycle_i then
595
          case clk_mstate_i is
596
            -- write Temp Reg when contents of Program Memory is on bus
597
            when MSTATE1 =>
598 27 arniml
              alu_write_temp_reg_o  <= true;
599 4 arniml
 
600
            -- perform ADD and store in Accumulator
601
            when MSTATE3 =>
602
              and_or_xor_add_5_f(alu_op => ALU_ADD);
603
 
604
              if opc_opcode_s(4) = '1' then
605 27 arniml
                alu_use_carry_o     <= true;
606 4 arniml
              end if;
607
 
608 27 arniml
              psw_special_data_o    <= alu_carry_i;
609
              psw_write_carry_o     <= true;
610
              psw_write_aux_carry_o <= true;
611 4 arniml
 
612
            when others =>
613
              null;
614
 
615
          end case;
616
 
617
        end if;
618
 
619
      -- Mnemonic ANL ---------------------------------------------------------
620
      when MN_ANL =>
621
        case clk_mstate_i is
622
          -- read RAM once for indirect address mode
623
          when MSTATE3 =>
624 92 arniml
            if not enable_quartus_bugfix_c or
625
               opc_opcode_s(3) = '0' then
626
              address_indirect_3_f;
627
            end if;
628 4 arniml
 
629
          -- store data from RAM to Temp Reg
630
          when MSTATE4 =>
631
            and_or_xor_add_4_f;
632
 
633
          -- perform AND and store in Accumulator
634
          when MSTATE5 =>
635
            and_or_xor_add_5_f(alu_op => ALU_AND);
636
 
637
          when others =>
638
            null;
639
 
640
        end case;
641
 
642
      -- Mnemonic ANL_A_DATA --------------------------------------------------
643
      when MN_ANL_A_DATA =>
644
        assert_psen_s              <= true;
645
 
646
        if clk_second_cycle_i then
647
          case clk_mstate_i is
648
            -- write Temp Reg when contents of Program Memory is on bus
649
            when MSTATE1 =>
650
              alu_write_temp_reg_o <= true;
651
 
652
            -- perform AND and store in Accumulator
653
            when MSTATE3 =>
654
              and_or_xor_add_5_f(alu_op => ALU_AND);
655
 
656
            when others =>
657
              null;
658
 
659
          end case;
660
 
661
        end if;
662
 
663
      -- Mnemonic ANL_EXT -----------------------------------------------------
664
      when MN_ANL_EXT =>
665
        assert_psen_s            <= true;
666
 
667
        if not clk_second_cycle_i then
668
          -- read port to Temp Reg
669
          if clk_mstate_i = MSTATE5 then
670
            if opc_opcode_s(1 downto 0) = "00" then
671
              add_read_bus_s     <= true;
672
            elsif opc_opcode_s(1) = '0' then
673
              p1_read_p1_o       <= true;
674
              p1_read_reg_o      <= true;
675
            else
676
              p2_read_p2_o       <= true;
677
              p2_read_reg_o      <= true;
678
            end if;
679
 
680
            alu_write_temp_reg_o <= true;
681
          end if;
682
 
683
        else
684
          case clk_mstate_i is
685
            -- write shadow Accumulator when contents of Program Memory is
686
            -- on bus
687
            when MSTATE1 =>
688
              alu_write_shadow_o <= true;
689
 
690
            -- loop shadow Accumulator through ALU to prevent update from
691
            -- real Accumulator
692
            when MSTATE2 =>
693
              alu_read_alu_o     <= true;
694
              alu_write_shadow_o <= true;
695
 
696
            -- write result of AND operation back to port
697
            when MSTATE3 =>
698
              alu_op_o           <= ALU_AND;
699
              alu_read_alu_o     <= true;
700
 
701
              if opc_opcode_s(1 downto 0) = "00" then
702
                bus_write_bus_o  <= true;
703
              elsif opc_opcode_s(1) = '0' then
704
                p1_write_p1_o    <= true;
705
              else
706
                p2_write_p2_o    <= true;
707
              end if;
708
 
709
            when others =>
710
              null;
711
 
712
          end case;
713
 
714
        end if;
715
 
716
      -- Mnemonic CALL --------------------------------------------------------
717
      when MN_CALL =>
718
        assert_psen_s              <= true;
719
 
720
        if not clk_second_cycle_i then
721
          case clk_mstate_i is
722
            -- read Stack Pointer and address Data Memory for low byte
723
            -- also increment Program Counter to point to next instruction
724
            when MSTATE3 =>
725
              psw_read_sp_o        <= true;
726
              dm_write_dmem_addr_o <= true;
727
              dm_addr_type_o       <= DM_STACK;
728
 
729
              -- only increment PC if this is not an injected CALL
730
              -- injected CALLS are not located in Program Memory,
731
              -- the PC points already to the instruction to be executed
732
              -- after the interrupt
733
              if not int_pending_s then
734
                add_inc_pc_s       <= true;
735
              end if;
736
 
737
            -- store Program Counter low byte on stack
738
            when MSTATE4 =>
739
              pm_read_pcl_o        <= true;
740
              dm_write_dmem_s      <= true;
741
 
742
            -- store Program Counter high byte and PSW on stack
743
            -- increment Stack pointer
744
            when MSTATE5 =>
745
              psw_read_psw_o       <= true;
746
              pm_read_pch_o        <= true;
747
              dm_write_dmem_addr_o <= true;
748
              dm_addr_type_o       <= DM_STACK_HIGH;
749
              dm_write_dmem_s      <= true;
750
              psw_inc_stackp_o     <= true;
751
 
752
            when others =>
753
              null;
754
 
755
          end case;
756
 
757
        else
758
          case clk_mstate_i is
759
            -- store address in Program Counter low byte
760
            when MSTATE1 =>
761
              pm_write_pcl_o       <= true;
762
              branch_taken_s       <= true;
763
              if int_pending_s then
764
                -- apply low part of vector address manually
765
                data_s             <= (others => '0');
766
                data_s(1 downto 0) <= "11";
767
                if tim_int_s then
768
                  data_s(2)        <= '1';
769
                end if;
770
                read_dec_s         <= true;
771
              end if;
772
 
773
            when MSTATE2 =>
774
              pm_write_pch_o       <= true;
775
              read_dec_s           <= true;
776
              if not int_pending_s then
777
                -- store high part of target address in Program Counter
778 120 arniml
                data_s             <= "0000" & mb_v & opc_opcode_s(7 downto 5);
779 4 arniml
              else
780
                -- apply high part of vector address manually
781
                data_s             <= (others => '0');
782
                int_executed_s     <= true;
783
              end if;
784
 
785
            when others =>
786
              null;
787
 
788
          end case;
789
 
790
        end if;
791
 
792
      -- Mnemonic CLR_A -------------------------------------------------------
793
      when MN_CLR_A =>
794
        -- write CLR output of ALU to Accumulator
795
        if clk_mstate_i = MSTATE3 then
796
          alu_op_o         <= ALU_CLR;
797
          alu_read_alu_o   <= true;
798
          alu_write_accu_o <= true;
799
        end if;
800
 
801
      -- Mnemonic CLR_C -------------------------------------------------------
802
      when MN_CLR_C =>
803
        -- store 0 to Carry
804
        if clk_mstate_i = MSTATE3 then
805
          psw_special_data_o <= '0';
806
          psw_write_carry_o  <= true;
807
        end if;
808
 
809
      -- Mnemonic CLR_F -------------------------------------------------------
810
      when MN_CLR_F =>
811
        -- store 0 to selected flag
812
        if clk_mstate_i = MSTATE3 then
813
          if opc_opcode_s(5) = '0' then
814
            psw_special_data_o <= '0';
815
            psw_write_f0_o     <= true;
816
          else
817
            clear_f1_s         <= true;
818
          end if;
819
 
820
        end if;
821
 
822
      -- Mnemonic CPL_A -------------------------------------------------------
823
      when MN_CPL_A =>
824
        -- write CPL output of ALU to Accumulator
825
        if clk_mstate_i = MSTATE3 then
826
          alu_op_o         <= ALU_CPL;
827
          alu_read_alu_o   <= true;
828
          alu_write_accu_o <= true;
829
        end if;
830
 
831
      -- Mnemnonic CPL_C ------------------------------------------------------
832
      when MN_CPL_C =>
833
        -- write inverse of Carry to PSW
834
        if clk_mstate_i = MSTATE3 then
835
          psw_special_data_o <= not psw_carry_i;
836
          psw_write_carry_o  <= true;
837
        end if;
838
 
839
      -- Mnemonic CPL_F -------------------------------------------------------
840
      when MN_CPL_f =>
841
        -- write inverse of selected flag back to flag
842
        if clk_mstate_i = MSTATE3 then
843
          if opc_opcode_s(5) = '0' then
844
            psw_special_data_o <= not psw_f0_i;
845
            psw_write_f0_o     <= true;
846
          else
847
            cpl_f1_s           <= true;
848
          end if;
849
 
850
        end if;
851
 
852 27 arniml
      -- Mnemonic DA ----------------------------------------------------------
853
      when MN_DA =>
854
        alu_op_o                 <= ALU_ADD;
855
 
856
        case clk_mstate_i is
857
          -- Step 1: Preload Temp Reg with 0x06
858
          when MSTATE3 =>
859
            alu_p06_temp_reg_o   <= true;
860
 
861
          -- Step 2: Check Auxiliary Carry and overflow on low nibble
862
          --         Add 0x06 to shadow Accumulator if one is true
863
          when MSTATE4 =>
864
            if psw_aux_carry_i = '1' or alu_da_overflow_i then
865
              alu_read_alu_o     <= true;
866
              alu_write_shadow_o <= true;
867
            end if;
868
 
869
            -- preload Temp Reg with 0x60
870
            alu_p60_temp_reg_o  <= true;
871
 
872
          -- Step 3: Check overflow on high nibble
873
          --         Add 0x60 to shadow Accumulator if true and store result
874
          --         in Accumulator and PSW (only Carry)
875
          when MSTATE5 =>
876
            alu_da_high_o        <= true;
877
 
878
            if alu_da_overflow_i then
879
              psw_special_data_o <= alu_carry_i;
880
            else
881
              alu_op_o           <= ALU_NOP;
882
              psw_special_data_o <= '0';
883
            end if;
884
            alu_read_alu_o       <= true;
885
            alu_write_accu_o     <= true;
886
            psw_write_carry_o    <= true;
887
 
888
          when others =>
889
            null;
890
 
891
        end case;
892
 
893 4 arniml
      -- Mnemonic DEC ---------------------------------------------------------
894
      when MN_DEC =>
895
        case clk_mstate_i is
896
          when MSTATE4 =>
897
            -- DEC Rr: store data from RAM to shadow Accumulator
898
            if opc_opcode_s(6) = '1' then
899
              dm_read_dmem_o         <= true;
900
              alu_write_shadow_o     <= true;
901
            end if;
902
 
903
          when MSTATE5 =>
904
            alu_op_o                 <= ALU_DEC;
905
            alu_read_alu_o           <= true;
906
 
907
            if opc_opcode_s(6) = '0' then
908
              -- write DEC of Accumulator to Accumulator
909
              alu_write_accu_o       <= true;
910
            else
911
              -- store DEC of shadow Accumulator back to dmem
912
              dm_write_dmem_s        <= true;
913
            end if;
914
 
915
          when others =>
916
            null;
917
 
918
        end case;
919
 
920
      -- Mnemonic DIS_EN_I ----------------------------------------------------
921
      when MN_DIS_EN_I =>
922
        if clk_mstate_i = MSTATE3 then
923
          if opc_opcode_s(4) = '1' then
924
            dis_i_s <= true;
925
          else
926
            en_i_s  <= true;
927
          end if;
928
        end if;
929
 
930
      -- Mnemonic DIS_EN_TCNTI ------------------------------------------------
931
      when MN_DIS_EN_TCNTI =>
932
        if clk_mstate_i = MSTATE3 then
933
          if opc_opcode_s(4) = '1' then
934
            dis_tcnti_s <= true;
935
          else
936
            en_tcnti_s  <= true;
937
          end if;
938
        end if;
939
 
940
      -- Mnemonic DJNZ --------------------------------------------------------
941
      when MN_DJNZ =>
942
        assert_psen_s              <= true;
943
 
944
        if not clk_second_cycle_i then
945
          case clk_mstate_i is
946
            -- store data from RAM to shadow Accumulator
947
            when MSTATE4 =>
948
              dm_read_dmem_o         <= true;
949
              alu_write_shadow_o     <= true;
950
 
951
            -- write DEC result of shadow Accumulator back to dmem and
952
            -- conditional branch logic
953
            when MSTATE5 =>
954
              alu_op_o               <= ALU_DEC;
955
              alu_read_alu_o         <= true;
956
              dm_write_dmem_s        <= true;
957
 
958
              cnd_compute_take_o     <= true;
959
              cnd_branch_cond_o      <= COND_Z;
960
              cnd_comp_value_o(0)    <= '0';
961
 
962
            when others =>
963
              null;
964
 
965
          end case;
966
 
967
        else
968
          -- store address in Program Counter low byte if branch has to
969
          -- be taken
970 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
971
            cond_jump_c2_m1_f;
972
          end if;
973 4 arniml
 
974
        end if;
975
 
976
      -- Mnemonic ENT0_CLK ----------------------------------------------------
977
      when MN_ENT0_CLK =>
978
        if clk_mstate_i = MSTATE3 then
979
          ent0_clk_s <= true;
980
        end if;
981
 
982
      -- Mnemonic IN ----------------------------------------------------------
983
      when MN_IN =>
984
        -- read Port and store in Accumulator
985
        if clk_second_cycle_i and clk_mstate_i = MSTATE2 then
986
          alu_write_accu_o <= true;
987
 
988
          if opc_opcode_s(1) = '0' then
989
            p1_read_p1_o   <= true;
990
          else
991
            p2_read_p2_o   <= true;
992
          end if;
993
        end if;
994
 
995
      -- Mnemonic INS ---------------------------------------------------------
996
      when MN_INS =>
997 143 arniml
        clk_assert_rd_o  <= true;
998
 
999 4 arniml
        -- read BUS and store in Accumulator
1000
        if clk_second_cycle_i and clk_mstate_i = MSTATE2 then
1001
          alu_write_accu_o <= true;
1002
 
1003
          add_read_bus_s   <= true;
1004
        end if;
1005
 
1006
      -- Mnemonic INC ---------------------------------------------------------
1007
      when MN_INC =>
1008
        case clk_mstate_i is
1009
          -- read RAM once for indirect address mode
1010
          when MSTATE3 =>
1011 92 arniml
            if not enable_quartus_bugfix_c or
1012
               opc_opcode_s(3) = '0' then
1013
              address_indirect_3_f;
1014
            end if;
1015 4 arniml
 
1016
          when MSTATE4 =>
1017
            -- INC Rr; INC @ Rr: store data from RAM to shadow Accumulator
1018
            if opc_opcode_s(3 downto 2) /= "01" then
1019
              dm_read_dmem_o         <= true;
1020
              alu_write_shadow_o     <= true;
1021
            end if;
1022
 
1023
          when MSTATE5 =>
1024
            alu_op_o                 <= ALU_INC;
1025
            alu_read_alu_o           <= true;
1026
 
1027
            if opc_opcode_s(3 downto 2) = "01" then
1028
              -- write INC output of ALU to Accumulator
1029
              alu_write_accu_o       <= true;
1030
            else
1031
              -- store INC of shadow Accumulator back to dmem
1032
              dm_write_dmem_s        <= true;
1033
            end if;
1034
 
1035
          when others =>
1036
            null;
1037
 
1038
        end case;
1039
 
1040
      -- Mnemonic JBB ---------------------------------------------------------
1041
      when MN_JBB =>
1042
        assert_psen_s          <= true;
1043
        cnd_branch_cond_o      <= COND_ON_BIT;
1044
 
1045
        if not clk_second_cycle_i then
1046
          -- read Accumulator and start branch calculation
1047
          if clk_mstate_i = MSTATE3 then
1048
            alu_read_alu_o     <= true;
1049
            cnd_compute_take_o <= true;
1050
            -- cnd_comp_value_o is ok by default assignment
1051
          end if;
1052
 
1053
        else
1054
          -- store address in Program Counter low byte if branch has to
1055
          -- be taken
1056 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1057
            cond_jump_c2_m1_f;
1058
          end if;
1059 4 arniml
 
1060
        end if;
1061
 
1062
      -- Mnemonic JC ----------------------------------------------------------
1063
      when MN_JC =>
1064
        assert_psen_s           <= true;
1065
        cnd_branch_cond_o       <= COND_C;
1066
 
1067
        if not clk_second_cycle_i then
1068
          -- start branch calculation
1069
          if clk_mstate_i = MSTATE3 then
1070
            cnd_compute_take_o  <= true;
1071
            cnd_comp_value_o(0) <= opc_opcode_s(4);
1072
          end if;
1073
 
1074
        else
1075
          -- store address in Program Counter low byte if branch has to
1076
          -- be taken
1077 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1078
            cond_jump_c2_m1_f;
1079
          end if;
1080 4 arniml
 
1081
        end if;
1082
 
1083
      -- Mnemonic JF ----------------------------------------------------------
1084
      when MN_JF =>
1085
        assert_psen_s           <= true;
1086
 
1087
        if not clk_second_cycle_i then
1088
          -- start branch calculation
1089
          if clk_mstate_i = MSTATE3 then
1090
            cnd_compute_take_o  <= true;
1091
            if opc_opcode_s(7) = '1' then
1092
              -- JF0
1093
              cnd_branch_cond_o <= COND_F0;
1094
            else
1095
              -- JF1
1096
              cnd_branch_cond_o <= COND_F1;
1097
            end if;
1098
 
1099
          end if;
1100
 
1101
        else
1102
          -- store address in Program Counter low byte if branch has to
1103
          -- be taken
1104 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1105
            cond_jump_c2_m1_f;
1106
          end if;
1107 4 arniml
 
1108
        end if;
1109
 
1110
 
1111
      -- Mnemonic JMP ---------------------------------------------------------
1112
      when MN_JMP =>
1113
        assert_psen_s        <= true;
1114
 
1115
        if clk_second_cycle_i then
1116
          case clk_mstate_i is
1117
            -- store address in Program Counter low byte
1118
            when MSTATE1 =>
1119
              pm_write_pcl_o <= true;
1120
              branch_taken_s <= true;
1121
 
1122
            -- store high part of target address in Program Counter
1123
            when MSTATE2 =>
1124 120 arniml
              data_s         <= "0000" & mb_v & opc_opcode_s(7 downto 5);
1125 4 arniml
              read_dec_s     <= true;
1126
              pm_write_pch_o <= true;
1127
 
1128
            when others =>
1129
              null;
1130
 
1131
          end case;
1132
 
1133
        end if;
1134
 
1135
      -- Mnemonic JMPP --------------------------------------------------------
1136
      when MN_JMPP =>
1137
        assert_psen_s    <= true;
1138
 
1139
        if not clk_second_cycle_i then
1140
          -- write Accumulator to Program Memory address
1141
          -- (skip page offset update from Program Counter)
1142
          if clk_mstate_i = MSTATE3 then
1143
            alu_read_alu_o <= true;
1144
            pm_addr_type_o <= PM_PAGE;
1145
          end if;
1146
 
1147
        else
1148
          if clk_mstate_i = MSTATE1 then
1149
            -- store address in Program Counter low byte
1150
            pm_write_pcl_o <= true;
1151
            branch_taken_s <= true;
1152
          end if;
1153
 
1154
        end if;
1155
 
1156
      -- Mnemonic JNI ---------------------------------------------------------
1157
      when MN_JNI =>
1158
        assert_psen_s          <= true;
1159
        cnd_branch_cond_o      <= COND_INT;
1160
 
1161
        if not clk_second_cycle_i then
1162
          -- start branch calculation
1163
          if clk_mstate_i = MSTATE3 then
1164
            cnd_compute_take_o <= true;
1165
          end if;
1166
 
1167
        else
1168
          -- store address in Program Counter low byte if branch has to
1169
          -- be taken
1170 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1171
            cond_jump_c2_m1_f;
1172
          end if;
1173 4 arniml
 
1174
        end if;
1175
 
1176
      -- Mnemonic JT ----------------------------------------------------------
1177
      when MN_JT =>
1178
        assert_psen_s           <= true;
1179
        if opc_opcode_s(6) = '0' then
1180
          cnd_branch_cond_o     <= COND_T0;
1181
        else
1182
          cnd_branch_cond_o     <= COND_T1;
1183
        end if;
1184
 
1185
        if not clk_second_cycle_i then
1186
          -- start branch calculation
1187
          if clk_mstate_i = MSTATE3 then
1188
            cnd_compute_take_o  <= true;
1189
            cnd_comp_value_o(0) <= opc_opcode_s(4);
1190
          end if;
1191
 
1192
        else
1193
          -- store address in Program Counter low byte if branch has to
1194
          -- be taken
1195 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1196
            cond_jump_c2_m1_f;
1197
          end if;
1198 4 arniml
 
1199
        end if;
1200
 
1201
      -- Mnemonic JTF ---------------------------------------------------------
1202
      when MN_JTF =>
1203
        assert_psen_s          <= true;
1204
        cnd_branch_cond_o      <= COND_TF;
1205
 
1206
        if not clk_second_cycle_i then
1207
          -- start branch calculation
1208
          if clk_mstate_i = MSTATE3 then
1209
            cnd_compute_take_o <= true;
1210
            jtf_executed_s     <= true;
1211
          end if;
1212
 
1213
        else
1214
          -- store address in Program Counter low byte if branch has to
1215
          -- be taken
1216 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1217
            cond_jump_c2_m1_f;
1218
          end if;
1219 4 arniml
 
1220
        end if;
1221
 
1222
      -- Mnemonic JZ ----------------------------------------------------------
1223
      when MN_JZ =>
1224
        assert_psen_s           <= true;
1225
        cnd_branch_cond_o       <= COND_Z;
1226
 
1227
        if not clk_second_cycle_i then
1228
          -- read Accumulator and start branch calculation
1229
          if clk_mstate_i = MSTATE3 then
1230
            alu_read_alu_o      <= true;
1231
            cnd_compute_take_o  <= true;
1232
            cnd_comp_value_o(0) <= opc_opcode_s(6);
1233
          end if;
1234
 
1235
        else
1236
          -- store address in Program Counter low byte if branch has to
1237
          -- be taken
1238 92 arniml
          if clk_mstate_i = MSTATE1 and cnd_take_branch_i then
1239
            cond_jump_c2_m1_f;
1240
          end if;
1241 4 arniml
 
1242
        end if;
1243
 
1244
      -- Mnemonic MOV_A_DATA --------------------------------------------------
1245
      when MN_MOV_A_DATA =>
1246
        assert_psen_s      <= true;
1247
 
1248
        -- Write Accumulator when contents of Program Memory is on bus
1249
        -- during machine state 1 of second cycle.
1250
        if clk_second_cycle_i and clk_mstate_i = MSTATE1 then
1251
          alu_write_accu_o <= true;
1252
        end if;
1253
 
1254
      -- Mnemonic MOV_A_RR ----------------------------------------------------
1255
      when MN_MOV_A_RR =>
1256
        case clk_mstate_i is
1257
          -- read RAM once for indirect address mode
1258
          when MSTATE3 =>
1259 92 arniml
            if not enable_quartus_bugfix_c or
1260
               opc_opcode_s(3) = '0' then
1261
              address_indirect_3_f;
1262
            end if;
1263 4 arniml
 
1264
          -- read data from RAM and store in Accumulator
1265
          when MSTATE4 =>
1266
            and_or_xor_add_4_f;
1267
            alu_write_accu_o <= true;
1268
 
1269
          when others =>
1270
            null;
1271
 
1272
        end case;
1273
 
1274
      -- Mnemonic MOV_A_PSW ---------------------------------------------------
1275
      when MN_MOV_A_PSW =>
1276
        if clk_mstate_i = MSTATE3 then
1277
          psw_read_psw_o   <= true;
1278
          psw_read_sp_o    <= true;
1279
          alu_write_accu_o <= true;
1280
        end if;
1281
 
1282
      -- Mnemoniv MOV_PSW_A ---------------------------------------------------
1283
      when MN_MOV_PSW_A =>
1284
        if clk_mstate_i = MSTATE3 then
1285
          alu_read_alu_o  <= true;
1286
          psw_write_psw_o <= true;
1287
          psw_write_sp_o  <= true;
1288
        end if;
1289
 
1290
      -- Mnemonic MOV_RR ------------------------------------------------------
1291
      when MN_MOV_RR =>
1292
        case clk_mstate_i is
1293
          -- read RAM once for indirect address mode
1294
          when MSTATE3 =>
1295 92 arniml
            if not enable_quartus_bugfix_c or
1296
               opc_opcode_s(3) = '0' then
1297
              address_indirect_3_f;
1298
            end if;
1299 4 arniml
 
1300
          -- write Accumulator to dmem
1301
          when MSTATE5 =>
1302
            alu_read_alu_o       <= true;
1303
            dm_write_dmem_s      <= true;
1304
 
1305
          when others =>
1306
            null;
1307
 
1308
        end case;
1309
 
1310
      -- Mnemonic MOV_RR_DATA -------------------------------------------------
1311
      when MN_MOV_RR_DATA =>
1312
        assert_psen_s     <= true;
1313
 
1314
        -- read RAM once for indirect address mode
1315
        if not clk_second_cycle_i and clk_mstate_i = MSTATE3 then
1316 92 arniml
          if not enable_quartus_bugfix_c or
1317
             opc_opcode_s(3) = '0' then
1318
            address_indirect_3_f;
1319
          end if;
1320 4 arniml
        end if;
1321
 
1322
        -- Write Data Memory when contents of Program Memory is on bus
1323
        -- during machine state 1 of second cycle.
1324
        if clk_second_cycle_i and clk_mstate_i = MSTATE1 then
1325
          dm_write_dmem_s <= true;
1326
        end if;
1327
 
1328
      -- Mnemonic MOV_T -------------------------------------------------------
1329
      when MN_MOV_T =>
1330
        if clk_mstate_i = MSTATE3 then
1331
          if opc_opcode_s(5) = '1' then
1332
            alu_read_alu_o    <= true;  -- MOV T, A
1333
            tim_write_timer_o <= true;
1334
          else
1335
            tim_read_timer_o  <= true;  -- MOV A, T
1336
            alu_write_accu_o  <= true;
1337
          end if;
1338
        end if;
1339
 
1340 21 arniml
      -- Mnemonic OUTD_PP_A ---------------------------------------------------
1341
      when MN_OUTD_PP_A =>
1342
        clk_assert_prog_o     <= true;
1343
 
1344
        if not clk_second_cycle_i then
1345
          case clk_mstate_i is
1346
            -- propagate expander port number to Port 2
1347
            when MSTATE3 =>
1348
 
1349
              data_s(7 downto 4)     <= (others => '0');
1350
              data_s(1 downto 0)     <= opc_opcode_s(1 downto 0);
1351
              -- decide which 8243 command to use
1352
              case opc_opcode_s(7 downto 4) is
1353
                when "1001" =>
1354
                  data_s(3 downto 2) <= "11";  -- ANLD command
1355
                when "1000" =>
1356
                  data_s(3 downto 2) <= "10";  -- ORLD command
1357
                when "0011" =>
1358
                  data_s(3 downto 2) <= "01";  -- MOVD command
1359
                when others =>
1360
                  null;
1361
              end case;
1362
 
1363
              read_dec_s      <= true;
1364
              p2_write_exp_o  <= true;
1365
 
1366
            -- output expander port number on Port 2 while active edge of PROG
1367
            -- write Accumulator to expander port
1368
            when MSTATE4 =>
1369 204 arniml
              p2_output_exp_s <= true;
1370 21 arniml
 
1371
              alu_read_alu_o  <= true;
1372
              p2_write_exp_o  <= true;
1373
 
1374
            when MSTATE5 =>
1375 204 arniml
              p2_output_exp_s <= true;
1376 21 arniml
 
1377
            when others =>
1378
              null;
1379
 
1380
          end case;
1381
 
1382
        else
1383
          -- hold expander port until inactive edge of PROG 
1384
          if clk_mstate_i = MSTATE1 or clk_mstate_i = MSTATE2 then
1385 204 arniml
            p2_output_exp_s   <= true;
1386 21 arniml
          end if;
1387
 
1388
        end if;
1389
 
1390
      -- Mnemonic MOVD_A_PP ---------------------------------------------------
1391
      when MN_MOVD_A_PP =>
1392
        clk_assert_prog_o            <= true;
1393
 
1394
        if not clk_second_cycle_i then
1395
          case clk_mstate_i is
1396
            -- propagate expander port number to Port 2
1397
            when MSTATE3 =>
1398
              data_s                 <= "0000" &
1399
                                        "00"   &  -- 8243 command: read
1400
                                        opc_opcode_s(1 downto 0);
1401
              read_dec_s             <= true;
1402
              p2_write_exp_o         <= true;
1403
 
1404
            -- output expander port number on Port 2 while active edge of PROG
1405
            -- write 1's to expander port to set lower nibble of Port 2 to input
1406
            when MSTATE4 =>
1407 204 arniml
              p2_output_exp_s        <= true;
1408 21 arniml
 
1409
              data_s(nibble_t'range) <= (others => '1');
1410
              read_dec_s             <= true;
1411
              p2_write_exp_o         <= true;
1412
 
1413
            when MSTATE5 =>
1414 204 arniml
              p2_output_exp_s        <= true;
1415 21 arniml
 
1416
            when others =>
1417
              null;
1418
 
1419
          end case;
1420
 
1421
        else
1422
          case clk_mstate_i is
1423
            -- hold expander port until inactive edge of PROG
1424
            when MSTATE1 =>
1425 204 arniml
              p2_output_exp_s  <= true;
1426 21 arniml
 
1427
            -- hold expander port until inactive edge of PROG
1428
            -- write Accumulator with nibble of expander port
1429
            when MSTATE2 =>
1430 101 arniml
              p2_read_p2_o     <= true;
1431 204 arniml
              p2_output_exp_s  <= true;
1432 21 arniml
              p2_read_exp_o    <= true;
1433
              alu_write_accu_o <= true;
1434
 
1435
            when others =>
1436
              null;
1437
 
1438
          end case;
1439
 
1440
        end if;
1441
 
1442 4 arniml
      -- Mnemonic MOVP --------------------------------------------------------
1443
      when MN_MOVP =>
1444
        assert_psen_s        <= true;
1445
 
1446
        if not clk_second_cycle_i then
1447
          -- write Accumulator to Program Memory address
1448
          -- (skip page offset update from Program Counter)
1449
          if clk_mstate_i = MSTATE3 then
1450
            alu_read_alu_o   <= true;
1451
            if opc_opcode_s(6) = '0' then
1452
              pm_addr_type_o <= PM_PAGE;
1453
            else
1454
              pm_addr_type_o <= PM_PAGE3;
1455
            end if;
1456
          end if;
1457
 
1458
        else
1459
          if clk_mstate_i = MSTATE1 then
1460
            -- store data from Program Memory in Accumulator
1461
            alu_write_accu_o <= true;
1462
            -- trick & treat to prevent additional PC increment
1463
            -- our branch target is the previously incremented PC!
1464
            branch_taken_s   <= true;
1465
          end if;
1466
 
1467
        end if;
1468
 
1469
      -- Mnemonic MOVX --------------------------------------------------------
1470
      when MN_MOVX =>
1471
        bus_bidir_bus_o        <= true;
1472
 
1473
        if opc_opcode_s(4) = '0' then
1474
          clk_assert_rd_o      <= true;
1475
        else
1476
          clk_assert_wr_o      <= true;
1477
        end if;
1478
 
1479
        if not clk_second_cycle_i then
1480 78 arniml
          case clk_mstate_i is
1481
            -- read dmem and put contents on BUS as external address
1482
            when MSTATE3 =>
1483
              dm_read_dmem_o     <= true;
1484
              bus_write_bus_o    <= true;
1485 4 arniml
 
1486 78 arniml
            -- store contents of Accumulator to BUS
1487
            when MSTATE5 =>
1488
              if opc_opcode_s(4) = '1' then
1489
                alu_read_alu_o   <= true;
1490
                bus_write_bus_o  <= true;
1491
              end if;
1492
 
1493
            when others =>
1494
              null;
1495
          end case;
1496
 
1497 4 arniml
        else
1498 178 arniml
          if clk_mstate_i = MSTATE2 then
1499 4 arniml
            if opc_opcode_s(4) = '0' then
1500
              -- store contents of BUS in Accumulator
1501
              add_read_bus_s   <= true;
1502
              alu_write_accu_o <= true;
1503
            else
1504
              -- store contents of Accumulator to BUS
1505 178 arniml
              -- to this to keep bus in output direction
1506 4 arniml
              alu_read_alu_o   <= true;
1507
              bus_write_bus_o  <= true;
1508
            end if;
1509
          end if;
1510
 
1511
        end if;
1512
 
1513
      -- Mnemonic NOP ---------------------------------------------------------
1514
      when MN_NOP =>
1515
        -- nothing to do
1516
 
1517
      -- Mnemonic ORL ---------------------------------------------------------
1518
      when MN_ORL =>
1519
        case clk_mstate_i is
1520
          -- read RAM once for indirect address mode
1521
          when MSTATE3 =>
1522 92 arniml
            if not enable_quartus_bugfix_c or
1523
               opc_opcode_s(3) = '0' then
1524
              address_indirect_3_f;
1525
            end if;
1526 4 arniml
 
1527
          -- store data from RAM to Temp Reg
1528
          when MSTATE4 =>
1529
            and_or_xor_add_4_f;
1530
 
1531
          -- perform OR and store in Accumulator
1532
          when MSTATE5 =>
1533
            and_or_xor_add_5_f(alu_op => ALU_OR);
1534
 
1535
          when others =>
1536
            null;
1537
 
1538
        end case;
1539
 
1540
      -- Mnemonic ORL_A_DATA --------------------------------------------------
1541
      when MN_ORL_A_DATA =>
1542
        assert_psen_s              <= true;
1543
 
1544
        if clk_second_cycle_i then
1545
          case clk_mstate_i is
1546
            -- write Temp Reg when contents of Program Memory is on bus
1547
            when MSTATE1 =>
1548
              alu_write_temp_reg_o <= true;
1549
 
1550
            -- perform OR and store in Accumulator
1551
            when MSTATE3 =>
1552
              and_or_xor_add_5_f(alu_op => ALU_OR);
1553
 
1554
            when others =>
1555
              null;
1556
 
1557
          end case;
1558
 
1559
        end if;
1560
 
1561
      -- Mnemonic ORL_EXT -----------------------------------------------------
1562
      when MN_ORL_EXT =>
1563
        assert_psen_s            <= true;
1564
 
1565
        if not clk_second_cycle_i then
1566
          -- read port to Temp Reg
1567
          if clk_mstate_i = MSTATE5 then
1568
            if opc_opcode_s(1 downto 0) = "00" then
1569
              add_read_bus_s     <= true;
1570
            elsif opc_opcode_s(1) = '0' then
1571
              p1_read_p1_o       <= true;
1572
              p1_read_reg_o      <= true;
1573
            else
1574
              p2_read_p2_o       <= true;
1575
              p2_read_reg_o      <= true;
1576
            end if;
1577
 
1578
            alu_write_temp_reg_o <= true;
1579
          end if;
1580
 
1581
        else
1582
          case clk_mstate_i is
1583
            -- write shadow Accumulator when contents of Program Memory is
1584
            -- on bus
1585
            when MSTATE1 =>
1586
              alu_write_shadow_o <= true;
1587
 
1588
            -- loop shadow Accumulator through ALU to prevent update from
1589
            -- real Accumulator
1590
            when MSTATE2 =>
1591
              alu_read_alu_o     <= true;
1592
              alu_write_shadow_o <= true;
1593
 
1594
            -- write result of OR operation back to port
1595
            when MSTATE3 =>
1596
              alu_op_o           <= ALU_OR;
1597
              alu_read_alu_o     <= true;
1598
 
1599
              if opc_opcode_s(1 downto 0) = "00" then
1600
                bus_write_bus_o  <= true;
1601
              elsif opc_opcode_s(1) = '0' then
1602
                p1_write_p1_o    <= true;
1603
              else
1604
                p2_write_p2_o    <= true;
1605
              end if;
1606
 
1607
            when others =>
1608
              null;
1609
 
1610
          end case;
1611
 
1612
        end if;
1613
 
1614
      -- Mnemonic OUTL_EXT ----------------------------------------------------
1615
      when MN_OUTL_EXT =>
1616 143 arniml
        if opc_opcode_s(4) = '0' then
1617
          clk_assert_wr_o <= true;
1618
        end if;
1619
 
1620 4 arniml
        -- read Accumulator and store in Port/BUS output register
1621 143 arniml
        if not clk_second_cycle_i and clk_mstate_i = MSTATE4 then
1622 4 arniml
          alu_read_alu_o  <= true;
1623
 
1624
          if opc_opcode_s(4) = '1' then
1625
            if opc_opcode_s(1) = '0' then
1626
              p1_write_p1_o <= true;
1627
            else
1628
              p2_write_p2_o <= true;
1629
            end if;
1630
 
1631
          else
1632
            bus_write_bus_o <= true;
1633
 
1634
          end if;
1635
 
1636
        end if;
1637
 
1638
      -- Mnemonic RET ---------------------------------------------------------
1639
      when MN_RET =>
1640
        if not clk_second_cycle_i then
1641
          case clk_mstate_i is
1642
            -- decrement Stack Pointer
1643
            when MSTATE3 =>
1644
              psw_dec_stackp_o     <= true;
1645
 
1646
            -- read Stack Pointer and address Data Memory for low byte
1647
            when MSTATE4 =>
1648
              psw_read_sp_o        <= true;
1649
              dm_write_dmem_addr_o <= true;
1650
              dm_addr_type_o       <= DM_STACK;
1651
 
1652
            -- read Data Memory and store to Program Counter low
1653
            -- prepare address to Data memory for high byte
1654
            when MSTATE5 =>
1655
              dm_read_dmem_o       <= true;
1656
              pm_write_pcl_o       <= true;
1657
              dm_write_dmem_addr_o <= true;
1658
              dm_addr_type_o       <= DM_STACK_HIGH;
1659
 
1660
            when others =>
1661
              null;
1662
 
1663
          end case;
1664
 
1665
        else
1666
          case clk_mstate_i is
1667
            -- read Data Memory and store to Program Counter high and PSW
1668
            when MSTATE1 =>
1669
              dm_read_dmem_o         <= true;
1670
              pm_write_pch_o         <= true;
1671
              if opc_opcode_s(4) = '1' then
1672
                psw_write_psw_o      <= true;
1673
                retr_executed_s      <= true;
1674
              end if;
1675
 
1676
            when MSTATE2 =>
1677
              add_write_pmem_addr_s  <= true;
1678
 
1679
            when others =>
1680
              null;
1681
 
1682
          end case;
1683
 
1684
        end if;
1685
 
1686
      -- Mnemonic RL ----------------------------------------------------------
1687
      when MN_RL =>
1688
        if clk_mstate_i = MSTATE3 then
1689
          alu_op_o             <= ALU_RL;
1690
          alu_read_alu_o       <= true;
1691
          alu_write_accu_o     <= true;
1692
 
1693
          if opc_opcode_s(4) = '1' then
1694
            psw_special_data_o <= alu_carry_i;
1695
            psw_write_carry_o  <= true;
1696
            alu_use_carry_o    <= true;
1697
          end if;
1698
        end if;
1699
 
1700
      -- Mnemonic RR ----------------------------------------------------------
1701
      when MN_RR =>
1702
        if clk_mstate_i = MSTATE3 then
1703
          alu_op_o             <= ALU_RR;
1704
          alu_read_alu_o       <= true;
1705
          alu_write_accu_o     <= true;
1706
 
1707
          if opc_opcode_s(4) = '0' then
1708
            psw_special_data_o <= alu_carry_i;
1709
            psw_write_carry_o  <= true;
1710
            alu_use_carry_o    <= true;
1711
          end if;
1712
        end if;
1713
 
1714
      -- Mnemonic SEL_MB ------------------------------------------------------
1715
      when MN_SEL_MB =>
1716
        if clk_mstate_i = MSTATE3 then
1717
          if opc_opcode_s(4) = '1' then
1718
            set_mb_s   <= true;
1719
          else
1720
            clear_mb_s <= true;
1721
          end if;
1722
        end if;
1723
 
1724
      -- Mnemonic SEL_RB ------------------------------------------------------
1725
      when MN_SEL_RB =>
1726
        if clk_mstate_i = MSTATE3 then
1727
          psw_special_data_o <= opc_opcode_s(4);
1728
          psw_write_bs_o     <= true;
1729
        end if;
1730
 
1731
      -- Mnemonic STOP_TCNT ---------------------------------------------------
1732
      when MN_STOP_TCNT =>
1733
        if clk_mstate_i = MSTATE3 then
1734
          tim_stop_tcnt_o <= true;
1735
        end if;
1736
 
1737
      -- Mnemonic STRT --------------------------------------------------------
1738
      when MN_STRT =>
1739
        if clk_mstate_i = MSTATE3 then
1740
          if opc_opcode_s(4) = '1' then
1741
            tim_start_t_o   <= true;
1742
          else
1743
            tim_start_cnt_o <= true;
1744
          end if;
1745
        end if;
1746
 
1747
      -- Mnemonic SWAP --------------------------------------------------------
1748
      when MN_SWAP =>
1749
        alu_op_o           <= ALU_SWAP;
1750
 
1751
        if clk_mstate_i = MSTATE3 then
1752
          alu_read_alu_o   <= true;
1753
          alu_write_accu_o <= true;
1754
        end if;
1755
 
1756
      -- Mnemonic XCH ---------------------------------------------------------
1757
      when MN_XCH =>
1758
        case clk_mstate_i is
1759
          -- read RAM once for indirect address mode
1760
          when MSTATE3 =>
1761 92 arniml
            if not enable_quartus_bugfix_c or
1762
               opc_opcode_s(3) = '0' then
1763
              address_indirect_3_f;
1764
            end if;
1765 4 arniml
 
1766 38 arniml
          -- store data from RAM in Accumulator and Temp Reg
1767 4 arniml
          -- Accumulator is already shadowed!
1768
          when MSTATE4 =>
1769 38 arniml
            dm_read_dmem_o       <= true;
1770
            alu_write_accu_o     <= true;
1771
            alu_write_temp_reg_o <= true;
1772
            if opc_opcode_s(4) = '1' then
1773
              -- XCHD
1774
              -- only write lower nibble of Accumulator
1775
              alu_accu_low_o     <= true;
1776
            end if;
1777 4 arniml
 
1778
          -- store data from shadow (previous) Accumulator to dmem
1779
          when MSTATE5 =>
1780 38 arniml
            dm_write_dmem_s      <= true;
1781
            alu_read_alu_o       <= true;
1782
            if opc_opcode_s(4) = '1' then
1783
              -- XCHD
1784
              -- concatenate shadow Accumulator and Temp Reg
1785
              alu_op_o           <= ALU_CONCAT;
1786
            end if;
1787 4 arniml
 
1788
          when others =>
1789
            null;
1790
 
1791
        end case;
1792
 
1793
      -- Mnemonic XRL ---------------------------------------------------------
1794
      when MN_XRL =>
1795
        case clk_mstate_i is
1796
          -- read RAM once for indirect address mode
1797
          when MSTATE3 =>
1798 92 arniml
            if not enable_quartus_bugfix_c or
1799
               opc_opcode_s(3) = '0' then
1800
              address_indirect_3_f;
1801
            end if;
1802 4 arniml
 
1803
          -- store data from RAM to Temp Reg
1804
          when MSTATE4 =>
1805
            and_or_xor_add_4_f;
1806
 
1807
          -- perform XOR and store in Accumulator
1808
          when MSTATE5 =>
1809
            and_or_xor_add_5_f(alu_op => ALU_XOR);
1810
 
1811
          when others =>
1812
            null;
1813
 
1814
        end case;
1815
 
1816
      -- Mnemonic XRL_A_DATA --------------------------------------------------
1817
      when MN_XRL_A_DATA =>
1818
        assert_psen_s              <= true;
1819
 
1820
        if clk_second_cycle_i then
1821
          case clk_mstate_i is
1822
            -- write Temp Reg when contents of Program Memory is on bus
1823
            when MSTATE1 =>
1824
              alu_write_temp_reg_o <= true;
1825
 
1826
            -- perform XOR and store in Accumulator
1827
            when MSTATE3 =>
1828
              and_or_xor_add_5_f(alu_op => ALU_XOR);
1829
 
1830
            when others =>
1831
              null;
1832
 
1833
          end case;
1834
 
1835
        end if;
1836
 
1837
      -- Unimplemented mnemonic -----------------------------------------------
1838
      when others =>
1839
        -- this will behave like a NOP
1840
 
1841
        -- pragma translate_off
1842
        assert false
1843
          report "Mnemonic not yet implemented."
1844
          severity warning;
1845
        -- pragma translate_on
1846
 
1847
    end case;
1848
 
1849
  end process decode;
1850
  --
1851
  -----------------------------------------------------------------------------
1852
 
1853
 
1854
  -----------------------------------------------------------------------------
1855
  -- Process regs
1856
  --
1857
  -- Purpose:
1858
  --   Implements the various registes.
1859
  --
1860
  regs: process (res_i, clk_i)
1861
  begin
1862
    if res_i = res_active_c then
1863
      branch_taken_q <= false;
1864
      f1_q           <= '0';
1865
      mb_q           <= '0';
1866
      t0_dir_q       <= '0';
1867 38 arniml
      -- pragma translate_off
1868 64 arniml
      istrobe_res_q  <= '1';
1869
      istrobe_q      <= '0';
1870 60 arniml
      injected_int_q <= '0';
1871 38 arniml
      -- pragma translate_on
1872 4 arniml
 
1873
    elsif clk_i'event and clk_i = clk_active_c then
1874
      if en_clk_i then
1875
 
1876
        -- branch taken flag
1877
        if branch_taken_s then
1878
          branch_taken_q <= true;
1879
        elsif clk_mstate_i = MSTATE5 then
1880
          -- release flag when new instruction starts
1881
          branch_taken_q <= false;
1882
        end if;
1883
 
1884
        -- Flag 1
1885
        if clear_f1_s then
1886
          f1_q         <= '0';
1887
        elsif cpl_f1_s then
1888
          f1_q         <= not f1_q;
1889
        end if;
1890
 
1891
        -- Memory Bank select
1892
        if clear_mb_s then
1893
          mb_q         <= '0';
1894
        elsif set_mb_s then
1895
          mb_q         <= '1';
1896
        end if;
1897
 
1898
        -- T0 direction selection
1899
        if ent0_clk_s then
1900
          t0_dir_q     <= '1';
1901
        end if;
1902
 
1903 60 arniml
        -- pragma translate_off
1904
        -- Marker for injected instruction ------------------------------------
1905
        if opc_inj_int_s then
1906
          injected_int_q <= '1';
1907
        elsif clk_mstate_i = MSTATE5 and last_cycle_s then
1908
          injected_int_q <= '0';
1909
        end if;
1910 64 arniml
 
1911
        -- Remove istrobe after reset suppression -----------------------------
1912
        if clk_mstate_i = MSTATE5 and last_cycle_s then
1913
          istrobe_res_q  <= '0';
1914
        end if;
1915 60 arniml
        -- pragma translate_on
1916
 
1917 38 arniml
      end if;
1918
 
1919 64 arniml
      -- pragma translate_off
1920
      -- Instruction Strobe ---------------------------------------------------
1921
      if clk_mstate_i = MSTATE5 and last_cycle_s and
1922
         injected_int_q = '0' then
1923
        if istrobe_res_q = '0' then
1924
          istrobe_q <= '1';
1925
        end if;
1926
      else
1927
        istrobe_q   <= '0';
1928
      end if;
1929
      -- pragma translate_on
1930
 
1931 4 arniml
    end if;
1932
 
1933
  end process regs;
1934
  --
1935
  -----------------------------------------------------------------------------
1936
 
1937 53 arniml
  -- pragma translate_off
1938
  -- assign to global signal for testbench
1939 64 arniml
  tb_istrobe_s <= istrobe_q;
1940 53 arniml
  -- pragma translate_on
1941 4 arniml
 
1942 53 arniml
 
1943 4 arniml
  -----------------------------------------------------------------------------
1944
  -- Output Mapping.
1945
  -----------------------------------------------------------------------------
1946
  clk_multi_cycle_o    <= opc_multi_cycle_s;
1947
  cnd_f1_o             <= f1_q;
1948
  cnd_tf_o             <= tf_s;
1949
  data_o               <=   data_s
1950
                          when read_dec_s else
1951
                            (others => bus_idle_level_c);
1952
  dm_write_dmem_o      <= dm_write_dmem_s      and en_clk_i;
1953
  pm_inc_pc_o          <= pm_inc_pc_s          or add_inc_pc_s;
1954
  pm_write_pmem_addr_o <= pm_write_pmem_addr_s or add_write_pmem_addr_s;
1955
  t0_dir_o             <= t0_dir_q;
1956
  bus_read_bus_o       <= bus_read_bus_s       or add_read_bus_s;
1957
 
1958
end rtl;
1959
 
1960
 
1961
-------------------------------------------------------------------------------
1962
-- File History:
1963
--
1964
-- $Log: not supported by cvs2svn $
1965 204 arniml
-- Revision 1.21  2005/10/31 10:08:33  arniml
1966
-- Suppress assertion of bus_read_bus_s when interrupt is pending.
1967
-- This should fix bug report
1968
-- "PROBLEM WHEN INT AND JMP"
1969
--
1970 195 arniml
-- Revision 1.20  2005/09/13 21:08:34  arniml
1971
-- move check for int_pending_s into ea_i_='0' branch
1972
-- this fixes a glitch on PCH when an interrutp occurs
1973
-- during external program memory fetch
1974
--
1975 188 arniml
-- Revision 1.19  2005/06/11 10:08:43  arniml
1976
-- introduce prefix 't48_' for all packages, entities and configurations
1977
--
1978 179 arniml
-- Revision 1.18  2005/06/09 22:18:28  arniml
1979
-- Move latching of BUS to MSTATE2
1980
--   -> sample BUS at the end of RD'
1981
--
1982 178 arniml
-- Revision 1.17  2005/05/09 22:26:08  arniml
1983
-- remove obsolete output stack_high_o
1984
--
1985 171 arniml
-- Revision 1.16  2004/10/25 19:39:24  arniml
1986
-- Fix bug report:
1987
-- "RD' and WR' not asserted for INS A, BUS and OUTL BUS, A"
1988
-- rd is asserted for INS A, BUS
1989
-- wr is asserted for OUTL BUS, A
1990
-- P1, P2 and BUS are written in first instruction cycle
1991
--
1992 143 arniml
-- Revision 1.15  2004/09/12 00:35:44  arniml
1993
-- Fix bug report:
1994
-- "PSENn Timing"
1995
-- PSEN is now only asserted for the second cycle if explicitely
1996
-- requested by assert_psen_s.
1997
-- The previous implementation asserted PSEN together with RD or WR.
1998
--
1999 134 arniml
-- Revision 1.14  2004/06/30 21:18:28  arniml
2000
-- Fix bug report:
2001
-- "Program Memory bank can be switched during interrupt"
2002
-- int module emits int_in_progress signal that is used inside the decoder
2003
-- to hold mb low for JMP and CALL during interrupts
2004
--
2005 120 arniml
-- Revision 1.13  2004/05/20 21:51:40  arniml
2006
-- clean-up use of ea_i
2007
--
2008 106 arniml
-- Revision 1.12  2004/05/17 14:40:09  arniml
2009
-- assert p2_read_p2_o when expander port is read
2010
--
2011 101 arniml
-- Revision 1.11  2004/05/16 15:33:39  arniml
2012
-- work around bug in Quartus II 4.0
2013
--
2014 92 arniml
-- Revision 1.10  2004/04/25 16:22:03  arniml
2015
-- adjust external timing of BUS
2016
--
2017 78 arniml
-- Revision 1.9  2004/04/24 11:22:55  arniml
2018
-- removed superfluous signal from sensitivity list
2019
--
2020 72 arniml
-- Revision 1.8  2004/04/18 18:57:43  arniml
2021
-- + enhance instruction strobe generation
2022
-- + rework address output under EA=1 conditions
2023
--
2024 64 arniml
-- Revision 1.7  2004/04/15 22:06:05  arniml
2025
-- + add marker for injected calls
2026
-- + suppress intstruction strobes for injected calls
2027
--
2028 60 arniml
-- Revision 1.6  2004/04/14 20:53:33  arniml
2029
-- make istrobe visible through testbench package
2030
--
2031 53 arniml
-- Revision 1.5  2004/04/07 22:09:03  arniml
2032
-- remove unused signals
2033
--
2034 45 arniml
-- Revision 1.4  2004/04/04 14:18:53  arniml
2035
-- add measures to implement XCHD
2036
--
2037 38 arniml
-- Revision 1.3  2004/03/28 21:15:48  arniml
2038
-- implemented mnemonic DA
2039
--
2040 27 arniml
-- Revision 1.2  2004/03/28 13:06:32  arniml
2041
-- implement mnemonics:
2042
--    + MOVD_A_PP
2043
--    + OUTD_PP_A -> ANLD PP, A; MOVD PP, A; ORLD PP, A
2044
--
2045 21 arniml
-- Revision 1.1  2004/03/23 21:31:52  arniml
2046
-- initial check-in
2047 27 arniml
--
2048 4 arniml
-------------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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