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

Subversion Repositories t65

[/] [t65/] [trunk/] [rtl/] [vhdl/] [T65_MCode.vhd] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 jesus
--
2
-- 65xx compatible microprocessor core
3
--
4
-- Version : 0246
5
--
6
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
7
--
8
-- All rights reserved
9
--
10
-- Redistribution and use in source and synthezised forms, with or without
11
-- modification, are permitted provided that the following conditions are met:
12
--
13
-- Redistributions of source code must retain the above copyright notice,
14
-- this list of conditions and the following disclaimer.
15
--
16
-- Redistributions in synthesized form must reproduce the above copyright
17
-- notice, this list of conditions and the following disclaimer in the
18
-- documentation and/or other materials provided with the distribution.
19
--
20
-- Neither the name of the author nor the names of other contributors may
21
-- be used to endorse or promote products derived from this software without
22
-- specific prior written permission.
23
--
24
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
28
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
-- POSSIBILITY OF SUCH DAMAGE.
35
--
36
-- Please report bugs to the author, but before you do so, please
37
-- make sure that this is not a derivative work and that
38
-- you have the latest version of this file.
39
--
40
-- The latest version of this file can be found at:
41
--      http://www.opencores.org/cvsweb.shtml/t65/
42
--
43
-- Limitations :
44
--
45
-- 65C02
46
-- supported : inc, dec, phx, plx, phy, ply
47
-- missing : bra, ora, lda, cmp, sbc, tsb*2, trb*2, stz*2, bit*2, wai, stp, jmp, bbr*8, bbs*8
48
--
49
-- File history :
50
--
51
--      0246 : First release
52
--
53
 
54
library IEEE;
55
use IEEE.std_logic_1164.all;
56
use IEEE.numeric_std.all;
57
use work.T65_Pack.all;
58
 
59
entity T65_MCode is
60
        port(
61
                Mode                    : in std_logic_vector(1 downto 0);       -- "00" => 6502, "01" => 65C02, "10" => 65816
62
                IR                              : in std_logic_vector(7 downto 0);
63
                MCycle                  : in std_logic_vector(2 downto 0);
64
                P                               : in std_logic_vector(7 downto 0);
65
                LCycle                  : out std_logic_vector(2 downto 0);
66
                ALU_Op                  : out std_logic_vector(3 downto 0);
67
                Set_BusA_To             : out std_logic_vector(2 downto 0); -- DI,A,X,Y,S,P
68
                Set_Addr_To             : out std_logic_vector(1 downto 0); -- PC Adder,S,AD,BA
69
                Write_Data              : out std_logic_vector(2 downto 0); -- DL,A,X,Y,S,P,PCL,PCH
70
                Jump                    : out std_logic_vector(1 downto 0); -- PC,++,DIDL,Rel
71
                BAAdd                   : out std_logic_vector(1 downto 0);      -- None,DB Inc,BA Add,BA Adj
72
                BreakAtNA               : out std_logic;
73
                ADAdd                   : out std_logic;
74
                PCAdd                   : out std_logic;
75
                Inc_S                   : out std_logic;
76
                Dec_S                   : out std_logic;
77
                LDA                             : out std_logic;
78
                LDP                             : out std_logic;
79
                LDX                             : out std_logic;
80
                LDY                             : out std_logic;
81
                LDS                             : out std_logic;
82
                LDDI                    : out std_logic;
83
                LDALU                   : out std_logic;
84
                LDAD                    : out std_logic;
85
                LDBAL                   : out std_logic;
86
                LDBAH                   : out std_logic;
87
                SaveP                   : out std_logic;
88
                Write                   : out std_logic
89
        );
90
end T65_MCode;
91
 
92
architecture rtl of T65_MCode is
93
 
94
        signal Branch : std_logic;
95
 
96
begin
97
 
98
        with IR(7 downto 5) select
99
                Branch <= not P(Flag_N) when "000",
100
                        P(Flag_N) when "001",
101
                        not P(Flag_V) when "010",
102
                        P(Flag_V) when "011",
103
                        not P(Flag_C) when "100",
104
                        P(Flag_C) when "101",
105
                        not P(Flag_Z) when "110",
106
                        P(Flag_Z) when others;
107
 
108
        process (IR, MCycle, P, Branch, Mode)
109
        begin
110
                LCycle <= "001";
111
                Set_BusA_To <= "001"; -- A
