#INCLUDE "/home/amu5/users/georget/Phd/Simul/Defs/defs.inc"
#INCLUDE "/home/amu5/users/georget/Phd/Simul/PLA/RegC.inc"
#INCLUDE "/home/amu5/users/georget/Phd/Simul/PLA/PslC.inc"
#INCLUDE "/home/amu5/users/georget/Phd/Simul/PLA/NbsC.inc"
#INCLUDE "/home/amu5/users/georget/Phd/Simul/PLA/SeqC.inc"
#USE "/home/amu5/users/georget/Phd/Simul/library"



PROC Dec1CtrlB(CHAN OF BUNDLE In,CtrlAB,PCAB,LSMP0,LSMP1,RdGA,RdGena1,FromregAA,
                               FromregBA, FromRGA,FromregCA,FromImmA,
                               FromXpA,FromNGA,ALUgo,RdGenr,ToregAD,ToRGrs,
                               ToRGpc,ToregBD,ToregCD,ToImmd,ToXp,ToNGD,Ia3,
                               []CHAN OF DEB.MESSAGE screen, VAL INT trace, evaluate ) --4



  [32]BOOL Ib, Ctrlb, seqoutb, psloutb, nbsb,Regcout1b,Regcout2b,
           out0b,out1b,out2b,out3b:
  [28]BOOL Rsb:
  [3]BOOL  sq1b:
  [2]BOOL  sq0b:
  [2]BOOL  sq2b:
  [10]BOOL seqinb:
  [14]BOOL Inb:
  [26]BOOL I2b:
  [64]BOOL Regcoutb:
  [3]BOOL pslinb:
  [8]BOOL nbsinb:
  [26]BOOL I3b:
  [21]BOOL Ngb:
  [7]BOOL ALUokb:
  [6]BOOL modeb:

  INT clock:
  [15]INT delay:
  [1][OCCT.SIZE][OCCT.COL]INT null.occ.table:


  BOOL first,end,Aluok,r15A,r15M,Nrdg, I20,toI3,multi,NImm,Ntox0,ToN,Nalw1,done, finish:

  INT seqin,seqout,pslin,pslout,nbsin,nbsout, RegIn, Regcout1,Regcout2, temp,temp1,temp2,temp3,temp4,temp5:

  [MESGLEN]INT I2,Rs,Rd,I3,Ng,I,Ctrl,Pc,IRd,Ntrmpc,AckfRdg,AcktRdg,Acka,I2d,Ackb,
          Ackr,I3d,Ackc, Ackim,Ackxp,Ackgn,ALUok,Ack:


  [39][36]INT RegCout:
  [39][14]INT RegCmatch:
  [39][14]INT RegCmask:
  [2][3]INT PslCmatch:
  [2][3]INT PslCmask:
  [2][2]INT PslCout:
  [18][7]INT NbsCout:
  [18][8]INT NbsCmatch:
  [18][8]INT NbsCmask:
  [14][3] INT SeqCout:
  [14][10] INT SeqCmatch:
  [14][10] INT SeqCmask:

  -------------------------------------------------------------
  PROC calculate.delays()
    SEQ
      delay[0]:=    ((((REGCPLA + XOR) + XOR)+ NOR) + TOGGLE)+SELECT
      delay[1]:=    0
      delay[2]:=    SELECT + CALLR
      delay[13]:=   SELECT + XOR
      delay[3]:=    CALLR
      delay[4]:=    ((NOR + NOR) + SELECT) + MULLERC
      delay[5]:=    (NOR + NOR) + CALLR
      delay[6]:=    (NOR + NOR) + CALLR
      delay[7]:=    SELECT
      delay[8]:=    SELECT
      delay[9]:=    SELECT
      delay[10]:=   SELECT
      delay[11]:=   3*MULLERC
      delay[12]:=   (XOR + SELECT) + NOR
  :
  -------------------------------------------------------------

  PROC RegCpla(INT In, INT Out1, Out2)

    SEQ
      decode64(RegCout, RegCmatch, RegCmask, In, Out1, Out2, screen[0])

  :
  ------------------------------------------------------
  PROC PslCpla(INT In, INT Out)

    SEQ
      decode(PslCout, PslCmatch, PslCmask, In, Out)

  :
  ------------------------------------------------------
  PROC NbsCpla(INT In, INT Out)

    SEQ
      decode(NbsCout, NbsCmatch, NbsCmask, In, Out)

  :
  ------------------------------------------------------
  PROC SeqCpla(INT In, INT Out)
    SEQ
      decode(SeqCout, SeqCmatch, SeqCmask, In, Out)

  :
  ------------------------------------------------------------------------------
  PROC mkseqin()
    SEQ
      --Rsb[4] is x i.e. not used

      seqinb:= [Rsb[4], r15A, Ib[15],Ib[20],Ib[21],Ib[24],Aluok, sq1b[0], sq1b[1],sq1b[2]]
      init.hex(seqin, seqinb)

  :
  ---------------------------------------------------------


  PROC mkIn()
    SEQ


      [Inb FROM 0 FOR 2]:=[(seqoutb[1]),(seqoutb[2])]
      Inb[2]:=Ib[4]
      Inb[3]:=Ib[7]
      [Inb FROM 4 FOR 8]:=[Ib FROM 20 FOR 8]
      Inb[12]:=Rsb[4]
      Inb[13]:=Ctrlb[5]     --nXR
      init.hex(RegIn, Inb)
  :
  -------------------------------------------------------
  PROC mkI2()
    BOOL Bw:

    SEQ

      [I2b FROM 0 FOR 3]:=[Regcoutb[NIMM],Regcoutb[MULT],Regcoutb[TON]]
      [I2b FROM 3 FOR 4]:=[Regcoutb FROM 1 FOR 4]

      Bw:= (Regcoutb[BWEN] AND Ib[22])

      [I2b FROM 7 FOR 2]:=[Regcoutb[TOI3],Bw]
      [I2b FROM 9 FOR 7]:=[Ib FROM 5 FOR 7]
      [I2b FROM 16 FOR 3]:=[Regcoutb FROM 6 FOR 3]
      [I2b FROM 19 FOR 4]:=[Ib FROM 28 FOR 4]
      I2b[23]:=Ctrlb[6]                        ---Ipar==new.pcpar
      [I2b FROM 24 FOR 2]:=[Ctrlb FROM 0 FOR 2]
      init.hex(I2d[0], I2b)


  :
  ------------------------------------------

  PROC mkRS()
    INT pc,pc1, lk,sel0,in1,in2,in3, sel1,sel2,sel3,out0,out1,out2,out3:
    [32]BOOL  out0b,out1b,out2b,out3b:

    SEQ
      pc:=#F                            --r15
      pc1:=#F
      lk:=#E                             --r14

      --{ Rs[] = RdEn,ArNp,Ra[3:0],Rb[3:0],Psel[1:0],
        --LrNp,Rm[3:0],Rw[3:0],NBS[6:0] }
      ---------------------------------------
      init.hex(sel0, [Regcoutb FROM 28 FOR 2])
      init.hex(in1,  [Ib FROM 16 FOR 4])
      init.hex(in2,  [Ib FROM 8 FOR 4])
      mux4(sel0,pc,in1,in2,pc1,out0)
      ----------------------------------------
      init.hex(sel1, [Regcoutb FROM 30 FOR 2])
      init.hex(in1,  [Ib FROM 16 FOR 4])
      init.hex(in2,  [Ib FROM 12 FOR 4])
      init.hex(in3,  [Ib FROM 0 FOR 4])
      mux4(sel1,Rd[0],in1,in2,in3,out1)
      ----------------------------------------
      init.hex(sel2, [Regcoutb FROM 32 FOR 2])
      init.hex(in2,  [Ib FROM 12 FOR 4])
      mux4(sel2,pc,Rd[0],in2,pc1,out2)
      -----------------------------------------
      init.hex(sel3, [Regcoutb FROM 34 FOR 2])
      init.hex(in2,  [Ib FROM 16 FOR 4])
      init.hex(in3,  [Ib FROM 12 FOR 4])
      mux4( sel3,pc,lk,in2,in3,out3)
      -----------------------------------------
      int.to.bool(out0,out0b)
      int.to.bool(out1,out1b)
      int.to.bool(out2,out2b)
      int.to.bool(out3,out3b)
      [Rsb FROM 7 FOR 4]:= [out3b FROM 0 FOR 4]
      [Rsb FROM 11 FOR 4]:=[out2b FROM 0 FOR 4]
      [Rsb FROM 18 FOR 4]:=[out1b FROM 0 FOR 4]
      [Rsb FROM 22 FOR 4]:=[out0b FROM 0 FOR 4]
      r15A:=((Rsb[10] AND Rsb[9]) AND (Rsb[8] AND Rsb[7]))
      r15M:=((Rsb[14] AND Rsb[13]) AND (Rsb[12] AND Rsb[11]))
      Rsb[15]:=Regcoutb[25]
      [Rsb FROM 26 FOR 2]:=[Regcoutb FROM 26 FOR 2]

      -----------------------------------
      pslinb:=[Ib[16], Ib[19], Ctrlb[5]]
      init.hex(pslin,pslinb)
      PslCpla(pslin, pslout)
      int.to.bool(pslout, psloutb)
      [Rsb FROM 16 FOR 2]:=[psloutb FROM 0 FOR 2]
      -----------------------------------
      nbsinb:=[Ib[15], Ib[20], Ib[22], Regcoutb[NRDG],
               modeb[0],modeb[1],modeb[2],modeb[3]]
      init.hex(nbsin,nbsinb)
      NbsCpla(nbsin,nbsout)
      int.to.bool(nbsout, nbsb)
      [Rsb FROM 0 FOR 7]:=[nbsb FROM 0 FOR 7]
      init.hex(Rs[0],Rsb)
  :

  -------------------------------------------------------------
  PROC mkI3()
    BOOL Bw:
    INT i,j, result:
    [32]BOOL jb:

    SEQ
      Bw:= (Regcoutb[BWEN] AND Ib[22])
      [I3b FROM 0 FOR 3]:=[Bw,Regcoutb[NTOX],Regcoutb[NALW0]]
      [I3b FROM 3  FOR 4]:= [Regcoutb FROM 9 FOR 4]
      [I3b FROM 7  FOR 2]:=[Ib FROM 15 FOR 2]
      [I3b FROM 9  FOR 6]:=[Ib FROM 19 FOR 6]
      I3b[15]:=r15A
      I3b[16]:=r15M
      [I3b FROM 17  FOR 3]:=[Ctrlb FROM 2 FOR 3]    --vect[2:0]

      --------------------------send No of LDM, STM registers preemptions off wrtctrl
      j:=0
      int.to.bool(j,jb)
      IF
        ((((I[0]) /\  #0E000000) = #08000000) AND (first=TRUE))  --ldm or stm
          SEQ
            first:=FALSE
            IF
              (((I[0]) /\  #00100000) = #00100000)   --ldm
                SEQ
                  SEQ i=0 FOR 16
                    SEQ
                      IF
                        Ib[i]=TRUE
                          SEQ
                            j:=j+1
                        Ib[i]= FALSE
                          SEQ
                            SKIP
                  int.to.bool(j,jb)

              (((I[0]) /\  #00100000) <> #00100000)   --ldm
                SEQ
                  SKIP
        TRUE
          SEQ
            SKIP
      [I3b FROM 20  FOR 4]:=[jb FROM 0 FOR 4] 
 
      -------------------------  LDR or LDM Rd=r15  preemptions off AddC-Ctrl3
      IF
        (((((I[0]) /\  #0C000000) = #04000000)   AND ((((I[0]) /\  #00100000) = #00100000)  AND  (((I[0]) /\  #0000F000) = #0000F000)))  OR   ((((I[0]) /\  #0E000000) = #08000000)   AND  ((((I[0]) /\  #00100000) = #00100000)   AND   (((I[0]) /\  #00008000) = #00008000)))) 
          SEQ
            I3b[24]:=TRUE 
        TRUE
          SEQ
            I3b[24]:=FALSE

      -------------------------  send NULL message?? preemptions off AddC-Ctrl3
      decode.instruction.dec1(I[0], result)
      IF
        result<>(-1)
          SEQ
            I3b[25]:=TRUE
        TRUE
          SEQ
            I3b[25]:=FALSE

             




      
      init.hex(I3d[0],I3b)

  :
  -------------------------------------------------------------
  PROC mkNG()
    SEQ
      [Ngb FROM 0 FOR 3]:= [Ctrlb FROM 2 FOR 3]       --vect[2:0]
      [Ngb FROM 3 FOR 2]:= [Regcoutb FROM 20 FOR 2]   --NGn
      [Ngb FROM 5 FOR 16]:= [Ib FROM 0 FOR 16]        --I[15:0]

      init.hex(Ng[0], Ngb)
  :


  --********************************************************************

  SEQ
    RegCout:=CRegCout
    RegCmatch:=CRegCmatch
    RegCmask:=CRegCmask
    PslCmatch:=CPslCmatch
    PslCmask:=CPslCmask
    PslCout:=CPslCout
    NbsCout:=CNbsCout
    NbsCmatch:=CNbsCmatch
    NbsCmask:=CNbsCmask
    SeqCout:=CSeqCout
    SeqCmatch:=CSeqCmatch
    SeqCmask:=CSeqCmask

    Ackb[TIME.STAMP]:=0
    Ackr[TIME.STAMP]:=0
    Ackc[TIME.STAMP]:=0
    Ackim[TIME.STAMP]:=0
    Ackxp[TIME.STAMP]:=0
    Ackgn[TIME.STAMP] :=0




    seqout:=0
    done:= FALSE
    end:=FALSE
    Rsb[4]:=FALSE
    int.to.bool(seqout, seqoutb)
    calculate.delays()
    --RESET: GET INITIAL MODE FROM CTRL3 SHOULD BE  SVC

    ALUgo? ALUok   --ALUok[0]=(ALuok, mode[5:0])
    int.to.bool(ALUok[0],ALUokb)
    Aluok:=ALUokb[0]
    [modeb FROM 0 FOR 6]:=[ALUokb FROM 1 FOR 6]   --mode[5:4] is not used here.......


    PAR
      In?  I         -- from CtrlA read I, PC
      CtrlAB? Ctrl   --and Ctrl(nxr, vect,xt,ipar)
      PCAB?  Pc
    --***************************************
    clock:=I[TIME.STAMP]
    --***************************************
    debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: First Instruction has been received from CtrlA", Pc)
    int.to.bool(I[0], Ib)
    int.to.bool(Ctrl[0], Ctrlb)
    -----------------------------------------------
    mkIn()


    RegCpla(RegIn,Regcout1,Regcout2)                 --call PLA
    int.to.bool(Regcout1, Regcout1b)
    int.to.bool(Regcout2, Regcout2b)



    [Regcoutb FROM 0 FOR ((SIZE (RegCout[0]))/2)]:=[Regcout2b FROM 0 FOR ((SIZE (RegCout[0]))/2)]
    [Regcoutb FROM ((SIZE (RegCout[0]))/2) FOR ((SIZE (RegCout[0]))/2)]:=
    [Regcout1b FROM 0 FOR ((SIZE (RegCout[0]))/2)]


    [sq1b FROM 0 FOR 3]:=[Regcoutb FROM 14 FOR 3]

    Nrdg:=  Regcoutb[NRDG]
    toI3:=  Regcoutb[TOI3]
    NImm:=  Regcoutb[NIMM]
    Ntox0:= Regcoutb[NTOX]
    ToN:=   Regcoutb[TON]
    Nalw1:= Regcoutb[NALW1]

    get.bit(20,I[0],I20)

    -----------------------------------------------

    WHILE (end = FALSE)

      SEQ
        first:=TRUE
        --***************************************
        clock:=clock+delay[0]
        --***************************************

        Rd[0]:=15   -- { NB Rd[] = 15 when RdGen inactive ! }

        IF
          (Nrdg=FALSE)

            ------------start interaction with RdGen-----------------

            SEQ
              debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Nrdg=FALSE--Interaction with RdGen ", Pc)

              IRd[0] := (I[0] /\ #0000FFFF)    --IRd = I[15:0]
              IRd[TIME.STAMP]:= clock
              RdGenr!IRd
              done:=FALSE
              ALT
                LSMP0? Rd
                  SEQ
                    LSMP1? Ntrmpc
                    clock:=Rd[TIME.STAMP]
                RdGA? AckfRdg
                  SEQ
                    clock:=AckfRdg[TIME.STAMP]
                    done:=TRUE

              WHILE (done=FALSE)
                SEQ
                  mkI2()
                  mkRS()

                  PAR
                    ---------------------------------------------
                    SEQ                           --to/from AddInt
                      Ntrmpc[TIME.STAMP]:=clock+delay[1]
                      Ntrmpc[STALL]:=-1
                      debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Nrdg=FALSE Waiting to send NTRM to AddInt", Ntrmpc)
                      ToregAD!Ntrmpc
                      FromregAA? Acka
                      debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Nrdg=FALSE sent NTRM to AddInt", Ntrmpc)

                    ---------------------------------------------
                    SEQ                           --to/from DEC2

                      IF
                        (I20=FALSE)
                          SEQ
                            I2d[TIME.STAMP]:=clock+delay[2]
                            I2d[STALL]:=-1
                            debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: Nrdg=FALSE Waiting to send to Dec2", Pc)
                            ToregBD!I2d
                            FromregBA? Ackb
                            Ackb[TIME.STAMP]:=Ackb[TIME.STAMP]+CALLA

                            debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: Nrdg=FALSE sent to Dec2", Pc)

                        TRUE
                          SEQ
                            Ackb[TIME.STAMP]:=clock+delay[13]
                            SKIP
                    ---------------------------------------------
                    SEQ                   --to/from Register Bank
                      Rs[TIME.STAMP]:=clock+delay[3]
                      Rs[STALL]:=-1
                      debugmsg(trace,screen[2], "DEC1-Dec1CtrlB: Nrdg=FALSE Waiting to send to RegBank", Pc)
                      PAR
                        ToRGrs!Rs
                        ToRGpc!Pc
                      FromRGA? Ackr
                      Ackr[TIME.STAMP]:=Ackr[TIME.STAMP]+CALLA
                      debugmsg(trace,screen[2], "DEC1-Dec1CtrlB: Nrdg=FALSE sent to RegBank", Pc)


                  -----wait for either new data or ack from RdGen
                  temp:=max(Acka[TIME.STAMP],Ackb[TIME.STAMP])
                  AcktRdg[TIME.STAMP]:=max(temp,Ackr[TIME.STAMP])
                  RdGena1!AcktRdg
                  ALT
                    LSMP0? Rd
                      SEQ
                        LSMP1? Ntrmpc
                        clock:=Rd[TIME.STAMP]
                    RdGA? AckfRdg
                      SEQ
                        clock:=AckfRdg[TIME.STAMP]
                        done:=TRUE


          (Nrdg=TRUE)
            --------------------------------------------------------------
            SEQ
              debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Nrdg=TRUE", Pc)
              Pc[TIME.STAMP]:=clock+delay[9]
              Pc[STALL]:=-1

              mkRS()
              mkI3()
              PAR
                ------------------------------------------------------
                SEQ                            -- ALUgo from decode3
                  IF
                    (Nalw1=FALSE)
                      SEQ
                        debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: waiting for ALUgo", Pc)
                        ALUgo? ALUok   --ALUok[0]=(ALuok, mode[3:0])
                        debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Received ALUgo", Pc)
                        int.to.bool(ALUok[0],ALUokb)
                        Aluok:=ALUokb[0]
                        [modeb FROM 0 FOR 6]:=[ALUokb FROM 1 FOR 6]   --mode[5:4] is not used here.......
                        temp:=max(ALUok[TIME.STAMP], (clock+delay[4]))
                    (Nalw1=TRUE)
                      SEQ
                        temp:=0
                        SKIP
                ------------------------------------------------------------
                SEQ                        --to/from DEC2
                  mkI2()
                  I2d[TIME.STAMP]:=clock+delay[5]
                  I2d[STALL]:=-1
                  --debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: Nrdg=TRUE Waiting to send to Dec2", Pc)

                  ToregBD!I2d
                  FromregBA? Ackb
                  Ackb[TIME.STAMP]:=Ackb[TIME.STAMP]+CALLA

                  --debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: Nrdg=TRUE sent to Dec2", Pc)

                ---------------------------------------------
                SEQ                    --to/from Register Bank
                  Rs[TIME.STAMP]:=clock+delay[6]
                  Rs[STALL]:=-1

                  debugmsg(trace,screen[2], "DEC1-Dec1CtrlB: Nrdg=TRUE Waiting to send to RegBank", Pc)
                  PAR
                    ToRGrs!Rs
                    ToRGpc!Pc
                  FromRGA? Ackr
                  Ackr[TIME.STAMP]:=Ackr[TIME.STAMP]+CALLA

                  debugmsg(trace,screen[2], "DEC1-Dec1CtrlB: Nrdg=TRUE sent to RegBank", Pc)

                ---------------------------------------------
                SEQ                         --to/from DEC3

                  IF
                    (toI3=TRUE)
                      SEQ
                        I3d[TIME.STAMP]:=clock+delay[7]
                        I3d[STALL]:=-1

                        debugmsg(trace,screen[3], "DEC1-Dec1CtrlB: Nrdg=TRUE Waiting to send to Dec3", I3d)
                        ToregCD!I3d
                        FromregCA? Ackc
                        debugmsg(trace,screen[3], "DEC1-Dec1CtrlB: Nrdg=TRUE sent to Dec3", Pc)
                    (toI3=FALSE)
                      SEQ
                        Ackc[TIME.STAMP]:=clock+delay[7]
                        debugmsg(trace,screen[3], "DEC1-Dec1CtrlB: Nrdg=TRUE do not send to Dec3", Pc)
                        SKIP
                ---------------------------------------------
                SEQ                    --to/from IMM pipe

                  IF
                    (NImm=FALSE)
                      SEQ
                        I[TIME.STAMP]:=clock+delay[8]
                        I[STALL]:=-1

                        --debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Nrdg=TRUE Waiting to send to  IMMPipe", Pc)
                        ToImmd!I   -- I was sent by DatInt (Ipipe)
                        FromImmA? Ackim
                        --debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Nrdg=TRUE sent IMMPipe", Pc)
                    (NImm=TRUE)
                      SEQ
                        Ackim[TIME.STAMP]:=clock+delay[8]
                        SKIP
                ---------------------------------------------
                SEQ                 --to/from X pipe
                  --Ntox0:=FALSE
                  IF
                    (Ntox0=FALSE)
                      SEQ

                        debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: Waiting to send to XPipe PC", Pc)
                        ToXp!Pc
                        FromXpA? Ackxp
                        debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: sent to XPipe", Pc)
                    (Ntox0=TRUE)
                      SEQ
                        Ackxp[TIME.STAMP]:=clock+delay[9]
                        debugmsg(trace,screen[1], "DEC1-Dec1CtrlB:Ntox0 is TRUE-dont send to Xpipe ", Pc)
                        SKIP
                ---------------------------------------------
                SEQ

                  IF
                    (ToN=TRUE)
                      SEQ
                        mkNG()
                        Ng[TIME.STAMP]:=clock+delay[10]
                        Ng[STALL]:=-1

                        --debugmsg(trace,screen[2], "DEC1-Dec1CtrlB: Waiting to send to NGen", Pc)
                        ToNGD!Ng
                        FromNGA? Ackgn
                        --debugmsg(trace,screen[2], "DEC1-Dec1CtrlB: sent to  NGen", Pc)

                    (ToN=FALSE)
                      SEQ
                        Ackgn[TIME.STAMP]:=clock+delay[10]
                        SKIP

                ---------------------------------------------
              max.proc(temp,Ackb[TIME.STAMP], temp1)
              max.proc(temp1, Ackr[TIME.STAMP],temp2)
              max.proc(temp2,(Ackc[TIME.STAMP] + XOR),temp3)
              max.proc(temp3,(Ackim[TIME.STAMP] + XOR),temp4)
              max.proc(temp4,(Ackxp[TIME.STAMP] + XOR),temp5)
              max.proc((Ackgn[TIME.STAMP] + XOR),temp5,clock)

        mkseqin()
        SeqCpla(seqin, seqout)
        int.to.bool(seqout, seqoutb)
        multi:=seqoutb[0]
        clock:=clock+delay[11]
        IF
          (multi=FALSE)
            SEQ
              Ack[TIME.STAMP]:=clock+delay[12]

              debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: multi=FALSE waiting for new Instr, Ctrl, PC",NULL1)
              Ia3!Ack
              SEQ
                In? I     -- from CtrlA read I, ctrl(vect...), PC
                IF
                  I[0]<>FINISH
                    SEQ
                      PAR
                        CtrlAB? Ctrl
                        PCAB?  Pc
                      -----------------------------------
                      WHILE (I[0]=NULL.MESSAGE)  --just propagate NULL messages
                        SEQ
                          debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Received NULL MESSAGE, Ctrl-Instr is ", I)

                          PAR
                            Ia3!Ack
                            SEQ
                              ToregBD!I
                              FromregBA? Ackb
                          PAR
                            In? I
                            CtrlAB? Ctrl
                            PCAB?  Pc
                      debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: Reecived new Instr, Ctrl-Instr is ", I)
                      int.to.bool(I[0], Ib)
                      int.to.bool(Ctrl[0], Ctrlb)
                      debugmsg(trace,screen[1], "DEC1-Dec1CtrlB: Reecived new PC ", Pc)
                      clock:=I[TIME.STAMP]


                  I[0]=FINISH
                    -------------------------
                    SEQ
                      end:=TRUE




          (multi=TRUE)
            SEQ
              debugmsg(trace,screen[0], "DEC1-Dec1CtrlB: multi = TRUE",NULL1)
              SKIP
        -----------------------------------------------

        mkIn()
        RegCpla(RegIn,Regcout1,Regcout2)                 --call PLA
        int.to.bool(Regcout1, Regcout1b)
        int.to.bool(Regcout2, Regcout2b)
        [Regcoutb FROM 0 FOR ((SIZE (RegCout[0]))/2)]:=[Regcout2b FROM 0 FOR ((SIZE (RegCout[0]))/2)]
        [Regcoutb FROM ((SIZE (RegCout[0]))/2) FOR ((SIZE (RegCout[0]))/2)]:=
        [Regcout1b FROM 0 FOR ((SIZE (RegCout[0]))/2)]

        [sq1b FROM 0 FOR 3]:=[Regcoutb FROM 14 FOR 3]
        Nrdg:=  Regcoutb[NRDG]
        toI3:=  Regcoutb[TOI3]
        NImm:=  Regcoutb[NIMM]
        Ntox0:= Regcoutb[NTOX]
        ToN:=   Regcoutb[TON]
        Nalw1:= Regcoutb[NALW1]
        get.bit(20,I[0],I20)
        -----------------------------------------------

    -------------------------------------------------------------
    terminate(evaluate, I[TIME.STAMP],KILL, NO.FLUSH, null.occ.table, screen[0], [ToregAD,ToRGrs,ToregBD,ToregCD,ToImmd,ToXp,ToNGD,RdGenr])
    finish:=FALSE
    WHILE (finish=FALSE)
      SEQ
        ALUgo? ALUok      --SINK possible ALUgos arriving from Ctrl3
        IF
          ALUok[0]=FINISH
            SEQ
              finish:=TRUE
          TRUE
            SEQ
              SKIP

:
