;   							>>B/S<<
;	MASTER DOS MODULE
;
;	00.13 12/20/77 EH
;	00.17 1/7/78   RLR
;	00.32 4/28/78 RLR
;	00.50 5/10/78 RLR
;	01.01 5/30/78 RLR
;	01.02 10/78 RLR
;	01.05 5/78 rlr
;	02.00 1/80 RLR
;	02.07K 4/80 KRS
;	02.10 6/80 KRS
;	02.14 7/80 artib byte
;	02.20 7/80 krs cp/m 2.0 etc
;	02.32 11/13/80 rlr spllst
;	02.33 11/20/80 rlr cpm 2 fixes
;	02.34 12/24/80 krs 
;	02.35 4/13/81 RLR WITH NET,10/81 DEW MACROS
;	02.36 12/30/81 rlr - C3 special
;	02.37 2/82 krs - new master version w/subs
;	02.39 6/82 SBW - Remove call to GETDPB from RALCV (DOS 27 call)
;	02.40 8/5/82 sbw - Save HL at system abort, remove buffer defs
;       02.41 11/1/82 blc - ROMable version.
;
	icl	pdef		;02.39
	icl	df		;02.39
	df.dos			;02.39
	df.cpu			;02.39
	df.sys			;02.39
;
	NAM	DOS237
;
c3ver	equ	0	; 0 = not c3
;
	ENT	DOS
	ENT	ABORT,UCB                               ;02.41
	ENT	SAVAF,DOSEND				;02.35
	ENT	STCLC,SYABT                             ;02.41
	ENT	SETPRC                                  ;02.41
	ent	dosb			;02.20          ;02.41
	ENT	DSKFN					;02.37
;
	ext	opihl						;02.40
	EXT	CONPRY
        ext     urreg                                   ;02.41
	EXT	RDCLK,SDT                               ;02.41
	EXT	LOGVC,DSKVC,GDIRST                      ;02.41
	EXT	RDCNE,NAMFB,NEGHL
	EXT	PLINK,MULX,DIVX		; UPDIR REMOVED	 02.20
	EXT	LOGDK,DSKIO,CLRDK
	EXT	SYC01,SYC02,SYC03,SYC04,SYC05
	EXT	SYC07,SYC08,SYC09,SYC10,SYC11
	EXT	DRSCH,NXDIR,DELFL,CRFIL,RENFL
	EXT	FOPN,FCLOS,RDFIL,WRFIL
	EXT	ATBFL,RDLABL,GETDK
	EXT	WBOOT,DIV16,ERMSG			;02.35
	EXT	CSET,VERSION,BYE
	EXT	CLKCB,SCLK,OSTYPE
	EXT	SPLCTL,spllst,OPLINK                    ;02.32
	ext	rodvc,dostk				;02.14
	ext	syc06,wrtptx,atrix,ranrd		;02.20
	ext	ranwr,cfsiz,ranst			;02.20
	ext	setbot,readnv,writnv,tstalo		;02.20
	ext	mnta0,dmta1,mntc2,dmtc3			;02.20
	ext	dirlst					;02.20
	EXT	EIINST,HDRADR				;02.23
	EXT	RXDRV,WRRZF,SERNUM,SUBVER,getdpb	;02.37
	EXT	SYCNUL					;02.37
;
;
;
;
    ifc	SYSUCB=MULTI					;02.35
	EXT	SHLRG,SVCRG,RDUCB,ADUCB
    elsec
	ENT	?UHL,?UDE,?UBC,?UPSW,?USTK,?UHLX,?UDEX,?UBCX,?USWX,?UIX,?UIY
	ENT	?UDEV,?UDBF,?UDRB,?USFB,?UCHR,?UABT,?USKQ,?UPRC,?UTAB,?UOPT
	ENT	?UBF1,?UBF2,?UFCB,?UFCB1,?UFCB33
    endc
	EJECT
	icl	opdefn					;02.20
;
	eject
	RAM
