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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_0_6_1_beta/] [rtl/] [vhdl/] [decoder.vhd] - Blame information for rev 329

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

powered by: WebSVN 2.1.0

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