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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_2/] [rtl/] [vhdl/] [decoder.vhd] - Blame information for rev 214

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

powered by: WebSVN 2.1.0

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