Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Inc/MenuStructs.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Inc/MenuStructs.inc	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Inc/MenuStructs.inc	(revision 567)
@@ -47,5 +47,5 @@
 FLG_MENUITEM_BYTEVALUE		EQU	(1<<3)	; Item value is single byte
 FLG_MENUITEM_PROGRAMVAR		EQU	(1<<4)	; Item is for configuring program, not BIOS
-FLG_MENUITEM_CHOICESTRINGS  EQU (1<<5)  ; ChoiceToStringLookup table is 1-1 with ChoiceToValueLookup table,
+FLG_MENUITEM_CHOICESTRINGS	EQU (1<<5)	; ChoiceToStringLookup table is 1-1 with ChoiceToValueLookup table,
 										; ChoiceToStringLookup table must also be NULL terminated
 FLG_MENUITEM_MASKVALUE		EQU	(1<<6)	; Item value is more than one bit among other bits
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 567)
@@ -43,5 +43,5 @@
 ;	Returns:
 ;		ZF:		Set if supported version of XTIDE Universal BIOS is loaded
-;				Cleared no file or some other file is loaded
+;				Cleared if no file or some other file is loaded
 ;	Corrupts registers:
 ;		CX, SI, DI, ES
@@ -50,12 +50,12 @@
 Buffers_IsXtideUniversalBiosLoaded:
 	test	WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED
-	jz		SHORT .NoFileOrBiosLoaded
-
-	call	Buffers_GetFileBufferToESDI
-	jmp		SHORT Buffers_IsXtideUniversalBiosSignatureInESDI
-.NoFileOrBiosLoaded:
+	jnz		SHORT .FileOrBiosLoaded
 	or		cl, 1		; Clear ZF
 	ret
 
+.FileOrBiosLoaded:
+	call	Buffers_GetFileBufferToESDI
+	; Fall to Buffers_IsXtideUniversalBiosSignatureInESDI
+
 
 ;--------------------------------------------------------------------
@@ -65,5 +65,5 @@
 ;	Returns:
 ;		ZF:		Set if supported version of XTIDE Universal BIOS is loaded
-;				Cleared no file or some other file is loaded
+;				Cleared if no file or some other file is loaded
 ;	Corrupts registers:
 ;		CX, SI
@@ -183,5 +183,5 @@
 	mov		cx, [cs:di+g_rgwEepromTypeToSizeInWords]
 	sub		cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]	; CX = WORDs to append
-	jle		SHORT .NoNeedToAppendZeroes
+	jbe		SHORT .NoNeedToAppendZeroes
 
 	call	Buffers_GetFileBufferToESDI
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm	(revision 567)
@@ -38,5 +38,5 @@
 ;--------------------------------------------------------------------
 IdeAutodetect_DetectIdeDeviceFromPortDXAndReturnControlBlockInSI:
-	cmp		dx, FIRST_MEMORY_SEGMENT_ADDRESS
+	cmp		dh, FIRST_MEMORY_SEGMENT_ADDRESS >> 8
 	jb		SHORT DetectPortMappedDeviceFromPortDX
 	; Fall to DetectMemoryMappedDeviceFromSegmentDX
@@ -55,19 +55,32 @@
 ;--------------------------------------------------------------------
 DetectMemoryMappedDeviceFromSegmentDX:
