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

Subversion Repositories tg68kc

[/] [tg68kc/] [trunk/] [TG68KdotC_Kernel.vhd] - Blame information for rev 10

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

Line No. Rev Author Line
1 2 tobiflex
------------------------------------------------------------------------------
2
------------------------------------------------------------------------------
3
--                                                                          --
4 4 tobiflex
-- Copyright (c) 2009-2019 Tobias Gubener                                   -- 
5
-- Patches by MikeJ, Till Harbaum, Rok Krajnk, ...                          --
6 2 tobiflex
-- Subdesign fAMpIGA by TobiFlex                                            --
7
--                                                                          --
8
-- This source file is free software: you can redistribute it and/or modify --
9
-- it under the terms of the GNU Lesser General Public License as published --
10
-- by the Free Software Foundation, either version 3 of the License, or     --
11
-- (at your option) any later version.                                      --
12
--                                                                          --
13
-- This source file is distributed in the hope that it will be useful,      --
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of           --
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            --
16
-- GNU General Public License for more details.                             --
17
--                                                                          --
18
-- You should have received a copy of the GNU General Public License        --
19
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.    --
20
--                                                                          --
21
------------------------------------------------------------------------------
22 10 tobiflex
------------------------------------------------------------------------------
23 2 tobiflex
 
24 10 tobiflex
-- 10.11.2019 TG inset TRAPcc
25
-- 08.11.2019 TG bugfix movem in 68020 mode
26
-- 06.11.2019 TG bugfix CHK
27
-- 06.11.2019 TG bugfix flags and stackframe DIVU
28 9 tobiflex
-- 04.11.2019 TG insert RTE from TH
29 8 tobiflex
-- 03.11.2019 TG insert TrapV from TH 
30
-- 03.11.2019 TG bugfix MUL 64Bit 
31 7 tobiflex
-- 03.11.2019 TG rework barrel shifter - some other tweaks
32
-- 02.11.2019 TG bugfig N-Flag and Z-Flag for DIV
33 4 tobiflex
-- 30.10.2019 TG bugfix RTR in 68020-mode
34
-- 30.10.2019 TG bugfix BFINS again
35
-- 19.10.2019 TG insert some bugfixes from apolkosnik
36 2 tobiflex
-- 05.12.2018 TG insert RTD opcode
37
-- 03.12.2018 TG insert barrel shifter
38
-- 01.11.2017 TG bugfix V-Flag for ASL/ASR - thanks Peter Graf
39
-- 29.05.2017 TG decode 0x4AFB as illegal, needed for QL BKP - thanks Peter Graf
40
-- 21.05.2017 TG insert generic for hardware multiplier for MULU & MULS
41
-- 04.04.2017 TG change GPL to LGPL
42
-- 04.04.2017 TG BCD handling with all undefined behavior! 
43
-- 02.04.2017 TG bugfix Bitfield Opcodes 
44
-- 19.03.2017 TG insert PACK/UNPACK  
45
-- 19.03.2017 TG bugfix CMPI ...(PC) - thanks Till Harbaum
46
--     ???    MJ bugfix non_aligned movem access
47
-- add berr handling 10.03.2013 - needed for ATARI Core
48
 
49
-- bugfix session 07/08.Feb.2013
50
-- movem ,-(an)
51
-- movem (an)+,          - thanks  Gerhard Suttner
52
-- btst dn,#data         - thanks  Peter Graf
53
-- movep                 - thanks  Till Harbaum
54
-- IPL vector            - thanks  Till Harbaum
55
--  
56
 
57
-- optimize Register file
58
 
59
-- to do 68010:
60
-- (MOVEC)
61
-- BKPT
62
-- MOVES
63
--
64
-- to do 68020:
65
-- (CALLM)
66
-- (RETM)
67
 
68
-- CAS, CAS2
69
-- CHK2
70
-- CMP2
71
-- cpXXX Coprozessor stuff
72 10 tobiflex
 
73
-- done 020:
74 2 tobiflex
-- TRAPcc
75
-- PACK
76
-- UNPK
77
-- Bitfields
78
-- address modes
79
-- long bra
80
-- DIVS.L, DIVU.L
81
-- LINK long
82
-- MULS.L, MULU.L
83
-- extb.l
84
 
85
library ieee;
86
use ieee.std_logic_1164.all;
87
use ieee.std_logic_unsigned.all;
88
use work.TG68K_Pack.all;
89
 
90
entity TG68KdotC_Kernel is
91
        generic(
92 10 tobiflex
                SR_Read : integer:= 2;                          --0=>user,              1=>privileged,          2=>switchable with CPU(0)
93
                VBR_Stackframe : integer:= 2;           --0=>no,                        1=>yes/extended,        2=>switchable with CPU(0)
94
                extAddr_Mode : integer:= 2;             --0=>no,                        1=>yes,                         2=>switchable with CPU(1)
95
                MUL_Mode : integer := 2;                        --0=>16Bit,             1=>32Bit,                       2=>switchable with CPU(1),  3=>no MUL,  
96
                DIV_Mode : integer := 2;                        --0=>16Bit,             1=>32Bit,                       2=>switchable with CPU(1),  3=>no DIV,  
97
                BitField : integer := 2;                        --0=>no,                        1=>yes,                         2=>switchable with CPU(1) 
98
 
99
                BarrelShifter : integer := 1;           --0=>no,                        1=>yes,                         2=>switchable with CPU(1)  
100
                MUL_Hardware : integer := 1             --0=>no,                        1=>yes,  
101 2 tobiflex
                );
102 5 tobiflex
        port(clk                                                : in std_logic;
103
                nReset                                  : in std_logic;                 --low active
104
                clkena_in                               : in std_logic:='1';
105
                data_in                                 : in std_logic_vector(15 downto 0);
106
                IPL                                             : in std_logic_vector(2 downto 0):="111";
107
                IPL_autovector                  : in std_logic:='0';
108
                berr                                            : in std_logic:='0';                                     -- only 68000 Stackpointer dummy
109
                CPU                                             : in std_logic_vector(1 downto 0):="00";  -- 00->68000  01->68010  11->68020(only some parts - yet)
110
                addr_out                                        : out std_logic_vector(31 downto 0);
111
                data_write                              : out std_logic_vector(15 downto 0);
112
                nWr                                             : out std_logic;
113
                nUDS                                            : out std_logic;
114
                nLDS                                            : out std_logic;
115
                busstate                                        : out std_logic_vector(1 downto 0);      -- 00-> fetch code 10->read data 11->write data 01->no memaccess
116
                nResetOut                               : out std_logic;
117
                FC                                                      : out std_logic_vector(2 downto 0);
118
                clr_berr                                        : out std_logic;
119
-- for debug
120
                skipFetch                               : out std_logic;
121
                regin_out                               : out std_logic_vector(31 downto 0);
122
                CACR_out                                        : out std_logic_vector( 3 downto 0);
123
                VBR_out                                 : out std_logic_vector(31 downto 0)
124 4 tobiflex
                );
125 2 tobiflex
end TG68KdotC_Kernel;
126
 
127
architecture logic of TG68KdotC_Kernel is
128
 
129
 
130 10 tobiflex
        signal use_VBR_Stackframe       : std_logic;
131
 
132 4 tobiflex
        signal syncReset                        : std_logic_vector(3 downto 0);
133
        signal Reset                            : std_logic;
134
        signal clkena_lw                        : std_logic;
135
        signal TG68_PC                          : std_logic_vector(31 downto 0);
136
        signal tmp_TG68_PC              : std_logic_vector(31 downto 0);
137
        signal TG68_PC_add              : std_logic_vector(31 downto 0);
138
        signal PC_dataa                 : std_logic_vector(31 downto 0);
139
        signal PC_datab                 : std_logic_vector(31 downto 0);
140
        signal memaddr                          : std_logic_vector(31 downto 0);
141
        signal state                            : std_logic_vector(1 downto 0);
142
        signal datatype                 : std_logic_vector(1 downto 0);
143
        signal set_datatype             : std_logic_vector(1 downto 0);
144
        signal exe_datatype             : std_logic_vector(1 downto 0);
145
        signal setstate                 : std_logic_vector(1 downto 0);
146 2 tobiflex
 
147 4 tobiflex
        signal opcode                           : std_logic_vector(15 downto 0);
148
        signal exe_opcode                       : std_logic_vector(15 downto 0);
149
        signal sndOPC                           : std_logic_vector(15 downto 0);
150 2 tobiflex
 
151 10 tobiflex
        signal exe_pc                           : std_logic_vector(31 downto 0);--TH
152
        signal last_opc_pc              : std_logic_vector(31 downto 0);--TH
153 4 tobiflex
        signal last_opc_read            : std_logic_vector(15 downto 0);
154
        signal registerin                       : std_logic_vector(31 downto 0);
155
        signal reg_QA                           : std_logic_vector(31 downto 0);
156
        signal reg_QB                           : std_logic_vector(31 downto 0);
157
        signal Wwrena,Lwrena            : bit;
158
        signal Bwrena                           : bit;
159
        signal Regwrena_now             : bit;
160 2 tobiflex
        signal rf_dest_addr             : std_logic_vector(3 downto 0);
161
        signal rf_source_addr   : std_logic_vector(3 downto 0);
162
        signal rf_source_addrd  : std_logic_vector(3 downto 0);
163
 
164 4 tobiflex
        signal regin                            : std_logic_vector(31 downto 0);
165
        type   regfile_t is array(0 to 15) of std_logic_vector(31 downto 0);
166
        signal regfile                          : regfile_t := (OTHERS => (OTHERS => '0')); -- mikej stops sim X issues;
167
        signal RDindex_A                        : integer range 0 to 15;
168
        signal RDindex_B                        : integer range 0 to 15;
169
        signal WR_AReg                          : std_logic;
170 2 tobiflex
 
171
 
172 4 tobiflex
        signal addr                                     : std_logic_vector(31 downto 0);
173
        signal memaddr_reg              : std_logic_vector(31 downto 0);
174
        signal memaddr_delta            : std_logic_vector(31 downto 0);
175
        signal use_base                 : bit;
176 2 tobiflex
 
177 4 tobiflex
        signal ea_data                          : std_logic_vector(31 downto 0);
178
        signal OP1out                           : std_logic_vector(31 downto 0);
179
        signal OP2out                           : std_logic_vector(31 downto 0);
180
        signal OP1outbrief              : std_logic_vector(15 downto 0);
181
        signal OP1in                            : std_logic_vector(31 downto 0);
182
        signal ALUout   : std_logic_vector(31 downto 0);
183
        signal data_write_tmp   : std_logic_vector(31 downto 0);
184
        signal data_write_muxin : std_logic_vector(31 downto 0);
185
        signal data_write_mux   : std_logic_vector(47 downto 0);
186
        signal nextpass                 : bit;
187
        signal setnextpass              : bit;
188
        signal setdispbyte              : bit;
189
        signal setdisp                          : bit;
190
        signal regdirectsource  :bit;           -- checken !!!
191
        signal addsub_q                 : std_logic_vector(31 downto 0);
192
        signal briefdata                        : std_logic_vector(31 downto 0);
193
--      signal c_in                             : std_logic_vector(3 downto 0);
194
        signal c_out                            : std_logic_vector(2 downto 0);
195 2 tobiflex
 
196 4 tobiflex
        signal mem_address              : std_logic_vector(31 downto 0);
197
        signal memaddr_a                        : std_logic_vector(31 downto 0);
198 2 tobiflex
 
199 4 tobiflex
        signal TG68_PC_brw              : bit;
200
        signal TG68_PC_word             : bit;
201
        signal getbrief                 : bit;
202
        signal brief                            : std_logic_vector(15 downto 0);
203
        signal dest_areg                        : std_logic;
204
        signal source_areg              : std_logic;
205
        signal data_is_source   : bit;
206
        signal store_in_tmp             : bit;
207
        signal write_back                       : bit;
208
        signal exec_write_back  : bit;
209
        signal setstackaddr             : bit;
210
        signal writePC                          : bit;
211
        signal writePCbig                       : bit;
212
        signal set_writePCbig   : bit;
213
        signal setopcode                        : bit;
214
        signal decodeOPC                        : bit;
215
        signal execOPC                          : bit;
216
        signal setexecOPC                       : bit;
217
        signal endOPC                           : bit;
218
        signal setendOPC                        : bit;
219
        signal Flags                            : std_logic_vector(7 downto 0);  -- ...XNZVC
220
        signal FlagsSR                          : std_logic_vector(7 downto 0);  -- T.S.0III
221
        signal SRin                                     : std_logic_vector(7 downto 0);
222
        signal exec_DIRECT              : bit;
223
        signal exec_tas                 : std_logic;
224
        signal set_exec_tas             : std_logic;
225 2 tobiflex
 
226 4 tobiflex
        signal exe_condition            : std_logic;
227
        signal ea_only                          : bit;
228
        signal source_lowbits   : bit;
229
        signal source_2ndHbits  : bit;
230
        signal source_2ndLbits  : bit;
231
        signal dest_2ndHbits            : bit;
232
        signal dest_hbits                       : bit;
233
        signal rot_bits                 : std_logic_vector(1 downto 0);
234
        signal set_rot_bits             : std_logic_vector(1 downto 0);
235
        signal rot_cnt                          : std_logic_vector(5 downto 0);
236
        signal set_rot_cnt              : std_logic_vector(5 downto 0);
237
        signal movem_actiond            : bit;
238
        signal movem_regaddr            : std_logic_vector(3 downto 0);
239
        signal movem_mux                        : std_logic_vector(3 downto 0);
240
        signal movem_presub             : bit;
241
        signal movem_run                        : bit;
242
        signal ea_calc_b                        : std_logic_vector(31 downto 0);
243
        signal set_direct_data  : bit;
244
        signal use_direct_data  : bit;
245
        signal direct_data              : bit;
246 2 tobiflex
 
247 4 tobiflex
        signal set_V_Flag                       : bit;
248
        signal set_vectoraddr   : bit;
249
        signal writeSR                          : bit;
250
        signal trap_berr                        : bit;
251
        signal trap_illegal             : bit;
252
        signal trap_addr_error  : bit;
253
        signal trap_priv                        : bit;
254
        signal trap_trace                       : bit;
255
        signal trap_1010                        : bit;
256
        signal trap_1111                        : bit;
257
        signal trap_trap                        : bit;
258
        signal trap_trapv                       : bit;
259 10 tobiflex
        signal trap_trapcc              : bit;
260 4 tobiflex
        signal trap_interrupt   : bit;
261
        signal trapmake                 : bit;
262
        signal trapd                            : bit;
263
        signal trap_SR                          : std_logic_vector(7 downto 0);
264
        signal make_trace                       : std_logic;
265
        signal make_berr                        : std_logic;
266 10 tobiflex
        signal useStackframe2   : std_logic;
267 2 tobiflex
 
268 4 tobiflex
        signal set_stop                 : bit;
269
        signal stop                                     : bit;
270
        signal trap_vector              : std_logic_vector(31 downto 0);
271
        signal trap_vector_vbr  : std_logic_vector(31 downto 0);
272
        signal USP                                      : std_logic_vector(31 downto 0);
273
--      signal illegal_write_mode       : bit;
274
--      signal illegal_read_mode        : bit;
275
--      signal illegal_byteaddr         : bit;
276 2 tobiflex
 
277 4 tobiflex
        signal IPL_nr                           : std_logic_vector(2 downto 0);
278
        signal rIPL_nr                          : std_logic_vector(2 downto 0);
279
        signal IPL_vec                          : std_logic_vector(7 downto 0);
280
        signal interrupt                        : bit;
281
        signal setinterrupt             : bit;
282
        signal SVmode                           : std_logic;
283
        signal preSVmode                        : std_logic;
284
        signal Suppress_Base            : bit;
285
        signal set_Suppress_Base: bit;
286
        signal set_Z_error              : bit;
287
        signal Z_error                  : bit;
288
        signal ea_build_now             : bit;
289
        signal build_logical            : bit;
290
        signal build_bcd                        : bit;
291 2 tobiflex
 
292 4 tobiflex
        signal data_read                        : std_logic_vector(31 downto 0);
293
        signal bf_ext_in                        : std_logic_vector(7 downto 0);
294
        signal bf_ext_out                       : std_logic_vector(7 downto 0);
295
--      signal byte                                     : bit;
296
        signal long_start                       : bit;
297 2 tobiflex
        signal long_start_alu   : bit;
298 4 tobiflex
        signal non_aligned              : std_logic;
299
        signal long_done                        : bit;
300
        signal memmask                          : std_logic_vector(5 downto 0);
301
        signal set_memmask              : std_logic_vector(5 downto 0);
302
        signal memread                          : std_logic_vector(3 downto 0);
303
        signal wbmemmask                        : std_logic_vector(5 downto 0);
304
        signal memmaskmux                       : std_logic_vector(5 downto 0);
305
        signal oddout                           : std_logic;
306
        signal set_oddout                       : std_logic;
307
        signal PCbase                           : std_logic;
308
        signal set_PCbase                       : std_logic;
309 2 tobiflex
 
310 4 tobiflex
        signal last_data_read   : std_logic_vector(31 downto 0);
311
        signal last_data_in             : std_logic_vector(31 downto 0);
312 2 tobiflex
 
313 4 tobiflex
        signal bf_offset                        : std_logic_vector(5 downto 0);
314
        signal bf_width                 : std_logic_vector(5 downto 0);
315
        signal bf_bhits                 : std_logic_vector(5 downto 0);
316
        signal bf_shift                 : std_logic_vector(5 downto 0);
317
        signal alu_width                        : std_logic_vector(5 downto 0);
318
        signal alu_bf_shift             : std_logic_vector(5 downto 0);
319
        signal bf_loffset                       : std_logic_vector(5 downto 0);
320
        signal bf_full_offset   : std_logic_vector(31 downto 0);
321
        signal alu_bf_ffo_offset: std_logic_vector(31 downto 0);
322
        signal alu_bf_loffset   : std_logic_vector(5 downto 0);
323 2 tobiflex
 
324 4 tobiflex
        signal movec_data                       : std_logic_vector(31 downto 0);
325
        signal VBR                                      : std_logic_vector(31 downto 0);
326
        signal CACR                                     : std_logic_vector(3 downto 0);
327
        signal DFC                                      : std_logic_vector(2 downto 0);
328
        signal SFC                                      : std_logic_vector(2 downto 0);
329 2 tobiflex
 
330
 
331 4 tobiflex
        signal set                                      : bit_vector(lastOpcBit downto 0);
332
        signal set_exec                 : bit_vector(lastOpcBit downto 0);
333
        signal exec                                     : bit_vector(lastOpcBit downto 0);
334 2 tobiflex
 
335
        signal micro_state              : micro_states;
336
        signal next_micro_state : micro_states;
337
 
338
 
339
 
340
BEGIN
341
 
342
ALU: TG68K_ALU
343
        generic map(
344 4 tobiflex
                MUL_Mode => MUL_Mode,                           --0=>16Bit,     1=>32Bit,       2=>switchable with CPU(1),              3=>no MUL,
345
                MUL_Hardware => MUL_Hardware,           --0=>no,                1=>yes,
346
                DIV_Mode => DIV_Mode,                           --0=>16Bit,     1=>32Bit,       2=>switchable with CPU(1),              3=>no DIV,
347
                BarrelShifter => BarrelShifter  --0=>no,                1=>yes,         2=>switchable with CPU(1)  
348 2 tobiflex
                )
349 5 tobiflex
        port map(
350
                clk => clk,                                                             --: in std_logic;
351
                Reset => Reset,                                         --: in std_logic;
352
                clkena_lw => clkena_lw,                         --: in std_logic:='1';
353
                execOPC => execOPC,                                     --: in bit;
354
                decodeOPC => decodeOPC,                         --: in bit;
355
                exe_condition => exe_condition, --: in std_logic;
356
                exec_tas => exec_tas,                           --: in std_logic;
357
                long_start => long_start_alu,           --: in bit;
358
                non_aligned => non_aligned,
359
                movem_presub => movem_presub,           --: in bit;
360
                set_stop => set_stop,                           --: in bit;
361
                Z_error => Z_error,                                     --: in bit;
362 2 tobiflex
 
363 5 tobiflex
                rot_bits => rot_bits,                           --: in std_logic_vector(1 downto 0);
364
                exec => exec,                                                   --: in bit_vector(lastOpcBit downto 0);
365
                OP1out => OP1out,                                               --: in std_logic_vector(31 downto 0);
366
                OP2out => OP2out,                                               --: in std_logic_vector(31 downto 0);
367
                reg_QA => reg_QA,                                               --: in std_logic_vector(31 downto 0);
368
                reg_QB => reg_QB,                                               --: in std_logic_vector(31 downto 0);
369
                opcode => opcode,                                               --: in std_logic_vector(15 downto 0);
370
                exe_opcode => exe_opcode,                       --: in std_logic_vector(15 downto 0);
371
                exe_datatype => exe_datatype,           --: in std_logic_vector(1 downto 0);
372
                sndOPC => sndOPC,                                               --: in std_logic_vector(15 downto 0);
373
                last_data_read => last_data_read(15 downto 0),   --: in std_logic_vector(31 downto 0);
374
                data_read => data_read(15 downto 0),                             --: in std_logic_vector(31 downto 0);
375
                FlagsSR => FlagsSR,                                     --: in std_logic_vector(7 downto 0);
376
                micro_state => micro_state,             --: in micro_states;  
377
                bf_ext_in => bf_ext_in,
378
                bf_ext_out => bf_ext_out,
379
                bf_shift => alu_bf_shift,
380
                bf_width => alu_width,
381
                bf_ffo_offset => alu_bf_ffo_offset,
382
                bf_loffset => alu_bf_loffset(4 downto 0),
383
 
384
                set_V_Flag => set_V_Flag,                       --: buffer bit;
385
                Flags => Flags,                                         --: buffer std_logic_vector(8 downto 0);
386
                c_out => c_out,                                         --: buffer std_logic_vector(2 downto 0);
387
                addsub_q => addsub_q,                           --: buffer std_logic_vector(31 downto 0);
388
                ALUout => ALUout                                                --: buffer std_logic_vector(31 downto 0)
389
        );
390
 
391
        long_start_alu <= to_bit(NOT memmaskmux(3));
392
 
393
        process (memmaskmux)
