Index: trunk/Assembly_Library/Inc/CMOS.inc
===================================================================
--- trunk/Assembly_Library/Inc/CMOS.inc	(revision 617)
+++ trunk/Assembly_Library/Inc/CMOS.inc	(revision 618)
@@ -30,5 +30,5 @@
 
 ; Almost all of the CMOS locations are vendor specific and
-; there is very little standardation
+; there is very little standardization.
 HARD_DISK_TYPES					EQU		12h		; Windows 9x reads this to check if IDE drives
 												; are present so it should be safe to access this.
Index: trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 618)
@@ -99,5 +99,5 @@
 		mov		dl, %1
 	%endif
-		call	IdeIO_InputToALfromIdeRegisterInDL
+	call	IdeIO_InputToALfromIdeRegisterInDL
 
 %endif
Index: trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 618)
@@ -102,14 +102,14 @@
 
 ; Subcommands for COMMAND_SET_FEATURES
-FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE	EQU		01h		; CFA feature set only
-FEATURE_ENABLE_WRITE_CACHE				EQU		02h
-FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT	EQU	05h
-FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE	EQU		81h		; CFA feature set only
-FEATURE_DISABLE_WRITE_CACHE				EQU		82h		; Can also be used to flush cache
-FEATURE_DISABLE_ADVANCED_POWER_MANAGEMENT	EQU	85h		; Might not be supported even if FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT is
-FEATURE_SET_TRANSFER_MODE				EQU		03h		; Transfer mode goes to the Sector Count Register
-	PIO_DEFAULT_MODE					EQU		0h
-	PIO_DEFAULT_MODE_DISABLE_IORDY		EQU		1h
-	PIO_FLOW_CONTROL_MODE_xxx			EQU		(1<<3)	; Bits 2...0 hold the PIO mode
+FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE		EQU		01h		; CFA feature set only
+FEATURE_ENABLE_WRITE_CACHE					EQU		02h
+FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT	EQU		05h
+FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE		EQU		81h		; CFA feature set only
+FEATURE_DISABLE_WRITE_CACHE					EQU		82h		; Can also be used to flush cache
+FEATURE_DISABLE_ADVANCED_POWER_MANAGEMENT	EQU		85h		; Might not be supported even if FEATURE_ENABLE_ADVANCED_POWER_MANAGEMENT is
+FEATURE_SET_TRANSFER_MODE					EQU		03h		; Transfer mode goes to the Sector Count Register
+	PIO_DEFAULT_MODE						EQU		0h
+	PIO_DEFAULT_MODE_DISABLE_IORDY			EQU		1h
+	PIO_FLOW_CONTROL_MODE_xxx				EQU		(1<<3)	; Bits 2...0 hold the PIO mode
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDPT.asm	(revision 618)
@@ -43,14 +43,13 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AL
+;		AX
 ;--------------------------------------------------------------------
 .DetectPowerManagementSupport:
-	mov		al, [es:si+ATA6.wSetSup82]
-	mov		ah, [es:si+ATA6.wSetSup83]
-	and		ah, A6_wSetSup83_APM
-	shl		ah, 1						; APM bit 3 to bit 4
-	and		al, A6_wSetSup82_POWERMAN	; A6_wSetSup82_POWERMAN (bit 3) is the same
+	mov		ax, A6_wSetSup83_APM << 8 | A6_wSetSup82_POWERMAN	; Both of these flags are bit 3
+	and		ah, [es:si+ATA6.wSetSup83]
+	and		al, [es:si+ATA6.wSetSup82]
+	eSHL_IM	ah, 1						; APM bit 3 to bit 4 (same as FLGH_DPT_APM_SUPPORTED)
 	or		al, ah
-	or		[di+DPT.bFlagsHigh], al		; bit as FLGH_DPT_POWER_MANAGEMENT_SUPPORTED and FLGH_DPT_APM_SUPPORTED
+	or		[di+DPT.bFlagsHigh], al		; FLGH_DPT_POWER_MANAGEMENT_SUPPORTED and FLGH_DPT_APM_SUPPORTED
 %endif ; MODULE_POWER_MANAGEMENT
 
