Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm	(revision 546)
+++ 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
+