394
        begin
395
                non_aligned <= '0';
396
                if (memmaskmux(5 downto 4) = "01") or (memmaskmux(5 downto 4) = "10") then
397
                        non_aligned <= '1';
398
                end if;
399
        end process;
400 2 tobiflex
-----------------------------------------------------------------------------
401
-- Bus control
402
-----------------------------------------------------------------------------
403 4 tobiflex
   regin_out <= regin;
404
 
405
 
406 2 tobiflex
        nWr <= '0' WHEN state="11" ELSE '1';
407
        busstate <= state;
408
        nResetOut <= '0' WHEN exec(opcRESET)='1' ELSE '1';
409
 
410 5 tobiflex
        -- does shift for byte access. note active low me
411
        -- should produce address error on 68000
412
        memmaskmux <= memmask when addr(0) = '1' else memmask(4 downto 0) & '1';
413 2 tobiflex
        nUDS <= memmaskmux(5);
414
        nLDS <= memmaskmux(4);
415
        clkena_lw <= '1' WHEN clkena_in='1' AND memmaskmux(3)='1' ELSE '0';
416
        clr_berr <= '1' WHEN setopcode='1' AND trap_berr='1' ELSE '0';
417
 
418
        PROCESS (clk, nReset)
419
        BEGIN
420
                IF nReset='0' THEN
421
                        syncReset <= "0000";
422
                        Reset <= '1';
423
                ELSIF rising_edge(clk) THEN
424
                        IF clkena_in='1' THEN
425
                                syncReset <= syncReset(2 downto 0)&'1';
426
                                Reset <= NOT syncReset(3);
427
                        END IF;
428
                END IF;
429 10 tobiflex
                IF rising_edge(clk) THEN
430
                        IF VBR_Stackframe=1 or (cpu(0)='1' and VBR_Stackframe=2) THEN
431
                                use_VBR_Stackframe<='1';
432
                        ELSE
433
                                use_VBR_Stackframe<='0';
434
                        END IF;
435
                END IF;
436
        END PROCESS;
437 2 tobiflex
 
438
PROCESS (clk, long_done, last_data_in, data_in, addr, long_start, memmaskmux, memread, memmask, data_read)
439
        BEGIN
440
                IF memmaskmux(4)='0' THEN
441
                        data_read <= last_data_in(15 downto 0)&data_in;
442
                ELSE
443
                        data_read <= last_data_in(23 downto 0)&data_in(15 downto 8);
444
                END IF;
445
                IF memread(0)='1' OR (memread(1 downto 0)="10" AND memmaskmux(4)='1')THEN
446
                        data_read(31 downto 16) <= (OTHERS=>data_read(15));
447
                END IF;
448
 
449
                IF rising_edge(clk) THEN
450
                        IF clkena_lw='1' AND state="10" THEN
451
                                IF memmaskmux(4)='0' THEN
452
                                        bf_ext_in <= last_data_in(23 downto 16);
453
                                ELSE
454
                                        bf_ext_in <= last_data_in(31 downto 24);
455
                                END IF;
456
                        END IF;
457
                        IF Reset='1' THEN
458
                                last_data_read <= (OTHERS => '0');
459
                        ELSIF clkena_in='1' THEN
460
                                IF state="00" OR exec(update_ld)='1' THEN
461
                                        last_data_read <= data_read;
462
                                        IF state(1)='0' AND memmask(1)='0' THEN
463
                                                last_data_read(31 downto 16) <= last_opc_read;
464
                                        ELSIF state(1)='0' OR memread(1)='1' THEN
465
                                                last_data_read(31 downto 16) <= (OTHERS=>data_in(15));
466
                                        END IF;
467
                                END IF;
468
                                last_data_in <= last_data_in(15 downto 0)&data_in(15 downto 0);
469
 
470
                        END IF;
471
                END IF;
472
                                long_start <= to_bit(NOT memmask(1));
473
                                long_done <= to_bit(NOT memread(1));
474
        END PROCESS;
475
 
476
PROCESS (long_start, reg_QB, data_write_tmp, exec, data_read, data_write_mux, memmaskmux, bf_ext_out,
477
                 data_write_muxin, memmask, oddout, addr)
478
        BEGIN
479
                IF exec(write_reg)='1' THEN
480
                        data_write_muxin <= reg_QB;
481
                ELSE
482
                        data_write_muxin <= data_write_tmp;
483
                END IF;
484
 
485
                IF BitField=0 THEN
486
                        IF oddout=addr(0) THEN
487
                                data_write_mux <= "--------"&"--------"&data_write_muxin;
488
                        ELSE
489
                                data_write_mux <= "--------"&data_write_muxin&"--------";
490
                        END IF;
491
                ELSE
492
                        IF oddout=addr(0) THEN
493
                                data_write_mux <= "--------"&bf_ext_out&data_write_muxin;
494
                        ELSE
495
                                data_write_mux <= bf_ext_out&data_write_muxin&"--------";
496
                        END IF;
497
                END IF;
498
 
499
                IF memmaskmux(1)='0' THEN
500
                        data_write <= data_write_mux(47 downto 32);
501
                ELSIF memmaskmux(3)='0' THEN
502
                        data_write <= data_write_mux(31 downto 16);
503
                ELSE
504
                        data_write <= data_write_mux(15 downto 0);
505
                END IF;
506
                IF exec(mem_byte)='1' THEN      --movep
507
                        data_write(7 downto 0) <= data_write_tmp(15 downto 8);
508
                END IF;
509
        END PROCESS;
510
 
511
-----------------------------------------------------------------------------
512
-- Registerfile
513
-----------------------------------------------------------------------------
514
PROCESS (clk, regfile, RDindex_A, RDindex_B, exec)
515
        BEGIN
516
                reg_QA <= regfile(RDindex_A);
517
                reg_QB <= regfile(RDindex_B);
518
                IF rising_edge(clk) THEN
519
                    IF clkena_lw='1' THEN
520
                                rf_source_addrd <= rf_source_addr;
521
                                WR_AReg <= rf_dest_addr(3);
522
                                RDindex_A <= conv_integer(rf_dest_addr(3 downto 0));
523
                                RDindex_B <= conv_integer(rf_source_addr(3 downto 0));
524
                                IF Wwrena='1' THEN
525
                                        regfile(RDindex_A) <= regin;
526
                                END IF;
527
 
528
                                IF exec(to_USP)='1' THEN
529
                                        USP <= reg_QA;
530
                                END IF;
531
                        END IF;
532
                END IF;
533
        END PROCESS;
534
 
535
-----------------------------------------------------------------------------
536
-- Write Reg
537
-----------------------------------------------------------------------------
538
PROCESS (OP1in, reg_QA, Regwrena_now, Bwrena, Lwrena, exe_datatype, WR_AReg, movem_actiond, exec, ALUout, memaddr, memaddr_a, ea_only, USP, movec_data)
539
        BEGIN
540
                regin <= ALUout;
541
                IF exec(save_memaddr)='1' THEN
542
                        regin <= memaddr;
543
                ELSIF exec(get_ea_now)='1' AND ea_only='1' THEN
544
                        regin <= memaddr_a;
545
                ELSIF exec(from_USP)='1' THEN
546
                        regin <= USP;
547
                ELSIF exec(movec_rd)='1' THEN
548
                        regin <= movec_data;
549
                END IF;
550
 
551
                IF Bwrena='1' THEN
552
                        regin(15 downto 8) <= reg_QA(15 downto 8);
553
                END IF;
554
                IF Lwrena='0' THEN
555
                        regin(31 downto 16) <= reg_QA(31 downto 16);
556
                END IF;
557
 
558
                Bwrena <= '0';
559
                Wwrena <= '0';
560
                Lwrena <= '0';
561
                IF exec(presub)='1' OR exec(postadd)='1' OR exec(changeMode)='1' THEN           -- -(An)+
562
                        Wwrena <= '1';
563
                        Lwrena <= '1';
564
                ELSIF Regwrena_now='1' THEN             --dbcc  
565
                        Wwrena <= '1';
566
                ELSIF exec(Regwrena)='1' THEN           --read (mem)
567
                        Wwrena <= '1';
568
                        CASE exe_datatype IS
569
                                WHEN "00" =>            --BYTE
570
                                        Bwrena <= '1';
571
                                WHEN "01" =>            --WORD
572
                                        IF WR_AReg='1' OR movem_actiond='1' THEN
573
                                                Lwrena <='1';
574
                                        END IF;
575
                                WHEN OTHERS =>          --LONG
576
                                        Lwrena <= '1';
577
                        END CASE;
578
                END IF;
579
        END PROCESS;
580
 
581
-----------------------------------------------------------------------------
582
-- set dest regaddr
583
-----------------------------------------------------------------------------
584
PROCESS (opcode, rf_source_addrd, brief, setstackaddr, dest_hbits, dest_areg, data_is_source, sndOPC, exec, set, dest_2ndHbits)
585
        BEGIN
586
                IF exec(movem_action) ='1' THEN
587
                        rf_dest_addr <= rf_source_addrd;
588
                ELSIF set(briefext)='1' THEN
589
                        rf_dest_addr <= brief(15 downto 12);
590 4 tobiflex
                ELSIF set(get_bfoffset)='1' THEN
591 5 tobiflex
--                      IF opcode(15 downto 12)="1110" THEN
592 4 tobiflex
                                rf_dest_addr <= '0'&sndOPC(8 downto 6);
593 5 tobiflex
--                      ELSE
594
--                              rf_dest_addr <= sndOPC(9 downto 6);
595
--                      END IF;
596 2 tobiflex
                ELSIF dest_2ndHbits='1' THEN
597 4 tobiflex
                        rf_dest_addr <= '0'&sndOPC(14 downto 12);
598 2 tobiflex
                ELSIF set(write_reminder)='1' THEN
599 4 tobiflex
                        rf_dest_addr <= '0'&sndOPC(2 downto 0);
600 2 tobiflex
                ELSIF setstackaddr='1' THEN
601
                        rf_dest_addr <= "1111";
602
                ELSIF dest_hbits='1' THEN
603
                        rf_dest_addr <= dest_areg&opcode(11 downto 9);
604
                ELSE
605
                        IF opcode(5 downto 3)="000" OR data_is_source='1' THEN
606
                                rf_dest_addr <= dest_areg&opcode(2 downto 0);
607
                        ELSE
608
                                rf_dest_addr <= '1'&opcode(2 downto 0);
609
                        END IF;
610
                END IF;
611
        END PROCESS;
612
 
613
-----------------------------------------------------------------------------
614
-- set source regaddr
615
-----------------------------------------------------------------------------
616
PROCESS (opcode, movem_presub, movem_regaddr, source_lowbits, source_areg, sndOPC, exec, set, source_2ndLbits, source_2ndHbits)
617
        BEGIN
618
                IF exec(movem_action)='1' OR set(movem_action) ='1' THEN
619
                        IF movem_presub='1' THEN
620
                                rf_source_addr <= movem_regaddr XOR "1111";
621
                        ELSE
622
                                rf_source_addr <= movem_regaddr;
623
                        END IF;
624
                ELSIF source_2ndLbits='1' THEN
625 4 tobiflex
                        rf_source_addr <= '0'&sndOPC(2 downto 0);
626 2 tobiflex
                ELSIF source_2ndHbits='1' THEN
627 4 tobiflex
                        rf_source_addr <= '0'&sndOPC(14 downto 12);
628 2 tobiflex
                ELSIF source_lowbits='1' THEN
629
                        rf_source_addr <= source_areg&opcode(2 downto 0);
630
                ELSIF exec(linksp)='1' THEN
631
                        rf_source_addr <= "1111";
632
                ELSE
633
                        rf_source_addr <= source_areg&opcode(11 downto 9);
634
                END IF;
635
        END PROCESS;
636
 
637
-----------------------------------------------------------------------------
638
-- set OP1out
639
-----------------------------------------------------------------------------
640
PROCESS (reg_QA, store_in_tmp, ea_data, long_start, addr, exec, memmaskmux)
641
        BEGIN
642
                OP1out <= reg_QA;
643
                IF exec(OP1out_zero)='1' THEN
644
                        OP1out <= (OTHERS => '0');
645
                ELSIF exec(ea_data_OP1)='1' AND store_in_tmp='1' THEN
646
                        OP1out <= ea_data;
647
                ELSIF exec(movem_action)='1' OR memmaskmux(3)='0' OR exec(OP1addr)='1' THEN
648
                        OP1out <= addr;
649
                END IF;
650
        END PROCESS;
651
 
652
-----------------------------------------------------------------------------
653
-- set OP2out
654
-----------------------------------------------------------------------------
655
PROCESS (OP2out, reg_QB, exe_opcode, exe_datatype, execOPC, exec, use_direct_data,
656
             store_in_tmp, data_write_tmp, ea_data)
657
        BEGIN
658
                OP2out(15 downto 0) <= reg_QB(15 downto 0);
659
                OP2out(31 downto 16) <= (OTHERS => OP2out(15));
660
                IF exec(OP2out_one)='1' THEN
661
                        OP2out(15 downto 0) <= "1111111111111111";
662
                ELSIF exec(opcEXT)='1' THEN
663
                        IF exe_opcode(6)='0' OR exe_opcode(8)='1' THEN   --ext.w
664
                                OP2out(15 downto 8) <= (OTHERS => OP2out(7));
665
                        END IF;
666
                ELSIF use_direct_data='1' OR (exec(exg)='1' AND execOPC='1') OR exec(get_bfoffset)='1' THEN
667
                        OP2out <= data_write_tmp;
668
                ELSIF (exec(ea_data_OP1)='0' AND store_in_tmp='1') OR exec(ea_data_OP2)='1' THEN
669
                        OP2out <= ea_data;
670
                ELSIF exec(opcMOVEQ)='1' THEN
671
                        OP2out(7 downto 0) <= exe_opcode(7 downto 0);
672
                        OP2out(15 downto 8) <= (OTHERS => exe_opcode(7));
673
                ELSIF exec(opcADDQ)='1' THEN
674
                        OP2out(2 downto 0) <= exe_opcode(11 downto 9);
675
                        IF exe_opcode(11 downto 9)="000" THEN
676
                                OP2out(3) <='1';
677
                        ELSE
678
                                OP2out(3) <='0';
679
                        END IF;
680
                        OP2out(15 downto 4) <= (OTHERS => '0');
681
                ELSIF exe_datatype="10" THEN
682
                        OP2out(31 downto 16) <= reg_QB(31 downto 16);
683
                END IF;
684
        END PROCESS;
685
 
686
 
687
-----------------------------------------------------------------------------
688
-- handle EA_data, data_write
689
-----------------------------------------------------------------------------
690
PROCESS (clk)
691
        BEGIN
692
        IF rising_edge(clk) THEN
693
                        IF Reset = '1' THEN
694
                                store_in_tmp <='0';
695
                                exec_write_back <= '0';
696
                                direct_data <= '0';
697
                                use_direct_data <= '0';
698
                                Z_error <= '0';
699
                        ELSIF clkena_lw='1' THEN
700 10 tobiflex
                                useStackframe2<='0';
701 2 tobiflex
                                direct_data <= '0';
702
                                IF state="11" THEN
703
                                        exec_write_back <= '0';
704
                                ELSIF setstate="10" AND write_back='1' THEN
705 10 tobiflex
--                              ELSIF setstate = "10" AND write_back = '1' AND next_micro_state = idle THEN     --this shut be a fix for pinball
706
--                                                                                                                                                                                                                                              --but it destory pack -(ax),-(ay) and unpack
707 2 tobiflex
                                        exec_write_back <= '1';
708
                                END IF;
709
 
710 9 tobiflex
                                IF exec(hold_OP2)='1' THEN
711 8 tobiflex
                                        use_direct_data <= '1';
712
                                END IF;
713 2 tobiflex
                                IF set_direct_data='1' THEN
714
                                        direct_data <= '1';
715
                                        use_direct_data <= '1';
716
                                ELSIF endOPC='1' THEN
717
                                        use_direct_data <= '0';
718
                                END IF;
719
                                exec_DIRECT <= set_exec(opcMOVE);
720
 
721
                                IF endOPC='1' THEN
722
                                        store_in_tmp <='0';
723
                                        Z_error <= '0';
724
                                ELSE
725
                                        IF set_Z_error='1'  THEN
726
                                                Z_error <= '1';
727
                                        END IF;
728
                                        IF set_exec(opcMOVE)='1' AND state="11" THEN
729
                                                use_direct_data <= '1';
730
                                        END IF;
731
 
732
                                        IF state="10" OR exec(store_ea_packdata)='1' THEN
733
                                                store_in_tmp <= '1';
734
                                        END IF;
735
                                        IF direct_data='1' AND state="00" THEN
736
                                                store_in_tmp <= '1';
737
                                        END IF;
738
                                END IF;
739
 
740
                                IF state="10" AND exec(hold_ea_data)='0' THEN
741
                                        ea_data <= data_read;
742
                                ELSIF exec(get_2ndOPC)='1' THEN
743
                                        ea_data <= addr;
744
                                ELSIF exec(store_ea_data)='1' OR (direct_data='1' AND state="00") THEN
745
                                        ea_data <= last_data_read;
746
                                END IF;
747
 
748
                                IF writePC='1' THEN
749
                                        data_write_tmp <= TG68_PC;
750
                                ELSIF exec(writePC_add)='1' THEN
751
                                        data_write_tmp <= TG68_PC_add;
752 8 tobiflex
-- paste and copy form TH       ---------       
753
                                elsif micro_state=trap00 THEN
754
                                        data_write_tmp <= exe_pc; --TH
755 10 tobiflex
                                        useStackframe2<='1';
756 8 tobiflex
                                elsif micro_state = trap0 then
757
                  -- this is only active for 010+ since in 000 writePC is
758
                  -- true in state trap0
759 10 tobiflex
--                                      if trap_trace='1' or set_exec(opcTRAPV)='1' or Z_error='1' then
760
                                        IF      useStackframe2='1' THEN
761 8 tobiflex
                                                -- stack frame format #2
762
                                                data_write_tmp(15 downto 0) <= "0010" & trap_vector(11 downto 0); --TH
763
                                        else
764
                                                data_write_tmp(15 downto 0) <= "0000" & trap_vector(11 downto 0);
765
                                        end if;
766
------------------------------------
767
--                              ELSIF micro_state=trap0 THEN    
768
--                                      data_write_tmp(15 downto 0) <= trap_vector(15 downto 0);
769 2 tobiflex
                                ELSIF exec(hold_dwr)='1' THEN
770
                                        data_write_tmp <= data_write_tmp;
771
                                ELSIF exec(exg)='1' THEN
772
                                        data_write_tmp <= OP1out;
773
                                ELSIF exec(get_ea_now)='1' AND ea_only='1' THEN         -- ist for pea
774
                                        data_write_tmp <= addr;
775
                                ELSIF execOPC='1' THEN
776
                                        data_write_tmp <= ALUout;
777
                                ELSIF (exec_DIRECT='1' AND state="10") THEN
778
                                        data_write_tmp <= data_read;
779
                                        IF  exec(movepl)='1' THEN
780
                                                data_write_tmp(31 downto 8) <= data_write_tmp(23 downto 0);
781
                                        END IF;
782
                                ELSIF exec(movepl)='1' THEN
783
                                        data_write_tmp(15 downto 0) <= reg_QB(31 downto 16);
784
                                ELSIF direct_data='1' THEN
785
                                        data_write_tmp <= last_data_read;
786
                                ELSIF writeSR='1'THEN
787
                                        data_write_tmp(15 downto 0) <= trap_SR(7 downto 0)& Flags(7 downto 0);
788
                                ELSE
789
                                        data_write_tmp <= OP2out;
790
                                END IF;
791
                        END IF;
792
                END IF;
793
        END PROCESS;
794
 
795
-----------------------------------------------------------------------------
796
-- brief
797
-----------------------------------------------------------------------------
798
PROCESS (brief, OP1out, OP1outbrief, cpu)
799
        BEGIN
800
                IF brief(11)='1' THEN
801
                        OP1outbrief <= OP1out(31 downto 16);
802
                ELSE
803
                        OP1outbrief <= (OTHERS=>OP1out(15));
804
                END IF;
805
                briefdata <= OP1outbrief&OP1out(15 downto 0);
806
                IF extAddr_Mode=1 OR (cpu(1)='1' AND extAddr_Mode=2) THEN
807
                        CASE brief(10 downto 9) IS
808
                                WHEN "00" => briefdata <= OP1outbrief&OP1out(15 downto 0);
809
                                WHEN "01" => briefdata <= OP1outbrief(14 downto 0)&OP1out(15 downto 0)&'0';
810
                                WHEN "10" => briefdata <= OP1outbrief(13 downto 0)&OP1out(15 downto 0)&"00";
811
                                WHEN "11" => briefdata <= OP1outbrief(12 downto 0)&OP1out(15 downto 0)&"000";
812
                                WHEN OTHERS => NULL;
813
                        END CASE;
814
                END IF;
815
        END PROCESS;
816
 
817
-----------------------------------------------------------------------------
818
-- MEM_IO 
819
-----------------------------------------------------------------------------
820
PROCESS (clk, setdisp, memaddr_a, briefdata, memaddr_delta, setdispbyte, datatype, interrupt, rIPL_nr, IPL_vec,
821 10 tobiflex
         memaddr_reg, reg_QA, use_base, VBR, last_data_read, trap_vector, exec, set, cpu, use_VBR_Stackframe)
822 2 tobiflex
        BEGIN
823
 
824
                IF rising_edge(clk) THEN
825 10 tobiflex
                        IF clkena_lw='1' THEN
826 2 tobiflex
                                trap_vector(31 downto 10) <= (others => '0');
827
                                IF trap_berr='1' THEN
828
                                        trap_vector(9 downto 0) <= "00" & X"08";
829
                                END IF;
830
                                IF trap_addr_error='1' THEN
831
                                        trap_vector(9 downto 0) <= "00" & X"0C";
832
                                END IF;
833
                                IF trap_illegal='1' THEN
834
                                        trap_vector(9 downto 0) <= "00" & X"10";
835
                                END IF;
836 10 tobiflex
                                IF set_Z_error='1' THEN
837 2 tobiflex
                                        trap_vector(9 downto 0) <= "00" & X"14";
838
                                END IF;