112
                Set_Addr_To <= (others => '0');
113
                Write_Data <= (others => '0');
114
                Jump <= (others => '0');
115
                BAAdd <= "00";
116
                BreakAtNA <= '0';
117
                ADAdd <= '0';
118
                PCAdd <= '0';
119
                Inc_S <= '0';
120
                Dec_S <= '0';
121
                LDA <= '0';
122
                LDP <= '0';
123
                LDX <= '0';
124
                LDY <= '0';
125
                LDS <= '0';
126
                LDDI <= '0';
127
                LDALU <= '0';
128
                LDAD <= '0';
129
                LDBAL <= '0';
130
                LDBAH <= '0';
131
                SaveP <= '0';
132
                Write <= '0';
133
 
134
                case IR(7 downto 5) is
135
                when "100" =>
136
                        case IR(1 downto 0) is
137
                        when "00" =>
138
                                Set_BusA_To <= "011"; -- Y
139
                                Write_Data <= "011"; -- Y
140
                        when "10" =>
141
                                Set_BusA_To <= "010"; -- X
142
                                Write_Data <= "010"; -- X
143
                        when others =>
144
                                Write_Data <= "001"; -- A
145
                        end case;
146
                when "101" =>
147
                        case IR(1 downto 0) is
148
                        when "00" =>
149
                                if IR(4) /= '1' or IR(2) /= '0' then
150
                                        LDY <= '1';
151
                                end if;
152
                        when "10" =>
153
                                LDX <= '1';
154
                        when others =>
155
                                LDA <= '1';
156
                        end case;
157
                        Set_BusA_To <= "000"; -- DI
158
                when "110" =>
159
                        case IR(1 downto 0) is
160
                        when "00" =>
161
                                if IR(4) = '0' then
162
                                        LDY <= '1';
163
                                end if;
164
                                Set_BusA_To <= "011"; -- Y
165
                        when others =>
166
                                Set_BusA_To <= "001"; -- A
167
                        end case;
168
                when "111" =>
169
                        case IR(1 downto 0) is
170
                        when "00" =>
171
                                if IR(4) = '0' then
172
                                        LDX <= '1';
173
                                end if;
174
                                Set_BusA_To <= "010"; -- X
175
                        when others =>
176
                                Set_BusA_To <= "001"; -- A
177
                        end case;
178
                when others =>
179
                end case;
180
 
181
                if IR(7 downto 6) /= "10" and IR(1 downto 0) = "10" then
182
                        Set_BusA_To <= "000"; -- DI
183
                end if;
184
 
185
                case IR(4 downto 0) is
186
                when "00000" | "01000" | "01010" | "11000" | "11010" =>
187
                        -- Implied
188
                        case IR is
189
                        when "00000000" =>
190
                                -- BRK
191
                                LCycle <= "110";
192
                                case to_integer(unsigned(MCycle)) is
193
                                when 1 =>
194
                                        Set_Addr_To <= "01"; -- S
195
                                        Write_Data <= "111"; -- PCH
196
                                        Write <= '1';
197
                                when 2 =>
198
                                        Dec_S <= '1';
199
                                        Set_Addr_To <= "01"; -- S
200
                                        Write_Data <= "110"; -- PCL
201
                                        Write <= '1';
202
                                when 3 =>
203
                                        Dec_S <= '1';
204
                                        Set_Addr_To <= "01"; -- S
205
                                        Write_Data <= "101"; -- P
206
                                        Write <= '1';
207
                                when 4 =>
208
                                        Dec_S <= '1';
209
                                        Set_Addr_To <= "11"; -- BA
210
                                when 5 =>
211
                                        LDDI <= '1';
212
                                        Set_Addr_To <= "11"; -- BA
213
                                when 6 =>
214
                                        Jump <= "10"; -- DIDL
215
                                when others =>
216
                                end case;
217
                        when "00100000" =>
218
                                -- JSR
219
                                LCycle <= "101";
220
                                case to_integer(unsigned(MCycle)) is
221
                                when 1 =>
222
                                        Jump <= "01";
223
                                        LDDI <= '1';
224
                                        Set_Addr_To <= "01"; -- S
225
                                when 2 =>
226
                                        Set_Addr_To <= "01"; -- S
227
                                        Write_Data <= "111"; -- PCH
228
                                        Write <= '1';
229
                                when 3 =>
