* GPL Routine >22 - Modify file protection
*
* This procedure will either set or reset the protection on
* a file depending on the value stored at >834d
*
* Inputs:
*    >834C - SCSI device number and buffer bit
*    >834D - 0=unprotect, 1=protect
*    >834E - Pointer to file name
*
* Outputs:
*    >8350 - Error status
*               0 = No error
*           non 0 = Error
*

GPL22
       ANDI R12,>FF00
       AI   R12,24
       BL   @SAVPAD
       BL   @MAKEFN
       BL   @GETFDR
       BL   @RESPAD
       LDCR @ZERO,4
       CI   R5,0
       JNE  GPL22A

G22ERR LDCR @ZERO,4
       MOVB @B01,@>8350      Set an error status
       B    @DSRRT

GPL22A MOVB @>834D,R1        Check protection code
       JEQ  GPL22B

* The protection code was not zero so we have to protect the file.
* If the file is already protected, we just return.  Otherwise,
* we set the bit in the VIB and write it back out

       LDCR @ZERO,4
       MOV  @12(R5),R1       Get file flags
       COC  @PROBIT,R1
       JEQ  G22RT

       SOC  @PROBIT,@12(R5)  Set protection bit
       JMP  GPL22C

* The protection code was zero so we have to unprotect the file.
* If the file is already unprotected, we just return.  Otherwise,
* we clear the bit in the VIB and write it back out

GPL22B LDCR @ZERO,4
       MOV  @12(R5),R1       Get file flags
       CZC  @PROBIT,R1
       JEQ  G22RT

       SZC  @PROBIT,@12(R5)  Clear protection bit

GPL22C

* Now we write the FDR back out to disk.
*
       LDCR @B04,4
       MOV  @SAVEAU,R7
       MOV  R6,R3
       SRL  R3,8
       SLA  R3,1
       MPY  @SAUTBL(R3),R7
       SRL  R8,1
       SRL  R7,1
       JNC  GPL22D
       AI   R8,>8000
GPL22D
       LDCR @ZERO,4
       BLWP @BANKIT
       DATA SCSIWT
       JNE  G22ERR

G22RT  MOVB @ZERO,@>8350     Set success
       B    @DSRRT
