;  NETWORK DISK OPERATING SYSTEM FOR CP/NET-86
;
;  1983.9.1.	VER.1.00
;
	TITLE	'NETWORK DISK OPERATING SYSTEM FOR CP/NET-86 SLAVE'
;
;
BASE	EQU	100H			;FOR RELOCATION
;
;  EQUATIONS OF DATA
;
LF	EQU	0AH			;LINE FEED
CR	EQU	0DH			;CARRIAGE RETURN
EOF	EQU	0FFH			;0FFH IS END OF FILE
;
FSEND	EQU	0			;SEND FORMAT CODE
FRECV	EQU	1			;RECEIVE FORMAT CODE
;
BDOS	EQU	224			;BDOS FUNCTION CALL INTERRUPT
VBDOS	EQU	BDOS*4			;BDOS VECTOR POINT
BIOSTP	EQU	2500H			;BIOS TOP OFFSET
COMBUF	EQU	9			;BIAS TO COMMENT BUFFER OF CCP
BDCUDK	EQU	5			;BIAS TO BDOS CURRENT DISK
BDCUDR	EQU	23			;BIAS TO BODS CURRENT DRIVE
;
SCTLNG	EQU	128			;ONE SECTOR LENGTH
;
NOFUNC	EQU	8000H			;NO FUNCTION CODE IN CP/NET
;
;  EQUATIONS OF DOS FUNCTION
;
CRESET	EQU	0			;RESET SYSTEM
CCNDIN	EQU	3			;CONSOLE INPUT WITH DEVICE CODE
CCNDOT	EQU	4			;CONSOLE OUTPUT WITH DEVICE CODE
CBUFPR	EQU	9			;BUFFER PRINT
CRDCBF	EQU	10			;READ CONSOLE BUFFER
CCONST	EQU	11			;GET CONSOLE STATUS
CGETVR	EQU	12			;GET VERSION NUMBER
CRSDSK	EQU	13			;RESET DISK
CSELDK	EQU	14			;SELECT DISK
COPEN	EQU	15			;OPEN FILE
CCLOSE	EQU	16			;CLOSE FILE
CSRFST	EQU	17			;SEARCH FIRST
CSRNXT	EQU	18			;SEARCH NEXT DIRECTORY
CREAD	EQU	20			;READ FILE
CSTDMA	EQU	26			;SET DMA ADDRESS
CGTALC	EQU	27			;GET ALLOCATION VECTOR ADDRESS
CGTDPA	EQU	31			;GET DISK PARAMETER BLOCK ADDRESS
CSTUSC	EQU	32			;SET USER CODE
CRSDSN	EQU	37			;RESET DISK BY DISK VERCTOR
CACCES	EQU	38			;ACCESS DRIVE
CFREE	EQU	39			;FREE DRIVE
CGTSYA	EQU	49			;GET SYSTEM ADDRESS
;
CLOGIN	EQU	64			;LOGIN
CLOGOF	EQU	65			;LOGOFF
CNMAX	EQU	71			;MAX OF NDOS FUNCTION
CSTDPS	EQU	106			;SET DEFAULT PASSWORD
;
;  SLAVE CONFIGRATION TABLE
;
; -1	NETWORK STATUS
;  0	SLAVE PROCESSOR ID
;  1-32	A - P DISK DEVICE CODE
; 33-34	CONSOLE DEVICE
; 35-36	LIST DEVICE
; 37	LIST BUFFER COUNTER
; 38-42	MESSAGE HEADER FOR LIST OUT
; 43	LISTER DEVICE NUMBER
; 44-171 LIST OUT DATA BUFFER
;
;  EACH DEVICE DATA USED 2 BYTES
;  IN 1-36
;  1B:BIT 7 H ON NETWORK
;     BIT 6 H SET UP IN DISK
;     BIT 0-3 DEVICE NUMBER IN MASTER
;  2B:MASTER ID
;
;
;  BIAS TO DATA IN CONFIGRATION TABLE
;
BSCONS	EQU	33			;BIAS TO CONSOLE DATA
BSLIST	EQU	35			;BIAS TO LISTER DATA
;
;
	CSEG
	ORG	BASE
;
;  ENTRY POINTS
;
NDOSTP:					;NDOS TOP
;
;
CPMIDC:					;CP/M ID CODE AREA  6 BYTES
;
	JMP	NDOSE			;DOS ENTRY
	JMP	COLDST			;COLD START ENTRY
;
NDOS:					;NDOS ENTRY
	JMP	NDOSE			;DOS ENTRY MAIN
	JMP	COLDST			;COLD START POINTER
;
;  LINKED PARAMETERS
;
MDPROT	DB	0			;PRINTER OUT MODE FLG
MDPREC	DB	0			;CONTROL-P ECHO MODE
MRDCBF	DB	0			;READ CONSOLE BUFFER MODE
;
;
	DB	'COPYRIGHT (C) 1983, XYZ (DIGITAL RESEARCH) '
;
;  COLD START ROUTINE
;
COLDST:
	MOV	AX,CS
	MOV	SS,AX			;SET STACK SEGMENT
	MOV	SP,OFFSET STACK
	MOV	ES,AX
	MOV	DS,AX			;INITIALIZE ALL SEGMENT REGISTER
	CALL	NTWKIN			;INITIALIZE NETWORK
	OR	AL,AL
	JNZ	COLDSE			;INITIALIZE ERROR
	CALL	CNFTBL			;GET CONFIGRATION TABLE
	INC	BX
	MOV	CONTAD,BX		;SAVE CONFIGRATION TABLE POINT
	MOV	CL,CGTSYA
	INT	BDOS			;GET SYSTEM ADDRESS
	MOV	BDSYSA,BX		;SAVE SYSTEM ADDRESS
	CALL	STBITP			;SET BIOS TRAPS
	CALL	BGTMRT			;GET MEMORY REGION TABLE POINT
	MOV	AX,1[BX]		;GET FIRST REGION START
	MOV	DX,CS
	SUB	AX,DX
	ADD	AX,15
	AND	AX,0FFF0H
	MOV	CL,4
	SHL	AX,CL			;GET CCP TOP
	MOV	CCPTOP,AX		;SAVE TOP
	MOV	CL,CGETVR
	INT	BDOS			;GET VERSION NUMBER
	MOV	VERSION,BX		;SAVE VERSION NUMBER
	XOR	AX,AX
	MOV	ES,AX
	MOV	AX,ES:WORD PTR .VBDOS	;GET BDOS OFFSET
	MOV	BDOSE,AX		;SAVE BDOS ENTRY
	MOV	BX,OFFSET NDOS
	MOV	ES:WORD PTR .VBDOS,BX	;SET VECTOR TO NDOS
	MOV	CX,6			;ID CODE LENGTH
	SUB	AX,CX			;TO ID TOP
	MOV	SI,AX
	MOV	DI,OFFSET CPMIDC
	MOV	AX,DS
	MOV	ES,AX			;RESTORE ES
	CLD
	REP	MOVSB			;SET ID CODE
	CALL	NWBOTB			;DO BOOT PROCESS
	XOR	CX,CX			;USER 0 DRIVE A
	JMP	CCPTOP			;TO CCP
;
COLDSE:					;INITIALIZE ERROR
	MOV	CL,CBUFPR
	MOV	DX,(OFFSET CSTFIL)
	INT	BDOS			;START UP FAILURE
	MOV	CL,CRESET		;RETURN TO CP/M SYSTEM
	XOR	DX,DX
	INT	BDOS
;
;  NDOS FUNCTION DECODING BODDY
;
NDOSE:
	MOV	BL,CL
	CMP	CL,CNMAX+1
	JC	NDOSEF			;IN RANGE
	CMP	CL,CSTDPS
	JZ	NDOSED			;OK SET DEFAULT PASSWORD
NDOSEN:					;NO FUNCTION IN DOS
	MOV	AX,-1
	MOV	BX,AX
	IRET
;
NDOSED:					;SET DEFAULT PASS WORD
	MOV	BL,CNMAX+1
NDOSEF:
	XOR	AL,AL
	CMP	CL,CRDCBF
	JNZ	$+4
	INC	AL			;READ CONSOLE BUFFER
	MOV	CS:MRDCBF,AL		;SET MODE FOR COPNTROL-P
	XOR	BH,BH
	MOV	AL,CS:(OFFSET IXFUNC)[BX] ;GET CODE OF FUNCTION
	OR	AL,AL
	JNZ	NDOSEG			;GET SOME FUNCTION
	JMP	CS:BDOSE		;NO FUNCTION IN NDOS  TO BDOS