UCB:
?UHL:	DS	2	;HL
?UDE:	DS	2	;DE
?UBC:	DS	2	;BC
?UPSW:	DS	2	;AF
?USTK:	DS	2	;SP
?UHLX:	DS	2	;XHL				 02.14
?UDEX:	DS	2	;XDE				 02.14
?UBCX:	DS	2	;XBC				 02.14
?USWX:	DS	2	;XAF				 02.14
?UIX:	DS	2	; IX				 02.14
?UIY:	DS	2	; IY				 02.14
?UDEV:	DB	0	; USER MASTER DEVICE
?UDBF:	DW	80H	; USER DISK BUFFER
?UDRB:	DB	0	; USER DIRECTORY BLOCK
?USFB:	DW	0	; USER WORKSPACE PTR
?UCHR:	DB	0	; USER INPUT CHAR BUFFER
?UABT:	DW	0	; USER ABORT ADR		02.37
?USKQ:	DB	0	; STACK SWITCH
?UPRC:	DB	0	; RETURN CODE
?UTAB:	DB	0	; tab control			02.20
?UOPT:	DB	0	; OPTION BYTE			02.14
;	80		TRANSPARENT MODE		 02.37
;	40		NO ECHO				 02.37
;	20		RESERVED			 02.37
OPTDIO	EQU	10H	NO DISK I/O ERROR REPORT	 02.37
;	08		NO CR ECHO			 02.37
;	04		USE <ESC> AS LINE TERMINATOR	 02.37
;	02		READ AFTER WRITE		 02.37
;	01		^P TOGGLE			 02.37
?UBF1:	DW	0	; SYSTEM BUFFER PTR 1
?UBF2:	DW	0	; SYSTEM BUFFER PTR 2
DOSEND:		; END OF BOOT LOAD
?UFCB:	DS	33	; USER CHAIN FCB
	ds	1	; for 17/18 call use only	 02.20
?UFCB1	EQU	?UFCB+1					;02.35
?UFCB33 EQU	?UFCB+33				;02.35
;
        ram                                             ;02.41
spsav:  dw      0
retsv:  dw      0
pswsv:  dw      0
hlsav:  dw      0
xspsav: dw      0
;
	EJECT
	ROG
;
DOS:	DI						;02.37
	SHLD	HLSAV		; TEMP SAVE		;02.37
	sspd	SPSAV		; TEMP SAVE	;02.37  ;02.41
;
	POP	H					;02.37
	SHLD	RETSV					;02.37
	PUSH	PSW					;02.37
	POP	H					;02.37
	SHLD	PSWSV		; TEMP SAVE		;02.37
	PUSH	D					;02.37
	LHLD	URREG					;02.37
	IFC	SYSCPU=C.Z80				;02.37
	LXI	D,URIY+2	; Z80 AREAS		;02.37
	ELSEC						;02.37
	LXI	D,URSTK+2	; DISP TO SAVE AREA	;02.37
	ENDC						;02.37
;
	DAD	D					;02.37
	XCHG						;02.37
	lhld    retsv                        ;02.37     ;02.41
	XTHL						;02.37
	XCHG						;02.37
	SPHL			; SP NOW ADDRESSES SAVE ;02.37
;
	IFC	SYSCPU=C.Z80				;02.37
	PUSH	Y					;02.37
	PUSH	X					;02.37
	EXAF						;02.37
	PUSH	PSW					;02.37
	EXAF						;02.37
	EXX						;02.37
	PUSH	B					;02.37
	PUSH	D					;02.37
	PUSH	H					;02.37
	EXX						;02.37
	ENDC						;02.37
;
	lhld    spsav                        ;02.37     ;02.41
;
	PUSH	H		; SAVE SP		;02.37
	lhld    pswsv                        ;02.37     ;02.41
;
	PUSH	H		; SAVE PSW		;02.37
	PUSH	B		; SAVE BC		;02.37
	PUSH	D		; SAVE DE		;02.37
	lhld    hlsav                        ;02.37     ;02.41
	PUSH	H		; SAVE HL		;02.37
;
	LXI	SP,DOSTK
	CALL	EIINST	; ENABLE IS USER OPTION		 02.23