230
                                        Dec_S <= '1';
231
                                        Set_Addr_To <= "01"; -- S
232
                                        Write_Data <= "110"; -- PCL
233
                                        Write <= '1';
234
                                when 4 =>
235
                                        Dec_S <= '1';
236
                                when 5 =>
237
                                        Jump <= "10"; -- DIDL
238
                                when others =>
239
                                end case;
240
                        when "01000000" =>
241
                                -- RTI
242
                                LCycle <= "101";
243
                                case to_integer(unsigned(MCycle)) is
244
                                when 1 =>
245
                                        Set_Addr_To <= "01"; -- S
246
                                when 2 =>
247
                                        Inc_S <= '1';
248
                                        Set_Addr_To <= "01"; -- S
249
                                when 3 =>
250
                                        Inc_S <= '1';
251
                                        Set_Addr_To <= "01"; -- S
252
                                        Set_BusA_To <= "000"; -- DI
253
                                when 4 =>
254
                                        LDP <= '1';
255
                                        Inc_S <= '1';
256
                                        LDDI <= '1';
257
                                        Set_Addr_To <= "01"; -- S
258
                                when 5 =>
259
                                        Jump <= "10"; -- DIDL
260
                                when others =>
261
                                end case;
262
                        when "01100000" =>
263
                                -- RTS
264
                                LCycle <= "101";
265
                                case to_integer(unsigned(MCycle)) is
266
                                when 1 =>
267
                                        Set_Addr_To <= "01"; -- S
268
                                when 2 =>
269
                                        Inc_S <= '1';
270
                                        Set_Addr_To <= "01"; -- S
271
                                when 3 =>
272
                                        Inc_S <= '1';
273
                                        LDDI <= '1';
274
                                        Set_Addr_To <= "01"; -- S
275
                                when 4 =>
276
                                        Jump <= "10"; -- DIDL
277
                                when 5 =>
278
                                        Jump <= "01";
279
                                when others =>
280
                                end case;
281
                        when "00001000" | "01001000" | "01011010" | "11011010" =>
282
                                -- PHP, PHA, PHY*, PHX*
283
                                LCycle <= "010";
284
                                if Mode = "00" and IR(1) = '1' then
285
                                        LCycle <= "001";
286
                                end if;
287
                                case to_integer(unsigned(MCycle)) is
288
                                when 1 =>
289
                                        case IR(7 downto 4) is
290
                                        when "0000" =>
291
                                                Write_Data <= "101"; -- P
292
                                        when "0100" =>
293
                                                Write_Data <= "001"; -- A
294
                                        when "0101" =>
295
                                                Write_Data <= "011"; -- Y
296
                                        when "1101" =>
297
                                                Write_Data <= "010"; -- X
298
                                        when others =>
299
                                        end case;
300
                                        Write <= '1';
301
                                        Set_Addr_To <= "01"; -- S
302
                                when 2 =>
303
                                        Dec_S <= '1';
304
                                when others =>
305
                                end case;
306
                        when "00101000" | "01101000" | "01111010" | "11111010" =>
307
                                -- PLP, PLA, PLY*, PLX*
308
                                LCycle <= "011";
309
                                if Mode = "00" and IR(1) = '1' then
310
                                        LCycle <= "001";
311
                                end if;
312
                                case IR(7 downto 4) is
313
                                when "0010" =>
314
                                        LDP <= '1';
315
                                when "0110" =>
316
                                        LDA <= '1';
317
                                when "0111" =>
318
                                        if Mode /= "00" then
319
                                                LDY <= '1';
320
                                        end if;
321
                                when "1111" =>
322
                                        if Mode /= "00" then
323
                                                LDX <= '1';
324
                                        end if;
325
                                when others =>
326
                                end case;
327
                                case to_integer(unsigned(MCycle)) is
328
                                when 0 =>
329
                                        SaveP <= '1';
330
                                when 1 =>
331
                                        Set_Addr_To <= "01"; -- S
332
                                when 2 =>
333
                                        Inc_S <= '1';
334
                                        Set_Addr_To <= "01"; -- S
335
                                when 3 =>
336
                                        Set_BusA_To <= "000"; -- DI
337
                                when others =>
338
                                end case;
339
                        when "10100000" | "11000000" | "11100000" =>
340
                                -- LDY, CPY, CPX
341
                                -- Immediate