;
NDOSEG:
	INC	AL
	JZ	NDOSEN			;NO FUNCTION IN DOS
	MOV	CS:INDSEG,DS		;SAVE DSEG
	MOV	BX,CS
	MOV	DS,BX			;SET SEGMENT REGISTERS
	MOV	ES,BX
	MOV	USTKSG,SS		;SAVE STACK SEGMENT
	MOV	USTACK,SP		;SAVE STACK OFFSET
	MOV	SS,BX
	MOV	SP,OFFSET STACK		;TO NDOS STACK
	PUSH	BP
	PUSH	DI
	PUSH	SI
	MOV	CURSEG,BX		;SET CURRENT SEGMENT TO OUTPUT SEGMENT
	MOV	ENTSTK,SP		;SAVE NDOS PROCESS ENTRY STACK
	MOV	PARAMT,DX		;SET INPUT PARAMETER
	MOV	FUNCOD,CL
	MOV	MSGFUN,CL		;SET FUNCTION CODE
	MOV	BX,OFFSET MSGSIZ
	MOV	BYTE PTR [BX],0		;CLEAR SIZE
	INC	BX
	MOV	MCRPNT,BX		;INITIALIZE POINTER
	MOV	BX,OFFSET NDENDP
	PUSH	BX			;SET RETURN ADDRESS
	MOV	BX,OFFSET IXMACR-2
	XOR	AH,AH
	ADD	BX,AX
	PUSH	BX			;SAVE MACRO POINTER
NDOSLP:					;LOOP OF MACRO PROCESS
	POP	SI			;GET INDEX
	CLD
	LODSB
	MOV	DL,AL
	AND	DX,07FH			;OFF END BIT & GET BIAS
	MOV	BX,OFFSET IXMAIN	;INDEX OF ROUTINE
	ADD	BX,DX
	MOV	DX,[BX]			;GET ROUTINE ADDRESS
	RCL	AL,1
	JC	$+7			;END OF MACRO
	PUSH	SI
	MOV	BX,OFFSET NDOSLP
	PUSH	BX			;SAVE RETURN POINT
	JMP	DX			;TO EACH ROUTINE
;
;   1:SEND MESSAGE WITH HEADER SET UP
;
;  23:RENAME
;  27:GET ALLOCATION VECTOR
;  28:WRITE PROTECT DISK
;  31:GET DISK PARAMETER BLOCK
;
SNDHDR:
	MOV	SI,CONTAD
	MOV	BX,OFFSET MSGTOP
	MOV	BYTE PTR [BX],FSEND	;FORMAT CODE TO SEND MODE
	MOV	AL,[SI]			;GET SLAVE ID
	MOV	2[BX],AL		;SET SLAVE ID
	MOV	DX,MCRPNT		;GET CURRENT POINT OF MESSAGE
	SUB	DX,OFFSET MSGDAT	;GET LENGTH OF MESSAGE
	JZ	$+3			;NO DATA
	DEC	DX
	MOV	4[BX],DL		;SET SIZE
	MOV	CX,OFFSET MSGTOP
;
;  SEND MESSAGE WITH ERROR PROCESS
;  INPUT
;  CX:MESSAGE ADDRESS	DS:SEGMENT
;
SDMSGE:
	CALL	SNDMSG			;SEND IN SNIOS
	MOV	BX,CS
	MOV	DS,BX
	MOV	ES,BX			;RESTORE SEGMENT REGISTERS
	INC	AL
	JZ	NERROR			;ERROR
	RET				;NOT ERROR
;
;  RECEIVE MESSAGE WITH ERROR PROCESS
;  INPUT
;  CX:MESSAGE ADDRESS  DS:SEGMENT
;
RVMSGE:
	CALL	RCVMSG			;RECEIVE IN SNIOS
	MOV	BX,CS
	MOV	DS,BX
	MOV	ES,BX
	INC	AL
	JZ	NERROR			;ERROR
	RET				;NOT ERROR
;
;  ERROR END OF NDOS FUNCTION
;
NERROR:
	MOV	BH,0FFH
	MOV	AL,BH
	JMPS	NDEND			;END OF NDOS
;
;  END OF DOS FUNCTION
;  INPUT
;  BH:RETURN PARAMETER
;
NDENDP:
	MOV	AL,OTPARA
NDEND:
	MOV	SP,ENTSTK		;NDOS PROCESS ENTRY STACK
	POP	SI
	POP	DI
	POP	BP
	MOV	ES,CURSEG		;SET OUTPUT SEGMENT
	MOV	SS,USTKSG
	MOV	SP,USTACK		;RESTORE STACK
	MOV	DS,INDSEG		;RESTORE DATA SEGMENT
	MOV	BL,AL
	MOV	AH,BH
	IRET
;
;   2:RECEIVE MESSAGE WITH INITIALIZATION OF MESSAGE POINTER
;
;  NOT DIRECTLY USED
;
RCVPAR:
	MOV	CX,OFFSET MSGTOP
	CALL	RVMSGE			;RECEIVE
	MOV	BX,OFFSET MSGDAT
	MOV	MCRPNT,BX		;INITIALIZE POINTER
	RET
;
;  TO BDOS WITH PARAMETER
;
TBDOSP:
	MOV	DX,PARAMT		;GET PARAMETER
	MOV	CL,FUNCOD		;GET FUNCTION CODE
;
;  TO BDOS
;
TOBDOS:
	PUSH	DS
	MOV	DS,INDSEG		;SET ENTER SEGMENT
	PUSHF				;SET FLAG
	PUSH	CS			;SET SEGMENT FOR IRET
	CALL	CS:BDOSE		;TO BDOS
	POP	DS
	MOV	CURSEG,ES		;SAVE RESULT SEGMENT
	MOV	DX,DS
	MOV	ES,DX			;RESTORE SEGMENT
	RET
;
;  TO BDOS & END
;
TBDOSE:
	CALL	TBDOSP
	JMP	NDEND
;
;  CHECK & SET UP DISK & OVERRIDING GOTO BDOS, IF LOCAL
;  OUTPUT
;  AL:MASTER ID
;  CL:DISK ENTRY
;
CHKDSK:
	MOV	BX,PARAMT		;GET FCB POINT
	MOV	ES,INDSEG		;GET SEGMENT
	MOV	DL,ES:[BX]		;GET ENTRY TYPE
	DEC	DL
	JNS	CHKDSS			;HAS ENTRY TYPE
	MOV	DL,CURDSK
CHKDSS:
	MOV	BP,CS
	MOV	ES,BP			;RESTORE SEGMENT
	CALL	GETDPT
	CMP	AL,0FFH
	JZ	TBDOSE			;LOCAL & END
	RET				;NETWORK DRIVE
;
;  GET DISK PARAMETER POINT
;  INPUT
;  DL:DISK NUMBER
;  OUTPUT
;  AL:MASTER ID  -1 LOCAL
;  CL:MASTER DRIVE ENTRY
;  OUTPUT
;  BX:CODE POINT-1
;
GETDPT:
	XOR	DH,DH
	MOV	BX,CONTAD
	ADD	BX,DX
	ADD	BX,DX
	MOV	AL,-1
	MOV	CL,1[BX]		;GET DRIVE CODE
	TEST	CL,80H
	JZ	GETDPE			;LOCAL
	AND	CL,0FH			;NETWORK GET DISK
	INC	CL
	MOV	AL,2[BX]		;GET MASTER ID
	MOV	MSGID,AL		;SET MASTER ID
GETDPE:
	RET
;
;  WARM BOOT
;
NWBOOT:
	MOV	AX,CS
	MOV	ES,AX
	MOV	DS,AX
	CALL	NWBOTB			;WARM BOOT BODY
	MOV	BX,CCPTOP
	ADD	BX,6
	JMP	BX			;TO CCP WARM START
;
;  WARM BOOT BODY
;
NWBOTB:
	MOV	AL,CFREE
	MOV	FUNCOD,AL		;SET FUNCTION CODE
	MOV	INDSEG,DS		;SET ENTRY SEGMENT
	MOV	MSGFUN,AL
	MOV	PARAMT,-1		;ALL DRIVE
	CALL	DSKACC			;FREE ALL DRIVE
	CALL	NTWKBT			;WARM BOOT OF SNIOS
	MOV	DL,USRCOD		;CURRENT USER CODE
	MOV	CL,CSTUSC
	JMP	TOBDOS			;SET USER CODE
;
;   3:SET FCB & SEND
;
;  19:DELETE FILE
;  20:READ SEQUENTIAL
;  30:SET FILE ATTRIBUTE
;  33:READ RANDOM
;  35:COMPUTE FILE SIZE
;  36:SET RANDOM RECORD
;
STFCBS:
	CALL	SETFCB			;SET FCB DATA
	JMP	SNDHDR			;SEND