@@ -118,5 +117,5 @@
 	cmp		BYTE [di+DPT_ATA.bDevice], DEVICE_32BIT_ATA
 	ja		SHORT .NoAdvancedControllerDetected
-	
+
 	mov		bx, [di+DPT.wBasePort]
 	call	AdvAtaInit_DetectControllerForIdeBaseInBX
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 618)
@@ -250,8 +250,13 @@
 	pop		WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
 	cmp		dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]	; DL is still drive number?
-	je		SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	je		SHORT Int13h_ReturnFromHandlerWithoutStoringErrorCode
 	mov		[bp+IDEPACK.intpack+INTPACK.dl], dl	; Something is returned in DL
 %endif
-	jmp		SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	jmp		SHORT Int13h_ReturnFromHandlerWithoutStoringErrorCode
+	; We cannot return via Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH!
+	; 1. If the other BIOS returns something in DL then that is assumed to be a drive number
+	;    (if MODULE_SERIAL_FLOPPY is included) even though it could be anything.
+	; 2. Any non-zero value in AH will cause the CF to be set on return from the handler.
+	;    This breaks INT 13h/AH=15h for drives handled by the other BIOS.
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 618)
@@ -106,5 +106,5 @@
 ; Enable/disable advanced power management command can be used to scale
 ; power consumption and performance. Drive supporting Enable APM might not
-; support Disable AMP so we set the drive to max performance if stand by
+; support Disable APM so we set the drive to max performance if stand by
 ; timer value is 0 (idle/standby disabled)
 ;
@@ -126,11 +126,10 @@
 	test	dl, dl
 	jnz		SHORT .EnablePowerSave
-	dec		dx
-	dec		dx		; DL = FEh = Maximum performance
-	jmp		AH23h_SetControllerFeatures
-	
+	mov		dl, 0FEh	; Maximum performance
+	SKIP2B	f
+
 ; TODO: We should add power management level to IDEVARS to be adjustable with xtidecfg
 .EnablePowerSave:
 	mov		dl, 0BFh	; For Toshiba 1.8" HDD: 80h...BFh = Mode 1
-	jmp		AH23h_SetControllerFeatures
-%endif ; %ifdef MODULE_POWER_MANAGEMENT
+	jmp		SHORT AH23h_SetControllerFeatures
+%endif ; MODULE_POWER_MANAGEMENT
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH4h_HVerify.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH4h_HVerify.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH4h_HVerify.asm	(revision 618)
@@ -65,5 +65,5 @@
 ;	Parameters:
 ;		AH:		INT 13h error code
-;		CX:		Number of sectors that was meant to we verified
+;		CX:		Number of sectors that was meant to be verified
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;		SS:BP:	Ptr to IDEPACK
@@ -74,10 +74,9 @@
 ALIGN JUMP_ALIGN
 AH4h_CalculateNumberOfSuccessfullyVerifiedSectors:
-	xchg	cx, ax			; Store error code to CL
+	xchg	cx, ax						; Store error code to CH
 	call	Device_ReadLBAlowRegisterToAL
-	mov		ah, [bp+IDEPACK.bLbaLow]
-	sub		al, ah			; AL = sector address with verify failure - starting sector address
+	sub		al, [bp+IDEPACK.bLbaLow]	; AL = sector address with verify failure - starting sector address
 	xor		ah, ah
-	xchg	cx, ax			; Number of successfully verified sectors in CX, error code in AH
+	xchg	cx, ax						; Number of successfully verified sectors in CX, error code in AH
 	stc
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 618)
@@ -204,5 +204,4 @@
 	mov		dl, [cs:ROMVARS.bIdleTimeout]
 	push	dx
-	push	dx
 	test	dh, FLGH_DPT_APM_SUPPORTED
 	jz		SHORT .NoAdvancedPowerManagementSupport
