1 * ************************************************************
   2 * *                                                          *
   3 * * Copyright, (C) BULL HN Information Systems Inc., 1989    *
   4 * *                                                          *
   5 * * Copyright, (C) Honeywell Information Systems Inc., 1982  *
   6 * *                                                          *
   7 * * Copyright, (C) Honeywell Information Systems Inc., 1980. *
   8 * *                                                          *
   9 * ************************************************************
  10           lbl       ,x25_tables
  11           ttl       x25_tables
  12           editp     on
  13           pmc       off
  14           detail    off
  15           pcc       off
  16 ****************************************************************
  17 *
  18 *         x25_tables (orginal called x25lap_tables)
  19 *
  20 *         This module is designed to use the HDLC subchannel of
  21 *         the high-speed line adaptor to implement the Link
  22 *         Access Procedure (LAP) of CCITT recommendation X.25.  This
  23 *         module supports both asynchronous response mode and
  24 *         asynchronous balance mode (LAPB).
  25 *
  26 *         Coded August, 1979 by J. Stern
  27 *         Fixed for TELENET May 1980 by C. Hornig
  28 *         RNR problem fixed October 1980 by C. Hornig
  29 *         Modified for parameterization December 1980 by R. Harvey
  30 *         Rewritten by D. W. Cousins June 1981
  31 *         Fixed bugs to pass TELNET certication and
  32 *          improve maintinance for future improvements.
  33 *         Rewritten by D. W. Cousins April, 1982 for LAPB
  34 *         Modified by D. W. Cousins  July,1982 for eom sentinal
  35 *         Modified by D. W. Cousins Janurary, 1983 for stpchn problem on exhaust
  36 *         Modified by D. W. Cousins Janurary, 1983 for bugs fixes
  37 *         Modified by D. W. Cousins June 8, 1983 for output blockage during
  38 *           link recovery from timer expired with transmitter busy
  39 *         Modified by D. W. Cousins Sept 9, 1983 for LAPB reset I-frame hold
  40 *         Modified by D. W. Cousins April 1984 for speed ups in the output
  41 *           section to used a nrn instruction inplace of tstlcf code and
  42 *           set up a CMDR/FRMR check for I-frames with more data then remote
  43 *           can accept to cause the link to disconnect.
  44 *         Modified by D. W. Cousins Oct 12 1984 to have the control of crash
  45 *           to deactivate the line in such a matter to only have an activate
  46 *           control order to turn it back on.
  47 *         Modified by D. W. Cousins Oct 18, 1985 to correct a problem of RNR,
  48 *            RR being recieve during I-frame output in which a.r is reset
  49 *            such that no messages are acknowledged that should be.
  50 *         Modified by D. W. Cousins Nov 22 1985 to abort the hangup timer in
  51 *            control_tables so that the activation order is not lost.
  52 *
  53 *
  54 ****************************************************************
  55 
  56 * HISTORY COMMENTS:
  57 *  1) change(86-02-03,Kissel), approve(86-02-03,MCR7297),
  58 *     audit(86-02-03,Coren), install(86-04-10,MR12.0-1038):
  59 *     Correct a problem of RNR or RR being received during I-frame output in
  60 *     which a.r is reset such that no messages are acknowledged when they
  61 *     should be.
  62 *  2) change(86-02-03,Kissel), approve(86-02-03,MCR7324),
  63 *     audit(86-02-03,Coren), install(86-04-10,MR12.0-1038):
  64 *     Modified to abort the hangup timer in the control_tables so that an
  65 *     activation order is not lost.
  66 *  3) change(86-12-19,Cousins), approve(87-01-26,MCR7605),
  67 *     audit(87-06-11,Brunelle), install(87-07-15,MR12.1-1041):
  68 *     Close a hole in detecting invalid frames.  Bug caused connection to go
  69 *     into LINK-up state when it should not.  This would not happen with
  70 *     certified connections, expected only during certification tests.
  71 *  4) change(87-02-04,Beattie), approve(87-04-06,MCR7657),
  72 *     audit(87-06-11,Brunelle), install(87-07-15,MR12.1-1041):
  73 *     The FNP erroneously sends out 2 DISC (disconnect) commands when a DM
  74 *     (disconnected mode) response is received when the link is down.  This
  75 *     can cause loss of synchronization with the other end.  There is also a
  76 *     bug in handling of DMs when the connection is in the link up state.
  77 *  5) change(89-04-30,Beattie), approve(89-05-15,MCR8108),
  78 *     audit(89-06-15,Brunelle):
  79 *     Input exhaust status processing incorrectly reestablishing T1 timer to
  80 *     1 second rather than current value for T1.  Can cause extra data to be
  81 *     sent to remote terminal.
  82 *                                                      END HISTORY COMMENTS
  83 
  84           rem
  85 x25tbs    null
  86           rem
  87           symdef    x25str
  88           rem
  89           symref    begin
  90           symref    hungup
  91           symref    adbyte
  92           symref    cvaddr
  93           symref    setbpt    /*18 to 15 bit for i/o buffers */
  94           rem
  95           pmc       save,on
  96           tib
  97           sfcm      hsla
  98           csbits
  99           buffer
 100           comreg
 101           tconst
 102           meters
 103           pmc       restore
 104           rem
 105           start     x25tbs,,c3x25m0c0000
 106           ttls      X25 LAP tib extension variables
 107           tibex     locadr,char         /* local station address */
 108           tibex     remadr,char         /* remote station address */
 109           tibex     frmadr,char         /* address from current input frame */
 110           tibex     pmask,char          /* P bit mask for command output */
 111           tibex     fmask,char          /* F bit mask for response output */
 112           tibex     cfield,char         /* output frame control field */
 113           tibex     cmdrb1,char         /* CMDR/FRMR info field, byte 1 */
 114           tibex     cmdrb2,char         /* CMDR/FRMR info field, byte 2 */
 115           tibex     cmdrb3,char         /* CMDR/FRMR info field, byte 3 */
 116           rem
 117           tibex     lkupws,word         /* which table during link up */
 118           tibex     lastf,word          /* last function recieve */
 119           tibex     stat0,word          /* line status/line control words */
 120           tibex     stat1,word
 121           tibex     stat2,word
 122           tibex     stat3,word
 123           tibex     rc,word   /* retry counter */
 124           tibex     v.s,word  /* next N(S) to send */
 125           tibex     v.r,word  /* next N(S) to receive */
 126           tibex     a.s,word  /* last N(R) sent */
 127           tibex     a.r,word  /* last N(R) received */
 128           tibex     xx,word   /* saved value of v.s during timer recovery */
 129           tibex     t1,word   /* response time-out interval (from host) */
 130           tibex     t3,word   /* time-out interval (from host) */
 131           tibex     n2,word   /* max number of retries (from host) */
 132           tibex     kc,word   /* number of frame before stopping HOST */
 133           tibex     kv,word   /* number of frame on the chain now */
 134           tibex     state,word          /* primary state */
 135           tibex     pstate,word         /* primanry up state */
 136           tibex     sstate,word         /* secondary up state */
 137           tibex     mxfrsz,word         /* max frame size (input) */
 138           tibex     uaoffs,word         /* buffer offset (offset to buffer) */
 139           tibex     bufadd,word         /* buffer pool address */
 140           tibex     upobuf,word         /* unprocess buffer address */
 141           tibex     nrv,word  /* n.r if xmit is busy */
 142           tibex     retlbl,word         /* label for stpchn return to */
 143           rem
 144           tibex     flgwd1,word         /* flags word link control */
 145 laparb    bool      000001    /* on if lapb protocall */
 146 dcedte    bool      000002    /* on if dce device */
 147 discft    bool      000004    /* on if send disc first */
 148 trcoff    bool      000010    /* on if trace is to be off on crash */
 149 rprtsw    bool      000020    /* on if report needed to host */
 150 xmitsw    bool      000040    /* on if transmitter busy */
 151 rcvsw     bool      000100    /* on if recieving mode on */
 152 oasw      bool      000200    /* on if output is recieve since last sndout */
 153 t1rec     bool      000400    /* on if timer recovery is in progress */
 154 timesw    bool      001000    /* on if timer is running */
 155 timet3    bool      002000    /* on if t3 timmer is running */
 156 pbit      bool      004000    /* on if poll is required */
 157 fbit      bool      010000    /* on if finial is required */
 158 ifrsnd    bool      020000    /* on if iframe on t.ocp (xmiting) */
 159 psarm     bool      040000    /* on if a prior sarm is recieve */
 160 oprusw    bool      100000    /* on if output recieve on xmit on */
 161 ackrq     bool      200000    /* on if ack is required because of i-frame xmit */
 162 downsw    bool      400000    /* on if link is down */
 163           rem
 164           tibex     flgwd2,word         /* flag word 2 output messages */
 165 sndm      bool      200000    /* on send dm (lapb) */
 166 sndisc    bool      100000    /* on send disc */
 167 snsarm    bool      040000    /* on send sarm (lap) */
 168 snsabm    bool      020000    /* on send sabm (lapb) */
 169 sncmdr    bool      010000    /* on send cmdr (lap) */
 170 snfrmr    bool      010000    /* on send frmr (lapb) */
 171 snua      bool      004000    /* on send ua */
 172 snrnr     bool      002000    /* on send response rnr */
 173 snrej     bool      001000    /* on send response rej */
 174 snifr     bool      000400    /* on send i-frame */
 175 snrr      bool      000200    /* on send response rr */
 176 snprnr    bool      000100    /* on send command rnr (lapb) */
 177 snprej    bool      000040    /* on send command rej (lapb) */
 178 snprr     bool      000020    /* on send command rr (lapb) */
 179 *unused             400017    /* note 0-bit must be zero for nrn to work */
 180           rem
 181           tibex     flgwd3,word         /* flag word 3 misc flags */
 182 rtyhld    bool      000001    /* on = no I-frame to be send t1rec */
 183 hldvar    bool      000002    /* on = next ua response to DISC not ss move */
 184 mstclr    bool      000004    /* on = must clear buffers */
 185 mstifr    bool      000010    /* on = sent one I-frame (timer recovery)*/
 186 *unused             777760
 187           ttls      X25 LAP constant symbols
 188 *
 189 *         miscellaneous chars
 190 *
 191 dceadr    bool      001       /* DCE address */
 192 dteadr    bool      003       /* DTE address */
 193 rr        bool      001       /* RR frame type */
 194 rnr       bool      005       /* RNR frame tpye */
 195 rej       bool      011       /* REJ frame type */
 196 sarm      bool      017       /* SARM frame type */
 197 sabm      bool      057       /* SABM frame type */
 198 disc      bool      103       /* DISC frame type */
 199 dm        bool      017       /* DM frame type */
 200 ua        bool      143       /* UA frame type */
 201 cmdr      bool      207       /* CMDR frame type */
 202 frmr      bool      207       /* FRMR frame type */
 203 pfon      bool      020       /* P/F bit mask */
 204 eof       bool      400       /* end of frame bit */
 205 *
 206 *         link state constants
 207 *
 208 lkdnst    equ       1         /*link down state */
 209 lkt3st    equ       2         /* t3 state */
 210 lkssst    equ       3         /* sabm send state (lapb) */
 211 lksust    equ       4         /* link setup state */
 212 lkisup    equ       5         /* link up state */
 213 lkprnr    equ       5         /* prinary normal state */
 214 lkprrb    equ       6         /* primary remote busy state */
 215 lkprt1    equ       7         /* primary t1 expire state */
 216 lkprsr    equ       8         /* primary sarm reset state */
 217 lkscnm    equ       9         /* secondary normal state */
 218 lksclb    equ       10        /* secondary local busy state */
 219 lkscrj    equ       11        /* secondary reject state */
 220 lksccs    equ       12        /* secondary cmdr send state */
 221 lkupfr    equ       13        /* link up frmr send (lapb) */
 222 lkuprs    equ       14        /* link up reset started (lapb) */
 223 *
 224 *         miscellaneous integers
 225 *
 226 dialim    equ       8         /* max queued frames to DIA */
 227 *
 228 *         line control types
 229 *
 230 lctact    equ       1         /* activate link */
 231 lctdea    equ       2         /* deactivate link */
 232 lctdis    equ       3         /* disconnect link */
 233 *
 234 *         format of activate order (stat0)
 235 *
 236 dceflg    bool      400000    /* we are a dce */
 237 abmflg    bool      200000    /* default to lapb */
 238 disftf    bool      100000    /* disc first flags */
 239 *unused   077000
 240 ordmsk    bool      000777    /* control order type */
 241 *
 242 *         line status types
 243 *
 244 lstdwn    equ       1         /* link is down */
 245 lstup     equ       2         /* link is up */
 246 lstcmr    equ       3         /* CMDR of I-frame Y set*/
 247 *
 248 *         bldmsg control strings
 249 *
 250 srmmsg    chstr     (remadr,sarm,seteom)
 251 dmmsg     chstr     (locadr,dm,seteom)
 252 sbmmsg    chstr     (remadr,sabm,seteom)
 253 dscmsg    chstr     (remadr,disc,seteom)
 254 uamsg     chstr     (locadr,ua,seteom)
 255 cmdmsg    chstr     (remadr,cfield,seteom)
 256 rspmsg    chstr     (locadr,cfield,seteom)
 257 frmrms    null
 258 cmdrms    chstr     (locadr,cmdr,cmdrb1,cmdrb2,cmdrb3,seteom)
 259 *
 260 *         outscn control strings
 261 *
 262 setp      chstr     (rescan,ignore,setbit,pmask)
 263 setf      chstr     (rescan,ignore,setbit,fmask)
 264 setac     chstr     (rescan,replac,remadr,ignore,replac,cfield,setbit,pmask,e
 265           etc       ndchn,offbit,eof)
 266 *
 267 *         gocase control labels, compare strings, and tables constants
 268 *
 269 *         tables constants
 270 *
 271 rvbdad    equ       0         /* bad address or other type of trash */
 272 rvdisc    equ       1         /* receive disc */
 273 rvdm      equ       2         /* receive dm (lapb) */
 274 rvsarm    equ       3         /* receive sarm (lap) */
 275 rvsabm    equ       4         /* recieve sabm (lapb) */
 276 rvua      equ       5         /* recieve ua */
 277 rvcmdr    equ       6         /* recieve cmdr (lap) or frmr (lapb) */
 278 rvrr      equ       7         /* recieve response rr */
 279 rvrnr     equ       8         /* recieve response rnr */
 280 rvrej     equ       9         /* recieve response rej */
 281 rvbdcr    equ       10        /* recieve a bad command or response */
 282 rvt12l    equ       11        /* t1 expired rc less then n2 */
 283 rvt12e    equ       12        /* t1 expired rc equal to n2 */
 284 rvbdfb    equ       13        /* recieve bad f-bit */
 285 rvbdir    equ       14        /* recieve i-frame bad n(r) */
 286 rvbdis    equ       15        /* recieve i-frame bad n(s) */
 287 rvifrm    equ       16        /* recieve i-frame */
 288 rvprr     equ       17        /* recieve command poll rr (lapb) */
 289 rvprnr    equ       18        /* recieve command poll rnr (lapb) */
 290 rvprej    equ       19        /* recieve command poll rej (lapb) */
 291 *
 292 *         down state table control array
 293 *
 294 downst    chstr     (rvdisc,rvdm,rvua,rvt12l,rvt12e)
 295 *
 296 *         t3 state table (mostly send disc go to down state used by
 297 *            DCE portion only)
 298 *
 299 t3stat    chstr     (rvdisc,rvdm,rvsarm,rvsabm,rvcmdr,rvrr,rvrnr,rvrej,rvbdcr
 300           etc       ,rvt12l,rvt12e,rvbdfb,rvbdir,rvbdis,rvifrm,rvprr,rvprnr,r
 301           etc       vprej)
 302 *
 303 *          sabm send state  used by LAPB only
 304 *
 305 ssstat    chstr     (rvdisc,rvdm,rvsabm,rvua,rvcmdr,rvt12l,rvt12e)
 306 *
 307 *         set up state  used by LAP only
 308 *
 309 sustat    chstr     (rvdisc,rvsarm,rvua,rvt12l,rvt12e)
 310 *
 311 *         link up state primary side sub tables
 312 *           prinr - primary normal state
 313 *           prirb - primary remote busy state
 314 *           prit1 - primary timer reset state
 315 *
 316 prinr     null
 317 prirb     null
 318 prit1     chstr     (rvdisc,rvdm,rvsarm,rvsabm,rvua,rvcmdr,rvrr,rvrnr,rvrej,r
 319           etc       vbdcr,rvt12l,rvt12e,rvbdfb,rvbdir,rvbdis,rvifrm)
 320 *
 321 *         link up primary substate sarm send state LAP only
 322 *
 323 prisr     chstr     (rvua,rvt12l,rvt12e)
 324 *
 325 *         link up secondary substate
 326 *           secnm - secondary normal
 327 *           seclb - secondary local busy
 328 *           secrj - secondary reject
 329 *           seccs - secondary command send LAP only
 330 *
 331 secnm     null
 332 seclb     null
 333 secrj     null
 334 seccs     chstr     (rvdisc,rvsarm,rvsabm,rvua,rvcmdr,rvrr,rvrnr,rvrej,rvbdcr
 335           etc       ,rvbdir,rvbdis,rvifrm,rvprr,rvprnr,rvprej)
 336 *
 337 *         link up frame reject state LAPB only
 338 *
 339 prifr     chstr     (rvdisc,rvdm,rvsarm,rvsabm,rvua,rvcmdr,rvrr,rvrnr,rvrej,r
 340           etc       vbdcr,rvt12l,rvt12e,rvbdfb,rvbdir,rvbdis,rvifrm,rvprr,rvp
 341           etc       rnr,rvprej)
 342 *
 343 *         link up reset send state LAPB only
 344 *
 345 prisrt    chstr     (rvdisc,rvdm,rvsabm,rvua,rvcmdr,rvt12l,rvt12e)
 346 *
 347 *         which state tables gocase is going to used?
 348 *           (used in linkup state only)
 349 *
 350 whstgc    chstr     (lkprnr,lkprrb,lkprt1,lkprsr,lkscnm,lksclb,lkscrj,lksccs,
 351           etc       lkupfr,lkuprs)
 352 *
 353 *         gocase label tables
 354 *
 355 *         down state transferred vectors
 356 *
 357 dslabl    adrlst    (dssnua,dmstt3,srtt3,disct1,dst1e)
 358 *
 359 *         t3 state transferred vectors
 360 *
 361 t3labl    adrlst    (sndua,dsdisc,susua,lpbiup,dsdisc,dsdisc,dsdisc,dsdisc,ds
 362           etc       disc,t3t1ln,dsdscp,dsdisc,dsdisc,dsdisc,dsdisc,dsdisc,dsd
 363           etc       isc,dsdisc)
 364 *
 365 *         ss LAPB state transferred vectors for sabm sent state
 366 *
 367 sslabl    adrlst    (sndua,ckdisc,sndua,lpbiup,sndsbm,t1sabm,ckdscp)
 368 *
 369 *         set up state transferred vectors (lap)
 370 *
 371 sulabl    adrlst    (dsdsua,sndua1,ckupst,sndsmp,dsdscp)
 372 *
 373 *         primary normal state
 374 *         primary remote busy
 375 *         primary t1 time out
 376 *           transferred vectors
 377 *
 378 pnrlbl    null
 379 prblbl    null
 380 pt1lbl    adrlst    (frsrrq,dsdisc,frsrrq,frsrrq,uaigfr,sborsm,nrrr,rbrnr,nrr
 381           etc       ej,frsrrq,t1stch,n2rssr,frsrrq,frsrrq,frsrrq,frsrrq)
 382 *
 383 *         primary sarm rest state transferred vectors
 384 *
 385 psrlbl    adrlst    (backnr,tisarm,tidisc)
 386 *
 387 *         secondary normal state transferred vectors
 388 *
 389 snmlbl    adrlst    (dsduab,nmdua,nmduab,frcmdr,frcmdr,frcmdr,frcmdr,frcmdr,f
 390           etc       rcmdr,frsrrq,rjrej,nmif,finrr,finrr,finrr)
 391 *
 392 *         secondary local busy state transferred vectors
 393 *
 394 slblbl    adrlst    (dsduab,nmsdua,nmduab,frcmdr,frcmdr,frcmdr,frcmdr,frcmdr,
 395           etc       frcmdr,frsrrq,sndrnr,sndrnr,finrnr,finrnr,finrnr)
 396 *
 397 *         secondary reject state transferred vectors
 398 *
 399 srjlbl    adrlst    (dsduab,nmsdua,nmduab,frcmdr,frcmdr,frcmdr,frcmdr,frcmdr,
 400           etc       frcmdr,frsrrq,rej1,pnmif,finrej,finrej,finrej)
 401 *
 402 *         secondary command reject state transferred vectors
 403 *
 404 scslbl    adrlst    (dsdsua,nmsdua,sndcmd,sndcmd,sndcmd,sndcmd,sndcmd,sndcmd,
 405           etc       sndcmd,frsrrq,sndcmd,sndcmd,sndcmd,sndcmd,sndcmd)
 406 *
 407 *         lapb frame reject transferred vectors
 408 *
 409 lbfrtv    adrlst    (dsduab,discds,sndfr,lpbpup,sndfr,rssabm,sndfr,sndfr,sndf
 410           etc       r,sndfr,t1nor,rssabm,sndfr,sndfr,sndfr,sndfr,sndfr,sndfr,
 411           etc       sndfr)
 412 *
 413 *         reset sabm send state transferred vectors
 414 *
 415 lbrstv    adrlst    (dsduab,discds,sndua,lpbpup,sndsbm,t1sabm,discds)
 416 *
 417 *         which gocase table search to use transferred vectors
 418 *
 419 whgclb    adrlst    (lkpnr,lkprb,lkpt1,lkpsr,lksnm,lkslb,lksrj,lkscs,lkfrlb,l
 420           etc       krslb)
 421           rem
 422 *
 423 *         meter difinitions
 424 *
 425 frmxmt    equ       1         /* output messages */
 426 frmrcv    equ       0         /* input messages */
 427 rtyxmt    equ       m.cnt1    /* metter xmt retried */
 428 resxmt    equ       m.cnt2    /* meter xmt reset */
 429 rtyrcv    equ       m.cnt3    /* meter frmaes discarded */
 430 resrcv    equ       m.cnt4    /* meter reciever reset */
 431 mfce      equ       m.cnt5    /* meter fcs errors */
 432 mrab      equ       m.cnt6    /* meter read aborts */
 433           rem
 434 ************************************************************
 435 *
 436 *
 437 *         The x25 protocall has states in which only certain
 438 *          function can be preform, If these are violated; the
 439 *          state will send it to another state for that function
 440 *          or if function is satisfied then it will progress it
 441 *          to the proper state in line to link up.
 442 *
 443 *         The first function is the physcal connect. This
 444 *          is not a state for the x25, but a common state to
 445 *          all lines.
 446 *
 447 *         The following is the primary states for normal linkup flow
 448 *
 449 *           LAP                    LAPB
 450 *         down state             down state
 451 *         t3 state               t3 state
 452 *         setup state            sabm send state
 453 *         linkup state           linkup state
 454 *          Note LAPB can go to linkup state in t3 state but
 455 *           LAP cann't
 456 *
 457 *         the following is the linkup substate
 458 *
 459 *           LAP                    LAPB
 460 *         primary normal         primary normal
 461 *         primary remote busy    primary remote busy
 462 *         primary t1             primary t1
 463 *         primary sarm send
 464 *         secondary normal       secondary normal
 465 *         secondary local busy   secondary local busy
 466 *         secondary reject       secondary reject
 467 *         secondary command reject
 468 *                                frame reject
 469 *                                reset sabm send
 470 *
 471 ************************************************************
 472           ttls      physical connection
 473           eject
 474 ************************************************************
 475 *
 476 *         wait for the activation order
 477 *
 478 ************************************************************
 479           rem
 480 x25str    clrflg    tfhang    /* clear last hangup flag just in case */
 481           config              /* set idle link state */
 482           rmode     fg.itf    /* don't transmit flags */
 483           getext    ,gopunt   /* get tib extension */
 484           linctl    stat0,actwt         /* did we get activated? */
 485           goto      actts2    /* yes, process it now */
 486           rem
 487 actwt     wait      0,0,actts /* wait for activation order */
 488           rem
 489 actts     tstflg    tfhang,hangr        /* start over */
 490           linctl    stat0,actwt         /* is it a activation order */
 491 actts2    calasm    dcdact,(actwt)      /* decode it */
 492           rem
 493 lisna     tstflg    tflisn,lisn         /* told to listen? */
 494           wait      0,0,lisnt /* test for it type */
 495           rem
 496 lisnt     tstflg    tfhang,hangr        /* told to hand up */
 497           goto      lisna     /* all other */
 498           rem
 499 lisn      contrl    sdtr+srts+stat      /* full duplex set rts and dtr */
 500           rem
 501           wait      0,0,cklisn          /* wait for changes or status */
 502           status    cts+dsr+cd,0,ckdlup
 503 *         /* must have cts, dsr, and cd before we can talk */
 504           rem
 505 ckdlup    setime    1         /* wait one second for line settling */
 506           wait      ckline,0,ckdlup
 507           rem
 508 ckline    contrl    stat      /*find out if line still up */
 509           rem
 510           wait      0,0,cklisn
 511           status    cts+dsr+cd,0,dialed /* it dial up */
 512           status    0,dsr,hang          /* dead line so drop it */
 513           rem
 514 cklisn    tstflg    tfhang,hang         /* told to drop the line */
 515           tstflg    tflisn,golisn       /* still listening */
 516           goto      hang      /* none so quit */
 517           rem
 518 golisn    waitm
 519           rem
 520           rem
 521 ************************************************************
 522 *
 523 *         the line has dial up now set up some tables
 524 *
 525 ************************************************************
 526           rem
 527 dialed    calasm    cfgpcw    /* set configuration pcw */
 528           contrl    srec      /* enter recieve mode */
 529           setlcf    flgwd1,rcvsw        /* say we are recieving */
 530           rem
 531           config              /* set active link state */
 532           smode     fg.itf
 533           rem
 534           clrlcf    flgwd1,xmitsw       /* clear transmitter */
 535           goto      pcdown    /* start the down state function */
 536           rem
 537 ************************************************************
 538 *
 539 *         handle the deactivation of the line
 540 *
 541 ************************************************************
 542           rem
 543 deact     contrl    rrec      /* exit recieve mode */
 544           config              /* set idle link */
 545           rmode     fg.itf
 546           goto      hang      /* wait for activation order */
 547           ttls      link down state
 548           eject
 549           rem
 550 ************************************************************
 551 *
 552 *         link down has two phases. one is for initialization
 553 *          the other is for the actual down state functions
 554 *
 555 ************************************************************
 556           rem
 557 pcdown    clrlcf    flgwd1,rprtsw       /* no report is needed */
 558           setlcl    flgwd2,0  /* clear all messages */
 559           setlcl    flgwd3,0  /* clear more flags */
 560           clrlcf    flgwd1,xmitsw       /* xmiter not busy */
 561           tstlcf    flgwd1,discft,dwnst /* down state required */
 562           tstlcf    flgwd1,laparb,pssute /* setup for lapb */
 563           goto      psuste    /* lap setup */
 564 dwnst     setlcf    flgwd1,downsw       /* shown link is down */
 565           clrlcf    flgwd1,t1rec        /* no timer recovery */
 566           clrlcf    flgwd1,timet3       /* no t3 timer going */
 567           clrlcf    flgwd1,pbit         /* clear p bit */
 568           clrlcf    flgwd1,fbit         /* clear f bit */
 569           setchr    pmask,null
 570           setchr    fmask,null
 571           calsub    clrabf    /* free any messages buffers */
 572           rem
 573           tstlcf    flgwd1,rprtsw,repdns /* do we report down state */
 574           goto      dwnwt     /* no */
 575           rem
 576 repdns    setlcl    stat0,lstdwn        /* set order to down state */
 577           setlcv    stat1,lastf         /* going tell HOST why we when down */
 578           setlcv    stat2,state
 579           setlcv    stat3,sstate
 580           tstlcf    flgwd1,trcoff,repdn1
 581           goto      repdn2
 582 repdn1    setlcl    .crtsw,1
 583 repdn2    calasm    setust
 584           linsta    stat0
 585           clrlcf    flgwd1,rprtsw       /* clear the report switch */
 586           goto      deact               /* not the correct place, but */
 587           rem                           /* link crash so deactivate it */
 588           rem
 589 dwnwt     setlcl    state,lkdnst        /* show we are down */
 590           setlcl    pstate,0  /* save a mess later */
 591           clrlcf    flgwd1,psarm        /* prior sarm required off */
 592           setlcl    rc,0      /* set retry counter to zero */
 593           setimv    t1        /* set timer */
 594           setlcf    flgwd1,timesw       /* start timer */
 595           setlcf    flgwd2,sndisc       /* set send disc message */
 596           calsub    outlst    /* output it */
 597           rem
 598 dwntwt    setlcl    retlbl,dwntwt       /* return label for stpchn */
 599           wait      timeds,badoa,testst /* main wait for down state */
 600           status    0,dsr,hang          /* line drop hangup */
 601           status    exh,0,exhsta        /* no buffers avaible */
 602           status    fcserr,0,fcesta     /* fcs error */
 603           status    rcvabt,0,rabsta     /* read abort */
 604           status    rcvtrm,0,rddsin     /* read terminate check it out */
 605           status    term,0,outpcw       /* output terminate see if any more */
 606           status    xte,0,xtesta        /* punt transferred timming error */
 607           rem
 608 ************************************************************
 609 *
 610 *         driver for the down state
 611 *
 612 ************************************************************
 613           rem
 614 timeds    calsub    timeo     /* which timer is it (t3, t1 < rc, or t1 = rc */
 615           goto      dstest    /* go to work */
 616           rem
 617 rddsin    meterm    frmrcv    /* meter input */
 618           calasm    valfrm    /* get function form input */
 619           setlcl    rc,0      /* still some life give it a chance */
 620           rem
 621 dstest    gocase    lastf,downst,dslabl /* do the work */
 622           meter2    rtyrcv,1  /* not handle here meter it */
 623           dumpin              /* ignore it */
 624           setchr    fmask,null          /* no finial here */
 625           clrlcf    flgwd1,fbit
 626           waitm               /* go back to where came from */
 627           ttls      t3 state
 628           eject
 629           rem
 630 ************************************************************
 631 *
 632 *         t3 state DCE use only - set t3 and wait for sarm
 633 *          for LAP and UA for LAPB
 634 *
 635 ************************************************************
 636           rem
 637 t3tat     setlcl    retlbl,t3tat        /* return label for stpchn */
 638           wait      tmt3,badoa,testst /* main wait for t3 state */
 639           status    0,dsr,hang          /* dead line - hangup */
 640           status    exh,0,exhsta        /* exhaust */
 641           status    fcserr,0,fcesta     /* fcs error */
 642           status    rcvabt,0,rabsta     /* read abort */
 643           status    rcvtrm,0,rdnt3      /* reader terminate */
 644           status    term,0,outpcw       /* output terminate */
 645           status    xte,0,xtesta        /* punt transferred timing error */
 646           rem
 647 rdnt3     meterm    frmrcv    /* meter this */
 648           calasm    valfrm    /* get function from input */
 649           goto      t3test    /* go do the work */
 650           rem
 651 tmt3      calsub    timeo     /* which time */
 652           tstlcf    flgwd1,timet3,dsdscp /* t3 expired go down */
 653           rem
 654 t3test    gocase    lastf,t3stat,t3labl /* do the work */
 655           meter2    rtyrcv,1  /* not handle here */
 656           dumpin              /* ignore it */
 657           setchr    fmask,null          /* no finial here */
 658           clrlcf    flgwd1,fbit
 659           waitm               /* go back were we came from */
 660           ttls      ss state (lapb only)
 661           eject
 662           rem
 663 ************************************************************
 664 *
 665 *         ss state a LAPB state for link initialization.
 666 *           It is waiting for a UA response to the previous
 667 *          SABM command
 668 *
 669 ************************************************************
 670           rem
 671 pssute    clrlcf    flgwd3,hldvar
 672           setlcf    flgwd2,snsabm       /* sabm is to be sent */
 673           calsub    outlst
 674           setlcf    flgwd1,timesw
 675           setimv    t1
 676           setlcl    rc,0
 677 sspbst    setlcl    retlbl,sspbst       /* return label for stpchn */
 678           wait      tmss,badoa,testst /* main wait for ss state */
 679           status    0,dsr,hang          /* line drop */
 680           status    exh,0,exhsta        /* exhaust conditions */
 681           status    fcserr,0,fcesta     /* fcs error */
 682           status    rcvabt,0,rabsta     /* read abort */
 683           status    rcvtrm,0,rdnss      /* read terminate */
 684           status    term,0,outpcw       /* output terminate */
 685           status    xte,0,xtesta        /* punt transferred timing error */
 686           rem
 687 tmss      calsub    timeo     /* which timer */
 688           goto      sstest    /* process it */
 689           rem
 690 rdnss     meterm    frmrcv    /* meter the input */
 691           calasm    valfrm    /* what function to preform */
 692           rem
 693 sstest    gocase    lastf,ssstat,sslabl /* driver to process ss state */
 694           dumpin              /* not process here dump it */
 695           meter2    rtyrcv,1  /* meter it */
 696           setchr    fmask,null          /* no finial here */
 697           clrlcf    flgwd1,fbit
 698           waitm               /* go back to wait */
 699           rem
 700           ttls      set up state
 701           eject
 702           rem
 703 ************************************************************
 704 *
 705 *         setup state a short distant to link up, only
 706 *          need a UA to complete it (lap)
 707 *
 708 ************************************************************
 709           rem
 710 psuste    setlcf    flgwd2,snsarm       /* send a sarm now */
 711           calsub    outlst
 712           setlcf    flgwd1,timesw
 713           setimv    t1
 714           setlcl    rc,0
 715 sustte    setlcl    retlbl,sustte       /* return label for stpchn */
 716           wait      timesu,badoa,testst /* main wait */
 717           status    0,dsr,hang          /* drop line hangup */
 718           status    exh,0,exhsta        /* exhaust condition */
 719           status    fcserr,0,fcesta     /* fcs error */
 720           status    rcvabt,0,rabsta     /* read abort */
 721           status    rcvtrm,0,rdnsu      /* read terminate */
 722           status    term,0,outpcw       /* output terminate */
 723           status    xte,0,xtesta        /* punt transferred timing error */
 724           rem
 725 rdnsu     meterm    frmrcv    /* meter input */
 726           calasm    valfrm    /* process ctr field */
 727           goto      sutest
 728           rem
 729 timesu    calsub    timeo     /* which time is it */
 730 sutest    gocase    lastf,sustat,sulabl /* process the frame */
 731           dumpin              /* not process here */
 732           meter2    rtyrcv,1  /* meter it */
 733           setchr    fmask,null          /* no finial here */
 734           clrlcf    flgwd1,fbit
 735           waitm               /* return back to last wait */
 736           ttls      link up state (information transfer state)
 737           eject
 738           rem
 739 ************************************************************
 740 *
 741 *         Link up stae this contains two side of the protocol
 742 *          the primary and the secondary. To insure the proper
 743 *          rountines to call a double gocase is perform. The
 744 *          first is to get the right tables, the second is to call the
 745 *          right function.
 746 *
 747 ************************************************************
 748           rem
 749 linkup    setlcl    retlbl,linkup       /* return lable for stpchn */
 750           wait      timelk,writeo,testst /* main linkup wait */
 751           status    0,dsr,hang          /* line drop hangup */
 752           status    exh,0,exhsta        /* exhaust condition */
 753           status    fcserr,0,fcesta     /* fcs error */
 754           status    rcvabt,0,rabsta     /* read abort */
 755           status    rcvtrm,0,rdnlk      /* read terminate */
 756           status    term,0,outpcw       /* output terminate */
 757           status    xte,0,xtesta        /* punt transferred timing error */
 758           rem
 759 timelk    calsub    timeo     /* which time is it */
 760           goto      tmlk
 761           rem
 762 rdnlk     meterm    frmrcv    /* meter input */
 763           calasm    valfrm    /* find which function is it */
 764           cmpchr    frmadr,locadr,secmpr /* secondary side */
 765           setlcv    lkupws,pstate       /* no primary side */
 766           goto      tmlk
 767           rem
 768 secmpr    setlcv    lkupws,sstate /* set to secondary tables */
 769           rem
 770 tmlk      gocase    lkupws,whstgc,whgclb /* which table to use */
 771           dumpin              /* bad input */
 772           meter2    rtyrcv,1
 773           waitm
 774           rem
 775 lkpnr     gocase    lastf,prinr,pnrlbl /* primary mornal */
 776           goto      lkpret    /* not handle function */
 777           rem
 778 lkprb     gocase    lastf,prirb,prblbl /* primary remote busy */
 779           goto      lkpret    /* not handle function */
 780           rem
 781 lkpt1     gocase    lastf,prit1,pt1lbl /* primary t1 expired */
 782           goto      lkpret    /* not handle functions */
 783           rem
 784 lkpsr     gocase    lastf,prisr,psrlbl /* primary sarm sent (lap)*/
 785           goto      lkpret    /* not handle functions */
 786           rem
 787 lksnm     gocase    lastf,secnm,snmlbl /* secondary normal */
 788           goto      lkpret    /* not handle functions */
 789           rem
 790 lkslb     gocase    lastf,seclb,slblbl /* secondary local busy */
 791           goto      lkpret    /* not handle functions */
 792           rem
 793 lksrj     gocase    lastf,secrj,srjlbl /* secondary reject */
 794           goto      lkpret    /* functions not handle */
 795           rem
 796 lkscs     gocase    lastf,seccs,scslbl /* secondary command sent */
 797           goto      lkpret    /* functions not handle */
 798           rem
 799 lkfrlb    gocase    lastf,prifr,lbfrtv /* frame reject (lapb) */
 800           goto      lkpret    /* function not handle */
 801           rem
 802 lkrslb    gocase    lastf,prisrt,lbrstv /* reset sabm (lapb) */
 803           rem
 804           setchr    fmask,null
 805           clrlcf    flgwd1,fbit
 806 lkpret    dumpin              /* ignore function */
 807           meter2    rtyrcv,1  /* meter anyway */
 808           waitm
 809           ttls driver call functional code for X.25 protocol
 810           eject
 811           rem
 812 ************************************************************
 813 *
 814 *         dssnua - down state, receive disc send ua
 815 *           if lap dce send ua plus a disc
 816 *           if lap dte just a ua
 817 *           if lapb dce just a ua
 818 *           if lapb dte send ua plus a disc
 819 *
 820 ************************************************************
 821           rem
 822 dssnua    setlcf    flgwd2,snua         /* set send ua flag */
 823           calsub    outlst    /* output it */
 824           dumpin              /* dump any input */
 825           setimv    t1        /* set timer */
 826           setlcf    flgwd1,timesw       /* set indicator timer is running */
 827           tstlcf    flgwd1,laparb,lpbtst /* test for lapb */
 828           rem
 829           tstlcf    flgwd1,dcedte,stdisc /* test for dce */
 830           rem
 831 dsrtsn    waitm               /* nothing more to do */
 832           rem
 833 lpbtst    tstlcf    flgwd1,dcedte,dsrtsn /* test for dce */
 834 stdisc    setlcf    flgwd2,sndisc       /* set flag it will be sent later */
 835           waitm               /* that is all */
 836           rem
 837           rem
 838 ************************************************************
 839 *
 840 *         dmstt3 - dm recieve while in down state
 841 *         send mode setting response (sabm) in lapb only
 842 *         if lap - ingore it as an error
 843 *
 844 ************************************************************
 845           rem
 846 dmstt3    tstlcf    flgwd1,laparb,dmst3n /* is it lapb */
 847           goto      lkpret    /* no error ingore it */
 848 dmst3n    setlcf    flgwd2,snsabm       /* send a sabm */
 849           clrlcf    flgwd3,hldvar       /* no ua to hold */
 850           goto      srtt3
 851           rem
 852           rem
 853 ************************************************************
 854 *
 855 *         srtt3 - start t3 timer
 856 *         if dte then do;
 857 *           if lap go to su state, send a sarm, and wait for a ua
 858 *           if lapb go to ss state, send a sabm, and wait for a ua
 859 *         end
 860 *         else do;
 861 *           go to t3 state
 862 *           set t3 timer
 863 *           wait for approxiate command
 864 *         end;
 865 *
 866 ************************************************************
 867           rem
 868 srtt3     tstlcf    flgwd3,hldvar,srt3i /* do we readly want to go to t3  state */
 869           setime    0         /* reset timer */
 870           setlcl    rc,0      /* reset rc counter */
 871           clrlcf    flgwd1,timesw       /* reset timer running flag */
 872           calsub    fbitck    /* check final bit */
 873           dumpin              /* dump any input */
 874           tstlcf    flgwd1,dcedte,t3sts /* test for dce */
 875           rem
 876           setimv    t1        /* set timer to t1 */
 877           clrlcf    flgwd1,timet3       /* reset t3 flag */
 878           setlcf    flgwd1,timesw       /* set t1 flag */
 879           tstlcf    flgwd1,laparb,t3sbm /* dce send sabm */
 880           setlcf    flgwd2,snsarm       /* set send sarm for lap */
 881           calsub    outlst    /* output it */
 882           setlcl    state,lksust
 883           goto      sustte    /* go to set up state */
 884           rem
 885 t3sbm     setlcf    flgwd2,snsabm       /* set send sabm flag for lapb */
 886           calsub    outlst    /* output it */
 887           setlcl    state,lkssst
 888           goto      sspbst    /* go to send sabm state */
 889           rem
 890 t3sts     setimv    t3        /* set timer to t3 */
 891           setlcf    flgwd1,timesw       /* set timer running flag */
 892           setlcf    flgwd1,timet3       /* set t3 flag */
 893           setlcl    state,lkt3st
 894           calsub    outlst    /*just in case (dm sabm request) */
 895           goto      t3tat     /* go to t3 state */
 896           rem
 897 srt3i     clrlcf    flgwd3,hldvar       /*no holding now */
 898           calsub    fbitck
 899           dumpin
 900           waitm
 901           rem
 902           rem
 903 ************************************************************
 904 *
 905 *         disct1 - t1 expired send disc - polled
 906 *
 907 *         dst1ep - same as above but doesn't increase rc
 908 *
 909 ************************************************************
 910           rem
 911 disct1    addlcl    rc,1      /* add one to retry counter */
 912 dst1ep    setchr    pmask,pfon          /* set poll bit */
 913           setlcf    flgwd2,sndisc       /* send a disc */
 914           calsub    outlst    /* output it */
 915           setlcf    flgwd1,timesw       /* set timer running flag */
 916           setimv    t1        /* set timer */
 917           waitm
 918           rem
 919           rem
 920 ************************************************************
 921 *
 922 *         dst1e - t1 expired with rc = n2
 923 *           if dte lapb reset timer and ignore
 924 *           It should be HANGUP for DTE on both lap & lapb
 925 *
 926 ************************************************************
 927           rem
 928 dst1e     tstlcf    flgwd1,laparb,dst1e2 /* if lapb */
 929           goto      dst1ep
 930           rem
 931 dst1e2    tstlcf    flgwd1,dcedte,dst1ep /* if dce */
 932           clrlcf    flgwd1,timesw       /* reset timer flag */
 933           setime    0         /* reset timer */
 934           setlcl    rc,0      /* clear the retry count for later */
 935           waitm
 936           rem
 937           rem
 938 ************************************************************
 939 *
 940 *         sndua - send ua and remine here
 941 *
 942 ************************************************************
 943           rem
 944 sndua1    setlcf    flgwd1,psarm
 945 sndua     setlcf    flgwd2,snua         /* set send ua flag */
 946           meter2    resrcv,1  /* meter this, but it not right */
 947           dumpin              /* dump any input */
 948           calsub    fbitck    /* check f-bit */
 949           calsub    outlst    /* output it */
 950           waitm
 951           rem
 952           rem
 953 ************************************************************
 954 *
 955 *         dsdisc - send disc go to down state (link still down )
 956 *
 957 *         dsdscp - same as above but send a poll disc
 958 *
 959 ************************************************************
 960           rem
 961 ckdisc    setlcf    flgwd3,hldvar       /* DM slow UA process to SS state */
 962           tstlcf    flgwd1,discft,dsdisc
 963           clrlcf    flgwd3,hldvar       /*no down state let t1 handle it */
 964           dumpin
 965           waitm
 966 ckdscp    tstlcf    flgwd1,discft,dsdscp
 967           goto      t1sbmg    /* ss state t1 expired rc=n2 */
 968           rem
 969 dsdscp    setchr    pmask,pfon          /* set polled bit */
 970 dsdisc    setlcf    flgwd1,downsw       /* set down flag */
 971           setlcl    flgwd2,0  /* clear out output control */
 972           calsub    fbitck    /* check for f-bit */
 973           dumpin              /* dump any input */
 974           goto      dwnst     /* goto down state */
 975           rem
 976           rem
 977 ************************************************************
 978 *
 979 *         susua - send ua and goto to setup state (lap only)
 980 *          since DCE are in t3, no check for dte needed
 981 *          if lapb - set lastf to bad command go to driver
 982 *          else send a sarm, send ua, reset t3, goto su state
 983 *
 984 ************************************************************
 985           rem
 986 susua     tstlcf    flgwd1,laparb,t3bcrd /* lapb bad news */
 987           setlcf    flgwd1,psarm        /* sarm recieve */
 988           clrlcf    flgwd1,timet3       /* clear t3 timer */
 989           setime    0         /* clear timer */
 990           setlcl    rc,0      /* reset retry counter */
 991           dumpin              /* dump any input */
 992           setlcl    state,lksust        /* set state to su */
 993           setlcf    flgwd2,snsarm       /* one sarm needed */
 994           setlcf    flgwd2,snua         /* also one ua */
 995           calsub    outlst    /* output one of them */
 996           setimv    t1        /* set timer */
 997           setlcf    flgwd1,timesw       /* insure timer is running */
 998           goto      sustte    /* go to su state wait */
 999           rem