;
;   4:SET FCB DATA
;
;  15:OPEN FILE
;  16:CLOSE FILE
;  21:WRITE SEQUENTIAL
;  22:MAKE FILE
;  23:RENAME FILE
;  30:SET FILE ATTRIBUTE
;  34:WRITE RANDOM
;  42:LOCK RECORD
;  43:UNLOCK RECORD
;
SETFCB:
	CALL	CHKDSK			;CHECK DISK
SETFCS:
	MOV	BX,MCRPNT		;GET POINTER
	MOV	AL,USRCOD
	MOV	[BX],AL			;SET USER CODE
	INC	BX
	MOV	[BX],CL			;ENTRY TYPE DRIVE CODE
	INC	BX			;TO FCB NAME TOP
	MOV	DX,PARAMT
	MOV	DS,INDSEG		;SOURCE FCB POINT
	INC	DX
	MOV	CX,35
	CALL	MSCOPY			;SET FCB DATA
	XOR	AL,AL
	MOV	MMODIF,AL		;CLEAR NAME MODIFY BITS
	MOV	MUNLRW,AL		;CLEAR UNLOCK R/W MODE
;
;  CHECK & SET UP SUBMIT OR TEMPORARY FILE NAME
;  INPUT
;  BX:NAME TOP
;
CHKFCB:
	CALL	CHKFNM			;CHECK SUBMIT FILE
	ADD	BX,CX
	INC	BX
	INC	BX
	TEST	BYTE PTR 0FFFFH[BX],80H
	JZ	CHKFCS			;LOCKED FILE
	TEST	BYTE PTR [BX],80H	;UNLOCKED MODE
	JNZ	CHKFCS			;UNLOCKED R/O
	MOV	MUNLRW,-1		;SET UNLOCKED R/W MODE
CHKFCS:
	SHL	MMODIF,1		;UP MODIFIED BIT TO MODIFY POSITION
	INC	BX
	INC	BX
	INC	BX			;TO SET UP TEMPORARY FILE MODE
;
;  CHECK & SET UP TEMPORARY OR SUBMIT
;  INPUT
;  BX:DATA POINT
;  OUTPUT
;  BX+CX:NETX POINT   BX+3
;
CHKFNM:
	MOV	CX,3
	MOV	DI,BX
	MOV	AL,'$'
	CLD
	REPZ	SCASB
	MOV	BX,DI			;SET END POINT
	JCXZ	$+3
	RET				;NOT MODIFIED MODE
;
	INC	MMODIF			;SET MODIFIED BIT
	MOV	SI,BX
	DEC	SI
	MOV	BX,CONTAD
	MOV	AL,[BX]			;GET SLAVE ID
	MOV	AH,AL
	CALL	SETNIB			;SET LOWER NIBBLE
	DEC	SI
	MOV	AL,AH
	RCR	AL,1
	RCR	AL,1
	RCR	AL,1
	RCR	AL,1			;GET HIGHER NIBBLE
;
;  SET NIBBLE
;  INPUT
;  SI:DATA POINT
;  AL:DATA
;
SETNIB:
	AND	AL,0FH
	ADD	AL,'0'
	CMP	AL,'9'+1
	JC	$+4			;0 TO 9
	ADD	AL,7			;A TO F
	MOV	[SI],AL
	RET
;
;   5:CHECK & SET UP NAME OF SECOND PART
;
;  23:RENAME
;
CHKSFC:
	MOV	BX,MCRPNT
	SUB	BX,19
	JMP	CHKFCB
;
;  COPY TO MESSAGE DATA AREA
;  INPUT
;  CX:COUNT
;  BX:DESTINATION POINTER	ES:SEGMENT
;  DX:SOURCE POINTER		DS:SEGMENT
;  OUTPUT
;  BX:BX
;  DX:DX
;  DS:CS
;
MSCOPY:
	MOV	SI,DX
	MOV	DI,BX
	CLD
	REP	MOVSB			;COPY DATA
	MOV	SI,CS
	MOV	DS,SI			;RESTORE DATA SEGMENT
	MOV	MCRPNT,DI		;SET NET MESSAGE POINT
	RET
;
;   6:SET LOCK/UNLOCK RECORD & SEND
;
;  42:LOCK RECORD
;  43:UNLOCK RECORD
;
STLKRN:
	MOV	CX,2
	JMPS	WTDTCS
;
;   7:SET FILE PASSWORD & SEND
;
;  15:OPEN FILE
;  16:CLOSE FILE
;  22:MAKE FILE
;
STPWRD:
	MOV	CX,8
	JMPS	WTDTCS
;
;   8:SET ONE SECTOR DATA TO MESSAGE BUFFER
;
;  21:WRITE SEQUENTIAL
;  34:WRITE RANDOM
;  40 WRITE RANDOM WITH ZERO FILL
;
WTDTCP:
	MOV	CX,SCTLNG		;ONE SECTOR LENGTH
WTDTCS:
	MOV	DX,DMAADD		;SOURCE
	MOV	BX,MCRPNT		;DESTINATION
	MOV	DS,DMASEG		;SOURCE SEGMENT
	CALL	MSCOPY			;COPY DATA
	JMP	SNDHDR			;SEND
;
;   9:SET DRIVE CODE
;
;  27:GET ALLOCATION VECTOR
;  28:WRITE PROTECT DISK
;  31:GET DISK PARAMETER BLOCK
;
SETDRC:
	MOV	DL,CURDSK
	CALL	GETDPT			;GET DISK MODE
	CMP	AL,0FFH
	JNZ	$+5			;NETWORK DISK
	JMP	TBDOSE			;LOCAL DISK
;
	MOV	BX,MCRPNT
	DEC	CL
	MOV	[BX],CL			;SET DRIVE NUMBER
	INC	BX
	MOV	MCRPNT,BX		;UP DATA POINTER
	RET
;
;   A:SET FCB EXTENDED DATA
;
;  70:SET COMPATIBILITY ATTRIBUTE
; 106:SET DEFAULT PASSWORD
;
STXFCB:
	MOV	DX,0
	CALL	GTDMAP			;GET SELECTED NETWORK DISK
	MOV	AL,CL
	INC	CL
	JNZ	$+5	
	JMP	CLDMAP			;NO NETWORK DISK LEFT
;
	MOV	MSGID,AL		;SET MASTER ID OF NETWORK DISK
	MOV	DX,PARAMT
	MOV	BX,MCRPNT
	CMP	FUNCOD,CSTDPS
	JZ	STXFCD			;SET DEFAULT PASSWORD
	MOV	[BX],DL			;SET COMPATIBILITY ATTRIBUTE
	JMPS	STXFCS			;SO ONE BYTE DATA
;
STXFCD:					;DEFAULT PASS WORD
	MOV	CX,8			;SET DEFAULT PASSWORD
	MOV	DS,INDSEG
	CALL	MSCOPY			;SET PASSWORD
STXFCS:
	CALL	SNDHDR			;SEND
	CALL	RCVPAR			;RECEIVE
	JMPS	STXFCB			;TO NEXT MASTER
;
;   B:DISK ACCESS CONTROL
;
;  37:RESET DRIVE
;  38:ACCESS DRIVE
;  39:FREE DRIVE
;
DSKACC:
	MOV	DX,PARAMT		;GET DISK VECTOR
DSKACL:					;ONE MASTER LOOP
	CALL	GTDMAP			;GET NETWORK DISK
	PUSH	BX
	MOV	AL,CL
	INC	CL
	JNZ	DSKACD			;SET SOME MASTER
	CALL	CLDMAP			;END OF ALL NETWORK DISK, SO CLEAR FLAG
	POP	DX			;GET LEFT DRIVE BIT
	CMP	FUNCOD,CRSDSN
	JNZ	DSKACE			;NOT RESET DRIVE
	MOV	CL,AL			;RESET DRIVE, SO RESET LOCAL DISK
	CALL	TOBDOS
	MOV	OTPARA,AL
DSKACE:
	RET
;
DSKACD:					;GET SOME NETWORK MASTER
	MOV	MSGID,AL		;SAVE MASTER ID
	MOV	BX,OFFSET MSGDAT+2
	MOV	-2[BX],DX		;SET DRIVE BIT MAP
	MOV	MCRPNT,BX
	CALL	SNDHDR			;SEND
	MOV	AL,FUNCOD
	SUB	AL,CACCES
	JZ	DSKACS			;ACCESS DISK
	PUSH	AX
	CALL	RCVPAR			;SIMPLE RECEIVE
	POP	AX
	POP	DX
	DEC	AL
	JZ	DSKACL			;FREEE DISK MODE
	MOV	AL,MSGDAT		;RESET DISK MODE
	MOV	OTPARA,AL
	INC	AL
	JNZ	DSKACL			;TO NEXT MASTER
	JMP	CLDMAP			;ERROR END