-	; *** Try to detect JR-IDE/ISA (only if MODULE_8BIT_IDE_ADVANCED is present) ***
+	; *** Try to detect JR-IDE/ISA and ADP50L (only if MODULE_8BIT_IDE_ADVANCED is present) ***
 	test	WORD [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE_ADVANCED
-	jz		SHORT NoIdeDeviceFound
+	stc
+	jz		SHORT .NoIdeDeviceFound
 
 	push	ds
 	mov		ds, dx
-	cli									; Disable Interrupts
+
+	cli
 	mov		ah, [JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET + STATUS_REGISTER_in]
 	mov		al, [JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET + ALTERNATE_STATUS_REGISTER_in]
-	sti									; Enable Interrupts
+	sti
+	call	CompareIdeStatusRegistersFromALandAH
+	mov		al, DEVICE_8BIT_JRIDE_ISA
+	jnc		.IdeDeviceFound
+
+	cli
+	mov		ah, [ADP50L_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET + (STATUS_REGISTER_in << 1)]
+	mov		al, [ADP50L_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET + (ALTERNATE_STATUS_REGISTER_in << 1)]
+	sti
+	call	CompareIdeStatusRegistersFromALandAH
+	mov		al, DEVICE_8BIT_ADP50L
+
+.IdeDeviceFound:
+	mov		si, dx						; For IDEDTCT.COM
 	pop		ds
-	call	CompareIdeStatusRegistersFromALandAH
-	mov		al, DEVICE_8BIT_JRIDE_ISA	; Assume CF was cleared
-	mov		si, dx						; For IDEDTCT.COM
-	ret									; No need to return Control Block Port
+.NoIdeDeviceFound:
+	ret
 
 
@@ -110,6 +123,7 @@
 
 	; Detect 8-bit devices only if MODULE_8BIT_IDE is available
-	test	BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE
+	test	BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE | FLG_ROMVARS_MODULE_8BIT_IDE_ADVANCED
 	jz		SHORT NoIdeDeviceFound
+	jpo		SHORT .SkipXTCF				; Only 1 bit set means no MODULE_8BIT_IDE_ADVANCED
 
 	; *** Try to detect XT-CF ***
@@ -120,5 +134,6 @@
 	mov		al, DEVICE_8BIT_XTCF_PIO8
 	jnc		SHORT .IdeDeviceFound
-
+	shr		bx, 1
+.SkipXTCF:
 
 	; *** Try to detect 8-bit XT-IDE rev 1 or rev 2 ***
@@ -126,6 +141,6 @@
 	; Status Register addresses. That is why we need another step
 	; to check is this XT-IDE rev 1 or rev 2.
-	sub		si, BYTE XTCF_CONTROL_BLOCK_OFFSET >> 1
-	shr		bx, 1
+	mov		si, dx
+	add		si, BYTE XTIDE_CONTROL_BLOCK_OFFSET
 	call	DetectIdeDeviceFromPortsDXandSIwithOffsetsInBLandBH
 	jc		SHORT NoIdeDeviceFound		; No XT-IDE rev 1 or rev 2 found
@@ -210,5 +225,5 @@
 	test	al, FLG_STATUS_DRDY
 	jz		SHORT NoIdeDeviceFound	; Device needs to be ready
-	ret										; Return with CF cleared
+	ret								; Return with CF cleared
 
 NoIdeDeviceFound:
@@ -305,12 +320,14 @@
 	dw		3C0h
 	dw		3E0h
-	; JR-IDE/ISA (Memory Segment Addresses)
-	dw		0C000h
-	dw		0C400h
-	dw		0C800h
-	dw		0CC00h
-	dw		0D000h
-	dw		0D400h
-	dw		0D800h
+	; Memory Segment Addresses
+	dw		0C000h	; JR-IDE/ISA
+	dw		0C400h	; JR-IDE/ISA
+	dw		0C800h	; JR-IDE/ISA and ADP50L
+	dw		0CA00h	; ADP50L
+	dw		0CC00h	; JR-IDE/ISA and ADP50L
+	dw		0CE00h	; ADP50L
+	dw		0D000h	; JR-IDE/ISA
+	dw		0D400h	; JR-IDE/ISA
+	dw		0D800h	; JR-IDE/ISA
 .wLastIdePort:
-	dw		0DC00h
+	dw		0DC00h	; JR-IDE/ISA
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menuitem.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menuitem.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menuitem.asm	(revision 567)
@@ -389,2 +389,23 @@
 	mov		di, g_cfgVars
 	ret
+
+
+;--------------------------------------------------------------------
+; EnableMenuitemFromCSBX
+; DisableMenuitemFromCSBX
+;	Parameters:
+;		CS:BX:	Ptr to MENUITEM
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+EnableMenuitemFromCSBX:
+	or		BYTE [cs:bx+MENUITEM.bFlags], FLG_MENUITEM_VISIBLE
+	ret
+
+ALIGN JUMP_ALIGN
+DisableMenuitemFromCSBX:
+	and		BYTE [cs:bx+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
+	ret
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/BootMenuSettingsMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/BootMenuSettingsMenu.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/BootMenuSettingsMenu.asm	(revision 567)
@@ -235,11 +235,9 @@
 ALIGN JUMP_ALIGN
 .EnableMenuitemFromCSBX:
-	or		BYTE [cs:bx+MENUITEM.bFlags], FLG_MENUITEM_VISIBLE
-	ret
+	jmp		EnableMenuitemFromCSBX
 
 ALIGN JUMP_ALIGN
 .DisableMenuitemFromCSBX:
-	and		BYTE [cs:bx+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
-	ret
+	jmp		DisableMenuitemFromCSBX
 
 
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm	(revision 567)
@@ -217,11 +217,6 @@
 .DisableAllIdeControllerMenuitems:
 	mov		cx, MAX_ALLOWED_IDE_CONTROLLERS-1
-	mov		bx, g_MenuitemConfigurationSecondaryIdeController
-ALIGN JUMP_ALIGN
-.DisableNextIdeControllerMenuitem:
-	call	.DisableMenuitemFromCSBX
-	add		bx, BYTE MENUITEM_size
-	loop	.DisableNextIdeControllerMenuitem
-	ret
+	mov		ax, DisableMenuitemFromCSBX
+	jmp		SHORT .Go
 
 ALIGN JUMP_ALIGN
@@ -230,10 +225,12 @@
 	dec		cx			; Primary always enabled
 	jz		SHORT .PrimaryControllerAlreadyEnabled
+	mov		ax, EnableMenuitemFromCSBX
+.Go:
 	mov		bx, g_MenuitemConfigurationSecondaryIdeController
 ALIGN JUMP_ALIGN
-.EnableNextIdeControllerMenuitem:
-	call	.EnableMenuitemFromCSBX
+.EnableOrDisableNextIdeControllerMenuitem:
+	call	ax
 	add		bx, BYTE MENUITEM_size
-	loop	.EnableNextIdeControllerMenuitem
+	loop	.EnableOrDisableNextIdeControllerMenuitem
 .PrimaryControllerAlreadyEnabled:
 	ret
@@ -288,5 +285,5 @@
 	call	Buffers_GetRomvarsFlagsToAX
 	mov		bx, g_MenuitemConfigurationIdleTimeout
-	test	ax, FLG_ROMVARS_MODULE_FEATURE_SETS
+	test	ax, FLG_ROMVARS_MODULE_POWER_MANAGEMENT
 	jz		SHORT .DisableMenuitemFromCSBX
 	; Fall to .EnableMenuitemFromCSBX
@@ -305,12 +302,9 @@
 ALIGN JUMP_ALIGN
 .EnableMenuitemFromCSBX:
-	or		BYTE [cs:bx+MENUITEM.bFlags], FLG_MENUITEM_VISIBLE
-	ret
+	jmp		EnableMenuitemFromCSBX
 
 ALIGN JUMP_ALIGN
 .DisableMenuitemFromCSBX:
-	and		BYTE [cs:bx+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
-	ret
-
+	jmp		DisableMenuitemFromCSBX
 
 
@@ -419,5 +413,5 @@
 	jnz		.next
 	mov		si, di
-	jmp		.next
+	SKIP2B	f
 
 .notSerial:
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm	(revision 567)
@@ -242,8 +242,10 @@
 	dw	NULL
 
-SERIAL_DEFAULT_CUSTOM_PORT   EQU		300h           ; can't be any of the pre-defined COM values
-
-PackedCOMPortAddresses:				; COM1 - COMC (or COM12)
-	db      SERIAL_COM1_IOADDRESS >> 2
+SERIAL_DEFAULT_CUSTOM_PORT		EQU		300h		; can't be any of the pre-defined COM values
+SERIAL_DEFAULT_COM				EQU		'1'
+SERIAL_DEFAULT_BAUD				EQU		((115200 / 9600)	& 0xff)
+
+PackedCOMPortAddresses:								; COM1 - COMC (or COM12)
+	db		SERIAL_COM1_IOADDRESS >> 2
 	db		SERIAL_COM2_IOADDRESS >> 2
 	db		SERIAL_COM3_IOADDRESS >> 2
@@ -258,5 +260,4 @@
 	db		SERIAL_COMC_IOADDRESS >> 2
 	db		SERIAL_DEFAULT_CUSTOM_PORT >> 2			; must be last entry (see reader/writer routines)
-SERIAL_DEFAULT_COM			EQU		'1'
 
 g_rgbChoiceToValueLookupForBaud:
@@ -279,5 +280,4 @@
 	dw		g_szValueCfgBaud2400
 	dw		NULL
-SERIAL_DEFAULT_BAUD			EQU		((115200 / 9600)	& 0xff)
 
 ; Section containing code
@@ -339,4 +339,5 @@
 	push	cs
 	pop		ds
+	call	.EnableOrDisableCommandBlockPort
 	call	.EnableOrDisableControlBlockPort
 	call	.DisableIRQchannelSelection
@@ -345,4 +346,23 @@
 	mov		si, g_MenupageForIdeControllerMenu
 	jmp		Menupage_ChangeToNewMenupageInDSSI
+
+
+;--------------------------------------------------------------------
+; .EnableOrDisableCommandBlockPort
+;	Parameters:
+;		SS:BP:	Menu handle
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.EnableOrDisableCommandBlockPort:
+	mov		bx, [cs:g_MenuitemIdeControllerDevice+MENUITEM.itemValue+ITEM_VALUE.wRomvarsValueOffset]
+	call	Buffers_GetRomvarsValueToAXfromOffsetInBX
+	mov		bx, g_MenuitemIdeControllerCommandBlockAddress
+	cmp		al, DEVICE_SERIAL_PORT
+	je		SHORT .DisableMenuitemFromCSBX
+	jmp		SHORT .EnableMenuitemFromCSBX
 
 
@@ -385,8 +405,8 @@
 	call	Buffers_GetRomvarsValueToAXfromOffsetInBX
 	mov		bx, g_MenuitemIdeControllerEnableInterrupt
-	cmp		al, DEVICE_8BIT_XTIDE_REV2
+	cmp		al, DEVICE_8BIT_XTCF_PIO8
 	jae		SHORT .DisableMenuitemFromCSBX
 
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 	; Fall to .EnableOrDisableIRQchannelSelection
 
@@ -424,40 +444,38 @@
 ALIGN JUMP_ALIGN
 .DisableMenuitemFromCSBX:
-	and		BYTE [cs:bx+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
-	ret
+	jmp		DisableMenuitemFromCSBX
 
 ALIGN JUMP_ALIGN
 .EnableMenuitemFromCSBX:
-	or		BYTE [cs:bx+MENUITEM.bFlags], FLG_MENUITEM_VISIBLE
-	ret
+	jmp		EnableMenuitemFromCSBX
 
 
 .EnableOrDisableSerial:
 	mov		bx, g_MenuitemIdeControllerSerialBaud
-	call	.DisableMenuitemFromCSBX
+	call	DisableMenuitemFromCSBX
 
 	mov		bx, g_MenuitemIdeControllerSerialCOM
-	call	.DisableMenuitemFromCSBX
+	call	DisableMenuitemFromCSBX
 
 	mov		bx, g_MenuitemIdeControllerSerialPort
-	call	.DisableMenuitemFromCSBX
+	call	DisableMenuitemFromCSBX
 
 	mov		bx, [cs:g_MenuitemIdeControllerDevice+MENUITEM.itemValue+ITEM_VALUE.wRomvarsValueOffset]
 	call	Buffers_GetRomvarsValueToAXfromOffsetInBX
 	cmp		al, DEVICE_SERIAL_PORT
-	jnz		.DisableAllSerial
+	jne		.DisableAllSerial
 
 	mov		bx, g_MenuitemIdeControllerSerialCOM
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 
 	mov		bx, g_MenuitemIdeControllerSerialBaud
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 
 	mov		bx, [cs:g_MenuitemIdeControllerSerialCOM+MENUITEM.itemValue+ITEM_VALUE.wRomvarsValueOffset]
 	call	Buffers_GetRomvarsValueToAXfromOffsetInBX
 	mov		bx, g_MenuitemIdeControllerSerialPort
-	cmp		al,'x'
-	jz		.EnableMenuitemFromCSBX
-	jmp		.DisableMenuitemFromCSBX
+	cmp		al, 'x'
+	je		SHORT .EnableMenuitemFromCSBX
+	jmp		SHORT .DisableMenuitemFromCSBX
 .DisableAllSerial:
 	ret
@@ -485,5 +503,5 @@
 DisplayMasterSlaveMenu:
 ;
-; block mode is not supported on serial drives, disable/enable the option as appropriate
+; "Block Mode Transfers" and "Internal Write Cache" are not supported on serial drives, disable/enable the options as appropriate
 ;
 	push	bx
@@ -491,10 +509,18 @@
 	call	Buffers_GetRomvarsValueToAXfromOffsetInBX
 	mov		bx, g_MenuitemMasterSlaveBlockModeTransfers
-	cmp		al,DEVICE_SERIAL_PORT
-	jz		.isSerial
-	or		BYTE [cs:bx+MENUITEM.bFlags], FLG_MENUITEM_VISIBLE
+
+	cmp		al, DEVICE_SERIAL_PORT
+	je		.isSerial
+
+	call	EnableMenuitemFromCSBX
+	mov		bx, g_MenuitemMasterSlaveWriteCache
+	call	EnableMenuitemFromCSBX
 	jmp		.isDone
+
 .isSerial:
-	and		BYTE [cs:bx+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
+	call	DisableMenuitemFromCSBX
+	mov		bx, g_MenuitemMasterSlaveWriteCache
+	call	DisableMenuitemFromCSBX
+
 .isDone:
 	pop		bx
@@ -515,7 +541,7 @@
 ; Writers:
 ;	Parameters:
-;       AX:     Value that the MENUITEM system was interacting with
-;		ES:DI:  ROMVARS location where the value is to be stored
-;	    DS:SI:  MENUITEM pointer
+;		AX:		Value that the MENUITEM system was interacting with
+;		ES:DI:	ROMVARS location where the value is to be stored
+;		DS:SI:	MENUITEM pointer
 ;	Returns:
 ;		AX:		Value to actually write to ROMVARS
@@ -525,7 +551,7 @@
 ; Readers:
 ;	Parameters:
-;       AX:     Value read from the ROMVARS location
-;		ES:DI:  ROMVARS location where the value was just read from
-;	    DS:SI:  MENUITEM pointer
+;		AX:		Value read from the ROMVARS location
+;		ES:DI:	ROMVARS location where the value was just read from
+;		DS:SI:	MENUITEM pointer
 ;	Returns:
 ;		AX:		Value that the MENUITEM system will interact with and display
@@ -535,12 +561,9 @@
 ALIGN JUMP_ALIGN
 WriterForXTCFwindow:
-	mov		al, ah
+	xor		al, al
+	SKIP2B	f
+ReaderForXTCFwindow:
 	xor		ah, ah
-	ret
-
-ALIGN JUMP_ALIGN
-ReaderForXTCFwindow:
-	mov		ah, al
-	xor		al, al
+	xchg	al, ah
 	ret
 
@@ -552,62 +575,60 @@
 ALIGN JUMP_ALIGN
 IdeControllerMenu_WriteDevice:
-		push	bx
-		push	di
-		push	di
-		push	ax
-
-		; Note! AL is the choice index, not device code
-		shl		ax, 1								; Selection to device code
-		mov		bl, [es:di]							; what is the current Device we are changing from?
-		sub		di, BYTE IDEVARS.bDevice - IDEVARS.wBasePort	; Get ready to set the Port addresses
-		cmp		al, DEVICE_SERIAL_PORT
-		je		SHORT .changingToSerial
-		cmp		al, DEVICE_8BIT_JRIDE_ISA
-		je		SHORT .ChangingToJrIdeIsa
-		cmp		al, DEVICE_8BIT_ADP50L
-		je		SHORT .ChangingToADP50L
-
-		; Restore ports to default values
-		cmp		al, DEVICE_8BIT_ATA					; Standard ATA controllers, including 8-bit mode
-		mov		ax, DEVICE_ATA_PRIMARY_PORT			; Defaults for 16-bit and better ATA devices
-		mov		bx, DEVICE_ATA_PRIMARY_PORTCTRL
-		jbe		SHORT .writeNonSerial
-
-		mov		ax, DEVICE_XTIDE_DEFAULT_PORT		; Defaults for 8-bit XTIDE and XT-CF devices
-		mov		bx, DEVICE_XTIDE_DEFAULT_PORTCTRL
-
-.writeNonSerial:
-		stosw										; Store defaults in IDEVARS.wBasePort and IDEVARS.wBasePortCtrl
-		xchg	bx, ax
-		stosw
-		jmp		SHORT .done
+	push	bx
+	push	di
+	push	ax
+
+	; Note! AL is the choice index, not device code
+	shl		ax, 1								; Selection to device code
+	mov		bl, [es:di]							; what is the current Device we are changing from?
+	sub		di, BYTE IDEVARS.bDevice - IDEVARS.wBasePort	; Get ready to set the Port addresses
+	cmp		al, DEVICE_SERIAL_PORT
+	je		SHORT .ChangingToSerial
+	cmp		al, DEVICE_8BIT_JRIDE_ISA
+	je		SHORT .ChangingToJrIdeIsa
+	cmp		al, DEVICE_8BIT_ADP50L
+	je		SHORT .ChangingToADP50L
+
+	; Restore ports to default values
+	cmp		al, DEVICE_8BIT_ATA					; Standard ATA controllers, including 8-bit mode
+	mov		ax, DEVICE_ATA_PRIMARY_PORT			; Defaults for 16-bit and better ATA devices
+	mov		bx, DEVICE_ATA_PRIMARY_PORTCTRL
+	jbe		SHORT .WriteNonSerial
+
+	mov		ax, DEVICE_XTIDE_DEFAULT_PORT		; Defaults for 8-bit XTIDE and XT-CF devices
+	mov		bx, DEVICE_XTIDE_DEFAULT_PORTCTRL
+
+.WriteNonSerial:
+	stosw										; Store defaults in IDEVARS.wBasePort and IDEVARS.wBasePortCtrl
+	xchg	bx, ax
+	stosw
+	jmp		SHORT .Done
 
 .ChangingToJrIdeIsa:
-		mov		ah, JRIDE_DEFAULT_SEGMENT_ADDRESS >> 8
-		SKIP2B	bx
+	mov		ah, JRIDE_DEFAULT_SEGMENT_ADDRESS >> 8
+	SKIP2B	bx
 
 .ChangingToADP50L:
-		mov		ah, ADP50L_DEFAULT_BIOS_SEGMENT_ADDRESS >> 8
-		xor		al, al
-		xor		bx, bx
-		jmp		SHORT .writeNonSerial
-
-.changingToSerial:
-		cmp		bl, DEVICE_SERIAL_PORT
-		je		SHORT .done							; if we were already serial, nothing to do
-
-		mov		BYTE [es:di+IDEVARS.bSerialBaud-IDEVARS.wBasePort], SERIAL_DEFAULT_BAUD
-
-		mov		al, SERIAL_DEFAULT_COM
-		sub		di, IDEVARS.wBasePort - IDEVARS.bSerialCOMPortChar
-		call	IdeControllerMenu_SerialWriteCOM
-		stosb
-
-.done:
-		pop		ax
-		pop		di			; IDEVARS.bDevice
-		pop		di
-		pop		bx
-		ret
+	mov		ah, ADP50L_DEFAULT_BIOS_SEGMENT_ADDRESS >> 8
+	xor		al, al
+	xor		bx, bx
+	jmp		SHORT .WriteNonSerial
+
+.ChangingToSerial:
+	cmp		bl, DEVICE_SERIAL_PORT
+	je		SHORT .Done							; if we were already serial, nothing to do
+
+	mov		BYTE [es:di+IDEVARS.bSerialBaud-IDEVARS.wBasePort], SERIAL_DEFAULT_BAUD
+
+	mov		al, SERIAL_DEFAULT_COM
+	sub		di, IDEVARS.wBasePort - IDEVARS.bSerialCOMPortChar
+	call	IdeControllerMenu_SerialWriteCOM
+	stosb
+
+.Done:
+	pop		ax
+	pop		di			; IDEVARS.bDevice
+	pop		bx
+	ret
 
 ;
@@ -617,37 +638,37 @@
 ALIGN JUMP_ALIGN
 IdeControllerMenu_SerialWriteCOM:
-		push	ax
-		push	bx
-		push	si
-
-		mov		si,g_rgbChoiceToValueLookupForCOM
-		mov		bx,PackedCOMPortAddresses
+	push	ax
+	push	bx
+	push	si
+
+	mov		si, g_rgbChoiceToValueLookupForCOM
+	mov		bx, PackedCOMPortAddresses
 
 .loop:
-		mov		ah,[bx]
-
-		cmp		ah,(SERIAL_DEFAULT_CUSTOM_PORT >> 2)
-		jz		.notFound
-
-		cmp		al,[si]
-		jz		.found
-
-		inc		si
-		inc		si
-		inc		bx
-
-		jmp		.loop
+	mov		ah, [bx]
+
+	cmp		ah, (SERIAL_DEFAULT_CUSTOM_PORT >> 2)
+	je		.notFound
+
+	cmp		al, [si]
+	je		.found
+
+	inc		si
+	inc		si
+	inc		bx
+
+	jmp		.loop
 
 .notFound:
-		mov		al, 'x'
+	mov		al, 'x'
 
 .found:
-		mov		[es:di+IDEVARS.bSerialPort-IDEVARS.bSerialCOMPortChar], ah
-
-		pop		si
-		pop		bx
-		pop		ax
-
-		ret
+	mov		[es:di+IDEVARS.bSerialPort-IDEVARS.bSerialCOMPortChar], ah
+
+	pop		si
+	pop		bx
+	pop		ax
+
+	ret
 
 
@@ -657,7 +678,7 @@
 ALIGN JUMP_ALIGN
 IdeControllerMenu_SerialReadPort:
-		xor		ah,ah
-		eSHL_IM	ax, 2
-		ret
+	xor		ah, ah
+	eSHL_IM	ax, 2
+	ret
 
 ;
@@ -667,33 +688,33 @@
 ALIGN JUMP_ALIGN
 IdeControllerMenu_SerialWritePort:
-		push	bx
-		push	si
-
-		eSHR_IM	ax, 2
-		and		al,0feh			; force 8-byte boundary
-
-		mov		si,g_rgbChoiceToValueLookupForCOM
-		mov		bx,PackedCOMPortAddresses			; loop, looking for port address in known COM address list
+	push	bx
+	push	si
+
+	eSHR_IM	ax, 2
+	and		al, 0feh			; force 8-byte boundary
+
+	mov		si, g_rgbChoiceToValueLookupForCOM
+	mov		bx, PackedCOMPortAddresses			; loop, looking for port address in known COM address list
 
 .loop:
-		mov		ah,[si]
-		cmp		ah,'x'
-		jz		.found
-
-		cmp		al,[bx]
-		jz		.found
-
-		inc		si
-		inc		si
-		inc		bx
-
-		jmp		.loop
+	mov		ah, [si]
+	cmp		ah, 'x'
+	je		.found
+
+	cmp		al, [bx]
+	je		.found
+
+	inc		si
+	inc		si
+	inc		bx
+
+	jmp		.loop
 
 .found:
-		mov		[es:di+IDEVARS.bSerialCOMPortChar-IDEVARS.bSerialPort], ah
-
-		pop		si
-		pop		bx
-
-		ret
-
+	mov		[es:di+IDEVARS.bSerialCOMPortChar-IDEVARS.bSerialPort], ah
+
+	pop		si
+	pop		bx
+
+	ret
+
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/MasterSlaveMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/MasterSlaveMenu.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/MasterSlaveMenu.asm	(revision 567)
@@ -290,21 +290,21 @@
 	; Enable both
 	mov		bx, g_MenuitemMasterSlaveUserCHS
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveUserLBA
-	jmp		.EnableMenuitemFromCSBX
+	jmp		SHORT .EnableMenuitemFromCSBX
 
 ALIGN JUMP_ALIGN
 .EnableCHSandDisableLBA:
 	mov		bx, g_MenuitemMasterSlaveUserCHS
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveUserLBA
-	jmp		.DisableMenuitemFromCSBX
+	jmp		SHORT .DisableMenuitemFromCSBX
 
 ALIGN JUMP_ALIGN
 .DisableCHSandEnableLBA:
 	mov		bx, g_MenuitemMasterSlaveUserLBA
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveUserCHS
-	jmp		.DisableMenuitemFromCSBX
+	jmp		SHORT .DisableMenuitemFromCSBX
 
 
@@ -328,7 +328,7 @@
 
 	mov		bx, g_MenuitemMasterSlaveCylinders
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveHeads
-	call	.EnableMenuitemFromCSBX
+	call	EnableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveSectors
 	jmp		SHORT .EnableMenuitemFromCSBX
@@ -337,7 +337,7 @@
 .DisableCHandS:
 	mov		bx, g_MenuitemMasterSlaveCylinders
-	call	.DisableMenuitemFromCSBX
+	call	DisableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveHeads
-	call	.DisableMenuitemFromCSBX
+	call	DisableMenuitemFromCSBX
 	mov		bx, g_MenuitemMasterSlaveSectors
 	jmp		SHORT .DisableMenuitemFromCSBX
@@ -377,11 +377,9 @@
 ALIGN JUMP_ALIGN
 .EnableMenuitemFromCSBX:
-	or		BYTE [cs:bx+MENUITEM.bFlags], FLG_MENUITEM_VISIBLE
-	ret
+	jmp		EnableMenuitemFromCSBX
 
 ALIGN JUMP_ALIGN
 .DisableMenuitemFromCSBX:
-	and		BYTE [cs:bx+MENUITEM.bFlags], ~FLG_MENUITEM_VISIBLE
-	ret
+	jmp		DisableMenuitemFromCSBX
 
 
@@ -407,5 +405,5 @@
 
 	xchg	ax, dx				; SHR 16
-	eSHIFT_IM ax, 4, shr		; SHR 4 => AX = DX:AX / (1024*1024)
+	eSHR_IM	ax, 4				; SHR 4 => AX = DX:AX / (1024*1024)
 
 	pop		dx
@@ -429,5 +427,5 @@
 
 	xor		dx, dx
-	eSHIFT_IM ax, 4, shl
+	eSHL_IM	ax, 4
 	xchg	dx, ax			; DX:AX now holds AX * 1024 * 1024
 
@@ -445,29 +443,29 @@
 ALIGN JUMP_ALIGN
 MasterSlaveMenu_WriteCHSFlag:
-		test	word [es:di], FLG_DRVPARAMS_USERCHS
-		jnz		.alreadySet
-
-		push	ax
-		push	di
-		push	si
-
-		mov		ax, MASTERSLAVE_CYLINDERS_DEFAULT
-		mov		si, g_MenuitemMasterSlaveCylinders
-		call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
-
-		mov		ax, MASTERSLAVE_HEADS_DEFAULT
-		mov		si, g_MenuitemMasterSlaveHeads
-		call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
-
-		mov		ax, MASTERSLAVE_SECTORS_DEFAULT
-		mov		si, g_MenuitemMasterSlaveSectors
-		call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
-
-		pop		si
-		pop		di
-		pop		ax
+	test	word [es:di], FLG_DRVPARAMS_USERCHS
+	jnz		.alreadySet
+
+	push	ax
+	push	di
+	push	si
+
+	mov		ax, MASTERSLAVE_CYLINDERS_DEFAULT
+	mov		si, g_MenuitemMasterSlaveCylinders
+	call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
+
+	mov		ax, MASTERSLAVE_HEADS_DEFAULT
+	mov		si, g_MenuitemMasterSlaveHeads
+	call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
+
+	mov		ax, MASTERSLAVE_SECTORS_DEFAULT
+	mov		si, g_MenuitemMasterSlaveSectors
+	call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
+
+	pop		si
+	pop		di
+	pop		ax
 
 .alreadySet:
-		ret
+	ret
 
 ;
@@ -477,19 +475,19 @@
 ALIGN JUMP_ALIGN
 MasterSlaveMenu_WriteLBAFlag:
-		test	word [es:di], FLG_DRVPARAMS_USERLBA
-		jnz		.alreadySet
-
-		push	ax
-		push	di
-		push	si
-
-		mov		ax, MASTERSLAVE_USERLBA_DEFAULT
-		mov		si, g_MenuitemMasterSlaveUserLbaValue
-		call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
-
-		pop		si
-		pop		di
-		pop		ax
+	test	word [es:di], FLG_DRVPARAMS_USERLBA
+	jnz		.alreadySet
+
+	push	ax
+	push	di
+	push	si
+
+	mov		ax, MASTERSLAVE_USERLBA_DEFAULT
+	mov		si, g_MenuitemMasterSlaveUserLbaValue
+	call	Menuitem_StoreValueFromAXtoMenuitemInDSSI
+
+	pop		si
+	pop		di
+	pop		ax
 
 .alreadySet:
-		ret
+	ret
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm	(revision 565)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm	(revision 567)
@@ -69,6 +69,6 @@
 g_szItemMainFlash:		db	"Flash EEPROM",NULL
 g_szItemMainSave:		db	"Save BIOS back to original file",NULL
-g_szItemMainLicense:	db  "Copyright and License Information",NULL
-g_szItemMainHomePage:	db  "Web Links",NULL
+g_szItemMainLicense:	db	"Copyright and License Information",NULL
+g_szItemMainHomePage:	db	"Web Links",NULL
 
 g_szDlgMainLoadROM:		db	"Successfully loaded XTIDE Universal BIOS from EEPROM.",NULL
@@ -128,5 +128,5 @@
 g_szNfoCfgIdleTimeout:	db	"Enable Power Management to set the harddrive(s) to spin down after idling a certain amount of time.",NULL
 
-g_szSerialMoved:		db  "A Serial Controller has been moved to the end of the Controller list."
+g_szSerialMoved:		db	"A Serial Controller has been moved to the end of the Controller list."
 						db	" No further action is required. Serial Controllers must be placed at the end of the list.",NULL
 
@@ -294,10 +294,10 @@
 g_szValueCfgDeviceSerial:					db	"Serial",NULL
 
-g_szSerialCOMChoice:	db  "COM1 - address 3F8h",LF
+g_szSerialCOMChoice:	db	"COM1 - address 3F8h",LF
 						db	"COM2 - address 2F8h",LF
-						db  "COM3 - address 3E8h",LF
-						db  "COM4 - address 2E8h",LF
-						db  "COM5 - address 2F0h",LF
-						db  "COM6 - address 3E0h",LF
+						db	"COM3 - address 3E8h",LF
+						db	"COM4 - address 2E8h",LF
+						db	"COM5 - address 2F0h",LF
+						db	"COM6 - address 3E0h",LF
 						db	"COM7 - address 2E0h",LF
 						db	"COM8 - address 260h",LF
@@ -306,5 +306,5 @@
 						db	"COMB - address 360h",LF
 						db	"COMC - address 270h",LF
-						db  "COMx - Custom address",NULL
+						db	"COMx - Custom address",NULL
 
 g_szValueCfgCOM1:		db	"COM1",NULL
@@ -322,12 +322,12 @@
 g_szValueCfgCOMx:		db	"Custom",NULL
 
-g_szSerialBaudChoice:	db  "115.2K baud",LF
-						db  "57.6K baud",LF
+g_szSerialBaudChoice:	db	"115.2K baud",LF
+						db	"57.6K baud",LF
 						db	"38.4K baud",LF
-						db  "28.8K baud",LF
-						db  "19.2K baud",LF
+						db	"28.8K baud",LF
+						db	"19.2K baud",LF
 						db	"9600 baud",LF
-						db  "4800 baud",LF
-						db  "2400 baud",NULL
+						db	"4800 baud",LF
+						db	"2400 baud",NULL
 
 g_szValueCfgBaud115_2:	db	"115.2K",NULL
@@ -377,8 +377,8 @@
 						db	" least one drive with buggy Block Mode implementation.",NULL
 
-g_szHelpDrvWriteCache:	db	"Modern Hard Drives have large internal write cache."
-						db	" The cache will speed up writes since the drive can free the bus right after data has been written in cache."
-						db	" The drive then starts to write the data from cache by itself."
-						db	" That can be dangerous since all unwritten data in cache is lost if power is turned off or the system is reset."
+g_szHelpDrvWriteCache:	db	"Modern Hard Drives have a large amount of internal write cache."
+						db	" The cache will speed up writes since the drive can free the bus right after data has been written to cache."
+						db	" The drive then starts to write the data from cache to disk by itself."
+						db	" This can be dangerous since all unwritten data in cache is lost if power is turned off or the system is reset."
 						db	" Modern operating systems will flush the cache when user shuts down the system."
 						db	" DOS does not have that sort of protection so it is up to the user to make sure cache is flushed."
