;vector_handler_40541
;---------------------
;Hijacks SWI FileCore_Create if it's ADFS calling

; R11 - pointer to VARS

 .ADFS_boot     DCB "Acorn "
 .ADFS_Module   DCB "ADFS", 0
                ALIGN

.reinit_ADFS
 STMFD   R13!, {R14}
 MOV     R0, #Module_ReInit
 ADR     R1, ADFS_Module
 SWI     XOS_Module
LDMFD   R13!, {PC}




.vector_handler_40541			;SWI FileCore_Create (&40541)
 LDRB    R14, [R0, #3]			;get the file system number
 TEQ     R14, #8			;is it ADFS?
 BNE     vector_handler_forward		;NO, forward to OS

 LDR     R14, [R0]			;1st word of ADFS' FileCore block
;@@@ following lines are for debugging purposes only
;BIC R14, R14, #ADFS_Sector_Aligned	;switch to byte mode
;BIC R14, R14, #%10			;turn off floppy FIQ's
;MOV R5, #0				;turn off background transfers
 STR     R14, [R11, #ADFS_FS_Create_Block - VARS]	;our FileCore create block

 LDR     R14, [R0, #12]			;load ADFS' DiscOp relative address
 ADD     R14, R14, R1			;ADFS' DiscOp physical address
 STR     R14, [R11, #os_ADFS_DiscOp - VARS]
 LDR     R14, [R0, #16]			;load ADFS' MiscOp relative address
 ADD     R14, R14, R1			;ADFS' MiscOp physical address
 STR     R14, [R11, #os_ADFS_MiscOp - VARS]

 TST     R3, #&FF			;no. of floppies
 ORREQ   R3, R3, #1			;ensure it's at least one
 STREQB  R3, No_Floppy_Support		;and note, so we don't try to pass unhandled calls on

 ADD     R0, R11, #ADFS_FS_Create_Block - VARS	;redirect FileCore to our FS block
 ADR     R1, 0				;redirect FileCore to our module

 #if report_FileCore_Create == 1
   STMFD   R13!, {R0, R14}
   ADR     R0, _report0
   BL      pre_SWI_veneer		;call SWI that follows
   SWI     XReport_Text0
   BL      dontexit_SWI_veneer
   LDMFD   R13!, {R0, R14}
 #endif
 BL      pre_SWI_veneer			;call SWI that follows
 SWI     XFileCore_Create
 BL      post_SWI_veneer
 BVS     exit_SWI_veneer		;exit on error
 #if report_FileCore_Create == 1
   STMFD   R13!, {R0, R14}
   ADR     R0, _report1
   SWI     XReport_Text0
   LDMFD   R13!, {R0, R14}
 #endif

 STR     R0, [R11, #ADFS_FileCore_Private - VARS]	;store the FileCore details returned
 STR     R1, [R11, #FileCore_Notify_Background - VARS]
 STR     R3, [R11, #FileCore_Release_FIQ - VARS]
 BL      Check_FDC_Type			;need to return the correct errors
B       exit_SWI_veneer

#if report_FileCore_Create == 1
._report0 DCB "FileCore_Create raised", 0
._report1 DCB "FileCore_Create success", 0
ALIGN
#endif