Index: /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 593)
+++ /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 594)
@@ -69,4 +69,7 @@
 	.rgbTopOfStack:						; 256 bytes of stack
 	.fpInt13hEntryStack		resb	4
+%endif
+%ifdef MODULE_MFM_COMPATIBILITY
+	.fpMFMint13h			resb	4
 %endif
 	.fpOldI13h				resb	4	; Far pointer to old INT 13h handler
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13hMFMcompatibility.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13hMFMcompatibility.asm	(revision 594)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13hMFMcompatibility.asm	(revision 594)
@@ -0,0 +1,81 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	Int 13h handler that is used by MODULE_MFM_COMPATIBILITY.
+;					It is placed between XTUB Int 13h hander and system INT 13h hander
+;					to hide XTUB from MFM controllers whose BIOS assumes they handler
+;					all hard drives on the system.
+
+;
+; XTIDE Universal BIOS and Associated Tools
+; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
+;
+; This program is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+;
+; This program is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+; GNU General Public License for more details.
+; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+;
+
+; Section containing code
+SECTION .text
+
+
+;--------------------------------------------------------------------
+; Int 13h software interrupt handler for MFM compatibility.
+;
+; Some MDM controllers require that BDA drive count is what they have set.
+; The purpose for this handler is to restore BDA drive count to what MFM controller
+; expects and then call MFM controller INT 13h.
+;
+; Int13hMFMcompatibilityHandler
+;	Parameters:
+;		Any INT 13h function and parameters
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Int13hMFMcompatibilityHandler:
+	eENTER	6, 0
+	push	es
+	push	ds
+	push	di
+
+	LOAD_BDA_SEGMENT_TO es, di
+	call	RamVars_GetSegmentToDS
+
+	; Remove our drives from BDA drive count
+	push	ax
+	mov		al, [RAMVARS.bDrvCnt]
+	mov		[bp-2], al			; Store our drive count for later use
+	sub		[es:HDBDA.bHDCount], al
+	pop		ax
+
+	; Copy MFM controller INT 13h address to stack
+	les		di, [RAMVARS.fpMFMint13h]
+	mov		[bp-4], es
+	mov		[bp-6], di
+
+	; Restore registers so we can call MFM int 13h
+	pop		di
+	pop		ds
+	pop		es
+
+	pushf	; Push flags to simulate INT
+	call far [bp-6]
+
+	; Now we can restore BDA drive count
+	push	ds
+	push	ax
+	lahf					; Get return flags to AH
+	mov		[bp-12], ah		; Store return flags to be popped by iret
+	LOAD_BDA_SEGMENT_TO ds, ax
+	mov		al, [bp-2]
+	add		[HDBDA.bHDCount], al
+	pop		ax
+	pop		ds
+
+	; Return from this handler
+	eLEAVE
+	iret
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 593)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 594)
@@ -115,5 +115,5 @@
 		test	al, al
 		jnz		SHORT .ContinueInitialization	; CMOS byte 12h is ready for Windows 95
-		call	CMOS_Verify10hTo2Dh
+		call	CMOS_Verify10hTo2Dh				; Can we modify CMOS?
 		jnz		SHORT .ClearBdaDriveCount		; Unsupported BIOS, use plan B
 	
@@ -123,9 +123,9 @@
 		call	CMOS_WriteALtoIndexInDL
 		call	CMOS_StoreNewChecksumFor10hto2Dh
-	%endif
+.ClearBdaDriveCount:
+	%endif	; MODULE_WIN95_CMOS_HACK
 
 	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES
 	jz		SHORT .ContinueInitialization
-.ClearBdaDriveCount:
 	mov		BYTE [es:BDA.bHDCount], 0	; Set hard disk count to zero
 .ContinueInitialization:
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 593)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 594)
@@ -59,4 +59,14 @@
 ;--------------------------------------------------------------------
 .InitializeInt13hAnd40h:
+%ifdef MODULE_MFM_COMPATIBILITY
+	mov		ax, [es:BIOS_DISK_INTERRUPT_13h*4+2]; Load old INT 13h segment
+	mov		[RAMVARS.fpMFMint13h+2], ax			; Store old INT 13h segment
+	xchg	dx, ax
+	mov		ax, [es:BIOS_DISK_INTERRUPT_13h*4]	; Load old INT 13h offset
+	mov		[RAMVARS.fpMFMint13h], ax			; Store old INT 13h offset
+	
+	mov		[RAMVARS.fpOldI13h+2], cs
+	mov		WORD [RAMVARS.fpOldI13h], Int13hMFMcompatibilityHandler	
+%else
 	mov		ax, [es:BIOS_DISK_INTERRUPT_13h*4+2]; Load old INT 13h segment
 	mov		[RAMVARS.fpOldI13h+2], ax			; Store old INT 13h segment
@@ -64,4 +74,5 @@
 	mov		ax, [es:BIOS_DISK_INTERRUPT_13h*4]	; Load old INT 13h offset
 	mov		[RAMVARS.fpOldI13h], ax				; Store old INT 13h offset
+%endif
 
 	; Only store INT 13h handler to 40h if 40h is not already installed.
Index: /trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 593)
+++ /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 594)
@@ -280,4 +280,7 @@
 
 	; INT 13h Hard Disk BIOS functions
+%ifdef MODULE_MFM_COMPATIBILITY
+	%include "Int13hMFMcompatibility.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 593)
+++ /trunk/XTIDE_Universal_BIOS/makefile	(revision 594)
@@ -30,4 +30,6 @@
 # MODULE_POWER_MANAGEMENT     Power Management support                                             #
 # MODULE_WIN95_CMOS_HACK      Hack for Windows 95 compatibility                                    #
+# MODULE_MFM_COMPATIBILITY    Restores BDA drive count for MFM controllers that expect to be the   #
+#                             only hard drive controller on the system                             #
 #                                                                                                  #
 # Not modules but these affect the assembly:                                                       #
@@ -121,5 +123,5 @@
 
 DEFINES_ALL_FEATURES = MODULE_8BIT_IDE MODULE_8BIT_IDE_ADVANCED MODULE_ADVANCED_ATA MODULE_EBIOS MODULE_BOOT_MENU MODULE_HOTKEYS MODULE_IRQ MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_STRINGS_COMPRESSED MODULE_POWER_MANAGEMENT MODULE_COMPATIBLE_TABLES
-DEFINES_ALL_FEATURES += ELIMINATE_CGA_SNOW RELOCATE_INT13H_STACK RESERVE_DIAGNOSTIC_CYLINDER MODULE_WIN95_CMOS_HACK
+DEFINES_ALL_FEATURES += ELIMINATE_CGA_SNOW RELOCATE_INT13H_STACK RESERVE_DIAGNOSTIC_CYLINDER MODULE_WIN95_CMOS_HACK MODULE_MFM_COMPATIBILITY
 
 
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 593)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 594)
@@ -188,9 +188,5 @@
 
 	eMOVZX	di, [cs:g_cfgVars+CFGVARS.bEepromType]
-;%if g_rgwEepromTypeToSizeInWords = 0	; *FIXME* It really is but NASM won't accept this.
-	mov		cx, [cs:di]
-;%else
-;	mov		cx, [cs:di+g_rgwEepromTypeToSizeInWords]
-;%endif
+	mov		cx, [cs:di+g_rgwEepromTypeToSizeInWords]
 	sub		cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]	; CX = WORDs to append
 	jbe		SHORT .NoNeedToAppendZeroes
