Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13hBiosInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13hBiosInit.asm	(revision 559)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13hBiosInit.asm	(revision 560)
@@ -22,46 +22,40 @@
 SECTION .text
 
-TEMPORARY_VECTOR_FOR_SYSTEM_INT13h		EQU		21h	; MS-DOS
+TEMPORARY_VECTOR_FOR_SYSTEM_INT13h		EQU		20h	; MS-DOS so BIOSes most likely do not use this
 
 
+;--------------------------------------------------------------------
+; Int 13h software interrupt handler.
+; This handler captures boot sector read from foreign drive when our
+; INT 19h is not called. This way we can for XTIDE Universal BIOS
+; initialization even without INT 19h being called.
+;
+; Int13hBiosInit_Handler
+;	Parameters:
+;		AH:		Bios function
+;				READ_SECTORS_INTO_MEMORY will initialize XTIDE Universal BIOS
+;--------------------------------------------------------------------
 Int13hBiosInit_Handler:
+	; Initialize XTIDE Universal BIOS only if Int13hBiosInit_Handler is still at
+	; vector 13h. Otherwise some other BIOS has hooked us and our very late
+	; initialization is not possible.
+	push	ds
+	push	ax
+	LOAD_BDA_SEGMENT_TO	ds, ax
+	pop		ax
+	cmp		WORD [BIOS_DISK_INTERRUPT_13h*4], Int13hBiosInit_Handler
+	pop		ds
+	jne		SHORT .VeryLateInitFailed	; XTIDE Universal BIOS does not work
+
 	; Ignore all but read command (assumed to read boot sector)
 	cmp		ah, READ_SECTORS_INTO_MEMORY
-	jne		SHORT .MainBiosStillInInitializationMode
+	je		SHORT Int19h_BootLoaderHandler
 
-	LOAD_BDA_SEGMENT_TO	ds, ax
-
-	; Now install our handler and call 19h since non-standard motherboard BIOS did not
-	; do that or our INT 19h hander was replaced by other BIOS.
-	mov		WORD [BIOS_BOOT_LOADER_INTERRUPT_19h*4], Int19h_BootLoaderHandler
-	mov		[BIOS_BOOT_LOADER_INTERRUPT_19h*4+2], cs
-	int		BIOS_BOOT_LOADER_INTERRUPT_19h	; Does not return
-
-	; Main BIOS might reset floppy drives etc. so let's wait longer
-	; before installing our INT 19h handler.
-.MainBiosStillInInitializationMode:
+	; Call system INT 13h since not trying to read boot sector
 	int		TEMPORARY_VECTOR_FOR_SYSTEM_INT13h
 	retf	2
 
-
-;--------------------------------------------------------------------
-; Int13hBiosInit_RestoreSystemHandler
-;	Parameters:
-;		Nothing
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, DS, ES
-;--------------------------------------------------------------------
-Int13hBiosInit_RestoreSystemHandler:
-	LOAD_BDA_SEGMENT_TO	ds, ax
-
-	; Is our very late init handler in place
-	cmp		WORD [BIOS_DISK_INTERRUPT_13h*4], Int13hBiosInit_Handler
-	jne		SHORT .SystemHandlerAlreadyInPlace
-
-	les		ax, [TEMPORARY_VECTOR_FOR_SYSTEM_INT13h*4]
-	mov		[BIOS_DISK_INTERRUPT_13h*4], ax
-	mov		[BIOS_DISK_INTERRUPT_13h*4+2], es
-.SystemHandlerAlreadyInPlace:
-	ret
+.VeryLateInitFailed:
+	mov		ah, RET_HD_INVALID
+	stc
+	retf	2
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm	(revision 559)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int19h.asm	(revision 560)
@@ -31,8 +31,10 @@
 	sti											; Enable interrupts
 	cld											; String instructions to increment pointers
-%ifndef USE_AT
-	call	Int13hBiosInit_RestoreSystemHandler	; Needed if initialization was started on INT 13h instead on 19h
-%endif
 	LOAD_BDA_SEGMENT_TO	es, ax					; Load BDA segment (zero) to ES
+%ifdef MODULE_VERY_LATE_INITIALIZATION
+	lds		ax, [es:TEMPORARY_VECTOR_FOR_SYSTEM_INT13h*4]
+	mov		[es:BIOS_DISK_INTERRUPT_13h*4], ax
+	mov		[es:BIOS_DISK_INTERRUPT_13h*4+2], ds
+%endif
 	; Fall to .PrepareBootLoaderStack
 
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm	(revision 559)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm	(revision 560)
@@ -37,12 +37,6 @@
 	sti									; Enable interrupts for keystrokes
 	push	ds
-
-%ifdef USE_AT
-	push	BYTE 0
-	pop		ds
-%else
 	push	ax							; We use AX to install very late init handler
 	LOAD_BDA_SEGMENT_TO	ds, ax
-%endif
 
 	test	BYTE [BDA.bKBFlgs1], (1<<2)	; Clears ZF if CTRL is held down
@@ -53,6 +47,5 @@
 	mov		[BIOS_BOOT_LOADER_INTERRUPT_19h*4+2], cs
 
-	; Very late initialization for XT builds only
-%ifndef USE_AT
+%ifdef MODULE_VERY_LATE_INITIALIZATION
 	push	es
 	; Install special INT 13h hander that initializes XTIDE Universal BIOS
@@ -67,7 +60,5 @@
 
 .SkipRomInitialization:
-%ifndef USE_AT
 	pop		ax
-%endif
 	pop		ds
 	popf
Index: trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 559)
+++ trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 560)
@@ -218,4 +218,7 @@
 
 	; Boot loader
+%ifdef MODULE_VERY_LATE_INITIALIZATION
+	%include "Int13hBiosInit.asm"
+%endif
 	%include "Int19h.asm"			; For Int 19h, Boot Loader
 	%include "BootSector.asm"		; For loading boot sector
@@ -254,7 +257,4 @@
 
 	; INT 13h Hard Disk BIOS functions
-%ifndef USE_AT
-	%include "Int13hBiosInit.asm"
-%endif
 	%include "Int13h.asm"			; For Int 13h, Disk functions
 	%include "AH0h_HReset.asm"
Index: trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- trunk/XTIDE_Universal_BIOS/makefile	(revision 559)
+++ trunk/XTIDE_Universal_BIOS/makefile	(revision 560)
@@ -27,4 +27,5 @@
 # MODULE_SERIAL_FLOPPY        Virtual floppy drives using serial port (requires MODULE_SERIAL)     #
 # MODULE_STRINGS_COMPRESSED   Use compressed strings to save space                                 #
+# MODULE_VERY_LATE_INITIALIZATION Initialize on INT 13h if our INT 19h handler is not called       #
 # MODULE_FEATURE_SETS         Power Management support                                             #
 #                                                                                                  #
@@ -100,5 +101,5 @@
 # Assembler preprocessor defines.                               #
 #################################################################
-DEFINES_COMMON = MODULE_STRINGS_COMPRESSED MODULE_HOTKEYS MODULE_8BIT_IDE MODULE_EBIOS MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_FEATURE_SETS RESERVE_DIAGNOSTIC_CYLINDER
+DEFINES_COMMON = MODULE_STRINGS_COMPRESSED MODULE_HOTKEYS MODULE_8BIT_IDE MODULE_EBIOS MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_VERY_LATE_INITIALIZATION MODULE_FEATURE_SETS RESERVE_DIAGNOSTIC_CYLINDER
 DEFINES_COMMON_LARGE = MODULE_BOOT_MENU MODULE_8BIT_IDE_ADVANCED MODULE_COMPATIBLE_TABLES
 