;
	MOV	A,C					;02.37
	RLC
	BRC	XDOS					;02.35
;
	LXI	H,XDOSZ	; CP/M COMPATABLE CALL
	MVI	D,MXDOSZ	; MAX DOS CALLS
	BR	DOSA					;02.35
;
XDOS:	rlc		;check for c0 range		 02.20
	BRC	xdos2				;02.20	;02.35
	LXI	H,XDOSL
	MVI	D,MXDOSL
	BR	dosa				;02.20	;02.35
;
xdos2:	lxi	h,xdos2l				;02.20
	mvi	d,mxdos2				;02.20
;
DOSA:	MVI	B,0
	MOV	A,C
	ANI	3FH	; FIX FOR 0C0-0FF CALLS		 02.37
	CMP	D
	BRGE	ILLDOS	; IF >MAX THEN ERR		;02.35
	MOV	C,A
	DAD	B
	DAD	B
	MOV	E,M
	INX	H
	MOV	D,M	; DE=ROUTINE ADR
;
	LXI	H,DOSB
	PUSH	H	; ROUTINE RTN ON STK
	PUSH	D	; ROUTINE ADR
;
	CALL	SPLLST	;02.32 CHECK SPOOL
	JMP	LODRG2	; RETURN REGS			;02.37
;
DOSB:	DI		; FOR MULT-USER
	LHLUCB	STK					;02.35
	PUSH	H	; HIS STACK			 02.20
	CALL	LODRG	; HIS REGISTERS			 02.20
	SHLD	HLSAV					;02.20
	POP	H	; HIS STACK			 02.20
	SPHL
	LHLD	HLSAV					;02.20
	JMP	EIINST	; ENABLE IS USER OPTION		 02.23
	EJECT
; ILLEGAL DOS CALLS GIVE ERROR
;
ILLDOS:
	LHLUCB	BC					;02.35
	SHLD	ILLDM1	; C=CALL NUMBER
;
	LHLUCB	STK					;02.35
	MOV	E,M	; GET ADRESS FROM STACK
	INX	H
	MOV	D,M
	XCHG
	SHLD	ILLDM2
	LXI	H,ILLDMG
	CALL	ERMSG
	JMP	SYABT
;
ILLDMG:	DB	13,10,'Illegal System Call ',80H	 ;02.07
        DW      ILLDM1                          ;02.41
       	DB	'H at ',81H                     ;02.41
        DW      ILLDM2                          ;02.41
       	DB	'H',13,10,0                     ;02.41
        RAM                                     ;02.41
ILLDM1: DB      0,0                             ;02.41
ILLDM2: DB      0,0                             ;02.41
;
        ROG
NOOP:	XRA	A				;02.37
	CALL	SAVAF				;02.37
	BR	DOSB				;02.37
;
; OUT OF BUFFERS PANIC	(02.00)
;
	EJECT
;
LODRG2:	DI						;02.37
	CALL	LODRG					;02.37
	JMP	EIINST					;02.37
;
LODRG:	
	sspd	XSPSAV		; TEMP SAVE	;02.37  ;02.41
	LHLD	URREG					;02.37
	LXI	D,URHL					;02.37
	DAD	D					;02.37
	SPHL						;02.37
	POP	H					;02.37
	POP	D					;02.37
	POP	B					;02.37
	POP	PSW					;02.37
	IFC	SYSCPU=C.Z80				;02.37
	EXX						;02.37
	POP	D	; DUMMY TO GET PAST SP SAVE AREA;02.37
	POP	H					;02.37
	POP	D					;02.37
	POP	B					;02.37
	EXX						;02.37
	EXAF						;02.37
	POP	PSW					;02.37
	EXAF						;02.37
	POP	X					;02.37
	POP	Y					;02.37
	ENDC						;02.37
	lspd    xspsav                       ;02.37     ;02.41
	RET
;
	EJECT
