TITLE KCLNUA
;
; 9/22/82      Sue Arnold
;
; This is an assembly program that will UNLOCK a file record so that
; other programs may access it.  This routine should only be used to    
; UNLOCK a record that has been previously LOCKED by the calling routine.
; It is VERY important to unlock the record as no one else can do it 
; for you.                                   
;
; CALLING PROCEDURE=
;
;       AUNLCK (VAR FIB.addr: file_descriptor); (pointer to the file FIB)
;               VAR lck_err:  INTEGER;          (0=success)
;
; This routine uses XDOS function number 2Bh for an AUNLCK.
;

	.Z80
;
BDOSJP	EQU 5		; Use this to call XDOS
;
;
	PUBLIC AUNLCK
	CSEG
;
;
AUNLCK:
	POP HL		; HL = Pascal Return Address 
        POP DE          ; DE = The addr of the error code variable
        EX (SP), HL     ; HL = The addr of the file descriptor
                        ; (top of stack now has the Pascal rtn addr)
        EX DE, HL       ; DE = The addr of the descriptor
                        ; HL = The addr of the err code variable
        LD C, 2BH       ; UNLOCK function number
        PUSH DE         ; Save the addr of the descriptor
        PUSH HL         ; Save the error code addr
	LD HL, 11H      ; Add 17 to the address
	ADD HL,DE	; To get the addr of the FCB within
	EX DE,HL	; The file descriptor block
        CALL BDOSJP     ; lock out the record
        POP HL          ; Restore error code addr
        POP DE          ; Restore file descriptor address
        LD (HL), A      ; Put error code in err code variable
        RET             ; Else, Return to calling routine

	END AUNLCK