342
                                case to_integer(unsigned(MCycle)) is
343
                                when 0 =>
344
                                when 1 =>
345
                                        Jump <= "01";
346
                                when others =>
347
                                end case;
348
                        when "10001000" =>
349
                                -- DEY
350
                                LDY <= '1';
351
                                case to_integer(unsigned(MCycle)) is
352
                                when 0 =>
353
                                when 1 =>
354
                                        Set_BusA_To <= "011"; -- Y
355
                                when others =>
356
                                end case;
357
                        when "11001010" =>
358
                                -- DEX
359
                                LDX <= '1';
360
                                case to_integer(unsigned(MCycle)) is
361
                                when 0 =>
362
                                when 1 =>
363
                                        Set_BusA_To <= "010"; -- X
364
                                when others =>
365
                                end case;
366
                        when "00011010" | "00111010" =>
367
                                -- INC*, DEC*
368
                                if Mode /= "00" then
369
                                        LDA <= '1'; -- A
370
                                end if;
371
                                case to_integer(unsigned(MCycle)) is
372
                                when 0 =>
373
                                when 1 =>
374
                                        Set_BusA_To <= "100"; -- S
375
                                when others =>
376
                                end case;
377
                        when "00001010" | "00101010" | "01001010" | "01101010" =>
378
                                -- ASL, ROL, LSR, ROR
379
                                LDA <= '1'; -- A
380
                                Set_BusA_To <= "001"; -- A
381
                                case to_integer(unsigned(MCycle)) is
382
                                when 0 =>
383
                                when 1 =>
384
                                when others =>
385
                                end case;
386
                        when "10001010" | "10011000" =>
387
                                -- TYA, TXA
388
                                LDA <= '1'; -- A
389
                                case to_integer(unsigned(MCycle)) is
390
                                when 0 =>
391
                                when 1 =>
392
                                when others =>
393
                                end case;
394
                        when "10101010" | "10101000" =>
395
                                -- TAX, TAY
396
                                case to_integer(unsigned(MCycle)) is
397
                                when 0 =>
398
                                when 1 =>
399
                                        Set_BusA_To <= "001"; -- A
400
                                when others =>
401
                                end case;
402
                        when "10011010" =>
403
                                -- TXS
404
                                case to_integer(unsigned(MCycle)) is
405
                                when 0 =>
406
                                        LDS <= '1';
407
                                when 1 =>
408
                                when others =>
409
                                end case;
410
                        when "10111010" =>
411
                                -- TSX
412
                                LDX <= '1';
413
                                case to_integer(unsigned(MCycle)) is
414
                                when 0 =>
415
                                when 1 =>
416
                                        Set_BusA_To <= "100"; -- S
417
                                when others =>
418
                                end case;
419
 
420
--                      when "00011000" | "00111000" | "01011000" | "01111000" | "10111000" | "11011000" | "11111000" | "11001000" | "11101000" =>
421
--                              -- CLC, SEC, CLI, SEI, CLV, CLD, SED, INY, INX
422
--                              case to_integer(unsigned(MCycle)) is
423
--                              when 1 =>
424
--                              when others =>
425
--                              end case;
426
                        when others =>
427
                                case to_integer(unsigned(MCycle)) is
428
                                when 0 =>
429
                                when others =>
430
                                end case;
431
                        end case;
432
 
433
                when "00001" | "00011" =>
434
                        -- Zero Page Indexed Indirect (d,x)
435
                        LCycle <= "101";
436
                        if IR(7 downto 6) /= "10" then
437
                                LDA <= '1';
438
                        end if;
439
                        case to_integer(unsigned(MCycle)) is
440
                        when 0 =>
441
                        when 1 =>
442
                                Jump <= "01";
443
                                LDAD <= '1';
444
                                Set_Addr_To <= "10"; -- AD
445
                        when 2 =>
446
                                ADAdd <= '1';
447
                                Set_Addr_To <= "10"; -- AD
448
                        when 3 =>
449
                                BAAdd <= "01";  -- DB Inc
450
                                LDBAL <= '1';
451
                                Set_Addr_To <= "10"; -- AD
452
                        when 4 =>
453
                                LDBAH <= '1';
454
                                if IR(7 downto 5) = "100" then
455
                                        Write <= '1';
456
                                end if;
457
                                Set_Addr_To <= "11"; -- BA
458
                        when 5 =>