; TABLE DEFINITION 
;    NET ADDS EXTRA FLAG BYTE
;    MSB SAYS A NET ITEM, REST IS NET CONTROL CODE
;
;
DNET	MAC			;02.35
[	DW	&1
]
DNORM	MAC			;02.35
[	DW	&1
]
;
;
;	NEW DOS COMMAND TABLE
;
XDOSL:	
 DNORM	RDCNE	; 0-READ CONSOLE/NO ECHO	80
 DNORM	RDURG	; 1-USER REGISTER PTR		81
 DNORM	STCLC	; 2-SET USER CONTROL-C ABORT	82
 Dnet	RDLBK,18 ; 3-READ LOGICAL BLOCK		83
 Dnet	WRLBK,19 ; 4-WRITE LOGICAL BLOCK	84
 DNORM	SPLCTL	; 5-spooling interface		85
 DNORM	NAMFB	; 6-FORMAT NAME TO FCB		86
 DNORM	ILLDOS	; 7-MADE ILLEGAL	02.20	87
 DNORM	PLINK	; 8-LINK TO PROGRAM		88
 DNORM	MULX	; 9-MULTIPLY			89
 DNORM  DIVX	;10-DIVIDE			8A
 Dnet	HOMEX,20 ;11-HOME DISK			8B
 DNET	EJCTX,21 ;12-EJECT DISK			8C
 DNORM	GVER	;13-GET VERSION NUMBER		8D
 DNORM	CSET	;14-SET CONSOLE CURSOR		8E
 DNORM	SDATE	;15-SET DATE			8F
 DNORM	RDATE	;16-READ DATE			90
 DNORM	STIME	;17-SET TIME			91
 DNORM	RTIME	;18-READ TIME			92
 DNORM	SETPRC	;19-SET PGM RET.CODE		93
 Dnet	ATBFL,22 ;20-SET FILE ATTRIBUTE		94
 Dnet	RDLABL,23 ;21-READ DISK LABEL		95
 Dnet	MTROFF,24 ;22-TURN MOTOR OFF		96
 DNORM	setbot	;23-set bottom		02.20	97
 Dnet	readnv,25 ;24-read w/o advance	02.20	98
 Dnet	writnv,26 ;25-write w/o advance	02.20	99
 Dnet	tstalo,27 ;26-test allocated	02.20	9A
 DNORM	illdos	;27-deallocate		02.20	9B
 Dnet	dirlst,28 ;28-dir listing		02.20	9C
 DNORM	setopt	;29-set pgm options	02.20	9D
 DNORM	illdos	;30-delete extent	02.20	9E
 DNORM	getmst	;31-get master drive	02.20	9F
 Dnet	mnta0,29 ;32-mount disk		02.20	A0
 Dnet	dmta1,30 ;33-dismount		02.20	A1
 DNORM	ILLDOS	;UNASSIGNED			A2
;
MXDOSL	EQU	$-XDOSL/2
	EJECT
;	c0 series of commands (sd)		02.20
xdos2l:
 DNORM	illdos	;start user		02.20	C0
 DNORM	illdos	;stop user		02.20	C1
 Dnet	mntc2,31 ;mount disk		02.20	C2
 Dnet	dmtc3,32 ;dismount disk		02.20	C3
 DNORM	illdos	;get user status	02.20	C4
 DNORM	illdos	;dispatch message	02.20	C5
 DNORM	illdos	;record lock		02.20	C6
 DNORM	ILLDOS	;MULTI CALL			C7
 DNORM	ILLDOS	;MULTI CALL			C8
 DNORM	ILLDOS	;MULTI CALL			C9
 DNORM	ILLDOS	;MULTI CALL			CA
 DNORM	ILLDOS	;MULTI CALL			CB
 DNORM	SYCNUL	;PRINT BUFFER TO NULL		CC
 DNORM	ILLDOS	;MULTI CALL			CD
 DNORM	DIOFG	;SET I/O ERROR FLAG		CE
 DNORM	ILLDOS	;MULTI CALL			CF
 DNORM	ILLDOS	;MULTI CALL			D0
 DNORM	ILLDOS	;MULTI CALL			D1
 DNORM	ILLDOS	;UNASSIGNED			D2
