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 292

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

powered by: WebSVN 2.1.0

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