;
; COPYRIGHT 1980,1983 CONVERGENT TECHNOLOGIES, INC.
; ALL RIGHTS RESERVED
;
; THIS PROGRAM IS FURNISHED UNDER A LICENSE RESTRICTING ITS USE
; SOLELY FOR THE OPERATION OF A DESIGNATED COMPUTER FOR A
; PARTICULAR PURPOSE, AND MAY NOT BE  COPIED OR OTHERWISE USED
; WITHOUT THE PRIOR WRITTEN CONSENT OF CONVERGENT  TECHNOLOGIES,
; INC.  TITLE TO AND OWNERSHIP OF THE PROGRAM, INCLUDING ITS
; SOURCE CODE, SHALL AT ALL TIMES REMAIN IN CONVERGENT TECHNOLOGIES.
;
Set(Level,0)
Set(counter,0)
SET(nSysRequest,0)
SET(nUsrRequest,0)
SET(nTerminationRq,0)
SET(nSwappingRq,0)
SET(nWsAbortRq,0)
SET(nChgUserNumRq,0)

;
; macro for defining termination request needed
;
*DEFINE (TerminationRequest(rc))(
rgTables segment public 'memory'
IF (nTerminationRq EQ 0) THEN (
EVEN
rgTerminationRq LABEL WORD) FI
DW rc
rgTables ends
SET(nTerminationRq, nTerminationRq+1))

;
; macro for defining abort request needed
;
*DEFINE (WsAbortRequest(rc))(
rgTables segment public 'memory'
IF (nWsAbortRq EQ 0) THEN (
rgWsAbortRq LABEL BYTE) FI
DW rc
rgTables ends
SET(nWsAbortRq, nWsAbortRq+1))

;
; macro for defining ChgUserNum request needed
;
*DEFINE (ChgUserNumRequest(rc))(
rgTables segment public 'memory'
IF (nChgUserNumRq EQ 0) THEN (
rgChgUserNumRq LABEL BYTE) FI
DW rc
rgTables ends
SET(nChgUserNumRq, nChgUserNumRq+1))

;
; macro for defining Swapping request needed
;
*DEFINE (SwappingRequest(rc))(
rgTables segment public 'memory'
IF (nSwappingRq EQ 0) THEN (
rgSwappingRq LABEL BYTE) FI
DW rc
rgTables ends
SET(nSwappingRq, nSwappingRq+1))

*define(xOut(str))(out(str))
define(nl)(
)
public rgNetRouting, rgPrgNetRouting
public  rgRqExchgSys
public rgSCntlInfoSys, rgNReqRespPbCbSys
public  rgLocalServiceCode, rgLocalServiceCodeSys, nSysRequest, rcLookupSys, rcMaxSys

public  rgRqExchgUsr
public rgSCntlInfoUsr, rgNReqRespPbCbUsr
public  rgLocalServiceCodeUsr, nUsrRequest, rcLookupUsr, rcMaxUsr
public nTerminationRqInit, nWsAbortRqInit, nSwappingRqInit, nChgUserNumRqInit
Public rcLookUp, rgPrcLookUp, rgPrcLookUpBase
Public rgRqExchg, rgPrgRqExchg
Public rgRcMax, rgPrgLocalServiceCode, rgPrgNetRouting
Public rgSwappingRq, rgChgUserNumRq, rgTerminationRq, rgWsAbortRq
Public cbTCode

STACK segment word stack 'STACK'
STACK ends

; For loadable requests, put first the tables that will be discarded:
; rgP's. Then put OCode, because part of it may be discardable.
; OCode contains the dividing point.
;

;  Version and Tables
;  Table array entries: rgWsAbortRq, rgChgUserNumRq, rgTerminationRq,
;  rgSwappingRq. The second word tells InitRqEx how many bytes are in
;  rgTables.

rgTables segment public 'memory'
	DB	'J', 'F'	;Version, change here and in InitRqEx.plm
cbRgTables DW 0
rgTables ends

; Array [0..16] of pointer to rgRqExchg
;

DGroup group rqSeg0, rqSeg1, rqSeg2, rqSeg3, rqSeg4, rqSeg5, rqSeg6
DGroup group rqSeg7, rqSeg8, rqSeg9, rqSeg10, OCode

rqSeg5 segment public 'const'

rgPrgRqExchg Label Byte
 DD rgRqExchgSys

rqSeg5 ends

; Array [0..8] of pointer to rcLookup
;
rqSeg6 segment word public 'const'