459
                        when others =>
460
                        end case;
461
 
462
                when "01001" | "01011" =>
463
                        -- Immediate
464
                        LDA <= '1';
465
                        case to_integer(unsigned(MCycle)) is
466
                        when 0 =>
467
                        when 1 =>
468
                                Jump <= "01";
469
                        when others =>
470
                        end case;
471
 
472
                when "00010" | "10010" =>
473
                        -- Immediate, KIL
474
                        LDX <= '1';
475
                        case to_integer(unsigned(MCycle)) is
476
                        when 0 =>
477
                        when 1 =>
478
                                if IR = "10100010" then
479
                                        -- LDX
480
                                        Jump <= "01";
481
                                else
482
                                        -- KIL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
483
                                end if;
484
                        when others =>
485
                        end case;
486
 
487
                when "00100" =>
488
                        -- Zero Page
489
                        LCycle <= "010";
490
                        case to_integer(unsigned(MCycle)) is
491
                        when 0 =>
492
                                if IR(7 downto 5) = "001" then
493
                                        SaveP <= '1';
494
                                end if;
495
                        when 1 =>
496
                                Jump <= "01";
497
                                LDAD <= '1';
498
                                if IR(7 downto 5) = "100" then
499
                                        Write <= '1';
500
                                end if;
501
                                Set_Addr_To <= "10"; -- AD
502
                        when 2 =>
503
                        when others =>
504
                        end case;
505
 
506
                when "00101" | "00110" | "00111" =>
507
                        -- Zero Page
508
                        if IR(7 downto 6) /= "10" and IR(1 downto 0) = "10" then
509
                                -- Read-Modify-Write
510
                                LCycle <= "100";
511
                                case to_integer(unsigned(MCycle)) is
512
                                when 1 =>
513
                                        Jump <= "01";
514
                                        LDAD <= '1';
515
                                        Set_Addr_To <= "10"; -- AD
516
                                when 2 =>
517
                                        LDDI <= '1';
518
                                        Write <= '1';
519
                                        Set_Addr_To <= "10"; -- AD
520
                                when 3 =>
521
                                        LDALU <= '1';
522
                                        SaveP <= '1';
523
                                        Write <= '1';
524
                                        Set_Addr_To <= "10"; -- AD
525
                                when 4 =>
526
                                when others =>
527
                                end case;
528
                        else
529
                                LCycle <= "010";
530
                                if IR(7 downto 6) /= "10" then
531
                                        LDA <= '1';
532
                                end if;
533
                                case to_integer(unsigned(MCycle)) is
534
                                when 0 =>
535
                                when 1 =>
536
                                        Jump <= "01";
537
                                        LDAD <= '1';
538
                                        if IR(7 downto 5) = "100" then
539
                                                Write <= '1';
540
                                        end if;
541
                                        Set_Addr_To <= "10"; -- AD
542
                                when 2 =>
543
                                when others =>
544
                                end case;
545
                        end if;
546
 
547
                when "01100" =>
548
                        -- Absolute
549
                        if IR(7 downto 6) = "01" and IR(4 downto 0) = "01100" then
550
                                -- JMP
551
                                if IR(5) = '0' then
552
                                        LCycle <= "011";
553
                                        case to_integer(unsigned(MCycle)) is
554
                                        when 2 =>
555
                                                Jump <= "01";
556
                                                LDDI <= '1';
557
                                        when 3 =>
558
                                                Jump <= "10"; -- DIDL
559
                                        when others =>
560
                                        end case;
561
                                else
562
                                        LCycle <= "101";
563
                                        case to_integer(unsigned(MCycle)) is
564
                                        when 2 =>
565
                                                Jump <= "01";
566
                                                LDDI <= '1';
567
                                                LDBAL <= '1';
568
                                        when 3 =>
569
                                                LDBAH <= '1';
570
                                                if Mode /= "00" then
571
                                                        Jump <= "10"; -- DIDL
572
                                                end if;
573
                                                if Mode = "00" then
574
                                                        Set_Addr_To <= "11"; -- BA
575
                                                end if;
576
                                        when 4 =>
577
                                                LDDI <= '1';
578
                                                if Mode = "00" then
579
                                                        Set_Addr_To <= "11"; -- BA
580
                                                        BAAdd <= "01";  -- DB Inc
581
                                                else
582
                                                        Jump <= "01";
583
                                                end if;
