TITLE KOCLA
;
; 9/22/82      Sue Arnold
;
; This is an assembly program that will lock a file record so that no
; other programs may access it.  This routine should only be used to    
; WRITE to a record that has been previously READ by the calling routine.
; It is VERY important to call UNLOCK after the write operation so as
; to free up the record for other routines.
;
; CALLING PROCEDURE=
;
;        ALOCK (VAR FIB.addr: file_descriptor); (pointer to the file FIB)
;               VAR lck_err:  INTEGER;          (0=success)
;
; This routine uses XDOS function number 2Ah for a lock.
;

	PAGE
	.Z80
;
BDOSJP	EQU 5		; Use this to call XDOS
;
;
	PAGE
	PUBLIC ALOCK
	CSEG
;
;
ALOCK:
	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, 2AH       ; LOCK 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 ALOCK