;
DSKACS:					;ACCESS DISK
	CALL	RPROCC			;RECEIVE AS *EE* MODE
	POP	DX
	JMPS	DSKACL			;TO NEXT MASTER
;
;  GET NETWORK DISK MAP
;  INPUT
;  DX:TARGET DISK BIT MAP
;  OUTPUT
;  BX:LEFT BIT MAP
;  CL:MASTER ID   -1 NOT NETWORK DISK LEFT
;  DX:DISK BIT MAP OF MASTER
;
GTDMAP:
	MOV	BX,CONTAD
	INC	BX
	PUSH	DX
	MOV	DI,0			;CLEAR MASTER ID BIT MAP
	MOV	DX,10FFH		;DH COUNT   DL MASTER ID
GTDMAL:					;ONE DRIVE LOOP
	MOV	AL,[BX]
	RCL	AL,1
	JNC	GTDMAN			;LOCAL
	RCL	AL,1
	JC	GTDMAN			;ALREADY PROCESSED DRIVE
	CMP	DL,0FFH
	JZ	GTDMAM			;FIRST MASTER
	CMP	DL,1[BX]		;CHECK WITH LAST MASTER
	JNZ	GTDMAN			;DEFFERNT MASTER SO PASS
GTDMAM:					;GET DRIVE
	MOV	DL,1[BX]		;SET MASTER ID
	OR	BYTE PTR [BX],40H	;SET PROCESSED BIT
	POP	AX
	SHR	AX,1			;GET INPUT BIT MAP MODE
	PUSH	AX
	JNC	GTDMAE			;NOT TARGET DRIVE
	MOV	CL,[BX]
	AND	CL,0FH			;GET MASTER DRIVE NUMBER
	INC	CL
	MOV	SI,8000H
	ROL	SI,CL			;GET MASTER DRIVE BIT
	OR	DI,SI			;SET UP MASTER DRIVE BIT MAP
	JMPS	GTDMAE
;
GTDMAN:
	POP	AX
	ROR	AX,1			;ROTATE ONE BIT
	PUSH	AX
GTDMAE:
	INC	BX
	INC	BX
	DEC	DH
	JNZ	GTDMAL			;TO NEXT DRIVE
	MOV	CL,DL
	MOV	DX,DI
	POP	BX
	RET
;
;  RESET PROCESSED MODE BIT OF DISK
;
CLDMAP:
	MOV	BX,CONTAD
	INC	BX
	MOV	CX,16
CLDMAL:					;ONE DISK LOOP
	AND	BYTE PTR [BX],08FH	;OF PROCESSED BIT
	INC	BX
	INC	BX
	LOOP	CLDMAL
	RET
;
;  20:SEARCH FIRST DATA SET UP
;
;  17:SEARCH FIRST
;
SERCHF:
	MOV	FLSRCH,-1		;SET SEARCH MODE TO LOCAL
	MOV	BX,PARAMT		;GET FCB POINT
	PUSH	DS
	MOV	DS,INDSEG		;GET SEGMENT
	CMP	BYTE PTR [BX],'?'
	POP	DS
	JNZ	SERCHA			;NOT ALL DISK
	CALL	SETDRC			;SET DRIVE CODE
	MOV	CL,'?'
	CALL	SETFCS			;SET FCB
	JMPS	SERCHE
;
SERCHA:
	INC	MCRPNT
	CALL	SETFCB			;SET FCB
SERCHE:
	MOV	AL,MSGID
	MOV	FLSRCH,AL		;SET SEARCH MODE
	JMP	SNDHDR
;
;  21:SEARCH NEXT SET UP
;
;  18:SEARCH NEXT
;
SERCHN:
	MOV	AL,FLSRCH		;GET SEARCH MODE
	CMP	AL,0FFH
	JNZ	SERCHS			;NETWORK
	JMP	TBDOSE			;LOCAL
;
SERCHS:
	MOV	MSGID,AL		;SET MASTER ID
	MOV	AL,USRCOD
	MOV	BX,MCRPNT
	INC	BX
	MOV	[BX],AL			;SET USER CODE
	INC	BX
	MOV	MCRPNT,BX
	JMP	SNDHDR			;SEND
;
;   C:RECEIVE PROCESS FOR *EE*  MODE FUNCTIONS
;
;  FOR MANY FUNCTION RECEIVE PROCESS
;
RPROCC:
	CALL	RCVPAR			;RECEIVE
	MOV	BX,OFFSET MSGDAT+1
	MOV	MCRPNT,BX
	MOV	DX,-1[BX]		;GET RETURN CODE
	MOV	OTPARA,DL		;SAVE AS OUTPUT PARAMETER
	MOV	AL,-2[BX]		;GET SIZE
	DEC	AL
	JNZ	RPROCE			;NOT *EE* MODE
	XCHG	BX,DX
	CMP	ERRMOD,-1		;GET BDOS ERROR MODE
	JZ	RPROCN			;SIMPLE RETURN MODE
	PUSH	BX			;OUT ERROR COMMENT
	MOV	DX,OFFSET CNDOSE
	CALL	PMSGLC			;'NDOS ERROR'
	POP	AX
	CALL	PRNUMB			;PRINT ERROR NUMBER
	MOV	DX,OFFSET CNDSER
	CALL	PMSGLC			;', FUNC '
	MOV	AL,FUNCOD
	CALL	PRNUMB			;PRINT FUNCTION
	CMP	ERRMOD,-2
	JNZ	RPROCW			;WARM BOOT
RPROCN:
	JMP	NDENDP			;MESSAGE OUT & RETURN MODE
;
RPROCW:
	JMP	NWBOOT			;WARM BOOT MODE
;
RPROCE:
	RET
;
;  PRINT NUMBER BY HEXADECIMAL
;  INPUT
;  AL:DATA
;
PRNUMB:
	MOV	SI,OFFSET ERRPBF+1
	MOV	AH,AL			;SAVE DATA
	CALL	SETNIB			;SET LOWER NIBBLE
	MOV	AL,AH
	RCR	AL,1
	RCR	AL,1
	RCR	AL,1
	RCR	AL,1
	DEC	SI
	CALL	SETNIB			;SET HIGHER NIBBLE
	MOV	DX,SI
;
;  PRINT MESSAGE
;  INPUT
;  DX:MESSAGE ADDRESS
;
PMSGLC:
	MOV	CL,CBUFPR
	JMP	TOBDOS
;
;   D:RESTORE FCB FOR OPEN/CLOSE
;
;  15:OPEN FILE
;  16:CLOSE FILE
;
RSTFCO:
	CMP	MUNLRW,-1		;GET UNLOCKED R/W MODE
	JNZ	RSTFCB			;NORMAL READ/WRITE
;
;   F:RESTORE FCB FOR RANDOM ACCRESS
;
;  33:READ RANDOM
;  34:WRITE RANDOM
;  35:COMPUTE FILE SIZE
;  36:SET RANDOM RECORD
;  42:LOCK RECORD
;  43:UNLOCK RECORD
;
RSTFCR:
	MOV	CX,35			;WITH RECORD DATA
	JMPS	RSTFCS
;
;   E:RESTORE FCB DATA
;
;  20:READ SEQUENTIAL
;  21:WRITE SEQUENTIAL
;  30:SET FILE ATTRIBUTE
;
RSTFCB:
	MOV	CX,32
RSTFCS:
	CALL	RSTNAM			;RESTORE NAME
	MOV	SI,BX
	INC	SI
	MOV	DI,PARAMT		;FCB TOP
	INC	DI
	MOV	ES,INDSEG		;FCB SEGMENT
;
;  RESTORE DATA FROM MESSAGE AREA TO USER AREA
;  INPUT
;  SI:SOURCE AREA		DS:SEGMENT
;  DI:DESTINATION AREA		ES:SEGMENT
;  CX:COUNT
;  OUTPUT
;  ES:CS
;
RSTDAT:
	CLD
	REP	MOVSB
	MOV	MCRPNT,SI		;SAVE NEXT POINT
	MOV	SI,CS
	MOV	ES,SI			;RESTORE SEGMENT
	RET
;
;  RESTORE FILE NAME OF TEMPORARY OR SUBMIT
;  OUTPUT
;  BX:MESSAGE POINT	FCB TOP
;
RSTNAM:
	MOV	BX,MCRPNT		;FCB DATA TOP
	MOV	AL,MMODIF		;GET MODIFIED MODE
	RCR	AL,1
	RCR	AL,1
	JNC	RSTNAT
	MOV	WORD PTR 2[BX],'$$'