;
mxdos2	equ	$-xdos2l/2
;
;	CP/M COMPATABLE FUNCTIONS
XDOSZ:
;	DEVICE I/O
;
 DNORM	SYABT	; 0 - RETURN TO SYSTEM			00
 DNORM	SYC01	; 1 - READ CONSOLE			01
 DNORM	SYC02	; 2 - WRITE CONSOLE			02
 Dnet	SYC03,1	; 3 - READ READER			03
 Dnet	SYC04,2	; 4 - WRITE PUNCH			04
 Dnet	SYC05,3	; 5 - WRITE LIST			05
 DNORM	syc06	; 6 - direct console i/o	02.20	06
 DNORM	SYC07	; 7 - GET I/O STATUS			07
 DNORM	SYC08	; 8 - SET I/O STATUS			08
 DNORM	SYC09	; 9 - PRINT BUFFER			09
 DNORM	SYC10	;10 - READ BUFFER			0A
 DNORM	SYC11	;11 - INTERROGATE CONSOLE READY		0B
;
;	FILE I/O
;
 DNORM	VNMCPM		;12 -  return ver #		02.20	0C
 DNORM	SELDA		;13 - INIT CDOS				0D
 DNORM	SELDK		;14 - SELECT DISK			0E
 Dnet	FOPN,4		;15 - OPEN FILE				0F
 Dnet	FCLOS,5		;16 - CLOSE FILE			10
 Dnet	DRSCH,6		;17 - SEARCH FOR FILE			11
 Dnet	NXDIR,7		;18 - SEARCH FOR NEXT			12
 Dnet	DELFL,8		;19 - DELETE FILE			13
 dnet	RDFIL,9		;20 - READ FILE				14
 dnet	WRFIL,10	;21 - WRITE FILE			15
 dnet	CRFIL,11	;22 - CREATE FILE			16
 dnet	RENFL,12	;23 - RENAME FILE			17
 DNORM	RLOGV		;24 - GET LOG-IN VECTOR			18
 DNORM	RCDSK		;25 - GET DRIVE NUMBER			19
 DNORM	SETBF		;26 - SET BUFFER ADDRESS		1A
 DNORM	RALCV		;27 - GET ALLOCATION ADDRESS		1B
 DNORM	wrtptx		;28 - write protect disk	02.20	1C
 DNORM	rovec		;29 - get r/o vector		02.20	1D
 dnet	atrix,13	;30 - set atributes		02.20	1E
 DNORM	getdpb		;31 - cpm disk parm blk ***	02.20	1F
 DNORM	NOOP		;32 - Get/Set file owner	02.36	20
 dnet	ranrd,14	;33 - random read		02.20	21
 dnet	ranwr,15	;34 - random write		02.20	22
 dnet	cfsiz,16	;35 - compute file size		02.20	23
 dnet	ranst,17	;36 - set random record		02.20	24
 dnet	rxdrv,33	;37 - C/pM RESET DRIVE		02.37	25
 DNORM	NOOP		;38 - ALLOW ACCESS		02.37	26
 dnet	rxdrv,33	;39 - same as 37		02.37	27
 dnet	WRRZF,34	;40 - C/pM WRITE RANDOM W/FILL  02.37	28
;
MXDOSZ	EQU	$-XDOSZ/2
	EJECT
;
; SET DISK PARAMETERS DISK/BUFFER
;	DE=DISK OR BUFFER ADR
;	SET DISK(14) / SET DMA(26)
;
SELDK:	LDA	SDT
	DCR	A
	CMP	E
	RLT		; AND <MAX DSKS THEN OK
	ADRUCB	DEV					;02.37
	MOV	M,E	; USER MASTER DEVICE
	MOV	B,E
	LHLUCB	DBF	; HL:=BUFF			;02.35
;	was a call to logdk				 02.10
	ret						;02.10
;
SETBF:
	JSDEUCB	DBF				;02.35!!