@@ -213,4 +212,5 @@
 	; COMMAND_STAND_BY seemed to do the trick
 	pop		dx
+	push	dx
 	mov		al, COMMAND_STAND_BY
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/EBIOS/AH44h_ExtendedVerifySectors.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/EBIOS/AH44h_ExtendedVerifySectors.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/EBIOS/AH44h_ExtendedVerifySectors.asm	(revision 618)
@@ -41,5 +41,5 @@
 AH44h_HandlerForExtendedVerifySectors:
 	call	Prepare_ByLoadingDapToESSIandVerifyingForTransfer
-	push	WORD [es:si+DAP.wSectorCount]				; Store for successfull number of sectors transferred
+	push	WORD [es:si+DAP.wSectorCount]				; Store for successful number of sectors transferred
 	mov		ah, [cs:bx+g_rgbVerifyCommandLookup]
 	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm	(revision 618)
@@ -39,6 +39,11 @@
 	mov		bl, 3Fh				; Load sector number mask
 	and		bl, cl				; Sector number now in BL
+%ifndef USE_186
 	sub		cl, bl				; Remove from cylinder number high
-	eROL_IM	cl, 2				; High bits to beginning
+	rol		cl, 1				; High bits to beginning
+	rol		cl, 1
+%else
+	shr		cl, 6
+%endif
 	mov		bh, dh				; Copy Head number
 	xchg	cl, ch				; Cylinder number now in CX
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/AtaID.asm	(revision 618)
@@ -49,5 +49,6 @@
 
 	; Only correct cylinders since there are no reports that head or sectors could be wrong
-	MIN_U	WORD [es:si+ATA1.wCylCnt], MAX_PCHS_CYLINDERS		; Limit to max allowed value
+	mov		cx, MAX_PCHS_CYLINDERS
+	MIN_U	[es:si+ATA1.wCylCnt], cx	; Limit to max allowed value
 
 	; Note! There are ATA ID words 54-58 that also need to be modified! However,
Index: trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- trunk/XTIDE_Universal_BIOS/makefile	(revision 617)
+++ trunk/XTIDE_Universal_BIOS/makefile	(revision 618)
@@ -3,9 +3,10 @@
 #                                                                                                  #
 # Valid makefile targets are:                                                                      #
-# all       Removes existing files and builds binary files in \Build                               #
-# small     Builds 8 kiB binaries only (without checksum)                                          #
-# large     Builds 12 kiB binaries only (without checksum)                                         #
+# all       Removes existing files and builds binary files in \Build (without checksums)           #
+# small     Builds only binaries smaller than or equal to 8 kiB (without checksums)                #
+# large     Builds only binaries larger than 8 kiB (without checksums)                             #
+# custom    Builds custom binary without checksum (change DEFINES_CUSTOM / BIOS_SIZE_CUSTOM first) #
 # clean     Removes all files from \Build                                                          #
-# checksum* Builds all and then generates checksum byte to all binary files                        #
+# checksum* Same as 'all' but also applies checksums to the binaries                               #
 # strings*  Compress src\Strings.asm to src\StringsCompressed.asm                                  #
 # unused*   Checks if there are any unused functions that can be removed to save space             #
@@ -37,5 +38,5 @@
 # RELOCATE_INT13H_STACK **    Relocates INT 13h stack to beginning of stolen conventional memory   #
 # NO_ATAID_VALIDATION ***     Excludes code that tries to ensure proper communication with drives  #
-# NO_ATAID_CORRECTION		  Excludes code that corrects illegal CHS values from some CF cards    #
+# NO_ATAID_CORRECTION         Excludes code that corrects illegal CHS values from some CF cards    #
 # USE_186                     Use instructions supported by 80188/80186 and V20/V30 and later      #
 # USE_286                     Use instructions supported by 286 and later (defines USE_UNDOC_INTEL)#