839
                                IF exec(trap_chk)='1' THEN
840
                                        trap_vector(9 downto 0) <= "00" & X"18";
841
                                END IF;
842
                                IF trap_trapv='1' THEN
843
                                        trap_vector(9 downto 0) <= "00" & X"1C";
844
                                END IF;
845
                                IF trap_priv='1' THEN
846
                                        trap_vector(9 downto 0) <= "00" & X"20";
847
                                END IF;
848
                                IF trap_trace='1' THEN
849
                                        trap_vector(9 downto 0) <= "00" & X"24";
850
                                END IF;
851
                                IF trap_1010='1' THEN
852
                                        trap_vector(9 downto 0) <= "00" & X"28";
853
                                END IF;
854
                                IF trap_1111='1' THEN
855
                                        trap_vector(9 downto 0) <= "00" & X"2C";
856
                                END IF;
857
                                IF trap_trap='1' THEN
858
                                        trap_vector(9 downto 0) <= "0010" & opcode(3 downto 0) & "00";
859
                                END IF;
860
                                IF trap_interrupt='1' or set_vectoraddr = '1' THEN
861
                                        trap_vector(9 downto 0) <= IPL_vec & "00";      --TH
862
                                END IF;
863
                        END IF;
864
                END IF;
865 10 tobiflex
                IF use_VBR_Stackframe='1' THEN
866
                        trap_vector_vbr <= trap_vector+VBR;
867
                ELSE
868 2 tobiflex
                        trap_vector_vbr <= trap_vector;
869
                END IF;
870
 
871
                memaddr_a(4 downto 0) <= "00000";
872
                memaddr_a(7 downto 5) <= (OTHERS=>memaddr_a(4));
873
                memaddr_a(15 downto 8) <= (OTHERS=>memaddr_a(7));
874
                memaddr_a(31 downto 16) <= (OTHERS=>memaddr_a(15));
875
                IF setdisp='1' THEN
876
                        IF exec(briefext)='1' THEN
877
                                memaddr_a <= briefdata+memaddr_delta;
878
                        ELSIF setdispbyte='1' THEN
879
                                memaddr_a(7 downto 0) <= last_data_read(7 downto 0);
880
                        ELSE
881
                                memaddr_a <= last_data_read;
882
                        END IF;
883
                ELSIF set(presub)='1' THEN
884
                        IF set(longaktion)='1' THEN
885
                                memaddr_a(4 downto 0) <= "11100";
886
                        ELSIF datatype="00" AND set(use_SP)='0' THEN
887
                                memaddr_a(4 downto 0) <= "11111";
888
                        ELSE
889
                                memaddr_a(4 downto 0) <= "11110";
890
                        END IF;
891
                ELSIF interrupt='1' THEN
892
                        memaddr_a(4 downto 0) <= '1'&rIPL_nr&'0';
893
                END IF;
894
 
895
                IF rising_edge(clk) THEN
896
                        IF clkena_in='1' THEN
897
                                IF exec(get_2ndOPC)='1' OR (state="10" AND memread(0)='1') THEN
898
                                        tmp_TG68_PC <= addr;
899
                                END IF;
900
                                use_base <= '0';
901
                                IF memmaskmux(3)='0' OR exec(mem_addsub)='1' THEN
902
                                        memaddr_delta <= addsub_q;
903
                                ELSIF state="01" AND exec_write_back='1' THEN
904
                                        memaddr_delta <= tmp_TG68_PC;
905
                                ELSIF exec(direct_delta)='1' THEN
906
                                        memaddr_delta <= data_read;
907
                                ELSIF exec(ea_to_pc)='1' AND setstate="00" THEN
908
                                        memaddr_delta <= addr;
909
                                ELSIF set(addrlong)='1' THEN
910
                                        memaddr_delta <= last_data_read;
911
                                ELSIF setstate="00" THEN
912
                                        memaddr_delta <= TG68_PC_add;
913
                                ELSIF exec(dispouter)='1' THEN
914
                                        memaddr_delta <= ea_data+memaddr_a;
915
                                ELSIF set_vectoraddr='1' THEN
916
                                        memaddr_delta <= trap_vector_vbr;
917
                                ELSE
918
                                        memaddr_delta <= memaddr_a;
919
                                        IF interrupt='0' AND Suppress_Base='0' THEN
920
--                                      IF interrupt='0' AND Suppress_Base='0' AND setstate(1)='1' THEN
921
                                                use_base <= '1';
922
                                        END IF;
923
                                END IF;
924
 
925
                -- only used for movem address update
926
--                                      IF (long_done='0' AND state(1)='1') OR movem_presub='0' THEN
927
                                        if ((memread(0) = '1') and state(1) = '1') or movem_presub = '0' then -- fix for unaligned movem mikej
928
                                                memaddr <= addr;
929
                                        END IF;
930
                        END IF;
931
                END IF;
932
 
933
                -- if access done, and not aligned, don't increment
934
                addr <= memaddr_reg+memaddr_delta;
935 4 tobiflex
                addr_out <= memaddr_reg + memaddr_delta;
936
 
937 2 tobiflex
                IF use_base='0' THEN
938
                        memaddr_reg <= (others=>'0');
939
                ELSE
940
                        memaddr_reg <= reg_QA;
941
                END IF;
942
    END PROCESS;
943
 
944
-----------------------------------------------------------------------------
945
-- PC Calc + fetch opcode
946
-----------------------------------------------------------------------------
947
PROCESS (clk, IPL, setstate, state, exec_write_back, set_direct_data, next_micro_state, stop, make_trace, make_berr, IPL_nr, FlagsSR, set_rot_cnt, opcode, writePCbig, set_exec, exec,
948 10 tobiflex
        PC_dataa, PC_datab, setnextpass, last_data_read, TG68_PC_brw, TG68_PC_word, Z_error, trap_trap, trap_trapv, trap_trapcc, interrupt, tmp_TG68_PC, TG68_PC)
949 2 tobiflex
        BEGIN
950
 
951
                PC_dataa <= TG68_PC;
952
                IF TG68_PC_brw = '1' THEN
953
                        PC_dataa <= tmp_TG68_PC;
954
                END IF;
955
 
956
                PC_datab(2 downto 0) <= (others => '0');
957
                PC_datab(3) <= PC_datab(2);
958
                PC_datab(7 downto 4) <= (others => PC_datab(3));
959
                PC_datab(15 downto 8) <= (others => PC_datab(7));
960
                PC_datab(31 downto 16) <= (others => PC_datab(15));
961
                IF interrupt='1' THEN
962
                        PC_datab(2 downto 1) <= "11";
963
                END IF;
964
                IF exec(writePC_add) ='1' THEN
965
                        IF writePCbig='1' THEN
966
                                PC_datab(3) <= '1';
967
                                PC_datab(1) <= '1';
968
                        ELSE
969
                                PC_datab(2) <= '1';
970
                        END IF;
971
                        IF trap_trap='1' OR trap_trapv='1' OR exec(trap_chk)='1' OR Z_error='1' THEN
972
                                PC_datab(1) <= '1';
973
                        END IF;
974
                ELSIF state="00" THEN
975
                        PC_datab(1) <= '1';
976
                END IF;
977
                IF TG68_PC_brw = '1' THEN
978
                        IF TG68_PC_word='1' THEN
979
                                PC_datab <= last_data_read;
980
                        ELSE
981
                                PC_datab(7 downto 0) <= opcode(7 downto 0);
982
                        END IF;
983
                END IF;
984
 
985
                TG68_PC_add <= PC_dataa+PC_datab;
986
 
987
                setopcode <= '0';
988
                setendOPC <= '0';
989
                setinterrupt <= '0';
990
                IF setstate="00" AND next_micro_state=idle AND setnextpass='0' AND (exec_write_back='0' OR state="11") AND set_rot_cnt="000001" AND set_exec(opcCHK)='0'THEN
991
                        setendOPC <= '1';
992
                        IF FlagsSR(2 downto 0)<IPL_nr OR IPL_nr="111"  OR make_trace='1' OR make_berr='1' THEN
993
                                setinterrupt <= '1';
994
                        ELSIF stop='0' THEN
995
                                setopcode <= '1';
996
                        END IF;
997
                END IF;
998
                setexecOPC <= '0';
999
                IF setstate="00" AND next_micro_state=idle AND set_direct_data='0' AND (exec_write_back='0' OR state="10") THEN
1000
                        setexecOPC <= '1';
1001
                END IF;
1002
 
1003
                IPL_nr <= NOT IPL;
1004
                IF rising_edge(clk) THEN
1005 4 tobiflex
                        IF Reset = '1' THEN
1006 2 tobiflex
                                state <= "01";
1007
                                opcode <= X"2E79";                                      --move $0,a7
1008
                                trap_interrupt <= '0';
1009
                                interrupt <= '0';
1010
                                last_opc_read  <= X"4EF9";                      --jmp nn.l
1011
                                TG68_PC <= X"00000004";
1012
                                decodeOPC <= '0';
1013
                                endOPC <= '0';
1014
                                TG68_PC_word <= '0';
1015
                                execOPC <= '0';
1016
                                stop <= '0';
1017
                                rot_cnt <="000001";
1018
--                              byte <= '0';
1019
--                              IPL_nr <= "000";
1020
                                trap_trace <= '0';
1021
                                trap_berr <= '0';
1022
                                writePCbig <= '0';
1023
--                              recall_last <= '0';
1024
                                Suppress_Base <= '0';
1025
                                make_berr <= '0';
1026
                                memmask <= "111111";
1027
                        ELSE
1028
--                              IPL_nr <= NOT IPL;
1029
                                IF clkena_in='1' THEN
1030
                                        memmask <= memmask(3 downto 0)&"11";
1031
                                        memread <= memread(1 downto 0)&memmaskmux(5 downto 4);
1032
--                                      IF wbmemmask(5 downto 4)="11" THEN      
1033
--                                              wbmemmask <= memmask;
1034
--                                      END IF;
1035
                                        IF exec(directPC)='1' THEN
1036
                                                TG68_PC <= data_read;
1037
                                        ELSIF exec(ea_to_pc)='1' THEN
1038
                                                TG68_PC <= addr;
1039
                                        ELSIF (state ="00" OR TG68_PC_brw = '1') AND stop='0'  THEN
1040
                                                TG68_PC <= TG68_PC_add;
1041
                                        END IF;
1042
                                END IF;
1043
                                IF clkena_lw='1' THEN
1044
                                        interrupt <= setinterrupt;
1045
                                        decodeOPC <= setopcode;
1046
                                        endOPC <= setendOPC;
1047
                                        execOPC <= setexecOPC;
1048
 
1049
                                        exe_datatype <= set_datatype;
1050
                                        exe_opcode <= opcode;
1051
 
1052
                                        if(trap_berr='0') then
1053
                                                make_berr <= (berr OR make_berr);
1054
                                        else
1055
                                                make_berr <= '0';
1056
                                        end if;
1057
 
1058
                                        stop <= set_stop OR (stop AND NOT setinterrupt);
1059
                                        IF setinterrupt='1' THEN
1060
                                                trap_interrupt <= '0';
1061
                                                trap_trace <= '0';
1062
--                                              TG68_PC_word <= '0';
1063
                                                make_berr <= '0';
1064
                                                trap_berr <= '0';
1065
                                                IF make_trace='1' THEN
1066
                                                        trap_trace <= '1';
1067
                                                ELSIF make_berr='1' THEN
1068
                                                        trap_berr <= '1';
1069
                                                ELSE
1070
                                                        rIPL_nr <= IPL_nr;
1071
                                                        IPL_vec <= "00011"&IPL_nr;            --        TH              
1072
                                                        trap_interrupt <= '1';
1073
                                                END IF;
1074
                                        END IF;
1075
                                        IF micro_state=trap0 AND IPL_autovector='0' THEN
1076
                                                IPL_vec <= last_data_read(7 downto 0);    --     TH
1077
                                        END IF;
1078
                                        IF state="00" THEN
1079
                                                last_opc_read <= data_read(15 downto 0);
1080 8 tobiflex
                                                last_opc_pc <= tg68_pc;--TH
1081 2 tobiflex
                                        END IF;
1082
                                        IF setopcode='1' THEN
1083
                                                trap_interrupt <= '0';
1084
                                                trap_trace <= '0';
1085
                                                TG68_PC_word <= '0';
1086
                                                trap_berr <= '0';
1087
                                        ELSIF opcode(7 downto 0)="00000000" OR opcode(7 downto 0)="11111111" OR data_is_source='1' THEN
1088
                                                TG68_PC_word <= '1';
1089
                                        END IF;
1090
 
1091
                                        IF exec(get_bfoffset)='1' THEN
1092
                                                alu_width <= bf_width;
1093
                                                alu_bf_shift <= bf_shift;
1094
                                                alu_bf_loffset <= bf_loffset;
1095
                                                alu_bf_ffo_offset <= bf_full_offset+bf_width+1;
1096
                                        END IF;
1097
                                        memread <= "1111";
1098
                                        FC(1) <= NOT setstate(1) OR (PCbase AND NOT setstate(0));
1099
                                        FC(0) <= setstate(1) AND (NOT PCbase OR setstate(0));
1100
                                        IF interrupt='1' THEN
1101
                                                FC(1 downto 0) <= "11";
1102
                                        END IF;
1103
                                        IF (state="10" AND write_back='1' AND setstate/="10") OR set_rot_cnt/="000001" OR (stop='1' AND interrupt='0') OR set_exec(opcCHK)='1' THEN
1104
                                                state <= "01";
1105
                                                memmask <= "111111";
1106
                                        ELSIF execOPC='1' AND exec_write_back='1' THEN
1107
                                                state <= "11";
1108
                                                FC(1 downto 0) <= "01";
1109
                                                memmask <= wbmemmask;
1110
                                        ELSE
1111
                                                state <= setstate;
1112
                                                IF setstate="01" THEN
1113
                                                        memmask <= "111111";
1114
                                                        wbmemmask <= "111111";
1115
                                                ELSIF exec(get_bfoffset)='1' THEN
1116
                                                        memmask <= set_memmask;
1117
                                                        wbmemmask <= set_memmask;
1118
                                                        oddout <= set_oddout;
1119
                                                ELSIF set(longaktion)='1' THEN
1120
                                                        memmask <= "100001";
1121
                                                        wbmemmask <= "100001";
1122
                                                        oddout <= '0';
1123
                                                ELSIF set_datatype="00" AND setstate(1)='1' THEN
1124
                                                        memmask <= "101111";
1125
                                                        wbmemmask <= "101111";
1126
                                                        IF set(mem_byte)='1' THEN
1127
                                                                oddout <= '0';
1128
                                                        ELSE
1129
                                                                oddout <= '1';
1130
                                                        END IF;
1131
                                                ELSE
1132
                                                        memmask <= "100111";
1133
                                                        wbmemmask <= "100111";
1134
                                                        oddout <= '0';
1135
                                                END IF;
1136
                                        END IF;
1137
 
1138
                                        IF decodeOPC='1' THEN
1139
                                                rot_bits <= set_rot_bits;
1140
                                                writePCbig <= '0';
1141
                                        ELSE
1142
                                                writePCbig <= set_writePCbig OR writePCbig;
1143
                                        END IF;
1144
                                        IF decodeOPC='1' OR exec(ld_rot_cnt)='1' OR rot_cnt/="000001" THEN
1145
                                                rot_cnt <= set_rot_cnt;
1146
                                        END IF;
1147
 
1148
                                        IF set_Suppress_Base='1' THEN
1149
                                                Suppress_Base <= '1';
1150
                                        ELSIF setstate(1)='1' OR (ea_only='1' AND set(get_ea_now)='1') THEN
1151
                                                Suppress_Base <= '0';
1152
                                        END IF;
1153
                                        IF getbrief='1' THEN
1154
                                                IF state(1)='1' THEN
1155
                                                        brief <= last_opc_read(15 downto 0);
1156
                                                ELSE
1157
                                                        brief <= data_read(15 downto 0);
1158
                                                END IF;
1159
                                        END IF;
1160
 
1161
                                        IF setopcode='1' AND berr='0' THEN
1162
                                                IF state="00" THEN
1163
                                                        opcode <= data_read(15 downto 0);
1164 8 tobiflex
                                                        exe_pc <= tg68_pc;--TH
1165 2 tobiflex
                                                ELSE
1166
                                                        opcode <= last_opc_read(15 downto 0);
1167 8 tobiflex
                                                        exe_pc <= last_opc_pc;--TH
1168 2 tobiflex
                                                END IF;
1169
                                                nextpass <= '0';
1170
                                        ELSIF setinterrupt='1' OR setopcode='1' THEN
1171
                                                opcode <= X"4E71";              --nop
1172
                                                nextpass <= '0';
1173
                                        ELSE
1174
--                                              IF setnextpass='1' OR (regdirectsource='1' AND state="00") THEN
1175
                                                IF setnextpass='1' OR regdirectsource='1' THEN
1176
                                                        nextpass <= '1';
1177
                                                END IF;
1178 10 tobiflex
                                        END IF;
1179
 
1180
-- why do not I need this ??? What are the immediate data for ???                                       
1181
--                                      IF      trap_trapcc='1' THEN
1182
--                                              IF opcode(2 downto 0)="100" THEN
1183
--                                                      exe_pc <= (others => '0');
1184
--                                              ELSE
1185
--                                                      exe_pc <= last_data_read;
1186
--                                              END IF;
1187
--                                      END IF;
1188 2 tobiflex
 
1189
                                        IF decodeOPC='1' OR interrupt='1' THEN
1190
                                                trap_SR <= FlagsSR;
1191
                                        END IF;
1192
                                END IF;
1193
                        END IF;
1194
                END IF;
1195
 
1196
                IF rising_edge(clk) THEN
1197 5 tobiflex
                        IF Reset = '1' THEN
1198 2 tobiflex
                                PCbase <= '1';
1199
                        ELSIF clkena_lw='1' THEN
1200
                                PCbase <= set_PCbase OR PCbase;
1201
                                IF setexecOPC='1' OR (state(1)='1' AND movem_run='0') THEN
1202
                                        PCbase <= '0';
1203
                                END IF;
1204
                        END IF;
1205
                        IF clkena_lw='1' THEN
1206
                                exec <= set;
1207
                                exec_tas <= '0';
1208
                                exec(subidx) <= set(presub) or set(subidx);
1209
                                IF setexecOPC='1' THEN
1210
                                        exec <= set_exec OR set;
1211
                                        exec_tas <= set_exec_tas;
1212
                                END IF;
1213
                                exec(get_2ndOPC) <= set(get_2ndOPC) OR setopcode;
1214
                        END IF;
1215
                END IF;
1216
        END PROCESS;
1217
 
1218
------------------------------------------------------------------------------
1219
--prepare Bitfield Parameters
1220
------------------------------------------------------------------------------          
1221
PROCESS (clk, Reset, sndOPC, reg_QA, reg_QB, bf_width, bf_offset, bf_bhits, opcode, setstate, bf_shift)
1222
        BEGIN
1223
                IF sndOPC(11)='1' THEN
1224
                        bf_offset <= '0'&reg_QA(4 downto 0);
1225
                ELSE
1226
                        bf_offset <= '0'&sndOPC(10 downto 6);
1227
                END IF;
1228
                IF sndOPC(11)='1' THEN
1229
                        bf_full_offset <= reg_QA;
1230
                ELSE
1231
                        bf_full_offset <= (others => '0');
1232
                        bf_full_offset(4 downto 0) <= sndOPC(10 downto 6);
1233
                END IF;
1234
 
1235
                bf_width(5) <= '0';
1236
                IF sndOPC(5)='1' THEN
1237
                        bf_width(4 downto 0) <= reg_QB(4 downto 0)-1;
1238
                ELSE
1239
                        bf_width(4 downto 0) <= sndOPC(4 downto 0)-1;
1240
                END IF;
1241
                bf_bhits <= bf_width+bf_offset;
1242
                set_oddout <= NOT bf_bhits(3);
1243
 
1244 4 tobiflex
 
1245
-- bf_loffset is used for the shifted_bitmask
1246 2 tobiflex
                IF opcode(10 downto 8)="111" THEN --INS
1247
                        bf_loffset <= 32-bf_shift;
1248
                ELSE
1249
                        bf_loffset <= bf_shift;
1250
                END IF;
1251
                bf_loffset(5) <= '0';
1252
 
1253
                IF opcode(4 downto 3)="00" THEN
1254
                        IF opcode(10 downto 8)="111" THEN --INS
1255
                                bf_shift <= bf_bhits+1;
1256
                        ELSE
1257
                                bf_shift <= 31-bf_bhits;
1258
                        END IF;
1259
                        bf_shift(5) <= '0';
1260
                ELSE
1261 4 tobiflex
                        IF opcode(10 downto 8)="111" THEN --INS
1262
                                bf_shift <= "011001"+("000"&bf_bhits(2 downto 0));
1263
                                bf_shift(5) <= '0';
1264 2 tobiflex
                        ELSE
1265
                                bf_shift <= "000"&("111"-bf_bhits(2 downto 0));
1266
                        END IF;
1267
                        bf_offset(4 downto 3) <= "00";
1268
                END IF;
1269 4 tobiflex
 
1270
                CASE bf_bhits(5 downto 3) IS
1271
                        WHEN "000" =>
1272
                                set_memmask <= "101111";
1273
                        WHEN "001" =>
1274 2 tobiflex
                                set_memmask <= "100111";
1275 4 tobiflex
                        WHEN "010" =>
1276
                                set_memmask <= "100011";
1277
                        WHEN "011" =>
1278
                                set_memmask <= "100001";
1279
                        WHEN OTHERS =>
1280
                                set_memmask <= "100000";
1281
                END CASE;
1282
                IF setstate="00" THEN
1283
                        set_memmask <= "100111";
1284
                END IF;
1285 2 tobiflex
        END PROCESS;
1286
 
1287
------------------------------------------------------------------------------
1288
--SR op
1289
------------------------------------------------------------------------------          
1290
PROCESS (clk, Reset, FlagsSR, last_data_read, OP2out, exec)
1291
        BEGIN
1292
                IF exec(andiSR)='1' THEN
1293
                        SRin <= FlagsSR AND last_data_read(15 downto 8);
1294
                ELSIF exec(eoriSR)='1' THEN
