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 195

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

powered by: WebSVN 2.1.0

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