rgPrcLookup Label Byte
 DD RcLookUpSys

rqSeg6 ends

; array [ 0..8 ] of pointers to first word of table data
;
rqSeg7 segment word public 'const'

rgPrcLookUpBase Label Byte
 DD pRgbTcodeBase  ; entry for level 0 (0..FDF)

rqSeg7 ends

; array [0..16] of max request codes
;
rqSeg8 segment word public 'const'

rgRcMax Label Byte
 
rqSeg8 ends

; array [0..16] of pointers to local service code tables
;
rqSeg9 segment word public 'const'

rgPrgLocalServiceCode Label Byte
 DD rgLocalServiceCodeSys

rqSeg9 ends

; array [0..16] of pointers to net routing code tables
;
rqSeg10 segment word public 'const'

rgPrgNetRouting Label Byte
 DD rgNetRouting

rqSeg10 ends

;  Put data segment with discarded segments, for loadable rq files
;
data segment public 'data'

dummy Label Byte
data ends

; 
;  Format array entries
;
TCode segment word public 'memory'

prgbTcodeBase Label Byte
TCode ends

;  Offsets into the 'format' array
;
OCode segment word public 'const'

rcLookUp Label Byte

OCode ends

; Exchange servicing a request
;
rqSeg0 segment word public 'const'

rgRqExchg Label Byte

rqSeg0 ends

; sCntlInfo array
;
rqSeg1 segment word public 'const'
rqSeg1 ends

; RqPbCb array, RespPbCb array
;
rqSeg2 segment word public 'const'
rqSeg2 ends

; Local Service code array
;
rqSeg3 segment word public 'const'
rqSeg3 ends

; Net Routing arrays
;
rqSeg4 segment word public 'const'
rqSeg4 ends


; format macros none, b, w, and c (basic macros)
;
*define(none)()
*define(noRouting)()

*define(illegal)(define(varLB)(Ill))

*define(b(loc))(define(n)(eval(loc))IF(n + 2 GT sRq)THEN'
(define(sRq)(eval(n + 2)))FIdefine(varLB)(varLBbLabn)'
define(varDB)(varDB
db loc)SET(nVar,nVar+1))

*define(w(loc))(define(n)(eval(loc))'
IF(n + 2 GT sRq)THEN(define(sRq)(eval(n + 2)))FI'
define(varLB)(varLBn)define(varDB)(varDB
db 80h+loc)SET(nVar,nVar+1))

*define(c(val,loc))(if(val ne 0) then(define(n)(eval(loc))'
IF(n + 2 GT sRq)THEN(define(sRq)(eval(n + 2)))FI'
define(conLB)(conLBeval(val)n)define(conDB)(conDB
db loc,val)SET(nCon,nCon+1))fi)

*Define(bLab)(b)
*Define(sep)(X)
;
; Define abreviations on above macros:
;
;fh = w(12)

*define(fh)(IF(0EH GT sRq)THEN(define(sRq)(0EH))FI'
define(varLB)(varLB(0CH))'
define(varDB)(varDB
DB 8CH)SET(nVar,nVar+1))

*define(lfa)(IF(12H GT sRq)THEN(define(sRq)(12H))FI'
define(varLB)(varLB(10H0EH))define(varDB)(varDB
DB 90H,8EH)SET(nVar,nVar+2))

*define(p0)(IF(16H GT sRq)THEN(define(sRq)(16H))FI'
define(varLB)(varLB(14H12H))define(varDB)(varDB
DB 94H,92H)SET(nVar,nVar+2))

*define(s0)(w(22))

*define(pbcb0)(IF(18H GT sRq)THEN(define(sRq)(18H))FI'
define(varLB)(varLB(14H12H16H))define(varDB)(varDB
DB 94H,92H,96H)SET(nVar,nVar+3))

*define(p1)(IF(1CH GT sRq)THEN(define(sRq)(1CH))FI'
define(varLB)(varLB(1AH18H))define(varDB)(varDB
DB 9AH,98H)SET(nVar,nVar+2))

*define(s1)(w(28))

*define(pbcb1)(IF(1EH GT sRq)THEN(define(sRq)(1EH))FI'
define(varLB)(varLB(1AH18H1CH))define(varDB)(varDB
DB 09AH,98H,09CH)SET(nVar,nVar+3))

*define(p2)(IF(22H GT sRq)THEN(define(sRq)(22H))FI'
define(varLB)(varLB(20H1EH))define(varDB)(varDB
DB 0A0H,9EH)SET(nVar,nVar+2))