1295
                        SRin <= FlagsSR XOR last_data_read(15 downto 8);
1296
                ELSIF exec(oriSR)='1' THEN
1297
                        SRin <= FlagsSR OR last_data_read(15 downto 8);
1298
                ELSE
1299
                        SRin <= OP2out(15 downto 8);
1300
                END IF;
1301
 
1302
                IF rising_edge(clk) THEN
1303 4 tobiflex
                        IF Reset='1' THEN
1304 2 tobiflex
                                FC(2) <= '1';
1305
                                SVmode <= '1';
1306
                                preSVmode <= '1';
1307 7 tobiflex
                                FlagsSR <= "00100111";
1308 2 tobiflex
                                make_trace <= '0';
1309
                        ELSIF clkena_lw = '1' THEN
1310
                                IF setopcode='1' THEN
1311
                                        make_trace <= FlagsSR(7);
1312
                                        IF set(changeMode)='1' THEN
1313
                                                SVmode <= NOT SVmode;
1314
                                        ELSE
1315
                                                SVmode <= preSVmode;
1316
                                        END IF;
1317
                                END IF;
1318
                                IF set(changeMode)='1' THEN
1319
                                        preSVmode <= NOT preSVmode;
1320
                                        FlagsSR(5) <= NOT preSVmode;
1321
                                        FC(2) <= NOT preSVmode;
1322
                                END IF;
1323
                                IF micro_state=trap3 THEN
1324
                                        FlagsSR(7) <= '0';
1325
                                END IF;
1326
                                IF trap_trace='1' AND state="10" THEN
1327
                                        make_trace <= '0';
1328
                                END IF;
1329
                                IF exec(directSR)='1' OR set_stop='1' THEN
1330
                                        FlagsSR <= data_read(15 downto 8);
1331
                                END IF;
1332
                                IF interrupt='1' AND trap_interrupt='1' THEN
1333
                                        FlagsSR(2 downto 0) <=rIPL_nr;
1334
                                END IF;
1335
                                IF exec(to_SR)='1' THEN
1336
                                        FlagsSR(7 downto 0) <= SRin;     --SR
1337
                                        FC(2) <= SRin(5);
1338
                                ELSIF exec(update_FC)='1' THEN
1339
                                        FC(2) <= FlagsSR(5);
1340
                                END IF;
1341
                                IF interrupt='1' THEN
1342
                                        FC(2) <= '1';
1343 7 tobiflex
                                END IF;
1344
                                IF cpu(1)='0' THEN
1345
                                        FlagsSR(6) <= '0';
1346
                                END IF;
1347 4 tobiflex
                                FlagsSR(3) <= '0';
1348 2 tobiflex
                        END IF;
1349
                END IF;
1350
        END PROCESS;
1351
 
1352
-----------------------------------------------------------------------------
1353
-- decode opcode
1354
-----------------------------------------------------------------------------
1355
PROCESS (clk, cpu, OP1out, OP2out, opcode, exe_condition, nextpass, micro_state, decodeOPC, state, setexecOPC, Flags, FlagsSR, direct_data, build_logical,
1356
                 build_bcd, set_Z_error, trapd, movem_run, last_data_read, set, set_V_Flag, z_error, trap_trace, trap_interrupt,
1357
                 SVmode, preSVmode, stop, long_done, ea_only, setstate, execOPC, exec_write_back, exe_datatype,
1358 10 tobiflex
                 datatype, interrupt, c_out, trapmake, rot_cnt, brief, addr, trap_trapv, trap_trapcc, last_data_in, use_VBR_Stackframe,
1359 2 tobiflex
                 long_start, set_datatype, sndOPC, set_exec, exec, ea_build_now, reg_QA, reg_QB, make_berr, trap_berr)
1360
        BEGIN
1361
                TG68_PC_brw <= '0';
1362
                setstate <= "00";
1363
                Regwrena_now <= '0';
1364
                movem_presub <= '0';
1365
                setnextpass <= '0';
1366
                regdirectsource <= '0';
1367
                setdisp <= '0';
1368
                setdispbyte <= '0';
1369
                getbrief <= '0';
1370
                dest_areg <= '0';
1371
                source_areg <= '0';
1372
                data_is_source <= '0';
1373
                write_back <= '0';
1374
                setstackaddr <= '0';
1375
                writePC <= '0';
1376
                ea_build_now <= '0';
1377
--              set_rot_bits <= "00";
1378
                set_rot_bits <= opcode(4 downto 3);
1379
                set_rot_cnt <= "000001";
1380
                dest_hbits <= '0';
1381
                source_lowbits <= '0';
1382
                source_2ndHbits <= '0';
1383
                source_2ndLbits <= '0';
1384
                dest_2ndHbits <= '0';
1385
                ea_only <= '0';
1386
                set_direct_data <= '0';
1387
                set_exec_tas <= '0';
1388
                trap_illegal <='0';
1389
                trap_addr_error <= '0';
1390
                trap_priv <='0';
1391
                trap_1010 <='0';
1392
                trap_1111 <='0';
1393
                trap_trap <='0';
1394
                trap_trapv <= '0';
1395 10 tobiflex
                trap_trapcc <= '0';
1396 2 tobiflex
                trapmake <='0';
1397
                set_vectoraddr <='0';
1398
                writeSR <= '0';
1399
                set_stop <= '0';
1400
--              illegal_write_mode <= '0';
1401
--              illegal_read_mode <= '0';
1402
--              illegal_byteaddr <= '0';
1403
                set_Z_error <= '0';
1404
 
1405
                next_micro_state <= idle;
1406
                build_logical <= '0';
1407
                build_bcd <= '0';
1408
                skipFetch <= make_berr;
1409
                set_writePCbig <= '0';
1410
--              set_recall_last <= '0';
1411
                set_Suppress_Base <= '0';
1412
                set_PCbase <= '0';
1413
 
1414
                IF rot_cnt/="000001" THEN
1415
                        set_rot_cnt <= rot_cnt-1;
1416
                END IF;
1417
                set_datatype <= datatype;
1418
 
1419
                set <= (OTHERS=>'0');
1420
                set_exec <= (OTHERS=>'0');
1421
                set(update_ld) <= '0';
1422
--              odd_start <= '0';
1423
------------------------------------------------------------------------------
1424
--Sourcepass
1425
------------------------------------------------------------------------------          
1426
                CASE opcode(7 downto 6) IS
1427
                        WHEN "00" => datatype <= "00";          --Byte
1428
                        WHEN "01" => datatype <= "01";          --Word
1429
                        WHEN OTHERS => datatype <= "10";        --Long
1430
                END CASE;
1431
 
1432 10 tobiflex
                IF interrupt='1' AND trap_berr='1' THEN
1433
                        next_micro_state <= trap0;
1434
                        IF preSVmode='0' THEN
1435
                                set(changeMode) <= '1';
1436
                        END IF;
1437
                        setstate <= "01";
1438
                END IF;
1439 8 tobiflex
                IF trapmake='1' AND trapd='0' THEN
1440 10 tobiflex
                        IF use_VBR_Stackframe='1' AND (trap_trapv='1' OR set_Z_error='1' OR exec(opcCHK)='1') THEN
1441 8 tobiflex
                                next_micro_state <= trap00;
1442
                        else
1443
                                next_micro_state <= trap0;
1444
                        end if;
1445 10 tobiflex
                        IF use_VBR_Stackframe='0' THEN
1446 2 tobiflex
                                set(writePC_add) <= '1';
1447
--                              set_datatype <= "10";
1448
                        END IF;
1449
                        IF preSVmode='0' THEN
1450
                                set(changeMode) <= '1';
1451
                        END IF;
1452
                        setstate <= "01";
1453
                END IF;
1454
                IF micro_state=int1 OR (interrupt='1' AND trap_trace='1') THEN
1455 8 tobiflex
-- paste and copy form TH       ---------       
1456 10 tobiflex
                        if trap_trace='1' AND use_VBR_Stackframe='1' then
1457 8 tobiflex
                                next_micro_state <= trap00;  --TH
1458
                        else
1459
                                next_micro_state <= trap0;
1460
                        end if;
1461
------------------------------------
1462
--                      next_micro_state <= trap0;
1463 2 tobiflex
--                      IF cpu(0)='0' THEN
1464
--                              set_datatype <= "10";
1465
--                      END IF;
1466
                        IF preSVmode='0' THEN
1467
                                set(changeMode) <= '1';
1468
                        END IF;
1469
                        setstate <= "01";
1470
                END IF;
1471 8 tobiflex
        if micro_state = int1 or (interrupt = '1' and trap_trace = '1') then
1472
          if preSVmode = '0' then
1473
                set(changeMode) <= '1';
1474
          end if;
1475
          setstate <= "01";
1476
        end if;
1477 2 tobiflex
 
1478
                IF setexecOPC='1' AND FlagsSR(5)/=preSVmode THEN
1479
                        set(changeMode) <= '1';
1480
--                      setstate <= "01";
1481
--                      next_micro_state <= nop;
1482
                END IF;
1483
 
1484
                IF interrupt='1' AND trap_interrupt='1'THEN
1485
--                      skipFetch <= '1';
1486
                        next_micro_state <= int1;
1487
                        set(update_ld) <= '1';
1488
                        setstate <= "10";
1489
                END IF;
1490
 
1491
                IF set(changeMode)='1' THEN
1492
                        set(to_USP) <= '1';
1493
                        set(from_USP) <= '1';
1494
                        setstackaddr <='1';
1495
                END IF;
1496
 
1497
                IF ea_only='0' AND set(get_ea_now)='1' THEN
1498
                        setstate <= "10";
1499
--                      set_recall_last <= '1';
1500
--                      set(update_ld) <= '0';
1501
                END IF;
1502
 
1503
                IF setstate(1)='1' AND set_datatype(1)='1' THEN
1504
                        set(longaktion) <= '1';
1505
                END IF;
1506
 
1507
                IF (ea_build_now='1' AND decodeOPC='1') OR exec(ea_build)='1' THEN
1508
                        CASE opcode(5 downto 3) IS              --source
1509
                                WHEN "010"|"011"|"100" =>                                               -- -(An)+
1510
                                        set(get_ea_now) <='1';
1511
                                        setnextpass <= '1';
1512
                                        IF opcode(3)='1' THEN   --(An)+
1513
                                                set(postadd) <= '1';
1514
                                                IF opcode(2 downto 0)="111" THEN
1515
                                                        set(use_SP) <= '1';
1516
                                                END IF;
1517
                                        END IF;
1518
                                        IF opcode(5)='1' THEN   -- -(An)
1519
                                                set(presub) <= '1';
1520
                                                IF opcode(2 downto 0)="111" THEN
1521
                                                        set(use_SP) <= '1';
1522
                                                END IF;
1523
                                        END IF;
1524
                                WHEN "101" =>                           --(d16,An)
1525
                                        next_micro_state <= ld_dAn1;
1526
                                WHEN "110" =>                           --(d8,An,Xn)
1527
                                        next_micro_state <= ld_AnXn1;
1528
                                        getbrief <='1';
1529
                                WHEN "111" =>
1530
                                        CASE opcode(2 downto 0) IS
1531
                                                WHEN "000" =>                           --(xxxx).w
1532
                                                        next_micro_state <= ld_nn;
1533
                                                WHEN "001" =>                           --(xxxx).l
1534
                                                        set(longaktion) <= '1';
1535
                                                        next_micro_state <= ld_nn;
1536
                                                WHEN "010" =>                           --(d16,PC)
1537
                                                        next_micro_state <= ld_dAn1;
1538
                                                        set(dispouter) <= '1';
1539
                                                        set_Suppress_Base <= '1';
1540
                                                        set_PCbase <= '1';
1541
                                                WHEN "011" =>                           --(d8,PC,Xn)
1542
                                                        next_micro_state <= ld_AnXn1;
1543
                                                        getbrief <= '1';
1544
                                                        set(dispouter) <= '1';
1545
                                                        set_Suppress_Base <= '1';
1546
                                                        set_PCbase <= '1';
1547
                                                WHEN "100" =>                           --#data
1548
                                                        setnextpass <= '1';
1549
                                                        set_direct_data <= '1';
1550
                                                        IF datatype="10" THEN
1551
                                                                set(longaktion) <= '1';
1552
                                                        END IF;
1553
                                                WHEN OTHERS => NULL;
1554
                                        END CASE;
1555
                                WHEN OTHERS => NULL;
1556
                        END CASE;
1557
                END IF;
1558
------------------------------------------------------------------------------
1559
--prepere opcode
1560
------------------------------------------------------------------------------          
1561
                CASE opcode(15 downto 12) IS
1562
-- 0000 ----------------------------------------------------------------------------            
1563
                        WHEN "0000" =>
1564
                        IF opcode(8)='1' AND opcode(5 downto 3)="001" THEN --movep
1565
                                datatype <= "00";                               --Byte
1566
                                set(use_SP) <= '1';             --addr+2
1567
                                set(no_Flags) <='1';
1568
                                IF opcode(7)='0' THEN  --to register
1569
                                        set_exec(Regwrena) <= '1';
1570
                                        set_exec(opcMOVE) <= '1';
1571
                                        set(movepl) <= '1';
1572
                                END IF;
1573
                                IF decodeOPC='1' THEN
1574
                                        IF opcode(6)='1' THEN
1575
                                                set(movepl) <= '1';
1576
                                        END IF;
1577
                                        IF opcode(7)='0' THEN
1578
                                                set_direct_data <= '1';         -- to register
1579
                                        END IF;
1580
                                        next_micro_state <= movep1;
1581
                                END IF;
1582
                                IF setexecOPC='1' THEN
1583
                                        dest_hbits <='1';
1584
                                END IF;
1585
                        ELSE
1586
                                IF opcode(8)='1' OR opcode(11 downto 9)="100" THEN              --Bits
1587
                                        set_exec(opcBITS) <= '1';
1588
                                        set_exec(ea_data_OP1) <= '1';
1589
                                        IF opcode(7 downto 6)/="00" THEN
1590
                                                IF opcode(5 downto 4)="00" THEN
1591
                                                        set_exec(Regwrena) <= '1';
1592
                                                END IF;
1593
                                                write_back <= '1';
1594
                                        END IF;
1595
                                        IF opcode(5 downto 4)="00" THEN
1596
                                                datatype <= "10";                       --Long
1597
                                        ELSE
1598
                                                datatype <= "00";                       --Byte
1599
                                        END IF;
1600
                                        IF opcode(8)='0' THEN
1601
                                                IF decodeOPC='1' THEN
1602
                                                        next_micro_state <= nop;
1603
                                                        set(get_2ndOPC) <= '1';
1604
                                                        set(ea_build) <= '1';
1605
                                                END IF;
1606
                                        ELSE
1607
                                                ea_build_now <= '1';
1608
                                        END IF;
1609
                                ELSIF opcode(11 downto 9)="111" THEN            --MOVES not in 68000
1610
                                        trap_illegal <= '1';
1611
--                                      trap_addr_error <= '1';
1612
                                        trapmake <= '1';
1613
                                ELSE                                                            --andi, ...xxxi 
1614
                                        IF opcode(11 downto 9)="000" THEN       --ORI
1615
                                                set_exec(opcOR) <= '1';
1616
                                        END IF;
1617
                                        IF opcode(11 downto 9)="001" THEN       --ANDI
1618
                                                set_exec(opcAND) <= '1';
1619
                                        END IF;
1620
                                        IF opcode(11 downto 9)="010" OR opcode(11 downto 9)="011" THEN  --SUBI, ADDI
1621
                                                set_exec(opcADD) <= '1';
1622
                                        END IF;
1623
                                        IF opcode(11 downto 9)="101" THEN       --EORI
1624
                                                set_exec(opcEOR) <= '1';
1625
                                        END IF;
1626
                                        IF opcode(11 downto 9)="110" THEN       --CMPI
1627
                                                set_exec(opcCMP) <= '1';
1628
                                        END IF;
1629
                                        IF opcode(7)='0' AND opcode(5 downto 0)="111100" AND (set_exec(opcAND) OR set_exec(opcOR) OR set_exec(opcEOR))='1' THEN           --SR
1630
                                                IF decodeOPC='1' AND SVmode='0' AND opcode(6)='1' THEN  --SR
1631
                                                        trap_priv <= '1';
1632
                                                        trapmake <= '1';
1633
                                                ELSE
1634
                                                        set(no_Flags) <= '1';
1635
                                                        IF decodeOPC='1' THEN
1636
                                                                IF opcode(6)='1' THEN
1637
                                                                        set(to_SR) <= '1';
1638
                                                                END IF;
1639
                                                                set(to_CCR) <= '1';
1640
                                                                set(andiSR) <= set_exec(opcAND);
1641
                                                                set(eoriSR) <= set_exec(opcEOR);
1642
                                                                set(oriSR) <= set_exec(opcOR);
1643
                                                                setstate <= "01";
1644
                                                                next_micro_state <= nopnop;
1645
                                                        END IF;
1646
                                                END IF;
1647
                                        ELSE
1648
                                                IF decodeOPC='1' THEN
1649
                                                        next_micro_state <= andi;
1650
                                                        set(get_2ndOPC) <='1';
1651
                                                        set(ea_build) <= '1';
1652
                                                        set_direct_data <= '1';
1653
                                                        IF datatype="10" THEN
1654
                                                                set(longaktion) <= '1';
1655
                                                        END IF;
1656
                                                END IF;
1657
                                                IF opcode(5 downto 4)/="00" THEN
1658
                                                        set_exec(ea_data_OP1) <= '1';
1659
                                                END IF;
1660
                                                IF opcode(11 downto 9)/="110" THEN      --CMPI 
1661
                                                        IF opcode(5 downto 4)="00" THEN
1662
                                                                set_exec(Regwrena) <= '1';
1663
                                                        END IF;
1664
                                                        write_back <= '1';
1665
                                                END IF;
1666
                                                IF opcode(10 downto 9)="10" THEN        --CMPI, SUBI
1667
                                                        set(addsub) <= '1';
1668
                                                END IF;
1669
                                        END IF;
1670
                                END IF;
1671
                        END IF;
1672
 
1673
-- 0001, 0010, 0011 -----------------------------------------------------------------           
1674
                        WHEN "0001"|"0010"|"0011" =>                            --move.b, move.l, move.w
1675
                                set_exec(opcMOVE) <= '1';
1676
                                ea_build_now <= '1';
1677
                                IF opcode(8 downto 6)="001" THEN
1678
                                        set(no_Flags) <= '1';
1679
                                END IF;
1680
                                IF opcode(5 downto 4)="00" THEN --Dn, An
1681
                                        IF opcode(8 downto 7)="00" THEN
1682
                                                set_exec(Regwrena) <= '1';
1683
                                        END IF;
1684
                                END IF;
1685
                                CASE opcode(13 downto 12) IS
1686
                                        WHEN "01" => datatype <= "00";          --Byte
1687
                                        WHEN "10" => datatype <= "10";          --Long
1688
                                        WHEN OTHERS => datatype <= "01";        --Word
1689
                                END CASE;
1690
                                source_lowbits <= '1';                                  -- Dn=>  An=>
1691
                                IF opcode(3)='1' THEN
1692
                                        source_areg <= '1';
1693
                                END IF;
1694
 
1695
                                IF nextpass='1' OR opcode(5 downto 4)="00" THEN
1696
                                        dest_hbits <= '1';
1697
                                        IF opcode(8 downto 6)/="000" THEN
1698
                                                dest_areg <= '1';
1699
                                        END IF;
1700
                                END IF;
1701
--                              IF setstate="10" THEN
1702
--                                      set(update_ld) <= '0';
1703
--                              END IF;
1704
--
1705
                                IF micro_state=idle AND (nextpass='1' OR (opcode(5 downto 4)="00" AND decodeOPC='1')) THEN
1706
                                        CASE opcode(8 downto 6) IS              --destination
1707
                                                WHEN "000"|"001" =>                                             --Dn,An
1708
                                                                set_exec(Regwrena) <= '1';
1709
                                                WHEN "010"|"011"|"100" =>                                       --destination -(an)+
1710
                                                        IF opcode(6)='1' THEN   --(An)+
1711
                                                                set(postadd) <= '1';
1712
                                                                IF opcode(11 downto 9)="111" THEN
1713
                                                                        set(use_SP) <= '1';
1714
                                                                END IF;
1715
                                                        END IF;
1716
                                                        IF opcode(8)='1' THEN   -- -(An)
1717
                                                                set(presub) <= '1';
1718
                                                                IF opcode(11 downto 9)="111" THEN
1719
                                                                        set(use_SP) <= '1';
1720
                                                                END IF;
1721
                                                        END IF;
1722
                                                        setstate <= "11";
1723
                                                        next_micro_state <= nop;
1724
                                                        IF nextpass='0' THEN
1725
                                                                set(write_reg) <= '1';
1726
                                                        END IF;
1727
                                                WHEN "101" =>                           --(d16,An)
1728
                                                        next_micro_state <= st_dAn1;
1729
--                                                      getbrief <= '1';
1730
                                                WHEN "110" =>                           --(d8,An,Xn)
1731
                                                        next_micro_state <= st_AnXn1;
1732
                                                        getbrief <= '1';
1733
                                                WHEN "111" =>
1734
                                                        CASE opcode(11 downto 9) IS
1735
                                                                WHEN "000" =>                           --(xxxx).w
1736
                                                                        next_micro_state <= st_nn;
1737
                                                                WHEN "001" =>                           --(xxxx).l
1738
                                                                        set(longaktion) <= '1';
1739
                                                                        next_micro_state <= st_nn;
1740
                                                                WHEN OTHERS => NULL;
1741
                                                        END CASE;
1742
                                                WHEN OTHERS => NULL;
1743
                                        END CASE;
1744
                                END IF;
1745
---- 0100 ----------------------------------------------------------------------------          
1746
                        WHEN "0100" =>                          --rts_group
1747
                                IF opcode(8)='1' THEN           --lea
1748
                                        IF opcode(6)='1' THEN           --lea
1749
                                                IF opcode(7)='1' THEN
1750
                                                        source_lowbits <= '1';
1751
--                                                      IF opcode(5 downto 3)="000" AND opcode(10)='0' THEN             --ext
1752
                                                        IF opcode(5 downto 4)="00" THEN         --extb.l
1753
                                                                set_exec(opcEXT) <= '1';