RSTNAT:
	RCL	AL,1
	JNC	RSTNAE			;NO TYPE MODIFIED
	MOV	WORD PTR 10[BX],'$$'	;RESTORE TYPE
RSTNAE:
	RET
;
;  10:GET DIRECTORY DATA TO DMA BUFFER
;
;  17:SEARCH FIRST
;  18:SEARCH NEXT
;
GTDRDT:
	MOV	AL,OTPARA
	INC	AL
	JZ	RSTNAE			;NOT FOUND
	DEC	AL
	MOV	CL,5
	SHL	AL,CL			;*32
	MOV	DI,DMAADD		;DESTNATION OFFSET
	ADD	DI,AX			;GET DESTINATION POINT
	MOV	SI,MCRPNT
	MOV	ES,DMASEG		;DESTINATION SEGMENT
	MOV	CX,32
	JMP	RSTDAT			;RESTORE DATA
;
;  11:GET READ DATA
;
;  20:EAD SEQUENTIAL
;  33:READ RANDOM
;
GTRDDT:
	TEST	OTPARA,-1
	JNZ	RSTNAE			;ERROR
	MOV	SI,OFFSET MSGDAT+37
	MOV	DI,DMAADD		;DESTINATION OFFSET
	MOV	CX,SCTLNG		;SECTOR LENGTH
	MOV	ES,DMASEG		;DESTINATION SEGMENT
	JMP	RSTDAT			;COPY READ DATA
;
;  12:GET VECTOR DATA
;
;  27:GET ALLOCATION VECTOR
;  31:GET DISK PARAMETER ADDRESS
;  71:GET SERVER CONFIGRATION TABLE
;
GTVCDT:
	MOV	BX,MCRPNT
	DEC	BX
	MOV	AL,FUNCOD
	CMP	AL,CGTALC
	JZ	GTVCSE			;GET ALLOCATION VECTOR ADDRESS
	CMP	AL,CGTDPA
	JNZ	GTVCSV			;GET SERVER CONFIGRATION TABLE
	MOV	DI,OFFSET BFDPBK	;GET DISK PARAMETER ADDRESS
	MOV	CX,16
	JMPS	GTVCSS			;COPY DISK PARAMETER TO BUFFER
;
GTVCSV:					;SERVER CONFIGRATION TABLE
	MOV	DI,OFFSET BFSVCT
	MOV	CX,23			;MOVE CONFIGRATION DATA TO BUFFER
GTVCSS:
	PUSH	DI
	MOV	SI,BX
	CALL	RSTDAT			;MOVE DATA
	POP	BX			;RESTORE BUFFER TOP
GTVCSE:
	MOV	OTPARA,BL		;SAVE VECTOR
	RET
;
;  13:MAKE UP DRIVE VECTOR
;
;  24:RETURN LOGIN VECTOR
;  29:GET R/O VECTOR
;
MKDRVC:
	MOV	SI,CONTAD
	ADD	SI,31			;GET BOTTOM POINT OF DRIVE DATA
	MOV	CX,16			;DRIVE COUNT
MKDRVL:					;ONE DRIVE LOOP
	STD
	LODSW				;GET MASTER ID & DRIVE CODE
	SHL	BX,1			;UP DRIVE VECTOR
	CALL	MKDRON			;CHECK ONE DRIVE
	LOOP	MKDRVL			;TO NEXT DRIVE
	MOV	OTPARA,BL		;SET LOWER BYTE
	RET
;
;  CHECK ONE DRIVE MODE
;  INPUT
;  AL:DRIVE CODE
;  AH:MASTER ID
;  BX:VECTOR
;  OUTPUT
;  BX:NEW VECTOR
;
MKDRON:
	PUSH	SI
	PUSH	CX
	PUSH	BX
	RCL	AL,1
	JC	MKDROT			;NET DRIVE
	PUSH	CX			;LOCAL DRIVE
	CALL	TBDOSP			;SO CHECK LOCAL
	POP	CX
	DEC	CX
	XCHG	BX,DX
	JMPS	MKDROS
;
MKDROT:					;NET DRIVE
	RCR	AL,1
	AND	AL,0FH			;GET DRIVE IN MASTER
	MOV	CL,AL
	MOV	MSGID,AH		;SET MASTER ID
	MOV	BX,OFFSET MSGDAT
	MOV	MCRPNT,BX
	PUSH	CX
	CALL	SNDHDR			;SEND REQUEST
	CALL	RCVPAR			;GET DATA
	POP	CX
	MOV	BX,MCRPNT
	MOV	DX,[BX]			;GET VECTOR
MKDROS:
	JCXZ	MKDROE
	ROR	DX,CL			;TO CURRENT DRIVE BIT POINT
MKDROE:
	AND	DX,1			;GET TARGET DRIVE BIT
	POP	BX
	OR	BX,DX			;SET CURRENT BIT	
	POP	CX
	POP	SI
	RET
;
;  14:SET DMA ADDRESS
;
;  26:SET DMA ADDRESS
;
SETDMA:
	MOV	BX,PARAMT
	MOV	DMAADD,BX
SETDMB:
	JMP	TBDOSP
;
;  15:SELECT DISK
;
;  14:SELECT DISK
;
SELDSK:
	MOV	DL,PARAMB
	MOV	CURDSK,DL
	CALL	GETDPT			;GET DISK PARAMETER POINT
	CMP	AL,0FFH
	JZ	SETDMB			;LOCAL
	MOV	BX,MCRPNT		;NETWORK DRIVE
	DEC	CL
	MOV	[BX],CL			;SET DRIVE
	INC	BX
	MOV	MCRPNT,BX
	CALL	SNDHDR			;SEND
	JMP	RPROCC			;RECEIVE
;
;  19:RESET DISK
;
;  13:RESET DISK
;
RSTDSK:
	MOV	PARAMB,0
	MOV	AL,CSELDK
	MOV	FUNCOD,AL
	MOV	MSGFUN,AL		;SET SELECT DISK FUNCTION
	MOV	MCRPNT,OFFSET MSGDAT
	CALL	SELDSK
	MOV	BX,CONTAD
	TEST	BYTE PTR 1[BX],80H	;GET HOME DISK MODE
	JNZ	RSTDSS			;HOME DISK IS NEWORK
	MOV	CL,CRSDSK		;HOME DISK IS LOCAL
	CALL	TOBDOS			;RESET LOCAL DRIVE
	MOV	OTPARA,AL
	RET
;
RSTDSS:					;HOME DISK IS NETWORK
	MOV	BX,BDSYSA		;BDOS SYSTEM ADDRESS
	MOV	BYTE PTR BDCUDK[BX],0	;CLEAR CURRENT DISK
	MOV	BYTE PTR BDCUDR[BX],0	;CLEAR CURRENT DRIVE
RSTDSE:
	MOV	DX,-1
	MOV	CL,CRSDSN
	JMP	TOBDOS			;RESET ALL LOCAL DISK
;
;  16:SET/GET USER CODE
;
;  32:SET/GET USER CODE
;
STGTUC:
	MOV	DL,PARAMB
	CMP	DL,0FFH
	MOV	BX,OFFSET USRCOD
	MOV	AL,[BX]			;GET CURRENT USER CODE
	MOV	OTPARA,AL
	JZ	GETVEE			;INTEROGATE MODE
	MOV	[BX],DL			;SET USER CODE
	JMP	TBDOSP			;SET USER CODE OF LOCAL
;
;  17:GET VERSION NUMBER
;
;  12:RETURN VERSION NUMBER
;
GETVER:
	MOV	BX,VERSION
	OR	BH,2			;MAKE TO CP/NET VERSION
	MOV	OTPARA,BL
GETVEE:
	RET
;
;  18:GET CURRENT DISK
;
;  25:GET CURRENT DISK
;
GETCDK:
	MOV	AL,CURDSK
	MOV	OTPARA,AL
	RET
;
;  1A:GET NETWORK STATUS
;
;  68:GET NETWORK STATUS
;
GNTWKS:
	CALL	NTWKST			;GET STATUS BY SNIOS ROUTINE
	MOV	OTPARA,AL
	RET
;
;  1B:GET CONFIGURATION TABLE
;
;  69:GET CONFIGURATION TABLE
;
GCNFTB:
	CALL	CNFTBL			;GET CONFIGRATION TABLE POINT
	MOV	OTPARA,BL
	RET
;
;  1E:LOGIN
;
;  64:LOGIN
;
LOGIN:
	MOV	DX,MCRPNT		;MESSAGE POINT
	MOV	BX,PARAMT
	MOV	DS,INDSEG		;PASSWORD SEGMENT
	MOV	AL,[BX]
	MOV	CS:MSGID,AL		;SET MASTER ID
	INC	BX
	XCHG	BX,DX
	MOV	CX,8
	CALL	MSCOPY			;SET PASSWORD
	JMP	SNDHDR
