;Entry:
; R11 - pointer to commandline
; R12 - pointer to VARS
;
;Exit:
; R0 - error or 0
; R1-R11 - corrupted

.Entry_ADFMount_ADF
 MOV     R0, #17			;read file information
 MOV     R1, R11			;point to filename
 SWI     XOS_File			;PRM2-38
 BVS     Entry_ADFMount_Exit		;exit on error

 LDR     R2, [R12, #File_Size_Limit - VARS]
 CMP     R4, R2				;is filesize above our limit?
 ADRHI   R0, Error_File_Size		;YES, point to error
 BHI     Entry_ADFMount_Exit		;  +- exit on error
 BL      MemAlloc			;Allocate memory
 BVS     Entry_ADFMount_Exit		;exit on error

 LDR     R0, _FileType_ADF		;it's an ADF
 STR     R0, [R12, #FileType_Loaded - VARS]

 MOV     R1, R11			;filename
 MOV     R0, #&4F			;open read only
 SWI     XOS_Find			;PRM2-78
 BVS     Entry_ADFMount_Exit		;exit on error

 MOV     R1, R0				;file handle
 MOV     R0, #4				;read from current pointer
 LDR     R2, [R12, #DA_address - VARS]	;address to load file
 MOV     R3, R4
 SWI     XOS_GBPB			;PRM2-69
 MOVVS   R4, R0				;preserve any error
 MOVVS   R2, #0				;mark ADF FS as empty
 MOVVC   R2, #1				;loaded okay if V clear

 STR     R2, [R12, #ADF_Mounted - VARS]
 MOV     R0, #3
 STR     R0, [R12, #ADF_Changed - VARS]	;notify Miscop of change

 MOV     R0, #0				;close file
 SWI     XOS_Find			;close the file PRM2-77
 TEQ     R2, #0				;did an error occur?
 MOVEQ   R0, R4				;YES
 BEQ     Entry_ADFMount_Exit		;exit on error
B       Entry_ADFMount_mounted

 ._FileType_ADF		DCB "ADF", 0