1754
                                                                set_exec(opcMOVE) <= '1';
1755
                                                                set_exec(Regwrena) <= '1';
1756
--                                                              IF opcode(6)='0' THEN
1757
--                                                                      datatype <= "01";               --WORD
1758
--                                                              END IF;
1759
                                                        ELSE
1760
                                                                source_areg <= '1';
1761
                                                                ea_only <= '1';
1762
                                                                set_exec(Regwrena) <= '1';
1763
                                                                set_exec(opcMOVE) <='1';
1764
                                                                set(no_Flags) <='1';
1765
                                                                IF opcode(5 downto 3)="010" THEN        --lea (Am),An
1766
                                                                        dest_areg <= '1';
1767
                                                                        dest_hbits <= '1';
1768
                                                                ELSE
1769
                                                                        ea_build_now <= '1';
1770
                                                                END IF;
1771
                                                                IF set(get_ea_now)='1' THEN
1772
                                                                        setstate <= "01";
1773
                                                                        set_direct_data <= '1';
1774
                                                                END IF;
1775
                                                                IF setexecOPC='1' THEN
1776
                                                                        dest_areg <= '1';
1777
                                                                        dest_hbits <= '1';
1778
                                                                END IF;
1779
                                                        END IF;
1780
                                                ELSE
1781
                                                        trap_illegal <= '1';
1782
                                                        trapmake <= '1';
1783
                                                END IF;
1784
                                        ELSE                                                            --chk
1785
                                                IF opcode(7)='1' THEN
1786
                                                        datatype <= "01";       --Word
1787 10 tobiflex
                                                        set(trap_chk) <= '1';
1788 2 tobiflex
                                                        IF (c_out(1)='0' OR OP1out(15)='1' OR OP2out(15)='1') AND exec(opcCHK)='1' THEN
1789
                                                                trapmake <= '1';
1790
                                                        END IF;
1791
                                                ELSIF cpu(1)='1' THEN   --chk long for 68020
1792
                                                        datatype <= "10";       --Long
1793 10 tobiflex
                                                        set(trap_chk) <= '1';
1794
                                                        IF (c_out(2)='0' OR OP1out(31)='1' OR OP2out(31)='1') AND exec(opcCHK)='1' THEN
1795 2 tobiflex
                                                                trapmake <= '1';
1796
                                                        END IF;
1797
                                                ELSE
1798
                                                        trap_illegal <= '1';            -- chk long for 68020
1799
                                                        trapmake <= '1';
1800
                                                END IF;
1801
                                                IF opcode(7)='1' OR cpu(1)='1' THEN
1802
                                                        IF (nextpass='1' OR opcode(5 downto 4)="00") AND exec(opcCHK)='0' AND micro_state=idle THEN
1803
                                                                set_exec(opcCHK) <= '1';
1804
                                                        END IF;
1805
                                                        ea_build_now <= '1';
1806
                                                        set(addsub) <= '1';
1807
                                                        IF setexecOPC='1' THEN
1808
                                                                dest_hbits <= '1';
1809
                                                                source_lowbits <='1';
1810
                                                        END IF;
1811
                                                END IF;
1812
                                        END IF;
1813
                                ELSE
1814
                                        CASE opcode(11 downto 9) IS
1815
                                                WHEN "000"=>
1816
                                                        IF opcode(7 downto 6)="11" THEN                                 --move from SR
1817
                                                                IF SR_Read=0 OR (cpu(0)='0' AND SR_Read=2) OR SVmode='1'  THEN
1818
                                                                        ea_build_now <= '1';
1819
                                                                        set_exec(opcMOVESR) <= '1';
1820
                                                                        datatype <= "01";
1821
                                                                        write_back <='1';                                                       -- im 68000 wird auch erst gelesen
1822
                                                                        IF cpu(0)='1' AND state="10" THEN
1823
                                                                                skipFetch <= '1';
1824
                                                                        END IF;
1825
                                                                        IF opcode(5 downto 4)="00" THEN
1826
                                                                                set_exec(Regwrena) <= '1';
1827
                                                                        END IF;
1828
                                                                ELSE
1829
                                                                        trap_priv <= '1';
1830
                                                                        trapmake <= '1';
1831
                                                                END IF;
1832
                                                        ELSE                                                                    --negx
1833
                                                                ea_build_now <= '1';
1834
                                                                set_exec(use_XZFlag) <= '1';
1835
                                                                write_back <='1';
1836
                                                                set_exec(opcADD) <= '1';
1837
                                                                set(addsub) <= '1';
1838
                                                                source_lowbits <= '1';
1839
                                                                IF opcode(5 downto 4)="00" THEN
1840
                                                                        set_exec(Regwrena) <= '1';
1841
                                                                END IF;
1842
                                                                IF setexecOPC='1' THEN
1843
                                                                        set(OP1out_zero) <= '1';
1844
                                                                END IF;
1845
                                                        END IF;
1846
                                                WHEN "001"=>
1847
                                                        IF opcode(7 downto 6)="11" THEN                                 --move from CCR 68010
1848
                                                                IF SR_Read=1 OR (cpu(0)='1' AND SR_Read=2) THEN
1849
                                                                        ea_build_now <= '1';
1850
                                                                        set_exec(opcMOVESR) <= '1';
1851
                                                                        datatype <= "01";
1852
                                                                        write_back <='1';                                                       -- im 68000 wird auch erst gelesen
1853
--                                                                      IF state="10" THEN
1854
--                                                                              skipFetch <= '1';
1855
--                                                                      END IF;
1856
                                                                        IF opcode(5 downto 4)="00" THEN
1857
                                                                                set_exec(Regwrena) <= '1';
1858
                                                                        END IF;
1859
                                                                ELSE
1860
                                                                        trap_illegal <= '1';
1861
                                                                        trapmake <= '1';
1862
                                                                END IF;
1863
                                                        ELSE                                                                                    --clr
1864
                                                                ea_build_now <= '1';
1865
                                                                write_back <='1';
1866
                                                                set_exec(opcAND) <= '1';
1867
                                                        IF cpu(0)='1' AND state="10" THEN
1868
                                                                skipFetch <= '1';
1869
                                                        END IF;
1870
                                                                IF setexecOPC='1' THEN
1871
                                                                        set(OP1out_zero) <= '1';
1872
                                                                END IF;
1873
                                                                IF opcode(5 downto 4)="00" THEN
1874
                                                                        set_exec(Regwrena) <= '1';
1875
                                                                END IF;
1876
                                                        END IF;
1877
                                                WHEN "010"=>
1878
                                                        ea_build_now <= '1';
1879
                                                        IF opcode(7 downto 6)="11" THEN                                 --move to CCR
1880
                                                                datatype <= "01";
1881
                                                                source_lowbits <= '1';
1882
                                                                IF (decodeOPC='1' AND opcode(5 downto 4)="00") OR state="10" OR direct_data='1' THEN
1883
                                                                        set(to_CCR) <= '1';
1884
                                                                END IF;
1885
                                                        ELSE                                                                                    --neg
1886
                                                                write_back <='1';
1887
                                                                set_exec(opcADD) <= '1';
1888
                                                                set(addsub) <= '1';
1889
                                                                source_lowbits <= '1';
1890
                                                                IF opcode(5 downto 4)="00" THEN
1891
                                                                        set_exec(Regwrena) <= '1';
1892
                                                                END IF;
1893
                                                                IF setexecOPC='1' THEN
1894
                                                                        set(OP1out_zero) <= '1';
1895
                                                                END IF;
1896
                                                        END IF;
1897
                                                WHEN "011"=>                                                                            --not, move toSR
1898
                                                        IF opcode(7 downto 6)="11" THEN                                 --move to SR
1899
                                                                IF SVmode='1' THEN
1900
                                                                        ea_build_now <= '1';
1901
                                                                        datatype <= "01";
1902
                                                                        source_lowbits <= '1';
1903
                                                                        IF (decodeOPC='1' AND opcode(5 downto 4)="00") OR state="10" OR direct_data='1' THEN
1904
                                                                                set(to_SR) <= '1';
1905
                                                                                set(to_CCR) <= '1';
1906
                                                                        END IF;
1907
                                                                        IF exec(to_SR)='1' OR (decodeOPC='1' AND opcode(5 downto 4)="00") OR state="10" OR direct_data='1' THEN
1908
                                                                                setstate <="01";
1909
                                                                        END IF;
1910
                                                                ELSE
1911
                                                                        trap_priv <= '1';
1912
                                                                        trapmake <= '1';
1913
                                                                END IF;
1914
                                                        ELSE                                                                                    --not
1915
                                                                ea_build_now <= '1';
1916
                                                                write_back <='1';
1917
                                                                set_exec(opcEOR) <= '1';
1918
                                                                set_exec(ea_data_OP1) <= '1';
1919
                                                                IF opcode(5 downto 3)="000" THEN
1920
                                                                        set_exec(Regwrena) <= '1';
1921
                                                                END IF;
1922
                                                                IF setexecOPC='1' THEN
1923
                                                                        set(OP2out_one) <= '1';
1924
                                                                END IF;
1925
                                                        END IF;
1926
                                                WHEN "100"|"110"=>
1927
                                                        IF opcode(7)='1' THEN                   --movem, ext
1928
                                                                IF opcode(5 downto 3)="000" AND opcode(10)='0' THEN              --ext
1929
                                                                        source_lowbits <= '1';
1930
                                                                        set_exec(opcEXT) <= '1';
1931
                                                                        set_exec(opcMOVE) <= '1';
1932
                                                                        set_exec(Regwrena) <= '1';
1933
                                                                        IF opcode(6)='0' THEN
1934
                                                                                datatype <= "01";               --WORD
1935
                                                                        END IF;
1936
                                                                ELSE                                                                                                    --movem
1937
--                                                              IF opcode(11 downto 7)="10001" OR opcode(11 downto 7)="11001" THEN      --MOVEM
1938
                                                                        ea_only <= '1';
1939
                                                                        set(no_Flags) <= '1';
1940
                                                                        IF opcode(6)='0' THEN
1941
                                                                                datatype <= "01";               --Word transfer
1942
                                                                        END IF;
1943
                                                                        IF (opcode(5 downto 3)="100" OR opcode(5 downto 3)="011") AND state="01" THEN   -- -(An), (An)+
1944
                                                                                set_exec(save_memaddr) <= '1';
1945
                                                                                set_exec(Regwrena) <= '1';
1946
                                                                        END IF;
1947
                                                                        IF opcode(5 downto 3)="100" THEN        -- -(An)
1948
                                                                                movem_presub <= '1';
1949
                                                                                set(subidx) <= '1';
1950
                                                                        END IF;
1951
                                                                        IF state="10" THEN
1952
                                                                                set(Regwrena) <= '1';
1953
                                                                                set(opcMOVE) <= '1';
1954
                                                                        END IF;
1955
                                                                        IF decodeOPC='1' THEN
1956
                                                                                set(get_2ndOPC) <='1';
1957
                                                                                IF opcode(5 downto 3)="010" OR opcode(5 downto 3)="011" OR opcode(5 downto 3)="100" THEN
1958
                                                                                        next_micro_state <= movem1;
1959
                                                                                ELSE
1960
                                                                                        next_micro_state <= nop;
1961
                                                                                        set(ea_build) <= '1';
1962
                                                                                END IF;
1963
                                                                        END IF;
1964
                                                                        IF set(get_ea_now)='1' THEN
1965
                                                                                IF movem_run='1' THEN
1966
                                                                                        set(movem_action) <= '1';
1967
                                                                                        IF opcode(10)='0' THEN
1968
                                                                                                setstate <="11";
1969
                                                                                                set(write_reg) <= '1';
1970
                                                                                        ELSE
1971
                                                                                                setstate <="10";
1972
                                                                                        END IF;
1973
                                                                                        next_micro_state <= movem2;
1974
                                                                                        set(mem_addsub) <= '1';
1975
                                                                                ELSE
1976
                                                                                        setstate <="01";
1977
                                                                                END IF;
1978
                                                                        END IF;
1979
                                                                END IF;
1980
                                                        ELSE
1981
                                                                IF opcode(10)='1' THEN                                          --MUL.L, DIV.L 68020
1982
         --FPGA Multiplier for long                                                     
1983
                                                                        IF MUL_Hardware=1 AND (opcode(6)='0' AND (MUL_Mode=1 OR (cpu(1)='1' AND MUL_Mode=2))) THEN
1984
                                                                                IF decodeOPC='1' THEN
1985
                                                                                        next_micro_state <= nop;
1986
                                                                                        set(get_2ndOPC) <= '1';
1987
                                                                                        set(ea_build) <= '1';
1988
                                                                                END IF;
1989
                                                                                IF (micro_state=idle AND nextpass='1') OR (opcode(5 downto 4)="00" AND exec(ea_build)='1') THEN
1990
                                                                                        dest_2ndHbits <= '1';
1991
                                                                                        datatype <= "10";
1992
                                                                                        set(opcMULU) <= '1';
1993
                                                                                        set(write_lowlong) <= '1';
1994
                                                                                        IF sndOPC(10)='1' THEN
1995
                                                                                                setstate <="01";
1996
                                                                                                next_micro_state <= mul_end2;
1997
                                                                                        END IF;
1998
                                                                                        set(Regwrena) <= '1';
1999
                                                                                END IF;
2000
                                                                                source_lowbits <='1';
2001
                                                                                datatype <= "10";
2002
 
2003
         --no FPGA Multplier                                            
2004
                                                                        ELSIF (opcode(6)='1' AND (DIV_Mode=1 OR (cpu(1)='1' AND DIV_Mode=2))) OR
2005
                                                                           (opcode(6)='0' AND (MUL_Mode=1 OR (cpu(1)='1' AND MUL_Mode=2))) THEN
2006
                                                                                IF decodeOPC='1' THEN
2007
                                                                                        next_micro_state <= nop;
2008
                                                                                        set(get_2ndOPC) <= '1';
2009
                                                                                        set(ea_build) <= '1';
2010
                                                                                END IF;
2011
                                                                                IF (micro_state=idle AND nextpass='1') OR (opcode(5 downto 4)="00" AND exec(ea_build)='1')THEN
2012
                                                                                        setstate <="01";
2013
                                                                                        dest_2ndHbits <= '1';
2014
                                                                                        source_2ndLbits <= '1';
2015
                                                                                        IF opcode(6)='1' THEN
2016
                                                                                                next_micro_state <= div1;
2017
                                                                                        ELSE
2018
                                                                                                next_micro_state <= mul1;
2019
                                                                                                set(ld_rot_cnt) <= '1';
2020
                                                                                        END IF;
2021
                                                                                END IF;
2022
                                                                                IF z_error='0' AND set_V_Flag='0' AND set(opcDIVU)='1' THEN
2023
                                                                                        set(Regwrena) <= '1';
2024
                                                                                END IF;
2025
                                                                                source_lowbits <='1';
2026
                                                                                IF nextpass='1' OR (opcode(5 downto 4)="00" AND decodeOPC='1') THEN
2027
                                                                                        dest_hbits <= '1';
2028
                                                                                END IF;
2029
                                                                                datatype <= "10";
2030
                                                                        ELSE
2031
                                                                                trap_illegal <= '1';
2032
                                                                                trapmake <= '1';
2033
                                                                        END IF;
2034
 
2035
                                                                ELSE                                                    --pea, swap
2036
                                                                        IF opcode(6)='1' THEN
2037
                                                                                datatype <= "10";
2038
                                                                                IF opcode(5 downto 3)="000" THEN                --swap
2039
                                                                                        set_exec(opcSWAP) <= '1';
2040
                                                                                        set_exec(Regwrena) <= '1';
2041
                                                                                ELSIF opcode(5 downto 3)="001" THEN             --bkpt
2042 7 tobiflex
                                                                                        trap_illegal <= '1';
2043
                                                                                        trapmake <= '1';
2044 2 tobiflex
                                                                                ELSE                                                                    --pea
2045
                                                                                        ea_only <= '1';
2046
                                                                                        ea_build_now <= '1';
2047
                                                                                        IF nextpass='1' AND micro_state=idle THEN
2048
                                                                                                set(presub) <= '1';
2049
                                                                                                setstackaddr <='1';
2050
                                                                                                setstate <="11";
2051
                                                                                                next_micro_state <= nop;
2052
                                                                                        END IF;
2053
                                                                                        IF set(get_ea_now)='1' THEN
2054
                                                                                                setstate <="01";
2055
                                                                                        END IF;
2056
                                                                                END IF;
2057
                                                                        ELSE
2058
                                                                                IF opcode(5 downto 3)="001" THEN --link.l
2059
                                                                                        datatype <= "10";
2060
                                                                                        set_exec(opcADD) <= '1';                                                --for displacement
2061
                                                                                        set_exec(Regwrena) <= '1';
2062
                                                                                        set(no_Flags) <= '1';
2063
                                                                                        IF decodeOPC='1' THEN
2064
                                                                                                set(linksp) <= '1';
2065
                                                                                                set(longaktion) <= '1';
2066
                                                                                                next_micro_state <= link1;
2067
                                                                                                set(presub) <= '1';
2068
                                                                                                setstackaddr <='1';
2069
                                                                                                set(mem_addsub) <= '1';
2070
                                                                                                source_lowbits <= '1';
2071
                                                                                                source_areg <= '1';
2072
                                                                                                set(store_ea_data) <= '1';
2073
                                                                                        END IF;
2074
                                                                                ELSE                                            --nbcd  
2075
                                                                                        ea_build_now <= '1';
2076
                                                                                        set_exec(use_XZFlag) <= '1';
2077
                                                                                        write_back <='1';
2078
                                                                                        set_exec(opcADD) <= '1';
2079
                                                                                        set_exec(opcSBCD) <= '1';
2080
                                                                                        set(addsub) <= '1';
2081
                                                                                        source_lowbits <= '1';
2082
                                                                                        IF opcode(5 downto 4)="00" THEN
2083
                                                                                                set_exec(Regwrena) <= '1';
2084
                                                                                        END IF;
2085
                                                                                        IF setexecOPC='1' THEN
2086
                                                                                                set(OP1out_zero) <= '1';
2087
                                                                                        END IF;
2088
                                                                                END IF;
2089
                                                                        END IF;
2090
                                                                END IF;
2091
                                                        END IF;
2092
--0x4AXX                                                        
2093
                                                WHEN "101"=>                                            --tst, tas  4aFC - illegal
2094
--                                                      IF opcode(7 downto 2)="111111" THEN   --illegal
2095
                                                        IF opcode(7 downto 3)="11111" AND opcode(2 downto 1)/="00" THEN   --0x4AFC illegal  --0x4AFB BKP Sinclair QL
2096
                                                                trap_illegal <= '1';
2097
                                                                trapmake <= '1';
2098
                                                        ELSE
2099
                                                                ea_build_now <= '1';
2100
                                                                IF setexecOPC='1' THEN
2101
                                                                        source_lowbits <= '1';
2102
                                                                        IF opcode(3)='1' THEN                   --MC68020...
2103
                                                                                source_areg <= '1';
2104
                                                                        END IF;
2105
                                                                END IF;
2106
                                                                set_exec(opcMOVE) <= '1';
2107
                                                                IF opcode(7 downto 6)="11" THEN         --tas
2108
                                                                        set_exec_tas <= '1';
2109
                                                                        write_back <= '1';
2110
                                                                        datatype <= "00";                               --Byte
2111
                                                                        IF opcode(5 downto 4)="00" THEN
2112
                                                                                set_exec(Regwrena) <= '1';
2113
                                                                        END IF;
2114
                                                                END IF;
2115
                                                        END IF;
2116
----                                            WHEN "110"=>
2117
                                                WHEN "111"=>                                    --4EXX
2118
--
2119
--                                                                                      ea_only <= '1';
2120
--                                                                                      ea_build_now <= '1';
2121
--                                                                                      IF nextpass='1' AND micro_state=idle THEN
2122
--                                                                                              set(presub) <= '1';
2123
--                                                                                              setstackaddr <='1';
2124
--                                                                                              set(mem_addsub) <= '1';
2125
--                                                                                              setstate <="11";
2126
--                                                                                              next_micro_state <= nop;
2127
--                                                                                      END IF;
2128
--                                                                                      IF set(get_ea_now)='1' THEN
2129
--                                                                                              setstate <="01";
2130
--                                                                                      END IF;
2131
--                                                              
2132
 
2133
 
2134
 
2135
                                                        IF opcode(7)='1' THEN           --jsr, jmp
2136
                                                                datatype <= "10";
2137
                                                                ea_only <= '1';
2138
                                                                ea_build_now <= '1';
2139
                                                                IF exec(ea_to_pc)='1' THEN
2140
                                                                        next_micro_state <= nop;
2141
                                                                END IF;
2142
                                                                IF nextpass='1' AND micro_state=idle AND opcode(6)='0' THEN
2143
                                                                        set(presub) <= '1';
2144
                                                                        setstackaddr <='1';
2145
                                                                        setstate <="11";
2146
                                                                        next_micro_state <= nopnop;
2147
                                                                END IF;
2148
-- achtung buggefahr                                                            
2149
                                                                IF micro_state=ld_AnXn1 AND brief(8)='0'THEN                     --JMP/JSR n(Ax,Dn)
2150
                                                                        skipFetch <= '1';
2151
                                                                END IF;
2152
                                                                IF state="00" THEN
2153
                                                                        writePC <= '1';
2154
                                                                END IF;
2155
                                                                set(hold_dwr) <= '1';
2156
                                                                IF set(get_ea_now)='1' THEN                                     --jsr
2157
                                                                        IF exec(longaktion)='0' OR long_done='1' THEN
2158
                                                                                skipFetch <= '1';
2159
                                                                        END IF;
2160
                                                                        setstate <="01";
2161
                                                                        set(ea_to_pc) <= '1';
2162
                                                                END IF;
2163
                                                        ELSE                                            --
2164
                                                                CASE opcode(6 downto 0) IS
2165
                                                                        WHEN "1000000"|"1000001"|"1000010"|"1000011"|"1000100"|"1000101"|"1000110"|"1000111"|           --trap
2166
                                                                             "1001000"|"1001001"|"1001010"|"1001011"|"1001100"|"1001101"|"1001110"|"1001111" =>         --trap
2167
                                                                                        trap_trap <='1';