;
;  1F:LOGOFF
;
;  65:LOGOFF
;  71:SET SERVER CONFIGURATION
;
LOGOFF:
	MOV	AL,PARAMB
	MOV	MSGID,AL
	JMP	SNDHDR
;
;  1C:SEND MESSAGE
;
;  66:SEND MESSAGE
;
SENDMS:
	MOV	CX,PARAMT		;OFFSET
	MOV	DS,INDSEG		;SEGMENT
	JMP	SDMSGE
;
;  1D:RECEIVE MESSAGE
;
;  67:RECEIVE MESSAGE
;
RECVMS:
	MOV	CX,PARAMT		;OFFSET
	MOV	DS,INDSEG		;SEGMENT
	JMP	RVMSGE
;
;  22:SET BDOS ERROR MODE
;
;  45:SET BDOS ERROR MODE
;
STBDEM:
	MOV	AL,PARAMB
	MOV	ERRMOD,AL
	RET
;
;  23:CHAIN TO PROGRAM
;
;  47:CHAIN TO PORGRAM
;
CHAIN:
	PUSH	DS
	MOV	CX,128
	MOV	DI,CCPTOP		;GET CCP TOP
	ADD	DI,COMBUF+2
	MOV	BX,DI			;SAVE PONT
	MOV	SI,DMAADD
	MOV	DS,DMASEG		;SOURCE SEGMENT
	CLD
CHAINL:					;MOVE LOOP
	LODSB
	STOSB				;MOVE
	OR	AL,AL
	LOOPNZ	CHAINL			;TO NEXT
	MOV	AL,127
	SUB	AL,CL			;GET LENGTH
	POP	DS			;RESTORE SEGMENT
	MOV	-1[BX],AL		;SET LENGTH
	XOR	DX,DX
	MOV	CL,CRESET
	JMP	BDOSE			;DIRECT RETURN TO WARM BOOT ROUTINE
;
;  24:SET DMA SEGMENT
;
;  51:SET DMA SEGMENT
;
SETDMS:
	MOV	BX,PARAMT
	MOV	DMASEG,BX		;SET SEGMENT
	JMP	TBDOSP			;TO BDOS
;
;  BIOS TRAP ROUTINES
;
;  CONSOLE STATUS
;
NCONST:
	MOV	BX,BCONST
	MOV	DX,CCONST		;CONSOLE STATUS FUNCTION CODE
	JMP	NCONCM
;
;  CONSOLE INPUT
;
NCONIN:
	MOV	BX,(OFFSET NCONIE)
	PUSH	BX			;CHECK CONTROL-P
	MOV	BX,BCONIN
	MOV	DX,CCNDIN		;CONSOLE INPUT WITH DEVICE CODE
	JMP	NCONCM
;
;  CHECK CONTROL-P MODE IN CONSOLE INPUT
;
NCONIE:
	PUSH	AX
	CMP	AL,'P'-40H
	JNZ	NCONIF			;NOT CONTROL-P SO END
	MOV	AL,MRDCBF
	OR	AL,AL
	JZ	NCONIF			;NOT READ CONSOLE BUFFER MODE
	MOV	BX,CONTAD
	DEC	BX
	TEST	MDPREC,-1		;GET CURRENT MODE
	JZ	NCONIO			;TO ON
	MOV	MDPREC,0		;TO OFF
	AND	BYTE PTR [BX],0FBH	;OFF CONTROL-P MODE IN NETWORK STATUS
	ADD	BX,BLIST+1
	MOV	CL,-1
	TEST	BYTE PTR [BX],80H	;GET LSITER MODE
	JNC	$+5			;LOCAL LIST
	CALL	NLIST			;CLOSE IF NETWORK LIST
	MOV	MDPROT,0		;CLEAR LIST BUFFER MODE
	MOV	BX,'FF'
	MOV	WORD PTR CCNTRS,BX
	JMPS	NCONIP			;'CTL-P OFF'
;
NCONIO:					;TO ON
	NOT	MDPREC			;SET ON MODE
	OR	BYTE PTR [BX],4		;SET STATUS BIT
	MOV	BX,'N'
	MOV	WORD PTR CCNTRS,BX	;'CTL-P ON'
NCONIP:
	MOV	BX,OFFSET CCNTRP
NCONIL:
	MOV	CL,[BX]
	PUSH	BX
	CALL	NCONOT
	POP	BX
	INC	BX
	TEST	BYTE PTR [BX],-1
	JNZ	NCONIL			;TO NEXT
NCONIF:					;END OF CONTROL-P CHECKING
	POP	AX
	RET
;
;  CONSOLE OUTPUT
;  INPUT
;   C:DATA
;
NCONOT:
	MOV	BX,BCONOT
	MOV	DX,100H+CCNDOT		;COUNT & CODE
;
;  CONSOLE I/O COMMON ROUTINE
;  INPUT
;  BX:BIOS ROUTINE ADDRESS
;  DL:FUNCTION CODE OF NETWORK
;  DH:SIZE
;
NCONCM:
	PUSH	BX			;SET BIOS ROUTINE VECTOR
	MOV	BX,CONTAD
	ADD	BX,BSCONS
	MOV	AL,[BX]			;GET CONSOLE MODE
	TEST	AL,80H
	JZ	NCONCE			;LOCAL  SO TO BIOS ROUTINE
	AND	AL,00FH			;GET CONSOLE NUMBER
	MOV	CH,AL			;SAVE CONSOLE NUMBER
	INC	BX
	MOV	AL,[BX]			;GET MASTER ID
	MOV	BX,OFFSET MSGTOP
	MOV	BYTE PTR [BX],FSEND	;FORMAT CODE TO SEND
	INC	BX
	MOV	[BX],AL			;DESTINATION ID
	POP	SI			;OFF BIOS VECTOR
	MOV	SI,CONTAD
	MOV	AL,[SI]			;GET SLAVE ID
	INC	BX
	MOV	[BX],AL			;SET SLAVE ID
	INC	BX
	MOV	[BX],DX			;SET FUNCTION & SIZE
	INC	BX
	INC	BX
	MOV	[BX],CH			;SET MASTER CONSOLE NUMBER
	INC	BX
	MOV	[BX],CL			;SET DATA
	MOV	CX,OFFSET MSGTOP
	CALL	SDMSGE			;SEND
	MOV	CX,OFFSET MSGTOP
	CALL	RVMSGE			;RECEIVE
	MOV	AL,MSGDAT		;GET RETUNR PARAMETER
NCONCE:
	RET
;
;  LIST OUT
;
NLIST:
	MOV	MDPROT,-1		;SET PRINT OUT MODE
	MOV	BX,CONTAD
	ADD	BX,BSLIST
	MOV	AL,[BX]			;GET LISTER MODE
	TEST	AL,80H
	JNZ	NLISTN			;NETWORK
	JMP	BLIST			;LOCAL
;
NLISTN:					;ON NETWORK
	AND	AL,00FH
	MOV	LSTUNT,AL		;SAVE UNIT CODE
	PUSH	CX
	MOV	AL,CL
	INC	BX
	INC	BX
	MOV	CL,[BX]			;GET COUNT
	INC	BYTE PTR [BX]		;COUNT UP
	CMP	CL,SCTLNG-1		;ONE SECTOR LENGTH
	JZ	NLISTB			;SECTOR BOUNDARY
	CMP	AL,EOF
	JNZ	NLISTS			;NOT END OF FILE
NLISTB:
	XOR	AL,AL
	MOV	[BX],AL			;CLEAR COUNT FOR SEND
	MOV	MDPROT,AL		;CLEAR PRINT OUT MODE
NLISTS:
	LAHF
	ADD	BX,7
	MOV	CH,0
	ADD	BX,CX
	SAHF
	POP	DX
	MOV	[BX],DL			;SET DATA
	JNZ	NCONCE			;NOT TRANSFER MODE
	MOV	BX,CONTAD		;TRANSFER ONE BLOCK
	ADD	BX,BSLIST+3		;LISTER OUT MESSAGE TOP
	MOV	AL,-2[BX]		;GET LISTER MASTER ID
	MOV	1[BX],AL		;SET MASTER ID
	INC	CL
	MOV	4[BX],CL		;SET SIZE
	MOV	AL,LSTUNT
	MOV	5[BX],AL		;SET UNIT CODE
	MOV	CX,BX
	CALL	SDMSGE			;SEND
	MOV	CX,OFFSET MSGTOP
	JMP	RVMSGE			;RECEIVE
