;
; SYSLIB Module Name:  SUD
; Author:  Richard Conn
; SYSLIB Version Number:  2.0
; Module Version Number:  1.0
; Module Entry Points:
;	GETUD		PUTUD		LOGUD		RETUD
; Module External References:
;	BDOS
;

;
;  EXTERNALS
;
	EXT	BDOS

;
;  PUTUD -- SAVE CURRENT USER/DISK FOR LATER RESTORE
;	NO REGS AFFECTED
;
PUTUD::
	PUSH	B	; SAVE REGS
	PUSH	PSW
	CALL	RETUD	; GET CURRENT USER AND DISK
	MOV	A,B	; GET DISK
	STA	CDISK	; SET CURRENT DISK
	MOV	A,C	; GET USER
	STA	CUSER	; SET CURRENT USER
	POP	PSW	; RESTORE REGS
	POP	B
	RET

;
;  BUFFERS
;
CDISK:
	DS	1	; CURRENT DISK
CUSER:
	DS	1	; CURRENT USER

;
;  GETUD -- RESTORE USER/DISK FROM PREVIOUS PUTUD
;
GETUD::
	PUSH	H	; SAVE REGS
	PUSH	D
	PUSH	B
	PUSH	PSW
	LDA	CDISK	; SELECT DISK
	MOV	E,A
	MVI	C,14	; SELECT
	CALL	BDOS
	LDA	CUSER	; SELECT USER
	MOV	E,A
	MVI	C,32	; SELECT
	CALL	BDOS
DONE:
	POP	PSW	; GET REGS
	POP	B
	POP	D
	POP	H
	RET

;
;  LOGUD -- LOG IN USER/DISK, WHICH C=USER AND B=DISK
;
LOGUD::
	PUSH	H	; SAVE REGS
	PUSH	D
	PUSH	B
	PUSH	PSW
	MOV	E,C	; SELECT USER
	MVI	C,32
	CALL	BDOS
	MOV	E,B	; SELECT DISK
	MVI	C,14
	CALL	BDOS
	JMP	DONE

;
;  RETUD -- RETURN CURRENT USER AND DISK IN C AND B, RESP
;	AFFECT ONLY BC
;
RETUD::
	PUSH	H	; SAVE REGS
	PUSH	D
	PUSH	PSW
	MVI	C,25	; GET CURRENT DISK
	CALL	BDOS
	PUSH	PSW	; SAVE IT
	MVI	E,0FFH	; GET CURRENT USER
	MVI	C,32
	CALL	BDOS
	MOV	C,A	; USER IN C
	POP	PSW	; GET DISK
	MOV	B,A	; DISK IN B
	POP	PSW	; GET REGS
	POP	D
	POP	H
	RET

	END