584
                                        when 5 =>
585
                                                Jump <= "10"; -- DIDL
586
                                        when others =>
587
                                        end case;
588
                                end if;
589
                        else
590
                                LCycle <= "011";
591
                                case to_integer(unsigned(MCycle)) is
592
                                when 0 =>
593
                                        if IR(7 downto 5) = "001" then
594
                                                SaveP <= '1';
595
                                        end if;
596
                                when 1 =>
597
                                        Jump <= "01";
598
                                        LDBAL <= '1';
599
                                when 2 =>
600
                                        Jump <= "01";
601
                                        LDBAH <= '1';
602
                                        if IR(7 downto 5) = "100" then
603
                                                Write <= '1';
604
                                        end if;
605
                                        Set_Addr_To <= "11"; -- BA
606
                                when 3 =>
607
                                when others =>
608
                                end case;
609
                        end if;
610
 
611
                when "01101" | "01110" | "01111" =>
612
                        -- Absolute
613
                        if IR(7 downto 6) /= "10" and IR(1 downto 0) = "10" then
614
                                -- Read-Modify-Write
615
                                LCycle <= "101";
616
                                case to_integer(unsigned(MCycle)) is
617
                                when 1 =>
618
                                        Jump <= "01";
619
                                        LDBAL <= '1';
620
                                when 2 =>
621
                                        Jump <= "01";
622
                                        LDBAH <= '1';
623
                                        Set_Addr_To <= "11"; -- BA
624
                                when 3 =>
625
                                        LDDI <= '1';
626
                                        Write <= '1';
627
                                        Set_Addr_To <= "11"; -- BA
628
                                when 4 =>
629
                                        Write <= '1';
630
                                        LDALU <= '1';
631
                                        SaveP <= '1';
632
                                        Set_Addr_To <= "11"; -- BA
633
                                when 5 =>
634
                                        SaveP <= '1';
635
                                when others =>
636
                                end case;
637
                        else
638
                                LCycle <= "011";
639
                                if IR(7 downto 6) /= "10" then
640
                                        LDA <= '1';
641
                                end if;
642
                                case to_integer(unsigned(MCycle)) is
643
                                when 0 =>
644
                                when 1 =>
645
                                        Jump <= "01";
646
                                        LDBAL <= '1';
647
                                when 2 =>
648
                                        Jump <= "01";
649
                                        LDBAH <= '1';
650
                                        if IR(7 downto 5) = "100" then
651
                                                Write <= '1';
652
                                        end if;
653
                                        Set_Addr_To <= "11"; -- BA
654
                                when 3 =>
655
                                when others =>
656
                                end case;
657
                        end if;
658
 
659
                when "10000" =>
660
                        -- Relative
661
                        if Branch = '1' then
662
                                LCycle <= "100";
663
                        else
664
                                LCycle <= "010";
665
                        end if;
666
                        case to_integer(unsigned(MCycle)) is
667
                        when 2 =>
668
                                Jump <= "01";
669
                                LDDI <= '1';
670
                        when 3 =>
671
                                Jump <= "11"; -- Rel
672
                                PCAdd <= '1';
673
                        when 4 =>
674
                        when others =>
675
                        end case;
676
 
677
                when "10001" | "10011" =>
678
                        -- Zero Page Indirect Indexed (d),y
679
                        LCycle <= "101";
680
                        if IR(7 downto 6) /= "10" then
681
                                LDA <= '1';
682
                        end if;
683
                        case to_integer(unsigned(MCycle)) is
684
                        when 0 =>
685
                        when 1 =>
686
                                Jump <= "01";
687
                                LDAD <= '1';
688
                                Set_Addr_To <= "10"; -- AD
689
                        when 2 =>
690
                                LDBAL <= '1';
691
                                BAAdd <= "01";  -- DB Inc
692
                                Set_Addr_To <= "10"; -- AD
693
                        when 3 =>
694
                                Set_BusA_To <= "011"; -- Y
695
                                BAAdd <= "10";  -- BA Add
696
                                LDBAH <= '1';
697
                                Set_Addr_To <= "11"; -- BA
698
                        when 4 =>
699
                                BAAdd <= "11";  -- BA Adj
700
                                if IR(7 downto 5) = "100" then
701
                                        Write <= '1';
702
                                else
703
                                        BreakAtNA <= '1';
704
                                end if;