;
; READ/WRITE LOGICAL BLOCKS
; INPUT - B TOP BIT = INTERLEAVING (0 - NO, 1 - YES)
;	  B LOW BITS = DISK NUMBER
;	  DE = BLOCK
;
RDLBK:	MVI	H,4	; READ REQ.
	BR	RWBK					;02.35
;
WRLBK:	MVI	H,6	; WRITE REQ.
RWBK:	MOV	C,A	; KEEP BLOCK(HIGH)
	MOV	A,B
	RLC
	ANI	1
	ADD	H	; ADD INTERVEAVING
	PUSH	B
	LHLUCB	DBF	; HL:=BUFF			;02.35
	POP	B
;	A=FUNC/HL=BUFF
DSKFN:	PUSH	PSW
	MOV	A,B	; GET DISK NUMBER
	CALL	GETDK	; GET DISK NUMBER
	POP	PSW
;
	CALL	DSKIO
	JMP	SAVAF	; SAVE ONLY ERROR CODE
;
;	HOME DISK
; INPUT - B = DISK NUMBER
;
HOMEX:	MVI	A,9	; FLUSH				;02.37
	PUSH	B					;02.37
	CALL	DSKFN					;02.37
	POP	B					;02.37
	PUSH	B					;02.37
	MVI	A,11	;FREE				;02.37
	CALL	DSKFN					;02.37
	POP	B					;02.37
	MVI	A,10	; GET CHARACTISTERICS ON HOME	 02.20
	PUSH	B					;02.20
	CALL	DSKFN					;02.20
	POP	B					;02.20
	MVI	A,0
	BR	DSKFN	; DISK FUNCTION			;02.35
;
;EJECT A DISK
;INPUT - E CONTAINS DISK NUMBER
;
EJCTX:	MOV	A,E	; GET DISK NUMBER
	CALL	GETDK
	CALL	CLRDK	; UNLOG THE DISK		 02.20
	INR	B	; PUT DISK BACK TO 1..N BASE	 02.28
	MVI	A,3	; EJECT COMMAND
	BR	DSKFN	; EJECT			 02.20	 :02.35
;
; VERSION NUMBER FOR CP/M(12)				;02.37
;
VNMCPM:
	lxi	h,002fh	;force ver 2.15			 02.20
	SHLUCB	HL	;02.33 and save it		 02.37
	MOV	A,L					;02.37
	JMP	SAVAF					;02.37
;
; TURN MOTOR OFF ON CURRENT DISK (X22)
; (ON SOME SYSTEMS IT TURNS ALL MOTORS OFF)
;
MTROFF:
	LHLUCB	DEV					;02.35
	MOV	B,L	; B:=DISK
	MVI	A,1	; DE-SELECT
	BR	DSKFN					;02.35
;
; 81H-READ USER REGISTER PTR
;
RDURG:	LXI	H,URREG
	JSHLUCB	BC					;02.37
	EJECT
; 82H-SET USER CONTROL-C FUNCTION
;	@DE:=ADR , 0=SET SYSTEM ABORT
;
STCLC:	; SPECIAL TREATMENT OF ZERO DELETED		 02.37
	JSDEUCB	ABT					;02.35
;
;	ABORT
;	   CONTROL-C
; RETURNS TO CALLER IF USER ABORT INACTIVE
;
;	USER ABORT
;
ABORT:	PUSH	H	; SAVE USER HL IF RETURN
	LHLUCB	ABT					;02.35
	MOV	A,H
	ANA	L
	CPI	-1
	BRNE	ABORT1					;02.35
; INACTIVE USER ABORT (RETURN TO CALLER)
	POP	H	; RECOVER HL
	RET
;
ABORT1:	MOV	A,H	;				 02.37
	ORA	L	; CHECK FOR ZERO		 02.37
	BRNZ	ABORT2	; IF NOT, PROCEED		 02.37
	MVI	A,0C3H	; A 'JUMP'			 02.37
	CMP	M	; COMPARE TO LOC 0		 02.37
	BRNE	SYABT	; IF NOT, CAN'T GO THERE	 02.37
ABORT2:	XCHG
	LHLUCB	STK					;02.35
	SPHL		; RESTORE USER STACK
	XCHG
	PCHL		; GOTO @USER ABORT