2168
                                                                                        trapmake <= '1';
2169
                                                                        WHEN "1010000"|"1010001"|"1010010"|"1010011"|"1010100"|"1010101"|"1010110"|"1010111"=>          --link word
2170
                                                                                datatype <= "10";
2171
                                                                                set_exec(opcADD) <= '1';                                                --for displacement
2172
                                                                                set_exec(Regwrena) <= '1';
2173
                                                                                set(no_Flags) <= '1';
2174
                                                                                IF decodeOPC='1' THEN
2175
                                                                                        next_micro_state <= link1;
2176
                                                                                        set(presub) <= '1';
2177
                                                                                        setstackaddr <='1';
2178
                                                                                        set(mem_addsub) <= '1';
2179
                                                                                        source_lowbits <= '1';
2180
                                                                                        source_areg <= '1';
2181
                                                                                        set(store_ea_data) <= '1';
2182
                                                                                END IF;
2183
 
2184
                                                                        WHEN "1011000"|"1011001"|"1011010"|"1011011"|"1011100"|"1011101"|"1011110"|"1011111" =>         --unlink
2185
                                                                                datatype <= "10";
2186
                                                                                set_exec(Regwrena) <= '1';
2187
                                                                                set_exec(opcMOVE) <= '1';
2188
                                                                                set(no_Flags) <= '1';
2189
                                                                                IF decodeOPC='1' THEN
2190
                                                                                        setstate <= "01";
2191
                                                                                        next_micro_state <= unlink1;
2192
                                                                                        set(opcMOVE) <= '1';
2193
                                                                                        set(Regwrena) <= '1';
2194
                                                                                        setstackaddr <='1';
2195
                                                                                        source_lowbits <= '1';
2196
                                                                                        source_areg <= '1';
2197
                                                                                END IF;
2198
 
2199
                                                                        WHEN "1100000"|"1100001"|"1100010"|"1100011"|"1100100"|"1100101"|"1100110"|"1100111" =>         --move An,USP
2200
                                                                                IF SVmode='1' THEN
2201
--                                                                                      set(no_Flags) <= '1';
2202
                                                                                        set(to_USP) <= '1';
2203
                                                                                        source_lowbits <= '1';
2204
                                                                                        source_areg <= '1';
2205
                                                                                        datatype <= "10";
2206
                                                                                ELSE
2207
                                                                                        trap_priv <= '1';
2208
                                                                                        trapmake <= '1';
2209
                                                                                END IF;
2210
                                                                        WHEN "1101000"|"1101001"|"1101010"|"1101011"|"1101100"|"1101101"|"1101110"|"1101111" =>         --move USP,An
2211
                                                                                IF SVmode='1' THEN
2212
--                                                                                      set(no_Flags) <= '1';
2213
                                                                                        set(from_USP) <= '1';
2214
                                                                                        datatype <= "10";
2215
                                                                                        set_exec(Regwrena) <= '1';
2216
                                                                                ELSE
2217
                                                                                        trap_priv <= '1';
2218
                                                                                        trapmake <= '1';
2219
                                                                                END IF;
2220
 
2221
                                                                        WHEN "1110000" =>                                       --reset
2222
                                                                                IF SVmode='0' THEN
2223
                                                                                        trap_priv <= '1';
2224
                                                                                        trapmake <= '1';
2225
                                                                                ELSE
2226
                                                                                        set(opcRESET) <= '1';
2227
                                                                                        IF decodeOPC='1' THEN
2228
                                                                                                set(ld_rot_cnt) <= '1';
2229
                                                                                                set_rot_cnt <= "000000";
2230
                                                                                        END IF;
2231
                                                                                END IF;
2232
 
2233
                                                                        WHEN "1110001" =>                                       --nop
2234
 
2235
                                                                        WHEN "1110010" =>                                       --stop
2236
                                                                                IF SVmode='0' THEN
2237
                                                                                        trap_priv <= '1';
2238
                                                                                        trapmake <= '1';
2239
                                                                                ELSE
2240
                                                                                        IF decodeOPC='1' THEN
2241
                                                                                                setnextpass <= '1';
2242
                                                                                                set_stop <= '1';
2243
                                                                                        END IF;
2244
                                                                                        IF stop='1' THEN
2245
                                                                                                skipFetch <= '1';
2246
                                                                                        END IF;
2247
 
2248
                                                                                END IF;
2249
 
2250
                                                                        WHEN "1110011"|"1110111" =>                                                                     --rte/rtr
2251
                                                                                IF SVmode='1' OR opcode(2)='1' THEN
2252
                                                                                        IF decodeOPC='1' THEN
2253
                                                                                                setstate <= "10";
2254
                                                                                                set(postadd) <= '1';
2255
                                                                                                setstackaddr <= '1';
2256
                                                                                                IF opcode(2)='1' THEN
2257
                                                                                                        set(directCCR) <= '1';
2258
                                                                                                ELSE
2259
                                                                                                        set(directSR) <= '1';
2260
                                                                                                END IF;
2261
                                                                                                next_micro_state <= rte1;
2262
                                                                                        END IF;
2263
                                                                                ELSE
2264
                                                                                        trap_priv <= '1';
2265
                                                                                        trapmake <= '1';
2266
                                                                                END IF;
2267
 
2268
                                                                        WHEN "1110100" =>                                                                       --rtd
2269
                                                                                datatype <= "10";
2270
                                                                                IF decodeOPC='1' THEN
2271
                                                                                        setstate <= "10";
2272
                                                                                        set(postadd) <= '1';
2273
                                                                                        setstackaddr <= '1';
2274
                                                                                        set(direct_delta) <= '1';
2275
                                                                                        set(directPC) <= '1';
2276
                                                                                        set_direct_data <= '1';
2277
                                                                                        next_micro_state <= rtd1;
2278
                                                                                END IF;
2279
 
2280
 
2281
                                                                        WHEN "1110101" =>                                                                       --rts
2282
                                                                                datatype <= "10";
2283
                                                                                IF decodeOPC='1' THEN
2284
                                                                                        setstate <= "10";
2285
                                                                                        set(postadd) <= '1';
2286
                                                                                        setstackaddr <= '1';
2287
                                                                                        set(direct_delta) <= '1';
2288
                                                                                        set(directPC) <= '1';
2289
                                                                                        next_micro_state <= nopnop;
2290
                                                                                END IF;
2291
 
2292
                                                                        WHEN "1110110" =>                                                                       --trapv
2293
                                                                                IF decodeOPC='1' THEN
2294
                                                                                        setstate <= "01";
2295
                                                                                END IF;
2296
                                                                                IF Flags(1)='1' AND state="01" THEN
2297
                                                                                        trap_trapv <= '1';
2298
                                                                                        trapmake <= '1';
2299
                                                                                END IF;
2300
 
2301
                                                                        WHEN "1111010"|"1111011" =>                                                                     --movec
2302 10 tobiflex
                                                                                IF cpu="00" THEN
2303 2 tobiflex
                                                                                        trap_illegal <= '1';
2304
                                                                                        trapmake <= '1';
2305
                                                                                ELSIF SVmode='0' THEN
2306
                                                                                        trap_priv <= '1';
2307
                                                                                        trapmake <= '1';
2308
                                                                                ELSE
2309
                                                                                        datatype <= "10";       --Long
2310
                                                                                        IF last_data_read(11 downto 0)=X"800" THEN
2311
                                                                                                set(from_USP) <= '1';
2312
                                                                                                IF opcode(0)='1' THEN
2313
                                                                                                        set(to_USP) <= '1';
2314
                                                                                                END IF;
2315
                                                                                        END IF;
2316
                                                                                        IF opcode(0)='0' THEN
2317
                                                                                                set_exec(movec_rd) <= '1';
2318
                                                                                        ELSE
2319
                                                                                                set_exec(movec_wr) <= '1';
2320
                                                                                        END IF;
2321
                                                                                        IF decodeOPC='1' THEN
2322
                                                                                                next_micro_state <= movec1;
2323
                                                                                                getbrief <='1';
2324
                                                                                        END IF;
2325
                                                                                END IF;
2326
 
2327
                                                                        WHEN OTHERS =>
2328
                                                                                trap_illegal <= '1';
2329
                                                                                trapmake <= '1';
2330
                                                                END CASE;
2331
                                                        END IF;
2332
                                                WHEN OTHERS => NULL;
2333
                                        END CASE;
2334
                                END IF;
2335
--                                      
2336
---- 0101 ----------------------------------------------------------------------------          
2337
                        WHEN "0101" =>                                                          --subq, addq    
2338
                                        IF opcode(7 downto 6)="11" THEN --dbcc
2339
                                                IF opcode(5 downto 3)="001" THEN --dbcc
2340
                                                        IF decodeOPC='1' THEN
2341
                                                                next_micro_state <= dbcc1;
2342
                                                                set(OP2out_one) <= '1';
2343
                                                                data_is_source <= '1';
2344 10 tobiflex
                                                        END IF;
2345
                                                ELSIF opcode(5 downto 3)="111" AND (opcode(2 downto 1)="01" OR opcode(2 downto 0)="100") THEN    --trapcc
2346
                                                        IF cpu(1)='1' THEN                                                      -- only 68020+
2347
                                                                IF opcode(2 downto 1)="01" THEN
2348
                                                                        IF decodeOPC='1' THEN
2349
                                                                                IF opcode(0)='1' THEN                    --long
2350
                                                                                        set(longaktion) <= '1';
2351
                                                                                END IF;
2352
                                                                                next_micro_state <= nop;
2353
                                                                        END IF;
2354
                                                                ELSE
2355
                                                                        IF decodeOPC='1' THEN
2356
                                                                                setstate <= "01";
2357
                                                                        END IF;
2358
                                                                END IF;
2359
                                                                trap_trapcc<='1';
2360
                                                                IF exe_condition='1' AND decodeOPC='0' THEN
2361
                                                                        trap_trapv <= '1';
2362
                                                                        trapmake <= '1';
2363
                                                                END IF;
2364
                                                        ELSE
2365
                                                                trap_illegal <= '1';
2366
                                                                trapmake <= '1';
2367
                                                        END IF;
2368 2 tobiflex
                                                ELSE                            --Scc
2369
                                                        datatype <= "00";                       --Byte
2370
                                                        ea_build_now <= '1';
2371
                                                        write_back <= '1';
2372
                                                        set_exec(opcScc) <= '1';
2373
                                                        IF cpu(0)='1' AND state="10" THEN
2374
                                                                skipFetch <= '1';
2375
                                                        END IF;
2376
                                                        IF opcode(5 downto 4)="00" THEN
2377
                                                                set_exec(Regwrena) <= '1';
2378
                                                        END IF;
2379
                                                END IF;
2380
                                        ELSE                                    --addq, subq
2381
                                                ea_build_now <= '1';
2382
                                                IF opcode(5 downto 3)="001" THEN
2383
                                                        set(no_Flags) <= '1';
2384
                                                END IF;
2385
                                                IF opcode(8)='1' THEN
2386
                                                        set(addsub) <= '1';
2387
                                                END IF;
2388
                                                write_back <= '1';
2389
                                                set_exec(opcADDQ) <= '1';
2390
                                                set_exec(opcADD) <= '1';
2391
                                                set_exec(ea_data_OP1) <= '1';
2392
                                                IF opcode(5 downto 4)="00" THEN
2393
                                                        set_exec(Regwrena) <= '1';
2394
                                                END IF;
2395
                                        END IF;
2396
--                              
2397
---- 0110 ----------------------------------------------------------------------------          
2398
                        WHEN "0110" =>                          --bra,bsr,bcc
2399
                                datatype <= "10";
2400
 
2401
                                IF micro_state=idle THEN
2402
                                        IF opcode(11 downto 8)="0001" THEN              --bsr
2403
                                                set(presub) <= '1';
2404
                                                setstackaddr <='1';
2405
                                                IF opcode(7 downto 0)="11111111" THEN
2406
                                                        next_micro_state <= bsr2;
2407
                                                        set(longaktion) <= '1';
2408
                                                ELSIF opcode(7 downto 0)="00000000" THEN
2409
                                                        next_micro_state <= bsr2;
2410
                                                ELSE
2411
                                                        next_micro_state <= bsr1;
2412
                                                        setstate <= "11";
2413
                                                        writePC <= '1';
2414
                                                END IF;
2415
                                        ELSE                                                                    --bra
2416
                                                IF opcode(7 downto 0)="11111111" THEN
2417
                                                        next_micro_state <= bra1;
2418
                                                        set(longaktion) <= '1';
2419
                                                ELSIF opcode(7 downto 0)="00000000" THEN
2420
                                                        next_micro_state <= bra1;
2421
                                                ELSE
2422
                                                        setstate <= "01";
2423
                                                        next_micro_state <= bra1;
2424
                                                END IF;
2425
                                        END IF;
2426
                                END IF;
2427
 
2428
-- 0111 ----------------------------------------------------------------------------            
2429
                        WHEN "0111" =>                          --moveq
2430
                                        datatype <= "10";               --Long
2431
                                        set_exec(Regwrena) <= '1';
2432
                                        set_exec(opcMOVEQ) <= '1';
2433
                                        set_exec(opcMOVE) <= '1';
2434
                                        dest_hbits <= '1';
2435
 
2436
---- 1000 ----------------------------------------------------------------------------          
2437
                        WHEN "1000" =>                                                          --or    
2438
                                IF opcode(7 downto 6)="11" THEN --divu, divs
2439
                                        IF DIV_Mode/=3 THEN
2440
                                                IF opcode(5 downto 4)="00" THEN --Dn, An
2441
                                                        regdirectsource <= '1';
2442
                                                END IF;
2443
                                                IF (micro_state=idle AND nextpass='1') OR (opcode(5 downto 4)="00" AND decodeOPC='1') THEN
2444
                                                        setstate <="01";
2445
                                                        next_micro_state <= div1;
2446
                                                END IF;
2447
                                                ea_build_now <= '1';
2448
                                                IF z_error='0' AND set_V_Flag='0' THEN
2449
                                                        set_exec(Regwrena) <= '1';
2450
                                                END IF;
2451
                                                        source_lowbits <='1';
2452
                                                IF nextpass='1' OR (opcode(5 downto 4)="00" AND decodeOPC='1') THEN
2453
                                                        dest_hbits <= '1';
2454
                                                END IF;
2455
                                                datatype <= "01";
2456
                                        ELSE
2457
                                                trap_illegal <= '1';
2458
                                                trapmake <= '1';
2459
                                        END IF;
2460
 
2461
                                ELSIF opcode(8)='1' AND opcode(5 downto 4)="00" THEN    --sbcd, pack , unpack
2462
                                        IF opcode(7 downto 6)="00" THEN --sbcd
2463
                                                build_bcd <= '1';
2464
                                                set_exec(opcADD) <= '1';
2465
                                                set_exec(opcSBCD) <= '1';
2466
                                                set(addsub) <= '1';
2467
                                        ELSIF opcode(7 downto 6)="01" OR opcode(7 downto 6)="10" THEN   --pack , unpack
2468
                                                set_exec(ea_data_OP1) <= '1';
2469
                                                set(no_Flags) <= '1';
2470
                                                source_lowbits <='1';
2471
                                                IF opcode(7 downto 6) = "01" THEN       --pack
2472
                                                        set_exec(opcPACK) <= '1';
2473
                                                        datatype <= "01";                               --Word
2474
                                                ELSE                                                            --unpk
2475
                                                        set_exec(opcUNPACK) <= '1';
2476
                                                        datatype <= "00";                               --Byte
2477
                                                END IF;
2478
                                                IF opcode(3)='0' THEN
2479
                                                        IF opcode(7 downto 6) = "01" THEN       --pack
2480
                                                                set_datatype <= "00";           --Byte
2481
                                                        ELSE                                                            --unpk
2482
                                                                set_datatype <= "01";           --Word
2483
                                                        END IF;
2484
                                                        set_exec(Regwrena) <= '1';
2485
                                                        dest_hbits <= '1';
2486
                                                        IF decodeOPC='1' THEN
2487
                                                                next_micro_state <= nop;
2488
--                                                              set_direct_data <= '1';
2489
                                                                set(store_ea_packdata) <= '1';
2490
                                                                set(store_ea_data) <= '1';
2491
                                                        END IF;
2492
                                                ELSE                            -- pack -(Ax),-(Ay)
2493
                                                        write_back <= '1';
2494
                                                        IF decodeOPC='1' THEN
2495
                                                                next_micro_state <= pack1;
2496
                                                                set_direct_data <= '1';
2497
                                                        END IF;
2498
                                                END IF;
2499
                                        ELSE
2500
                                                trap_illegal <= '1';
2501
                                                trapmake <= '1';
2502
                                        END IF;
2503
                                ELSE                                                                    --or
2504
                                        set_exec(opcOR) <= '1';
2505
                                        build_logical <= '1';
2506
                                END IF;
2507
 
2508
---- 1001, 1101 -----------------------------------------------------------------------         
2509
                        WHEN "1001"|"1101" =>                                           --sub, add      
2510
                                set_exec(opcADD) <= '1';
2511
                                ea_build_now <= '1';
2512
                                IF opcode(14)='0' THEN
2513
                                        set(addsub) <= '1';
2514
                                END IF;
2515
                                IF opcode(7 downto 6)="11" THEN --      --adda, suba
2516
                                        IF opcode(8)='0' THEN    --adda.w, suba.w
2517
                                                datatype <= "01";       --Word
2518
                                        END IF;
2519
                                        set_exec(Regwrena) <= '1';
2520
                                        source_lowbits <='1';
2521
                                        IF opcode(3)='1' THEN
2522
                                                source_areg <= '1';
2523
                                        END IF;
2524
                                        set(no_Flags) <= '1';
2525
                                        IF setexecOPC='1' THEN
2526
                                                dest_areg <='1';
2527
                                                dest_hbits <= '1';
2528
                                        END IF;
2529
                                ELSE
2530
                                        IF opcode(8)='1' AND opcode(5 downto 4)="00" THEN               --addx, subx
2531
                                                build_bcd <= '1';
2532
                                        ELSE                                                    --sub, add
2533
                                                build_logical <= '1';
2534
                                        END IF;
2535
                                END IF;
2536
 
2537
--                              
2538
---- 1010 ----------------------------------------------------------------------------          
2539
                        WHEN "1010" =>                                                  --Trap 1010
2540
                                trap_1010 <= '1';
2541
                                trapmake <= '1';
2542
---- 1011 ----------------------------------------------------------------------------          
2543
                        WHEN "1011" =>                                                  --eor, cmp
2544
                                ea_build_now <= '1';
2545
                                IF opcode(7 downto 6)="11" THEN --CMPA
2546
                                        IF opcode(8)='0' THEN    --cmpa.w
2547
                                                datatype <= "01";       --Word
2548
                                                set_exec(opcCPMAW) <= '1';
2549
                                        END IF;
2550
                                        set_exec(opcCMP) <= '1';
2551
                                        IF setexecOPC='1' THEN
2552
                                                source_lowbits <='1';
2553
                                                IF opcode(3)='1' THEN
2554
                                                        source_areg <= '1';
2555
                                                END IF;
2556
                                                dest_areg <='1';
2557
                                                dest_hbits <= '1';
2558
                                        END IF;
2559
                                        set(addsub) <= '1';
2560
                                ELSE
2561
                                        IF opcode(8)='1' THEN
2562
                                                IF opcode(5 downto 3)="001" THEN                --cmpm
2563
                                                        set_exec(opcCMP) <= '1';
2564
                                                        IF decodeOPC='1' THEN
2565
                                                                IF opcode(2 downto 0)="111" THEN
2566
                                                                        set(use_SP) <= '1';
2567
                                                                END IF;
2568
                                                                setstate <= "10";
2569
                                                                set(update_ld) <= '1';
2570
                                                                set(postadd) <= '1';
2571
                                                                next_micro_state <= cmpm;
2572
                                                        END IF;
2573
                                                        set_exec(ea_data_OP1) <= '1';
2574
                                                        set(addsub) <= '1';
2575
                                                ELSE                                            --EOR
2576
                                                        build_logical <= '1';
2577
                                                        set_exec(opcEOR) <= '1';
2578
                                                END IF;
2579
                                        ELSE                                                    --CMP
2580
                                                build_logical <= '1';
2581
                                                set_exec(opcCMP) <= '1';
2582
                                                set(addsub) <= '1';
2583
                                        END IF;
2584
                                END IF;
2585
--                              
2586
---- 1100 ----------------------------------------------------------------------------          
2587
                        WHEN "1100" =>                                                          --and, exg
2588
                                IF opcode(7 downto 6)="11" THEN --mulu, muls
2589
                                        IF MUL_Mode/=3 THEN
2590
                                                IF opcode(5 downto 4)="00" THEN --Dn, An
2591
                                                        regdirectsource <= '1';
2592
                                                END IF;
2593
                                                IF (micro_state=idle AND nextpass='1') OR (opcode(5 downto 4)="00" AND decodeOPC='1') THEN
2594
                                                        IF MUL_Hardware=0 THEN
2595
                                                                setstate <="01";
2596
                                                                set(ld_rot_cnt) <= '1';
2597
                                                                next_micro_state <= mul1;
2598
                                                        ELSE
2599
                                                                set_exec(write_lowlong) <= '1';
2600
                                                                set_exec(opcMULU) <= '1';
2601
                                                        END IF;
2602
                                                END IF;
2603
                                                ea_build_now <= '1';
2604
                                                set_exec(Regwrena) <= '1';
2605
                                                source_lowbits <='1';
2606
                                                IF (nextpass='1') OR (opcode(5 downto 4)="00" AND decodeOPC='1') THEN
2607
                                                        dest_hbits <= '1';
2608
                                                END IF;
2609
                                                datatype <= "01";
2610
                                                IF setexecOPC='1' THEN
2611
                                                        datatype <= "10";
2612
                                                END IF;
2613
 
2614
                                        ELSE
2615
                                                trap_illegal <= '1';
2616
                                                trapmake <= '1';
2617
                                        END IF;
2618
 
2619
                                ELSIF opcode(8)='1' AND opcode(5 downto 4)="00" THEN    --exg, abcd
2620
                                        IF opcode(7 downto 6)="00" THEN --abcd
2621
                                                build_bcd <= '1';
2622
                                                set_exec(opcADD) <= '1';