705
                                Set_Addr_To <= "11"; -- BA
706
                        when 5 =>
707
                        when others =>
708
                        end case;
709
 
710
                when "10100" | "10101" | "10110" | "10111" =>
711
                        -- Zero Page, X
712
                        if IR(7 downto 6) /= "10" and IR(1 downto 0) = "10" then
713
                                -- Read-Modify-Write
714
                                LCycle <= "101";
715
                                case to_integer(unsigned(MCycle)) is
716
                                when 1 =>
717
                                        Jump <= "01";
718
                                        LDAD <= '1';
719
                                        Set_Addr_To <= "10"; -- AD
720
                                when 2 =>
721
                                        ADAdd <= '1';
722
                                        Set_Addr_To <= "10"; -- AD
723
                                when 3 =>
724
                                        LDDI <= '1';
725
                                        Write <= '1';
726
                                        Set_Addr_To <= "10"; -- AD
727
                                when 4 =>
728
                                        LDALU <= '1';
729
                                        SaveP <= '1';
730
                                        Write <= '1';
731
                                        Set_Addr_To <= "10"; -- AD
732
                                when 5 =>
733
                                when others =>
734
                                end case;
735
                        else
736
                                LCycle <= "011";
737
                                if IR(7 downto 6) /= "10" then
738
                                        LDA <= '1';
739
                                end if;
740
                                case to_integer(unsigned(MCycle)) is
741
                                when 0 =>
742
                                when 1 =>
743
                                        Jump <= "01";
744
                                        LDAD <= '1';
745
                                        Set_Addr_To <= "10"; -- AD
746
                                when 2 =>
747
                                        ADAdd <= '1';
748
                                        if IR(7 downto 5) = "100" then
749
                                                Write <= '1';
750
                                        end if;
751
                                        Set_Addr_To <= "10"; -- AD
752
                                when 3 =>
753
                                when others =>
754
                                end case;
755
                        end if;
756
 
757
                when "11001" | "11011" =>
758
                        -- Absolute Y
759
                        LCycle <= "100";
760
                        if IR(7 downto 6) /= "10" then
761
                                LDA <= '1';
762
                        end if;
763
                        case to_integer(unsigned(MCycle)) is
764
                        when 0 =>
765
                        when 1 =>
766
                                Jump <= "01";
767
                                LDBAL <= '1';
768
                        when 2 =>
769
                                Jump <= "01";
770
                                Set_BusA_To <= "011"; -- Y
771
                                BAAdd <= "10";  -- BA Add
772
                                LDBAH <= '1';
773
                                Set_Addr_To <= "11"; -- BA
774
                        when 3 =>
775
                                BAAdd <= "11";  -- BA adj
776
                                if IR(7 downto 5) = "100" then
777
                                        Write <= '1';
778
                                else
779
                                        BreakAtNA <= '1';
780
                                end if;
781
                                Set_Addr_To <= "11"; -- BA
782
                        when 4 =>
783
                        when others =>
784
                        end case;
785
 
786
                when "11100" | "11101" | "11110" | "11111" =>
787
                        -- Absolute X
788
                        if IR(7 downto 6) /= "10" and IR(1 downto 0) = "10" then
789
                                -- Read-Modify-Write
790
                                LCycle <= "110";
791
                                case to_integer(unsigned(MCycle)) is
792
                                when 1 =>
793
                                        Jump <= "01";
794
                                        LDBAL <= '1';
795
                                when 2 =>
796
                                        Jump <= "01";
797
                                        Set_BusA_To <= "010"; -- X
798
                                        BAAdd <= "10";  -- BA Add
799
                                        LDBAH <= '1';
800
                                        Set_Addr_To <= "11"; -- BA
801
                                when 3 =>
802
                                        BAAdd <= "11";  -- BA adj
803
                                        Set_Addr_To <= "11"; -- BA
804
                                when 4 =>
805
                                        LDDI <= '1';
806
                                        Write <= '1';
807
                                        Set_Addr_To <= "11"; -- BA
808
                                when 5 =>
809
                                        LDALU <= '1';
810
                                        SaveP <= '1';
811
                                        Write <= '1';
812
                                        Set_Addr_To <= "11"; -- BA
813
                                when 6 =>
814
                                when others =>
815
                                end case;
816
                        else
817
                                LCycle <= "100";
818
                                if IR(7 downto 6) /= "10" then