*define(s2)(w(34))

*define(pbcb2)(IF(24H GT sRq)THEN(define(sRq)(24H))FI'
define(varLB)(varLB(20H1EH22H))define(varDB)(varDB
DB 0A0H,9EH,0A2H)SET(nVar,nVar+3))

*define(p3)(IF(28H GT sRq)THEN(define(sRq)(28H))FI'
define(varLB)(varLB(26H24H))define(varDB)(varDB
DB 0A6H,0A4H)SET(nVar,nVar+2))

*define(pbcb3)(IF(2AH GT sRq)THEN(define(sRq)(2AH))FI'
define(varLB)(varLB(26H24H28H))define(varDB)(varDB
DB 0A6H,0A4H,0A8H)SET(nVar,nVar+3))


*define(p(o))(w(o+2)w(o))

; routing macros
;

; Set expandFileSpec and routeByNode
*define(FileSpec)(SET(netRouting,netRouting+3))

; Set expandDevSpec and routeByNode
*define(DevSpec)(SET(netRouting,netRouting+1))

; Set expandDirSpec and routeByNode
*define(DirSpec)(SET(netRouting,netRouting+2))

; Set expand2FileSpecs and routeByNode
*define(FileSpec2)(SET(netRouting,netRouting+4))

; Set expand2FileSpec specified by p2 and s2 and routeByNode
*define(FileSpecP2S2)(SET(netRouting,netRouting+5))
*define(rFh)(SET(netRouting,netRouting+8))
*define(openFh)(SET(netRouting,netRouting+40h))
*define(closeFh)(SET(netRouting,netRouting+6))
*define(CloseAtTermination)(SET(netRouting,netRouting+20h))
*define(SpecPw)(SET(netRouting,netRouting+10h))
*define(RW)(SET(netRouting,netRouting+80h))

;
; Sys Requests 
;
*define(SysRequestInit)('
'
' 'xOut(nl Start Sys requests:nl )'
'
' 'Enter6(rgRqExchgSys LABEL byte'
'  ',rgSCntlInfoSys LABEL byte'
'  ',rgNReqRespPbCbSys LABEL word'
'  ',rgLocalServiceCode LABEL byte
'  'rgLocalServiceCodeSys EQU rgLocalServiceCode'
'  ',RcLookUpSys LABEL byte'
'  ',RgNetRouting LABEL byte)'
)

;
; new table 
;
*Define(NewTable)(TCode segment
rqLabel label byte
db sRq, nVar
varDB
db nCon
conDB
TCode ends
)
;


*define(c1xx(s,q,p))(if(q eq 0)then(c10x(s,p))else(c11x(s,q,p))fi)
*define(c0xx(q,p))(if(q eq 0)then(c00x(p))else(c01x(q,p))fi)
*define(c00x(p))(if(p eq 0)then(c000)else(c001(p))fi)
*define(c01x(q,p))(if(p eq 0)then(c010(q))else(c011(q,p))fi)
*define(c10x(s,p))(if(p eq 0)then(c100(s))else(c101(s,p))fi)
*define(c11x(s,q,p))(if(p eq 0)then(c110(s,q))else(c111(s,q,p))fi)

*define(c000)(define(conDB)()define(nCon)(0)define(conLB)())
*define(c001(p))(define(conDB)(
db 3,p)define(nCon)(1)define(conLB)(3eval(p)))
*define(c010(q))(define(conDB)(
db 2,q)define(nCon)(1)define(conLB)(2eval(q)))
*define(c011(q,p))(define(conDB)(
db 2,q,3,p)define(nCon)(2)define(conLB)(2eval(q)3eval(p)))
*define(c100(s))(define(conDB)(
db 0,s)define(nCon)(1)define(conLB)(0eval(s)))
*define(c101(s,p))(define(conDB)(
db 0,s,3,p)define(nCon)(2)define(conLB)(0eval(s)3eval(p)))
*define(c110(s,q))(define(conDB)(
db 0,s,2,q)define(nCon)(2)define(conLB)(0eval(s)2eval(q)))
*define(c111(s,q,p))(define(conDB)(
db 0,s,2,q,3,p)define(nCon)(3)define(conLB)(0eval(s)2eval(q)3eval(p)))