2623
                                                set_exec(opcABCD) <= '1';
2624
                                        ELSE                                                                    --exg
2625
                                                datatype <= "10";
2626
                                                set(Regwrena) <= '1';
2627
                                                set(exg) <= '1';
2628
                                                IF opcode(6)='1' AND opcode(3)='1' THEN
2629
                                                        dest_areg <= '1';
2630
                                                        source_areg <= '1';
2631
                                                END IF;
2632
                                                IF decodeOPC='1' THEN
2633
                                                        setstate <= "01";
2634
                                                ELSE
2635
                                                        dest_hbits <= '1';
2636
                                                END IF;
2637
                                        END IF;
2638
                                ELSE                                                                    --and
2639
                                        set_exec(opcAND) <= '1';
2640
                                        build_logical <= '1';
2641
                                END IF;
2642
--                              
2643
---- 1110 ----------------------------------------------------------------------------          
2644
                        WHEN "1110" =>                                                          --rotation / bitfield
2645
                                IF opcode(7 downto 6)="11" THEN
2646
                                        IF opcode(11)='0' THEN
2647
                                                IF BarrelShifter=0 THEN
2648
                                                        set_exec(opcROT) <= '1';
2649
                                                ELSE
2650
                                                        set_exec(exec_BS) <='1';
2651
                                                END IF;
2652
                                                ea_build_now <= '1';
2653
                                                datatype <= "01";
2654
                                                set_rot_bits <= opcode(10 downto 9);
2655
                                                set_exec(ea_data_OP1) <= '1';
2656
                                                write_back <= '1';
2657
                                        ELSE            --bitfield
2658
                                                IF BitField=0 OR (cpu(1)='0' AND BitField=2) THEN
2659
                                                        trap_illegal <= '1';
2660
                                                        trapmake <= '1';
2661
                                                ELSE
2662
                                                        IF decodeOPC='1' THEN
2663
                                                                next_micro_state <= nop;
2664
                                                                set(get_2ndOPC) <= '1';
2665
                                                                set(ea_build) <= '1';
2666
                                                        END IF;
2667
                                                        set_exec(opcBF) <= '1';
2668
--              000-bftst, 001-bfextu, 010-bfchg, 011-bfexts, 100-bfclr, 101-bfff0, 110-bfset, 111-bfins                                                                
2669
                                                        IF opcode(10)='1' OR opcode(8)='0' THEN
2670
                                                                set_exec(opcBFwb) <= '1';                       --'1' for tst,chg,clr,ffo,set,ins    --'0' for extu,exts
2671
                                                        END IF;
2672
                                                        IF opcode(10 downto 8)="111" THEN       --BFINS
2673
                                                                set_exec(ea_data_OP1) <= '1';
2674
                                                        END IF;
2675
 
2676
                                                        IF opcode(10 downto 8)="010" OR opcode(10 downto 8)="100" OR opcode(10 downto 8)="110" OR opcode(10 downto 8)="111" THEN
2677
                                                                write_back <= '1';
2678
                                                        END IF;
2679
                                                        ea_only <= '1';
2680
                                                        IF opcode(10 downto 8)="001" OR opcode(10 downto 8)="011" OR opcode(10 downto 8)="101" THEN
2681
                                                                set_exec(Regwrena) <= '1';
2682
                                                        END IF;
2683
                                                        IF opcode(4 downto 3)="00" THEN
2684
                                                                IF opcode(10 downto 8)/="000" THEN
2685
                                                                        set_exec(Regwrena) <= '1';
2686
                                                                END IF;
2687
                                                                IF exec(ea_build)='1' THEN
2688
                                                                        dest_2ndHbits <= '1';
2689
                                                                        source_2ndLbits <= '1';
2690
                                                                        set(get_bfoffset) <='1';
2691
                                                                        setstate <= "01";
2692
                                                                END IF;
2693
                                                        END IF;
2694
                                                        IF set(get_ea_now)='1' THEN
2695
                                                                setstate <= "01";
2696
                                                        END IF;
2697
                                                        IF exec(get_ea_now)='1' THEN
2698
                                                                dest_2ndHbits <= '1';
2699
                                                                source_2ndLbits <= '1';
2700
                                                                set(get_bfoffset) <='1';
2701
                                                                setstate <= "01";
2702
                                                                set(mem_addsub) <='1';
2703
                                                                next_micro_state <= bf1;
2704
                                                        END IF;
2705
 
2706
                                                        IF setexecOPC='1' THEN
2707
                                                                IF opcode(10 downto 8)="111" THEN       --BFINS
2708
                                                                        source_2ndHbits <= '1';
2709
                                                                ELSE
2710
                                                                        source_lowbits <= '1';
2711
                                                                END IF;
2712
                                                                IF opcode(10 downto 8)="001" OR opcode(10 downto 8)="011" OR opcode(10 downto 8)="101" THEN     --BFEXT, BFFFO
2713
                                                                        dest_2ndHbits <= '1';
2714
                                                                END IF;
2715
                                                        END IF;
2716
                                                END IF;
2717
                                        END IF;
2718
                                ELSE
2719
                                        data_is_source <= '1';
2720
                                        IF BarrelShifter=0 OR (cpu(1)='0' AND BarrelShifter=2) THEN
2721
 
2722
                                                set_exec(opcROT) <= '1';
2723
                                                set_rot_bits <= opcode(4 downto 3);
2724
                                                set_exec(Regwrena) <= '1';
2725
                                                IF decodeOPC='1' THEN
2726
                                                        IF opcode(5)='1' THEN
2727
                                                                next_micro_state <= rota1;
2728
                                                                set(ld_rot_cnt) <= '1';
2729
                                                                setstate <= "01";
2730
                                                        ELSE
2731
                                                                set_rot_cnt(2 downto 0) <= opcode(11 downto 9);
2732
                                                                IF opcode(11 downto 9)="000" THEN
2733
                                                                        set_rot_cnt(3) <='1';
2734
                                                                ELSE
2735
                                                                        set_rot_cnt(3) <='0';
2736
                                                                END IF;
2737
                                                        END IF;
2738
                                                END IF;
2739
                                        ELSE
2740
                                                set_exec(exec_BS) <='1';
2741
                                                set_rot_bits <= opcode(4 downto 3);
2742
                                                set_exec(Regwrena) <= '1';
2743
                                        END IF;
2744
                                END IF;
2745
--                                                      
2746
----      ----------------------------------------------------------------------------          
2747
                        WHEN OTHERS =>
2748
                                trap_1111 <= '1';
2749
                                trapmake <= '1';
2750
 
2751
                END CASE;
2752
 
2753
-- use for AND, OR, EOR, CMP
2754
                IF build_logical='1' THEN
2755
                        ea_build_now <= '1';
2756
                        IF set_exec(opcCMP)='0' AND (opcode(8)='0' OR opcode(5 downto 4)="00" ) THEN
2757
                                set_exec(Regwrena) <= '1';
2758
                        END IF;
2759
                        IF opcode(8)='1' THEN
2760
                                write_back <= '1';
2761
                                set_exec(ea_data_OP1) <= '1';
2762
                        ELSE
2763
                                source_lowbits <='1';
2764
                                IF opcode(3)='1' THEN           --use for cmp
2765
                                        source_areg <= '1';
2766
                                END IF;
2767
                                IF setexecOPC='1' THEN
2768
                                        dest_hbits <= '1';
2769
                                END IF;
2770
                        END IF;
2771
                END IF;
2772
 
2773
-- use for ABCD, SBCD
2774
                IF build_bcd='1' THEN
2775
                        set_exec(use_XZFlag) <= '1';
2776
                        set_exec(ea_data_OP1) <= '1';
2777
                        write_back <= '1';
2778
                        source_lowbits <='1';
2779
                        IF opcode(3)='1' THEN
2780
                                IF decodeOPC='1' THEN
2781
                                        IF opcode(2 downto 0)="111" THEN
2782
                                                set(use_SP) <= '1';
2783
                                        END IF;
2784
                                        setstate <= "10";
2785
                                        set(update_ld) <= '1';
2786
                                        set(presub) <= '1';
2787
                                        next_micro_state <= op_AxAy;
2788
                                        dest_areg <= '1';                               --???
2789
                                END IF;
2790
                        ELSE
2791
                                dest_hbits <= '1';
2792
                                set_exec(Regwrena) <= '1';
2793
                        END IF;
2794
                END IF;
2795
 
2796
 
2797
------------------------------------------------------------------------------          
2798
------------------------------------------------------------------------------          
2799
                IF set_Z_error='1'  THEN                -- divu by zero
2800
                        trapmake <= '1';                        --wichtig for USP
2801
                        IF trapd='0' THEN
2802
                                writePC <= '1';
2803
                        END IF;
2804
                END IF;
2805
 
2806
-----------------------------------------------------------------------------
2807
-- execute microcode
2808
-----------------------------------------------------------------------------
2809
                IF rising_edge(clk) THEN
2810
                IF Reset='1' THEN
2811
                                micro_state <= ld_nn;
2812
                        ELSIF clkena_lw='1' THEN
2813
                                trapd <= trapmake;
2814
                                micro_state <= next_micro_state;
2815
                        END IF;
2816
                END IF;
2817
 
2818
                        CASE micro_state IS
2819
                                WHEN ld_nn =>           -- (nnnn).w/l=>
2820
                                        set(get_ea_now) <='1';
2821
                                        setnextpass <= '1';
2822
                                        set(addrlong) <= '1';
2823
 
2824
                                WHEN st_nn =>           -- =>(nnnn).w/l
2825
                                        setstate <= "11";
2826
                                        set(addrlong) <= '1';
2827
                                        next_micro_state <= nop;
2828
 
2829
                                WHEN ld_dAn1 =>         -- d(An)=>, --d(PC)=>
2830
                                        set(get_ea_now) <='1';
2831
                                        setdisp <= '1';         --word
2832
                                        setnextpass <= '1';
2833
 
2834
                                WHEN ld_AnXn1 =>                -- d(An,Xn)=>, --d(PC,Xn)=>
2835
                                        IF brief(8)='0' OR extAddr_Mode=0 OR (cpu(1)='0' AND extAddr_Mode=2) THEN
2836
                                                setdisp <= '1';         --byte  
2837
                                                setdispbyte <= '1';
2838
                                                setstate <= "01";
2839
                                                set(briefext) <= '1';
2840
                                                next_micro_state <= ld_AnXn2;
2841
                                        ELSE
2842
                                                IF brief(7)='1'THEN             --suppress Base
2843
                                                        set_suppress_base <= '1';
2844
                                                ELSIF exec(dispouter)='1' THEN
2845
                                                        set(dispouter) <= '1';
2846
                                                END IF;
2847
                                                IF brief(5)='0' THEN --NULL Base Displacement
2848
                                                        setstate <= "01";
2849
                                                ELSE  --WORD Base Displacement
2850
                                                        IF brief(4)='1' THEN
2851
                                                                set(longaktion) <= '1'; --LONG Base Displacement
2852
                                                        END IF;
2853
                                                END IF;
2854
                                                next_micro_state <= ld_229_1;
2855
                                        END IF;
2856
 
2857
                                WHEN ld_AnXn2 =>
2858
                                        set(get_ea_now) <='1';
2859
                                        setdisp <= '1';         --brief
2860
                                        setnextpass <= '1';
2861
 
2862
-------------------------------------------------------------------------------------                                   
2863
 
2864
                                WHEN ld_229_1 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2865
                                        IF brief(5)='1' THEN    --Base Displacement
2866
                                                setdisp <= '1';         --add last_data_read
2867
                                        END IF;
2868
                                        IF brief(6)='0' AND brief(2)='0' THEN --Preindex or Index
2869
                                                set(briefext) <= '1';
2870
                                                setstate <= "01";
2871
                                                IF brief(1 downto 0)="00" THEN
2872
                                                        next_micro_state <= ld_AnXn2;
2873
                                                ELSE
2874
                                                        next_micro_state <= ld_229_2;
2875
                                                END IF;
2876
                                        ELSE
2877
                                                IF brief(1 downto 0)="00" THEN
2878
                                                        set(get_ea_now) <='1';
2879
                                                        setnextpass <= '1';
2880
                                                ELSE
2881
                                                        setstate <= "10";
2882
                                                        set(longaktion) <= '1';
2883
                                                        next_micro_state <= ld_229_3;
2884
                                                END IF;
2885
                                        END IF;
2886
 
2887
                                WHEN ld_229_2 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2888
                                        setdisp <= '1';         -- add Index
2889
                                        setstate <= "10";
2890
                                        set(longaktion) <= '1';
2891
                                        next_micro_state <= ld_229_3;
2892
 
2893
                                WHEN ld_229_3 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2894
                                        set_suppress_base <= '1';
2895
                                        set(dispouter) <= '1';
2896
                                        IF brief(1)='0' THEN --NULL Outer Displacement
2897
                                                setstate <= "01";
2898
                                        ELSE  --WORD Outer Displacement
2899
                                                IF brief(0)='1' THEN
2900
                                                        set(longaktion) <= '1'; --LONG Outer Displacement
2901
                                                END IF;
2902
                                        END IF;
2903
                                        next_micro_state <= ld_229_4;
2904
 
2905
                                WHEN ld_229_4 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2906
                                        IF brief(1)='1' THEN  -- Outer Displacement
2907
                                                setdisp <= '1';   --add last_data_read
2908
                                        END IF;
2909
                                        IF brief(6)='0' AND brief(2)='1' THEN --Postindex
2910
                                                set(briefext) <= '1';
2911
                                                setstate <= "01";
2912
                                                next_micro_state <= ld_AnXn2;
2913
                                        ELSE
2914
                                                set(get_ea_now) <='1';
2915
                                                setnextpass <= '1';
2916
                                        END IF;
2917
 
2918
----------------------------------------------------------------------------------------                                
2919
                                WHEN st_dAn1 =>         -- =>d(An)
2920
                                        setstate <= "11";
2921
                                        setdisp <= '1';         --word
2922
                                        next_micro_state <= nop;
2923
 
2924
                                WHEN st_AnXn1 =>                -- =>d(An,Xn)
2925
                                        IF brief(8)='0' OR extAddr_Mode=0 OR (cpu(1)='0' AND extAddr_Mode=2) THEN
2926
                                                setdisp <= '1';         --byte  
2927
                                                setdispbyte <= '1';
2928
                                                setstate <= "01";
2929
                                                set(briefext) <= '1';
2930
                                                next_micro_state <= st_AnXn2;
2931
                                        ELSE
2932
                                                IF brief(7)='1'THEN             --suppress Base
2933
                                                        set_suppress_base <= '1';
2934
--                                              ELSIF exec(dispouter)='1' THEN
2935
--                                                      set(dispouter) <= '1';
2936
                                                END IF;
2937
                                                IF brief(5)='0' THEN --NULL Base Displacement
2938
                                                        setstate <= "01";
2939
                                                ELSE  --WORD Base Displacement
2940
                                                        IF brief(4)='1' THEN
2941
                                                                set(longaktion) <= '1'; --LONG Base Displacement
2942
                                                        END IF;
2943
                                                END IF;
2944
                                                next_micro_state <= st_229_1;
2945
                                        END IF;
2946
 
2947
                                WHEN st_AnXn2 =>
2948
                                        setstate <= "11";
2949
                                        setdisp <= '1';         --brief 
2950
                                        next_micro_state <= nop;
2951
 
2952
-------------------------------------------------------------------------------------                                   
2953
 
2954
                                WHEN st_229_1 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2955
                                        IF brief(5)='1' THEN    --Base Displacement
2956
                                                setdisp <= '1';         --add last_data_read
2957
                                        END IF;
2958
                                        IF brief(6)='0' AND brief(2)='0' THEN --Preindex or Index
2959
                                                set(briefext) <= '1';
2960
                                                setstate <= "01";
2961
                                                IF brief(1 downto 0)="00" THEN
2962
                                                        next_micro_state <= st_AnXn2;
2963
                                                ELSE
2964
                                                        next_micro_state <= st_229_2;
2965
                                                END IF;
2966
                                        ELSE
2967
                                                IF brief(1 downto 0)="00" THEN
2968
                                                        setstate <= "11";
2969
                                                        next_micro_state <= nop;
2970
                                                ELSE
2971
                                                        set(hold_dwr) <= '1';
2972
                                                        setstate <= "10";
2973
                                                        set(longaktion) <= '1';
2974
                                                        next_micro_state <= st_229_3;
2975
                                                END IF;
2976
                                        END IF;
2977
 
2978
                                WHEN st_229_2 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2979
                                        setdisp <= '1';         -- add Index
2980
                                        set(hold_dwr) <= '1';
2981
                                        setstate <= "10";
2982
                                        set(longaktion) <= '1';
2983
                                        next_micro_state <= st_229_3;
2984
 
2985
                                WHEN st_229_3 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2986
                                        set(hold_dwr) <= '1';
2987
                                        set_suppress_base <= '1';
2988
                                        set(dispouter) <= '1';
2989
                                        IF brief(1)='0' THEN --NULL Outer Displacement
2990
                                                setstate <= "01";
2991
                                        ELSE  --WORD Outer Displacement
2992
                                                IF brief(0)='1' THEN
2993
                                                        set(longaktion) <= '1'; --LONG Outer Displacement
2994
                                                END IF;
2995
                                        END IF;
2996
                                        next_micro_state <= st_229_4;
2997
 
2998
                                WHEN st_229_4 =>                -- (bd,An,Xn)=>, --(bd,PC,Xn)=>
2999
                                        set(hold_dwr) <= '1';
3000
                                        IF brief(1)='1' THEN  -- Outer Displacement
3001
                                                setdisp <= '1';   --add last_data_read
3002
                                        END IF;
3003
                                        IF brief(6)='0' AND brief(2)='1' THEN --Postindex
3004
                                                set(briefext) <= '1';
3005
                                                setstate <= "01";
3006
                                                next_micro_state <= st_AnXn2;
3007
                                        ELSE
3008
                                                setstate <= "11";
3009
                                                next_micro_state <= nop;
3010
                                        END IF;
3011
 
3012
----------------------------------------------------------------------------------------                                
3013
                                WHEN bra1 =>            --bra
3014
                                        IF exe_condition='1' THEN
3015
                                                TG68_PC_brw <= '1';     --pc+0000
3016
                                                next_micro_state <= nop;
3017
                                                skipFetch <= '1';
3018
                                        END IF;
3019
 
3020
                                WHEN bsr1 =>            --bsr short
3021
                                        TG68_PC_brw <= '1';
3022
                                        next_micro_state <= nop;
3023
 
3024
                                WHEN bsr2 =>            --bsr
3025
                                        IF long_start='0' THEN
3026
                                                TG68_PC_brw <= '1';
3027
                                        END IF;
3028
                                        skipFetch <= '1';
3029
                                        set(longaktion) <= '1';
3030
                                        writePC <= '1';
3031
                                        setstate <= "11";
3032
                                        next_micro_state <= nopnop;
3033
                                        setstackaddr <='1';
3034
                                WHEN nopnop =>          --bsr
3035
                                        next_micro_state <= nop;
3036
 
3037
                                WHEN dbcc1 =>           --dbcc
3038
                                        IF exe_condition='0' THEN
3039
                                                Regwrena_now <= '1';
3040
                                                IF c_out(1)='1' THEN
3041
                                                        skipFetch <= '1';
3042
                                                        next_micro_state <= nop;
3043
                                                        TG68_PC_brw <= '1';
3044
                                                END IF;
3045
                                        END IF;
3046
 
3047
                                WHEN movem1 =>          --movem
3048
                                        IF last_data_read(15 downto 0)/=X"0000" THEN
3049
                                                setstate <="01";
3050
                                                IF opcode(5 downto 3)="100" THEN
3051 10 tobiflex
                                                        set(mem_addsub) <= '1';
3052
                                                        IF cpu(1)='1' THEN
3053
                                                                set(Regwrena) <= '1';   --tg
3054
                                                        END IF;
3055 2 tobiflex
                                                END IF;
3056
                                                next_micro_state <= movem2;
3057
                                        END IF;
3058
                                WHEN movem2 =>          --movem
3059
                                        IF movem_run='0' THEN
3060
                                                setstate <="01";
3061
                                        ELSE
3062
                                                set(movem_action) <= '1';
3063
                                                set(mem_addsub) <= '1';
3064
                                                next_micro_state <= movem2;
3065
                                                IF opcode(10)='0' THEN
3066
                                                        setstate <="11";
3067
                                                        set(write_reg) <= '1';
3068
                                                ELSE
3069
                                                        setstate <="10";
3070
                                                END IF;
3071
                                        END IF;
3072
 
3073
                                WHEN andi =>            --andi
3074
                                        IF opcode(5 downto 4)/="00" THEN
3075
                                                setnextpass <= '1';
3076
                                        END IF;
3077
 
3078
                                WHEN pack1 =>           -- pack -(Ax),-(Ay)
3079 6 tobiflex
                                        IF opcode(2 downto 0)="111" THEN
3080
                                                set(use_SP) <= '1';
3081
                                        END IF;
3082 2 tobiflex
                                        set(hold_ea_data) <= '1';
3083
                                        set(update_ld) <= '1';
3084
                                        setstate <= "10";
3085
                                        set(presub) <= '1';
3086
                                        next_micro_state <= pack2;
3087
                                        dest_areg <= '1';
3088
                                WHEN pack2 =>
3089 6 tobiflex
                                        IF opcode(11 downto 9)="111" THEN
3090
                                                set(use_SP) <= '1';
3091
                                        END IF;
3092 2 tobiflex
                                        set(hold_ea_data) <= '1';
3093
                                        set_direct_data <= '1';
3094
                                        IF opcode(7 downto 6) = "01" THEN       --pack
3095
                                                datatype <= "00";               --Byte
3096
                                        ELSE                                                            --unpk
3097
                                                datatype <= "01";               --Word
3098
                                        END IF;
3099
                                        set(presub) <= '1';
3100
                                        dest_hbits <= '1';
3101
                                        dest_areg <= '1';
3102
                                        setstate <= "10";
3103
                                        next_micro_state <= pack3;
3104
                                WHEN pack3 =>
3105
                                        skipFetch <= '1';
3106
 
3107
                                WHEN op_AxAy =>         -- op -(Ax),-(Ay)