819
                                        LDA <= '1';
820
                                end if;
821
                                case to_integer(unsigned(MCycle)) is
822
                                when 0 =>
823
                                when 1 =>
824
                                        Jump <= "01";
825
                                        LDBAL <= '1';
826
                                when 2 =>
827
                                        Jump <= "01";
828
                                        Set_BusA_To <= "010"; -- X
829
                                        BAAdd <= "10";  -- BA Add
830
                                        LDBAH <= '1';
831
                                        Set_Addr_To <= "11"; -- BA
832
                                when 3 =>
833
                                        BAAdd <= "11";  -- BA adj
834
                                        if IR(7 downto 5) = "100" then
835
                                                Write <= '1';
836
                                        else
837
                                                BreakAtNA <= '1';
838
                                        end if;
839
                                        Set_Addr_To <= "11"; -- BA
840
                                when 4 =>
841
                                when others =>
842
                                end case;
843
                        end if;
844
                when others =>
845
                end case;
846
        end process;
847
 
848
        process (IR, MCycle)
849
        begin
850
                -- ORA, AND, EOR, ADC, NOP, LD, CMP, SBC
851
                -- ASL, ROL, LSR, ROR, BIT, LD, DEC, INC
852
                case IR(1 downto 0) is
853
                when "00" =>
854
                        case IR(4 downto 2) is
855
                        when "000" | "001" | "011" =>
856
                                case IR(7 downto 5) is
857
                                when "110" | "111" =>
858
                                        -- CP
859
                                        ALU_Op <= "0110";
860
                                when "101" =>
861
                                        -- LD
862
                                        ALU_Op <= "0101";
863
                                when "001" =>
864
                                        -- BIT
865
                                        ALU_Op <= "1100";
866
                                when others =>
867
                                        -- NOP/ST
868
                                        ALU_Op <= "0100";
869
                                end case;
870
                        when "010" =>
871
                                case IR(7 downto 5) is
872
                                when "111" | "110" =>
873
                                        -- IN
874
                                        ALU_Op <= "1111";
875
                                when "100" =>
876
                                        -- DEY
877
                                        ALU_Op <= "1110";
878
                                when others =>
879
                                        -- LD
880
                                        ALU_Op <= "1101";
881
                                end case;
882
                        when "110" =>
883
                                case IR(7 downto 5) is
884
                                when "100" =>
885
                                        -- TYA
886
                                        ALU_Op <= "1101";
887
                                when others =>
888
                                        ALU_Op <= "----";
889
                                end case;
890
                        when others =>
891
                                case IR(7 downto 5) is
892
                                when "101" =>
893
                                        -- LD
894
                                        ALU_Op <= "1101";
895
                                when others =>
896
                                        ALU_Op <= "0100";
897
                                end case;
898
                        end case;
899
                when "01" =>
900
                        ALU_Op(3) <= '0';
901
                        ALU_Op(2 downto 0) <= IR(7 downto 5);
902
                when "10" =>
903
                        ALU_Op(3) <= '1';
904
                        ALU_Op(2 downto 0) <= IR(7 downto 5);
905
                        case IR(7 downto 5) is
906
                        when "000" =>
907
                                if IR(4 downto 2) = "110" then
908
                                        -- INC
909
                                        ALU_Op <= "1111";
910
                                end if;
911
                        when "001" =>
912
                                if IR(4 downto 2) = "110" then
913
                                        -- DEC
914
                                        ALU_Op <= "1110";
915
                                end if;
916
                        when "100" =>
917
                                if IR(4 downto 2) = "010" then
918
                                        -- TXA
919
                                        ALU_Op <= "0101";
920
                                else
921
                                        ALU_Op <= "0100";
922
                                end if;
923
                        when others =>
924
                        end case;
925
                when others =>
926
                        case IR(7 downto 5) is
927
                        when "100" =>
928
                                ALU_Op <= "0100";
929
                        when others =>
930
                                if MCycle = "000" then
931
                                        ALU_Op(3) <= '0';
932
                                        ALU_Op(2 downto 0) <= IR(7 downto 5);
933
                                else
934
                                        ALU_Op(3) <= '1';
935
                                        ALU_Op(2 downto 0) <= IR(7 downto 5);
936
                                end if;
937
                        end case;
938
                end case;
939
        end process;
940
 
941
end;

powered by: WebSVN 2.1.0

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