*define(SysRequest(id,name,exchange,code,size,nReqPbCb,nRespPbCb,format,routing))(xOut(id)define(varLB)()define(varDB)()define(nVar)(0)
set(sRq,12+size+6*(nReqPbCb+nRespPbCb))set(netRouting,0)if(size EQ 0)
THEN(c0xx(nReqPbCb,nRespPbCb))ELSE(c1xx(size,nReqPbCb,nRespPbCb))FI
formatroutingdefine(rqLabel)(TconLBsepvarLB)IF(NOT(isdef(rqLabel)))THEN(NewTable)FI
rqSeg0 segment
DB exchange
rqSeg0 ends
rqSeg1 segment
DB size
rqSeg1 ends
rqSeg2 segment
DB nReqPbCb
DB nRespPbCb
rqSeg2 ends
rqSeg3 segment
DW code
rqSeg3 ends
OCode segment
DW offset rqLabel  offset prgbTcodeBase
OCode ends
rqSeg4 segment
DB netRouting
rqSeg4 ends
SET(nSysRequest,nSysRequest+1)xOut(,))

;
; USR REQUESTS 
;
*define(UsrRequestInit)('
'
' 'xOut(nl Start User requests:nl)'
'
' 'Enter6(rgRqExchgUsr LABEL byte'
'  ',rgSCntlInfoUsr LABEL byte'
'  ',rgNReqRespPbCbUsr LABEL byte'
'  ',rgLocalServiceCodeUsr LABEL byte'
'  ',RcLookUpUsr LABEL byte'
'  ',RgNetRoutingUsr LABEL byte)'
)

*define(UsrRequest(id,name,exchange,code,size,nReqPbCb,nRespPbCb,format,routing))('
' 'xOut(id)'
' 'nl;name (id)nl
' 'define(varLB)()'
' 'define(conLB)()'
' 'define(varDB)()'
' 'define(conDB)()'
' 'define(nCon)(0)'
' 'define(nVar)(0)'
' 'set(sRq,12+size+6*(nReqPbCb+nRespPbCb))'
' 'set(netRouting,0)'
'
' 'c(size,0)'
' 'c(nReqPbCb,2)'
' 'c(nRespPbCb,3)'
' 'format'
' 'routing'
' 'define(rqLabel)(TconLBsepvarLB)'
' 'IF(NOT(isdef(rqLabel))) THEN(NewTable)FI
'
' 'Enter6(DB exchange,DB size,DB nReqPbCb
'   'DB nRespPbCb,DW code,'
'   'DW offset rqLabel  offset prgbTcodeBase,DB netRouting)'
' 'SET(nUsrRequest,nUsrRequest+1)'
' 'xOut(,)'
)
; Enter a string into each of 6 segments, used for constructing tables 
;
*DEFINE(Enter6(data0,data1,data2,data3,data4,data5))(
rqSeg0 segment
data0
rqSeg0 ends
rqSeg1 segment
data1
rqSeg1 ends
rqSeg2 segment
data2
rqSeg2 ends
rqSeg3 segment
data3
rqSeg3 ends
OCode segment
data4
OCode ends
rqSeg4 segment
data5
rqSeg4 ends
)
*DEFINE(Enter3(data0,data1,data5))(
rqSeg0 segment
data0
rqSeg0 ends
rqSeg3 segment
data1
rqSeg3 ends
OCode segment
data5
OCode ends
)
*DEFINE(Enter4(data0,data1,data5,data6))(
rqSeg0 segment
data0
rqSeg0 ends
rqSeg3 segment
data1
rqSeg3 ends
OCode segment
data5
OCode ends
rqSeg4 segment
data6
rqSeg4 ends
)
*define(RequestInit(OldLevel,Level))('
If (OldLevel EQ 0h) Then (
rqSeg8 Segment
Dw nSysRequest
rqSeg8 Ends
) Else (
rqSeg5 Segment
 DD rgRqExchgOldLevel
rqSeg5 Ends
rqSeg9 Segment
 DD rgLocalServiceCodeOldLevel
rqSeg9 Ends
rqSeg10 Segment
 DD rgNetRoutingOldLevel
rqSeg10 Ends
rqSeg8 Segment
 DW counter
rqSeg8 Ends
If ((OldLevel And 1) EQ 0) Then (
rqSeg6 Segment
 DD rgFormatOffsetTableOldLevel
rqSeg6 Ends
rqSeg7 Segment
 DD prgbTcodeBase
rqSeg7 Ends
) Fi
) Fi
Set(counter,0)
If (Level NE 10h) Then (
xOut(nl Level Level requests: )
Enter4(rgRqExchgLevel LABEL byte,rgLocalServiceCodeLevel Label Byte
,rgFormatOffsetTableLevel LABEL byte,rgNetRoutingLevel Label Byte)'
) Fi
)
*Define(erc1)(xOut(
Use UsrRequest for Requests in the 32..1 range
))
*Define(erc2)(xOut(
Use SysRequest for Requests in the 0..0FDFh range
))