3108
                                        IF opcode(11 downto 9)="111" THEN
3109
                                                set(use_SP) <= '1';
3110
                                        END IF;
3111
                                        set_direct_data <= '1';
3112
                                        set(presub) <= '1';
3113
                                        dest_hbits <= '1';
3114
                                        dest_areg <= '1';
3115
                                        setstate <= "10";
3116
 
3117
                                WHEN cmpm =>            -- cmpm (Ay)+,(Ax)+
3118
                                        IF opcode(11 downto 9)="111" THEN
3119
                                                set(use_SP) <= '1';
3120
                                        END IF;
3121
                                        set_direct_data <= '1';
3122
                                        set(postadd) <= '1';
3123
                                        dest_hbits <= '1';
3124
                                        dest_areg <= '1';
3125
                                        setstate <= "10";
3126
 
3127
                                WHEN link1 =>           -- link
3128
                                        setstate <="11";
3129
                                        source_areg <= '1';
3130
                                        set(opcMOVE) <= '1';
3131
                                        set(Regwrena) <= '1';
3132
                                        next_micro_state <= link2;
3133
                                WHEN link2 =>           -- link
3134
                                        setstackaddr <='1';
3135
                                        set(ea_data_OP2) <= '1';
3136
 
3137
                                WHEN unlink1 =>         -- unlink
3138
                                        setstate <="10";
3139
                                        setstackaddr <='1';
3140
                                        set(postadd) <= '1';
3141
                                        next_micro_state <= unlink2;
3142
                                WHEN unlink2 =>         -- unlink
3143 10 tobiflex
                                        set(ea_data_OP2) <= '1';
3144 2 tobiflex
 
3145 8 tobiflex
-- paste and copy form TH       ---------       
3146 10 tobiflex
                                WHEN trap00 =>          -- TRAP format #2
3147 8 tobiflex
                                        next_micro_state <= trap0;
3148
                                        set(presub) <= '1';
3149
                                        setstackaddr <='1';
3150
                                        setstate <= "11";
3151
                                        datatype <= "10";
3152
------------------------------------
3153 2 tobiflex
                                WHEN trap0 =>           -- TRAP
3154
                                        set(presub) <= '1';
3155
                                        setstackaddr <='1';
3156
                                        setstate <= "11";
3157 10 tobiflex
                                        IF use_VBR_Stackframe='1' THEN  --68010
3158 2 tobiflex
                                                set(writePC_add) <= '1';
3159
                                                datatype <= "01";
3160
--                                              set_datatype <= "10";
3161
                                                next_micro_state <= trap1;
3162
                                        ELSE
3163
                                                IF trap_interrupt='1' OR trap_trace='1' OR trap_berr='1' THEN
3164
                                                        writePC <= '1';
3165
                                                END IF;
3166
                                                datatype <= "10";
3167
                                                next_micro_state <= trap2;
3168 8 tobiflex
                                        END IF;
3169
 
3170 2 tobiflex
                                WHEN trap1 =>           -- TRAP
3171
                                        IF trap_interrupt='1' OR trap_trace='1' THEN
3172
                                                writePC <= '1';
3173
                                        END IF;
3174
                                        set(presub) <= '1';
3175
                                        setstackaddr <='1';
3176
                                        setstate <= "11";
3177
                                        datatype <= "10";
3178
                                        next_micro_state <= trap2;
3179
                                WHEN trap2 =>           -- TRAP
3180
                                        set(presub) <= '1';
3181
                                        setstackaddr <='1';
3182
                                        setstate <= "11";
3183
                                        datatype <= "01";
3184
                                        writeSR <= '1';
3185
                                        IF trap_berr='1' THEN
3186
                                                next_micro_state <= trap4;
3187
                                        ELSE
3188
                                                next_micro_state <= trap3;
3189
                                        END IF;
3190
                                WHEN trap3 =>           -- TRAP
3191
                                        set_vectoraddr <= '1';
3192
                                        datatype <= "10";
3193
                                        set(direct_delta) <= '1';
3194
                                        set(directPC) <= '1';
3195
                                        setstate <= "10";
3196
                                        next_micro_state <= nopnop;
3197
                                WHEN trap4 =>           -- TRAP
3198
                                        set(presub) <= '1';
3199
                                        setstackaddr <='1';
3200
                                        setstate <= "11";
3201
                                        datatype <= "01";
3202
                                        writeSR <= '1';
3203
                                        next_micro_state <= trap5;
3204
                                WHEN trap5 =>           -- TRAP
3205
                                        set(presub) <= '1';
3206
                                        setstackaddr <='1';
3207
                                        setstate <= "11";
3208
                                        datatype <= "10";
3209
                                        writeSR <= '1';
3210
                                        next_micro_state <= trap6;
3211
                                WHEN trap6 =>           -- TRAP
3212
                                        set(presub) <= '1';
3213
                                        setstackaddr <='1';
3214
                                        setstate <= "11";
3215
                                        datatype <= "01";
3216
                                        writeSR <= '1';
3217
                                        next_micro_state <= trap3;
3218
 
3219 9 tobiflex
                                                                                -- return from exception - RTE
3220
                                                                                -- fetch PC and status register from stack
3221
                                                                                -- 010+ fetches another word containing
3222
                                                                                -- the 12 bit vector offset and the
3223
                                                                                -- frame format. If the frame format is
3224
                                                                                -- 2 another two words have to be taken
3225
                                                                                -- from the stack
3226 2 tobiflex
                                WHEN rte1 =>            -- RTE
3227
                                        datatype <= "10";
3228
                                        setstate <= "10";
3229
                                        set(postadd) <= '1';
3230
                                        setstackaddr <= '1';
3231 4 tobiflex
                                        set(directPC) <= '1';
3232 10 tobiflex
                                        IF use_VBR_Stackframe='0' OR opcode(2)='1' THEN  --opcode(2)='1' => opcode is RTR
3233 2 tobiflex
                                                set(update_FC) <= '1';
3234
                                                set(direct_delta) <= '1';
3235
                                        END IF;
3236
                                        next_micro_state <= rte2;
3237
                                WHEN rte2 =>            -- RTE
3238
                                        datatype <= "01";
3239
                                        set(update_FC) <= '1';
3240 10 tobiflex
                                        IF use_VBR_Stackframe='1' AND opcode(2)='0' THEN
3241 9 tobiflex
                                                                                                -- 010+ reads another word
3242 2 tobiflex
                                                setstate <= "10";
3243
                                                set(postadd) <= '1';
3244
                                                setstackaddr <= '1';
3245
                                                next_micro_state <= rte3;
3246
                                        ELSE
3247
                                                next_micro_state <= nop;
3248
                                        END IF;
3249 9 tobiflex
--                              WHEN rte3 =>                    -- RTE
3250
--                                      next_micro_state <= nop;
3251
----                                    set(update_FC) <= '1';
3252
-- paste and copy form TH       ---------       
3253
                                when rte3 => -- RTE
3254
                                        setstate <= "01"; -- idle state to wait
3255
                                                                                        -- for input data to
3256
                                                                                        -- arrive
3257
                                        next_micro_state <= rte4;
3258
                                WHEN rte4 =>         -- RTE
3259
                                                                                        -- check for stack frame format #2
3260
                                        if last_data_in(15 downto 12)="0010" then
3261
                                                                                  -- read another 32 bits in this case
3262
                                                setstate <= "10"; -- read
3263
                                                datatype <= "10"; -- long word
3264
                                                set(postadd) <= '1';
3265
                                                setstackaddr <= '1';
3266
                                                next_micro_state <= rte5;
3267
                                        else
3268
                                                datatype <= "01";
3269
                                                next_micro_state <= nop;
3270
                                        end if;
3271
                                WHEN rte5 =>            -- RTE
3272
                                        next_micro_state <= nop;
3273
-------------------------------------
3274 2 tobiflex
 
3275
                                WHEN rtd1 =>            -- RTD
3276
                                        next_micro_state <= rtd2;
3277
                                WHEN rtd2 =>            -- RTD
3278
                                        setstackaddr <= '1';
3279
                                        set(Regwrena) <= '1';
3280
 
3281
                                WHEN movec1 =>          -- MOVEC
3282
                                        set(briefext) <= '1';
3283
                                        set_writePCbig <='1';
3284
                                        IF (brief(11 downto 0)=X"000" OR brief(11 downto 0)=X"001" OR brief(11 downto 0)=X"800" OR brief(11 downto 0)=X"801") OR
3285
                                           (cpu(1)='1' AND (brief(11 downto 0)=X"002" OR brief(11 downto 0)=X"802" OR brief(11 downto 0)=X"803" OR brief(11 downto 0)=X"804")) THEN
3286
                                                IF opcode(0)='0' THEN
3287
                                                        set(Regwrena) <= '1';
3288
                                                END IF;
3289
--                                      ELSIF brief(11 downto 0)=X"800"OR brief(11 downto 0)=X"001" OR brief(11 downto 0)=X"000" THEN
3290
--                                              trap_addr_error <= '1';
3291
--                                              trapmake <= '1';
3292
                                        ELSE
3293
                                                trap_illegal <= '1';
3294
                                                trapmake <= '1';
3295
                                        END IF;
3296
 
3297
                                WHEN movep1 =>          -- MOVEP d(An)
3298
                                        setdisp <= '1';
3299
                                        set(mem_addsub) <= '1';
3300
                                        set(mem_byte) <= '1';
3301
                                        set(OP1addr) <= '1';
3302
                                        IF opcode(6)='1' THEN
3303
                                                set(movepl) <= '1';
3304
                                        END IF;
3305
                                        IF opcode(7)='0' THEN
3306
                                                setstate <= "10";
3307
                                        ELSE
3308
                                                setstate <= "11";
3309
                                        END IF;
3310
                                        next_micro_state <= movep2;
3311
                                WHEN movep2 =>
3312
                                        IF opcode(6)='1' THEN
3313
                                                set(mem_addsub) <= '1';
3314
                                            set(OP1addr) <= '1';
3315
                                        END IF;
3316
                                        IF opcode(7)='0' THEN
3317
                                                setstate <= "10";
3318
                                        ELSE
3319
                                                setstate <= "11";
3320
                                        END IF;
3321
                                        next_micro_state <= movep3;
3322
                                WHEN movep3 =>
3323
                                        IF opcode(6)='1' THEN
3324
                                                set(mem_addsub) <= '1';
3325
                                            set(OP1addr) <= '1';
3326
                                                set(mem_byte) <= '1';
3327
                                                IF opcode(7)='0' THEN
3328
                                                        setstate <= "10";
3329
                                                ELSE
3330
                                                        setstate <= "11";
3331
                                                END IF;
3332
                                                next_micro_state <= movep4;
3333
                                        ELSE
3334
                                                datatype <= "01";               --Word
3335
                                        END IF;
3336
                                WHEN movep4 =>
3337
                                        IF opcode(7)='0' THEN
3338
                                                setstate <= "10";
3339
                                        ELSE
3340
                                                setstate <= "11";
3341
                                        END IF;
3342
                                        next_micro_state <= movep5;
3343
                                WHEN movep5 =>
3344
                                        datatype <= "10";               --Long
3345
 
3346
                                WHEN mul1       =>              -- mulu
3347
                                        IF opcode(15)='1' OR MUL_Mode=0 THEN
3348
                                                set_rot_cnt <= "001110";
3349
                                        ELSE
3350
                                                set_rot_cnt <= "011110";
3351
                                        END IF;
3352
                                        setstate <="01";
3353
                                        next_micro_state <= mul2;
3354
                                WHEN mul2       =>              -- mulu
3355 8 tobiflex
                                        setstate <="01";
3356 2 tobiflex
                                        IF rot_cnt="00001" THEN
3357 8 tobiflex
                                                next_micro_state <= mul_end1;
3358
 
3359 2 tobiflex
                                        ELSE
3360
                                                next_micro_state <= mul2;
3361
                                        END IF;
3362
                                WHEN mul_end1   =>              -- mulu
3363 8 tobiflex
                                        IF opcode(15)='0' THEN
3364 9 tobiflex
                                                set(hold_OP2) <= '1';
3365 8 tobiflex
                                        END IF;
3366 2 tobiflex
                                        datatype <= "10";
3367
                                        set(opcMULU) <= '1';
3368
                                        IF opcode(15)='0' AND (MUL_Mode=1 OR MUL_Mode=2) THEN
3369
                                                dest_2ndHbits <= '1';
3370
                                                set(write_lowlong) <= '1';
3371
                                                IF sndOPC(10)='1' THEN
3372
                                                        setstate <="01";
3373
                                                        next_micro_state <= mul_end2;
3374
                                                END IF;
3375
                                                set(Regwrena) <= '1';
3376
                                        END IF;
3377
                                        datatype <= "10";
3378
                                WHEN mul_end2   =>              -- divu
3379
                                        set(write_reminder) <= '1';
3380
                                        set(Regwrena) <= '1';
3381
                                        set(opcMULU) <= '1';
3382
 
3383
                                WHEN div1       =>              -- divu
3384
                                        setstate <="01";
3385
                                        next_micro_state <= div2;
3386
                                WHEN div2       =>              -- divu
3387
                                        IF (OP2out(31 downto 16)=x"0000" OR opcode(15)='1' OR DIV_Mode=0) AND OP2out(15 downto 0)=x"0000" THEN            --div zero
3388
                                                set_Z_error <= '1';
3389
                                        ELSE
3390
                                                next_micro_state <= div3;
3391
                                        END IF;
3392
                                        set(ld_rot_cnt) <= '1';
3393
                                        setstate <="01";
3394
                                WHEN div3       =>              -- divu
3395
                                        IF opcode(15)='1' OR DIV_Mode=0 THEN
3396
                                                set_rot_cnt <= "001101";
3397
                                        ELSE
3398
                                                set_rot_cnt <= "011101";
3399
                                        END IF;
3400
                                        setstate <="01";
3401
                                        next_micro_state <= div4;
3402
                                WHEN div4       =>              -- divu
3403
                                        setstate <="01";
3404
                                        IF rot_cnt="00001" THEN
3405
                                                next_micro_state <= div_end1;
3406
                                        ELSE
3407
                                                next_micro_state <= div4;
3408
                                        END IF;
3409
                                WHEN div_end1   =>              -- divu
3410
                                        IF opcode(15)='0' AND (DIV_Mode=1 OR DIV_Mode=2) THEN
3411
                                                set(write_reminder) <= '1';
3412
                                                next_micro_state <= div_end2;
3413
                                                setstate <="01";
3414
                                        END IF;
3415
                                        set(opcDIVU) <= '1';
3416
                                        datatype <= "10";
3417
                                WHEN div_end2   =>              -- divu
3418
                                        dest_2ndHbits <= '1';
3419
                                        source_2ndLbits <= '1';--???
3420
                                        set(opcDIVU) <= '1';
3421
 
3422
                                WHEN rota1      =>
3423
                                        IF OP2out(5 downto 0)/="000000" THEN
3424
                                                set_rot_cnt <= OP2out(5 downto 0);
3425
                                        ELSE
3426
                                                set_exec(rot_nop) <= '1';
3427
                                        END IF;
3428
 
3429
                                WHEN bf1 =>
3430
                                        setstate <="10";
3431
 
3432
                                WHEN OTHERS => NULL;
3433
                        END CASE;
3434
        END PROCESS;
3435
 
3436
-----------------------------------------------------------------------------
3437
-- MOVEC
3438
-----------------------------------------------------------------------------
3439
  process (clk, VBR, CACR, brief)
3440
  begin
3441
        -- all other hexa codes should give illegal isntruction exception
3442
        if rising_edge(clk) then
3443
          if Reset = '1' then
3444
                VBR <= (others => '0');
3445
                CACR <= (others => '0');
3446
          elsif clkena_lw = '1' and exec(movec_wr) = '1' then
3447
                case brief(11 downto 0) is
3448
                  when X"000" => NULL; -- SFC -- 68010+
3449
                  when X"001" => NULL; -- DFC -- 68010+
3450
                  when X"002" => CACR <= reg_QA(3 downto 0); -- 68020+
3451
                  when X"800" => NULL; -- USP -- 68010+
3452
                  when X"801" => VBR <= reg_QA; -- 68010+
3453
                  when X"802" => NULL; -- CAAR -- 68020+
3454
                  when X"803" => NULL; -- MSP -- 68020+
3455
                  when X"804" => NULL; -- isP -- 68020+
3456
                  when others => NULL;
3457
                end case;
3458
          end if;
3459
        end if;
3460
 
3461
        movec_data <= (others => '0');
3462
        case brief(11 downto 0) is
3463
          when X"002" => movec_data <= "0000000000000000000000000000" & (CACR AND "0011");
3464
 
3465 10 tobiflex
          when X"801" =>
3466 2 tobiflex
                movec_data <= VBR;
3467
                --end if;
3468
          when others => NULL;
3469
        end case;
3470
  end process;
3471
 
3472
  CACR_out <= CACR;
3473
  VBR_out <= VBR;
3474
-----------------------------------------------------------------------------
3475
-- Conditions
3476
-----------------------------------------------------------------------------
3477
PROCESS (exe_opcode, Flags)
3478
        BEGIN
3479
                CASE exe_opcode(11 downto 8) IS
3480
                        WHEN X"0" => exe_condition <= '1';
3481
                        WHEN X"1" => exe_condition <= '0';
3482
                        WHEN X"2" => exe_condition <=  NOT Flags(0) AND NOT Flags(2);
3483
                        WHEN X"3" => exe_condition <= Flags(0) OR Flags(2);
3484
                        WHEN X"4" => exe_condition <= NOT Flags(0);
3485
                        WHEN X"5" => exe_condition <= Flags(0);
3486
                        WHEN X"6" => exe_condition <= NOT Flags(2);
3487
                        WHEN X"7" => exe_condition <= Flags(2);
3488
                        WHEN X"8" => exe_condition <= NOT Flags(1);
3489
                        WHEN X"9" => exe_condition <= Flags(1);
3490
                        WHEN X"a" => exe_condition <= NOT Flags(3);
3491
                        WHEN X"b" => exe_condition <= Flags(3);
3492
                        WHEN X"c" => exe_condition <= (Flags(3) AND Flags(1)) OR (NOT Flags(3) AND NOT Flags(1));
3493
                        WHEN X"d" => exe_condition <= (Flags(3) AND NOT Flags(1)) OR (NOT Flags(3) AND Flags(1));
3494
                        WHEN X"e" => exe_condition <= (Flags(3) AND Flags(1) AND NOT Flags(2)) OR (NOT Flags(3) AND NOT Flags(1) AND NOT Flags(2));
3495
                        WHEN X"f" => exe_condition <= (Flags(3) AND NOT Flags(1)) OR (NOT Flags(3) AND Flags(1)) OR Flags(2);
3496
                        WHEN OTHERS => NULL;
3497
                END CASE;
3498
        END PROCESS;
3499
 
3500
-----------------------------------------------------------------------------
3501
-- Movem
3502
-----------------------------------------------------------------------------
3503
PROCESS (clk)
3504
        BEGIN
3505
                IF rising_edge(clk) THEN
3506
                        IF clkena_lw='1' THEN
3507
                                movem_actiond <= exec(movem_action);
3508
                                IF decodeOPC='1' THEN
3509
                                        sndOPC <= data_read(15 downto 0);
3510
                                ELSIF exec(movem_action)='1' OR set(movem_action) ='1' THEN
3511
                                        CASE movem_regaddr IS
3512
                                                WHEN "0000" => sndOPC(0)  <= '0';
3513
                                                WHEN "0001" => sndOPC(1)  <= '0';
3514
                                                WHEN "0010" => sndOPC(2)  <= '0';
3515
                                                WHEN "0011" => sndOPC(3)  <= '0';
3516
                                                WHEN "0100" => sndOPC(4)  <= '0';
3517
                                                WHEN "0101" => sndOPC(5)  <= '0';
3518
                                                WHEN "0110" => sndOPC(6)  <= '0';
3519
                                                WHEN "0111" => sndOPC(7)  <= '0';
3520
                                                WHEN "1000" => sndOPC(8)  <= '0';
3521
                                                WHEN "1001" => sndOPC(9)  <= '0';
3522
                                                WHEN "1010" => sndOPC(10) <= '0';
3523
                                                WHEN "1011" => sndOPC(11) <= '0';
3524
                                                WHEN "1100" => sndOPC(12) <= '0';
3525
                                                WHEN "1101" => sndOPC(13) <= '0';
3526
                                                WHEN "1110" => sndOPC(14) <= '0';
3527
                                                WHEN "1111" => sndOPC(15) <= '0';
3528
                                                WHEN OTHERS => NULL;
3529
                                        END CASE;
3530
                                END IF;
3531
                        END IF;
3532
                END IF;
3533
        END PROCESS;
3534
 
3535
PROCESS (sndOPC, movem_mux)
3536
        BEGIN
3537
                movem_regaddr <="0000";
3538
                movem_run <= '1';
3539
                IF sndOPC(3 downto 0)="0000" THEN
3540
                        IF sndOPC(7 downto 4)="0000" THEN
3541
                                movem_regaddr(3) <= '1';
3542
                                IF sndOPC(11 downto 8)="0000" THEN
3543
                                        IF sndOPC(15 downto 12)="0000" THEN
3544
                                                movem_run <= '0';
3545
                                        END IF;
3546
                                        movem_regaddr(2) <= '1';
3547
                                        movem_mux <= sndOPC(15 downto 12);
3548
                                ELSE
3549
                                        movem_mux <= sndOPC(11 downto 8);
3550
                                END IF;
3551
                        ELSE
3552
                                movem_mux <= sndOPC(7 downto 4);
3553
                                movem_regaddr(2) <= '1';
3554
                        END IF;
3555
                ELSE
3556
                        movem_mux <= sndOPC(3 downto 0);
3557
                END IF;
3558
                IF movem_mux(1 downto 0)="00" THEN
3559
                        movem_regaddr(1) <= '1';
3560
                        IF movem_mux(2)='0' THEN
3561
                                movem_regaddr(0) <= '1';
3562
                        END IF;
3563
                ELSE
3564
                        IF movem_mux(0)='0' THEN
3565
                                movem_regaddr(0) <= '1';
3566
                        END IF;
3567
                END  IF;
3568
        END PROCESS;
3569
END;

powered by: WebSVN 2.1.0

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