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

Subversion Repositories pdp8

[/] [pdp8/] [trunk/] [pdp8/] [cpu/] [cpu.new] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 trurl
--------------------------------------------------------------------------------
2
--!
3
--! PDP8 Processor
4
--!
5
--! \brief
6
--!      Processor
7
--!
8
--! \details
9
--!      I hope you like state machines because this is implemented as one big
10
--!      state machine.
11
--!
12
--! \file
13
--!      cpu.vhd
14
--!
15
--! \author
16
--!      Rob Doyle - doyle (at) cox (dot) net
17
--!
18
--------------------------------------------------------------------------------
19
--
20
--  Copyright (C) 2009, 2010, 2011, 2012 Rob Doyle
21
--
22
-- This source file may be used and distributed without restriction provided
23
-- that this copyright statement is not removed from the file and that any
24
-- derivative work contains the original copyright notice and the associated
25
-- disclaimer.
26
--
27
-- This source file is free software; you can redistribute it and/or modify it
28
-- under the terms of the GNU Lesser General Public License as published by the
29
-- Free Software Foundation; version 2.1 of the License.
30
--
31
-- This source is distributed in the hope that it will be useful, but WITHOUT
32
-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
33
-- FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
34
-- details.
35
--
36
-- You should have received a copy of the GNU Lesser General Public License
37
-- along with this source; if not, download it from
38
-- http://www.gnu.org/licenses/lgpl.txt
39
--
40
--------------------------------------------------------------------------------
41
--
42
-- Comments are formatted for doxygen
43
--
44
 
45
library ieee;                                   --! IEEE Library
46
use ieee.std_logic_1164.all;                    --! IEEE 1164
47
use ieee.numeric_std.all;                       --! IEEE Numeric Standard
48
use work.cpu_types.all;
49
-- synthesis translate_off
50
use std.textio.all;
51
use ieee.std_logic_textio.all;
52
use work.pck_fio.all;
53
-- synthesis translate_on
54
 
55
--
56
--! eCPU Entity
57
--
58
 
59
entity eCPU is port (
60
    sys     : in  sys_t;                        --! Clock/Reset
61
    swCPU   : in  swCPU_t;                      --! CPU Configuration
62
    swOPT   : in  swOPT_t;                      --! Options Configuration
63
    swDATA  : in  swDATA_t;                     --! Data Switch Inputs
64
    swCNTL  : in  swCNTL_t;                     --! Control Switch Inputs
65
    dev     : in  dev_t;                        --! Device Output
66
    cpu     : out cpu_t                         --! CPU Output
67
);
68
end eCPU;
69
 
70
--
71
--! eCPU RTL
72
--
73
 
74
architecture rtl of eCPU is
75
 
76
    --
77
    -- Registers
78
    --
79
 
80
    signal LAC      : ldata_t;                  --! Link and Accumulator
81
    alias  L        : std_logic is LAC (0);     --! Link Bit
82
    alias  AC       : data_t is LAC(1 to 12);   --! Accumulator
83
    signal IR       : data_t;                   --! Instruction Register
84
    signal PC       : addr_t;                   --! Program Counter
85
    signal MA       : addr_t;                   --! Memory Address Register
86
    signal MB       : data_t;                   --! Memory Buffer (output)
87
    signal MD       : data_t;                   --! Memory Data Register (input)
88
    signal MQ       : data_t;                   --! MQ Register
89
    signal MQA      : data_t;                   --! MQA Register
90
    signal SC       : sc_t;                     --! SC Register
91
    signal SP1      : addr_t;                   --! Stack Pointer
92
    signal SP2      : addr_t;                   --! Stack Pointer
93
    signal SR       : data_t;                   --! Switch Register
94
 
95
    --
96
    -- Register Operation
97
    --
98
 
99
    signal acOP     : acOP_t;                   --! AC operation
100
    signal pcOP     : pcOP_t;                   --! PC operation
101
    signal irOP     : irOP_t;                   --! IR operation
102
    signal maOP     : maOP_t;                   --! MA operation
103
    signal mbOP     : mbOP_t;                   --! MB operation
104
    signal mqOP     : mqOP_t;                   --! MQ operation
105
    signal mqaOP    : mqaOP_t;                  --! MQA operation
106
    signal scOP     : scOP_t;                   --! SC operation
107
    signal sp1OP    : spOP_t;                   --! SP1 operation
108
    signal sp2OP    : spOP_t;                   --! SP2 operation
109
    signal srOP     : srOP_t;                   --! SR operation
110
 
111
    --
112
    -- Memory Extension Control Registers
113
    --
114
 
115
    signal IB       : field_t;                  --! Instruction Buffer
116
    signal INF      : field_t;                  --! Instruction Field
117
    signal DF       : field_t;                  --! Data Field
118
    signal SF       : sf_t;                     --! Save Field
119
    signal UB       : std_logic;                --! User Buffer Flag
120
    signal UF       : std_logic;                --! User Flag
121
 
122
    --
123
    -- Memory Extension Control Register Operations
124
    --
125
 
126
    signal ibOP     : ibOP_t;                   --! IB operation
127
    signal ifOP     : ifOP_t;                   --! IF operation
128
    signal dfOP     : dfOP_t;                   --! DF operation
129
    signal sfOP     : sfOP_t;                   --! SF operation
130
    signal ubOP     : ubOP_t;                   --! User Buffer operation
131
    signal ufOP     : ufOP_t;                   --! USER Flag operation
132
    signal IRQ      : std_logic;                --! IRQ Flag
133
 
134
    --
135
    -- BTSTRP:
136
    --
137
 
138
    signal BTSTRP   : std_logic;                --! BTSTRP Flag
139
    signal btstrpOP : btstrpOP_t;               --! BTSTRP operation
140
 
141
    --
142
    -- CTRLFF:
143
    -- The Control Panel Flip-Flop (CTRLFF), is set when the CPREQ is granted.
144
    -- CTRLFF prevents further CPREQs from being granted, bypasses the
145
    -- interrupt enable system and redefines several of the internal control
146
    -- instructions.  As long as the CTRLFF is set, LXPAR is used for all
147
    -- instruction, direct data and indirect pointer references.  Also, while
148
    -- CTRLFF is set, the INTGNT line is held inactive but the Interrupt Grant
149
    -- Flip Flop is not cleared.  IOTs executed while CTRLFF is set do not clear
150
    -- the Interrupt grant flip flop.
151
    --
152
 
153
    signal CTRLFF   : std_logic;                --! CTRLFF
154
    signal ctrlffOP : ctrlffOP_t;               --! CTRLFF operation
155
 
156
    --
157
    -- EAE:
158
    -- EAE Long Operations
159
    --
160
 
161
    signal EAE      : eae_t;                    --! EAE Register
162
    signal eaeOP    : eaeOP_t;                  --! EAE operation
163
 
164
    --
165
    -- EMODE:
166
    -- The EMODE bit is set at reset and is set by the SWAB and cleared by the
167
    -- SWBA instructions.  This enables EAE Mode A and EAE Mode B instructions.
168
    --
169
 
170
    signal EMODE    : std_logic;                --! EAE Mode
171
    signal emodeOP  : emodeOP_t;                --! EAE Mode operation
172
 
173
    --
174
    -- FZ:
175
    -- The Force Zero Flag (FZ) is used to implement Extended memory operations
176
    -- for Panel Mode instructions.  When set, forces control panel instruction
177
    -- field access to field zero.  Indirect data accesses are not affected.
178
    --
179
 
180
    signal FZ       : std_logic;                --! Force Zero
181
    signal fzOP     : fzOP_t;                   --! FZ operation
182
 
183
    --
184
    -- HLTTRP:
185
    -- The HLTTRP flip-flop allows the cpu to single step through code.
186
    -- The HLTTRP flip-flop is set by a HLT instruction.
187
    --
188
 
189
    signal HLTTRP   : std_logic;                --! HLTTRP Flip-Flop
190
    signal hlttrpOP : hlttrpOP_t;               --! HLTTRP operation
191
 
192
    --
193
    -- GTF:
194
    --
195
 
196
    signal GTF      : std_logic;                --! Greater than Flag
197
    signal gtfOP    : gtfOP_t;                  --! GTF operation
198
 
199
    --
200
    -- ID:
201
    -- The Interrupt Enable Delay Flip-Flop (ID) delays the effect of the ION
202
    -- instruction until the instruction after the ION instruction has executed.
203
    -- This will allow a return from interrupt to be executed before the next
204
    -- interrupt request is serviced.
205
    --
206
 
207
    signal ID       : std_logic;                --! ION Delay Flip-flop
208
    signal idOP     : idOP_t;                   --! ION Delay Operation
209
 
210
    --
211
    -- IE:
212
    -- The Interrupt Enable Flip-Flop (IE) enables and disables interrupts.
213
    --
214
 
215
    signal IE       : std_logic;                --! Interrupt Enable
216
    signal ieOP     : ieOP_t;                   --! IE operation
217
 
218
    --
219
    -- II:
220
    -- The Interrupt Inhibit (II) Flip-Flop is set whenever there is an
221
    -- instruction executed that could change the Instruction Field.  These
222
    -- include CIF, CDI, RMF, RTF, CAF, CUF, SUF.  The II Flip-Flop is
223
    -- cleared when the next JMP, JMS, RTN1, or RTN2 instruction is executed.
224
    -- This prevents an interrupt from occuring between the CIF (or like)
225
    -- instruction and the return (or like) instruction.
226
    --
227
 
228
    signal II       : std_logic;                -- Interrupt Inhibit Flip-Flop
229
    signal iiOP     : iiOP_t;                   -- Interrupt Inhibit Operation
230
 
231
    --
232
    -- PDF:
233
    -- The Panel Data Flag (PDF) is used to contol whether indirectly addressed
234
    -- data references by Control Panel AND, TAD, ISZ or DCA instructions
235
    -- reference panel memory or main memory.  If PDF is set, this flag causes
236
    -- indirect references from control panel memory to address control panel
237
    -- memory by asserting LXPAR.  If PDF is cleared, this flag causes indirect
238
    -- references from control panel memory to address main memory by asserting
239
    -- LXMAR.  The PDF is cleared unconditionally whenever the panel mode is
240
    -- entered for any reason.  It is also cleared by the Clear Panel Data
241
    -- (CPD) instruction.  The PDF is set by the Set Panel Data (SPD)
242
    -- instruction. The state of the Panel Data flag is ignored when not
243
    -- operating in panel mode.
244
    --
245
 
246
    signal PDF      : std_logic;                --! Panel Data Flag
247
    signal pdfOP    : pdfOP_t;                  --! PDF operation
248
 
249
    --
250
    -- PEX:
251
    -- The Panel Exit Delay (PEX) Flip-Flop is set by the PEX instruction.
252
    -- When a JMP, JMS, RET1, or RET2 instruction is executed with the PEX
253
    -- Flip-Flop set, the CPU will exit panel mode.  The PEX Flip-Flop is
254
    -- cleared by the JMP, JMS, RET1, or RET2 instruction.
255
    --
256
 
257
    signal PEX      : std_logic;                -- PEX Flip-Flop
258
    signal pexOP    : pexOP_t;                  -- PEX Operation
259
 
260
    --
261
    -- PNLTRP:
262
    -- A Panel Trap is one of the many ways to enter panel mode.  The Panel Trap
263
    -- Flip-Flop (PNLTRP) is set by any of the PR0, PR1, PR2, PR3 instructions.
264
    -- The PNLTRP flag can be examined and cleared by the PRS instruction.
265
    --
266
 
267
    signal PNLTRP   : std_logic;                --! PNLTRP Flag
268
    signal pnltrpOP : pnltrpOP_t;               --! PNLTRP operation
269
 
270
    --
271
    -- PRWON:
272
    -- The Power-On Trap Flip-Flop (PWRTRP) is set when STRTUP is negated during
273
    -- RESET, The Power-On Flip-Flop (PWRTRP) is reset by a PRS or PEX
274
    -- instruction.
275
    --
276
 
277
    signal PWRTRP   : std_logic;                --! PWRTRP Flip-Flop
278
    signal pwrtrpOP : pwrtrpOP_t;               --! PWRTRP operation
279
 
280
    --
281
    -- USRTRP:
282
    -- User Mode Trap.
283
    --
284
 
285
    signal USRTRP   : std_logic;                --! USR Interrupt
286
    signal usrtrpOP : usrtrpOP_t;               --! USR Interrupt operation
287
 
288
    --
289
    -- XMA
290
    --
291
 
292
    signal XMA      : field_t;                  --! XMA Register
293
    signal xmaOP    : xmaOP_t;                  --! XMA operation
294
 
295
    --
296
    -- Bus Control Signals
297
    --
298
 
299
    signal busb     : busOP_t;                  --! Bus Operation output
300
    signal busOP    : busOP_t;                  --! Bus Operation input
301
    signal ioclrb   : std_logic;                --! IOCLR register output
302
    signal ioclrOP  : std_logic;                --! IOCLR register input
303
    signal wrb      : std_logic;                --! WR signal register input
304
    signal wrOP     : std_logic;                --! WR signal register output
305
    signal rdb      : std_logic;                --! RD signal register output
306
    signal rdOP     : std_logic;                --! RD signal register input
307
    signal ifetchb  : std_logic;                --! IFETCH signal register output
308
    signal ifetchOP : std_logic;                --! IFETCH signal register input
309
    signal datafb   : std_logic;                --! DATAF signal register output
310
    signal datafOP  : std_logic;                --! DATAF signal register input
311
    signal lxdarb   : std_logic;                --! LXDAR signal register output
312
    signal lxdarOP  : std_logic;                --! LXDAR signal register input
313
    signal lxmarb   : std_logic;                --! LXMAR signal register output
314
    signal lxmarOP  : std_logic;                --! LXMAR signal register input
315
    signal lxparb   : std_logic;                --! LXPAR signal register output
316
    signal lxparOP  : std_logic;                --! LXPAR signal register input
317
    signal memselb  : std_logic;                --! MEMSEL signal register output
318
    signal memselOP : std_logic;                --! MEMSEL signal register input
319
    signal intgntb  : std_logic;                --! INTGNT signal register output
320
    signal dmagnt   : std_logic;                --! DMAGNT signal register input
321
    signal intgntOP : std_logic;                --! INTGNT signal register input
322
    signal waitfb   : std_logic;                --! WAITF signal register output
323
    signal waitfOP  : std_logic;                --! WAITF signal register input
324
 
325
    signal oops     : std_logic;
326
 
327
    --
328
    -- State Information
329
    --
330
 
331
    type state_t is (
332
        stateReset,
333
        stateInit,
334
        stateCheckReq,
335
        stateFetchAddr,
336
        stateFetchData,
337
        stateLoadIR,
338
        stateDecodeInstruction,
339
 
340
        --
341
        -- MRI States
342
        --
343
 
344
        stateMRIreadAddr,
345
        stateMRIreadDataIND,
346
        stateMRIreadIncAddr,
347
        stateMRIreadIndData,
348
        stateMRIexecute,
349
 
350
        --
351
        -- IOT states
352
        --
353
 
354
        stateIOTdecode,
355
        stateIOT,
356
 
357
        --
358
        -- Stack Operation States
359
        --
360
 
361
        statePOPaddr,
362
        statePOPdata,
363
        stateRTN1,
364
        stateRTN2,
365
        stateRTNaddr,
366
        stateRTNdata,
367
 
368
        --
369
        -- OPR Groups
370
        --
371
 
372
        stateOprGroup1Seq3,
373
        stateOprGroup1Seq4,
374
        stateOprGroup2Seq2,
375
        stateOprGroup3Seq3,
376
 
377
        --
378
        -- Front Panel States
379
        --
380
 
381
        stateHalt,
382
        stateContinue,
383
        stateLoadADDR,
384
        stateLoadEXTD,
385
        stateClear,
386
        stateDepositWriteData,
387
        stateDeposit,
388
        stateExamine,
389
        stateExamineReadAddr,
390
        stateExamineReadData,
391
        stateHaltDone,
392
 
393
        --
394
        -- EAE States
395
        --
396
 
397
        stateEAEfetchAddr,
398
        stateEAEfetchData,
399
        stateEAEindWrite,
400
        stateEAEindReadAddr,
401
        stateEAEindReadData,
402
        stateEAEshift,
403
        stateEAEwait,
404
        stateEAEnmi,
405
        stateEAEshiftDVI,
406
        stateEAEsubDVI,
407
        stateEAEmuy,
408
        stateEAEreadDADaddr0,
409
        stateEAEreadDADaddr1,
410
        stateEAEreadDADdata0,
411
        stateEAEreadDADdata1,
412
        stateEAEdst,
413
 
414
        --
415
        -- HALT states
416
        --
417
 
418
        stateDone,
419
        stateLALA
420
    );
421
 
422
 
423
    signal   state      : state_t;
424
    signal   nextState  : state_t;
425
    constant maAutoIncr : std_logic_vector(3 to 11) := o"001";
426
 
427
    --
428
    -- Output files for state dumpState
429
    --
430
 
431
    -- synthesis translate_off
432
    file     FIL        : text is out "STD_OUTPUT";
433
    file     STDOUT     : text is out "STD_OUTPUT";
434
  --file     FIL        : text is out "trace.txt";
435
    -- synthesis translate_on
436
 
437
    --
438
    -- vectorize
439
    --
440
 
441
    function vectorize(s: std_logic) return std_logic_vector is
442
        variable v: std_logic_vector(0 to 0);
443
    begin
444
        v(0) := s;
445
        return v;
446
    end;
447
 
448
    --
449
    -- dumpState()
450
    --
451
 
452
    procedure dumpState(PC : in addr_t) is
453
        -- synthesis translate_off
454
        variable LIN : line;
455
        -- synthesis translate_on
456
    begin
457
        -- synthesis translate_off