;
;	SYSTEM ABORT
;	OR DOS CALL 0 (RETURN TO SYSTEM)
;
SYABT:
	shld	opihl						;02.40
	LXI	SP,DOSTK
	CALL	CLRVC
	ADRUCB	DEV					;02.37
	MOV	A,M
	PUSH	PSW
	PUSH	H	; SAVE MASTER DEVICE
	CALL	RESET	; RESET DISK I/O
	POP	H
	POP	PSW
	MOV	M,A
	JMP	CONPRY	; GOTO USER			 02.20
	EJECT
;
; RESET DOS/SELECT DISK A/DMA @ 80H (13)
;
SELDA:	CALL	CLRVC	; CLEAR ALL DISKS
;
RESET:	PUSH	PSW	; SAVE DISK TO LOG IN
	ADRUCB	DEV					;02.37
	MVI	A,0	; DISK=0
	LXI	D,80H	; BUFFER:=80H
	MOV	M,A	; DISK:=0 (A)
	INX	H
	MOV	M,E
	INX	H
	MOV	M,D	; BUFFER:=80H
	XCHG	;@HL:=BUFFER
	POP	B
	RET		       ;NO LOGIN		 02.07
;
;  CLEAR LOGIN VECTOR
;
CLRVC:	
	LDA	SDT					;02.37
	MVI	B,0					;02.37
CLRX0:	PUSH	PSW					;02.37
	PUSH	B					;02.37
	CALL	CLRDK					;02.37
	POP	B					;02.37
	POP	PSW					;02.37
	INR	B					;02.37
	DCR	A					;02.37
	RZ						;02.37
	BR	CLRX0					;02.37
;
;	UCB ACCESS
;
;	SAVE USER A-REG AND FLAGS
;
    ifc SYSUCB=MULTI	;MULTI
SAVAF:	PUSH	H
	PUSH	D
	PUSH	PSW
	ADRUCB	PSW					;02.37
	POP	D
	MOV	M,E
	INX	H
	MOV	M,D
	POP	D
	POP	H
	RET
;
;
    elsec	;its SINGLE
SAVAF:
	PUSH	H					;02.36
	PUSH	PSW					;02.36
	POP	H					;02.36
	SHLD	?UPSW					;02.36
	POP	H					;02.36
	RET						;02.36
    endc
;
;	RETURN A=LOGIN VECTOR (24)
;
RLOGV:		; code deleted here			 02.10
	LHLD	LOGVC
	SHLUCB	HL	; HL:=0..15			;02.35
	MOV	A,L					;02.37
	BR	SAVAF	; SAVE AF			;02.35
;
rovec:	lhld	rodvc	;return the			 02.20
	JSHLUCB	HL	;r/o disk vector in hl	; 02.20	:02.35
;
;	RETURN A=CURRECT DISK (25)
;
RCDSK:
	LHLUCB	DEV	; L:=UCB.URDEV			;02.35
	MOV	A,L
	BR	SAVAF					;02.35
;
;  *** DOS CALL 27 ***
;    RETURN @BC=ALLOCATION VECTOR (27)
;	   A = number of blocks per clusters
;	   DE= number of clusters on disk
; cp/m 2 wants vector ptr -> HL
;
RALCV:
	LHLUCB	DEV					;02.35
	MOV	B,L
	PUSH	B	; SAVE DISK #
	CALL	DSKVC	; @HL:=ALLOCATION VECTOR[UCB.DISK]
	SHLUCB	BC	; BC:=HL				;02.35
	SHLUCB	HL	;02.33 also save in hl for cp/m 2	;02.35
	POP	B	; GET DISK NUMBER
	MVI	A,8	; GET # OF BLOCKS
	CALL	DSKIO
	SAFUCB		; SAVE BLOCKS / CLUSTER			;02.35
	XCHG		; HL:=NUMBER OF CLUSTERS
	SHLUCB	DE	;save as DE				;02.35
	RET							;02.39