*define(Request(id,name,exchange,code,size,nReqPbCb,nRespPbCb,format,'
routing))(define(varLB)()define(conLB)()define(varDB)()define(conDB)'
()define(nCon)(0)define(nVar)(0)set(sRq,12+size+6*(nReqPbCb+nRespPbCb))'
set(netRouting,0)c(size,0)'
c(nReqPbCb,2)c(nRespPbCb,3)formatroutingSet(OldLevel, Level)'
Set(Level, (Id1000h) And 0Fh)If ((eval(Id) GE 0FFE0h) And ('
Eval(Id) LE 0FFFFh)) Then (erc1)FiIf (Level EQ 0) Then (erc2)Fi'
While ((OldLevel And 0Fh) LT Level)(RequestInit(OldLevel,'
Eval(OldLevel+1))Set(OldLevel,OldLevel+1))xOut(id)define(rqLabel)'
(TconLBsepvarLB)IF(NOT(isdef(rqLabel))) THEN(NewTable)FI
Enter4(DB exchange,DW Code,DW offset rqLabel  offset prgbTcodeBase,DB netRouting)Set(counter,counter+1)xOut(,))
;
; final  set counters in various tables, create gen table.
;
*define(Final)(
rgTables segment public 'memory'
IF (nWsAbortRq EQ 0) THEN (rgWsAbortRq label byte) FI
IF (nChgUserNumRq EQ 0) THEN (rgChgUserNumRq label byte) FI
IF (nTerminationRq EQ 0) THEN (rgTerminationRq label byte) FI
IF (nSwappingRq EQ 0) THEN (rgSwappingRq label byte) FI
rgTables ends
OCode segment
rcMaxSys DW nSysRequest
rcMaxUsr DW nUsrRequest
OCode ends

TCode segment
rgbTCodeEnd Label Byte
TCode ends

data segment public 'data'
rgnRequest label word
nSysRequest DW nSysRequest
nUsrRequest DW nUsrRequest
nWsAbortRqInit DW nWsAbortRq
nChgUserNumRqInit DW nChgUserNumRq
nTerminationRqInit DW nTerminationRq
nSwappingRqInit DW nSwappingRq
cbTcode DW OFFSET rgbTcodeEnd
data ends
While(Level LE 15)(RequestInit(Level,Eval(Level+1))Set(Level,Level+1))
rqSeg5 Segment
DD rgRqExchgUsr
rqSeg5 Ends
rqSeg6 Segment
DD RcLookUpUsr
rqSeg6 Ends
rqSeg7 Segment
DD pRgbTcodeBase
rqSeg7 Ends
rqSeg8 Segment
Dw nUsrRequest
rqSeg8 Ends
rqSeg9 Segment
DD rgLocalServiceCodeUsr
rqSeg9 Ends
rqSeg10 Segment
DD rgNetRoutingUsr, rgSCntlInfoSys, rgSCntlInfoUsr, rgNReqRespPbCbSys
DD rgNReqRespPbCbUsr, rgWsAbortRq, rgChgUserNumRq, rgTerminationRq
DD rgSwappingRq, rgnRequest
DB if(*isdef(fMerge)) THEN (fMerge) ELSE(0FFh)FI
rqSeg10 Ends
rgTables segment public 'memory'
ORG offset cbRgTables
DW (nSwappingRq + nChgUserNumRq + nTerminationRq + nWsAbortRq)*2
rgTables ends
Set(counter,0)
Set(Level,0h)
xOut(nl End passnl))
qSeg1 ends
rqSeg2 segment
DB nReqPbCb
DB nRespPbCb
rqSeg2 ends
rqSeg3 segment
DW code
rqSeg3 ends
OCode segment
DW offset rqLabel  offset prgbTcodeBase
OCode ends
rqSeg4 segment
DB netRouting
rqSeg4 ends
SET(nSysRequest,nSysRequest+1)xOut(,))

;
; USR REQUESTS 
;
*define(UsrRequestInit)('
'
' 'xOut(nl Start User requests:nl)'
'
' 'Enter6(rgRqExchgUsr LABEL byte'
'  ',rgSCntlInfoUsr LABEL byte'
'  ',rgNReqRespPbCbUsr LABEL byte'
'  ',rgLocalServiceCodeUsr LABEL b