;
;  LIST STATUS
;
NLSTST:
	MOV	BX,CONTAD
	ADD	BX,BSLIST
	MOV	AL,[BX]
	RCL	AL,1
	JC	NGTMRE			;ON NETWORK
	JMP	BLSTST			;LOCAL
;
;  GET MEMORY REGION TABLE
;
NGTMRT:
	CALL	BGTMRT			;GET BY BIOS ROUTINE
	MOV	CL,[BX]			;GET COUNT
	MOV	CH,0
	SHL	CX,1
	SHL	CX,1			;*4
	INC	CX			;GET MAP LENGTH
	MOV	AX,CS
	MOV	ES,AX
	MOV	DI,OFFSET MRTBL
	MOV	SI,BX			;SOURCE POINTER
	CLD
	REP	MOVSB			;GET IN BUFFER
	CALL	NTWKEN			;GET SNIOS END POINT
	ADD	BX,255
	AND	BX,0FF00H
	MOV	CL,4
	SHR	BX,CL			;GET SIZE BY PARAGRAPH
	MOV	AX,CS
	ADD	AX,BX			;GET END PARAGRAPH
	MOV	BX,OFFSET MRTBL+1
	MOV	DX,[BX]
	MOV	[BX],AX			;SET LEFT REGION TOP
	SUB	AX,DX
	MOV	DX,2[BX]
	SUB	DX,AX			;GET LEFT SIZE
	MOV	2[BX],DX		;SET LENGTH
	DEC	BX
NGTMRE:
	RET
;
;  SET BIOS TRAP
;
STBITP:
	MOV	BX,BIOSTP		;BIOS TRAP OFFSET
	MOV	CX,19			;ROUTINE COUNT
	MOV	SI,OFFSET TLBIOS	;TRAP POINTER TABLE
STBITL:					;ONE BLOCK LOOP
	ADD	BX,3
	MOV	DX,[SI]			;GET TRAP ROUTINE POINTER
	OR	DX,DX
	JZ	STBITS			;NO TRAP
	MOV	AX,-2[BX]		;GET DISPLACEMENT
	ADD	AX,BX			;GET OFFSET
	MOV	[SI],AX			;SAVE ADDRESS OF ORIGINAL ROUTINE
	SUB	DX,BX			;MAKE DISPLACEMENT
	MOV	-2[BX],DX		;SAVE TRAP ROUTINE DISPLACEMENT
STBITS:
	ADD	SI,2
	LOOP	STBITL			;TO NEXT ROUTINE
	RET
;
;
DTAREA	EQU	$
	DSEG
	ORG	OFFSET DTAREA
;
;  MAIN ROUTINE INDEX OF MACRO
;
IXMAIN:
	DW	NWBOOT			; 0 WARM BOOT  NOT USED
	DW	SNDHDR			; 1 SEND MESSAGE WITH HEADER SET UP
	DW	RCVPAR			; 2 RECEIVE MESSAGE WITH POINTER INIT
	DW	STFCBS			; 3 SET FCB & SEND
	DW	SETFCB			; 4 SET FCB DATA
	DW	CHKSFC			; 5 CHECK SECOND FCB
	DW	STLKRN			; 6 SET LOCK/UNLOCK RECORD
	DW	STPWRD			; 7 SET FILE PASSWORD & SEND
	DW	WTDTCP			; 8 SET ONE SECTOR DATA & SEND
	DW	SETDRC			; 9 SET DRIVE CODE
	DW	STXFCB			; A SET FCB EXTENDED DATA
	DW	DSKACC			; B DISK ACCESS CONTROL
	DW	RPROCC			; C RECEIVE PROCESS
	DW	RSTFCO			; D RESTORE FCB FOR OPEN/CLOSE
	DW	RSTFCB			; E RESTORE FCB
	DW	RSTFCR			; F RESTORE FCB FOR RANDOM
	DW	GTDRDT			;10 GET DIRECTORY DATA TO DMA BUFFER
	DW	GTRDDT			;11 GET READ DATA
	DW	GTVCDT			;12 GET VECTOR DATA
	DW	MKDRVC			;13 MAKE UP DRIVE VECTOR
	DW	SETDMA			;14 SET DMA ADDRESS
	DW	SELDSK			;15 SELECT DISK
	DW	STGTUC			;16 SET/GET USER CODE
	DW	GETVER			;17 GET VERSION NUMBER
	DW	GETCDK			;18 GET CURRENT DISK
	DW	RSTDSK			;19 RESET DISK
	DW	GNTWKS			;1A GET NETWORK STATUS
	DW	GCNFTB			;1B GET CONFIGURATION TABLE POINT
	DW	SENDMS			;1C SEND MESSAGE 
	DW	RECVMS			;1D RECEIVE MESSAGE
	DW	LOGIN			;1E LOGIN
	DW	LOGOFF			;1F LOGOFF
	DW	SERCHF			;20 SEARCH FIRST
	DW	SERCHN			;21 SEARCH NEXT
	DW	STBDEM			;22 SET BDOS ERROR MODE
	DW	CHAIN			;23 CHAIN TO PROGRAM
	DW	SETDMS			;24 SET DMA SEGMENT
;
;  ROUTINE MACRO TABLE
;
IXMACR:
	DB	17H*2+80H		; 1 RETURN VERSION NUMBER
;
	DB	19H*2+80H		; 2 RESET DISK
;
	DB	0BH*2+80H		; 3 RESET, ACCESS, FREE DISK
;
	DB	15H*2+80H		; 4 SELECT DISK
;
	DB	4H*2			; 5 OPEN, CLOSE, MAKE
	DB	7H*2
	DB	0CH*2
	DB	0DH*2+80H
;
	DB	03H*2			; 9 DELETE
	DB	0CH*2+80H
;
	DB	20H*2			; B SEARCH FIRST
	DB	0CH*2
	DB	10H*2+80H
;
	DB	21H*2			; E SEARCH NEXT
	DB	0CH*2
	DB	10H*2+80H
;
	DB	03H*2			;11 READ SEQUENTIAL
	DB	0CH*2
	DB	0EH*2
	DB	11H*2+80H
;
	DB	04H*2			;15 WRITE SEQUENTIAL
	DB	08H*2
	DB	0CH*2
	DB	0EH*2+80H
;
	DB	04H*2			;19 RENAME
	DB	05H*2
	DB	01H*2
	DB	0CH*2+80H
;
	DB	13H*2+80H		;1D LOGIN, R/O VECTOR
;
	DB	18H*2+80H		;1E GET CURRENT DISK
;
	DB	14H*2+80H		;1F SET DMA
;
	DB	9H*2			;20 GET ALL MAP, DISK PBLK
	DB	1H*2
	DB	0CH*2
	DB	12H*2+80H
;
	DB	09H*2			;24 WRITE PROTECT DISK
	DB	1H*2
	DB	0CH*2+80H
;
	DB	03H*2			;27 SET FILE ATTRIBUTE
	DB	0CH*2
	DB	0EH*2+80H
;
	DB	16H*2+80H		;2A SET/GET USER CODE
;
	DB	03H*2			;2B READ RANDOM
	DB	0CH*2
	DB	0FH*2
	DB	11H*2+80H
;
	DB	04H*2			;2F WRITE RANDOM, WRITE RANDOM WITH ZERO FILL
	DB	08H*2
	DB	0CH*2
	DB	0FH*2+80H
;
	DB	3H*2			;33 COMPUTE FILE SIZE, SET RANDOM RECORD
	DB	0CH*2
	DB	0FH*2+80H
;
	DB	4H*2			;36 LOCK, UNLOCK RECORD
	DB	06H*2
	DB	0CH*2
	DB	0FH*2+80H
;
	DB	22H*2+80H		;3A SET BDOS ERROR MODE
;
	DB	0AH*2+80H		;3B SET DEFAULT PASSWORD
;
	DB	1EH*2			;3C LOGIN
	DB	0CH*2+80H
;
	DB	1FH*2			;3E LOGOFF
	DB	0CH*2+80H
;
	DB	1CH*2+80H		;40 SEND MESSAGE
;
	DB	1DH*2+80H		;41 RECEIVE MESSAGE
;
	DB	1AH*2+80H		;42 GET NETWORK STATUS
;
	DB	1BH*2+80H		;43 GET CONFIGURATION TABLE
;
	DB	0AH*2+80H		;44 SET COMPATIBILITY ATTRIBUTE
;
	DB	1FH*2			;45 GET SERVER CONFIGURATION
	DB	0CH*2
	DB	12H*2+80H
;
	DB	23H*2+80H		;48 CHAIN TO PROGRAM
;
	DB	24H*2+80H		;49 SET DMA SEGMENT