458
        write (LIN, string'("ST:"));
459
        write (LIN, string'(" PC="));
460
        owrite(LIN, PC);
461
        write (LIN, string'(", IR="));
462
        owrite(LIN, IR);
463
        write (LIN, string'(", LAC="));
464
        owrite(LIN, "00" & LAC);
465
        write (LIN, string'(", MQ="));
466
        owrite(LIN, MQ);
467
        write (LIN, string'(", SR="));
468
        owrite(LIN, SR);
469
        write (LIN, string'(", IF="));
470
        owrite(LIN, INF);
471
        write (LIN, string'(", DF="));
472
        owrite(LIN, DF);
473
        write (LIN, string'(", IB="));
474
        owrite(LIN, IB);
475
        write (LIN, string'(", UB="));
476
        owrite(LIN, "00" & vectorize(UB));
477
        write (LIN, string'(", UF="));
478
        owrite(LIN, "00" &  vectorize(UF));
479
        write (LIN, string'(", USF="));
480
        owrite(LIN, "00" &  SF(0 to 0));
481
        write (LIN, string'(", ISF="));
482
        owrite(LIN, SF(1 to 3));
483
        write (LIN, string'(", DSF="));
484
        owrite(LIN, SF(4 to 6));
485
        write (LIN, string'(", SC="));
486
        owrite(LIN, '0' & SC);
487
        write (LIN, string'(", GTF="));
488
        owrite(LIN, "00" & vectorize(GTF));
489
        write (LIN, string'(", EMODE="));
490
        owrite(LIN, "00" & vectorize(EMODE));
491
        write (LIN, string'(", IEFF="));
492
        owrite(LIN, "00" & vectorize(IE));
493
        write (LIN, string'(", IDFF="));
494
        owrite(LIN, "00" & vectorize(ID));
495
        write (LIN, string'(", IIFF="));
496
        owrite(LIN, "00" & vectorize(II));
497
        write (LIN, string'(", IRQ="));
498
        owrite(LIN, "00" & vectorize(IRQ));
499
        write (LIN, string'(", SP1="));
500
        owrite(LIN, SP2);
501
        write (LIN, string'(", SP2="));
502
        owrite(LIN, SP1);
503
        write (LIN, string'("; MA=00000"));
504
        --owrite(LIN, XMA & MA);
505
        writeline(FIL, LIN);
506
        -- synthesis translate_on
507
    end dumpState;
508
 
509
    --
510
    -- dispHALT
511
    --
512
 
513
    procedure dispHALT(signal PC : in addr_t) is
514
        -- synthesis translate_off
515
       variable LIN : line;
516
        -- synthesis translate_on
517
    begin
518
        -- synthesis translate_off
519
        write (LIN, string'("CPU Halted at PC = "));
520
        owrite(LIN, PC);
521
        writeline(STDOUT, LIN);
522
        -- synthesis translate_on
523
    end dispHALT;
524
 
525
    --
526
    -- dispCONT
527
    --
528
 
529
    procedure dispCONT(signal PC : in addr_t) is
530
        -- synthesis translate_off
531
        variable LIN : line;
532
        -- synthesis translate_on
533
    begin
534
        -- synthesis translate_off
535
        write (LIN, string'("CPU Continued at PC = "));
536
        owrite(LIN, PC);
537
        writeline(STDOUT, LIN);
538
        -- synthesis translate_on
539
    end dispCONT;
540
 
541
begin
542
 
543
    IRQ <= '1' when ((dev.intr = '1') or
544
                     (USRTRP = '1' and swOPT.TSD = '0') or
545
                     (usrtrpOP = usrtrpopSET and swOPT.TSD = '0')) else '0';
546
 
547
    --
548
    --  ALU
549
    --
550
 
551
    iALU : entity work.eALU (rtl) port map (
552
        sys     => sys,
553
        acOP    => acOP,
554
        BTSTRP  => BTSTRP,
555
        GTF     => GTF,
556
        HLTTRP  => HLTTRP,
557
        IE      => IE,
558
        IRQ     => IRQ,
559
        PNLTRP  => PNLTRP,
560
        PWRTRP  => PWRTRP,
561
        DF      => DF,
562
        EAE     => EAE,
563
        INF     => INF,
564
        IR      => IR,
565
        MA      => MA,
566
        MD      => MD,
567
        MQ      => MQ,
568
        SC      => SC,
569
        SF      => SF,
570
        SP1     => SP1,
571
        SP2     => SP2,
572
        SR      => SR,
573
        UF      => UF,
574
        LAC     => LAC
575
    );
576
 
577
    --
578
    -- CTRLFF
579
    --
580
 
581
    iCTRLFF : entity work.eCTRLFF (rtl) port map (
582
        sys      => sys,
583
        ctrlffOP => ctrlffOP,
584
        CTRLFF   => CTRLFF
585
    );
586
 
587
    --
588
    -- EAE Register
589
    --
590
 
591
    iEAE : entity work.eEAE (rtl) port map (
592
        sys     => sys,
593
        eaeOP   => eaeOP,
594
        MD      => MD,
595
        MQ      => MQ,
596
        AC      => AC,
597
        EAE     => EAE
598
    );
599
 
600
    --
601
    -- EAE Mode A
602
    --
603
 
604
    iEMODE : entity work.eEMODE (rtl) port map (
605
        sys     => sys,
606
        emodeOP => emodeOP,
607
        EMODE   => EMODE
608
    );
609
 
610
    --
611
    -- FZ Flip Flop
612
    --
613
 
614
    iFZ : entity work.eFZ (rtl) port map (
615
        sys  => sys,
616
        fzOP => fzOP,
617
        FZ   => FZ
618
    );
619
 
620
    --
621
    -- GTF
622
    --
623
 
624
    iGTF : entity work.eGTF (rtl) port map (
625
        sys   => sys,
626
        gtfOP => gtfOP,
627
        AC    => AC,
628
        GTF   => GTF
629
    );
630
 
631
    --
632
    -- HLTTRP
633
    --
634
 
635
    iHLTTRP : entity work.eHLTTRP (rtl) port map (
636
        sys      => sys,
637
        hlttrpOP => hlttrpOP,
638
        HLTTRP   => HLTTRP
639
    );
640
 
641
    --
642
    -- Program Counter (PC)
643
    --
644
 
645
    iPC : entity work.ePC (rtl) port map (
646
        sys  => sys,
647
        pcOP => pcOP,
648
        IR   => IR,
649
        MA   => MA,
650
        MB   => MB,
651
        MD   => MD,
652
        SR   => SR,
653
        PC   => PC
654
    );
655
 
656
    --
657
    -- Multiplier Quotient Register (MQ)
658
    --
659
 
660
    iMQ : entity work.eMQ (rtl) port map (
661
        sys  => sys,
662
        mqOP => mqOP,
663
        AC   => AC,
664
        MD   => MD,
665
        EAE  => EAE,
666
        MQ   => MQ
667
    );
668
 
669
    --
670
    -- Auxillary Multiplier Quotient Register (MQA)
671
    --
672
 
673
    iMQA : entity work.eMQA (rtl) port map (
674
        sys   => sys,
675
        mqaOP => mqaOP,
676
        MQ    => MQ,
677
        MQA   => MQA
678
    );
679
 
680
    --
681
    -- Interrupt Enable Flip-Flop
682
    --
683
 
684
    iIE : entity work.eIE (rtl) port map (
685
        sys  => sys,
686
        ieOP => ieOP,
687
        IE   => IE
688
    );
689
 
690
    --
691
    -- Interrupt Inhibit Flip-Flop
692
    --
693
 
694
    iII : entity work.eII (rtl) port map (
695
        sys  => sys,
696
        iiOP => iiOP,
697
        II   => II
698
    );
699
 
700
    --
701
    -- USRTRP Flip-Flop
702
    --
703
 
704
    iUSRTRP : entity work.eUSRTRP (rtl) port map (
705
        sys      => sys,
706
        usrtrpOP => usrtrpOP,
707
        USRTRP   => USRTRP
708
    );
709
 
710
    --
711
    -- Instruction Register (IR)
712
    --
713
 
714
    iIR: entity work.eIR (rtl) port map (
715
        sys   => sys,
716
        irOP  => irOP,
717
        MD    => MD,
718
        IR    => IR
719
    );
720
 
721
    --
722
    -- Memory Address Register (MA)
723
    --
724
 
725
    iMA : entity work.eMA (rtl) port map (
726
        sys  => sys,
727
        maOP => maOP,
728
        IR   => IR,
729
        MB   => MB,
730
        MD   => MD,
731
        PC   => PC,
732
        SP1  => SP1,
733
        SP2  => SP2,
734
        SR   => SR,
735
        MA   => MA
736
    );
737
 
738
    --
739
    -- Memory Buffer Register (MB)
740
    --
741
 
742
    iMB : entity work.eMB (rtl) port map (
743
        sys  => sys,
744
        mbOP => mbOP,
745
        AC   => AC,
746
        MA   => MA,
747
        MD   => MD,
748
        MQ   => MQ,
749
        PC   => PC,
750
        SR   => SR,
751
        MB   => MB
752
    );
753
 
754
    --
755
    -- Instruction Buffer Address Extension Register (IB)
756
    --
757
 
758
    iIB : entity work.eIB (rtl) port map (
759
        sys  => sys,
760
        ibOP => ibOP,
761
        SF   => SF,
762
        AC   => AC,
763
        IR   => IR,
764
        IB   => IB
765
    );
766
 
767
    --
768
    -- Instruction Field Address Extension Register (IF/INF)
769
    --
770
 
771
    iIF : entity work.eIF (rtl) port map (
772
        sys  => sys,
773
        ifOP => ifOP,
774
        IB   => IB,
775
        SR   => SR,
776
        INF  => INF
777
    );
778
 
779
    --
780
    -- ION Delay Flip-Flop
781
    --
782
 
783
    iID : entity work.eID (rtl) port map (
784
        sys  => sys,
785
        idOP => idOP,
786
        ID   => ID
787
    );
788
 
789
    --
790
    -- Data Field Address Extension Register (DF)
791
    --
792
 
793
    iDF : entity work.eDF (rtl) port map (
794
        sys  => sys,
795
        dfOP => dfOP,
796
        AC   => AC,
797
        IR   => IR,
798
        SF   => SF,
799
        SR   => SR,
800
        DF   => DF
801
    );
802
 
803
    --
804
    -- BTSTRP Flip-Flop
805
    --
806
 
807
    iBTSTRP : entity work.eBTSTRP (rtl) port map (
808
        sys      => sys,
809
        btstrpOP => btstrpOP,
810
        BTSTRP   => BTSTRP
811
    );
812
 
813
    --
814
    -- PDF Flip-Flop
815
    --
816
 
817
    iPDF : entity work.ePDF (rtl) port map (
818
        sys   => sys,
819
        pdfOP => pdfOP,
820
        PDF   => PDF
821
    );
822
 
823
    --
824
    -- PEX Flip-Flop
825
    --
826
 
827
    iPEX : entity work.ePEX (rtl) port map (
828
        sys   => sys,
829
        pexOP => pexOP,
830
        PEX   => PEX
831
    );
832
 
833
    --
834
    -- PNLTRP Flip-Flop
835
    --
836
 
837
    iPNLTRP : entity work.ePNLTRP (rtl) port map (
838
        sys      => sys,
839
        pnltrpOP => pnltrpOP,
840
        PNLTRP   => PNLTRP
841
    );
842
 
843
    --
844
    -- PWRTRP Flip-Flop
845
    -- When set during reset, the unit will enter panel mode before executing
846
    -- the first instruction.
847
    --
848
 
849
    iPWRTRP : entity work.ePWRTRP (rtl) port map (
850
        sys      => sys,
851
        pwrtrpOP => pwrtrpOP,
852
        PWRTRP   => PWRTRP
853
    );
854
 
855
    --
856
    -- SC
857
    -- Step Counter
858
    --
859
 
860
    iSC : entity work.eeSC (rtl) port map (
861
        sys  => sys,
862
        scOP => scOP,
863
        AC   => AC,
864
        MD   => MD,
865
        SC   => SC
866
    );
867
 
868
    --
869
    -- SF
870
    -- Save Field Address Extension Register (SF)
871
    --
872
 
873
    iSF : entity work.eSF (rtl) port map (
874
        sys  => sys,
875
        sfOP => sfOP,
876
        DF   => DF,
877
        IB   => IB,
878
        UB   => UB,
879
        SF   => SF
880
    );
881
 
882
    --
883
    -- SP1
884
    -- Stack Pointer #1
885
    --
886
 
887
    iSP1 : entity work.eSP (rtl) port map (
888
        sys  => sys,
889
        spOP => sp1OP,
890
        AC   => AC,
891
        SP   => SP1
892
    );
893
 
894
    --
895
    -- SP2
896
    -- Stack Pointer #2
897
    --
898
 
899
    iSP2: entity work.eSP (rtl) port map (
900
        sys  => sys,
901
        spOP => sp2OP,
902
        AC   => AC,
903
        SP   => SP2
904
    );
905
 
906
    --
907
    -- SR
908
    -- Switch Register
909
    --
910
 
911
    iSR : entity work.eSR (rtl) port map (
912
        sys   => sys,
913
        swCPU => swCPU,
914
        srOP  => srOP,
915
        AC    => AC,
916
        SRD   => swDATA,
917
        SR    => SR
918
    );
919
 
920
    --
921
    -- UB
922
    -- User Buffer Flag
923
    --
924
 
925
    iUB : entity work.eUB (rtl) port map (
926
        sys  => sys,
927
        ubOP => ubOP,
928
        AC5  => AC(5),
929
        SF0  => SF(0),
930
        UB   => UB
931
    );
932
 
933
    --
934
    -- UF
935
    -- User Flag
936
    --
937
 
938
    iUF : entity work.eUF (rtl) port map (
939
        sys  => sys,
940
        ufOP => ufOP,
941
        UB   => UB,
942
        UF   => UF
943
    );
944
 
945
    --
946
    -- XMA
947
    -- XMA is disabled by disabling the KM8E option
948
    --
949
 
950
    iXMA : entity work.eXMA (rtl) port map (
951
        sys   => sys,
952
        xmaOP => xmaOP,
953
        sWCPU => swCPU,
954
        DF    => DF,
955
        INF   => INF,
956
        IB    => IB,
957
        XMA   => XMA
958
    );
959
 
960
    --
961
    -- Next State Decoder
962
    --
963
 
964
    process(swOPT, dev, IRQ, state, USRTRP, AC, L, MQA,
965
            BTSTRP, CTRLFF, EMODE, GTF, HLTTRP, ID, IE, II,
966
            LAC, MA, MD, MQ, PC, PEX, PNLTRP, PWRTRP, IR, SC, UF, swCPU,
967
            swCNTL.halt, swCNTL.clear, swCNTL.exam, swCNTL.dep, swCNTL.lock,
968
            swCNTL.step, swCNTL.cont, swCNTL.loadADDR, swCNTL.loadEXTD)
969
 
970
        variable EAEIR : std_logic_vector(0 to 3);
971
 
972
    begin
973
 
974
        --
975
        -- Control signal defaults
976
        --
977
 
978
        busOP      <= busopNOP;
979
        ioclrOP    <= '0';
980
        wrOP       <= '0';
981
        rdOP       <= '0';
982
        ifetchOP   <= '0';
983
        datafOP    <= '0';
984
        lxdarOP    <= '0';
985
        memselOP   <= '0';
986
        intgntOP   <= '0';
987
 
988
        --
989
        -- Operation defaults
990
        --
991
 
992
        acOP       <= acopNOP;
993
        busOP      <= busopNOP;
994
        btstrpOP   <= btstrpopNOP;
995
        ctrlffOP   <= ctrlffopNOP;
996
        dfOP       <= dfopNOP;
997
        eaeOP      <= eaeopNOP;
998
        emodeOP    <= emodeopNOP;
999
        fzOP       <= fzopNOP;
1000
        gtfOP      <= gtfopNOP;
1001
        hlttrpOP   <= hlttrpopNOP;
1002
        idOP       <= idopNOP;
1003
        ieOP       <= ieopNOP;
1004
        iiOP       <= iiopNOP;
1005
        ibOP       <= ibopNOP;
1006
        ifOP       <= ifopNOP;
1007
        irOP       <= iropNOP;
1008
        maOP       <= maopNOP;
1009
        mbOP       <= mbopNOP;
1010
        mqOP       <= mqopNOP;
1011
        mqaOP      <= mqaopNOP;
1012
        pcOP       <= pcopNOP;
1013
        pdfOP      <= pdfopNOP;
1014
        pexOP      <= pexopNOP;
1015
        pnltrpOP   <= pnltrpopNOP;
1016
        pwrtrpOP   <= pwrtrpopNOP;
1017
        scOP       <= scopNOP;
1018
        sfOP       <= sfopNOP;
1019
        sp1OP      <= spopNOP;
1020
        sp2OP      <= spopNOP;
1021
        srOP       <= sropNOP;
1022
        ubOP       <= ubopNOP;
1023
        ufOP       <= ufopNOP;
1024
        usrtrpOP   <= usrtrpopNOP;
1025
        xmaOP      <= xmaopNOP;
1026
 
1027
        --
1028
        -- Default Next State
1029
        --
1030
 
1031
        nextState <= stateLALA;
1032
 
1033
        --
1034
        -- BTSTRP set when CPREQ is asserted
1035
        --
1036
 
1037
        if dev.cpreq = '1' and swCPU = swHD6120 then
1038
            btstrpOP <= btstrpOPSET;
1039
        end if;
1040
 
1041
        --
1042
        -- The State Machine
1043
        --
1044
 
1045
        case state is
1046
 
1047
            --
1048
            -- Reset State
1049
            --
1050
 
1051
            when stateRESET =>
1052
                busOP     <= busopRESET;
1053
                nextState <= stateInit;
1054
 
1055
            --
1056
            --
1057
            -- Startup States
1058
            --
1059
 
1060
            when stateInit =>
1061
                if swCPU = swHD6120 then
1062
 
1063
                    --
1064
                    -- HD6120 Mode with STARTUP asserted.
1065
                    -- Boot to front panel mode (PC=7777)
1066
                    --
1067
 
1068
                    if swOPT.STARTUP = '1' then
1069
                        pwrtrpOP  <= pwrtrpopSET;
1070
                        nextState <= stateCheckReq;
1071
 
1072
                    --
1073
                    -- HD6120 Mode with STARTUP negated.
1074
                    -- Begin executing at PC=0000
1075
                    --
1076
 
1077
                    else
1078
                        pwrtrpOP  <= pwrtrpopCLR;
1079
                        nextState <= stateCheckReq;
1080
 
1081
                    end if;
1082
                else
1083
 
1084
                    --
1085
                    -- PDP8 Mode with STARTUP asserted.
1086
                    -- Set PC to contents of switch register and start
1087
                    -- execution.
1088
                    --
1089
 
1090
                    if swOPT.STARTUP = '1' then
1091
                        pcOP      <= pcopSR;
1092
                        nextState <= stateFetchAddr;
1093
 
1094
                    --
1095
                    -- PDP8 Mode with STARTUP negated.
1096
                    -- Start in HALT state.  User must interact with front
1097
                    -- panel.
1098
                    --
1099
 
1100
                    else
1101
                        nextState <= stateHalt;
1102
 
1103
                    end if;
1104
                end if;
1105
 
1106
            --
1107
            -- This state occurs at the very top of the processing loop.
1108
            -- The priority hierarchy is:
1109
            -- 1.  RESET -   Clears Accummulator and Link registers and clears the
1110
            --               RUN output signal.
1111
            -- 2.  CPREQ -   If not RESET and CPREQ is asserted, the processor
1112
            --               enters Panel Mode.
1113
            -- 3.  RUN/HLT - If neither RESET or CPREQ is asserted and HLT is
1114
            --               asserted (HLTFLAG = '1'), the processor should enter
1115
            --               the HALT state and the end of the current cycle.
1116
            -- 4.  DEV.INTR -  If no higher priority signal is asserted and IRQ is
1117
            --               asserted an interrup may be processed.
1118
            --
1119
 
1120
            when stateCheckReq =>
1121
 
1122
                --
1123
                -- HD6120:
1124
                -- Panel mode is entered because of the occurrence of any of
1125
                -- four events.  Each of these events sets a status flag, as
1126
                -- well as causing the entry into panel mode. It should be
1127
                -- noted that more than one event might happen simultaneously.
1128
                --
1129
                -- These events are:
1130
                --  1. PWRTRP  - Power-up Trap
1131
                --  2. PNLTRP  - Panel Trap
1132
                --  3. HLTTRP  - HLT insruction
1133
                --  4. BTSTRP  - CPREQ asserted.
1134
                --  5. Not already in panel mode
1135
                --
1136
                -- When a panel request is granted, the PC is stored in
1137
                -- location 0000 of the control panel memory and the CPU
1138
                -- resumes operation at location 7777 (octal) of the panel
1139
                -- memory. During the PC write, 0 appears on EMA0, EMA1 and
1140
                -- EMA2. The states of the IB, IF/INF, OF, ISF and DSF
1141
                -- registers are not disturbed by entry into the control
1142
                -- panel mode but execution is forced to commence in field
1143
                -- zero.
1144
                --
1145
                -- See also description of ID, IE, and II.
1146
                --
1147
 
1148
                if (((swCPU = swHD6120) and (ID = '0') and (II = '0') and (CTRLFF = '0') and (PWRTRP = '1')) or
1149
                    ((swCPU = swHD6120) and (ID = '0') and (II = '0') and (CTRLFF = '0') and (PNLTRP = '1')) or
1150
                    ((swCPU = swHD6120) and (ID = '0') and (II = '0') and (CTRLFF = '0') and (BTSTRP = '1')) or
1151
                    ((swCPU = swHD6120) and (ID = '0') and (II = '0') and (CTRLFF = '0') and (HLTTRP = '1'))) then
1152
 
1153
                    ctrlffOP  <= ctrlffopSET;
1154
                    fzOP      <= fzopSET;
1155
                    pdfOP     <= pdfopCLR;
1156
                    maOP      <= maop0000;
1157
                    mbOP      <= mbopPC;
1158
                    pcOP      <= pcop7777;
1159
                    xmaOP     <= xmaopCLR;
1160
                    busOP     <= busopWRZF;
1161
                    assert false report "---------------------> Panel Trap <---------------------" severity note;
1162
                    nextState <= stateFetchAddr;
1163
 
1164
                --
1165
                -- HALT Mode is entered if the HLTTRP is set or the RUN/HALT
1166
                -- Switch is in the HALT position.
1167
                --
1168
 
1169
                elsif (((swCPU /= swHD6120) and (HLTTRP = '1')) or
1170
                       ((swCPU /= swHD6120) and (swCNTL.halt = '1') and (swCNTL.lock = '0')) or
1171
                       ((swCPU /= swHD6120) and (swCNTL.step = '1') and (swCNTL.lock = '0'))) then
1172
                    hlttrpOP  <= hlttrpopCLR;
1173
                    dispHALT(PC);
1174
                    nextState <= stateHalt;
1175
 
1176
                --
1177
                -- Interrupt Request
1178
                -- When an External Interrupt is asserted, the following occurs:
1179
                --   1.  The PC is stored in location 0000 of field 0.
1180
                --   2.  The Interrupt Enable Flip-Flop (IE) is disabled
1181
                --       which precludes automatically nested interupts.
1182
                --   3.  The INTGNT signal is is asserted.
1183
                --   4.  UF, IF/INF, DF is loaded into SF.
1184
                --   5.  IF/INF is cleared.
1185
                --   6.  IB is cleared.
1186
                --   7.  DF is cleared.
1187
                --   8.  UF is cleared.
1188
                --   9.  UB is cleared.
1189
                --  10.  The PC is set to "0001" of main memory field 0 so
1190
                --       that the next instruction is fetched from there.
1191
                --
1192
                -- See also description of ID, IE, and II.
1193
                --
1194
 
1195
                elsif (IRQ = '1') and (ID = '0') and (IE = '1') and (II = '0') then
1196
                    intgntOP  <= '1';
1197
                    maOP      <= maop0000;
1198
                    mbOP      <= mbopPC;
1199
                    ieOP      <= ieopCLR;
1200
                    sfOP      <= sfopUBIBDF;
1201
                    dfOP      <= dfopCLR;
1202
                    ifOP      <= ifopCLR;
1203
                    ibOP      <= ibopCLR;
1204
                    ufOP      <= ufopCLR;
1205
                    ubOP      <= ubopCLR;
1206
                    pcOP      <= pcop0001;
1207
                    xmaOP     <= xmaopCLR;
1208
                    busOP     <= busopWRZF;
1209
                    assert false report "---------------------> Interrupt <---------------------" severity note;
1210
                    nextState <= stateFetchAddr;
1211
 
1212
                --
1213
                -- No interrupts, halt, single step, or anthing else.
1214
                -- Just start to fetch the next instruction.
1215
                --
1216
 
1217
                else
1218
                    nextState <= stateFetchAddr;
1219
 
1220
                end if;
1221
 
1222
            --
1223
            -- HALT State
1224
            -- An HD6120 will never get to this state since halts are trapped
1225
            -- by the front panel.
1226
            --
1227
 
1228
            when stateHalt =>
1229
 
1230
                --
1231
                -- Continue Switch Pressed
1232
                --
1233
 
1234
                if ((swCNTL.cont = '1' and swCNTL.lock = '0') or
1235
                    (swCNTL.step = '1' and swCNTL.lock = '0')) then
1236
                    dispCONT(PC);
1237
                    nextState <= stateContinue;
1238
 
1239
                --
1240
                -- Load Address Switch Pressed
1241
                -- This sets MA and PC to the contents of the switch register.
1242
                --  MA <- SR
1243
                --  PC <- SR
1244
                --
1245
 
1246
                elsif swCNTL.loadADDR = '1' and swCNTL.lock = '0' then
1247
                    pcOP      <= pcopSR;
1248
                    maOP      <= maopSR;
1249
                    nextState <= stateLoadADDR;
1250
 
1251
                --
1252
                -- Load Extended Address Switch Pressed
1253
                -- This sets IF and DF to the contents of the switch register.
1254
                --  IF <- SR[6:8]
1255
                --  DF <- SR[9:11]
1256
                --
1257
 
1258
                elsif swCNTL.loadEXTD = '1' and swCNTL.lock = '0' then
1259
                    ifOP      <= ifopSR6to8;
1260
                    dfOP      <= dfopSR9to11;
1261
                    nextState <= stateLoadEXTD;
1262
 
1263
                --
1264
                -- Clear Switch Pressed
1265
                --
1266
 
1267
                elsif swCNTL.clear = '1' and swCNTL.lock = '0' then
1268
                    acOP      <= acopCLACLL;
1269
                    mqOP      <= mqopCLR;
1270
                    ifOP      <= ifopCLR;
1271
                    dfOP      <= dfopCLR;
1272
                    sp1OP     <= spopCLR;
1273
                    sp2OP     <= spopCLR;
1274
                    gtfOP     <= gtfopCLR;
1275
                    emodeOP   <= emodeopCLR;
1276
                    ieOP      <= ieopCLR;
1277
                    idOP      <= idopSET;
1278
                    usrtrpOP  <= usrtrpopCLR;
1279
                    busOP     <= busopIOCLR;
1280
                    nextState <= stateClear;
1281
 
1282
                --
1283
                -- Examine Switch Pressed
1284
                -- This loads the contents of the memory location addressed by
1285
                -- the MA register into the MD register and increments the MA
1286
                -- and PC registers.
1287
                --  MD <- MEM[IF'MA]
1288
                --
1289
 
1290
                elsif swCNTL.exam = '1' and swCNTL.lock = '0' then
1291
                    maOP      <= maopPC;
1292
                    xmaOP     <= xmaopIF;
1293
                    busOP     <= busopRDIFaddr;
1294
                    nextState <= stateExamineReadAddr;
1295
 
1296
                --
1297
                -- Deposit Switch Pressed
1298
                -- This writes the contents of the Switch Register into the
1299
                -- memory location addressed by the MA register.
1300
                --  MEM[IF'MA] <- SR
1301
                --
1302
 
1303
                elsif swCNTL.dep = '1' and swCNTL.lock = '0' then
1304
                    maOP      <= maopPC;
1305
                    mbOP      <= mbopSR;
1306
                    xmaOP     <= xmaopIF;
1307
                    busOP     <= busopWRIF;
1308
                    nextState <= stateDepositWriteData;
1309
 
1310
                else
1311
                    nextState <= stateHalt;
1312
 
1313
                end if;
1314
 
1315
            --
1316
            -- Wait for Continue button to negate
1317
            --
1318
 
1319
            when stateContinue =>
1320
                if swCNTL.cont = '1' then
1321
                    nextState <= stateContinue;
1322
                else
1323
                    nextState <= stateFetchAddr;
1324
                end if;
1325
 
1326
            --
1327
            -- Wait for LoadADDR button to negate
1328
            --
1329
 
1330
            when stateLoadADDR =>
1331
                if swCNTL.loadADDR = '1' then
1332
                    nextState <= stateLoadADDR;
1333
                else
1334
                    nextState <= stateHaltDone;
1335
                end if;
1336
 
1337
            --
1338
            -- Wait for LoadEXTD button to negate
1339
            --
1340
 
1341
            when stateLoadEXTD =>
1342
                if swCNTL.loadEXTD = '1' then
1343
                    nextState <= stateLoadEXTD;
1344
                else
1345
                    nextState <= stateHaltDone;
1346
                end if;
1347
 
1348
            --
1349
            -- Wait for Clear button to negate
1350
            --
1351
 
1352
            when stateClear =>
1353
                if swCNTL.clear = '1' then
1354
                    nextState <= stateClear;
1355
                else
1356
                    nextState <= stateHaltDone;
1357
                end if;
1358
 
1359
            --
1360
            -- Examine Read Addr
1361
            -- This is the address phase of the read cycle.
1362
            --  MD <- MEM[IF'MA]
1363
            --
1364
 
1365
            when stateExamineReadAddr =>
1366
                xmaOP     <= xmaopIF;
1367
                busOP     <= busopRDIFdata;
1368
                nextState <= stateExamineReadData;
1369
 
1370
            --
1371
            -- Examine Read Data
1372
            -- This is the data phase of the read cycle.
1373
            -- At the end of this cycle, MD will have the data that was read.
1374
            -- This state increments the PC and MA register after the examine.
1375
            --  MD <- MEM[IF'MA]
1376
            --  MA <- MA + 1
1377
            --  PC <- PC + 1
1378
            --
1379
 
1380
            when stateExamineReadData =>
1381
                maOP      <= maopINC;
1382
                pcOP      <= pcopINC;
1383
                nextState <= stateExamine;
1384
 
1385
            --
1386
            -- Wait for Examine button to negate
1387
            --
1388
 
1389
            when stateExamine =>
1390
                if swCNTL.exam = '1' then
1391
                    nextState <= stateExamine;
1392
                else
1393
                    nextState <= stateHaltDone;
1394
                end if;
1395
 
1396
            --
1397
            -- This cycle writes data to memory.  Once written
1398
            -- this state increments PC and MA.
1399
            --  MA <- MA + 1
1400
            --  PC <- PC + 1
1401
            --
1402
 
1403
            when stateDepositWriteData =>
1404
                maOP      <= maopINC;
1405
                pcOP      <= pcopINC;
1406
                nextState <= stateDeposit;
1407
 
1408
            --
1409
            -- Wait for Deposit button to negate
1410
            --
1411
 
1412
            when stateDeposit =>
1413
                if swCNTL.dep = '1' then
1414
                    nextState <= stateDeposit;
1415
                else
1416
                    nextState <= stateHaltDone;
1417
                end if;
1418
 
1419
            --
1420
            -- Update Front Panel display
1421
            --
1422
 
1423
            when stateHaltDone =>
1424
                nextState <= stateHalt;
1425
 
1426
            --
1427
            -- Begin Instruction Fetch.  Perform Read Address Cycle.
1428
            --  MA <- PC
1429
            --  MD <- MEM[IF'MA]
1430
            --
1431
 
1432
            when stateFetchAddr =>
1433
                maOP      <= maopPC;
1434
                xmaOP     <= xmaopIF;
1435
                busOP     <= busopFETCHaddr;
1436
                nextState <= stateFetchData;
1437
 
1438
            --
1439
            -- Continue Instruction Fetch.  Perform Read Data Cycle.
1440
            -- The Interrupt Enable Delay Flip-Flop (ID) is cleared.
1441
            -- If the ID was set at the beginning of this instruction,
1442
            -- an interrupt, if present, was deferred.  We clear it now.
1443
            -- Therefore this instruction will complete and then that
1444
            -- interrupt, if present, will be recognized.
1445
            --  MD <- MEM[IF'MA]
1446
            --
1447
 
1448
            when stateFetchData =>
1449
                pcOP      <= pcopINC;
1450
                idOP      <= idopCLR;
1451
                xmaOP     <= xmaopIF;
1452
                busOP     <= busopFETCHdata;
1453
                nextState <= stateLoadIR;
1454
 
1455
            --
1456
            -- Load IR with the instruction that was fetched.
1457
            -- Note: This state is a wasted state.  We could have decoded the MD
1458
            -- and loaded the IR simultaneously.
1459
            --  IR <- MD
1460
            --
1461
 
1462
            when stateLoadIR =>
1463
                irOP      <= iropMD;
1464
                nextState <= stateDecodeInstruction;
1465
 
1466
            --
1467
            -- Decode Instruction in IR
1468
            --
1469
 
1470
            when stateDecodeInstruction =>
1471
 
1472
                --
1473
                -- Default Next State
1474
                --
1475
 
1476
                nextState <= stateLALA;
1477
 
1478
                --
1479
                -- Parse OPCODE
1480
                --
1481
 
1482
                case IR(0 to 2) is
1483
 
1484
                    --
1485
                    -- AND Instruction
1486
                    --
1487
 
1488
                    when opAND =>
1489
 
1490
                        case IR(3 to 4) is
1491
 
1492
                            --
1493
                            -- AND, direct, zero page.  Start Read Addr Cycle
1494
                            --  MA <- 00000'IR(5:11)
1495
                            --
1496
 
1497
                            when amDZ =>
1498
                                maOP      <= maopZP;
1499
                                xmaOP     <= xmaopIF;
1500
                                busOP     <= busopRDIFaddr;
1501
                                nextState <= stateMRIreadAddr;
1502
 
1503
                            --
1504
                            -- AND, direct, curr page.  Start Read Addr Cycle
1505
                            --  MA <- MA(0:4)'IR(5:11)
1506
                            --
1507
 
1508
                            when amDC =>
1509
                                maOP      <= maopCP;
1510
                                xmaOP     <= xmaopIF;
1511
                                busOP     <= busopRDIFaddr;
1512
                                nextState <= stateMRIreadAddr;
1513
 
1514
                            --
1515
                            -- AND, indirect, zero page.  Start Read Addr Cycle
1516
                            --  MA <- 00000'IR(5:11)
1517
                            --
1518
 
1519
                            when amIZ =>
1520
                                maOP      <= maopZP;
1521
                                xmaOP     <= xmaopIF;
1522
                                busOP     <= busopRDIFaddr;
1523
                                nextState <= stateMRIreadAddr;
1524
 
1525
                            --
1526
                            -- AND, indirect, curr page.  Start Read Addr Cycle
1527
                            --  MA <- MA(0:4)'IR(5:11)
1528
                            --
1529
 
1530
                            when amIC =>
1531
                                maOP      <= maopCP;
1532
                                xmaOP     <= xmaopIF;
1533
                                busOP     <= busopRDIFaddr;
1534
                                nextState <= stateMRIreadAddr;
1535
 
1536
                            --
1537
                            -- Everthing else
1538
                            --
1539
 
1540
                            when others =>
1541
                                null;
1542
 
1543
                        end case;
1544
 
1545
                    --
1546
                    -- TAD Instruction
1547
                    --
1548
 
1549
                    when opTAD =>
1550
 
1551
                        case IR(3 to 4) is
1552
 
1553
                            --
1554
                            -- TAD, direct, zero page.  Start Read Addr Cycle
1555
                            --  MA <- 00000'IR(5:11)
1556
                            --
1557
 
1558
                            when amDZ =>
1559
                                maOP      <= maopZP;
1560
                                xmaOP     <= xmaopIF;
1561
                                busOP     <= busopRDIFaddr;
1562
                                nextState <= stateMRIreadAddr;
1563
 
1564
                            --
1565
                            -- TAD, direct, curr page.  Start Read Addr Cycle
1566
                            --  MA <- MA(0:4)'IR(5:11)
1567
                            --
1568
 
1569
                            when amDC =>
1570
                                maOP      <= maopCP;
1571
                                xmaOP     <= xmaopIF;
1572
                                busOP     <= busopRDIFaddr;
1573
                                nextState <= stateMRIreadAddr;
1574
 
1575
                            --
1576
                            -- TAD, indirect, zero page.  Start Read Addr Cycle
1577
                            --  MA <- 00000'IR(5:11)
1578
                            --
1579
 
1580
                            when amIZ =>
1581
                                maOP      <= maopZP;
1582
                                xmaOP     <= xmaopIF;
1583
                                busOP     <= busopRDIFaddr;
1584
                                nextState <= stateMRIreadAddr;
1585
 
1586
                            --
1587
                            -- TAD, indirect, curr page.  Start Read Addr Cycle
1588
                            --  MA <- MA(0:4)'IR(5:11)
1589
                            --
1590
 
1591
                            when amIC =>
1592
                                maOP      <= maopCP;
1593
                                xmaOP     <= xmaopIF;
1594
                                busOP     <= busopRDIFaddr;
1595
                                nextState <= stateMRIreadAddr;
1596
 
1597
                            --
1598
                            -- Everything else
1599
                            --
1600
 
1601
                            when others =>
1602
                                null;
1603
 
1604
                        end case;
1605
 
1606
                    --
1607
                    -- ISZ Instruction
1608
                    --
1609
 
1610
                    when opISZ =>
1611
 
1612
                        case IR(3 to 4) is
1613
 
1614
                            --
1615
                            -- ISZ, direct, zero page.  Start Read Addr Cycle
1616
                            --  MA <- 00000'IR(5:11)
1617
                            --
1618
 
1619
                            when amDZ =>
1620
                                maOP      <= maopZP;
1621
                                xmaOP     <= xmaopIF;
1622
                                busOP     <= busopRDIFaddr;
1623
                                nextState <= stateMRIreadAddr;
1624
 
1625
                            --
1626
                            -- ISZ, direct, curr page.  Start Read Addr Cycle
1627
                            --  MA <- MA(0:4)'IR(5:11)
1628
                            --
1629
 
1630
                            when amDC =>
1631
                                maOP      <= maopCP;
1632
                                xmaOP     <= xmaopIF;
1633
                                busOP     <= busopRDIFaddr;
1634
                                nextState <= stateMRIreadAddr;
1635
 
1636
                            --
1637
                            -- ISZ, indirect, zero page.  Start Read Addr Cycle
1638
                            --  MA <- 00000'IR(5:11)
1639
                            --
1640
 
1641
                            when amIZ =>
1642
                                maOP      <= maopZP;
1643
                                xmaOP     <= xmaopIF;
1644
                                busOP     <= busopRDIFaddr;
1645
                                nextState <= stateMRIreadAddr;
1646
 
1647
                            --
1648
                            -- ISZ, indirect, curr page.  Start Read Addr Cycle
1649
                            --  MA <- MA(0:4)'IR(5:11)
1650
                            --
1651
 
1652
                            when amIC =>
1653
                                maOP      <= maopCP;
1654
                                xmaOP     <= xmaopIF;
1655
                                busOP     <= busopRDIFaddr;
1656
                                nextState <= stateMRIreadAddr;
1657
 
1658
                            --
1659
                            -- Everything else
1660
                            --
1661
 
1662
                            when others =>
1663
                                null;
1664
 
1665
                        end case;
1666
 
1667
                    --
1668
                    -- MRI DCA
1669
                    --
1670
 
1671
                    when opDCA =>
1672
 
1673
                        case IR(3 to 4) is
1674
 
1675
                            --
1676
                            -- DCA, direct, zero page.  Start Write Cycle
1677
                            --  MA <- 00000'IR(5:11)
1678
                            --
1679
 
1680
                            when amDZ =>
1681
                                wrOP      <= '1';
1682
                                acOP      <= acopCLA;
1683
                                maOP      <= maopZP;
1684
                                mbOP      <= mbopAC;
1685
                                xmaOP     <= xmaopIF;
1686
                                busOP     <= busopRDIFaddr;
1687
                                nextState <= stateDone;
1688
 
1689
                            --
1690
                            -- DCA, direct, curr page.  Start Write Cycle
1691
                            --  MA <- MA(0:4)'IR(5:11)
1692
                            --
1693
 
1694
                            when amDC =>
1695
                                wrOP      <= '1';
1696
                                acOP      <= acopCLA;
1697
                                maOP      <= maopCP;
1698
                                mbOP      <= mbopAC;
1699
                                xmaOP     <= xmaopIF;
1700
                                busOP     <= busopRDIFaddr;
1701
                                nextState <= stateDone;
1702
 
1703
                            --
1704
                            -- DCA, indirect, zero page.  Start Read Addr Cycle.
1705
                            --  MA <- 00000'IR(5:11)
1706
                            --
1707
 
1708
                            when amIZ =>
1709
                                maOP      <= maopZP;
1710
                                xmaOP     <= xmaopIF;
1711
                                busOP     <= busopRDIFaddr;
1712
                                nextState <= stateMRIreadAddr;
1713
 
1714
                            --
1715
                            -- DCA, indirect, curr page.  Start Read Addr Cycle.
1716
                            --  MA <- MA(0:4)'IR(5:11)
1717
                            --
1718
 
1719
                            when amIC =>
1720
                                maOP      <= maopCP;
1721
                                xmaOP     <= xmaopIF;
1722
                                busOP     <= busopRDIFaddr;
1723
                                nextState <= stateMRIreadAddr;
1724
 
1725
                            --
1726
                            -- Everything else
1727
                            --
1728
 
1729
                            when others =>
1730
                                 null;
1731
 
1732
                        end case;
1733
 
1734
                    --
1735
                    -- JMS Instruction
1736
                    --
1737
 
1738
                    when opJMS =>
1739
 
1740
                        --
1741
                        -- The II Flip-Flop is cleared.
1742
                        -- The FZ Flip-Flop is cleared
1743
                        --
1744
 
1745
                        iiOP <= iiopCLR;
1746
                        fzOP <= fzopCLR;
1747
 
1748
                        case IR(3 to 4) is
1749
 
1750
                            --
1751
                            -- JMS, direct, zero page.  Start write cycle.
1752
                            --  MA <- 00000'IR(5:11)
1753
                            --
1754
                            -- When the PEX Flip-flop is set, the CPU shall
1755
                            -- exit from Panel Mode to Main Memory (i.e., clear
1756
                            -- CTRLFF) during the next JMP, JMS, RTN1 or RTN2
1757
                            -- instruction.
1758
                            --
1759
                            -- PEX is cleared by the JMP, JMS, RTN1 or RTN2
1760
                            -- instruction.
1761
                            --
1762
 
1763
                            when amDZ =>
1764
                                ifOP      <= ifopIB;
1765
                                ufOP      <= ufopUB;
1766
                                maOP      <= maopZP;
1767
                                mbOP      <= mbopPC;
1768
                                pcOP      <= pcopZPP1;
1769
                                xmaOP     <= xmaopIB;
1770
                                busOP     <= busopWRIB;
1771
                                if PEX = '1' then
1772
                                    ctrlffOP <= ctrlffopCLR;
1773
                                    pexOP    <= pexopCLR;
1774
                                end if;
1775
                                nextState <= stateDone;
1776
 
1777
                            --
1778
                            -- JMS, direct, curr page.  Start write cycle.
1779
                            --  MA <- MA(0:4)'IR(5:11)
1780
                            --
1781
                            -- When the PEX Flip-flop is set, the CPU shall
1782
                            -- exit from Panel Mode to Main Memory (i.e., clear
1783
                            -- CTRLFF) during the next JMP, JMS, RTN1 or RTN2
1784
                            -- instruction.
1785
                            --
1786
                            -- PEX is cleared by the JMP, JMS, RTN1 or RTN2
1787
                            -- instruction.
1788
                            --
1789
 
1790
                            when amDC =>
1791
                                ifOP      <= ifopIB;
1792
                                ufOP      <= ufopUB;
1793
                                maOP      <= maopCP;
1794
                                mbOP      <= mbopPC;
1795
                                pcOP      <= pcopCPP1;
1796
                                xmaOP     <= xmaopIB;
1797
                                busOP     <= busopWRIB;
1798
                                if PEX = '1' then
1799
                                    ctrlffOP <= ctrlffopCLR;
1800
                                    pexOP    <= pexopCLR;
1801
                                end if;
1802
                                nextState <= stateDone;
1803
 
1804
                            --
1805
                            -- JMS, indirect, zero page.  Start Read Addr Cycle.
1806
                            --  MA <- 00000'IR(5:11)
1807
                            --
1808
 
1809
                            when amIZ =>
1810
                                maOP      <= maopZP;
1811
                                xmaOP     <= xmaopIF;
1812
                                busOP     <= busopRDIFaddr;
1813
                                nextState <= stateMRIreadAddr;
1814
 
1815
                            --
1816
                            -- JMS, indirect, curr page.  Start Read Addr Cycle.
1817
                            --  MA <- MA(0:4)'IR(5:11)
1818
                            --
1819
 
1820
                            when amIC =>
1821
                                maOP      <= maopCP;
1822
                                xmaOP     <= xmaopIF;
1823
                                busOP     <= busopRDIFaddr;
1824
                                nextState <= stateMRIreadAddr;
1825
 
1826
                            --
1827
                            -- Everthing else
1828
                            --
1829
 
1830
                            when others =>
1831
                                null;
1832
 
1833
                        end case;
1834
 
1835
                    --
1836
                    -- JMP Instruction
1837
                    --
1838
 
1839
                    when opJMP =>
1840
 
1841
                        --
1842
                        -- The II Flip-Flop is cleared.
1843
                        -- The FZ Flip-Flop is cleared
1844
                        --
1845
 
1846
                        iiOP <= iiopCLR;
1847
                        fzOP <= fzopCLR;
1848
 
1849
                        case IR(3 to 4) is
1850
 
1851
                            --
1852
                            --
1853
                            -- JMP, direct, zero page.
1854
                            --  MA <- 00000'IR(5:11)
1855
                            --
1856
                            -- When the PEX Flip-flop is set, the CPU shall
1857
                            -- exit from Panel Mode to Main Memory (i.e., clear
1858
                            -- CTRLFF) during the next JMP, JMS, RTN1 or RTN2
1859
                            -- instruction.
1860
                            --
1861
                            -- PEX is cleared by the JMP, JMS, RTN1 or RTN2
1862
                            -- instruction.
1863
                            --
1864
 
1865
                            when amDZ =>
1866
                                maOP <= maopZP;
1867
                                pcOP <= pcopZP;
1868
                                ifOP <= ifopIB;
1869
                                ufOP <= ufopUB;
1870
                                if PEX = '1' then
1871
                                    ctrlffOP <= ctrlffopCLR;
1872
                                    pexOP    <= pexopCLR;
1873
                                end if;
1874
                                nextState <= stateDone;
1875
 
1876
                            --
1877
                            -- JMP, direct, curr page.
1878
                            --  MA <- MA(0:4)'IR(5:11)
1879
                            --
1880
                            -- When the PEX Flip-flop is set, the CPU shall
1881
                            -- exit from Panel Mode to Main Memory (i.e., clear
1882
                            -- CTRLFF) during the next JMP, JMS, RTN1 or RTN2
1883
                            -- instruction.
1884
                            --
1885
                            -- PEX is cleared by the JMP, JMS, RTN1 or RTN
1886
                            -- instruction.
1887
                            --
1888
 
1889
                            when amDC =>
1890
                                maOP <= maopCP;
1891
                                pcOP <= pcopCP;
1892
                                ifOP <= ifopIB;
1893
                                ufOP <= ufopUB;
1894
                                if PEX = '1' then
1895
                                    ctrlffOP <= ctrlffopCLR;
1896
                                    pexOP    <= pexopCLR;
1897
                                end if;
1898
                                nextState <= stateDone;
1899
 
1900
                            --
1901
                            -- JMP, indirect, zero page.  Start Read Addr Cycle.
1902
                            --  MA <- 00000'IR(5:11)
1903
                            --
1904
 
1905
                            when amIZ =>
1906
                                maOP      <= maopZP;
1907
                                xmaOP     <= xmaopIF;
1908
                                busOP     <= busopRDIFaddr;
1909
                                nextState <= stateMRIreadAddr;
1910
 
1911
                            --
1912
                            -- JMP, indirect, curr page.  Start Read Addr Cycle.
1913
                            --  MA <- MA(0:4)'IR(5:11)
1914
                            --
1915
 
1916
                            when amIC =>
1917
                                maOP      <= maopCP;
1918
                                xmaOP     <= xmaopIF;
1919
                                busOP     <= busopRDIFaddr;
1920
                                nextState <= stateMRIreadAddr;
1921
 
1922
                            --
1923
                            -- Everything else
1924
                            --
1925
 
1926
                            when others =>
1927
                                null;
1928
 
1929
                        end case;
1930
 
1931
                    --
1932
                    -- IOT Instructions
1933
                    --
1934
 
1935
                    when opIOT =>
1936
 
1937
                        --
1938
                        -- Default Next State
1939
                        --
1940
 
1941
                        nextState <= stateDone;
1942
 
1943
                        --
1944
                        -- Handle USR Mode interrupts
1945
                        --
1946
 
1947
                        if (UF = '1') then
1948
 
1949
                            usrtrpOP  <= usrtrpopSET;
1950
                            nextState <= stateDone;
1951
 
1952
                        else
1953
 
1954
                            --
1955
                            -- Internal IOT (CPU Control)
1956
                            --   600x, 62xx are internal IOTs
1957
                            --
1958
 
1959
                            case IR(0 to 11) is
1960
 
1961
                                --
1962
                                -- OP 6000: PRS/SKON
1963
                                --
1964
 
1965
                                when o"6000" =>
1966
 
1967
                                    --
1968
                                    -- HD6120 only
1969
                                    -- OP 6000: PRS - Panel Read Status Word.
1970
                                    -- Read panel status bits into AC<0-4>, 0
1971
                                    -- into AC<5:11>.  Following the reading of
1972
                                    -- the flags into the AC, the flags are
1973
                                    -- cleared, with the exception of HLTTRP.
1974
                                    -- BTSTR is cleared only if a 1 was read
1975
                                    -- into AC<0>.
1976
                                    --
1977
 
1978
                                    if swCPU = swHD6120 then
1979
                                        if CTRLFF = '1' then
1980
                                            acOP     <= acopPRS;
1981
                                            pnltrpOP <= pnltrpopCLR;
1982
                                            pwrtrpOP <= pwrtrpopCLR;
1983
                                            btstrpOP <= btstrpopCLR;
1984
                                        end if;
1985
 
1986
                                    --
1987
                                    -- PDP-8/E and later and HD-6120
1988
                                    -- SKON - Skip if interupt system is on,
1989
                                    -- turn it off.
1990
                                    --
1991
 
1992
                                    elsif ((swCPU = swPDP8E) or
1993
                                           (swCPU = swPDP8F) or
1994
                                           (swCPU = swPDP8A) or
1995
                                           (swCPU = swHD6120)) then
1996
                                        if IE = '1' then
1997
                                            pcOP <= pcopINC;
1998
                                        end if;
1999
                                        ieOP <= ieopCLR;
2000
 
2001
                                    --
2002
                                    -- Pre PDP8/E
2003
                                    -- This instruction was a NOP.
2004
                                    --
2005
 
2006
                                    else
2007
                                        null;
2008
 
2009
                                    end if;
2010
 
2011
                                --
2012
                                -- IOT 6001: ION - Enable Interrupts.
2013
                                -- The Interrupt Enable Flip-Flop (IE) is set.
2014
                                -- The Interrupt Enable Delay Flip-Flop (ID)
2015
                                -- is set.
2016
                                --
2017
                                -- Note: Setting the ID delays the interrupt
2018
                                -- enable by one instruction so that a return
2019
                                -- (from interrupt) may be executed before the
2020
                                -- next interrupt request is serviced.
2021
                                --
2022
 
2023
                                when o"6001" =>
2024
                                    ieOP <= ieopSET;
2025
                                    idOP <= idopSET;
2026
 
2027
                                --
2028
                                -- IOT 6002: IOF - Disable Interrupts
2029
                                -- The Interrupt Enable Flip Flop (IE) is cleared
2030
                                -- immediately. If IRQ is low while this
2031
                                -- instruction is being processed, the interrupt
2032
                                -- will not be recognized.
2033
                                --
2034
 
2035
                                when o"6002" =>
2036
                                    ieOP <= ieopCLR;
2037
 
2038
                                --
2039
                                -- OP 6003: PGO/SRQ
2040
                                --
2041
 
2042
                                when o"6003" =>
2043
 
2044
                                    --
2045
                                    -- HD6120 only
2046
                                    -- OP 6003: PGO - Panel Go.
2047
                                    --
2048
 
2049
                                    if swCPU = swHD6120 then
2050
                                        if CTRLFF = '1' then
2051
                                            hlttrpOP <= hlttrpopCLR;
2052
                                        end if;
2053
 
2054
                                    --
2055
                                    -- PDP-8/E and later and HD-6120
2056
                                    -- OP 6003: SRQ - Skip on Interupt Request
2057
                                    --
2058
 
2059
                                    elsif ((swCPU = swPDP8E) or
2060
                                           (swCPU = swPDP8F) or
2061
                                           (swCPU = swPDP8A) or
2062
                                           (swCPU = swHD6120)) then
2063
                                        if IRQ = '1' then
2064
                                            pcOP <= pcopINC;
2065
                                        end if;
2066
 
2067
                                    --
2068
                                    -- Pre PDP-8/E
2069
                                    -- OP 6003: ION - This was equivalent to
2070
                                    -- the ION instruction.
2071
                                    --
2072
 
2073
                                    else
2074
                                        ieOP <= ieopSET;
2075
                                        idOP <= idopSET;
2076
 
2077
                                    end if;
2078
 
2079
                                --
2080
                                -- IOT 6004: PEX/GTF
2081
                                --
2082
                                -- GTF - Get Flags
2083
                                --
2084
                                --  00 01 02 03 04 05 06 07 08 09 10 11
2085
                                -- +--+--+--+--+--+--+--------+--------+
2086
                                -- | L|GT|IR|0 |IE|UF|   IF   |   DF   |
2087
                                -- +--+--+--+--+--+--+--------+--------+
2088
                                --
2089
                                -- L  - The link bit.
2090
                                -- GT - The Greater Than bit
2091
                                -- IR - The interrupt request status, as tested by SRQ.
2092
                                -- IE - The state of the interrupt enable flip-flop (IE)
2093
                                -- UF - User Flag
2094
                                -- IF - The instruction field.
2095
                                -- DF - The data field.
2096
                                --
2097
                                -- PEX -  Panel Exit to Normal Mode
2098
                                -- Exit from panel mode into main memory at the end
2099
                                -- of the next JMP, JMS, RTN1 or RTN2 instruction.
2100
                                --
2101
 
2102
                                when o"6004" =>
2103
 
2104
                                    --
2105
                                    -- OP 6004: PEX - Panel Exit to Normal Mode
2106
                                    -- HD6120 in Panel Mode only
2107
                                    --
2108
                                    -- Set PEX Flip-flop
2109
                                    -- Clear PWRTRP and PNLTRP.
2110
                                    --
2111
 
2112
                                    if swCPU = swHD6120 and CTRLFF = '1' then
2113
                                        pwrtrpOP <= pwrtrpopCLR;
2114
                                        pnltrpOP <= pnltrpopCLR;
2115
                                        pexOP    <= pexopSET;
2116
 
2117
                                    --
2118
                                    -- OP 6004: GTF - Get Flags
2119
                                    -- HD6120 in Normal Mode only
2120
                                    -- AC(4) is always set.
2121
                                    -- AC(5) is always cleared.
2122
                                    --
2123
 
2124
                                    elsif swCPU = swHD6120 and CTRLFF = '0' then
2125
                                        acOP <= acopGTF1;
2126
 
2127
                                    --
2128
                                    -- OP 6004: GTF - Get Flags
2129
                                    -- PDP-8/E and later with KM8E installed
2130
                                    -- AC(4) is set to state of the interrupt
2131
                                    --
2132
 
2133
                                    elsif ((swCPU = swPDP8E and swOPT.KM8E = '1') or
2134
                                           (swCPU = swPDP8F and swOPT.KM8E = '1') or
2135
                                           (swCPU = swPDP8A and swOPT.KM8E = '1')) then
2136
                                        acOP <= acopGTF2;
2137
 
2138
                                    --
2139
                                    -- Pre PDP-8/E
2140
                                    -- OP 6004: This was and ADC operation or a
2141
                                    -- NOP.
2142
                                    --
2143
 
2144
                                    else
2145
                                        null;
2146
 
2147
                                    end if;
2148
 
2149
                                --
2150
                                -- IOT 6005: RTF - Restore Flags and Fields from AC.
2151
                                -- The flags are set as follows:
2152
                                --
2153
                                --  00 01 02 03 04 05 06 07 08 09 10 11
2154
                                -- +--+--+--+--+--+--+--------+--------+
2155
                                -- | L|GT|  |  |IE|UB|   IB   |   DF   |
2156
                                -- +--+--+--+--+--+--+--------+--------+
2157
                                --
2158
 
2159
                                when o"6005" =>
2160
                                    if ((swCPU = swPDP8E) or
2161
                                        (swCPU = swPDP8F) or
2162
                                        (swCPU = swPDP8A) or
2163
                                        (swCPU = swHD6120)) then
2164
 
2165
                                        --
2166
                                        -- HD6120: The AC is cleared following
2167
                                        -- the load operation.  The interrupt
2168
                                        -- is enabled per AC(4).  See HD6120
2169
                                        -- GTF instruction.
2170
                                        --
2171
 
2172
                                        if swCPU = swHD6120 then
2173
 
2174
                                            if AC(0) = '1' then
2175
                                                acOP <= acopCLACLLCML;
2176
                                            else
2177
                                                acOP <= acopCLACLL;
2178
                                            end if;
2179
 
2180
                                            if AC(4) = '1' then
2181
                                                ieOP <= ieopSET;
2182
                                                iiOP <= iiopSET;
2183
                                            end if;
2184
 
2185
                                        --
2186
                                        -- PDP8/E and later: AC is not modified by
2187
                                        -- the instruction. AC(4) is ignored and
2188
                                        -- interrupts are unconditionally
2189
                                        -- re-enabled.  AC(5) sets the UB bit.
2190
                                        -- See PDP/8 GTF instruction.
2191
                                        --
2192
 
2193
                                        else
2194
 
2195
                                            if AC(0) = '1' then
2196
                                                acOP <= acopCLLCML;
2197
                                            else
2198
                                                acOP <= acopCLL;
2199
                                            end if;
2200
                                            ieOP <= ieopSET;
2201
                                            iiOP <= iiopSET;
2202
                                            ubOP <= ubopAC5;
2203
                                        end if;
2204
 
2205
                                        gtfOP <= gtfopAC1;
2206
                                        ibOP  <= ibopAC6to8;
2207
                                        dfOP  <= dfopAC9to11;
2208
                                        fzop  <= fzopCLR;
2209
 
2210
                                    --
2211
                                    -- Pre PDP8/E
2212
                                    -- OP 6005: ION ORed with ADC
2213
                                    --
2214
 
2215
                                    else
2216
                                        ieOP <= ieopSET;
2217
                                        idOP <= idopSET;
2218
 
2219
                                    end if;
2220
 
2221
                                --
2222
                                -- OP 6006: SGT
2223
                                --
2224
 
2225
                                when o"6006" =>
2226
 
2227
                                    --
2228
                                    -- PDP8/E and later
2229
                                    -- OP 6006: SGT - Skip if the GT flag is set.
2230
                                    --
2231
 
2232
                                    if ((swCPU = swPDP8E) or
2233
                                        (swCPU = swPDP8F) or
2234
                                        (swCPU = swPDP8A) or
2235
                                        (swCPU = swHD6120)) then
2236
                                        if GTF = '1' then
2237
                                            pcOP <= pcopINC;
2238
                                        end if;
2239
 
2240
                                    --
2241
                                    -- Pre PDP8/E
2242
                                    -- OP 6006: This was equivalent to an IOF
2243
                                    -- ORed with and ADC op
2244
                                    --
2245
 
2246
                                    else
2247
                                        ieOP <= ieopCLR;
2248
 
2249
                                    end if;
2250
 
2251
                                --
2252
                                -- OP 6007: CAF - Clear all flags.
2253
                                --
2254
 
2255
                                when o"6007" =>
2256
 
2257
                                    --
2258
                                    -- PDP8/E and Later
2259
                                    -- IOT 6007: CAF - Clear all flags.
2260
                                    -- The AC, LINK and GT flag are cleared.
2261
                                    -- Interrupt Enable Flip Flop (IE) is cleared.
2262
                                    -- IOCLR is generated with LXDAR high, causing
2263
                                    -- peripheral devices to clear their flags.
2264
                                    --
2265
 
2266
                                    if ((swCPU = swPDP8E) or
2267
                                        (swCPU = swPDP8F) or
2268
                                        (swCPU = swPDP8A) or
2269
                                        (swCPU = swHD6120)) then
2270
                                        gtfOP     <= gtfopCLR;
2271
                                        acOP      <= acopCLACLL;
2272
                                        emodeOP   <= emodeopCLR;
2273
                                        ieOP      <= ieopCLR;
2274
                                        idOP      <= idopSET;
2275
                                        busOP     <= busopIOCLR;
2276
                                        usrtrpOP  <= usrtrpopCLR;
2277
 
2278
                                    --
2279
                                    -- Pre PDP8/E
2280
                                    -- OP 6007: ION ORed with ADC
2281
                                    --
2282
 
2283
                                    else
2284
                                        ieOP <= ieopSET;
2285
                                        idOP <= idopSET;
2286
 
2287
                                    end if;
2288
 
2289
                                --
2290
                                -- IOT 6200: LXM - Load Extended Mode Register
2291
                                -- On all machines without KT8-A this is executed
2292
                                -- as a NOP instruction.
2293
                                --
2294
 
2295
                                when o"6200" =>
2296
                                    null;
2297
 
2298
                                --
2299
                                -- IOT 62x1: CDF - Change Data Field
2300
                                -- The Data Field Register (DF) is loaded with IR<6:8>
2301
                                -- of this instruction.
2302
                                --
2303
 
2304
                                when o"6201" | o"6211" | o"6221" | o"6231" | o"6241" | o"6251" | o"6261" | o"6271" =>
2305
                                    dfOP <= dfopIR6to8;
2306
 
2307
                                --
2308
                                -- IOT 62x2: CIF - Change Instruction Field
2309
                                -- The Instruction Buffer (IB/IB) is loaded with
2310
                                -- IR<6:8> of this instruction and the Interrupt
2311
                                -- Inhibit Flip Flop (II) is set.
2312
                                --
2313
                                -- Note: Setting the II causes the CPU to ignore
2314
                                -- interrupt requests until the next JMP, JMS,
2315
                                -- RTN1 or RTN2 Instruction is executed.  At that
2316
                                -- time the contents of IB/IB are loaded into the
2317
                                -- IF/INF and the II cleared.
2318
                                --
2319
 
2320
                                when o"6202" | o"6212" | o"6222" | o"6232" | o"6242" | o"6252" | o"6262" | o"6272" =>
2321
                                    ibOP <= ibopIR6to8;
2322
                                    iiOP <= iiopSET;
2323
                                    fzop <= fzopCLR;
2324
 
2325
                                --
2326
                                -- IOT 62x2: CIF/CDF (CDI) - Change Instruction
2327
                                -- and Data Field.
2328
                                -- A microprogrammed combination of CDF and CIF.
2329
                                -- Both fields are set to X.
2330
                                --
2331
 
2332
                                when o"6203" | o"6213" | o"6223" | o"6233" | o"6243" | o"6253" | o"6263" | o"6273" =>
2333
                                    dfOP <= dfopIR6to8;
2334
                                    ibOP <= ibopIR6to8;
2335
                                    iiOP <= iiopSET;
2336
                                    fzop <= fzopCLR;
2337
 
2338
                                --
2339
                                -- IOT 6204: CINT - Clear User Interrupt Flag
2340
                                --
2341
 
2342
                                when o"6204" =>
2343
                                    usrtrpOP <= usrtrpopCLR;
2344
 
2345
                                --
2346
                                -- IOT 6205: PPC1 - Push (PC+1) to Stack 1
2347
                                -- The contents of the PC are incremented by
2348
                                -- one and the result is loaded into the memory
2349
                                -- location pointed to by the contents of SP1.
2350
                                -- SP1 is then decremented by 1.
2351
                                --
2352
                                -- The stacks are located in field 0 of memory.
2353
                                --
2354
 
2355
                                when o"6205" =>
2356
                                    if swCPU = swHD6120 then
2357
                                        maOP     <= maopSP1;
2358
                                        mbOP     <= mbopPCP1;
2359
                                        sp1OP    <= spopDEC;
2360
                                        xmaOP    <= xmaopCLR;
2361
                                        busOP    <= busopWRZF;
2362
                                    end if;
2363
 
2364
                                --
2365
                                -- IOT 6206: PR0 - Panel Request 0
2366
                                -- The PNLTRP flag is set.  If the Interrupt Inhibit
2367
                                -- Flip-Flop (ION) is not set, the CPU will enter
2368
                                -- panel mode instead of executing the next
2369
                                -- instruction.  If the Interrupt Inhibit Flip Flop
2370
                                -- is set, panel mode will be entered following the
2371
                                -- next JMP, JMS, RTN1 or RTN2 which clears the
2372
                                -- Interrupt inhibit flip flop.  This is a NOP in
2373
                                -- panel mode.
2374
                                --
2375
 
2376
                                when o"6206" =>
2377
                                    if swCPU = swHD6120 then
2378
                                        if CTRLFF = '0' then
2379
                                            pnltrpOP <= pnltrpopSET;
2380
                                        end if;
2381
                                    end if;
2382
 
2383
                                --
2384
                                -- IOT 6207: RSP1 - Read Stack 1 Pointer to AC
2385
                                -- The contents of SP1 is loaded Into the AC.
2386
                                --
2387
 
2388
                                when o"6207" =>
2389
                                    if swCPU = swHD6120 then
2390
                                        acOP <= acopSP1;
2391
                                    end if;
2392
 
2393
                                --
2394
                                -- IOT 6214: RDF - Read Data Field to AC<6:8>
2395
                                -- PDP8: The RDF ors the DF register with AC<6:8>.
2396
                                -- HD6120: The RDF replaces AC<6:8> with DF<0:2>.
2397
                                -- The other bits of the accumulator are unaffected
2398
                                --
2399
 
2400
                                when o"6214" =>
2401
                                    if swCPU = swHD6120 then
2402
                                        acOP <= acopRDF0;
2403
                                    else
2404
                                        acOP <= acopRDF1;
2405
                                    end if;
2406
 
2407
                                --
2408
                                -- IOT 6215: PAC1 - Push AC to Stack 1.
2409
                                -- The contents of the AC is loaded into the
2410
                                -- memory location pointed to by the contents
2411
                                -- of SP1. The contents of SP1 is then
2412
                                -- decremented by 1.
2413
                                --
2414
                                -- The stacks are located in field 0 of memory.
2415
                                --
2416
 
2417
                                when o"6215" =>
2418
                                    if swCPU = swHD6120 then
2419
                                        maOP     <= maopSP1;
2420
                                        mbOP     <= mbopAC;
2421
                                        sp1OP    <= spopDEC;
2422
                                        xmaOP    <= xmaopCLR;
2423
                                        busOP    <= busopWRZF;
2424
                                    end if;
2425
 
2426
                                --
2427
                                -- IOT 6216: PR1 - Panel Request 1.
2428
                                -- The PNLTRP flag is set.  If the Interrupt Inhibit
2429
                                -- Flip-Flop (ION) is not set, the CPU will enter
2430
                                -- panel mode instead of executing the next
2431
                                -- instruction.  If the Interrupt Inhibit Flip Flop
2432
                                -- is set, panel mode will be entered following the
2433
                                -- next JMP, JMS, RTN1 or RTN2 which clears the
2434
                                -- Interrupt inhibit flip flop.  This is a NOP in
2435
                                -- panel mode.
2436
                                --
2437
 
2438
                                when o"6216" =>
2439
                                    if swCPU = swHD6120 then
2440
                                        if CTRLFF = '0' then
2441
                                            pnltrpOP  <= pnltrpopSET;
2442
                                        end if;
2443
                                    end if;
2444
 
2445
                                --
2446
                                -- IOT 6217: LSP1 - Load Stack 1 Pointer from AC.
2447
                                -- The contents of the AC is loaded into SP1.
2448
                                -- The AC is cleared.
2449
                                --
2450
 
2451
                                when o"6217" =>
2452
                                    if swCPU = swHD6120 then
2453
                                        sp1OP <= spopAC;
2454
                                        acOP  <= acopCLA;
2455
                                    end if;
2456
 
2457
                                --
2458
                                -- IOT 6224: RIF - Read Instruction Field into AC<6:8>.
2459
                                -- PDP8: The RIF ors the IF/INF register with AC<6:8>.
2460
                                -- HD6120: The RIF replaces AC<6:8> with IF/INF<0:2>.
2461
                                -- The other bits of the accumulator are unaffected
2462
                                --
2463
 
2464
                                when o"6224" =>
2465
                                    if swCPU = swHD6120 then
2466
                                        acOP <= acopRIF0;
2467
                                    else
2468
                                        acOP <= acopRIF1;
2469
                                    end if;
2470
 
2471
                                --
2472
                                -- IOT 6225: RTN1 - Pop top of Stack 1 to PC
2473
                                --
2474
                                -- The contents of the stack pointer (SP1) is
2475
                                -- incremented by one.  The contents of the
2476
                                -- memory location pointed to by SP1 is loaded
2477
                                -- into the PC.
2478
                                --
2479
 
2480
                                when o"6225" =>
2481
                                    if swCPU = swHD6120 then
2482
                                        sp1OP     <= spopINC;
2483
                                        nextState <= stateRTN1;
2484
                                    end if;
2485
 
2486
                                --
2487
                                -- IOT 6226: PR2 - Panel Request 2.
2488
                                -- The PNLTRP flag is set.  If the Interrupt Inhibit
2489
                                -- Flip-Flop (ION) is not set, the CPU will enter
2490
                                -- panel mode instead of executing the next
2491
                                -- instruction.  If the Interrupt Inhibit Flip Flop
2492
                                -- is set, panel mode will be entered following the
2493
                                -- next JMP, JMS, RTN1 or RTN2 which clears the
2494
                                -- Interrupt inhibit flip flop.  This is a NOP in
2495
                                -- panel mode.
2496
                                --
2497
 
2498
                                when o"6226" =>
2499
                                    if swCPU = swHD6120 then
2500
                                        if CTRLFF = '0' then
2501
                                            pnltrpOP <= pnltrpopSET;
2502
                                        end if;
2503
                                    end if;
2504
 
2505
                                --
2506
                                -- IOT 6227: RSP2 - Read Stack 2 Pointer to AC
2507
                                -- The contents of SP2 is loaded Into the AC.
2508
                                --
2509
 
2510
                                when o"6227" =>
2511
                                    if swCPU = swHD6120 then
2512
                                        acOP <= acopSP2;
2513
                                    end if;
2514
 
2515
                                --
2516
                                -- IOT 6234: RIB - Read Instruction Save Field into AC<6:8>
2517
                                -- and Data Save Field into AC<9:11>.
2518
                                -- PDP8: The RIB ors the ISF/DSF register with AC<6:11>.
2519
                                -- HD6120: The RIB replaces AC<6:11> with ISF/DSF.
2520
                                -- The other bits of the accumulator are unaffected
2521
                                --
2522
 
2523
                                when o"6234" =>
2524
                                    if swCPU = swHD6120 then
2525
                                        acOP <= acopRIB0;
2526
                                    else
2527
                                        acOP <= acopRIB1;
2528
                                    end if;
2529
 
2530
                                --
2531
                                -- IOT 6235: POP1 - Pop top of Stack 1 to AC
2532
                                -- The contents of SP1 is incremented by 1. The
2533
                                -- contents of the memory location pointed to
2534
                                -- by SP1 is then loaded into the AC.
2535
                                --
2536
                                -- The stacks are located in field 0 of memory.
2537
                                --
2538
 
2539
                                when o"6235" =>
2540
                                    if swCPU = swHD6120 then
2541
                                        maOP      <= maopSP1P1;
2542
                                        sp1OP     <= spopINC;
2543
                                        xmaOP     <= xmaopCLR;
2544
                                        busOP     <= busopRDZFaddr;
2545
                                        nextState <= statePOPaddr;
2546
                                    end if;
2547
 
2548
                                --
2549
                                -- IOT 6236: PR3 - Panel Request 3.
2550
                                -- The PNLTRP flag is set.  If the Interrupt Inhibit
2551
                                -- Flip-Flop (ION) is not set, the CPU will enter
2552
                                -- panel mode instead of executing the next
2553
                                -- instruction.  If the Interrupt Inhibit Flip Flop
2554
                                -- is set, panel mode will be entered following the
2555
                                -- next JMP, JMS, RTN1 or RTN2 which clears the
2556
                                -- Interrupt inhibit flip flop.  This is a NOP in
2557
                                -- panel mode.
2558
                                --
2559
 
2560
                                when o"6236" =>
2561
                                    if swCPU = swHD6120 then
2562
                                        if CTRLFF = '0' then
2563
                                            pnltrpOP <= pnltrpopSET;
2564
                                        end if;
2565
                                    end if;
2566
 
2567
                                --
2568
                                -- IOT 6237: LSP2 - Load Stack 2 Pointer from AC.
2569
                                -- The contents of the AC is loaded into SP2.
2570
                                -- The AC is cleared.
2571
                                --
2572
 
2573
                                when o"6237" =>
2574
                                    if swCPU = swHD6120 then
2575
                                        sp2OP <= spopAC;
2576
                                        acOP  <= acopCLA;
2577
                                    end if;
2578
 
2579
                                --
2580
                                -- IOT 6244: RMF - Restore Memory Fields.
2581
                                -- Load the contents of ISF into IB, OSF into OF,
2582
                                -- and set the Interrupt Inhibit Flip Flop. This instruction
2583
                                -- is used to restore the contents of the memory
2584
                                -- field registers to their values before an
2585
                                -- interrupt occurred.
2586
                                --
2587
                                -- Note: Setting the II causes the CPU to ignore
2588
                                -- interrupt requests until the next JMP, JMS,
2589
                                -- RTN1 or RTN2 Instruction is executed.  At that
2590
                                -- time the contents of IB are loaded into the
2591
                                -- IF/INF and the II cleared.
2592
                                --
2593
 
2594
                                when o"6244" =>
2595
                                    ubOP <= ubopSF;
2596
                                    ibOP <= ibopSF1to3;
2597
                                    dfOP <= dfopSF4to6;
2598
                                    iiOP <= iiopSET;
2599
                                    fzop <= fzopCLR;
2600
 
2601
                                --
2602
                                -- IOT 6245: PPC2 - Push (PC+1) to Stack 2
2603
                                -- The contents of the PC are Incremented by
2604
                                -- one and the result is loaded into the memory
2605
                                -- location pointed to by the contents of SP2.
2606
                                -- SP2 is then decremented by 1.
2607
                                --
2608
                                -- The stacks are located in field 0 of memory.
2609
                                --
2610
 
2611
                                when o"6245" =>
2612
                                    if swCPU = swHD6120 then
2613
                                        maOP     <= maopSP2;
2614
                                        mbOP     <= mbopPCP1;
2615
                                        sp2OP    <= spopDEC;
2616
                                        xmaOP    <= xmaopCLR;
2617
                                        busOP    <= busopWRZF;
2618
                                    end if;
2619
 
2620
                                --
2621
                                -- IOT 6246: WSR - Write to Switch Register
2622
                                -- The contents of AC are written to the switch
2623
                                -- register and the AC is cleared.  This allows
2624
                                -- the switch register to be 'virtualized' in
2625
                                -- from panel mode for units without front panel
2626
                                -- interfaces.
2627
                                --
2628
 
2629
                                when o"6246" =>
2630
                                    if swCPU = swHD6120 then
2631
                                        srOP <= sropAC;
2632
                                        acOP <= acopCLA;
2633
                                    end if;
2634
 
2635
                                --
2636
                                -- IOT 6254: SINT - Skip on User Interrupt Flag
2637
                                --
2638
 
2639
                                when o"6254" =>
2640
                                    if USRTRP = '1' then
2641
                                        pcOP <= pcopINC;
2642
                                    end if;
2643
 
2644
                                --
2645
                                -- IOT 6255: PAC2 - Push AC to Stack 2.
2646
                                -- The contents of the AC is loaded into the
2647
                                -- memory location pointed to by the contents
2648
                                -- of SP2. The contents of SP2 is then
2649
                                -- decremented by 1.
2650
                                --
2651
                                -- The stacks are located in field 0 of memory.
2652
                                --
2653
 
2654
                                when o"6255" =>
2655
                                    if swCPU = swHD6120 then
2656
                                        maOP     <= maopSP2;
2657
                                        mbOP     <= mbopAC;
2658
                                        sp1OP    <= spopDEC;
2659
                                        xmaOP    <= xmaopCLR;
2660
                                        busOP    <= busopWRZF;
2661
                                    end if;
2662
 
2663
                                --
2664
                                -- IOT 6256: GCF
2665
                                -- Get current fields and flags
2666
                                --
2667
 
2668
                                when o"6256" =>
2669
                                    acOP <= acopGCF;
2670
 
2671
                                --
2672
                                -- IOF 6264: CUF - Clear User Flag
2673
                                -- The CUF instruction clears the User Flag (UF) and
2674
                                -- sets the Interrupt Inhibit Flip-Flop (II).
2675
                                --
2676
 
2677
                                when o"6264" =>
2678
                                    ubOP <= ubopCLR;
2679
                                    iiOP <= iiopSET;
2680
 
2681
                                --
2682
                                -- IOT 6265: RTN2 - Pop top of Stack 2 to PC
2683
                                --
2684
                                -- The contents of the stack pointer (SP2) is
2685
                                -- incremented by one.  The contents of the
2686
                                -- memory location pointed to by SP2 is loaded
2687
                                -- into the PC.
2688
                                --
2689
 
2690
                                when o"6265" =>
2691
                                    if swCPU = swHD6120 then
2692
                                        sp2op     <= spopINC;
2693
                                        nextState <= stateRTN2;
2694
                                    end if;
2695
 
2696
                                --
2697
                                -- IOT 6266: CPD - Clear Panel Data Flag
2698
                                -- Clears the Panel Data Flag (PDF) so that indirect
2699
                                -- data operands of panel mode instructions are
2700
                                -- obtained from main memory.
2701
                                --
2702
 
2703
                                when o"6266" =>
2704
                                    if swCPU = swHD6120 then
2705
                                        if CTRLFF = '1' then
2706
                                            pdfOP <= pdfopCLR;
2707
                                        end if;
2708
                                    end if;
2709
 
2710
                                --
2711
                                -- IOT 6274: SUF - Set User Flag
2712
                                -- The SUF instruction sets the User Flag (UF) and
2713
                                -- sets the Interrupt Inhibit Flip Flop (II).
2714
                                --
2715
 
2716
                                when o"6274" =>
2717
                                    ubOP <= ubopSET;
2718
                                    iiOP <= iiopSET;
2719
 
2720
                                --
2721
                                -- IOT 6275: POP2 - Pop top of Stack 2 to AC
2722
                                -- The contents of SP2 is incremented by 1. The contents
2723
                                -- of the memory location pointed to by SP2 is then
2724
                                -- loaded into the AC.
2725
                                --
2726
                                -- The stacks are located in field 0 of memory.
2727
                                --
2728
 
2729
                                when o"6275" =>
2730
                                    if swCPU = swHD6120 then
2731
                                        maOP      <= maopSP2P1;
2732
                                        sp2OP     <= spopINC;
2733
                                        xmaOP     <= xmaopCLR;
2734
                                        busOP     <= busopRDZFaddr;
2735
                                        nextState <= statePOPaddr;
2736
                                     end if;
2737
 
2738
                                --
2739
                                -- IOT 6276: SPD - Set Panel Data Flag
2740
                                -- Sets the Panel Data Flag (PDF) so that indirect
2741
                                -- data operands of panel mode instructions are
2742
                                -- obtained from panel memory.
2743
                                --
2744
 
2745
                                when o"6276" =>
2746
                                    if swCPU = swHD6120 then
2747
                                        if CTRLFF = '1' then
2748
                                            pdfOP <= pdfopSET;
2749
                                        end if;
2750
                                    end if;
2751
 
2752
                                --
2753
                                -- Unhandled IOTs
2754
                                --
2755
 
2756
                                when others =>
2757
 
2758
                                    if (IR(0 to 8) = o"600") or (IR(0 to 5)  = o"62") then
2759
 
2760
                                        --
2761
                                        -- Internal IOTS (600x and 62xx) that are
2762
                                        -- not handled above.
2763
                                        --
2764
 
2765
                                        assert false report "Unhandled Internal IOT" severity warning;
2766
                                        nextState <= stateLaLa;
2767
 
2768
                                    else
2769
 
2770
                                        --
2771
                                        -- External IOTS.  Handled by external
2772
                                        -- devices.
2773
                                        --
2774
 
2775
                                        maOP      <= maopIR;
2776
                                        mbOP      <= mbopAC;
2777
                                        busOP     <= busopIOTWR;
2778
                                        nextState <= stateIOTdecode;
2779
 
2780
                                    end if;
2781
                            end case;
2782
                        end if;
2783
 
2784
                    --
2785
                    -- Operate Instructions
2786
                    --
2787
 
2788
                    when opOPR =>
2789
 
2790
                        if IR(3) = '0' then
2791
 
2792
                            --
2793
                            -- Operate Group 1
2794
                            --
2795
                            --                        Group 1
2796
                            --  |           |           |           |           |
2797
                            --  |---|---|---|---|---|---|---|---|---|---|---|---|
2798
                            --  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|
2799
                            --  | 1 | 1 | 1 | 0 |CLA|CLL|CMA|CML| R1| R2| R3|IAC|
2800
                            --  |---|---|---|---|---|---|---|---|---|---|---|---|
2801
                            --                    |   |   |   |   |   |   |   |
2802
                            --        Sequence:   1   1   2   2   4   4   4   3
2803
                            --
2804
                            --
2805
 
2806
                            --
2807
                            -- Operate Group 1 Sequence 1 and Sequence 2
2808
                            -- This state executes all combinations of Sequence 1
2809
                            -- and Sequence 2 operations
2810
                            --
2811
 
2812
                            case IR(4 to 7) is
2813
 
2814
                                --
2815
                                -- OP 7000: NOP
2816
                                --
2817
 
2818
                                when "0000" =>
2819
                                    null;
2820
 
2821
                                --
2822
                                -- OP 7020: CML - Complement Link Register
2823
                                -- The contents of the LINK is complemented.
2824
                                --
2825
 
2826
                                when "0001" =>
2827
                                    acop <= acopCML;
2828
 
2829
                                --
2830
                                -- OP 7040: CMA - Complement accumulator.
2831
                                -- The contents of the AC is replaced by its
2832
                                -- 1's  complement.
2833
                                --
2834
 
2835
                                when "0010" =>
2836
                                    acop <= acopCMA;
2837
 
2838
                                --
2839
                                -- OP 7060: CMA CML
2840
                                -- The contents of the LINK is complemented.
2841
                                -- The contents of the AC is replaced by its
2842
                                -- 1's complement.
2843
 
2844
                                when "0011" =>
2845
                                    acOP <= acopCMACML;
2846
 
2847
                                --
2848
                                -- OP 7100: CLL - Clear LINK
2849
                                -- The LINK is set to zero.
2850
                                --
2851
 
2852
                                when "0100" =>  -- CLL
2853
                                    acOP <= acopCLL;
2854
 
2855
                                --
2856
                                -- OP 7120: CLL CML (STL) - Set LINK.
2857
                                -- Clear LINK then Complement LINK.  The LINK
2858
                                -- is set to one.
2859
                                --
2860
 
2861
                                when "0101" =>
2862
                                    acop <= acopCLLCML;
2863
 
2864
                                --
2865
                                -- OP 7140: CLL CMA -
2866
                                -- Clear LINK and Complement accumulator,
2867
                                --
2868
 
2869
                                when "0110" =>
2870
                                    acOP <= acopCLLCMA;
2871
                                --
2872
                                -- OP 7160: CLL CMA CML - STL CMA
2873
                                -- Set LINK and Complement accumulator,
2874
                                --
2875
 
2876
                                when "0111" =>
2877
                                    acOP <= acopCLLCMACML;
2878
 
2879
                                --
2880
                                -- OP 7200: CLA - Clear accumulator
2881
                                -- Load AC with "0000".
2882
                                --
2883
 
2884
                                when "1000" =>
2885
                                    acOP <= acopCLA;
2886
 
2887
                                --
2888
                                -- OP 7220: CLA CML
2889
                                -- Clear Accumulator and Complement LINK
2890
                                --
2891
 
2892
                                when "1001" =>
2893
                                    acOP <= acopCLACML;
2894
 
2895
                                --
2896
                                -- OP 7240: CLA CMA (STA)
2897
                                -- Clear Accumulator then Complement
2898
                                -- Accumulator, or Set Accumulator.
2899
                                --
2900
 
2901
                                when "1010" =>
2902
                                    acOP <= acopCLACMA;
2903
 
2904
                                --
2905
                                -- OP 7260: CLA CMA CML (STA CML)
2906
                                -- Set Accumulator and Complement LINK.
2907
                                --
2908
 
2909
                                when "1011" =>
2910
                                    acOP <= acopCLACMACML;
2911
 
2912
                                --
2913
                                -- OP 7300: CLA CLL
2914
                                -- Clear AC and Clear LINK.
2915
                                --
2916
 
2917
                                when "1100" =>
2918
                                    acOP <= acopCLACLL;
2919
 
2920
                                --
2921
                                -- OP 7320: CLA CLL CML
2922
                                -- Clear AC and Set LINK
2923
                                --
2924
 
2925
                                when "1101" =>
2926
                                    acOP <= acopCLACLLCML;
2927
 
2928
                                --
2929
                                -- OP 7340: CLA CLL CMA, STA CLL
2930
                                -- Set Accumulator and Clear LINK
2931
                                --
2932
 
2933
                                when "1110" =>
2934
                                    acOP <= acopCLACLLCMA;
2935
 
2936
                                --
2937
                                -- OP 7360: CLA CLL CMA CML, STA STL
2938
                                -- Set Accumulator and Set LINK
2939
                                --
2940
 
2941
                                when "1111" =>
2942
                                    acOP <= acopCLACLLCMACML;
2943
 
2944
                                --
2945
                                -- Everything else
2946
                                --
2947
 
2948
                                when others =>
2949
                                    null;
2950
 
2951
                            end case;
2952
 
2953
                            --
2954
                            -- Determine the next state.  Skip states if
2955
                            -- possible.
2956
                            --
2957
 
2958
                            if IR(11) = '1' then
2959
                                nextState <= stateOprGroup1Seq3;
2960
                            else
2961
                                if IR(8) = '1' or IR(9) = '1' or IR(10) = '1' then
2962
                                    nextState <= stateOprGroup1Seq4;
2963
                                else
2964
                                    nextState <= stateDone;
2965
                                end if;
2966
                            end if;
2967
 
2968
                        else    -- IR(3) = '1'
2969
 
2970
                            if IR(11) = '0' then
2971
 
2972
                                --
2973
                                -- Operate Group 2
2974
                                --
2975
                                --                        Group 2
2976
                                --  |           |           |           |           |
2977
                                --  |---|---|---|---|---|---|---|---|---|---|---|---|
2978
                                --  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|
2979
                                --  | 1 | 1 | 1 | 1 |CLA|SMA|SZA|SNL| 0 |OSR|HLT| 0 |
2980
                                --  | 1 | 1 | 1 | 1 |CLA|SPA|SNA|SZL| 1 |OSR|HLT| 0 |
2981
                                --  |---|---|---|---|---|---|---|---|---|---|---|---|
2982
                                --                    |   |   |   |       |   |
2983
                                --        Sequence:   2   1   1   1       3   3
2984
                                --
2985
                                --
2986
 
2987
                                --
2988
                                -- This state handles Operating Group 2
2989
                                -- Sequence 1
2990
                                --
2991
 
2992
                                case IR(5 to 8) is
2993
 
2994
                                    --
2995
                                    -- OP 7400: NOP
2996
                                    --
2997
 
2998
                                    when "0000" =>
2999
                                        null;
3000
 
3001
                                    --
3002
                                    -- OP 7410: SKP - SKIP
3003
                                    -- The content of the PC is incremented by 1,
3004
                                    -- to skip the next Instruction.
3005
                                    --
3006
 
3007
                                    when "0001" =>
3008
                                        pcop <= pcopINC;
3009
 
3010
                                    --
3011
                                    -- OP 7420: SNL
3012
                                    -- Skip if LINK = 1
3013
                                    --
3014
 
3015
                                    when "0010" =>
3016
                                        if L = '1' then
3017
                                            pcop <= pcopINC;
3018
                                        end if;
3019
 
3020
                                    --
3021
                                    -- OP 7430: SZL
3022
                                    -- Skip if LINK = 0
3023
                                    --
3024
 
3025
                                    when "0011" =>
3026
                                        if L = '0' then
3027
                                            pcop <= pcopINC;
3028
                                        end if;
3029
 
3030
                                    --
3031
                                    -- OP 7440: SZA
3032
                                    -- Skip on zero accumulator (AC = "0000")
3033
                                    --
3034
 
3035
                                    when "0100" =>
3036
                                        if AC = o"0000" then
3037
                                            pcop <= pcopINC;
3038
                                        end if;
3039
 
3040
                                    --
3041
                                    -- OP 7450: SNA
3042
                                    -- Skip on non-zero accumulator
3043
                                    --
3044
 
3045
                                    when "0101" =>
3046
                                        if AC /= o"0000" then
3047
                                            pcop <= pcopINC;
3048
                                        end if;
3049
 
3050
                                    --
3051
                                    -- OP 7460: SZA SNL
3052
                                    -- Skip if AC="0000" or if LINK = 1
3053
                                    --
3054
 
3055
                                    when "0110" =>
3056
                                        if ((AC = o"0000") or (L = '1')) then
3057
                                            pcop <= pcopINC;
3058
                                        end if;
3059
 
3060
                                    --
3061
                                    -- OP 7470: SNA SZL
3062
                                    -- Skip if AC not "0000" and if LINK = 1
3063
                                    --
3064
 
3065
                                    when "0111" =>
3066
                                        if ((AC /= o"0000") and (L = '0')) then
3067
                                            pcop <= pcopINC;
3068
                                        end if;
3069
 
3070
                                    --
3071
                                    -- OP 7500: SMA
3072
                                    -- Skip on negative (minus) accumulator (AC0=1)
3073
                                    --
3074
 
3075
                                    when "1000" =>
3076
                                        if AC(0) = '1' then
3077
                                            pcop <= pcopINC;
3078
                                        end if;
3079
 
3080
                                    --
3081
                                    -- OP 7510: SPA
3082
                                    -- Skip on positive accumulator (AC0=0)
3083
                                    --
3084
 
3085
                                    when "1001" =>
3086
                                        if AC(0) = '0' then
3087
                                            pcop <= pcopINC;
3088
                                        end if;
3089
 
3090
                                    --
3091
                                    -- OP 7520: SMA SNL
3092
                                    -- Skip if AC is negative (minus) or if LINK is 1
3093
                                    --
3094
 
3095
                                    when "1010" =>
3096
                                        if ((AC(0) = '1') or (L = '1')) then
3097
                                            pcop <= pcopINC;
3098
                                        end if;
3099
 
3100
                                    --
3101
                                    -- OP 7530: SPA SZL
3102
                                    -- Skip if AC is positive and if LINK is 0
3103
                                    --
3104
 
3105
                                    when "1011" =>
3106
                                        if ((AC(0) = '0') and (L = '0')) then
3107
                                            pcop <= pcopINC;
3108
                                        end if;
3109
 
3110
                                    --
3111
                                    -- OP 7540: SMA SZA - Skip if AC is minus or zero
3112
                                    --
3113
 
3114
                                    when "1100" =>
3115
                                        if ((AC(0) = '1') or (AC = o"0000")) then
3116
                                            pcop <= pcopINC;
3117
                                        end if;
3118
 
3119
                                    --
3120
                                    -- OP 7550: SPA SNA
3121
                                    -- Skip if AC is positive and non-zero
3122
                                    --
3123
 
3124
                                    when "1101" =>
3125
                                        if ((AC(0) = '0') and (AC /= o"0000")) then
3126
                                            pcop <= pcopINC;
3127
                                        end if;
3128
 
3129
                                    --
3130
                                    -- OP 7560: SMA SZA SNL
3131
                                    -- Skip if AC is minus or if AC="0000" or if LINK is 1
3132
                                    --
3133
 
3134
                                    when "1110" =>
3135
                                        if ((AC(0) = '1') or (AC = o"0000") or (L = '1')) then
3136
                                            pcop <= pcopINC;
3137
                                        end if;
3138
 
3139
                                    --
3140
                                    -- OP 7570: SPA SNA SZL
3141
                                    -- Skip if AC is positive, nonzero, and if LINK is zero.
3142
                                    --
3143
 
3144
                                    when "1111" =>
3145
                                        if ((AC(0) = '0') and (AC /= o"0000") and (L = '0')) then
3146
                                            pcop <= pcopINC;
3147
                                        end if;
3148
 
3149
                                    --
3150
                                    -- Everything else
3151
                                    --
3152
 
3153
                                    when others =>
3154
                                        null;
3155
 
3156
                                end case;
3157
 
3158
                                --
3159
                                -- Determine if there are any Group 2 Sequence
3160
                                -- 2 operations to perform.  Skip states if not.
3161
                                --
3162
 
3163
                                if IR(4) = '1' or IR(9) = '1' or IR(10) = '1' then
3164
                                    nextState <= stateOprGroup2Seq2;
3165
                                else
3166
                                    nextstate <= stateDone;
3167
                                end if;
3168
 
3169
                            else  -- IR(11) = '1'
3170
 
3171
                                --
3172
                                --
3173
                                -- Decode Group 3 Sequence 1,2 Opcode
3174
                                --
3175
                                --                        Group 3
3176
                                --  |           |           |           |           |
3177
                                --  |---|---|---|---|---|---|---|---|---|---|---|---|
3178
                                --  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|
3179
                                --  | 1 | 1 | 1 | 1 |CLA|MQA| 0 |MQL| 0 | 0 | 0 | 1 |
3180
                                --  |---|---|---|---|---|---|---|---|---|---|---|---|
3181
                                --                    |   |       |
3182
                                --        Sequence:   1   2       2
3183
                                --
3184
                                -- Note: In the state machine, Sequence 1 and Sequence 2
3185
                                -- are handled together to save time (cycles).
3186
                                --
3187
                                -- Operate Group 3, 3A and 3B instructions.
3188
                                --
3189
                                -- HD6120: If bits 6, 8, 9 or 10 are set to a
3190
                                -- one, instruction execution is not altered but the
3191
                                -- instruction becomes uninterruptable by either
3192
                                -- panel or normal interrupts.  That is, the next
3193
                                -- instruction is guaranteed to be fetched barring
3194
                                -- a reset, DMAREQ or RUN/HLT flip flop in the
3195
                                -- HLT state.
3196
                                --
3197
 
3198
                                if ((swCPU = swHD6120 and IR( 6) = '1') or
3199
                                    (swCPU = swHD6120 and IR( 8) = '1') or
3200
                                    (swCPU = swHD6120 and IR( 9) = '1') or
3201
                                    (swCPU = swHD6120 and IR(10) = '1')) then
3202
                                    idOP <= idopSET;
3203
                                end if;
3204
 
3205
                                --
3206
                                -- OP 74x1: EAE Instructions
3207
                                --
3208
                                -- The PDP8/L had no provision for EAE
3209
                                --
3210
                                -- These instructions were only available pre
3211
                                -- PDP8/E if EAE was added.
3212
                                --
3213
                                -- These instruction work on PDP8/E and later
3214
                                -- without EAE.
3215
                                --
3216
 
3217
                                if ((swCPU = swPDP8  and swOPT.KE8 = '1') or
3218
                                    (swCPU = swPDP8S and swOPT.KE8 = '1') or
3219
                                    (swCPU = swPDP8I and swOPT.KE8 = '1') or
3220
                                    -- PDP8L never supported EAE
3221
                                    (swCPU = swPDP8E) or
3222
                                    (swCPU = swPDP8F) or
3223
                                    (swCPU = swPDP8M) or
3224
                                    (swCPU = swPDP8A) or
3225
                                    (swCPU = swHD6120)) then
3226
 
3227
                                    EAEIR := IR(4) & IR(5) & IR(7) & '0';
3228
                                    case EAEIR(0 to 2) is
3229
 
3230
                                        --
3231
                                        -- OP 7401: NOP
3232
                                        --
3233
 
3234
                                        when "000" =>
3235
                                            null;
3236
 
3237
                                        --
3238
                                        -- OP 7421: MQL - MQ register load
3239
                                        -- The MQ is loaded with the contents of the
3240
                                        -- AC and the AC is cleared. The original
3241
                                        -- contents of the MQ is lost.
3242
                                        --
3243
 
3244
                                        when "001" =>
3245
                                            mqOP <= mqopAC;
3246
                                            acOP <= acopCLA;
3247
 
3248
                                        --
3249
                                        -- OP 7501: MQA - MQ "OR" with accumulator.
3250
                                        -- OR the contents of the MQ is "OR"ed with
3251
                                        -- the contents of the AC, and the result left
3252
                                        -- in the AC.  The MQ is not modified.
3253
                                        --
3254
 
3255
                                        when "010" =>
3256
                                            acOP <= acopORMQ;
3257
 
3258
                                        --
3259
                                        -- OP 7521: SWP - Swap contents of AC and MQ.
3260
                                        -- The contents of the AC and MQ are exchanged
3261
                                        --
3262
                                        -- The SWP instruction does not work on
3263
                                        -- Straight 8 (PDP8)
3264
 
3265
                                        when "011" =>
3266
                                            if ((swCPU = swPDP8) or
3267
                                                (swCPU = swPDP8I)) then
3268
                                                -- What should this do?
3269
                                                acOP <= acopNOP;
3270
                                                mqOP <= mqopNOP;
3271
                                            else
3272
                                                acOP <= acopMQ;
3273
                                                mqOP <= mqopAC;
3274
                                            end if;
3275
 
3276
                                        --
3277
                                        -- OP 7601: CLA - Clear Accumulator
3278
                                        -- The accumulator may be cleared prior to other
3279
                                        -- group three microcoded operations. Unless
3280
                                        -- microcoded with other group three instructions,
3281
                                        -- PDP-8 assemblers generally assume that the CLA
3282
                                        -- mnemonic refers to the group one instruction.
3283
                                        --
3284
 
3285
                                        when "100" =>
3286
                                            acOP <= acopCLA;
3287
 
3288
                                        --
3289
                                        -- OP 7621: CLA/MQL - CAM - Clear AC and MQ
3290
                                        -- This instruction first clears AC, so the
3291
                                        -- result is to clear both AC and MQ.
3292
                                        --
3293
 
3294
                                        when "101" =>
3295
                                            acOP <= acopCLA;
3296
                                            mqOP <= mqopCLR;
3297
 
3298
                                        --
3299
                                        -- OP 7701: CLA MQA - ACL - Microcode CLA MQA
3300
                                        -- This instruction first clears AC, so the
3301
                                        -- result is to load AC with the contents
3302
                                        -- of MQ.
3303
                                        --
3304
 
3305
                                        when "110" =>
3306
                                            acOP <= acopMQ;
3307
 
3308
                                        --
3309
                                        -- OP 7721: CLA SWP - Clear AC, then swap.
3310
                                        -- The MQ is loaded into the AC;
3311
                                        -- "0000" is loaded into the MQ.
3312
                                        --
3313
 
3314
                                        when "111" =>
3315
                                            acOP <= acopMQ;
3316
                                            mqOP <= mqopCLR;
3317
 
3318
                                        --
3319
                                        -- Everything else
3320
                                        --
3321
 
3322
                                        when others =>
3323
                                            null;
3324
 
3325
                                    end case;
3326
 
3327
                                    --
3328
                                    -- Group 3 Sequence 3 instruction are
3329
                                    -- supported with EAE installed.
3330
                                    --
3331
 
3332
                                    if swOPT.KE8 = '1' then
3333
                                        nextState <= stateOprGroup3Seq3;
3334
                                    else
3335
                                        nextstate <= stateDone;
3336
                                    end if;
3337
 
3338
                                end if;  -- Group 3
3339
                            end if;  -- IR(11)
3340
                        end if;  -- IR(3)
3341
 
3342
                    --
3343
                    -- Everything else
3344
                    --
3345
 
3346
                    when others =>
3347
                        null;
3348
 
3349
                end case;
3350
 
3351
            --
3352
            -- IOT Decode State
3353
            -- The previous state peformed an IOT write cycle.  This state
3354
            -- decides the devc and skip that is return by the IOT interface.
3355
            --
3356
 
3357
            when stateIOTdecode =>
3358
 
3359
                --
3360
                -- Handle Skip
3361
                --
3362
 
3363
                if dev.skip = '1' then
3364
                    pcOP <= pcopINC;
3365
                end if;
3366
 
3367
                --
3368
                -- Handle CLA
3369
                --
3370
 
3371
                if dev.devc = devWRCLR or dev.devc = devRDCLR then
3372
                    acOP <= acopCLA;
3373
                end if;
3374
 
3375
                --
3376
                -- Handle RD and WR
3377
                --
3378
 
3379
                if dev.devc = devRD or dev.devc = devRDCLR then
3380
                    busOP     <= busopRDIOT;
3381
                    nextState <= stateIOT;
3382
                else
3383
                    nextState <= stateDone;
3384
                end if;
3385
 
3386
            --
3387
            -- stateIOT:
3388
            -- The previous state performed a Read Data Cycle.  OR the IOT data
3389
            -- that was read with AC.
3390
            --
3391
 
3392
            when stateIOT =>
3393
                acOP      <= acopORMD;
3394
                nextState <= stateDone;
3395
 
3396
            --
3397
            -- Operate Group1 Sequence 3 State
3398
            --
3399
 
3400
            when stateOprGroup1Seq3 =>
3401
 
3402
                --
3403
                -- OP 7001: IAC - Increment accumulator.
3404
                -- The contents of the AC is incremented by 1.
3405
                -- Carry out complements the LINK.
3406
                --
3407
 
3408
                if IR(11) = '1' then
3409
                    acOP <= acopIAC;
3410
                end if;
3411
 
3412
                --
3413
                -- Determine the next state
3414
                --
3415
 
3416
                if IR(8) = '1' or IR(9) = '1' or IR(10) = '1' then
3417
                    nextState <= stateOprGroup1Seq4;
3418
                else
3419
                    nextState <= stateDone;
3420
                end if;
3421
 
3422
            --
3423
            -- Operate Group1 Sequence 4 State
3424
            --
3425
 
3426
            when stateOprGroup1Seq4 =>
3427
 
3428
                case IR(8 to 10) is
3429
 
3430
                    --
3431
                    -- OP 7000: NOP
3432
                    --
3433
 
3434
                    when "000" =>
3435
                        null;
3436
 
3437
                    --
3438
                    -- OP 7002: BSW - Byte swap
3439
                    --
3440
 
3441
                    when "001" =>
3442
 
3443
                        --
3444
                        -- PDP-8/E and later
3445
                        -- OP 7002: BSW - Byte swap
3446
                        -- AC are exchanged with AC<6-11> respectively.
3447
                        -- The LINK is not changed.
3448
                        --
3449
 
3450
                        if ((swCPU = swPDP8E) or
3451
                            (swCPU = swPDP8F) or
3452
                            (swCPU = swPDP8A) or
3453
                            (swCPU = swHD6120)) then
3454
                            acOP <= acopBSW;
3455
 
3456
                        --
3457
                        -- Pre PDP8/E
3458
                        -- OP 7002: Equivalent to a NOP
3459
                        --
3460
 
3461
                        else
3462
                            null;
3463
 
3464
                        end if;
3465
 
3466
                    --
3467
                    -- OP 7004: RAL - Rotate accumulator left.
3468
                    -- The contents of the AC and LINK are rotated one
3469
                    -- binary position to the left. AC(O) is shifted to
3470
                    -- LINK and LINK is shifted to AC(11).
3471
                    --
3472
                    -- RAL combined with IAC only works on PDP8I and later
3473
                    -- RAL combined with CMA is broke on on PDP8S
3474
                    --
3475
 
3476
                    when "010" =>
3477
                        if ((swCPU = swPDP8  and IR(11) = '1') or
3478
                            (swCPU = swPDP8S and IR(11) = '1')) then
3479
                            -- What should this do?
3480
                            acOP <= acopNOP;
3481
                        elsif swCPU = swPDP8S and IR(6) = '1' then
3482
                            -- What should this do?
3483
                            acOP <= acopNOP;
3484
                        else
3485
                            acOP <= acopRAL;
3486
                        end if;
3487
 
3488
                    --
3489
                    -- OP 7006: RTL - Rotate two left.
3490
                    -- Equivalent to two RAL's.
3491
                    --
3492
                    -- RTL combined with IAC only works on PDP8I and later
3493
                    -- RTL combined with CMA is broke on on PDP8S
3494
                    --
3495
 
3496
                    when "011" =>
3497
                        if ((swCPU = swPDP8  and IR(11) = '1') or
3498
                            (swCPU = swPDP8S and IR(11) = '1')) then
3499
                            -- What should this do?
3500
                            acOP <= acopNOP;
3501
                        elsif swCPU = swPDP8S and IR(6) = '1' then
3502
                            -- What should this do?
3503
                            acOP <= acopNOP;
3504
                        else
3505
                            acOP <= acopRTL;
3506
                        end if;
3507
 
3508
                    --
3509
                    -- OP 7010: RAR - Rotate accumulator right.
3510
                    -- The contents of the AC and LINK are rotated one
3511
                    -- binary position to the right.  AC(11) is shifted
3512
                    -- into the LINK, and LINK is shifted to AC(O).
3513
                    --
3514
                    -- RAR combined with IAC only works on PDP8I and later
3515
                    -- RAR combined with CMA is broke on on PDP8S
3516
                    --
3517
 
3518
                    when "100" =>
3519
                        if ((swCPU = swPDP8  and IR(11) = '1') or
3520
                            (swCPU = swPDP8S and IR(11) = '1')) then
3521
                            -- What should this do?
3522
                            acOP <= acopNOP;
3523
                        elsif swCPU = swPDP8S and IR(6) = '1' then
3524
                            -- What should this do?
3525
                            acOP <= acopNOP;
3526
                        else
3527
                            acOP <= acopRAR;
3528
                        end if;
3529
 
3530
                    --
3531
                    -- OP 7012: RTR - Rotate two right.
3532
                    -- Equivalent to two RAR's.
3533
                    --
3534
                    -- RTR combined with IAC only works on PDP8I and later
3535
                    -- RTR combined with CMA is broke on on PDP8S
3536
                    --
3537
 
3538
                    when "101" =>
3539
                        if ((swCPU = swPDP8  and IR(11) = '1') or
3540
                            (swCPU = swPDP8S and IR(11) = '1')) then
3541
                            -- What should this do?
3542
                            acOP <= acopNOP;
3543
                        elsif swCPU = swPDP8S and IR(6) = '1' then
3544
                            -- What should this do?
3545
                            acOP <= acopNOP;
3546
                        else
3547
                            acOP <= acopRTR;
3548
                        end if;
3549
 
3550
                    --
3551
                    -- OP 7014: PDP8: UNDEF1
3552
                    --   Sneak path though the AND array  This instruction
3553
                    --   produced predicable but undocumented results.
3554
                    -- OP 7014: PDP8E, PDP8F, PDP8M, PDP8A
3555
                    --   NOP.  Verified on David Gesswein's PDP8E
3556
                    -- OP 7014: HD6120:  R3L - Rotate 3 Left.
3557
                    --   Rotate AC (but not LINK) left 3 places.
3558
                    --   AC(0) is rotated into AC(9),
3559
                    --   AC(1) is rotated into AC(10),
3560
                    --   AC(2) is rotated into AC(11),
3561
                    --   AC(3) is rotated into AC(1), etc
3562
                    --
3563
 
3564
                    when "110" =>
3565
                        if swCPU = swHD6120 then
3566
                            acOP <= acopR3L;
3567
                        elsif ((swCPU = swPDP8E) or
3568
                               (swCPU = swPDP8F) or
3569
                               (swCPU = swPDP8M) or
3570
                               (swCPU = swPDP8A)) then
3571
                            acOP <= acopNOP;
3572
                        else
3573
                            acOP <= acopUNDEF1;
3574
                        end if;
3575
 
3576
                    --
3577
                    -- OP 7016: UNDEF2: Sneak though addr.  This instruction
3578
                    -- produced predicable but undocumented results.
3579
                    -- Verified on David Gesswein's PDP8E
3580
                    --
3581
 
3582
                    when "111" =>
3583
                        acOP <= acopUNDEF2;
3584
 
3585
                    --
3586
                    -- Everything else
3587
                    --
3588
 
3589
                    when others =>
3590
                        null;
3591
 
3592
                end case;
3593
                nextState <= stateDone;
3594
 
3595
            --
3596
            -- Operate Group 2 Sequence 2 State
3597
            --
3598
 
3599
            when stateOprGroup2Seq2 =>
3600
 
3601
                --
3602
                -- In USER mode, the OSR and HLT instructions are privledged
3603
                -- and generate a User Mode interrupt.
3604
                --
3605
 
3606
                if ((UF = '1' and IR( 9) = '1') or
3607
                    (UF = '1' and IR(10) = '1')) then
3608
                    if IR(4) = '1' then
3609
                        acOP <= acopCLA;
3610
                    end if;
3611
                    usrtrpOP  <= usrtrpopSET;
3612
 
3613
                else
3614
 
3615
                    --
3616
                    -- OP 7402: HLT - HALT
3617
                    -- OP 7406: OSR HLT - HALT
3618
                    -- OP 7606: CLA OSR HLT, LAS HLT - HALT
3619
                    -- The HALT Operation is not particularly sequence
3620
                    -- sensitive so it is decoded here.  The CPU will halt at
3621
                    -- the end of the current instruction.
3622
                    --
3623
 
3624
                    if IR(10) = '1' then
3625
                        hlttrpOP <= hlttrpopSET;
3626
                    end if;
3627
 
3628
                    if IR(9) = '1' then
3629
 
3630
                        --
3631
                        -- OP 7604: LAS : Load AC with Switches.
3632
                        --
3633
 
3634
                        if IR(4) = '1' then
3635
                            acOP <= acopLAS;
3636
 
3637
                        --
3638
                        -- OP 7404: OSR : OR Switch Register with accumulator.
3639
                        --
3640
 
3641
                        else
3642
                            acOP <= acopOSR;
3643
 
3644
                        end if;
3645
 
3646
                    else
3647
 
3648
                        --
3649
                        -- OP 7600: CLA - Clear Accumulator
3650
                        --
3651
 
3652
                        if IR(4) = '1' then
3653
                            acOP <= acopCLA;
3654
 
3655
                        end if;
3656
 
3657
                    end if;
3658
 
3659
                end if;
3660
                nextState <= stateDone;
3661
 
3662
            --
3663
            -- Operate Group 3 Sequence 3 Mode A State
3664
            --
3665
 
3666
            when stateOprGroup3Seq3 =>
3667
 
3668
                --
3669
                --                    Group 3 Mode A
3670
                --
3671
                --  |           |           |           |           |
3672
                --  |---|---|---|---|---|---|---|---|---|---|---|---|
3673
                --  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|
3674
                --  | 1 | 1 | 1 | 1 |CLA|MQA|SCA|MQL|   |   |   | 1 |
3675
                --  |---|---|---|---|---|---|---|---|---|---|---|---|
3676
                --                    |   |       | |           |
3677
                --      Sequence:     1   2       2  \____3____/
3678
                --                                        V
3679
                --                              0 = NOP       4 = NMI
3680
                --                              1 = SCL       5 = SHL
3681
                --                              2 = MUY       6 = ASR
3682
                --                              3 = DVI       7 = LSR
3683
                --
3684
                --
3685
                --                    Group 3 Mode B
3686
                --
3687
                --  |           |           |           |           |
3688
                --  |---|---|---|---|---|---|---|---|---|---|---|---|
3689
                --  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11|
3690
                --  | 1 | 1 | 1 | 1 |CLA|MQA|   |MQL|   |   |   | 1 |
3691
                --  |---|---|---|---|---|---|---|---|---|---|---|---|
3692
                --                    |   | |     |             |
3693
                --      Sequence:     1   2  \    2            /
3694
                --                            \_______3_______/
3695
                --                                    V
3696
                --                          0 = NOP       10 = SCA
3697
                --                          1 = ACS       11 = DAD
3698
                --                          2 = MUY       12 = DST
3699
                --                          3 = DVI       13 = SWBA
3700
                --                          4 = NMI       14 = DPSZ
3701
                --                          5 = SHL       15 = DPIC (MQL & MQA set)
3702
                --                          6 = ASR       16 = DCM  (MQL & MQA set)
3703
                --                          7 = LSR       17 = SAM
3704
                --
3705
 
3706
                if IR = o"7431" then
3707
 
3708
                    --
3709
                    -- OP 7431: SWAB - Switch from A to B.  The SWAB
3710
                    -- instruction cannot be microprogrammed with any of the
3711
                    -- Mode 3A or Mode 3B instructions.
3712
                    --
3713
                    -- EAE Mode B was only available on PDP8/E, PDP8/F, PDP8/M,
3714
                    -- PDP8/A with EAE.
3715
                    --
3716
 
3717
                    if ((swCPU = swPDP8E) or
3718
                        (swCPU = swPDP8F) or
3719
                        (swCPU = swPDP8M) or
3720
                        (swCPU = swPDP8A)) then
3721
                        emodeOP   <= emodeopSET;
3722
                        nextState <= stateDone;
3723
                    end if;
3724
 
3725
                elsif IR = o"7447" then
3726
 
3727
                    --
3728
                    -- SWBA - Switch from B to A.   Clear GTF.  The SWBA
3729
                    -- instruction cannot be microprogrammed with any of the
3730
                    -- Mode 3A or Mode 3B instructions.
3731
                    --
3732
 
3733
                    emodeOP   <= emodeopCLR;
3734
                    gtfOP     <= gtfopCLR;
3735
                    nextState <= stateDone;
3736
 
3737
                else
3738
 
3739
                    --
3740
                    -- EAE Mode A Operations clear GTF
3741
                    --
3742
 
3743
                    if EMODE = '0' then
3744
                        gtfOP <= gtfopCLR;
3745
                    end if;
3746
 
3747
                    --
3748
                    -- All the Mode 3A and Mode 3B instructions
3749
                    --
3750
 
3751
                    EAEIR := IR(6) & IR(8) & IR(9) & IR(10);
3752
                    case EAEIR is
3753
 
3754
                        --
3755
                        -- OP 7401: NOP
3756
                        --
3757
 
3758
                        when opEAENOP =>
3759
                            nextState <= stateDone;
3760
 
3761
                        --
3762
                        -- OP 7403: MODEA: SCL
3763
                        --          MODEB: ACS
3764
                        --
3765
 
3766
                        when "0001" =>
3767
 
3768
                            if EMODE = '0' then
3769
 
3770
                                --
3771
                                -- SCL - Step Counter Load from Memory.  The SCL
3772
                                -- instruction is a two-word instruction.  The
3773
                                -- value to load is contained in the operand
3774
                                -- which is located at the next memory
3775
                                -- location. Begin the fetch of the operand.
3776
                                --
3777
 
3778
                                maOP      <= maopPC;
3779
                                pcOP      <= pcopINC;
3780
                                xmaOP     <= xmaopIF;
3781
                                busOP     <= busopRDIFaddr;
3782
                                nextState <= stateEAEfetchAddr;
3783
 
3784
                            else
3785
 
3786
                                --
3787
                                -- ACS - Accumulator to Step Count.
3788
                                -- AC(7 to 11) are loaded into the Step Counter
3789
                                -- then the AC is cleared.
3790
                                --
3791
 
3792
                                scOP      <= scopAC7to11;
3793
                                acOP      <= acopCLA;
3794
                                nextState <= stateDone;
3795
 
3796
                            end if;
3797
 
3798
                        --
3799
                        -- OP 7405: MUY - Multiply.  The Multiply instruction
3800
                        -- is a two-word instruction.  The second word is
3801
                        -- either the multiplier or the address of the multiplier
3802
                        -- depending on the mode.  Begin the fetch of the operand.
3803
                        --
3804
 
3805
                        when opEAEMUY =>
3806
                            maOP      <= maopPC;
3807
                            pcOP      <= pcopINC;
3808
                            xmaOP     <= xmaopIF;
3809
                            busOP     <= busopRDIFaddr;
3810
                            nextState <= stateEAEfetchAddr;
3811
 
3812
                        --
3813
                        -- OP 7407: DVI - Divide.  The Divide instruction
3814
                        -- is a two-word instruction.  The second word is
3815
                        -- either the divisor or the address of the divisor
3816
                        -- depending on the mode.  Begin the fetch of the operand.
3817
                        --
3818
 
3819
                        when opEAEDVI =>
3820
                            maOP      <= maopPC;
3821
                            pcOP      <= pcopINC;
3822
                            xmaOP     <= xmaopIF;
3823
                            busOP     <= busopRDIFaddr;
3824
                            nextState <= stateEAEfetchAddr;
3825
 
3826
                        --
3827
                        -- OP 7411: NMI
3828
                        -- The Step Counter is initially cleared.
3829
                        --
3830
 
3831
                        when opEAENMI =>
3832
                            scOP      <= scopCLR;
3833
                            nextState <= stateEAEnmi;
3834
 
3835
                        --
3836
                        -- OP 7413: SHL - Shift Left.  The shift left
3837
                        -- instruction is a two-word instruction. The number of
3838
                        -- shifts is contained in operand which is located at
3839
                        -- the next memory location.  Begin the fetch of the operand.
3840
                        --
3841
 
3842
                        when opEAESHL =>
3843
                            maOP      <= maopPC;
3844
                            xmaOP     <= xmaopIF;
3845
                            pcOP      <= pcopINC;
3846
                            xmaOP     <= xmaopIF;
3847
                            busOP     <= busopRDIFaddr;
3848
                            nextState <= stateEAEfetchAddr;
3849
 
3850
                        --
3851
                        -- OP 7415: ASR - Arithmetic Shift Right.
3852
                        -- The number of shifts is contained in operand which
3853
                        -- is contained in the next memory location.  Begin the
3854
                        -- fetch of the operand.
3855
                        --
3856
 
3857
                        when opEAEASR =>
3858
                            maOP      <= maopPC;
3859
                            xmaOP     <= xmaopIF;
3860
                            pcOP      <= pcopINC;
3861
                            busOP     <= busopRDIFaddr;
3862
                            nextState <= stateEAEfetchAddr;
3863
 
3864
                        --
3865
                        -- OP 7417: LSR - Logical Shift Right
3866
                        -- The number of shifts is contained in operand which
3867
                        -- is located at the next memory location.  Begin the
3868
                        -- fetch of the operand.
3869
                        --
3870
 
3871
                        when opEAELSR =>
3872
                            maOP      <= maopPC;
3873
                            xmaOP     <= xmaopIF;
3874
                            pcOP      <= pcopINC;
3875
                            busOP     <= busopRDIFaddr;
3876
                            nextState <= stateEAEfetchAddr;
3877
 
3878
                        --
3879
                        -- OP 7441: SCA - Step Count OR with AC
3880
                        --
3881
 
3882
                        when opEAESCA =>
3883
                            acop      <= acopSCA;
3884
                            nextState <= stateDone;
3885
 
3886
                        --
3887
                        -- OP 7443: MODEA SCA/SCL
3888
                        --          MODEB DAD
3889
                        --
3890
 
3891
                        when opEAEDAD =>
3892
 
3893
                            if EMODE = '0' then
3894
 
3895
                                --
3896
                                -- SCA/SCL - Step Counter Load from Memory.  The SCL
3897
                                -- instruction is a two-word instruction.  The
3898
                                -- value to load is contained in the operand
3899
                                -- which is located at the next memory
3900
                                -- location.  Begin the fetch of the operand.
3901
                                --
3902
 
3903
                                acop      <= acopSCA;
3904
                                pcOP      <= pcopINC;
3905
                                maOP      <= maopPC;
3906
                                xmaOP     <= xmaopIF;
3907
                                busOP     <= busopRDIFaddr;
3908
                                nextState <= stateEAEfetchAddr;
3909
 
3910
                            else
3911
 
3912
                                --
3913
                                -- DAD - Double Precision Add.  The DAD
3914
                                -- instruction is a three-word instruction. The
3915
                                -- second word is the first operand which is
3916
                                -- the address of the LSW of the addend.  Begin
3917
                                -- the fetch of the first operand.
3918
                                --
3919
 
3920
                                pcOP      <= pcopINC;
3921
                                maOP      <= maopPC;
3922
                                xmaOP     <= xmaopIF;
3923
                                busOP     <= busopRDIFaddr;
3924
                                nextState <= stateEAEfetchAddr;
3925
 
3926
                            end if;
3927
 
3928
                        --
3929
                        -- OP 7445: MODEA: SCA/MUY
3930
                        --          MODEB: DST
3931
 
3932
                        when opEAEDST =>
3933
 
3934
                            if EMODE = '0' then
3935
 
3936
                                --
3937
                                -- SCA/MUY - Multiply.  The Multiply instruction
3938
                                -- is a two-word instruction.  The second word is
3939
                                -- either the multiplier or the address of the multiplier
3940
                                -- depending on the mode.  Begin the fetch of the operand.
3941
                                --
3942
 
3943
                                acop      <= acopSCA;
3944
                                pcOP      <= pcopINC;
3945
                                maOP      <= maopPC;
3946
                                xmaOP     <= xmaopIF;
3947
                                busOP     <= busopRDIFaddr;
3948
                                nextState <= stateEAEfetchAddr;
3949
 
3950
                            else
3951
 
3952
                                --
3953
                                -- DST - Double Precision Store.
3954
                                --
3955
 
3956
                                pcOP      <= pcopINC;
3957
                                maOP      <= maopPC;
3958
                                xmaOP     <= xmaopIF;
3959
                                busOP     <= busopRDIFaddr;
3960
                                nextState <= stateEAEfetchAddr;
3961
 
3962
                            end if;
3963
 
3964
                        --
3965
                        -- OP 7451: MODEA: SCA/NMI
3966
                        --          MODEB: DPSZ
3967
                        --
3968
 
3969
                        when opEAEDPSZ =>
3970
 
3971
                            if EMODE = '0' then
3972
 
3973
                                --
3974
                                -- SCA/NMI -
3975
                                -- The Step Counter is initially cleared.
3976
                                --
3977
 
3978
                                acop      <= acopSCA;
3979
                                scOP      <= scopCLR;
3980
                                nextState <= stateDone;
3981
 
3982
                            else
3983
 
3984
                                --
3985
                                -- DPSZ - Double Precision Skip if Zero
3986
                                --
3987
 
3988
                                if AC = o"0000" and MQ = o"0000" then
3989
                                    pcop  <= pcopINC;
3990
                                end if;
3991
                                nextState <= stateDone;
3992
 
3993
                            end if;
3994
 
3995
                        --
3996
                        -- OP 7453: MODEA: SCA/SHL
3997
                        --          MODEB: DPIC
3998
                        --
3999
 
4000
                        when opEAEDPIC =>
4001
 
4002
                            if EMODE = '0' then
4003
 
4004
                                --
4005
                                -- SCA/SHL - SCA combined with SHL
4006
                                --
4007
 
4008
                                acOP      <= acopSCA;
4009
                                maOP      <= maopPC;
4010
                                xmaOP     <= xmaopIF;
4011
                                pcOP      <= pcopINC;
4012
                                busOP     <= busopRDIFaddr;
4013
                                nextState <= stateEAEfetchAddr;
4014
 
4015
                            else
4016
 
4017
                                --
4018
                                -- DPIC - Double Precision Increment
4019
                                -- Note: AC and MQ were previously swapped because
4020
                                -- this instruction must be micro-coded with MQL and MQA.
4021
                                --
4022
 
4023
                                if AC = o"7777" then
4024
                                    mqOP <= mqopCLR;
4025
                                    if MQ = o"7777" then
4026
                                       acOP <= acopCLACLLCML;
4027
                                    else
4028
                                       acOP <= acopMQP1;
4029
                                    end if;
4030
                                else
4031
                                    mqOP <= mqopACP1;
4032
                                    acOP <= acopZMQ;
4033
                                end if;
4034
                                nextState <= stateDone;
4035
 
4036
                            end if;
4037
 
4038
                        --
4039
                        -- OP 7455: MODEA: SCA/ASR
4040
                        --          MODEB: DCM
4041
                        --
4042
 
4043
                        when opEAEDCM =>
4044
 
4045
                            if EMODE = '0' then
4046
 
4047
                                --
4048
                                -- SCA/ASR - SCA combined with ASR
4049
                                --
4050
 
4051
                                maOP      <= maopPC;
4052
                                xmaOP     <= xmaopIF;
4053
                                acOP      <= acopSCA;
4054
                                pcOP      <= pcopINC;
4055
                                busOP     <= busopRDIFaddr;
4056
                                nextState <= stateEAEfetchAddr;
4057
 
4058
                            else
4059
 
4060
                                --
4061
                                -- DCM - Double Precision Complement.
4062
                                -- The 24-bit number in AC and MQ is complemented and
4063
                                -- incremented. This has the effect of two complementing
4064
                                -- the 24-bit number.  The high-order carry is propigated
4065
                                -- into the link register.
4066
                                -- Note: AC and MQ were previously swapped because
4067
                                -- this instruction must be micro-coded with MQL and MQA.
4068
                                --
4069
 
4070
                                if AC = o"0000" then
4071
                                    mqOP <= mqopCLR;
4072
                                    if MQ = o"0000" then
4073
                                        acOP <= acopCLACLLCML;
4074
                                    else
4075
                                        acOP <= acopNEGMQ;
4076
                                    end if;
4077
                                else
4078
                                    mqOP <= mqopNEGAC;
4079
                                    acOP <= acopNOTMQ;
4080
                                end if;
4081
                                nextState <= stateDone;
4082
 
4083
                            end if;
4084
 
4085
                        --
4086
                        -- OP 7457: MODEA: SCA/LSR
4087
                        --          MODEB: SAM
4088
                        --
4089
 
4090
                        when opEAESAM =>
4091
 
4092
                            if EMODE = '0' then
4093
 
4094
                                --
4095
                                -- SCA/LSR - SCA combined with LSR
4096
                                --
4097
 
4098
                                maOP      <= maopPC;
4099
                                xmaOP     <= xmaopIF;
4100
                                pcOP      <= pcopINC;
4101
                                acOP      <= acopSCA;
4102
                                busOP     <= busopRDIFaddr;
4103
                                nextState <= stateEAEfetchAddr;
4104
 
4105
                            else
4106
 
4107
                                --
4108
                                -- SAM - Subtract AC from MQ.
4109
                                -- GTF is set if signed MQ >= signed AC
4110
                                -- otherwise GTF is cleared.
4111
                                --
4112
 
4113
                                acOP  <= acopMQSUB;
4114
                                if signed(MQ) >= signed(AC) then
4115
                                    gtfOP <= gtfopSET;
4116
                                else
4117
                                    gtfOP <= gtfopCLR;
4118
                                end if;
4119
                                nextState <= stateDone;
4120
 
4121
                            end if;
4122
 
4123
                        --
4124
                        -- Everything else
4125
                        --
4126
 
4127
                        when others =>
4128
                            assert false report "stateOprGroup3Seq3: Undecoded instruction" severity warning;
4129
                            nextState <= stateDone;
4130
 
4131
                    end case;
4132
 
4133
                end if;
4134
 
4135
            --
4136
            -- This state performs a read address cycle.
4137
            -- The next state will do a read data bus.
4138
            --
4139
 
4140
            when stateMRIreadAddr =>
4141
                xmaOP <= xmaopIF;
4142
                busOP <= busopRDIFaddr;
4143
                if ((IR(3 to 4) = amDZ) or IR(3 to 4) = amDC) then
4144
                    nextState <= stateMRIexecute;
4145
                else
4146
                    nextState <= stateMRIreadDataIND;
4147
                end if;
4148
 
4149
            --
4150
            -- This state perfored a read data bus cycle.
4151
            -- The data that was read is in MD.
4152
            --
4153
 
4154
            when stateMRIreadDataIND =>
4155
 
4156
                if MA(0 to 8) = maAutoIncr then
4157
 
4158
                    --
4159
                    -- Writeback auto incremented data.
4160
                    --  MB <- MD + 1
4161
                    --  MEM[IF'MA] <- MB
4162
                    --
4163
 
4164
                    mbOP      <= mbopMDP1;
4165
                    xmaOP     <= xmaopIF;
4166
                    busOP     <= busopWRIF;
4167
                    nextState <= stateMRIreadINCaddr;
4168
 
4169
                else
4170
 
4171
                    --
4172
                    -- Non-autoincrement addresses
4173
                    -- Start address phase of indirect data read
4174
                    -- Address input is in MD
4175
                    --
4176
 
4177
                    case IR(0 to 2) is
4178
 
4179
                        --
4180
                        -- MA <- MD
4181
                        -- MD <- MEM[IB'MA]
4182
                        --
4183
 
4184
                        when opJMS | opJMP =>
4185
                            maOP      <= maopMD;
4186
                            xmaOP     <= xmaopIB;
4187
                            busOP     <= busopRDIBaddr;
4188
                            nextState <= stateMRIexecute;
4189
 
4190
                            --
4191
                            -- MA <- MB
4192
                            -- MD <- MEM[DF'MA]
4193
                            --
4194
 
4195
                        when others =>
4196
                            maOP      <= maopMD;
4197
                            xmaOP     <= xmaopDF;
4198
                            busOP     <= busopRDDFaddr;
4199
                            nextState <= stateMRIreadINDdata;
4200
                    end case;
4201
 
4202
                end if;
4203
 
4204
            --
4205
            -- Start address phase of indirect data read
4206
            -- Address input is in MB
4207
            --
4208
 
4209
            when stateMRIreadINCaddr =>
4210
                case IR(0 to 2) is
4211
 
4212
                    --
4213
                    -- MA <- MB
4214
                    -- MD <- MEM[IB'MA]
4215
                    --
4216
 
4217
                    when opJMS | opJMP =>
4218
                        maOP      <= maopMB;
4219
                        xmaOP     <= xmaopIB;
4220
                        busOP     <= busopRDIBaddr;
4221
                        nextState <= stateMRIexecute;
4222
 
4223
                    --
4224
                    -- MA <- MB
4225
                    -- MD <- MEM[DF'MA]
4226
                    --
4227
 
4228
                    when others =>
4229
                        maOP      <= maopMB;
4230
                        xmaOP     <= xmaopDF;
4231
                        busOP     <= busopRDDFaddr;
4232
                        nextState <= stateMRIreadINDdata;
4233
                end case;
4234
 
4235
            --
4236
            -- Start data phase of indirect data read
4237
            --  MD <- MEM[DF'MA]
4238
            --
4239
 
4240
            when stateMRIreadINDdata =>
4241
                xmaOP     <= xmaopDF;
4242
                busOP     <= busopRDDFdata;
4243
                nextState <= stateMRIexecute;
4244
 
4245
            --
4246
            -- Dispatch the MRI ops.   The previous state was a read data cycle.
4247
            --  The data is in MD and the address is MA.
4248
            --
4249
 
4250
            when stateMRIexecute =>
4251
                case IR(0 to 2) is
4252
 
4253
                    --
4254
                    --  AC <- AC and MD
4255
                    --
4256
 
4257
                    when opAND =>
4258
                        acOP      <= acopANDMD;
4259
                        nextState <= stateDone;
4260
 
4261
                    --
4262
                    -- AC <- AC + MD
4263
                    --
4264
 
4265
                    when opTAD =>
4266
                        acOP      <= acopADDMD;
4267
                        nextState <= stateDone;
4268
 
4269
                    --
4270
                    -- MB <- MD + 1
4271
                    -- IF MD = 7777 (or MB = 0000) Then
4272
                    --    PC <- PC + 1;
4273
                    -- ENDIF
4274
                    -- IF ISZ DIRECT THEN
4275
                    --    MEM[IF'MA] <- MB
4276
                    -- ELSE
4277
                    --    MEM[DF'MA] <- MB
4278
                    -- ENDIF
4279
                    -- Note: Checking MD against 7777 saves a state...
4280
                    --
4281
 
4282
                    when opISZ =>
4283
                        mbOP <= mbopMDP1;
4284
                        if MD = o"7777" then
4285
                            pcOP <= pcopINC;
4286
                        end if;
4287
                        if ((IR(3 to 4) = amDZ) or IR(3 to 4) = amDC) then
4288
                            xmaOP <= xmaopIF;
4289
                            busOP <= busopWRIF;
4290
                        else
4291
                            xmaOP <= xmaopDF;
4292
                            busOP <= busopWRDF;
4293
                        end if;
4294
                        nextState <= stateDone;
4295
 
4296
                    --
4297
                    -- MB <- AC
4298
                    -- AC <- 0000
4299
                    -- IF DCA DIRECT THEN
4300
                    --    MEM[IF'MA] <- MB
4301
                    -- ELSE
4302
                    --    MEM[DF'MA] <- MB
4303
                    -- ENDIF
4304
                    --
4305
 
4306
                    when opDCA =>
4307
                        mbOP <= mbopAC;
4308
                        acOP <= acopCLA;
4309
                        if ((IR(3 to 4) = amDZ) or IR(3 to 4) = amDC) then
4310
                            xmaOP <= xmaopIF;
4311
                            busOP <= busopWRIF;
4312
                        else
4313
                            xmaOP <= xmaopDF;
4314
                            busOP <= busopWRDF;
4315
                        end if;
4316
                        nextState <= stateDone;
4317
 
4318
                    --
4319
                    -- opJMS
4320
                    --
4321
                    -- When the PEX Flip-flop is set, the CPU shall exit from
4322
                    -- Panel Mode to Main Memory (i.e., clear CTRLFF) during
4323
                    -- the next JMP, JMS, RTN1 or RTN2 instruction.  PEX is
4324
                    -- cleared by the JMP, JMS, RTN1 or RTN instruction.
4325
                    --
4326
                    -- IF <- IB
4327
                    -- UF <- UB
4328
                    -- IIFF <- '0'
4329
                    -- MB <- PC
4330
                    -- MEM[IB'MA] <- MB
4331
                    -- IF PEX = '1' THEN
4332
                    --    CTRLFF <- '0'
4333
                    --    PEX    <- '0'
4334
                    -- ENDIF
4335
                    --
4336
 
4337
                    when opJMS =>
4338
                        ifOP     <= ifopIB;
4339
                        ufOP     <= ufopUB;
4340
                        wrOP     <= '1';
4341
                        mbOP     <= mbopPC;
4342
                        pcOP     <= pcopMAP1;
4343
                        xmaOP    <= xmaopIB;
4344
                        memselOP <= '1';
4345
                        busOP    <= busopWRIB;
4346
                        if PEX = '1' then
4347
                            ctrlffOP <= ctrlffopCLR;
4348
                            pexOP    <= pexopCLR;
4349
                        end if;
4350
                        nextState <= stateDone;
4351
 
4352
                    --
4353
                    -- opJMP
4354
                    --
4355
                    -- When the PEX Flip-flop is set, the CPU shall exit from
4356
                    -- Panel Mode to Main Memory (i.e., clear CTRLFF) during
4357
                    -- the next JMP, JMS, RTN1 or RTN2 instruction.  PEX is
4358
                    -- cleared by the JMP, JMS, RTN1 or RTN instruction.
4359
                    --
4360
                    -- IF <- IB
4361
                    -- UF <- UB
4362
                    -- PC <- MA
4363
                    -- IF PEX = '1' THEN
4364
                    --    CTRLFF <- '0'
4365
                    --    PEX    <- '0'
4366
                    -- ENDIF
4367
                    --
4368
 
4369
                    when opJMP =>
4370
                        ifOP <= ifopIB;
4371
                        ufOP <= ufopUB;
4372
                        pcOP <= pcopMA;
4373
                        if PEX = '1' then
4374
                            ctrlffOP <= ctrlffopCLR;
4375
                            pexOP    <= pexopCLR;
4376
                        end if;
4377
                        nextState <= stateDone;
4378
 
4379
                    --
4380
                    -- Can't get to any of these
4381
                    --
4382
 
4383
                    when opIOT =>
4384
                        assert false report "stateMRIexecute: IOT direct." severity warning;
4385
                        nextState <= stateDone;
4386
                    when opOPR =>
4387
                        assert false report "stateMRIexecute: OPR direct." severity warning;
4388
                        nextState <= stateDone;
4389
                    when others =>
4390
                        assert false report "stateMRIexecute: Others direct." severity warning;
4391
                        nextState <= stateDone;
4392
                end case;
4393
 
4394
            --
4395
            -- The previous state set the MA register
4396
            -- This state handles the address phase of the read cycle.
4397
            --  MD <- MEM[IF,MA]
4398
            --
4399
 
4400
            when stateEAEfetchAddr =>
4401
                busOP     <= busopRDIFdata;
4402
                nextState <= stateEAEfetchData;
4403
 
4404
            --
4405
            -- This is the data phase of the EAE second word read.
4406
            -- At the end of this cycle, the second word is in the MD register.
4407
            --  MD <- MEM[IF,MA]
4408
            --
4409
            -- This state will re-dispatch EAE ops that have a single operand
4410
            -- that is used as 'immediate data'.  This state will begin the
4411
            -- fetch of indirect data for EAE ops with indirect operands.
4412
            --
4413
 
4414
            when stateEAEfetchData =>
4415
 
4416
                EAEIR := IR(6) & IR(8) & IR(9) & IR(10);
4417
                case EAEIR is
4418
 
4419
                    --
4420
                    -- OP 7401: NOP
4421
                    --
4422
 
4423
                    when opEAENOP =>
4424
                        nextState <= stateDone;
4425
 
4426
                    --
4427
                    -- OP 7403: MODEA: SCL
4428
                    --          MODEB: ACS
4429
                    --
4430
 
4431
                    when opEAEACS =>
4432
 
4433
                        if EMODE = '0' then
4434
 
4435
                            --
4436
                            -- SCL - The ones complement of the last five bits
4437
                            -- of this operand are loaded into the Step Counter
4438
                            -- and the program resumes at the instruction word
4439
                            -- following the operand.
4440
                            --
4441
 
4442
                            scOP      <= scopNOTMD7to11;
4443
                            nextState <= stateDone;
4444
 
4445
                        else
4446
 
4447
                            --
4448
                            -- ACS - Accumulator to Step Count.
4449
                            -- The ACS instruction doesn't re-dispatch here.
4450
                            -- You shouldn't get here.
4451
                            --
4452
 
4453
                            assert false report "stateEAEfetchData: ACS should not re-dispatch here" severity warning;
4454
                            nextState <= stateLALA;
4455
 
4456
                        end if;
4457
 
4458
                    --
4459
                    -- OP 7405: MUY - Multiply.
4460
                    -- In MODEA, the operand is the multiplier.
4461
                    -- In MODEB, the operand is the address of the multipler,
4462
                    -- which is possibly pre-incremented before use.  Start the
4463
                    -- multiply operation.
4464
                    --
4465
 
4466
                    when opEAEMUY =>
4467
                        if EMODE = '0' then
4468
 
4469
                            EAEop     <= eaeopMUY;
4470
                            nextState <= stateEAEmuy;
4471
 
4472
                        else
4473
 
4474
                            if MA(3 to 11) = maAutoIncr then
4475
 
4476
                                --
4477
                                -- Start the writeback of the incremented data
4478
                                --
4479
 
4480
                                wrOP      <= '1';
4481
                                mbOP      <= mbopMDP1;
4482
                                --XMAOPTBD
4483
                                datafOP   <= '1';
4484
                                memselOP  <= '1';
4485
                                nextState <= stateEAEindWrite;
4486
 
4487
                            else
4488
 
4489
                                --
4490
                                -- Start address phase of indirect data read
4491
                                --
4492
 
4493
                                maOP      <= maopMD;
4494
                                --XMAOPTBD
4495
                                datafOP   <= '1';
4496
                                memselOP  <= '1';
4497
                                nextState <= stateEAEindReadAddr;
4498
 
4499
                            end if;
4500
                        end if;
4501
 
4502
 
4503
                    --
4504
                    -- OP 7407: DVI - Divide
4505
                    -- In MODEA, the operand is the divisor
4506
                    -- In MODEB, the operand is the address of the divisor
4507
                    -- which is possibly pre-incremented before use.  The
4508
                    -- divisor is in MD.
4509
                    --
4510
 
4511
                    when opEAEDVI =>
4512
                        if EMODE = '0' then
4513
 
4514
                            --
4515
                            -- Handle divide overflow condition
4516
                            --
4517
 
4518
                            if AC >= MD then
4519
                                scOP      <= scopCLR;
4520
                                acOP      <= acopCLLCML;
4521
                                mqOP      <= mqopSHL1;
4522
                                nextState <= stateDone;
4523
 
4524
                            --
4525
                            -- Handle normal divide condition
4526
                            --
4527
 
4528
                            else
4529
                                mqaOP     <= mqaopMQ;
4530
                                scOP      <= scopCLR;
4531
                                acOP      <= acopCLL;
4532
                                nextState <= stateEAEsubDVI;
4533
 
4534
                            end if;
4535
 
4536
                        else
4537
                            if MA(3 to 11) = maAutoIncr then
4538
 
4539
                                --
4540
                                -- Start the writeback of the incremented data
4541
                                --
4542
 
4543
                                wrOP      <= '1';
4544
                                mbOP      <= mbopMDP1;
4545
                                --XMAOPTBD
4546
                                --DATAFOP OR IFETCHOP
4547
                                memselOP  <= '1';
4548
                                nextState <= stateEAEindWrite;
4549
 
4550
                            else
4551
 
4552
                                --
4553
                                -- Start address phase of indirect data read
4554
                                --
4555
 
4556
                                maOP      <= maopMD;
4557
                                --XMAOPTBD
4558
                                datafOP   <= '1';
4559
                                memselOP  <= '1';
4560
                                nextState <= stateEAEindReadAddr;
4561
 
4562
                            end if;
4563
                        end if;
4564
 
4565
                    --
4566
                    -- OP 7411: NMI - Normalize
4567
                    -- The NMI instruction doesn't re-dispatch here.
4568
                    -- You shouldn't get here.
4569
                    --
4570
 
4571
                    when opEAENMI =>
4572
                        assert false report "stateEAEfetchData: NMI should not re-dispatch here" severity warning;
4573
                        nextState <= stateLALA;
4574
 
4575
                    --
4576
                    -- OP 7413: SHL - Shift Left.
4577
                    -- The second word of the two-word instruction defines the
4578
                    -- number of shifts to be performed. In Mode A, the number
4579
                    -- of shifts performed is equal to one more than the number
4580
                    -- in the last five bits of the second word.  In Mode B,
4581
                    -- the number of shifts performed is equal to the number in
4582
                    -- the last five bits of the second word.  A shift count of
4583
                    -- zero is legal, and leaves the link, AC, and MQ registers
4584
                    -- unchaged.
4585
                    --
4586
 
4587
                    when opEAESHL =>
4588
                        if EMODE = '0' then
4589
 
4590
                            --
4591
                            -- Mode A:
4592
                            -- Handle case where SHL Shift count is maxed out.
4593
                            --
4594
 
4595
                            if unsigned(MD(7 to 11)) > 24 then
4596
                                scOP      <= scopCLR;
4597
                                mqOP      <= mqopCLR;
4598
                                acOP      <= acopCLACLL;
4599
                                nextState <= stateDone;
4600
 
4601
                            --
4602
                            -- Mode A:
4603
                            -- Normal case where SHL shift count not maxed out.
4604
                            --
4605
 
4606
                            else
4607
                                scOP      <= scopMDP1;
4608
                                nextState <= stateEAEshift;
4609
 
4610
                            end if;
4611
 
4612
                        else
4613
 
4614
                            --
4615
                            -- Mode B:
4616
                            -- Handle case where SHL Shift count is maxed out.
4617
                            --
4618
 
4619
                            if unsigned(MD(7 to 11)) > 25 then
4620
                                scOP      <= scopSET;
4621
                                mqOP      <= mqopCLR;
4622
                                acOP      <= acopCLACLL;
4623
                                nextState <= stateDone;
4624
 
4625
                            --
4626
                            -- Mode B:
4627
                            -- Handle case where SHL Shift count is zero
4628
                            --
4629
 
4630
                            elsif unsigned(MD(7 to 11)) = 0 then
4631
                                scOP      <= scopSET;
4632
                                nextState <= stateDone;
4633
 
4634
                            --
4635
                            -- Mode B:
4636
                            -- Normal case where SHL shift count not maxed out.
4637
                            --
4638
 
4639
                            else
4640
                                scOP      <= scopMD7to11;
4641
                                nextState <= stateEAEshift;
4642
 
4643
                            end if;
4644
                        end if;
4645
 
4646
 
4647
                    --
4648
                    -- OP 7415: ASR - Arithmetic Shift Right.
4649
                    -- The second word of the two-word instruction defines the
4650
                    -- number of shifts to be performed. In Mode A, the number
4651
                    -- of shifts performed is equal to one more than the number
4652
                    -- in the last five bits of the second word.  In Mode B,
4653
                    -- the number of shifts performed is equal to the number in
4654
                    -- the last five bits of the second word.  A shift count of
4655
                    -- zero is legal, and loads the link from AC(0) but leaves
4656
                    -- the AC and MQ registers unchaged.
4657
                    --
4658
 
4659
                    when opEAEASR =>
4660
                        if EMODE = '0' then
4661
 
4662
                            --
4663
                            -- Mode A:
4664
                            -- Handle case where ASR Shift count is maxed out.
4665
                            -- Sign extended AC into L and MQ
4666
                            --
4667
 
4668
                            if unsigned(MD(7 to 11)) > 23 then
4669
                                if AC(0) = '0' then
4670
                                    acOP <= acopCLACLL;
4671
                                    mqOP <= mqopCLR;
4672
                                else
4673
                                    acOP <= acopCLACLLCMACML;
4674
                                    mqOP <= mqopSET;
4675
                                end if;
4676
                                scOP      <= scopCLR;
4677
                                nextState <= stateDone;
4678
 
4679
                            --
4680
                            -- Mode A:
4681
                            -- Normal case where ASR shift count not maxed out.
4682
                            -- Sign extend AC into L
4683
                            --
4684
 
4685
                            else
4686
 
4687
                                scOP <= scopMDP1;
4688
                                if AC(0) = '0' then
4689
                                    acOP  <= acopCLL;
4690
                                else
4691
                                    acOP  <= acopCLLCML;
4692
                                end if;
4693
                                nextState <= stateEAEshift;
4694
 
4695
                            end if;
4696
 
4697
                        else
4698
 
4699
                            --
4700
                            -- Mode B:
4701
                            -- Handle case where ASR Shift count is maxed out.
4702
                            -- Shift sign extended AC
4703
                            --
4704
 
4705
                            if unsigned(MD(7 to 11)) > 25 then
4706
                                if AC(0) = '0' then
4707
                                    acOP  <= acopCLACLL;
4708
                                    mqOP  <= mqopCLR;
4709
                                    gtfOP <= gtfopCLR;
4710
                                else
4711
                                    acOP  <= acopCLACLLCMACML;
4712
                                    mqOP  <= mqopSET;
4713
                                    gtfOP <= gtfopSET;
4714
                                end if;
4715
                                scOP      <= scopSET;
4716
                                nextState <= stateDone;
4717
 
4718
                            --
4719
                            -- Mode B:
4720
                            -- Handle case where ASR Shift count is zero
4721
                            -- Sign extend AC into L
4722
                            --
4723
 
4724
                            elsif unsigned(MD(7 to 11)) = 0 then
4725
                                if AC(0) = '0' then
4726
                                    acOP  <= acopCLL;
4727
                                else
4728
                                    acOP  <= acopCLLCML;
4729
                                end if;
4730
                                nextState <= stateDone;
4731
 
4732
                            --
4733
                            -- Mode B:
4734
                            -- Normal case where ASR shift count not maxed out.
4735
                            --
4736
 
4737
                            else
4738
                                scOP      <= scopMD7to11;
4739
                                if AC(0) = '0' then
4740
                                    acOP  <= acopCLL;
4741
                                else
4742
                                    acOP  <= acopCLLCML;
4743
                                end if;
4744
                                nextState <= stateEAEshift;
4745
 
4746
                            end if;
4747
 
4748
                        end if;
4749
 
4750
                    --
4751
                    -- OP 7417: LSR - Logical Shift Right
4752
                    -- The second word of the two-word instruction defines the
4753
                    -- number of shifts to be performed. In Mode A, the number
4754
                    -- of shifts performed is equal to one more than the number
4755
                    -- in the last five bits of the second word.  In Mode B,
4756
                    -- the number of shifts performed is equal to the number in
4757
                    -- the last five bits of the second word.  A shift count of
4758
                    -- zero is legal, and clears the link without changing the
4759
                    -- AC or MQ registers.
4760
                    --
4761
 
4762
                    when opEAELSR =>
4763
                        if EMODE = '0' then
4764
 
4765
                            --
4766
                            -- Mode A:
4767
                            -- Handle case where LSR Shift count is maxed out.
4768
                            --
4769
 
4770
                            if unsigned(MD) > 23 then
4771
                                scOP      <= scopCLR;
4772
                                acOP      <= acopCLACLL;
4773
                                mqOP      <= mqopCLR;
4774
                                nextState <= stateDone;
4775
 
4776
                            --
4777
                            -- Mode A:
4778
                            -- Normal case where LSR shift count not maxed out.
4779
                            --
4780
 
4781
                            else
4782
                                scOP      <= scopMDP1;
4783
                                acOP      <= acopCLL;
4784
                                nextState <= stateEAEshift;
4785
 
4786
                            end if;
4787
 
4788
                        else
4789
 
4790
                            --
4791
                            -- Mode B:
4792
                            -- Handle case where LSR Shift count is maxed out.
4793
                            --
4794
 
4795
                            if unsigned(MD) > 24 then
4796
                                scOP      <= scopCLR;
4797
                                acOP      <= acopCLACLL;
4798
                                mqOP      <= mqopCLR;
4799
                                gtfOP     <= gtfopCLR;
4800
                                nextState <= stateEAEshift;
4801
 
4802
                            --
4803
                            -- Mode B:
4804
                            -- Handle case where LSR Shift count is zero
4805
                            --
4806
 
4807
                            elsif unsigned(MD(7 to 11)) = 0 then
4808
                                acOP      <= acopCLL;
4809
                                nextState <= stateDone;
4810
 
4811
                            --
4812
                            -- Mode B:
4813
                            -- Normal case where LSR shift count not maxed out.
4814
                            --
4815
 
4816
                            else
4817
                                scOP      <= scopMD7to11;
4818
                                acOP      <= acopCLL;
4819
                                nextState <= stateEAEshift;
4820
 
4821
                            end if;
4822
                        end if;
4823
 
4824
                    --
4825
                    -- OP 7441: SCA - Step Count OR with AC
4826
                    --
4827
                    -- The ones complement of the last five bits of this
4828
                    -- operand are loaded into the Step Counter and the
4829
                    -- program resumes at the instruction word following
4830
                    -- the operand.
4831
                    --
4832
 
4833
                    when opEAESCA =>
4834
                        assert false report "stateEAEfetchData: SCA should not re-dispatch here" severity warning;
4835
                        nextState <= stateLALA;
4836
 
4837
                    --
4838
                    -- OP 7407: DAD - Double Precision Add.  DAD is MODEB only.
4839
                    -- In MODEB, the operand is the address of the quotient,
4840
                    -- which is possibly pre-incremented before use.
4841
                    --
4842
 
4843
                    when opEAEDAD =>
4844
                        if EMODE = '0' then
4845
                            assert false report "stateEAEfetchData: SCA/SCL should not re-dispath here" severity warning;
4846
                            nextState <= stateLALA;
4847
                        else
4848
                            if MA(3 to 11) = maAutoIncr then
4849
 
4850
                                --
4851
                                -- Start the writeback of the incremented data
4852
                                --
4853
 
4854
                                wrOP      <= '1';
4855
                                mbOP      <= mbopMDP1;
4856
                                --XMAOPTBD
4857
                                --DATAFOP OR IFETCHOP
4858
                                memselOP  <= '1';
4859
                                nextState <= stateEAEindWrite;
4860
 
4861
                           else
4862
 
4863
                                --
4864
                                -- Start address phase of indirect data
4865
                                --
4866
 
4867
                                maOP      <= maopMD;
4868
                               --XMAOPTBD
4869
                                datafOP   <= '1';
4870
                                memselOP  <= '1';
4871
                                nextState <= stateEAEindReadAddr;
4872
 
4873
                            end if;
4874
                        end if;
4875
 
4876
                    --
4877
                    -- OP 7445: SCA/MUY -
4878
                    --          DST - Double Precision Store.
4879
                    --
4880
 
4881
                    when opEAEDST =>
4882
                        if EMODE = '0' then
4883
                            EAEop     <= eaeopMUY;
4884
                            nextState <= stateEAEmuy;
4885
                        else
4886
                            if MA(3 to 11) = maAutoIncr then
4887
 
4888
                                --
4889
                                -- Start the writeback of the incremented data
4890
                                --
4891
 
4892
                                wrOP      <= '1';
4893
                                mbOP      <= mbopMDP1;
4894
                                --XMAOPTBD
4895
                                --DATAFOP OR IFETCHOP
4896
                                memselOP  <= '1';
4897
                                nextState <= stateEAEindWrite;
4898
 
4899
                           else
4900
 
4901
                                --
4902
                                -- Start address phase of indirect data
4903
                                --
4904
 
4905
                                maOP      <= maopMD;
4906
                                xmaOP     <= xmaopDF;
4907
                                datafOP   <= '1';
4908
                                memselOP  <= '1';
4909
                                nextState <= stateEAEindReadAddr;
4910
 
4911
                            end if;
4912
                        end if;
4913
 
4914
                    --
4915
                    -- OP 7451:  DPSZ - Double Precision Skip if Zero
4916
                    --
4917
 
4918
                    when opEAEDPSZ =>
4919
                        assert false report "stateEAEfetchData: DPSZ should not re-dispatch here" severity warning;
4920
                        nextState <= stateLALA;
4921
 
4922
                    --
4923
                    -- OP 7453: DPIC - Double Precision Increment
4924
                    --
4925
 
4926
                    when opEAEDPIC =>
4927
                        assert false report "stateEAEfetchData: DPIC should not re-dispatch here" severity warning;
4928
                        nextState <= stateLALA;
4929
 
4930
                    --
4931
                    -- OP 7455: DCM - Double Precision Complement.
4932
                    --
4933
 
4934
                    when opEAEDCM =>
4935
                        assert false report "stateEAEfetchData: DCM should not re-dispatch here" severity warning;
4936
                        nextState <= stateLALA;
4937
 
4938
                    --
4939
                    -- OP 7457: SAM - Subtract AC from MQ.
4940
                    --
4941
 
4942
                    when opEAESAM =>
4943
                        assert false report "stateEAEfetchData: SAM should not re-dispatch here" severity warning;
4944
                        nextState <= stateLALA;
4945
 
4946
                    --
4947
                    -- Everything else.
4948
                    --
4949
 
4950
                    when others =>
4951
                        assert false report "stateEAEfetchData: Unimplemented EAE case" severity warning;
4952
                        nextState <= stateDone;
4953
                end case;
4954
 
4955
            --
4956
            -- statePOPaddr
4957
            -- This state increments the stack pointer SP1 or SP2, sets
4958
            -- the MA to the incremented value, and performs a Read Addr cycle.
4959
            --   MD <- MEM[000'MA]
4960
 
4961
            when statePOPaddr =>
4962
                acOP      <= acopCLA;
4963
                xmaOP     <= xmaopCLR;
4964
                busOP     <= busopRDZFdata;
4965
                nextState <= statePOPdata;
4966
 
4967
            --
4968
            -- statePOPdata
4969
            -- This state completed the read of the top-of-stack and
4970
            -- placed the data in the MD.  It also cleared AC so that
4971
            -- we can add MD to the AC.
4972
            --   AC <- MD
4973
            --
4974
 
4975
            when statePOPdata =>
4976
                acOP      <= acopADDMD;
4977
                nextState <= stateDone;
4978
 
4979
            --
4980
            -- RTN1 Read State
4981
            -- The previous state incremented SP1.
4982
            -- This state sets up a Read Addr Cycle to the memory location
4983
            -- pointed to by SP2.
4984
            --
4985
            -- If Instructions are being fetched from main memory, the stacks
4986
            -- are located in field 0 of main memory.  If Instructions are
4987
            -- being fetched from panel memory, the stacks are located in field
4988
            -- 0 of panel memory, except for the case of a RTN from control
4989
            -- panel  memory via a RTN1 or RTN2 Instruction. In this case, the
4990
            -- main memory stack is accessed by the instruction fetched from
4991
            -- panel memory.
4992
            --
4993
 
4994
            when stateRTN1 =>
4995
                maOP      <= maopSP1;
4996
                xmaOP     <= xmaopCLR;
4997
                busOP     <= stateRDZFaddr;
4998
                nextState <= stateRTNaddr;
4999
 
5000
            --
5001
            -- RTN2 Read State
5002
            -- The previous state incremented SP2.
5003
            -- This state sets up a Read Addr Cycle to the memory location
5004
            -- pointed to by SP2.
5005
            --
5006
            -- If Instructions are being fetched from main memory, the stacks
5007
            -- are located in field 0 of main memory.  If Instructions are
5008
            -- being fetched from panel memory, the stacks are located in field
5009
            -- 0 of panel memory, except for the case of a RTN from control
5010
            -- panel  memory via a RTN1 or RTN2 Instruction. In this case, the
5011
            -- main memory stack is accessed by the instruction fetched from
5012
            -- panel memory.
5013
            --
5014
 
5015
            when stateRTN2 =>
5016
                maOP      <= maopSP2;
5017
                xmaOP     <= xmaopCLR;
5018
                busOP     <= stateRDZFaddr;
5019
                nextState <= stateRTNaddr;
5020
 
5021
            --
5022
            -- stateRTNaddr
5023
            -- The previous state peformed a Read Addr cycle to the top-of-stack.
5024
            -- This state sets up a Read Data Cycle.
5025
            --
5026
            -- If Instructions are being fetched from main memory, the stacks
5027
            -- are located in field 0 of main memory.  If Instructions are
5028
            -- being fetched from panel memory, the stacks are located in field
5029
            -- 0 of panel memory, except for the case of a RTN from control
5030
            -- panel  memory via a RTN1 or RTN2 Instruction. In this case, the
5031
            -- main memory stack is accessed by the instruction fetched from
5032
            -- panel memory.
5033
            --
5034
 
5035
            when stateRTNaddr =>
5036
                xmaOP     <= xmaopCLR;
5037
                busOP     <= busopRDZFdata;
5038
                nextState <= stateRTNdata;
5039
 
5040
            --
5041
            -- stateRTNdata
5042
            -- The previous state performed a Read Data Cycle to the
5043
            -- top-of-stack.
5044
            --
5045
            -- The contents of the Instruction Buffer (IB) is loaded into the
5046
            -- Instruction Field (IF) register.
5047
            --
5048
            -- If the Interrupt Inhibit Flip Flop (II) is set, then the Force
5049
            -- Zero (FZ) flag is cleared.
5050
            --
5051
            -- When the PEX Flip-flop is set, the CPU shall exit from Panel
5052
            -- Mode to Main Memory (i.e., clear CTRLFF) during the next JMP,
5053
            -- JMS, RTN1 or RTN2 instruction.
5054
            --
5055
            -- PEX is cleared by the JMP, JMS, RTN1 or RTN2 instruction.
5056
            --
5057
 
5058
            when stateRTNdata =>
5059
                ifOP <= ifopIB;
5060
                pcOP <= pcopMD;
5061
 
5062
                if PEX = '1' then
5063
                    ctrlffOP <= ctrlffopCLR;
5064
                    pexOP    <= pexopCLR;
5065
                end if;
5066
 
5067
                if II = '1' then
5068
                    fzOP  <= fzopCLR;
5069
                end if;
5070
                nextState <= stateDone;
5071
 
5072
            --
5073
            -- stateEAEindWrite
5074
            -- This state performs an indirect write
5075
            --
5076
 
5077
            when stateEAEindWrite =>
5078
                maOP      <= maopMB;
5079
                --XMAOPTBD
5080
                datafOP   <= '1';
5081
                memselOP  <= '1';
5082
                nextState <= stateEAEindReadAddr;
5083
 
5084
            --
5085
            -- stateEAEindReadAddr -
5086
            -- The previous state set the MA register to the indirect address.
5087
            -- This state handles the address phase of the EAE indirect read cycle.
5088
            --
5089
 
5090
            when stateEAEindReadAddr =>
5091
                rdOP      <= '1';
5092
                --XMAOPTBD
5093
                datafOP   <= '1';
5094
                memselOP  <= '1';
5095
                nextState <= stateEAEindReadData;
5096
 
5097
            --
5098
            -- stateEAEindReadData -
5099
            -- This state handles the data phase of the EAE indirect read cycle.
5100
            -- At the end of this state, the indirect data should be in the MD
5101
            -- register.  This state then redispatches the MUY, DVI, DAD, and
5102
            -- DST instructions.  At this point the operand is in the MD register.
5103
            --
5104
 
5105
            when stateEAEindReadData =>
5106
                EAEIR := IR(6) & IR(8) & IR(9) & IR(10);
5107
                case EAEIR is
5108
 
5109
                    --
5110
                    -- MUY - Setup EAE and go to next state.
5111
                    --
5112
 
5113
                    when opEAEMUY =>
5114
                        eaeOP     <= eaeopMUY;
5115
                        nextState <= stateEAEmuy;
5116
 
5117
                    --
5118
                    -- DVI - Check for overflow right away.  If overflow, then
5119
                    -- set state and exit. Otherwise setup EAE, MQ, SC, and go to
5120
                    -- next state.  The Divisor is in MD.
5121
                    --
5122
 
5123
                    when opEAEDVI =>
5124
 
5125
                        --
5126
                        -- Handle divide overflow condition
5127
                        --
5128
 
5129
                        if AC >= MD then
5130
                            scOP      <= scopCLR;
5131
                            acOP      <= acopCLLCML;
5132
                            mqOP      <= mqopSHL1;
5133
                            nextState <= stateDone;
5134
 
5135
                        --
5136
                        -- Handle normal divide condition
5137
                        --
5138
 
5139
                        else
5140
                            mqaOP     <= mqaopMQ;
5141
                            scOP      <= scopCLR;
5142
                            acOP      <= acopCLL;
5143
                            nextState <= stateEAEsubDVI;
5144
 
5145
                        end if;
5146
 
5147
                    --
5148
                    -- DAD - Add the contents of MD to MQ.
5149
                    --
5150
                    --
5151
 
5152
                    when opEAEDAD =>
5153
                        maOP      <= maopINC;
5154
                        mqOP      <= mqopADDMD;
5155
                        --XMAOPTBD
5156
                        datafOP   <= '1';
5157
                        memselOP  <= '1';
5158
 
5159
                        --
5160
                        -- Handle cases where carry does/doesnot come from MQ
5161
                        --
5162
 
5163
                        if (unsigned('0'& MQ) + unsigned('0' & MD)) > 4095 then
5164
                            nextState <= stateEAEreadDADaddr1;
5165
                        else
5166
                            nextState <= stateEAEreadDADaddr0;
5167
                        end if;
5168
 
5169
                    --
5170
                    -- DST - Stores the MQ data to MEM[XMA & MA]
5171
                    --
5172
 
5173
                    when opEAEDST =>
5174
                        wrOP      <= '1';
5175
                        mbOP      <= mbopMQ;
5176
                        --XMAOPTBD
5177
                        --DATAFOP OR IFETCHOP
5178
                        memselOP  <= '1';
5179
                        nextState <= stateEAEdst;
5180
 
5181
                    --
5182
                    -- Everything else.
5183
                    --
5184
 
5185
                    when others =>
5186
                        nextState <= stateLALA;
5187
 
5188
                end case;
5189
 
5190
            --
5191
            -- StateEAEshift - This is where all the shift loop for the EAE ASR,
5192
            -- LSR, and SHR instructions occurs.  On right shifts, bits shifted
5193
            -- out of of EAE(24) are shifted into the GTF to facillitate
5194
            -- round-off operations.  In Mode A, the  shift operations complete
5195
            -- with SC set to zero.  In Mode B the shift operations complete
5196
            -- with the SC set to 31.
5197
            --
5198
 
5199
            when stateEAEshift =>
5200
                EAEIR := IR(6) & IR(8) & IR(9) & IR(10);
5201
                if unsigned(SC) = 0 then
5202
                    if EAEIR = opEAELSR then
5203
                        acOP <= acopCLL;
5204
                    end if;
5205
                    if EMODE = '0' then
5206
                        scOP <= scopCLR;
5207
                    else
5208
                        scOP <= scopSET;
5209
                    end if;
5210
                    nextState <= stateDone;
5211
                else
5212
                    case EAEIR is
5213
                        when opEAELSR =>
5214
                            if EMODE = '1' then
5215
                                if MQ(11) = '0' then
5216
                                    gtfOP <= gtfopCLR;
5217
                                else
5218
                                    gtfOP <= gtfopSET;
5219
                                end if;
5220
                            end if;
5221
                            acOP <= acopLSR;
5222
                            if AC(11) = '0' then
5223
                                mqOP <= mqopSHR0;
5224
                            else
5225
                                mqOP <= mqopSHR1;
5226
                            end if;
5227
                        when opEAEASR =>
5228
                            if EMODE = '1' then
5229
                                if MQ(11) = '0' then
5230
                                    gtfOP <= gtfopCLR;
5231
                                else
5232
                                    gtfOP <= gtfopSET;
5233
                                end if;
5234
                            end if;
5235
                            acOP <= acopASR;
5236
                            if AC(11) = '0' then
5237
                                mqOP <= mqopSHR0;
5238
                            else
5239
                                mqOP <= mqopSHR1;
5240
                            end if;
5241
                        when opEAESHL =>
5242
                            mqOP <= mqopSHL0;
5243
                            if MQ(0) = '0' then
5244
                                acOP <= acopSHL0;
5245
                            else
5246
                                acOP <= acopSHL1;
5247
                            end if;
5248
                        when others =>
5249
                            assert false report "stateEAEshift: Not a shift OP" severity warning;
5250
                    end case;
5251
                    scOP      <= scopDEC;
5252
                    nextState <= stateEAEwait;
5253
                end if;
5254
 
5255
            --
5256
            -- stateEAEwait
5257
            -- stateEAEshift has a hard time meeting timing.  This gives the
5258
            -- accumulators a little extra time to settle.
5259
            --
5260
 
5261
            when stateEAEwait =>
5262
                nextState <= stateEAEshift;
5263
 
5264
            --
5265
            -- stateEAEnmi
5266
            -- The Step Counter is initially cleared.  The contents of the
5267
            -- Link, AC, and MQ registers are are shifted left until AC(0) and
5268
            -- AC(1) are different or until AC(2) through MQ(11) are all zero.
5269
            -- The Step Count register is increment once for every shift.  If
5270
            -- MODE B, and the contents of AC & MQ is o"4000_0000", the AC is
5271
            -- cleared.
5272
            --
5273
 
5274
            when stateEAEnmi =>
5275
                if (AC(0) /= AC(1)) or (unsigned(AC(2 to 11)) = 0 and unsigned(MQ) = 0) then
5276
                    if EMODE = '1' and unsigned(AC) = 2048 and unsigned(MQ) = 0 then
5277
                        acOP  <= acopCLA;
5278
                    end if;
5279
                    nextState <= stateDone;
5280
                else
5281
                    scOP      <= scopINC;
5282
                    mqOP      <= mqopSHL0;
5283
                    if MQ(0) = '0' then
5284
                        acOP  <= acopSHL0;
5285
                    else
5286
                        acOP  <= acopSHL1;
5287
                    end if;
5288
                    nextState <= stateEAEnmi;
5289
                end if;
5290
 
5291
            --
5292
            -- The contents of the MQ are multiplied by the multiplier (in the
5293
            -- MD) and the MSBs of the 24 bit result are left in the AC and the
5294
            -- LSBs are left in the MQ. The multiplication is unsigned.  If AC
5295
            -- is non-zero, the product is added to AC.
5296
            --
5297
 
5298
            when stateEAEmuy =>
5299
                acOP      <= acopEAEZAC;
5300
                mqOP      <= mqopEAE;
5301
                scOP      <= scop12;
5302
                nextState <= stateDone;
5303
 
5304
            --
5305
            -- stateEAEsubDVI - Long division is a shift and subtract
5306
            -- operation.  This state handles the subtraction.
5307
            -- MQ = (AC & MQ) / MD
5308
            -- AC = (AC & MQ) % MD
5309
            --
5310
 
5311
            when stateEAEsubDVI =>
5312
                if unsigned(LAC) >= unsigned(MD) then
5313
                    mqOP  <= mqopSHL1;
5314
                    acOP  <= acopSUBMD;
5315
                else
5316
                    mqOP  <= mqopSHL0;
5317
                end if;
5318
                scOP      <= scopINC;
5319
                nextState <= stateEAEshiftDVI;
5320
 
5321
            --
5322
            -- stateEAEshiftDVI - Long division is a shift and subtract
5323
            -- operation.  This state handles the shift operation.
5324
            --
5325
 
5326
            when stateEAEshiftDVI =>
5327
 
5328
                --
5329
                -- Check for loop exit condtions
5330
                --
5331
 
5332
                if unsigned(SC) = 13 then
5333
                    acOP      <= acopCLL;
5334
                    nextState <= stateDone;
5335
 
5336
                --
5337
                -- Shift L, AC, and MQ left
5338
                --
5339
 
5340
                else
5341
                    mqaOP     <= mqaopSHL;
5342
                    if MQA(0) = '0' then
5343
                        acOP  <= acopSHL0;
5344
                    else
5345
                        acOP  <= acopSHL1;
5346
                    end if;
5347
                    nextState <= stateEAEsubDVI;
5348
 
5349
                end if;
5350
 
5351
            --
5352
            -- stateEAEreadDADaddr0
5353
            -- This is the address phase of the read cycle for the second
5354
            -- operand (third word).  This state is for cases where there is no
5355
            -- carry from the addition of MQ.
5356
            --
5357
 
5358
            when stateEAEreadDADaddr0 =>
5359
                rdOP      <= '1';
5360
                acOP      <= acopCLL;
5361
                --XMAOPTBD
5362
                datafOP   <= '1';
5363
                memselOP  <= '1';
5364
                nextState <= stateEAEreadDADdata0;
5365
 
5366
            --
5367
            -- stateEAEreadDADaddr1
5368
            -- This is the address phase of the read cycle for the second
5369
            -- operand (third word).   This state is for cases where there is a
5370
            -- carry from the addition of MQ.  Clear the link for the add
5371
            -- instruction in the next state.
5372
            --
5373
 
5374
            when stateEAEreadDADaddr1 =>
5375
                rdOP      <= '1';
5376
                acOP      <= acopCLL;
5377
                --XMAOPTBD
5378
                datafOP   <= '1';
5379
                memselOP  <= '1';
5380
                nextState <= stateEAEreadDADdata1;
5381
 
5382
            --
5383
            -- stateEAEreadDADdata0
5384
            -- This is the data phase of the read cycle for the second operand
5385
            -- (third word).  This state is for cases where there is no carry
5386
            -- from the addition of MQ. Clear the link for the add instruction
5387
            -- in the next state.
5388
            --
5389
 
5390
            when stateEAEreadDADdata0 =>
5391
                acOP      <= acopADDMD;
5392
                nextState <= stateDone;
5393
 
5394
            --
5395
            -- stateEAEreadDADdata1
5396
            -- This is the data phase of the read cycle for the second operand
5397
            -- (third word).  This state is for cases where there is a carry
5398
            -- from the addition of MQ.
5399
            --
5400
 
5401
            when stateEAEreadDADdata1 =>
5402
                acOP      <= acopADDMDP1;
5403
                nextState <= stateDone;
5404
 
5405
            --
5406
            -- stateEAEdst - This state stores the AC data to MEM[XMA & (MA + 1)]
5407
            --
5408
 
5409
            when stateEAEdst =>
5410
                wrOP      <= '1';
5411
                maOP      <= maopINC;
5412
                mbOP      <= mbopAC;
5413
                xmaOP     <= xmaopDF;
5414
                memselOP  <= '1';
5415
                datafOP   <= '1';
5416
                nextState <= stateDone;
5417
 
5418
            --
5419
            -- Done State
5420
            -- This is the last state of the instruction.  This wastes a state
5421
            -- but makes it easy to 'see' the end of the instruction cycle.
5422
            --
5423
 
5424
            when stateDone =>
5425
                nextstate <= stateCheckReq;
5426
 
5427
            --
5428
            -- You've landed in LA-LA land.  You shouldn't get here.  Somehow
5429
            -- some OPCODE was not decoded correctly or the next state for the
5430
            -- State Machine was not set.  Plug your ears, close your eyes and
5431
            -- scream LA-LA-LA-LA-LA-LA-LA-LA-LA-LA-LA.
5432
            --
5433
 
5434
            when stateLALA =>
5435
                nextState <= stateLALA;
5436
 
5437
        end case;
5438
 
5439
    end process;
5440
 
5441
    mem : block
5442
    begin
5443
 
5444
        --!
5445
        --! LXPAR is generated for panel memory accesses: It is asserted when:
5446
        --! #.  MEMSEL asserted and CPU is HD6120 and Panel Mode and Direct
5447
        --!     Memory Op with PDF in any state (two cases of CTRLFF).
5448
        --! #.  MEMSEL asserted and CPU is HD6120 and Panel Mode and Indirect
5449
        --!     Memory Op with PDF asserted (two cases of CTRLFF).
5450
        --!
5451
 
5452
        lxparOP <= '1' when ((memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '0' and ctrlffOP  = ctrlffopSET and datafOP = '0') or
5453
                             (memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '1' and ctrlffOP /= ctrlffopCLR and datafOP = '0') or
5454
                             (memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '0' and ctrlffOP  = ctrlffopSET and datafOP = '1' and PDF = '1') or
5455
                             (memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '1' and ctrlffOP /= ctrlffopCLR and datafOP = '1' and PDF = '1')) else
5456
                   '0';
5457
 
5458
 
5459
        --!
5460
        --! LXMAR is generated for normal memory accesses.  It is asserted when:
5461
        --! #.  MEMSEL asserted and CPU is HD6120 and Panel Mode and Indirect
5462
        --!     Memory Op with PDF negated (two cases of CRTLFF).
5463
        --! #.  MEMSEL asserted and CPU is HD6120 and Normal Mode (two cases of
5464
        --!     CTRLFF).
5465
        --! #.  MEMSEL asserted and not HD6120.
5466
        --!
5467
 
5468
        lxmarOP <= '1' when ((memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '0' and ctrlffOP  = ctrlffopSET and datafOP = '1' and PDF = '0') or
5469
                             (memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '1' and ctrlffOP /= ctrlffopCLR and datafOP = '1' and PDF = '0') or
5470
                             (memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '0' and ctrlffOP /= ctrlffopSET) or
5471
                             (memselOP = '1' and swCPU  = swHD6120 and CTRLFF = '1' and ctrlffOP  = ctrlffopCLR) or
5472
                             (memselOP = '1' and swCPU /= swHD6120)) else
5473
                   '0';
5474
 
5475
        --!
5476
        --! Wait for Bus ACK on:
5477
        --! #.  DMA access
5478
        --! #.  Memory accesses
5479
        --! #.  Reads to devices
5480
        --! #.  Writes to devices
5481
        --!
5482
 
5483
        waitfOP <= '1' when ((memselOP = '1') or
5484
                             (lxdarOP = '1' and rdOP = '1') or
5485
                             (lxdarOP = '1' and wrOP = '1')) else
5486
                   '0';
5487
 
5488
    end block;
5489
 
5490
    --!
5491
    --! DMA Request.
5492
    --! Only start DMA cycle when MEM cycle is unused.
5493
    --!
5494
 
5495
    process(sys.clk, sys.rst)
5496
    begin
5497
        if sys.rst = '1' then
5498
            dmagnt <= '0';
5499
        elsif rising_edge(sys.clk) then
5500
            if dev.dma.req = '1' then
5501
                if memselOP = '0' then
5502
                    dmagnt <= '1';
5503
                end if;
5504
            else
5505
                dmagnt <= '0';
5506
            end if;
5507
        end if;
5508
    end process;
5509
 
5510
    --!
5511
    --! State Machine
5512
    --! The state only changes when properly ack'd and when not doing DMA.
5513
    --!
5514
 
5515
    process(sys.clk, sys.rst)
5516
        variable lastdma : std_logic;
5517
        -- synthesis translate_off
5518
        variable LIN : line;
5519
        -- synthesis translate_on
5520
    begin
5521
        if sys.rst = '1' then
5522
            ioclrb  <= '1';
5523
            wrb     <= '0';
5524
            rdb     <= '0';
5525
            ifetchb <= '0';
5526
            datafb  <= '0';
5527
            lxdarb  <= '0';
5528
            lxmarb  <= '0';
5529
            lxparb  <= '0';
5530
            memselb <= '0';
5531
            intgntb <= '0';
5532
            waitfb  <= '0';
5533
            lastdma := '0';
5534
            state   <= stateReset;
5535
        elsif rising_edge(sys.clk) then
5536
            ioclrb  <= '0';
5537
            wrb     <= '0';
5538
            rdb     <= '0';
5539
            ifetchb <= '0';
5540
            datafb  <= '0';
5541
            lxdarb  <= '0';
5542
 
5543
            lxmarb  <= lxmarOP;
5544
            lxparb  <= lxparOP;
5545
 
5546
            memselb <= '0';
5547
 
5548
            if dmagnt = '1' and memselOP = '1' then
5549
                null;
5550
            else
5551
                if waitfb = '0' or dev.ack = '1' then
5552
                    case busOP is
5553
                        when busopNOP =>
5554
                            null;
5555
                        when busopRESET =>
5556
                            ioclrb  <= '1';
5557
                        when busopIOCLR =>
5558
                            ioclrb  <= '1';
5559
                            lxdarb  <= '1';
5560
                            datafb  <= '1';
5561
                        when busopPANELWR =>
5562
                            wrb     <= '1';
5563
                            memselb <= '1';
5564
                        when busopPANELRDaddr =>
5565
                            memselb <= '1';
5566
                        when busopPANELRDdata =>
5567
                            rdb     <= '1';
5568
                            memselb <= '1';
5569
                        when busopFETCHaddr =>
5570
                            ifetchb <= '1';
5571
                            memselb <= '1';
5572
                        when busopFETCHdata =>
5573
                            rdb     <= '1';
5574
                            ifetchb <= '1';
5575
                            memselb <= '1';
5576
                        when busopWRIB =>
5577
                            wrb     <= '1';
5578
                            memselb <= '1';
5579
                        when busopRDIBaddr =>
5580
                            memselb <= '1';
5581
                        when busopRDIBdata =>
5582
                            memselb <= '1';
5583
                        when busopWRIF =>
5584
                            wrb     <= '1';
5585
                            memselb <= '1';
5586
                        when busopRDIFaddr =>
5587
                            memselb <= '1';
5588
                        when busopRDIFdata =>
5589
                            rdb     <= '1';
5590
                            memselb <= '1';
5591
                        when busopWRDF =>
5592
                            wrb     <= '1';
5593
                            memselb <= '1';
5594
                        when busopRDDFaddr =>
5595
                            datafb  <= '1';
5596
                            memselb <= '1';
5597
                        when busopRDDFdata =>
5598
                            rdb     <= '1';
5599
                            datafb  <= '1';
5600
                            memselb <= '1';
5601
                        when busopIOTWR =>
5602
                            wrb     <= '1';
5603
                            datafb  <= '1';
5604
                            lxdarb  <= '1';
5605
                        when busopIOTRD =>
5606
                            rdb     <= '1';
5607
                            datafb  <= '1';
5608
                            lxdarb  <= '1';
5609
                        when busopWR0 =>
5610
                            wrOP    <= '1';
5611
                            memselb <= '1';
5612
                        when busopWRTBD =>
5613
                            memselb <= '1';
5614
                        when busopRDTBDaddr =>
5615
                            memselb <= '1';
5616
                        when busopRDTBDdata =>
5617
                            rdb     <= '1';
5618
                            memselb <= '1';
5619
                        when others =>
5620
                            null;
5621
                    end case;
5622
 
5623
                    ioclrb  <= ioclrOP;
5624
                    wrb     <= wrOP;
5625
                    rdb     <= rdOP;
5626
                    ifetchb <= ifetchOP;
5627
                    datafb  <= datafOP;
5628
                    lxdarb  <= lxdarOP;
5629
                    lxmarb  <= lxmarOP;
5630
                    lxparb  <= lxparOP;
5631
                    memselb <= memselOP;
5632
 
5633
                    intgntb <= intgntOP;
5634
                    waitfb  <= waitfOP;
5635
                    state   <= nextState;
5636
                end if;
5637
            end if;
5638
 
5639
-- synthesis translate_off
5640
 
5641
            if dmagnt = '1' and lastdma = '0' then
5642
                assert false report "-------------> DMA Asserted <------------" severity note;
5643
            elsif dmagnt = '0' and lastdma = '1' then
5644
                assert false report "-------------> DMA Negated <------------" severity note;
5645
            end if;
5646
            lastdma := dmagnt;
5647
 
5648
-- synthesis translate_on
5649
 
5650
        end if;
5651
    end process;
5652
 
5653
--    oops <= '1' when ((xmaOP  = xmaopIF and datafOP  = '1') or
5654
--                      (xmaOP  = xmaopDF and datafOP  = '0') or
5655
--                      (xmaOP /= xmaopIF and memselOP = '1') or
5656
--                      (xmaOP /= xmaopDF and memselOP = '1')) else '0';
5657
 
5658
 
5659
    oops <= '1' when ((busOP = busopRESET       and ioclrOP   =      '0') or            -- IOCLR should be set
5660
 
5661
                      (busOP = busopIOCLR       and ioclrOP  =       '0') or            -- IOCLR should be set
5662
                      (busOP = busopIOCLR       and lxdarOP  =       '0') or            -- LXDAR should be set
5663
                      (busOP = busopIOCLR       and datafOP  =       '0') or            -- DATAF should be set
5664
 
5665
                      (busOP = busopFETCHaddr   and xmaOP    /=  xmaopIF) or
5666
                      (busOP = busopFETCHaddr   and ifetchOP  =      '0') or
5667
                      (busOP = busopFETCHaddr   and memselOP  =      '0') or
5668
 
5669
                      (busOP = busopFETCHdata   and xmaOP    /=  xmaopIF) or
5670
                      (busOP = busopFETCHdata   and ifetchOP  =      '0') or
5671
                      (busOP = busopFETCHdata   and memselOP  =      '0') or
5672
                      (busOP = busopFETCHdata   and rdOP      =      '0') or
5673
 
5674
                      (busOP = busopWRIB        and xmaOP    /=  xmaopIB) or
5675
                      (busOP = busopWRIB        and memselOP  =      '0') or
5676
                      (busOP = busopWRIB        and wrOP      =      '0') or
5677
 
5678
                      (busOP = busopRDIBaddr    and xmaOP    /=  xmaopIB) or
5679
                      (busOP = busopRDIBaddr    and memselOP  =      '0') or
5680
 
5681
                      (busOP = busopRDIBdata    and xmaOP    /=  xmaopIB) or
5682
                      (busOP = busopRDIBdata    and memselOP  =      '0') or
5683
                      (busOP = busopRDIBdata    and rdOP      =      '0') or
5684
 
5685
                      (busOP = busopWRIF        and xmaOP    /=  xmaopIF) or
5686
                      (busOP = busopWRIF        and memselOP  =      '0') or
5687
                      (busOP = busopWRIF        and wrOP      =      '0') or
5688
 
5689
                      (busOP = busopRDIFaddr    and xmaOP    /=  xmaopIF) or
5690
                      (busOP = busopRDIFaddr    and memselOP  =      '0') or
5691
 
5692
                      (busOP = busopRDIFdata    and xmaOP    /=  xmaopIF) or
5693
                      (busOP = busopRDIFdata    and memselOP  =      '0') or
5694
                      (busOP = busopRDIFdata    and rdOP      =      '0') or
5695
 
5696
                      (busOP = busopWRDF        and xmaOP    /=  xmaopDF) or
5697
                      (busOP = busopWRDF        and memselOP  =      '0') or
5698
                      (busOP = busopRDDFaddr    and datafOP   =      '0') or
5699
                      (busOP = busopWRDF        and wrOP      =      '0') or
5700
 
5701
                      (busOP = busopRDDFaddr    and xmaOP    /=  xmaopDF) or
5702
                      (busOP = busopRDDFaddr    and memselOP  =      '0') or
5703
                      (busOP = busopRDDFaddr    and datafOP   =      '0') or
5704
 
5705
                      (busOP = busopRDDFdata    and xmaOP    /=  xmaopDF) or
5706
                      (busOP = busopRDDFdata    and memselOP  =      '0') or
5707
                      (busOP = busopRDDFdata    and datafOP   =      '0') or
5708
                      (busOP = busopRDDFdata    and rdOP      =      '0') or
5709
 
5710
                      (busOP = busopWRZF        and xmaOP    /= xmaopCLR) or
5711
                      (busOP = busopWRZF        and memselOP   =     '0') or
5712
                      (busOP = busopWRZF        and wrOP       =     '0') or
5713
 
5714
                      (busOP = busopRDZFaddr    and xmaOP    /= xmaopCLR) or
5715
                      (busOP = busopRDZFaddr    and memselOP  =      '0') or
5716
 
5717
                      (busOP = busopRDZFdata    and xmaOP    /= xmaopCLR) or
5718
                      (busOP = busopRDZFdata    and memselOP  =      '0') or
5719
                      (busOP = busopRDZFdata    and rdOP      =      '0') or
5720
 
5721
                      (busOP = busopWRIOT       and datafOP  =       '0') or
5722
                      (busOP = busopWRIOT       and lxdarOP  =       '0') or
5723
                      (busOP = busopWRIOT       and wrOP     =       '0') or
5724
 
5725
                      (busOP = busopRDIOT       and datafOP  =       '0') or
5726
                      (busOP = busopRDIOT       and lxdarOP  =       '0') or
5727
                      (busOP = busopRDIOT       and rdOP     =       '0')) else '0';
5728
 
5729
 
5730
    --!
5731
    --! Externally visable (front panel) register state is only updated at
5732
    --! certain times in the instruction cycle.
5733
    --!
5734
 
5735
    process(sys.clk, sys.rst)
5736
        variable CPC : addr_t;
5737
    begin
5738
        if sys.rst = '1' then
5739
            cpu.regs.PC  <= (others => '0');
5740
            cpu.regs.AC  <= (others => '0');
5741
            cpu.regs.IR  <= (others => '0');
5742
            cpu.regs.MQ  <= (others => '0');
5743
            cpu.regs.ST  <= (others => '0');
5744
            cpu.regs.SC  <= (others => '0');
5745
            cpu.regs.MD  <= (others => '0');
5746
            cpu.regs.MA  <= (others => '0');
5747
            cpu.regs.XMA <= (others => '0');
5748
            CPC          := (others => '0');
5749
        elsif rising_edge(sys.clk) then
5750
 
5751
            --
5752
            -- Handle reads are writes
5753
            --
5754
 
5755
            if lxmarb = '1' then
5756
                if rdb = '1' then
5757
                    cpu.regs.MD <= MD;
5758
                elsif wrb = '1' then
5759
                    cpu.regs.MD <= MB;
5760
                end if;
5761
                cpu.regs.MA  <= MA;
5762
                cpu.regs.XMA <= XMA;
5763
            end if;
5764
 
5765
            --
5766
            -- State-based updates
5767
            --
5768
 
5769
            case state is
5770
 
5771
                --
5772
                -- Instruction Fetch
5773
                --
5774
 
5775
                when stateFetchAddr =>
5776
                    CPC := PC;
5777
 
5778
                --
5779
                -- State Halt Done
5780
                --
5781
 
5782
                when stateHaltDone =>
5783
                    cpu.regs.PC <= PC;
5784
                    cpu.regs.AC <= AC;
5785
                    cpu.regs.IR <= IR;
5786
                    cpu.regs.MA <= MA;
5787
                    cpu.regs.MQ <= MQ;
5788
                    cpu.regs.ST <= L & GTF & IRQ & II & ID & UF & INF & DF;
5789
                    cpu.regs.SC <= "0000000" & SC;
5790
 
5791
                --
5792
                -- Last state of instruction
5793
                --
5794
 
5795
                when stateDone =>
5796
                    cpu.regs.PC <= PC;
5797
                    cpu.regs.AC <= AC;
5798
                    cpu.regs.IR <= IR;
5799
                    cpu.regs.MQ <= MQ;
5800
                    cpu.regs.ST <= L & GTF & IRQ & II & ID & UF & INF & DF;
5801
                    cpu.regs.SC <= "0000000" & SC;
5802
                    --dumpState(CPC);
5803
 
5804
                --
5805
                -- Anything else?
5806
                --
5807
 
5808
                when others =>
5809
                    null;
5810
            end case;
5811
        end if;
5812
    end process;
5813
 
5814
    --!
5815
    --! DMA Bus Switch
5816
    --!
5817
 
5818
    process(dmagnt, dev.dma.rd, dev.dma.wr, dev.dma.lxpar, dev.dma.lxmar, dev.dma.memsel,
5819
            dev.dma.addr, dev.dma.eaddr, dev.data, rdb, wrb, ifetchb, lxmarb, lxparb,
5820
            lxdarb, memselb, datafb, MA, MB, XMA)
5821
    begin
5822
        if dmagnt = '1' then
5823
            cpu.buss.rd     <= dev.dma.rd;
5824
            cpu.buss.wr     <= dev.dma.wr;
5825
            cpu.buss.ifetch <= '0';
5826
            cpu.buss.dataf  <= '0';
5827
            cpu.buss.lxmar  <= dev.dma.lxmar;
5828
            cpu.buss.lxpar  <= dev.dma.lxpar;
5829
            cpu.buss.lxdar  <= '0';
5830
            cpu.buss.memsel <= dev.dma.memsel;
5831
            cpu.buss.addr   <= dev.dma.addr;
5832
            cpu.buss.eaddr  <= dev.dma.eaddr;
5833
            cpu.buss.data   <= dev.data;
5834
        else
5835
            cpu.buss.rd     <= rdb;
5836
            cpu.buss.wr     <= wrb;
5837
            cpu.buss.ifetch <= ifetchb;
5838
            cpu.buss.dataf  <= datafb;
5839
            cpu.buss.lxmar  <= lxmarb;
5840
            cpu.buss.lxpar  <= lxparb;
5841
            cpu.buss.lxdar  <= lxdarb;
5842
            cpu.buss.memsel <= memselb;
5843
            cpu.buss.addr   <= MA;
5844
            cpu.buss.eaddr  <= XMA;
5845
            cpu.buss.data   <= MB;
5846
        end if;
5847
    end process;
5848
 
5849
    --!
5850
    --! Data Latch
5851
    --!
5852
 
5853
    process(sys.rst, rdb, dev.data, MD)
5854
    begin
5855
        if sys.rst = '1' then
5856
            MD <= (others => '0');
5857
        elsif rdb = '1' then
5858
            MD <= dev.data;
5859
        else
5860
            MD <= MD;
5861
        end if;
5862
    end process;
5863
 
5864
    --!
5865
    --! CPU combinational outputs
5866
    --!
5867
 
5868
    cpu.buss.ioclr  <= ioclrb;
5869
    cpu.buss.intgnt <= intgntb;
5870
    cpu.buss.dmagnt <= dmagnt;
5871
    cpu.run         <= '0' when ((state = stateReset            ) or
5872
                                 (state = stateInit             ) or
5873
                                 (state = stateHalt             ) or
5874
                                 (state = stateContinue         ) or
5875
                                 (state = stateLoadADDR         ) or
5876
                                 (state = stateLoadEXTD         ) or
5877
                                 (state = stateClear            ) or
5878
                                 (state = stateDepositWriteData ) or
5879
                                 (state = stateDeposit          ) or
5880
                                 (state = stateExamine          ) or
5881
                                 (state = stateExamineReadAddr  ) or
5882
                                 (state = stateExamineReadData  ) or
5883
                                 (state = stateHaltDone         ) or
5884
                                 (state = stateLALA             )) else
5885
                       '1';
5886
 
5887
end rtl;

powered by: WebSVN 2.1.0

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