1000 t3bcrd    setlcl    lastf,rvbdcr        /* bad command */
1001           goto      t3test    /* t3 state driver entry */
1002           rem
1003           rem
1004 ************************************************************
1005 *
1006 *         lpbiup - lapb initial linkup entry
1007 *          if state = t3state send a ua
1008 *          if lap entry then bad command (label t3bcrd)
1009 *         lkupst- -linkup for lap
1010 *         lpbpup - reset link (lapb) do not report to host
1011 *          status
1012 *
1013 ************************************************************
1014           rem
1015 ckupst    tstlcf    flgwd1,psarm,lkupst
1016           calsub    fbitck    /* check f-bit */
1017           dumpin              /* UA no longer needed */
1018           waitm
1019 lpbiup    tstlcf    flgwd1,laparb,lkupst /* if lapb */
1020           goto      t3bcrd    /* no bad command */
1021 lkupst    setlcf    flgwd1,rprtsw       /* report to host link failure */
1022           signal    dialup    /* the host we are up */
1023 lpbpup    calsub    fbitck    /* check f-bit */
1024           dumpin              /* dump any input */
1025           clrlcf    flgwd1,psarm
1026           clrlcf    flgwd1,downsw       /* clear down indicator */
1027           setlcl    flgwd2,0  /* clear any output */
1028           tstlcl    state,lkt3st,snualk /* send a ua */
1029           tstlcl    pstate,lkupfr,snualk /* also send ua */
1030           goto      norlku    /* no ua needed */
1031           rem
1032 snualk    setlcf    flgwd2,snua         /* set ua flag */
1033           calsub    outlst    /* output it */
1034           rem
1035 norlku    clrlcf    flgwd1,timesw       /* clear timer */
1036           clrlcf    flgwd1,timet3       /* clear t3 flag */
1037           setlcl    flgwd3,0  /* reset some flags */
1038           setlcl    v.s,0     /* clear the state variables */
1039           setlcl    v.r,0
1040           setlcl    a.s,0
1041           setlcl    a.r,0
1042           setlcl    rc,0      /* reset retry counter */
1043           setlcl    uaoffs,0  /* set to top message (first
1044 *                               unacknowledge message */
1045           clrlcf    flgwd1,t1rec
1046           setime    0         /* clear time */
1047           setlcl    state,lkisup        /* set statte to link up */
1048           setlcl    pstate,lkprnr       /* set p state to normal */
1049           setlcl    sstate,lkscnm       /* set s state to normal */
1050           setchr    pmask,null          /* reset mask bits */
1051           setchr    fmask,null
1052           setchr    cmdrb1,null         /* no cmdr/frmr info */
1053           calasm    scanup
1054           tstlcl    bufadd,0,nupwt      /* any thing to write */
1055           setlcf    flgwd2,snifr        /* yes */
1056           calsub    outlst    /* output if we can */
1057 nupwt     calsub    sigotp    /* check for sndout requirements */
1058           goto      linkup    /* that is all to link up */
1059           rem
1060           rem
1061 ************************************************************
1062 *
1063 *         t3t1ln - t3 state t1 expired rc < n2
1064 *          This is currently impositiable - for their is only
1065 *          one timer running. Incase  it is corrected inc rc
1066 *          and restart the timer.
1067 *
1068 ************************************************************
1069           rem
1070 t3t1ln    addlcl    rc,1      /* inc rc counter */
1071           setlcf    flgwd1,timesw       /* start timer flag */
1072           setimv    t1        /* set timer going */
1073           waitm
1074           rem
1075           rem
1076 ************************************************************
1077 *
1078 *         sndsbm - meter bad command send a sabm and remain
1079 *
1080 ************************************************************
1081           rem
1082 sndsbm    meter2    rtyrcv,1  /* meter bad command */
1083           dumpin              /* no input needed */
1084           setlcf    flgwd2,snsabm       /* set send sabm flag */
1085           calsub    outlst    /* output it */
1086           waitm
1087           rem
1088           rem
1089 ************************************************************
1090 *
1091 *         t1sabm - t1 expired send a sabm and remain
1092 *
1093 ************************************************************
1094           rem
1095 t1sabm    addlcl    rc,1      /* inc retry counter */
1096 t1sbmg    setchr    pmask,pfon
1097           setlcf    flgwd2,snsabm       /* set send sabm flag */
1098           calsub    outlst    /* output it */
1099           setlcf    flgwd1,timesw       /* set timer flag */
1100           setimv    t1        /* start timer */
1101           waitm
1102           rem
1103           rem
1104 ************************************************************
1105 *
1106 *         dsdsua - send disc, send ua, go to down state (lap)
1107 *          if dte send just a ua
1108 *          else send both disc and a ua
1109 *
1110 ************************************************************
1111           rem
1112 dsdsua    meter2    resrcv,1  /* meter reset counts */
1113           setlcl    flgwd2,0  /* clear any output messages */
1114           setchr    pmask,null          /* no poll needed */
1115           clrlcf    flgwd1,pbit         /* clear bit */
1116           setlcf    flgwd2,snua         /* set send ua flag */
1117           tstlcf    flgwd1,dcedte,dcdsua /*dce test */
1118           goto      dtdsua    /* nothing for dte */
1119 dcdsua    setlcf    flgwd2,sndisc       /* need one disc */
1120 dtdsua    dumpin              /* no input needed */
1121           calsub    outlst    /* output anything that is left */
1122           setlcl    rc,0      /* reset retry counter */
1123           setlcf    flgwd1,timesw       /* set timer flag */
1124           setimv    t1        /* set timer going */
1125           goto      dwnst     /* go to down state */
1126           rem
1127           rem
1128 ************************************************************
1129 *
1130 *         sndsmp - send pol sarm and remain
1131 *         tisarm - same
1132 *
1133 ************************************************************
1134           rem
1135 tisarm    null
1136 sndsmp    setchr    pmask,pfon          /* set pol bit */
1137           addlcl    rc,1      /* inc retry counter */
1138           setlcf    flgwd2,snsarm       /* set sarm flag */
1139           dumpin              /* dump any input */
1140           setlcf    flgwd1,timesw       /* restart the timer */
1141           calsub    outlst
1142           setimv    t1
1143           waitm
1144           rem
1145           rem
1146 ************************************************************
1147 *
1148 *         frsrrq - frame reject or sarm required
1149 *          if lapb send frame reject and goto fr state
1150 *          else send sarm go to sr state
1151 *
1152 ************************************************************
1153           rem
1154 frsrrq    meter2    resxmt,1  /* meter link reset */
1155           setlcl    rc,0      /* reset retry conter */
1156           setlcf    flgwd1,timesw
1157           tstlcf    flgwd1,laparb,lpbfrc /* lapb test */
1158           setlcf    flgwd2,snsarm       /* sarm needed (lap) */
1159           setlcl    pstate,lkprsr       /* set primary to new state */
1160           goto      frsren    /* go to continue */
1161 lpbfrc    setlcf    flgwd2,snfrmr       /* set send frmr */
1162           calasm    blfcdr    /* generate the frmr fields */
1163           calasm    ldnsdr    /* load the n(s) value */
1164           setlcl    pstate,lkupfr       /* set sub state to fr state */
1165           setlcl    sstate,lkupfr
1166 frsren    dumpin    /* dump input now */
1167           calsub    outlst
1168           setimv    t1        /* restart timer */
1169           waitm
1170           rem
1171           rem
1172 ************************************************************
1173 *
1174 *         sborsm - send SABM or SARM
1175 *           if LAP then send SARM and go to sarm reset state.
1176 *           else if LAPB then send SABM and go to reset state
1177 *
1178 ************************************************************
1179           rem
1180 sborsm    tstlcl    lastf,rvcmdr,cmchkl /* check I-frame length problem
1181           goto      sbors1    /* no continue */
1182 cmchkl    tstlcl    cmdrln,0,sbors1 /* length error */
1183           setlcf    flgwd2,sndisc /* send disc to crash the link */
1184           calsub    outlst    /* get the disc out
1185           setlcl    stat0,lstcmr /* set cmdr reject */
1186           linsta    stat0     /* send in the status */
1187           clrlcf    flgwd1,rprtsw /* clear report indicator */
1188           goto      deact     /* crash the link */
1189 sbors1    meter2    resxmt,1  /* meter link reset */
1190           setlcl    rc,0      /* reset counter */
1191           setlcf    flgwd1,timesw /* needed timer */
1192           tstlcf    flgwd1,laparb,lpbsbb /* lap or lapb */
1193           setlcl    pstate,lkprsr /* set sarm reset state */
1194           setlcf    flgwd2,snsarm /* send sarm */
1195           goto      sbsmct
1196 lpbsbb    setlcl    pstate,lkuprs /* set reset state */
1197           setlcl    sstate,lkuprs /* just in case */
1198           setlcf    flgwd2,snsabm /* send sabm */
1199 sbsmct    dumpin
1200           calsub    outlst    /* send the message */
1201           setimv    t1        /* set timer */
1202           setlcf    flgwd1,timesw /* set timer flags */
1203           waitm
1204           rem
1205           rem
1206 ************************************************************
1207 *
1208 *         uaigfr - UA receive during substates normal, t1
1209 *          expired, and remote busy. Ignore it unless it lapb
1210 *          then go to frame reject
1211 *
1212 ************************************************************
1213           rem
1214 uaigfr    calsub    fbitck    /* check the f-bit */
1215           tstlcf    flgwd1,laparb,frsrrq /* lapb frsrrq can do it */
1216           dumpin              /* input not needed now */
1217           waitm               /* ignore it, go back to start */
1218           rem
1219           rem
1220 ************************************************************
1221 *
1222 *         nrrr - Recieve RR frame - go back to nornal substate
1223 *          set xx and n(r), ack any frame, also set fbit and
1224 *          timer
1225 *
1226 ************************************************************
1227           rem
1228 nrrr      tstlcl    sstate,lksccs,cshook /* cs (lap) generate aproper response*/
1229           calsub    fbitck    /* process f bit */
1230           dumpin
1231           tstlcl    pstate,lkprrb,rsprrb /* remote busy some special */
1232           setlcl    pstate,lkprnr       /* set p state to normal */
1233           tstlcv    a.r,n.r,gowait      /* ack any */
1234           calsub    ackmsg    /* ok ack them */
1235           goto      suakst
1236 rsprrb    setlcl    pstate,lkprnr       /* set pstate to normal */
1237           calsub    ackmsg    /* ack any frames */
1238           setlcv    v.s,n.r   /* set v.s to normal */
1239           rem                 /* a.r will be handle by the ACK process */
1240           calsub    clrrbb    /* set up next output frame */
1241 suakst    setlcl    rc,0      /* reset retry counter */
1242           tstlcv    v.s,a.r,rclkrr      /* if equal reset clock */
1243           setlcf    flgwd1,timesw       /* no restart timer */
1244           setimv    t1
1245 gowait    tstlcf    flgwd1,t1rec,rect1 /* tier recovery in process */
1246           tstlcf    flgwd3,rtyhld,hldrty /* more t1 recovery LAPB left over */
1247 gownt1    calsub    outlst    /* output any thing */
1248           gotov     retlbl    /* that is all */
1249           rem
1250 ************************************************************
1251 *
1252 *         This should be only LAPB condition - reset
1253 *         I-frame hold flag and restart i_frame processing
1254 *
1255 ************************************************************
1256 hldrty    clrlcf    flgwd3,rtyhld       /* reset i-frame hold */
1257           calsub    clrrbb    /* setup next output i-frame */
1258           goto      gownt1    /* finish up */
1259           rem
1260 rect1     clrlcf    flgwd1,t1rec        /* reset recovery flag */
1261           clrlcf    flgwd3,rtyhld       /* reset i-frame hold */
1262           setlcl    rc,0      /* reset retry counter */
1263           calsub    clrrbb    /* setup next output frame */
1264 ************************************************************
1265 *
1266 *         lapb on timer recovery reset , must check for
1267 *          unack frames if any the polled bit must be set
1268 *          again for next I-frame to be sent
1269 *
1270 ************************************************************
1271           rem
1272           tstlcf    flgwd1,laparb,trplms /* is it lapb */
1273           goto      gownt1    /* no proceed */
1274 trplms    tstlcv    xx,a.r,gownt1       /* all ack return */
1275           tstlcl    bufadd,0,gownt1     /* test for no output */
1276           setchr    pmask,pfon          /* set poll on */
1277           setlcf    flgwd1,pbit         /* set bit */
1278           setlcf    flgwd3,mstifr       /* must send one I-frame out */
1279           calsub    outlst    /* output poll I-frame */
1280           setlcf    flgwd3,rtyhld       /* no more i-frame wait for response */
1281           gotov     retlbl    /* go back to normal wait */
1282           rem
1283 rclkrr    tstlcl    uaoffs,0,rclkra /* any unack messages? */
1284           punt      3         /* yes crash for there shouldn't be */
1285 rclkra    null
1286           clrlcf    flgwd1,timesw       /* clear flag */
1287           setime    0         /* reset timer */
1288           goto      gowait    /* now finish it up */
1289           rem
1290           rem
1291 ************************************************************
1292 *
1293 *         rbrnr - go to remote busy and process rnr message
1294 *
1295 ************************************************************
1296           rem
1297 rbrnr     tstlcl    sstate,lksccs,cshook /* lap error */
1298           calsub    fbitck    /* process f-bit */
1299           setlcl    pstate,lkprrb       /* set pstate to remote busy */
1300           dumpin
1301           calsub    ackmsg    /* ack any output messages */
1302           setlcl    uaoffs,0  /* sending no more, top one is next*/
1303           tstlcf    flgwd1,timesw,rbrn1 /* reset timer needed */
1304           goto      rbrnr2
1305 rbrn1     setlcl    rc,0      /* reset retry counter */
1306           setlcf    flgwd1,timesw       /* reset timer */
1307           setimv    t1
1308 rbrnr2    waitm
1309           rem
1310           rem
1311 ************************************************************
1312 *
1313 *         nrrej - normal state rej recieve
1314 *
1315 ************************************************************
1316           rem
1317 nrrej     tstlcl    sstate,lksccs,cshook
1318           calsub    fbitck
1319           setlcl    pstate,lkprnr       /*set state to normal */
1320           meter2    rtyxmt,1  /* meter this one */
1321           calsub    ackmsg    /* ack any output messages */
1322           calsub    rejrst    /* get reject message */
1323           dumpin              /* input not needed */
1324           tstlcv    v.s,a.r,rclkrr /* recieve last message so stop the clock */
1325           setlcv    v.s,n.r   /* transmit this frame next */
1326           goto      gowait    /*some more check common area */
1327           rem
1328           rem
1329 ************************************************************
1330 *
1331 *         t1stch - t1 expired retramit the earlest I-frame
1332 *          In lapb case start sending poll rr frames
1333 *
1334 ************************************************************
1335           rem
1336 t1stch    meter2    rtyxmt,1  /* meter this */
1337           clrlcf    flgwd3,rtyhld       /* tempory reset i-frame hold */
1338           addlcl    rc,1      /* inc the retry counter */
1339           setlcl    pstate,lkprt1       /* set pstate to t1 recovery */
1340           setlcf    flgwd1,t1rec        /* set t1 recovery flag */
1341           setlcv    xx,v.s    /* save current value */
1342           setlcv    v.s,a.r   /* set to first unack frame */
1343           setchr    pmask,pfon          /* set poll bit */
1344           setlcf    flgwd1,pbit
1345           setimv    t1        /* reset time for next time out */
1346           setlcl    uaoffs,0  /* setup first message */
1347           tstlcf    flgwd1,laparb,lpbt1s /* test for lapb */
1348           tstlcl    bufadd,0,lpanif
1349           setlcf    flgwd2,snifr        /* set i frame to transmit */
1350           setlcf    flgwd3,mstifr       /* force at least one I-frame */
1351 t1stou    calsub    outlst    /* output it */
1352           setlcf    flgwd3,rtyhld       /*no I-frame to be sent */
1353 lpanif    waitm     /* that is all */
1354 lpbt1s    clrlcf    flgwd2,snifr        /* lapb no i-frame during recovery */
1355           setlcf    flgwd2,snprr        /* set poll rr message needed */
1356           goto      t1stou
1357           rem
1358           rem
1359 ************************************************************
1360 *
1361 *         n2rssr - t1 expired with rc = n2
1362 *          lap go to sr state and send sarm
1363 *          lapb go to rs state and send sabm
1364 *
1365 ************************************************************
1366           rem
1367 n2rssr    meter2    resxmt,1  /* meter this */
1368           setchr    pmask,null          /* no needed poll bit yet */
1369           clrlcf    flgwd1,pbit
1370           setlcl    rc,0      /* reset retry counter */
1371           tstlcf    flgwd1,laparb,lpbsbs
1372           setlcl    pstate,lkprsr       /* set pstate to sr state */
1373           setlcf    flgwd2,snsarm       /* set send sarm flag */
1374           goto      n2rrsc
1375 lpbsbs    setlcl    pstate,lkuprs       /* set stats to reset sabm */
1376           setlcl    sstate,lkuprs
1377           setlcf    flgwd2,snsabm       /* send sabm now */
1378 n2rrsc    dumpin
1379           calsub    outlst
1380           setlcf    flgwd1,timesw       /* reset timer */
1381           setimv    t1        /* restart the timer */
1382           waitm
1383           rem
1384           rem
1385 ************************************************************
1386 *
1387 *         backnr - LAP only go back to normal state reset
1388 *          outgoing frames and v.s, a.s values
1389 *
1390 ************************************************************
1391           rem
1392 backnr    clrlcf    flgwd1,t1rec        /* no timer recovery */
1393           clrlcf    flgwd3,rtyhld       /* no i-frame holding */
1394           dumpin              /* needed no input */
1395           setlcl    v.s,0     /* reset some values */
1396           setlcl    a.r,0
1397           setime    0         /* reset timer */
1398           setlcl    rc,0      /* reset retry counter */
1399           clrlcf    flgwd1,timesw       /* reset timer indicator */
1400           setchr    fmask,null          /* reset maskes */
1401           setchr    pmask,null
1402           setlcl    uaoffs,0  /* reset i-frame to top */
1403           calasm    scanup
1404           tstlcl    bufadd,0,bknrni     /* any i-frame to transmit */
1405           setlcf    flgwd2,snifr        /* some to go */
1406 bknrni    setlcl    pstate,lkprnr       /* set pstate to normal */
1407           calsub    outlst    /* output frames */
1408           calsub    sigotp    /* tell HOST of output */
1409           waitm
1410           rem
1411           rem
1412 ************************************************************
1413 *
1414 *         tidisc - t1 expired with rc = n2 send dics and go down
1415 *
1416 ************************************************************
1417           rem
1418 tidisc    meter2    resxmt,1  /* meter this stuff */
1419           setlcl    rc,0      /* reset counter */
1420           setchr    pmask,null          /* reset mask */
1421           clrlcf    flgwd1,pbit
1422           setlcf    flgwd1,downsw       /* indicat we are down */
1423           setlcl    flgwd2,0  /* reset output flags */
1424           setlcf    flgwd2,sndisc       /* send a disc */
1425           calsub    fbitck
1426           calsub    outlst    /* output the disc */
1427           goto      dwnst     /* go down now */
1428           rem
1429 ************************************************************
1430 *
1431 *         dsduab - if lap then use dsdsua by goto
1432 *          else if lapb then send a ua and go to down state
1433 *
1434 ************************************************************
1435           rem
1436           rem
1437 dsduab    tstlcf    flgwd1,laparb,dsdub /* test for lapb */
1438           goto      dsdsua    /* lap only */
1439 dsdub     setlcl    flgwd2,0  /* reset output flags */
1440           setchr    pmask,null          /* reset poll bit */
1441           setlcf    flgwd2,snua         /* flag a send ua */
1442           calsub    outlst    /* output it now */
1443           goto      dwnst     /* ok go down now */
1444           rem
1445           rem
1446 ************************************************************
1447 *
1448 *         nmdua - send ua and clear this state.
1449 *
1450 *         nmsdua - go to normal   (lap only )
1451 *
1452 ************************************************************
1453           rem
1454           rem
1455 nmsdua    tstlcf    flgwd1,laparb,frcmdr /* lapb error */
1456           setlcl    sstate,lkscnm       /* reset state */
1457           setchr    cmdrb1,null /* clear cmdr fields */
1458 nmdua     tstlcf    flgwd1,laparb,frcmdr /* lapb error */
1459           setlcl    v.r,0     /* reset recieve variables */
1460           setlcl    a.s,0
1461           tstlcl    bufadd,0,nmdua1
1462           setlcf    flgwd2,snifr        /* tried to write something */
1463 nmdua1    setlcl    flgwd2,snua         /* send a ua */
1464           meter2    resrcv,1  /* meter the reset recieve */
1465           dumpin
1466           calsub    outlst    /* send ua out */
1467           waitm
1468           rem
1469           rem
1470 ************************************************************
1471 *
1472 *         nmduab - recieve sabm send a ua and reset link
1473 *          (lapb only )
1474 *
1475 ************************************************************
1476           rem
1477 nmduab    tstlcf    flgwd1,laparb,nmdubc /* test for lapb */
1478           goto      frcmdr    /* no it a lap */
1479 nmdubc    setlcl    flgwd2,0  /* clear all output stuff */
1480           dumpin              /* no more input needed */
1481           goto      snualk    /* reset link via linkup code */
1482           rem
1483           rem
1484 ************************************************************
1485 *
1486 *         frcmdr - build reject fields and set state as follows
1487 *          if lap then set state to CS
1488 *          else if lapb then set state to FR
1489 *
1490 *         sndcmd - cs lap only send cmdr again
1491 *
1492 *         sndfr - fr lapb only send frmr again
1493 *            NOTE cmdr and frmr are the same command
1494 *
1495 ************************************************************
1496           rem
1497 frcmdr    calasm    blfcdr    /* build the reject frame */
1498           tstlcf    flgwd1,laparb,lpbfrb /* test for lapb */
1499           setlcl    sstate,lksccs       /* lap set state */
1500           goto      sndcmd    /* continue on */
1501 lpbfrb    setlcl    sstate,lkupfr       /* set laps state */
1502           setlcl    pstate,lkupfr
1503           calasm    ldnsdr
1504 sndfr     null                 /* lapb entry */
1505 sndcmd    setlcf    flgwd2,sncmdr       /* set output flag */
1506           meter2    rtyrcv,1  /* meter this */
1507           dumpin    /* input not needed */
1508           calsub    outlst    /* output the command */
1509           waitm
1510           rem
1511           rem
1512 ************************************************************
1513 *
1514 *         rjrej - Reject - bad I-frame only one reject can be
1515 *          sent.
1516 *
1517 *         rej1 - same as reject but no rej is sent
1518 *
1519 ************************************************************
1520           rem
1521 rjrej     setlcl    sstate,lkscrj       /* set sstate to reject state */
1522           setlcf    flgwd2,snrej        /* set reject flag */
1523 rej1      calsub    ackmsg    /* ack any frames */
1524           calsub    outlst    /* output any messages */
1525           meter2    rtyrcv,1  /* meter it */
1526           dumpin
1527           waitm
1528           rem
1529           rem
1530 ************************************************************
1531 *
1532 *         nmif - process I-frame and stay here
1533 *
1534 *         pnmif - process I-frame and go to normal state
1535 *          also check for local busy conditions
1536 *
1537 ************************************************************
1538           rem
1539 pnmif     setlcl    sstate,lkscnm       /* set sstate */
1540 nmif      calasm    ckrnr     /* check for local busy */
1541           tstlcl    rnrflg,0,nmifa      /* is it */
1542           goto      sndrt1
1543 nmifa     calsub    ackmsg    /* ack any frames */
1544           setlcv    amarg1,v.r          /* set mod8 arith */
1545           setlcl    amarg2,1
1546           calasm    admod8
1547           setlcv    v.r,amarg2
1548           calasm    setbrk    /* set break flag */
1549           sendin              /* send it off to the HOST */
1550           tstlcv    a.r,v.s,rcnmif      /* reset timer */
1551           goto      nmifct
1552 rcnmif    tstlcf    flgwd1,t1rec,nmifct /* if recovery in process skip */
1553           tstlcl    uaoffs,0,rcnmfa     /*  some unack buffers ? */
1554           punt      3         /* shouldn't be any crash */
1555 rcnmfa    null
1556           clrlcf    flgwd1,timesw
1557           setime    0
1558 nmifct    null
1559           setlcf    flgwd2,snrr         /* ack this last frame */
1560           calsub    outlst    /* do it now */
1561           waitm
1562           rem
1563           rem
1564 ************************************************************
1565 *
1566 *         finrr - poll response recieve send a rr back
1567 *
1568 *         finrej - since one rej can be send send a rr back
1569 *          instead
1570 *
1571 ************************************************************
1572           rem
1573 finrr     null
1574 finrej    calsub    ackmsg    /* ack any frames */
1575           dumpin
1576           setlcf    flgwd2,snrr         /* send the rr */
1577           calsub    outlst
1578           waitm
1579           rem
1580           rem
1581 ************************************************************
1582 *
1583 *         sndrnr - send RNR remote busy recieve I-frame
1584 *          test for not busy if so process as normal
1585 *
1586 ************************************************************
1587           rem
1588 sndrnr    calasm    ckrnr     /* check for local busy */
1589           tstlcl    rnrflg,1,sndrt1     /* yes it is */
1590           setlcl    sstate,lkscnm
1591           goto      secmpr    /* reprocess it */
1592 sndrt1    setlcl    sstate,lksclb       /* set local busy condition */
1593           meter2    rtyrcv,1  /* meter this */
1594           calsub    ackmsg    /* ack any frames */
1595           dumpin
1596           setlcf    flgwd2,snrnr        /* send  rnr */
1597           calsub    outlst
1598           waitm
1599           rem
1600           rem
1601 ************************************************************
1602 *
1603 *         finrnr - poll response recieve send an rnr back
1604 *
1605 ************************************************************
1606           rem
1607 finrnr    calsub    ackmsg    /* ack any input frames */
1608           dumpin
1609           calasm    ckrnr     /* check if busy has been clear */
1610           tstlcl    rnrflg,0,finrn1
1611           setlcf    flgwd2,snrnr /* no send rnr */
1612           goto      finrn2
1613 finrn1    setlcl    sstate,lkscnm /* normal state */
1614           setlcf    flgwd2,snrr /*send rr */
1615 finrn2    calsub    outlst
1616           waitm
1617           rem
1618           rem
1619 ************************************************************
1620 *
1621 *         discds - either recieve DM or t1 expired with rc = n2
1622 *          on both FR and RS state - send disc and go down
1623 *
1624 ************************************************************
1625           rem
1626 discds    setlcl    flgwd2,0  /* clear out flags */
1627           dumpin
1628           setlcf    flgwd2,sndisc       /* send a disc now */
1629           calsub    outlst
1630           goto      dwnst
1631           rem
1632           rem
1633 ************************************************************
1634 *
1635 *         rssabm - go to RS state and send a sabm
1636 *
1637 ************************************************************
1638           rem
1639 rssabm    calsub    fbitck    /* check f-bit */
1640           dumpin              /* dump any input */
1641           setlcf    flgwd1,timesw
1642           setimv    t1
1643           setlcf    flgwd2,snsabm       /* set sabm flags */
1644           setlcl    pstate,lkuprs       /* set states now */
1645           setlcl    sstate,lkuprs
1646           calsub    outlst    /* output sabm now */
1647           waitm
1648           rem
1649           rem
1650 ************************************************************
1651 *
1652 *         t1nor - t1 - expired rest timer and to rc and wait
1653 *
1654 ************************************************************
1655           rem
1656 t1nor     addlcl    rc,1      /* inc rc counter */
1657           setlcf    flgwd1,timesw       /* set timer flag */
1658           setimv    t1        /* restart timer */
1659           waitm
1660           ttls      status called routines and errors handlers
1661           eject
1662           rem
1663 ************************************************************
1664 *
1665 *         exhsta - Got exhaust status.  This means an input tally runout
1666 *         occurred which resets receive mode.  Therefore, we must
1667 *         set receive mode on again.  Unfortunately, we cannot do
1668 *         this immediately if there is a pending output dcw list.
1669 *
1670 *         stpchn at this point realy messup the x25_tables, therefore,
1671 *         the code of stpchn is inserted here and is modified to
1672 *         handle the unique problem of this tables.
1673 *
1674 *****************************************************************
1675           rem
1676 exhsta    null
1677           meter2    m.exh,1   /* meter this conditions */
1678           goto      exhrst    /* and reset things */
1679           rem
1680 xtesta    null
1681           meter1    m.xte,1   /* meter it */
1682           rem
1683 exhrst    null
1684           contrl    rrec+rxmit+smark    /* reset transmit and recieve */
1685           setime    1         /* set a timer to insure resetting occures */
1686           wait      exhsta,exhwrt,testst          /* wait for reset */
1687           rem
1688 ************************************************************
1689 *
1690 *         NOTE: exhsta in time out is for insuring that the rrec and rxmit is performed.
1691 *
1692 *         exhwrt is to insure that no output is lost.
1693 *
1694 *         testst is to kill the line if a hangup is signalled.
1695 *
1696 ************************************************************
1697           rem
1698           status    marker,0,exhret /* finish on stopping the channel */
1699           status    0,dsr,hang
1700 *
1701 exhwrt    setlcf    flgwd1,oasw         /* output arrive */
1702           setlcf    flgwd1,oprusw       /* say it has been recieve */
1703           waitm               /*go back to waiting */
1704 *
1705 exhrtr    setimv    t1        / not right but timer will be restarted */
1706           goto      exhcnt
1707 *
1708 exhret    tstlcf    flgwd1,timesw,exhrtr /* timer running, set timer */
1709           setime    0         /* reset the timer */
1710 exhcnt    null
1711           clrlcf    flgwd1,rcvsw        /* out of rcv mode */
1712           meter2    rtyrcv,1  /* meter also a retried to be preform */
1713           dumpin
1714           tstlcf    flgwd1,xmitsw,outpcw /* output was going process like term */
1715           contrl    srec      /* reset recieve mode */
1716           setlcf    flgwd1,rcvsw
1717           tstlcf    flgwd1,oprusw,writeo /* output has arrive process it */
1718           gotov     retlbl    /* return to previous wait */
1719           rem
1720           rem
1721 ************************************************************
1722 *
1723 *         FCS error on the frame
1724 *
1725 ************************************************************
1726           rem
1727 fcesta    meter2    mfce,1    /* meter it */
1728           goto      abtfn
1729           rem
1730           rem
1731 ************************************************************
1732 *
1733 *         read abort status
1734 *
1735 ************************************************************
1736           rem
1737 rabsta    meter2    mrab,1
1738 abtfn     meter2    rtyrcv,1  /* meter everything as a retried */
1739           dumpin
1740           waitm
1741           rem
1742           rem
1743 ************************************************************
1744 *
1745 *         gopunt - unrecoverable error so DIE
1746 *
1747 ************************************************************
1748           rem
1749 gopunt    punt      2
1750           rem
1751           rem
1752 ************************************************************
1753 *
1754 *         hang - clean up tib extension and reset dtr
1755 *          signals
1756 *
1757 *         hangr - delete the tib extension and signal hangup
1758 *
1759 ************************************************************
1760           rem
1761 hang      stpchn              /* kill the channel */
1762           clrlcf    flgwd1,xmitsw
1763           calsub    clrabf
1764           config
1765           rmode     fg.itf
1766           contrl    rdtr+rrts
1767 hangr     unwind              /* in case we exited a subroutine */
1768           retext              /* release the extension */
1769           dumpin
1770 hang2     dmpout
1771           tstwrt    hang2     /* loop untill all output is gone */
1772           clrflg    (tflisn,tfhang)
1773           signal    hangup
1774           goto      hungup
1775           rem
1776           rem
1777 ************************************************************
1778 *
1779 *         outpcw - output process complete check for more
1780 *
1781 ************************************************************
1782           rem
1783 outpcw    clrlcf    flgwd1,xmitsw       /* reset transmitter busy */
1784           tstlcf    flgwd1,ifrsnd,iprotm
1785           dmpout
1786           goto      iptmrt
1787 outclr    calsub    clrabf    /* clear any data frames */
1788           goto      iptrta
1789 iprotm    calasm    clrocp
1790 iptmrt    tstlcf    flgwd3,mstclr,outclr
1791 iptrta    tstlcf    flgwd1,rcvsw,sgoa /* is reciver running */
1792           contrl    srec      /* no restart it */
1793           setlcf    flgwd1,rcvsw
1794 sgoa      tstlcf    flgwd1,ackrq,sgoa1
1795           goto      sgoa2
1796 sgoa1     setlcv    n.r,nrv
1797           calsub    ackmsg
1798 sgoa2     tstwrt    writa2    /* output on t.ocp process it */
1799           tstlcf    flgwd1,oprusw,write1
1800           clrlcf    flgwd1,ifrsnd       /* clear for next */
1801           tstlcf    flgwd1,ackrq,ackrtc
1802           calsub    outlst
1803           gotov     retlbl    /* insure right wait block */
1804           ttls      wait test routines and timer determination
1805           eject
1806           rem
1807 ************************************************************
1808 *
1809 *         timeo - time out processing set lastf to proper state
1810 *
1811 ************************************************************
1812           rem
1813 timeo     setlcl    lastf,rvbdad        /* set function to ignore value */
1814           setlcv    lkupws,pstate       /* set to primary state */
1815           tstlcf    flgwd1,timesw,cotime /* timer must be running */
1816 retime    retsub
1817           rem
1818 cotime    tstlcf    flgwd1,timet3,retime
1819           rem
1820           tstlcv    rc,n2,n2equl        /* rc = n2 */
1821           setlcl    lastf,rvt12l        /* no normal case */
1822           retsub
1823 n2equl    setlcl    lastf,rvt12e        /* next state or down */
1824           retsub
1825           rem
1826           rem
1827 ************************************************************
1828 *
1829 *         testst - comman DIA test line status and orders
1830 *
1831 ************************************************************
1832           rem
1833 testst    tstflg    tfhang,hang         /* told to hangup */
1834           linctl    stat0,testwt        /* line status - no return */
1835           tstlcl    stat0,lctdea,deact /* told to deactivate the line */
1836           tstlcl    stat0,lctdis,dsdisc /* logical disconnect the line*/
1837 *                     NOTE is status should never be used */
1838           rem
1839 testwt    waitm
1840           rem
1841           rem
1842 ************************************************************
1843 *
1844 *         badoa - write recieve for actual linkup and linkup
1845 *          is not complete. Rember the write, but flush the output
1846 *
1847 ************************************************************
1848           rem
1849 badoa     setlcf    flgwd1,oasw         /* output arrived since last sndout */
1850           tstlcf    flgwd1,xmitsw,badoa2 /* xmit busy */
1851           dmpout              /* no dump output now */
1852 badoa2    waitm
1853           rem
1854           rem
1855 ************************************************************
1856 *
1857 *         writeo - write output from the DIA (I-frame.
1858 *          This will not set up the control fiels in the I-frame
1859 *          nor will it set the clock and state variable, The outlst
1860 *          do the dirty work. Also the output is place on the
1861 *          unprocess chain for later processing.
1862 *
1863 ************************************************************
1864           rem
1865 writeo    setlcf    flgwd1,oasw         /* say we have output form host */
1866           setlcf    flgwd1,oprusw
1867           tstlcf    flgwd1,xmitsw,wrtrrt
1868           tstwrt    writa2
1869           clrlcf    flgwd1,oprusw
1870           goto      wrtret
1871 write1    tstlcf    flgwd1,ifrsnd,writ1a
1872           goto      writa2
1873 writ1a    calasm    scpbst
1874           clrlcf    flgwd1,ifrsnd
1875           goto      writa3
1876 writa2    calasm    ocpset,(temups)
1877           calasm    clrocp
1878 writa3    clrlcf    flgwd1,oprusw
1879           calasm    scupem
1880           tstlcf    flgwd1,ackrq,ackrtc
1881           calsub    outlst    /*tried to send it now */
1882 wrtret    calsub    sigotp    /* signal the HOST */
1883 wrtrrt    gotov     retlbl    /* insure right wait block */
1884           rem
1885 ackrtc    clrlcf    flgwd1,ackrq
1886           calsub    sigotp    /* just incase ackmsg bypassed it */
1887           goto      suakst
1888           rem
1889           rem
1890 ************************************************************
1891 *
1892 *         clrabf - clear the buffer chain and reset some variables
1893 *
1894 ************************************************************
1895           rem
1896 clrabf    tstlcf    flgwd1,xmitsw,busyst
1897           tstwrt    clrbfn    /* anything on the output chain */
1898 clrloo    calasm    setocp,(bufadd)
1899 clrlo1    dmpout              /* dump the message */
1900 clrlo2    tstwrt    clrlo1    /* anymore */
1901           tstlcl    upobuf,0,clrlo3
1902           calasm    setocp,(upobuf)
1903           setlcl    upobuf,0
1904           goto      clrlo2
1905 clrlo3    calasm    setocp,(temclr)
1906           setlcl    temclr,0
1907           setlcl    kv,0      /* clean up a few things */
1908           setlcl    bufadd,0
1909           setlcl    uaoffs,0
1910           clrlcf    flgwd3,mstclr
1911           retsub
1912 clrbfn    tstlcf    flgwd1,ifrsnd,clrloo /* onput frame  ignore it */
1913           calasm    ocpset,(temclr)
1914           goto      clrloo
1915 busyst    setlcf    flgwd3,mstclr
1916           retsub
1917 temclr    oct       0
1918           rem
1919           rem
1920 ****************************************************************
1921 *
1922 *         outlst - output a message under two different priorty
1923 *         but first dm of lapb may be outputed.
1924 *         if f bit send the following in order:  sarm, cmdr,
1925 *         ua, rnr, rej, and rr. Otherwise the order is disc
1926 *         sarm, cmdr, ua, rnr, rej, i, and rr.
1927 *          Lapb the sarm is sabm and cmdr is frmr. Also polled RR,
1928 *          RNR and REJ are send if so wanted
1929 *
1930 ************************************************************
1931           rem
1932 outlst    tstlcf    flgwd1,xmitsw,retotl /* busy return */
1933           tstlcf    flgwd1,fbit,flst /* f bit required */
1934           tstlcl    flgwd2,0,retotl     /* nothing to do return */
1935           calasm    getopt              /* find something to do
1936 sddnnt    bldmsg    dmmsg,gopunt        /* create the dm message */
1937           outscn    setf,gopunt         /* set f bit */
1938           clrlcf    flgwd2,sndm         /* clear it indicator */
1939           goto      wret      /* write it now */
1940 sdout     bldmsg    dscmsg,gopunt       /* build the disc message */
1941           outscn    setp,gopunt         /* set the p bit */
1942           clrlcf    flgwd2,sndisc       /* clear the flag */
1943           goto      wret      /* write it an d return */
1944 ssout1    bldmsg    srmmsg,gopunt       /* build the sarm message */
1945           outscn    setp,gopunt         /* set the p bit */
1946           clrlcf    flgwd2,snsarm       /* clear the send sarm */
1947           goto      wret      /* write and return */
1948 sbout1    bldmsg    sbmmsg,gopunt       /* build a sabm */
1949           outscn    setp,gopunt         /* set poll bit */
1950           clrlcf    flgwd2,snsabm
1951           goto      wret
1952 scout1    bldmsg    cmdrms,gopunt       /* build the cmdr message */
1953           outscn    setf,gopunt         /* set the f bit */
1954           clrlcf    flgwd2,sncmdr       /* clear the send cmdr flag */
1955           goto      wret      /* write it and return */
1956 sua1      bldmsg    uamsg,gopunt        /* build the ua message */
1957           outscn    setf,gopunt         /* set f bit */
1958           clrlcf    flgwd2,snua         /* clear the ua flag */
1959           goto      wret      /* write it and return */
1960 srnr1     setchr    cfield,null         /* clear cfield */
1961           calsub    outseq    /* setup n.r */
1962           calasm    bldrsp,(rnr)        /* build the rsp message */
1963           bldmsg    rspmsg,gopunt       /* build the actual message */
1964           outscn    setf,gopunt         /* set f bit */
1965           clrlcf    flgwd2,snrnr        /* clear the flag */
1966           goto      wret
1967 srej1     setchr    cfield,null         /* clear cfield */
1968           calsub    outseq    /* set up n.r */
1969           calasm    bldrsp,(rej)        /* build response field */
1970           bldmsg    rspmsg,gopunt       /* build the message */
1971           outscn    setf,gopunt         /* set f bit */
1972           clrlcf    flgwd2,snrej        /* reset the send reject flag */
1973           goto      wret      /* write it and return */
1974 sif1      tstlcl    pstate,lkprrb,ifrett /* no write right now */
1975           tstlcl    pstate,lkprsr,ifrett
1976           tstlcl    pstate,lkupfr,ifrett
1977           tstlcl    pstate,lkuprs,ifrett
1978           tstlcl    sstate,lksccs,ifrett /* no need to confuse the reciver */
1979           tstlcf    flgwd3,mstifr,ifskov /* required to send I-frame */
1980           tstlcf    flgwd3,rtyhld,ifrett /* hold i-frames */
1981 ifskov    clrlcf    flgwd3,mstifr       /* not required any more */
1982           calasm    gtntms    /* get next message on t.ocp */
1983           calasm    tstocp,(0,ifrett)
1984           goto      sif2
1985 ifrett    clrlcf    flgwd2,snifr
1986           goto      outlst    /* continue on for other output */
1987 sif2      setlcl    cfield,null         /* clear cfield */
1988           calasm    bldcfd    /* build cfield */
1989           outscn    setac,gopunt        /* finish control fields */
1990           setlcf    flgwd1,ifrsnd       /* set this for later processing */
1991           clrlcf    flgwd2,snrr         /* no rr needed I-frame will do */
1992           goto      wret      /* output it now */
1993 srr1      setchr    cfield,null         /* clear cfield */
1994           calsub    outseq    /* set up n.r */
1995           calasm    bldrsp,(rr)         /* build the response field */
1996           bldmsg    rspmsg,gopunt       /* build the output message */
1997           outscn    setf,gopunt         /* set finial bit in message */
1998           clrlcf    flgwd2,snrr         /* clear the flag */
1999           goto      wret      /* write it and return *?
2000 sprnr1    setchr    cfield,null         /* set c field to null for building */
2001           calsub    outseq    /* get n.r */
2002           calasm    bldrsp,(rnr)        /* gset in the command */
2003           bldmsg    cmdmsg,gopunt
2004           outscn    setp,gopunt
2005           clrlcf    flgwd2,snprnr
2006           goto      wret
2007 sprej1    setchr    cfield,null         /* clear cfield */
2008           calsub    outseq    /* get n.r :/
2009           calasm    bldrsp,(rej)
2010           bldmsg    cmdmsg,gopunt       /* build the command msg */
2011           outscn    setp,gopunt
2012           clrlcf    flgwd2,snprej
2013           goto      wret
2014 sprr1     setchr    cfield,null         /* clear cfiedl :/
2015           calsub    outseq    /* get n.r */
2016           calasm    bldrsp,(rr)         /* build rr control */
2017           bldmsg    cmdmsg,gopunt
2018           outscn    setp,gopunt
2019           clrlcf    flgwd2,snprr
2020           goto      wret
2021 flst      tstlcf    flgwd2,snsarm,fsout /* send a sarm */
2022           goto      fbout
2023 fsout     bldmsg    srmmsg,gopunt       /* build a sarm message */
2024 ************************************************************
2025 *
2026 *         a condition - the only time a sarm is send prior
2027 *          a final frame, This is done to achive a link up condition
2028 *          in most cases it wouldn't haven.
2029 *
2030 ************************************************************
2031           clrlcf    flgwd2,snsarm       /* clear the sarm flag */
2032 fsabmc    outscn    setp,gopunt         /* set p bit */
2033           calsub    write     /* write the message */
2034           goto      retotl
2035 fbout     tstlcf    flgwd2,snsabm,fbsout
2036           goto      fcout
2037 fbsout    bldmsg    sbmmsg,gopunt
2038           clrlcf    flgwd2,snsabm
2039           goto      fsabmc
2040 fcout     tstlcf    flgwd2,sncmdr,scout1 /* send a cmdr */
2041           tstlcf    flgwd2,snua,sua1 /* send ua */
2042           tstlcf    flgwd2,snrnr,srnr1  /* sned rnr */
2043           tstlcf    flgwd2,snrej,srej1  /* send a reject */
2044           goto      srr1      /* send rr like or not */
2045 wret      calsub    write     /* write the message */
2046           tstlcf    flgwd1,fbit,cfbps /* clear fbit? */
2047           tstlcf    flgwd1,ifrsnd,write2
2048           goto      retotl
2049 write2    tstlcf    flgwd1,timesw,write3 /* timer running */
2050           setlcf    flgwd1,timesw
2051           setimv    t1        /* set timer going */
2052 write3    setlcv    amarg1,v.s          /* add mod 8 to v.s */
2053           setlcl    amarg2,1
2054           calasm    admod8
2055           setlcv    v.s,amarg2
2056           tstlcf    flgwd1,t1rec,write4 /* in timer recovery check xx */
2057           retsub
2058 write4    tstlcv    xx,amarg1,write5
2059           retsub
2060 write5    setlcv    xx,amarg2 /* set xx to next */
2061           retsub
2062 cfbps     clrlcf    flgwd1,fbit         /* clear sending finial bit */
2063           setchr    fmask,null          /* clear mask also */
2064 retotl    retsub
2065           rem
2066           rem
2067 ************************************************************
2068 *
2069 *         fbitck - if f bit on then reset the fbit flags
2070 *
2071 ************************************************************
2072           rem
2073 fbitck    tstlcl    pf,0,fbitc1         /* f bit on */
2074           clrlcf    flgwd1,fbit         /* clear the flags */
2075           clrlcf    flgwd1,pbit
2076           setchr    fmask,null          /* clear the maskes */
2077           setchr    pmask,null
2078           setlcl    pf,0      /* reset the pf flag */
2079 fbitc1    retsub
2080           rem
2081           rem
2082 ************************************************************
2083 *
2084 *         sigotp - signal sndout if kv < kc else return
2085 *
2086 ************************************************************
2087           rem
2088 sigotp    tstlcv    kv,kc,sigret /* equal stop the HOST */
2089           tstlcf    flgwd1,oasw,sigctn /* needed sndout */
2090 sigret    retsub
2091 sigctn    signal    sndout
2092           clrlcf    flgwd1,oasw
2093           retsub
2094           rem
2095           rem
2096 ************************************************************
2097 *
2098 *         cshook - a hook for the send cmdr state into
2099 *          primary for responses
2100 *
2101 ************************************************************
2102           rem
2103 cshook    tstlcf    flgwd1,dcedte,frsrrq
2104           goto      sndcmd
2105           rem
2106           rem
2107 ************************************************************
2108 *
2109 *         ackmsg - acknowledge any I-frames. Delete all
2110 *          messages that have been ack. Reset kv as well
2111 *
2112 ************************************************************
2113           rem
2114 ackmsg    tstlcf    flgwd1,xmitsw,ackms1
2115           goto      ackms3
2116 ackms1    tstlcf    flgwd2,snifr,ackms2
2117           goto      ackms3
2118 ackms2    setlcv    nrv,n.r
2119           setlcf    flgwd1,ackrq
2120           retsub
2121 ackms3    tstlcv    a.r,n.r,akmret      /* any to ack */
2122           calasm    tstocp,(0,ackstr)
2123           calasm    ocpset,(temclr)
2124 ackstr    calasm    setocp,(bufadd)
2125 acklop    calasm    tstocp,(uaoffs,ackclr)
2126           goto      ackst1    /* no - no clear */
2127 ackclr    setlcl    uaoffs,0  /* clear it  next will off the top */
2128 ackst1    dmpout              /* dump one message */
2129           addlcl    kv,-1     /* one less off the chain */
2130           setlcv    amarg1,a.r          /* set up the admod8 to add one to a.r */
2131           setlcl    amarg2,1
2132           calasm    admod8
2133           tstlcf    flgwd1,t1rec,ackms4 /* if t1 recovery test v.s */
2134           goto      ackms6    /* if equal, increment it with a.r */
2135 ackms4    tstlcv    v.s,a.r,ackms5
2136           goto      ackms6
2137 ackms5    setlcv    v.s,amarg2
2138 ackms6    setlcv    a.r,amarg2
2139           tstlcv    a.r,n.r,ackpro      /* finish */
2140           goto      acklop    /* loop again not finish */
2141 ackpro    calasm    ocpset,(bufadd)
2142           calasm    setocp,(temclr)
2143           setlcl    temclr,0  /* clear tempory */
2144           tstlcf    flgwd1,oprusw,akmret /* no scanup if output recieve on bufadd */
2145           calasm    scanup    /* any on unprocess chain */
2146           calsub    sigotp    /* tell HOST if output is ok */
2147 akmret    retsub
2148           rem
2149           rem
2150 ************************************************************
2151 *
2152 *         clrrbb - clear a remote busy or reject mustsetup
2153 *          the next output buffer (set flgwd2,snifr) */
2154 *
2155 ************************************************************
2156           rem
2157 clrrbb    tstlcl    bufadd,0,clrret /* nothing to set up */
2158           setlcf    flgwd2,snifr        /* set  send i-frame */
2159 clrret    retsub
2160           rem
2161           rem
2162 ************************************************************
2163 *
2164 *         rejrst - reject recieve must reset uaoffs
2165 *
2166 ************************************************************
2167           rem
2168 rejrst    setlcl    uaoffs,0  /* top is the next if any */
2169           tstlcl    bufadd,0,rejret     /* nothing to do */
2170           setlcf    flgwd2,snifr        /* set send I-frame */
2171 rejret    retsub
2172           rem
2173           rem
2174 ************************************************************
2175 *
2176 *         outseq - put n(r) into the send frame
2177 *
2178 ************************************************************
2179           rem
2180 outseq    setlcv    outn.r,v.r          /* get current V(R) */
2181           calasm    putn.r    /* put N(R) in control field */
2182           setlcv    a.s,outa.s          /* remember most recent ack sent */
2183           retsub
2184           rem
2185           rem
2186 *****************************************************************
2187 *
2188 *         Subroutine to start transmission of the current output
2189 *         message.
2190 *
2191 *****************************************************************
2192           rem
2193 write     holdot              /* hold the output */
2194           meterm    frmxmt    /* meter this */
2195           setlcf    flgwd1,xmitsw       /* indicate xmit busy */
2196           dcwlst
2197           cmd       sxmit+rtroe
2198           output    (outmsg)
2199           cmd       rxmit+sterm
2200           retsub
2201           rem
2202           ttls      multiply and divide macros
2203 mpy       macro
2204           mpf       #1
2205           lrl       1
2206           endm      mpy
2207           rem
2208           rem
2209 dvd       macro
2210           qls       1
2211           dvf       #1
2212           endm      dvd
2213           ttls      assembler utility subroutines
2214 ************************************************************
2215 *
2216 *         dcdact - subroutine to decode the parameters from the
2217 *          activate control order.
2218 *          Control order format:
2219 *
2220 *         dcl 1 order_format aligned based (addr(stat0)),
2221 *             2 flags,
2222 *               3 dce_or_dte bit (1) unal, /* on = dce */
2223 *               3 lap_or_lapb bit (1) unal, /* on = lapb */
2224 *               3 disc_first bit (1) unal, /* on = disc sent right away */
2225 *               3 trace_off bit (1) unal, /* on = trace off upon crash */
2226 *               3 pad bit (5) unal, /* padding */
2227 *             2 activation_order bit (9) unal init ("001"b), /* constant */
2228 *             2 frame_size fixed bin (17) unal, /* max frame size */
2229 *             2 k fixed bin (8) unal, /* max unack frames */
2230 *             2 N2 uns fixed bin (9) unal, /* number of retries */
2231 *             2 T1 uns fixed bin (9) unal, /* retry time in tents of seconds */
2232 *             2 T3 uns fixed bin (9) unal; /* init timer */
2233 *
2234 *         called with address of opblock to return to if
2235 *          the control order is not activate
2236 *
2237 ************************************************************
2238           rem
2239 dcdact    subr      dcd,(x3)
2240           stx3      t.a000-*  /*save off the parameter */
2241 *
2242 *         check for activate
2243 *
2244           ldx3      l.a000-*  /* =stat0 getr address */
2245           tsy       a.a000-*,* /* = cvaddr in x3 */
2246           lda       0,3       /* got order word */
2247           sta       t.a001-*  /* save it */
2248           ana       l.a001-*  /* =ordmsk mask all but order */
2249           cmpa      l.a002-*  /* =lctact corrent one */
2250           tze       dcd010-*  /* yes go on */
2251 *
2252 *         unwanted order, return as requested
2253 *
2254           ldx3      t.a000-*  /* get address of parm block */
2255           ldx2      0,3       /* return is now in place */
2256           tra       dcdret-*  /* get out */
2257 *
2258 *         set flags and control address
2259 *
2260 dcd010    ldx3      l.a003-*  /* =flgwd1
2261           tsy       a.a000-*,* /* cvaddr */
2262           stz       0,3       /* clear the field */
2263           lda       t.a001-*  /* get back stat0 */
2264           ilq       0
2265           ars       12        /* clear the order :/
2266           icana     =4        /* trace off on crash */
2267           tze       dcd015-*
2268           iaq       =8
2269 dcd015    icana     =8        /* is disc on */
2270           tze       dcd020-*  /* no skip it */
2271           iaq       =4
2272 dcd020    icana     =16       /* is lapb on */
2273           tze       dcd030-*  /* no */
2274           iaq       =1
2275 dcd030    icana     =32       /* is dce on */
2276           tze       dcd040-*  /* no */
2277           iaq       =2        /* set up last flags */
2278           cqa                 /* place it into a */
2279           orsa      0,3       /* or it in */
2280           lda       l.a004-*  /* =locadr */
2281           tsy       a.a001-*,* /* adbyte */
2282           nop
2283           ila       dceadr    /* dec address */
2284           sta       0,3,b.0   /*store it */
2285           lda       l.a005-*  /* =remadr */
2286           tra       dcd050-*  /* common area */
2287           rem
2288 dcd040    cqa                 /* set flgwd1 flags */
2289           orsa      0,3       /* store them */
2290           lda       l.a005-*  /* remadr */
2291           tsy       a.a001-*,*           /* adbyte */
2292           nop
2293           ila       dceadr
2294           sta       0,3,b.0
2295           lda       l.a004-*  /*locadr */
2296           rem
2297 dcd050    tsy       a.a001-*,* /* =adbyte */
2298           nop
2299           ila       dteadr
2300           sta       0,3,b.0   /* flags bit are done */
2301 *
2302 *         now do the stat1 frame size (n1)
2303 *
2304           ldx3      l.a006-*  /* stat1 */
2305           tsy       a.a000-*,* /* =cvaddr */
2306           lda       0,3       /* get stat1 contents */
2307           iaa       7         /* round upward */
2308           ars       3         /* convert to bytes */
2309           caq                 /* get it to q */
2310           ldx3      l.a007-*  /* =mxfrsz max frame size */
2311           tsy       a.a000-*,* /* cvaddr */
2312           stq       0,3       /* save q for max size */
2313 *
2314 *         now do stat2 lower (k) window size
2315 *
2316           ldx3      l.a008-*  /* =stat2 */
2317           tsy       a.a000-*,* /* cvaddr */
2318           lda       0,3       /* get the contance of stat2 */
2319           sta       t.a002-*  /* saft temp storage */
2320           ldx3      l.a009-*  /* =kc unack number of frames */
2321           tsy       a.a000-*,* /* cvaddr :/
2322           lda       t.a002-*  /* retrieve stat2 */
2323           ars       9         /* get only k value */
2324           sta       0,3       /* put it in place */
2325 *
2326 *         upper of stat2 (n2)
2327 *
2328           ldx3      l.a010-*  /* =n2*/
2329           tsy       a.a000-*,* /* cvaddr */
2330           lda       t.a002-*  /* temp storage */
2331           ana       l.a011-*  /* =o000777 */
2332           sta       0,3
2333 *
2334 *         stat3 lower  (t1)
2335 *
2336           ldx3      l.a012-*  /* =stat3 */
2337           tsy       a.a000-*,* /* cvaddr */
2338           ldx2      0,3       /* got contants of stat3 */
2339           stx2      t.a003-*  /* save tempary */
2340           ldx3      l.a013-*  /* =t1 */
2341           tsy       a.a000-*,* /* cvaddr */
2342           cx2a                /* get back stat3*/
2343           arl       9         /* shift out bad bits */
2344           mpy       l.a014-*  /* convert tenths to negative milliseconds */
2345           stq       0,3       /* pu it in place */
2346 *
2347 *         now t3 in stat3
2348 *
2349           ldx3      l.a015-*  /* =t3 */
2350           tsy       a.a000-*,* /* cvaddr */
2351           lda       t.a003-*  /* get back stat3 */
2352           ana       l.a011-*  /* =o000777 */
2353           sta       0,3       /* save t3 */
2354 *
2355 *         all done, set up normal return
2356 *
2357           ila       0
2358           cax2
2359 dcdret    return    dcdact
2360           rem
2361 a.a000    ind       cvaddr
2362 a.a001    ind       adbyte
2363           rem
2364 l.a000    vfd       18/stat0
2365 l.a001    vfd       18/ordmsk
2366 l.a002    vfd       18/lctact
2367 l.a003    vfd       18/flgwd1
2368 l.a004    vfd       18/locadr
2369 l.a005    vfd       18/remadr
2370 l.a006    vfd       18/stat1
2371 l.a007    vfd       18/mxfrsz
2372 l.a008    vfd       18/stat2
2373 l.a009    vfd       18/kc
2374 l.a010    vfd       18/n2
2375 l.a011    oct       000777
2376 l.a012    vfd       18/stat3
2377 l.a013    vfd       18/t1
2378 l.a014    dec       -100
2379 l.a015    vfd       18/t3
2380           rem
2381 t.a000    bss       1         /* temp for parameters */
2382 t.a001    bss       1         /* stat0 tempory */
2383 t.a002    bss       1         /* stat2 tempory */
2384 t.a003    bss       1         /* stat3 tempory */
2385           rem
2386 ********************************************************************************
2387 *
2388 *         cfgpcw - set configuration pcw
2389 *
2390 *         Turns off unwanted bits in the configuration pcw.
2391 *
2392 **********************************************************************************
2393           rem
2394 cfgpcw    subr      cfp,(x3)
2395           rem
2396           lda       l.b000-*  (=tfkpar) get keep parity bit
2397           orsa      t.flg3,1  turn it on in the tib
2398           rem
2399           ldx3      t.sfcm,1  get addr of sfcm
2400           lda       l.b001-*  (=777704) get mask for word 1 of pcw
2401           ansa      sf.cfg,3  leave only wanted bits on in word 1 of pcw
2402           stz       sf.cfg+1,3          zero word 2 of pcw
2403           rem
2404           return    cfgpcw
2405 l.b000    vfd       18/tfkpar
2406 l.b001    oct       777704
2407           rem
2408           rem
2409 ************************************************************
2410 *
2411 *         valfrm - validate input frame - check for bad address,
2412 *          test for proper length, test for known commands,set
2413 *          calues - lastf and frmadr-, check for pand f bits
2414 *          for propper conditions, also test n(s) and n(r) in
2415 *          all messages
2416 *
2417 *         no arguments  (nornal usages a = controlfield q = function
2418 *
2419 ************************************************************
2420           rem
2421 valfrm    subr      vfm,(x1)
2422           stz       cmdrln-*            "zero length problem
2423           stz       a.c000-*,* /* =pf clear finial test data */
2424           lda       t.icp,1   /* get input buffer */
2425           tze       vfmree-*  /* nothing to do */
2426           tsy       a.c001-*,* /* =setbpt 18 - 15 bit address */
2427           cax2
2428           tsy       a.c002-*,* /* =gtbfsz get buffer data size */
2429           lda       a.c003-*,* /* = vfmsiz load a with size */
2430           icmpa     2         /* at least two bytes */
2431           tmi       vfmree-*  /* no not enought */
2432           iacx2     bf.dta    /* get data address */
2433           lda       0,2       /* get address fields */
2434           arl       9         /* clear all other fields */
2435           icmpa     1         /* dte pri */
2436           tze       vfm000-*  /* good */
2437           icmpa     3         /* dce pri */
2438           tnz       vfmree-*  /* bad address */
2439 vfm000    sta       q.save-*  /* save foeld tempory */
2440           lda       l.c000-*  /* =frmadr */
2441           tsy       a.c004-*,* /* =adbyte */
2442           oct       0         /* die on this error */
2443           ldq       q.save-*  /* bet back address fields */
2444           stq       0,3,b.0   /* store it in t.elnk */
2445           lda       0,2       /* get control field now */
2446           als       9         /* get rid of address fields */
2447           arl       9         /* control field is only thing left */
2448           icana     =o1       /* is it an i-frame */
2449           tze       iframp-*  /* yes */
2450           caq                 /* save it in q */
2451           arl       1         /* sift 1 */
2452           iana      7         /* mask out other bits */
2453           cax3                /* save in x3 */
2454           cqa
2455           tra       a.c010-*,* /* find what connamd it is */
2456 vfm020    tra       rrp-*     /* 000 rr frame */
2457           tra       dsuap-*   /* 001 either disc, ua, or bad frame */
2458           tra       rnrp-*    /* 010 rnr frame */
2459           tra       cmdrp-*   /* 011 cmdr or bad frame */
2460           tra       rejp-*    /* 100 rej frame */
2461           tra       bdcrp-*   /* 101 bad command */
2462           tra       bdcrp-*   /* 110 bad command */
2463           tra       sbrdmp-*  /* 111 dm, sarm, sabm, or bad command *]/
2464 bdcrp     ilq       rvbdcr    /* set function to bad command */
2465           tra       vfmret-*  /* return */
2466 cmdrp     ilq       rvcmdr    /* cmdr processing */
2467           icana     =o340     /* first is it cmdr */
2468           tze       bdcrp-*   /* no it isn't */
2469           icana     =o140
2470           tze       2         /* it is cmdr now */
2471           tra       bdcrp-*
2472           lda       1,2       "get cmdr cmd field
2473           ars       9         "get field in position
2474           icana     =o1       "is it and I-frame
2475           tnz       cmdrpc-*  "no
2476           lda       2,2       "get cmdr flags fields
2477           ars       9         "get field in to position
2478           icana     =o4       "is Y bit set
2479           tze       cmdrpc-*  "no
2480           aos       cmdrln-*  "indicate a problem
2481           ldx3      l.c003-*  "=stat1
2482           tsy       a.c009-*,* "cvaddr
2483           lda       1,2       "reject byte and state var
2484           sta       0,3       "stat1 field
2485           lda       2,2       "flags and zeros
2486           sta       1,3       "stat2
2487           stz       2,3       "stat3
2488 cmdrpc    lda       a.c003-*,* /* gtbfsz */
2489           icmpa     5         /* check for proprer frame size */
2490           tze       vfm030-*  /* good length */
2491           aos       a.c005-*,* /* bdlgsz */
2492           tra       bdcrp-*
2493 vfm030    null
2494 rspfck    tsy       checkr-*  /* check for response address */
2495           tra       vfmret-*  /* no respose */
2496           tsy       checkf-*  /* check f bit */
2497           tra       vfmret-*
2498           tra       vfmret-*  /* done */
2499 uap       ilq       rvua      /* function ua */
2500           lda       a.c003-*,* /*gtbfsz message size */
2501           icmpa     2         /* only two bytes */
2502           tze       rspfck-*
2503           aos       a.c005-*,*
2504           tra       bdcrp-*
2505 discp     ilq       rvdisc    /* function disc */
2506           lda       a.c003-*,* /* vfmsiz */
2507           icmpa     2         /* two bytes */
2508           tze       vfm040-*
2509           aos       a.c005-*,*
2510           tra       bdcrp-*
2511 vfm040    tsy       checkc-*  /* check for command */
2512           tra       vfmret-*
2513           tsy       checkp-*  /* check p bit */
2514           nop
2515           tra       vfmret-*
2516 sarmp     ilq       rvsarm    /* function sarm */
2517           lda       a.c003-*,* /* message size vfmsiz */
2518           icmpa     2         /* only two bytes */
2519           tze       vfm050-*
2520           aos       a.c005-*,*
2521           tra       bdcrp-*
2522 vfm050    tsy       checkc-*  /* check for command */
2523           tra       dmp-*     /* response then it a dm on lapb */
2524           tsy       checkp-*  /* check p bit */
2525           tra       vfmret-*
2526           tra       vfmret-*
2527 rrp       ilq       rvrr      /* function  rr */
2528           ila       rvprr     /* may be p rr */
2529 rpros     sta       polcmd-*
2530           tsy       checkr-*  /* check for response */
2531           tra       prespc-*  /* polled command */
2532           tsy       checkf-*  /* f bit processing */
2533           tra       vfmret-*
2534 rpcomp    tsy       a.c006-*,* /* chknr */
2535           tra       vfmret-*
2536           lda       a.c003-*,* /* vfmsiz */
2537           icmpa     2         /* two bytes only */
2538           tze       vfmret-*
2539           aos       a.c005-*,* /* bad length */
2540           tra       bdcrp-*
2541 rnrp      ilq       rvrnr     /* rnr = function */
2542           ila       rvprnr
2543           tra       rpros-*
2544 rejp      ilq       rvrej     /* rej = function */
2545           ila       rvprej
2546           tra       rpros-*
2547 prespc    tsy       checkp-*  /* check for polled bit */
2548           tra       bdcrp-*
2549           ldq       polcmd-*  /* set function to poll command function */
2550           tra       rpcomp-*
2551 iframp    ilq       rvifrm    /* i-frame processing */
2552           tsy       checkc-*
2553           tra       vfmret-*
2554           tsy       checkp-*
2555           nop
2556           tsy       a.c007-*,* /* checnr */
2557           tra       vfmret-*
2558           tsy       a.c008-*,* /* checnr */
2559           tra       vfmret-*
2560           ldq       a.c003-*,* /* vfmsiz */
2561           ldx3      l.c002-*  /* mxfrsz */
2562           tsy       a.c009-*,* /* cvaddr */
2563           cmpq      0,3       /* compare to max size */
2564           tze       vfm055-*  /* equal is allright */
2565           tpl       vfmbif-*
2566 vfm055    ilq       rvifrm
2567           tra       vfmret-*
2568 vfmbif    aos       a.c005-*,* /* bad info length */
2569           tra       bdcrp-*
2570 dsuap     icana     =o200     /* any 1xx */
2571           tnz       bdcrp-*   /* yes bad command */
2572           icana     =o340     /*  any 000 */
2573           tze       bdcrp-*   /* yes it is also bad */
2574           icana     =o240
2575           tze       discp-*   /* disc command */
2576           icana     =o300     /* misc bit check */
2577           tze       bdcrp-*   /* bad command */
2578           tra       uap-*     /* ua command */
2579 sbrdmp    icana     =o340
2580           tze       sarmp-*   /* sarm command */
2581           icana     =o300
2582           tnz       bdcrp-* /* not 001 */
2583           ilq       rvsabm    /* sabm function */
2584           lda       a.c003-*,* /* vfmsiz */
2585           icmpa     2         /* two bytes */
2586           tze       vfm070-*
2587           aos       a.c005-*,* /* bad message length */
2588           tra       bdcrp-*
2589 vfm070    tsy       checkc-*
2590           tra       vfmret-*
2591           tsy       checkp-*
2592           tra       vfmret-*
2593           tra       vfmret-*
2594 dmp       ilq       rvdm      /* dm recieve */
2595           tra       vfmret-*
2596 vfmree    ilq       rvbdad    /* function of nothing */
2597 vfmret    ila       0         /* set to return by clearing x2 */
2598           cax2
2599           ldx3      l.c001-*  /* lastf */
2600           tsy       a.c009-*,* /* cvaddr */
2601           stq       0,3
2602           return    valfrm
2603           rem
2604           rem
2605 q.save    bss       1
2606 polcmd    bss       1
2607 cmdrln    bss       1
2608           rem
2609 a.c000    ind       pf
2610 a.c001    ind       setbpt
2611 a.c002    ind       gtbfsz
2612 a.c003    ind       vfmsiz
2613 a.c004    ind       adbyte
2614 a.c005    ind       bdlgsz
2615 a.c006    ind       chknr
2616 a.c007    ind       checnr
2617 a.c008    ind       checns
2618 a.c009    ind       cvaddr
2619 a.c010    ind       vfm020,3
2620           rem
2621 l.c000    vfd       18/frmadr
2622 l.c001    vfd       18/lastf
2623 l.c002    vfd       18/mxfrsz
2624 l.c003    vfd       18/stat1
2625           rem
2626           rem
2627 ************************************************************
2628 *
2629 *         checkr - check response to address
2630 *
2631 ************************************************************
2632           rem
2633 checkr    subr      ckr,(a,q,x2,x3)
2634           lda       0,2       /* get control address again */
2635           arl       9         /* only address is needed */
2636           cax2
2637           lda       l.d001-*  /* remadr */
2638           tsy       a.d000-*,* /* adbyte */
2639           oct       0
2640           cmpx2     0,3,b.0   /* compare address */
2641           tnz       ckrree-*  /* no compare */
2642           aos       checkr-*
2643           tra       ckrret-*
2644 ckrree    ilq       rvbdcr    /* bad command */
2645           stq       ckrsq-*
2646 ckrret    return    checkr
2647           rem
2648           rem
2649 ************************************************************
2650 *
2651 *         checkc - check for command address
2652 *
2653 ************************************************************
2654           rem
2655 checkc    subr      chc,(a,q,x2,x3)
2656           lda       0,2       /* get address byte */
2657           arl       9         /* only address is needed */
2658           cax2
2659           lda       l.d002-*  /* locadr */
2660           tsy       a.d000-*,* /* adbyte */
2661           oct       0
2662           cmpx2     0,3,b.0   /* are they equal */
2663           tnz       ckcree-*
2664           aos       checkc-*
2665           tra       ckcret-*
2666 ckcree    ilq       rvbdcr    /* bad command */
2667           stq       chcsq-*
2668 ckcret    return    checkc
2669           rem
2670 l.d001    vfd       18/remadr
2671 l.d002    vfd       18/locadr
2672 a.d000    ind       adbyte
2673           rem
2674           rem
2675 ************************************************************
2676 *
2677 *         checkf - check f bit for validate response frames
2678 *
2679 ************************************************************
2680           rem
2681 checkf    subr      chf,(a,q,x3)
2682           lda       0,2       /* get back controls fields */
2683           als       9         /* only control bit needed */
2684           arl       9
2685           sta       chfsa-*
2686           stz       pf-*
2687           ana       l.e000-*  /*fbit position */
2688           sta       fchtmp-*  /* save it tempory */
2689           lda       l.e001-*  /* pbit pmask */
2690           tsy       a.e000-*,* /* adbyte */
2691           oct       0
2692           lda       fchtmp-*  /* get orgin value back */
2693           cmpa      0,3,b.0   /* compare if f bit is on */
2694           tnz       chf010-*  /* not equal */
2695           aos       checkf-*  /* normal return */
2696           szn       fchtmp-*  /* is it zero */
2697           tze       chfret-*  /* yes it is */
2698           aos       pf-*
2699 chfret    return    checkf
2700 chf010    ilq       rvbdfb    /* it a bad command */
2701           stq       chfsq-*   /* save for q reg restore */
2702           tra       chfret-*
2703           rem
2704 pf        bss       1
2705           rem
2706           rem
2707 ************************************************************
2708 *
2709 *         checkp - check poll bit if on set needed fbit
2710 *
2711 ************************************************************
2712           rem
2713 checkp    subr      chp,(a,q,x3)
2714           lda       0,2       /* get back controls fields */
2715           als       9         /* only control bits needed */
2716           arl       9
2717           sta       chpsa-*
2718           cana      l.e000-*  /* pfon */
2719           tze       chpret-*  /* nothing */
2720           aos       checkp-*  /* normal return */
2721           lda       l.e003-*  /* fmask */
2722           tsy       a.e000-*,* /* adbyte */
2723           oct       0
2724           lda       l.e000-*  /* pfon */
2725           orsa      0,3,b.0   /* or the bit in */
2726           ldx3      l.e004-*  /* flgwd1 */
2727           tsy       a.e001-*,* /* cvaddr */
2728           lda       l.e005-*  /* fbit */
2729           orsa      0,3
2730 chpret    return    checkp
2731           rem
2732 a.e000    ind       adbyte
2733 a.e001    ind       cvaddr
2734           rem
2735 l.e000    vfd       18/pfon
2736 l.e001    vfd       18/pmask
2737 *l.e002   unused
2738 l.e003    vfd       18/fmask
2739 l.e004    vfd       18/flgwd1
2740 l.e005    vfd       18/fbit
2741           rem
2742 fchtmp    bss       1
2743           rem
2744           rem
2745 ************************************************************
2746 *
2747 *         chknr - check nr for response frames, if out of
2748 *          range then it  is a error, else normal return
2749 *
2750 ************************************************************
2751           rem
2752 chknr     subr      chk,(a,x3)
2753           stz       bnr-*
2754           ana       l.f006-*  /* o=340 n.r mask */
2755           arl       5         /* shift it to proper place */
2756           sta       middle-*  /*let hope it is the middle */
2757           sta       n.r-*     /* storage for later uses */
2758           ldx3      l.f000-*  /* a.r */
2759           tsy       a.f000-*,* /* cvaddr */
2760           lda       0,3       /*get a.r */
2761           sta       low-*
2762           ldx3      l.f001-*  /* flgwd1 */
2763           tsy       a.f000-*,* /* cvaddr */
2764           lda       0,3
2765           ana       l.f002-*  /* mask all but t1rec */
2766           tze       chk010-*
2767           ldx3      l.f003-*  /* xx */
2768           tsy       a.f000-*,* /* cvaddr */
2769           tra       chk020-*
2770 chk010    ldx3      l.f004-*  /* v.s */
2771           tsy       a.f000-*,* /* cvaddr */
2772 chk020    lda       0,3
2773           sta       high-*
2774           tsy       chkrng-*
2775           szn       badrng-*
2776           tze       chk030-*
2777           ilq       rvbdcr    /* bad command +?
2778           aos       bnr-*
2779           tra       chkret-*
2780 chk030    aos       chknr-*
2781 chkret    return    chknr
2782           rem
2783 n.r       bss       1
2784 bnr       bss       1
2785           rem
2786           rem
2787 ************************************************************
2788 *
2789 *         checnr - check nr on i-frames
2790 *
2791 ************************************************************
2792           rem
2793 checnr    subr      chr,(a,x3)
2794           tsy       chknr-*   /* he'll do the work */
2795           tra       chr010-*
2796           tra       chr020-*
2797 chr010    ilq       rvbdir    /* bad N(r) I-frame  */
2798           tra       chrret-*
2799 chr020    aos       checnr-*
2800 chrret    return    checnr
2801           rem
2802           rem
2803 ************************************************************
2804 *
2805 *         checns - check n.s on i-frames
2806 *
2807 ************************************************************
2808           rem
2809 checns    subr      chs,(a,x3)
2810           iana      =o16      /* mask all but n.s */
2811           arl       1         /* shift by one */
2812           cax2
2813           ldx3      l.f005-*  /* v.r */
2814           tsy       a.f000-*,* /* cvaddr */
2815           cmpx2     0,3       /* must be equal */
2816           tze       chs010-*
2817           ilq       rvbdis    /* bad i-frame n.s */
2818           tra       chsret-*
2819 chs010    aos       checns-*
2820 chsret    return    checns
2821           rem
2822 a.f000    ind       cvaddr
2823           rem
2824 l.f000    vfd       18/a.r
2825 l.f001    vfd       18/flgwd1
2826 l.f002    vfd       18/t1rec
2827 l.f003    vfd       18/xx
2828 l.f004    vfd       18/v.s
2829 l.f005    vfd       18/v.r
2830 l.f006    oct       000340
2831           rem
2832           rem
2833 ************************************************************
2834 *
2835 *         chkrng - check range to check if midle is middle
2836 *          on mod 8 arith.
2837 *
2838 ************************************************************
2839           rem
2840 chkrng    subr      ckg
2841           lda       high-*    /* get upper bound */
2842           cmpa      low-*     /* hi < low */
2843           tpl       ckg010-*  /*no */
2844           ila       8         /* get modulus */
2845           asa       high-*    /* advance upper bound */
2846           lda       middle-*  /* get middle */
2847           cmpa      low-*     /* middle < low */
2848           tpl       ckg010-*  /* no */
2849           ila       8         /* get modulus */
2850           asa       middle-*  advance middle
2851           rem
2852 ckg010    ila       1
2853           sta       badrng-*  assume out of range */
2854           lda       middle-*  /* get middl */
2855           cmpa      low-*     /* less than lower bound */
2856           tmi       ckgret-*  /* yes it is bad */
2857           lda       high-*    /* get upper bound */
2858           cmpa      middle-*  /* less than middle */
2859           tmi       ckgret-*  /* yes error */
2860           rem
2861           stz       badrng-*
2862 ckgret    return    chkrng
2863           rem
2864 high      bss       1
2865 low       bss       1
2866 middle    bss       1
2867 badrng    bss       1
2868           rem
2869           rem
2870 ************************************************************
2871 *
2872 *         blfcdr - build command reject fields
2873 *
2874 ************************************************************
2875           rem
2876 blfcdr    subr      blc
2877           lda       t.icp,1   /* get pointer  to input message */
2878           tsy       a.g000-*,* /* setbpe */
2879           iaa       bf.dta    /* get buffer data offset */
2880           cax2
2881           ldq       0,2       get control field */
2882           qls       9         /* clean it up to have only control */
2883           qrl       9
2884           stq       qrsave-*  /* save it tempory */
2885           lda       l.g000-*  /* cmdr1 */
2886           tsy       a.g001-*,* /* adbyte */
2887           oct       0
2888           lda       0,3,b.0   /* get it info */
2889           tnz       blcret-*  /* sonething is already there */
2890           ldq       qrsave-*
2891           stq       0,3,b.0   /* put it in place */
2892           ldx3      l.g003-*  /* v.r */
2893           tsy       a.g002-*,* /* cvaddr */
2894           lda       0,3
2895           als       6         /* place in proper location */
2896           sta       qrsave-*
2897           lda       l.g001-*  /* cmdr2 */
2898           tsy       a.g001-*,* /* adbyte */
2899           oct       0
2900           ldq       qrsave-*
2901           stq       0,3,b.0
2902           szn       a.g003-*,* /* dblgsz */
2903           tze       blc010-*
2904           ilq       3         /*set w and x */
2905           lda       0,2
2906           icana     =01
2907           tze       2
2908           tra       blc020-*
2909           ilq       5         /* set w and y */
2910           tra       blc020-*
2911 blc010    szn       bnr-*
2912           tze       blc015-*
2913           ilq       =o10
2914           tra       blc020-*
2915 blc015    ilq       1         /* just w */
2916 blc020    stq       qrsave-*
2917           lda       l.g002-*  /* cmdr3 */
2918           tsy       a.g001-*,* /* adbyte */
2919           oct       0
2920           ldq       qrsave-*
2921           stq       0,3,b.0
2922 blcret    ila       0
2923           stz       bnr-*
2924           cax2
2925           return    blfcdr
2926           rem
2927 a.g000    ind       setbpt
2928 a.g001    ind       adbyte
2929 a.g002    ind       cvaddr
2930 a.g003    ind       bdlgsz
2931           rem
2932 l.g000    vfd       18/cmdrb1
2933 l.g001    vfd       18/cmdrb2
2934 l.g002    vfd       18/cmdrb3
2935 l.g003    vfd       18/v.r
2936 l.g004    vfd       18/v.s
2937           rem
2938           rem
2939 ************************************************************
2940 *
2941 *         ldnsdr - load ns into frmr for lapb reject
2942 *
2943 ************************************************************
2944           rem
2945 ldnsdr    subr      ldn,(x3)
2946           ldx3      l.g004-*  /*v.s */
2947           tsy       a.g002-*,* /* cvaddr */
2948           lda       0,3
2949           als       1
2950           sta       qrsave-*
2951           lda       l.g001-*  /* cmdrb2 */
2952           tsy       a.g001-*,* /* adbyte */
2953           oct       0
2954           lda       0,3,b.0
2955           ora       qrsave-*
2956           sta       0,3,b.0
2957           ila       0
2958           cax2
2959           return    ldnsdr
2960 qrsave    bss       1
2961           rem
2962           rem
2963 ************************************************************
2964 *
2965 *         ckrnr - check rnr needed
2966 *
2967 *         determines whether a rnr response is appropriate due to
2968 *         either of the following conditions:
2969 *
2970 *         1.  the total number of free buffers is less that the
2971 *         sum of the reserved buffer count plus twice the channel
2972 *         buffer size.
2973 *
2974 *         2.  two or more frames belonging to this channel are already
2975 *         queued for dia transfer.
2976 *
2977 ************************************************************
2978           rem
2979 ckrnr     subr      rnr,(x3)
2980           tsy       cntqf-*   /* count queued frames */
2981           lda       cqfcnt-*  /*get count */
2982           cmpa      l.h001-*  /* =dialim over limit */
2983           tpl       rnr030-*  /*yes, rnr required */
2984           rem
2985           stz       rnrflg-*
2986           tra       rnrret-*
2987           rem
2988 rnr030    ila       1
2989           sta       rnrflg-*  /* indicate rnr required */
2990           rem
2991 rnrret    return    ckrnr
2992           rem
2993 rnrflg    bss       1
2994 a.h000    ind       setbpt
2995           rem
2996 l.h000    vfd       18/bffbrk
2997 l.h001    vfd       18/dialim
2998           rem
2999           rem
3000 ************************************************************
3001 *
3002 *         cntqf - count queued frames
3003 *
3004 *         a subroutine to count the number of frames on the dia
3005 *         queue. (count only the i-frames)
3006 *
3007 ************************************************************
3008           rem
3009 cntqf     subr      cqf,(x3)
3010           stz       cqfcnt-*  /* start count at zero */
3011           lda       t.dcp,1   /* get start of dia queue */
3012           tze       cqf030-*  /* end of queue */
3013 cqf010    tsy       a.h000-*,* /* setbpe */
3014           cax3
3015           lda       bf.flg,3  /* look at buffer flags */
3016           cana      l.h000-*  /* =bffbrk */
3017           tze       cqf020-*
3018           aos       cqfcnt-*  /* yes, count another frame */
3019 cqf020    lda       bf.nxt,3  /* follow the chain */
3020           tnz       cqf010-*  /* if not the end */
3021 cqf030    return    cntqf
3022           rem
3023 cqfcnt    bss       1
3024           rem
3025           rem
3026 ************************************************************
3027 *
3028 *         admod8 - add modulo 8
3029 *
3030 ************************************************************
3031           rem
3032 admod8    subr      am8
3033           lda       amarg1-*  /* get arg 1 */
3034           asa       amarg2-*  /* add to arg 2 */
3035           lda       l.i000-*  /* =o000007 get mod 8 mask */
3036           ansa      amarg2-*  /* convert arg 2 to mod 8 */
3037           rem
3038           return    admod8
3039           rem
3040 amarg1    bss       1
3041 amarg2    bss       1
3042 l.i000    oct       000007
3043           rem
3044           rem
3045 ************************************************************
3046 *
3047 *         setbrk - set break flag in last buffer
3048 *
3049 ************************************************************
3050           rem
3051 setbrk    subr      sbk,(x3)
3052           lda       t.icp,1   /* get buffer address */
3053 sbk010    tsy       a.j000-*,* /* convert address to 15 bits */
3054           cax3                /* place address in index reg */
3055           szn       bf.nxt,3  /* is next zero */
3056           tze       sbk020-*  /* yes location found */
3057           lda       bf.nxt,3  /* get ready for follow the chain */
3058           tra       sbk010-*  /* follow it */
3059 sbk020    lda       l.j000-*  /* bffbrk flag */
3060           orsa      bf.flg,3  /* set it on */
3061           return    setbrk
3062           rem
3063           rem
3064 ************************************************************
3065 *
3066 *         gtbfsz- get buffer size. add all the buffers
3067 *          in the input chain and place it in vfmsiz
3068 *
3069 ************************************************************
3070           rem
3071 gtbfsz    subr      gtb,(x3)
3072           stz       vfmsiz-*  /* clear tally  */
3073           stz       bdlgsz-*  /* clear check */
3074           lda       t.icp,1   /* get input buffer */
3075 gtb010    tsy       a.j000-*,* /* setbpt */
3076           cax3
3077           lda       bf.tly,3  /* get the tally */
3078           ana       l.j002-*  /* bfmsk tally mask */
3079           asa       vfmsiz-*  /* add to storage */
3080           szn       bf.nxt,3  /* is next zero */
3081           tze       gtb020-*  /* yes finish */
3082           lda       bf.nxt,3  /* get next buffer */
3083           tra       gtb010-*  /* loop again */
3084 gtb020    lda       t.icp,1   /* get back  to orginal */
3085           tsy       a.j000-*,* /* setbpt */
3086           return    gtbfsz
3087           rem
3088 a.j000    ind       setbpt
3089           rem
3090 l.j000    vfd       18/bffbrk
3091 l.j001    vfd       18/bfflst
3092 l.j002    vfd       18/buftmk
3093           rem
3094 vfmsiz    bss       1
3095 bdlgsz    bss       1
3096           rem
3097           rem
3098 ************************************************************
3099 *
3100 *         addbte - add buffer to end of output chain
3101 *
3102 ************************************************************
3103           rem
3104 addbte    subr      adb,(x3)
3105           ldx3      l.k000-*  /* buffadd */
3106           tsy       a.k000-*,* /* cvaddr */
3107           lda       0,3       /* get buffer into regs */
3108           tnz       adb010-*  /* no more searching */
3109           lda       temups-*  /* get new buffer chain */
3110           sta       0,3       /* place it at the head */
3111           tra       adbret-*  /* that is all */
3112 adb010    tsy       a.k001-*,* /* convert 18 to 15 setbpt */
3113           cax3
3114           lda       bf.nxt,3  /* get next buffer */
3115           tze       adb020-*  /* no more add it here */
3116           tra       adb010-*  /* loop for end */
3117 adb020    lda       temups-*  /* get new chain */
3118           sta       bf.nxt,3  /* put in proper place */
3119 adbret    return    addbte
3120           rem
3121           rem
3122 ************************************************************
3123 *         bldrsp- build response command in cfield
3124 *
3125 ************************************************************
3126           rem
3127 bldrsp    subr      brp,(x3)
3128           lda       l.k001-*  /* cfield */
3129           tsy       a.k002-*,* /* adbyte */
3130           oct       0
3131           ldx2      brpsx3-*  /* get type of message address */
3132           lda       0,2       /* get response bits */
3133           orsa      0,3,b.0   /* or it into cfield */
3134           ila       0
3135           cax2
3136           return    bldrsp
3137           rem
3138 a.k000    ind       cvaddr
3139 a.k001    ind       setbpt
3140 a.k002    ind       adbyte
3141           rem
3142 l.k000    vfd       18/bufadd
3143 l.k001    vfd       18/cfield
3144 l.k002    vfd       18/kv
3145           rem
3146           rem
3147 ************************************************************
3148 *
3149 *         gtntms - get next message to send
3150 *
3151 ************************************************************
3152           rem
3153 gtntms    subr      gtn,(x3)
3154           ldx3      l.l000-*  /* uaoffs */
3155           tsy       a.l000-*,* /* cvaddr */
3156           cx3a
3157           cax2
3158           lda       0,3       /* get it buffer pointer address */
3159           tnz       gtn010-*  /* must loop down to end of message */
3160           ldx3      l.l001-*  /* bufadd */
3161           tsy       a.l000-*,* /* cvaddr */
3162           lda       0,3       /* get top message */
3163           sta       0,2       /* place it on uaoffs */
3164           tra       gtnret-*  /* common return */
3165 gtn010    tsy       a.l001-*,* /* setbpt */
3166           cax3
3167           lda       bf.flg,3  /* get buffer flags */
3168           ana       l.l002-*  /* bfflst */
3169           tnz       gtn020-*  /* finish this is next */
3170           lda       bf.nxt,3  /* get next message chain pointer */
3171           tze       gtnret-*  /* finish no more don`'t set uaoffs */
3172           tra       gtn010-*  /* loop again */
3173 gtn020    lda       bf.nxt,3  /* get next buffer */
3174           tze       gtnret-*  /* nothing there don't set uaoffs */
3175           sta       0,2       /* set uaoffs to head of message chain */
3176 gtnret    sta       t.ocp,1   /*  store next in output */
3177           stz       t.ocur,1
3178           stz       t.olst,1
3179           ila       0
3180           cax2
3181           return    gtntms
3182           rem
3183           rem
3184 ************************************************************
3185 *
3186 *         bldcfd - build command field for this i-frame
3187 *
3188 ************************************************************
3189           rem
3190 bldcfd    subr      bcd,(x3)
3191           lda       l.l003-*  /* cfield */
3192           tsy       a.l002-*,* /* adbyte */
3193           oct       0
3194           stz       0,3,b.0   /* clear cfield */
3195           cx3a
3196           cax2
3197           ldx3      l.l004-*  /* v.s */
3198           tsy       a.l000-*,* /* cvaddr */
3199           lda       0,3       /* v.s in a +?
3200           als       1         /* shift v.s to proper spot */
3201           sta       0,2,b.0   /* store it in cfield */
3202           ldx3      l.l005-*  /* v.r */
3203           tsy       a.l000-*,* /* cvaddr */
3204           lda       0,3
3205           sta       outn.r-*
3206           tsy       putn.r-*
3207           ldx2      outa.s-*  /* also remiber last ack */
3208           ldx3      l.l012-*  /* a.s */
3209           tsy       a.l000-*,* /* cvaddr */
3210           stx2      0,3
3211           ila       0
3212           cax2
3213           return    bldcfd
3214           rem
3215           rem
3216 ************************************************************
3217 *
3218 *         putn.r - put n(r) in to cfield
3219 *
3220 *          a subroutine to put the current n(r) value in the control
3221 *         field of the next output frame.
3222 *
3223 ************************************************************
3224           rem
3225 putn.r    subr      pnr,(q,x3)
3226           lda       outn.r-*  get n.r */
3227           ana       l.l006-*  /* 000007 */
3228           sta       outa.s-*  /* save for caller */
3229           als       5         /* shift into proper byte position +?
3230           sta       pnrtmp-*  /* save it in temp */
3231           lda       l.l003-*  /* cfield */
3232           tsy       a.l002-*,* /* adbyte */
3233           oct       0
3234           lda       0,3,b.0   /* get value of cfield */
3235           ora       pnrtmp-*  /* drop in n.r */
3236           sta       0,3,b.0   /* update cfield */
3237           return    putn.r    /* that is all folks */
3238           rem
3239 outn.r    bss       1
3240 outa.s    bss       1
3241 pnrtmp    bss       1
3242           rem
3243 a.l000    ind       cvaddr
3244 a.l001    ind       setbpt
3245 a.l002    ind       adbyte
3246           rem
3247 l.l000    vfd       18/uaoffs
3248 l.l001    vfd       18/bufadd
3249 l.l002    vfd       18/bfflst
3250 l.l003    vfd       18/cfield
3251 l.l004    vfd       18/v.s
3252 l.l005    vfd       18/v.r
3253 l.l006    oct       000007
3254 l.l007    vfd       18/stat2
3255 l.l008    oct       000777
3256 l.l009    vfd       18/lkupws
3257 l.l010    vfd       18/stat3
3258 l.l011    vfd       18/pstate
3259 l.l012    vfd       18/a.s
3260           rem
3261           rem
3262 ************************************************************
3263 *
3264 *         setust - set up link down status of word stat2 and
3265 *          stat3
3266 *
3267 ************************************************************
3268           rem
3269 setust    subr      sut,(x3)
3270           ldx3      l.l007-*  /* stat2 */
3271           tsy       a.l000-*,* /* cvaddr */
3272           lda       l.l008-*  /* o000777 */
3273           ansa      0,3       /* mask out upper half */
3274           cx3a
3275           cax2
3276           ldx3      l.l009-*  /* lkupws */
3277           tsy       a.l000-*,* /* cvaddr */
3278           lda       0,3       /* get data */
3279           als       9         /* place is upper position */
3280           orsa      0,2       /* store it */
3281           ldx3      l.l010-*  /* stat3 */
3282           tsy       a.l000-*,* /* cvaddr */
3283           lda       l.l008-*  /* o000777 */
3284           ansa      0,3
3285           cx3a
3286           cax2
3287           ldx3      l.l011-*  /* pstate */
3288           tsy       a.l000-*,* /* cvaddr */
3289           lda       0,3
3290           als       9
3291           orsa      0,2
3292           ila       0
3293           cax2
3294           return    setust
3295           rem
3296           rem
3297 ************************************************************
3298 *
3299 *         scpbst - scan process chain for unprocess messages
3300 *          and break chain on set address in temups
3301 *
3302 ************************************************************
3303           rem
3304 scpbst    subr      scp,(x3)
3305           ldx3      l.n000-*  /* =bufadd
3306           tsy       a.n000-*,* /* cvaddr */
3307           lda       0,3
3308           sta       fbufmg-*
3309           stz       fbufng-*  /* head of queue check */
3310           tze       scpret-*
3311 scp010    caq
3312           tsy       a.n001-*,* /* setbpt */
3313           cax3
3314           lda       bf.flg,3
3315           cana      l.n001-*  /* bfflst */
3316           tnz       scp020-*  /* last message flag */
3317           lda       bf.nxt,3
3318           tze       scp030-*  /* no more */
3319           tra       scp010-*
3320 scp020    aos       fbufng-*
3321           lda       bf.nxt,3
3322           tze       scpret-*
3323           stq       fbufmg-*
3324           tra       scp010-*
3325 scp030    lda       fbufmg-*
3326           szn       fbufng-*
3327           tze       scp040-*
3328           tsy       a.n001-*,* /* setbpe */
3329           cax3
3330           ldq       bf.nxt,3
3331           stz       bf.nxt,3
3332           stq       temups-*
3333           tra       scpret-*
3334 scp040    sta       temups-*
3335           ldx3      l.n000-*  /* bufadd */
3336           tsy       a.n000-*,* /* cvaddr */
3337           stz       0,3
3338 scpret    ila       0
3339           cax2
3340           return    scpbst
3341           rem
3342           rem
3343 ************************************************************
3344 *
3345 *         scupem - scan unprocess chain and add new buffer to it
3346 *
3347 ************************************************************
3348           rem
3349 scupem    subr      scu,(x3)
3350           ldq       temups-*
3351           tze       scu040-*
3352           ldx3      l.n002-*  /* upobuf */
3353           tsy       a.n000-*,* /* cvaddr */
3354           lda       0,3
3355           tze       scu020-*
3356 scu010    tsy       a.n001-*,* /* setbpe */
3357           cax3
3358           lda       bf.nxt,3
3359           tze       scu030-*
3360           tra       scu010-*
3361 scu020    stq       0,3
3362           tra       scu040-*
3363 scu030    stq       bf.nxt,3
3364 scu040    stz       temups-*
3365           tsy       scanup-*
3366           return    scupem
3367           rem
3368           rem
3369 fbufmg    bss       1
3370 temups    bss       1
3371 fbufng    bss       1
3372           rem
3373 a.n000    ind       cvaddr
3374 a.n001    ind       setbpt
3375 a.n002    ind       addbte
3376           rem
3377 l.n000    vfd       18/bufadd
3378 l.n001    vfd       18/bfflst
3379 l.n002    vfd       18/upobuf
3380 l.n003    vfd       18/buftmk
3381 l.n004    vfd       18/kv
3382 l.n005    vfd       18/kc
3383 l.n006    vfd       18/flgwd2
3384 l.n007    vfd       18/snifr
3385 *l.n008
3386 l.n009    oct       400000
3387 l.n010    oct       000400
3388 *l.n011
3389           rem
3390 ************************************************************
3391 *
3392 *         scanup - scan unprocess chain and place complete
3393 *          messages on the bufadd
3394 *
3395 ************************************************************
3396           rem
3397 scanup    subr      scn,(x3)
3398           ldx3      l.n004-*  /* kv */
3399           tsy       a.n000-*,* /* cvaddr */
3400           cx3a
3401           cax2
3402 scn010    ldx3      l.n005-*  /* kc */
3403           tsy       a.n000-*,* /* cvaddr */
3404           lda       0,2
3405           cmpa      0,3
3406           tze       scaret-*  /* no more output */
3407           tsy       getups-*  /* get next on upobuf chain */
3408           tra       scaret-*  /* done */
3409           tsy       a.n002-*,* /* add it to the bufadd */
3410           ldx3      l.n006-*  /* flgwd2 */
3411           tsy       a.n000-*,* /* cvaddr */
3412           lda       l.n007-*  /* snifr */
3413           orsa      0,3
3414           aos       0,2
3415           tra       scn010-*
3416 scaret    ila       0
3417           cax2
3418           return    scanup
3419           rem
3420           rem
3421 ************************************************************
3422 *
3423 *         getups - get next uprocess message and process it
3424 *
3425 ************************************************************
3426           rem
3427 getups    subr      gtp,(x2,x3)
3428           ldx3      l.n002-*  /* upobuf */
3429           tsy       a.n000-*,* /* cvaddr */
3430           lda       0,3
3431           tze       gtpret-*  /* nothing to do */
3432           sta       temups-*  /* store address  here for later use */
3433 gtp010    tsy       a.n001-*,* /*setbpt */
3434           sta       fbufmg-*  /* temp store for address modication */
3435           cax3
3436           lda       bf.tly,3
3437           ana       l.n003-*  /* only tally is needed */
3438           iaa       1
3439           ars       1
3440           iaa       -1
3441           ada       fbufmg-*
3442           iaa       bf.dta
3443           cax2
3444           lda       0,2
3445           cana      l.n009-*
3446           tnz       gtp020-*  /* found eom */
3447           cana      l.n010-*
3448           tnz       gtp020-*
3449           lda       bf.nxt,3
3450           tze       gtpret-*  /* no more input */
3451           tra       gtp010-*  /* loop again */
3452 gtp020    aos       getups-*  /* normal return */
3453           lda       l.n001-*  /* bfflst */
3454           orsa      bf.flg,3
3455           lda       bf.nxt,3
3456           stz       bf.nxt,3
3457           caq
3458           ldx3      l.n002-*  /* upobuf */
3459           tsy       a.n000-*,* /* cvaddr */
3460           stq       0,3
3461 gtpret    return    getups
3462           rem
3463           rem
3464 ************************************************************
3465 *
3466 *         getotp - a very fast method to get the proper output
3467 *          command/response to be sent
3468 *          This routine use the normalize instruction to
3469 *          preform this function.
3470 *
3471 *         parameters
3472 *          flgwd2 - Place in A-reg with bit 0 off (a must)
3473 *          pointer (endlist) in X1 for transfer lables back
3474 *
3475 *         results
3476 *          routines will return to lable corresponding to
3477 *          bit set in flgwd2
3478 *
3479 *         warnings
3480 *          flgwd2 must have bit 0 off
3481 *          and flgwd2 must not be zero
3482 *
3483 ************************************************************
3484 getopt    subr      gto,(x1)  "restore x1 on return
3485           ldx3      l.o000-*  "=flgwd2
3486           tsy       a.o000-*,* "=cvaddr
3487           lda       0,3       "flgwd2 must be in A-reg
3488           ldx1      l.o001-*  "address of endlist
3489           nrm                 "find something to output
3490           ldx2      0,1       "this what we will do
3491           return    getopt
3492           rem
3493 a.o000    ind       cvaddr
3494 l.o000    vfd       18/flgwd2
3495 l.o001    ind       endlst
3496           rem
3497           ind       sprr1     "poll rr command
3498           ind       sprej1    "poll rej command
3499           ind       sprnr1    "poll rnr command
3500           ind       srr1      "rr response
3501           ind       sif1      "I-frame
3502           ind       srej1     "rej response
3503           ind       srnr1     "rnr response
3504           ind       sua1      "ua response
3505           ind       scout1    "cmdr/frmr command
3506           ind       sbout1    "sabm command
3507           ind       ssout1    "sarm command
3508           ind       sdout     "disc command
3509 endlst    ind       sddnnt    "dm command
3510           rem
3511           rem
3512 ************************************************************
3513 *
3514 *         clrocp, setocp, ocpset, tstocp
3515 *
3516 *         subrountines to handle the t.ocp field
3517 *
3518 ************************************************************
3519 clrocp    subr
3520           stz       t.ocp,1
3521           stz       t.ocur,1
3522           stz       t.olst,1
3523           return    clrocp
3524           rem
3525 setocp    subr
3526           ldx3      0,3
3527           tsy       a.m000-*,* /* cvaddr */
3528           lda       0,3
3529           sta       t.ocp,1
3530           stz       t.ocur,1
3531           stz       t.olst,1
3532           ila       0
3533           cax2
3534           return    setocp
3535           rem
3536 ocpset    subr
3537           ldx3      0,3
3538           tsy       a.m000-*,* /* cvaddr */
3539           lda       t.ocp,1
3540           sta       0,3
3541           ila       0
3542           cax2
3543           return    ocpset
3544           rem
3545 tstocp    subr      tst,(x3)
3546           ldx3      0,3
3547           tze       tst010-* /* zero no address */
3548           tsy       a.m000-*,* /* cvaddr */
3549           lda       0,3
3550           tra       tst020-*
3551 tst010    cx3a
3552 tst020    cmpa      t.ocp,1
3553           tze       tst040-*
3554           ila       0
3555 tst030    cax2
3556           return    tstocp
3557 tst040    ldx3      tstsx3-*
3558           lda       1,3
3559           tra       tst030-*
3560 a.m000    ind       cvaddr
3561           end