;
;GET VERSION AND REVISION
;
GVER:	LXI	H,VERSION  ; GET MAJOR,MINOR REV.
	SHLUCB	BC		; BC:=MAJ,MIN			;02.35
	LXI	H,SUBVER					;02.37
	SHLUCB	DE		; DE:=CONFIG #			;02.37
	LHLD	SERNUM						;02.37
	SHLUCB	HL		; SERIAL NUMBER			;02.37
	LXI	H,OSTYPE
	MOV	A,L		; A:=TYPE
	BR	SAVAF	; SAVE REGISTERS			;02.35
;
; SYSTEM CLOCK CONTROL
;	SET: B:(DAY/SEC) D:(MON/MIN) E:(YR/HR)
;      READ: A:(DAY/SEC) B:(MON/MIN) C:(YR/HR)
;
;  SET DATE & TIME
SDATE:	LXI	H,CLKCB
	BR	PTCLK	; ENTER NEW VALUES			;02.35
;
STIME:	LXI	H,CLKCB
	INX	H	; SKIP YR,MN,DY
	INX	H
	INX	H
;
PTCLK:	MOV	M,E	; YR OR HR (24)
	INX	H
	MOV	M,D	; MON OR MIN
	INX	H
	MOV	M,B	; DAY OR SEC
	CALL	SCLK	; START CLOCK
	RET
; READ DATE & TIME
RDATE:	LXI	H,CLKCB
	BR	GTCLK	; GET VALUES			;02.35
;
RTIME:	LXI	H,CLKCB
	INX	H	; SKIP YR,MN,DY
	INX	H
	INX	H
; GET CLK VALUES
GTCLK:	PUSH	H
	CALL	RDCLK	; UPDATE CLOCK BLK
	POP	H
	MOV	E,M	; YR OR HR
	INX	H
	MOV	D,M	; MN OR MIN
	INX	H
	XCHG
	SHLUCB	BC	; SAVE HL AS USER'S BC			;02.35
	LDAX	D	; DAY OR SEC
	JSAFUCB		;    AS USER's AF			;02.36
;
; SET PROG RET CODE (19)
;
SETPRC:
	ADRUCB	PRC						;02.35
	MOV	M,A
	RET		; UCB.PRC:=A
;
DIOFG:	MVI	E,0		; 'ON' VALUE		;02.37
	ORA	A					;02.37
	BRZ	DIOFG1					;02.37
	MVI	E,10H		; 'OFF' VALUE		;02.37
DIOFG1:	ADRUCB	OPT					;02.37
	MOV	A,M					;02.37
	ANI	0EFH		; TURN BIT OFF		;02.37
	ORA	E		; SET DESIRED VALUE	;02.37
	MOV	M,A		; PUT BACK		;02.37
	RET						;02.37
;
setopt:		; set user option byte (cdos 9D)		 02.20
	mov	a,e	;mask					 02.20
	ani	0CFH	;defined bits				 02.30
	mov	e,a	;back to e with valid mask		 02.20
	SAFUCB		;save for return to user	 02.20	:02.35
	PUSH	PSW						;02.30
	ANA	D	; CLEAR EXTRANEOUS BITS IN D		 02.30
	MOV	D,A						;02.30
	POP	PSW						;02.30
	cma		;it IS a mask				 02.20
	ADRUCB	OPT						;02.37
	ana	m	;clear out masked bits			 02.20
	ora	d	;set new bits				 02.20
	mov	m,a	;and back to memory			 02.20
	ret		;done					 02.20
;
getmst:		;get master disk (cdos 9F)			 02.20
	lxi	h,oplink					;02.20
	lxi	d,comdsk	;address of com file disk	 02.20
	dad	d						;02.20
	mov	a,m	;get it					 02.20
	SAFUCB	;save it				 02.20	;02.35
	inx	h	; batch file master disk		 02.20
	mov	h,m	; get from memory			 02.20
	mov	l,c	;keep old c				 02.20
	JSHLUCB	BC	; return will be to orig caller	 02.20	;02.35
;
GSOWNR:	JMP	ILLDOS
;
	end