@@ -104,7 +105,7 @@
 
 
-#################################################################
-# Assembler preprocessor defines.                               #
-#################################################################
+##################################
+# Assembler preprocessor defines #
+##################################
 DEFINES_COMMON = MODULE_STRINGS_COMPRESSED MODULE_HOTKEYS MODULE_8BIT_IDE MODULE_EBIOS MODULE_SERIAL MODULE_SERIAL_FLOPPY MODULE_POWER_MANAGEMENT NO_ATAID_VALIDATION CLD_NEEDED
 DEFINES_COMMON_LARGE = MODULE_BOOT_MENU MODULE_8BIT_IDE_ADVANCED MODULE_COMPATIBLE_TABLES
@@ -113,12 +114,14 @@
 DEFINES_XTPLUS = $(DEFINES_XT) USE_186
 DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 MODULE_IRQ MODULE_COMPATIBLE_TABLES
+DEFINES_386 = $(DEFINES_AT) USE_386 MODULE_ADVANCED_ATA MODULE_WIN9X_CMOS_HACK
 
 DEFINES_XT_LARGE = $(DEFINES_XT) $(DEFINES_COMMON_LARGE)
 DEFINES_XTPLUS_LARGE = $(DEFINES_XTPLUS) $(DEFINES_COMMON_LARGE)
 DEFINES_AT_LARGE = $(DEFINES_AT) $(DEFINES_COMMON_LARGE)
-
-DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE NO_ATAID_VALIDATION CLD_NEEDED
-DEFINES_386 = $(DEFINES_AT) USE_386 MODULE_ADVANCED_ATA MODULE_WIN9X_CMOS_HACK
 DEFINES_386_LARGE = $(DEFINES_386) $(DEFINES_COMMON_LARGE)
+
+DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE NO_ATAID_VALIDATION NO_ATAID_CORRECTION CLD_NEEDED
+
+DEFINES_CUSTOM = ?
 
 
@@ -132,4 +135,5 @@
 BIOS_SIZE_SMALL = 8192
 BIOS_SIZE_LARGE = 10240
+BIOS_SIZE_CUSTOM = ?
 
 # Add -D in front of every preprocessor define declaration
@@ -143,4 +147,5 @@
 DEFS_386 = $(DEFINES_386:%=-D%) -DBIOS_SIZE=$(BIOS_SIZE_SMALL)
 DEFS_386_LARGE = $(DEFINES_386_LARGE:%=-D%) -DBIOS_SIZE=$(BIOS_SIZE_LARGE)
+DEFS_CUSTOM = $(DEFINES_CUSTOM:%=-D%) -DBIOS_SIZE=$(BIOS_SIZE_CUSTOM)
 
 # Add -I in front of all header directories
@@ -149,4 +154,5 @@
 # Path + target file to be built
 TARGET = $(BUILD_DIR)/$(PROG)
+
 
 #########################
@@ -223,4 +229,8 @@
 	@$(AS) "$(SRC_ASM)" $(ASFLAGS) $(DEFS_386_LARGE) -l"$(TARGET)_386l.lst" -o"$(TARGET)_386l.bin"
 	@echo * Large 386 version "$(TARGET)_386l.bin" built.
+
+custom:
+	@$(AS) "$(SRC_ASM)" $(ASFLAGS) $(DEFS_CUSTOM) -l"$(TARGET)_custom.lst" -o"$(TARGET)_custom.bin"
+	@echo * Custom version "$(TARGET)_custom.bin" built.
 
 strings: src\Strings.asm
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm	(revision 617)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm	(revision 618)
@@ -144,5 +144,5 @@
 	jne		SHORT .IdeDeviceFound
 	mov		al, DEVICE_8BIT_XTCF_PIO8
-	jmp		SHORT .IdeDeviceFound
+	ret		; With CF cleared
 .ContinueDetection:
 	shr		bx, 1
@@ -331,5 +331,5 @@
 	dw		320h
 	dw		340h
-	dw		360h
+	dw		360h	; Acculogic sIDE-1/16 (same controller type as XT-IDE rev 1)
 	dw		380h
 	dw		3A0h