;
;  FUNCTION INDEX
;   0:NO PROCESS IN NDOS
;  -1:NOT IMPLEMENTED
;  XX:MACRO INDEX ENTRY
;
IXFUNC:
	DB	0			; 0 SYSTEM RESET
	DB	0			; 1 CONSOLE INPUT
	DB	0			; 2 CONSOLE OUTPUT
	DB	0			; 3 READER INPUT
	DB	0			; 4 PUNCHER OUTPUT
	DB	0			; 5 LIST OUTPUT
	DB	0			; 6 DIRECT CONSOLE I/O
	DB	0			; 7 GET I/O BYTE
	DB	0			; 8 SET I/O BYTE
	DB	0			; 9 PRINT STRING
	DB	0			;10 READ CONSOLE BUFFER
	DB	0			;11 GET CONSOLE STATUS
	DB	1			;12 RETURN VERSION NUMBER
	DB	2			;13 RESET DISK
	DB	4			;14 SELECT DISK
	DB	5			;15 OPEN FILE
	DB	5			;16 CLOSE FILE
	DB	0BH			;17 SEARCH FIRST
	DB	0EH			;18 SEARCH NEXT
	DB	9			;19 DELETE FILE
	DB	11H			;20 READ SEQUENTIAL
	DB	15H			;21 WRITE SEQUENTIAL
	DB	5			;22 MAKE FILE
	DB	19H			;23 RENAME
	DB	1DH			;24 RETURN LOGIN VECTOR
	DB	1EH			;25 RETURN CURRENT DISK
	DB	1FH			;26 SET DMA ADDRESS
	DB	20H			;27 GET ALLOCATION VECTOR
	DB	24H			;28 WRITE PROTECT DISK
	DB	1DH			;29 GET R/O VECTOR
	DB	27H			;30 SET FILE ATTRIBUTE
	DB	20H			;31 GET DISK PARAMETER BLOCK
	DB	2AH			;32 SET/GET USER CODE
	DB	2BH			;33 READ RANDOM
	DB	2FH			;34 WRITE RANDOM
	DB	33H			;35 COMPUTE FILE SIZE
	DB	33H			;36 SET RANDOM RECORD
	DB	3			;37 RESET DRIVE
	DB	3			;38 ACCESS DRIVE
	DB	3			;39 FREE DRIVE
	DB	2FH			;40 WRITE RANDOM WITH ZERO FILL
	DB	0FFH			;41 TEST & WRITE RECORD
	DB	36H			;42 LOCK RECORD
	DB	36H			;43 UNLOCK RECORD
	DB	0FFH			;44 SET MULT-SECTOR COUNT
	DB	3AH			;45 SET BDOS ERROR MODE
	DB	0FFH			;46 GET DISK FREE SPACE
	DB	48H			;47 CHAIN TO PROGRAM
	DB	0			;48 FLUSH BUFFER
	DB	0			;49 GET SYSTEM ADDRESS
	DB	0			;50 DIRECT BIOS CALL
	DB	49H			;51 SET DMA SEGMENT
	DB	0			;52 GET DMA SEGMENT
	DB	0			;53 GET MAXIMUM MEMORY
	DB	0			;54 GET ABSOLUTE MEMORY
	DB	0			;55 ALLOCATE MEMORY
	DB	0			;56 ALLOCATE ABSOLUTE MEMORY
	DB	0			;57 FREE SPECIFIED MEMORY
	DB	0			;58 FREE ALL MEMORY
	DB	0			;59 LOAD PROGRAM
	DB	-1			;60 ------------
	DB	-1			;61 ------------
	DB	-1			;62 ------------
	DB	-1			;63 ------------
	DB	3CH			;64 LOGIN
	DB	3EH			;65 LOGOFF
	DB	40H			;66 SEND MESSAGE
	DB	41H			;67 RECEIVE MESSAGE
	DB	42H			;68 NETWORK STATUS
	DB	43H			;69 GET CONFIGURATION TABLE
	DB	44H			;70 SET COMPATIBILITY ATTRIBUTE
	DB	45H			;71 GET SERVER CONFIGURATION
	DB	3BH			;106 SET DEFAULT PASSWORD
;
;  COMMENTS
;
CSTFIL	DB	'INITIALIZE ERROR$'	;SNIOS INITIALIZE ERROR
CCNTRP	DB	'CTL-P O'		;COMMENT FOR CONTROL-P
CCNTRS	DB	'FF',0
CNDOSE	DB	CR,LF,'NDOS ERR $'	;NDOS FUNCTION ERROR
CNDSER	DB	', FUNC $'
ERRPBF	DB	0,0,'$'			;ERROR NUMBER PRINT BUFFER
ERRMOD	DB	0			;BDOS ERROR MODE	-1 RETURN
;
;  BIOS ROUTINE TABLE  0 NOT TRAP IN NDOS
;
TLBIOS:
	DW	0			;COLD BOOT
	DW	NWBOOT			;WARM BOOT
BCONST	DW	NCONST			;CONSOLE STATUS
BCONIN	DW	NCONIN			;C_NSOLE INPUT
BCONOT	DW	NCONOT			;CONSOLE OUTPUT
BLIST	DW	NLIST			;LIST OUT
	DW	0,0,0,0,0,0,0,0,0
BLSTST	DW	NLSTST			;LIST STATUS
	DW	0,0
BGTMRT	DW	NGTMRT			;GET MEMORY REGION TABLE
;
;  PARAMETER AREA
;
CONTAD	DW	0			;CONFIGURATION TABLE ADDRESS
CCPTOP	DW	0			;CCP TOP ADDRESS
BDOSE	DW	0			;BDOS ENTRY ADDRESS
BDSYSA	DW	0			;BDOS SYSTEM AREA
VERSION	DW	0			;VERSION NUMBER
FLSRCH	DB	0			;SEARCH MODE  -1 LOCAL OTHER MASTER ID
	DW	0
;
;  DOS WORKING
;
USTACK	DW	0			;USER STACK OFFSET
USTKSG	DW	0			;USER STACK SEGMENT
ENTSTK	DW	0			;NDOS PROCESS ENTRY STACK
FUNCOD	DB	0			;FUNCTION CODE
PARAMT	DW	0			;INPUT PARAMETER
PARAMB	EQU	BYTE PTR PARAMT
OTPARA	DB	0			;OUTPUT PARAMETER
INDSEG	DW	0			;INPUT DATA SEGMENT
CURSEG	DW	0			;OUTPUT SEGMENT
;
MCRPNT	DW	0			;MESSAGE DATA POINTER
LSTUNT	DB	0			;LISTER UNIT IN MASTER
MUNLRW	DB	0			;UNLOCKED R/W MODE
MMODIF	DB	0			;FILE NAME MODIFY MODE B0 TYPE  B1 NAME
BIOSEN	DW	0			;BIOS ENTRY POINT
CURDSK	DB	1			;CURRENT DISK BY ENTRY TYPE
DMAADD	DW	0			;DMA OFFSET
DMASEG	DW	0			;DMA SEGMENT
USRCOD	DB	0			;USER CODE
;
;  MESSAGE DATA AREA
;
MSGTOP:					;MESSAGE AREA TOP
	DB	0			;MESSAGE FORMAT CODE
MSGID	DB	0			;DESTINATION DEVICE ID
	DB	0			;SOURCE DEVICE ID
MSGFUN	DB	0			;FUNCTION CODE
MSGSIZ	DB	0			;MESSAGE SIZE -1
MSGDAT	RB	256			;DATA BUFFER
;
;
BFDPBK	RS	15			;DISK PARAMETER READ BUFFER
BFSVCT	RS	23			;SERVER CONFIGRATION TABLE
MRTBL	RS	65			;MEMORY REGION TABLE
;
;  STACK AREA
;
	RS	64
STACK:
;
;
	ORG	((OFFSET $+255) AND 0FF00H)-1
	DB	0			;END OF NDOS
;
;
NIOS	EQU	$
	CSEG
	ORG	OFFSET NIOS
SNIOS:
;
;  SINOS ROUTINES
;
NTWKIN	EQU	SNIOS			;INITIALIZE NETWORK INTERFACE
NTWKST	EQU	SNIOS+3			;GET NETWORK STATUS
CNFTBL	EQU	SNIOS+6			;GET CONFIGRATION TABLE POINT
SNDMSG	EQU	SNIOS+9			;SEND MESSAGE  CX,DS:MESSAGE BUFFER
RCVMSG	EQU	SNIOS+12		;RECEIVE MESSAGE CX,DS:MESSAGE BUFFER
NTWKER	EQU	SNIOS+15		;ERROR
NTWKBT	EQU	SNIOS+18		;BOOT
NTWKEN	EQU	SNIOS+21		;GET END ADDRESS OF SNIOS
;
;
	END
