Index: /trunk/Assembly_Library/Inc/CgaSnow.inc
===================================================================
--- /trunk/Assembly_Library/Inc/CgaSnow.inc	(revision 588)
+++ /trunk/Assembly_Library/Inc/CgaSnow.inc	(revision 589)
@@ -1,7 +1,3 @@
-; File name		:	CgaSnow.inc
-; Project name	:	AssemblyLibrary
-; Created date	:	8.10.2010
-; Last update	:	11.10.2010
-; Author		:	Tomi Tilli
+; Project name	:	Assembly Library
 ; Description	:	Macros for preventing CGA snow.
 %ifndef CGASNOW_INC
@@ -9,5 +5,6 @@
 
 ;--------------------------------------------------------------------
-; WAIT_RETRACE_IF_NECESSARY_THEN
+; CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN
+; JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN
 ;	Parameters:
 ;		%1:		Instruction that accessed CGA memory
@@ -22,5 +19,5 @@
 ;		AX, DX
 ;--------------------------------------------------------------------
-%macro WAIT_RETRACE_IF_NECESSARY_THEN 1
+%macro CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN 1
 %ifdef ELIMINATE_CGA_SNOW
 	%ifidn %1, stosb
@@ -31,5 +28,5 @@
 		call	CgaSnow_RepMovsb
 	%else
-		%error	"Invalid instruction passed to WAIT_RETRACE_IF_NECESSARY_THEN"
+		%error	"Invalid instruction passed to CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN"
 	%endif
 %else	; No CGA snow prevention
@@ -38,4 +35,26 @@
 	%else
 		%1	; Single instruction
+	%endif
+%endif
+%endmacro
+
+%macro JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN 1
+%ifdef ELIMINATE_CGA_SNOW
+	%ifidn %1, stosb
+		jmp		CgaSnow_Stosb
+	%elifidn %1, stosw
+		jmp		CgaSnow_Stosw
+	%elifidn %1, rep movsb
+		jmp		CgaSnow_RepMovsb
+	%else
+		%error	"Invalid instruction passed to JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN"
+	%endif
+%else	; No CGA snow prevention
+	%ifidn %1, rep movsb
+		eSEG_STR rep, es, movsb
+		ret
+	%else
+		%1	; Single instruction
+		ret
 	%endif
 %endif
Index: /trunk/Assembly_Library/Inc/DosFunctions.inc
===================================================================
--- /trunk/Assembly_Library/Inc/DosFunctions.inc	(revision 588)
+++ /trunk/Assembly_Library/Inc/DosFunctions.inc	(revision 589)
@@ -9,27 +9,31 @@
 DOS_TSR_MULTIPLEX_INTERRUPT_2Fh						EQU		2Fh
 
-; DOS drive and file functions
-SELECT_DEFAULT_DRIVE								EQU		0Eh
-GET_CURRENT_DEFAULT_DRIVE							EQU		19h
-GET_DISK_TRANSFER_AREA_ADDRESS						EQU		2Fh
-GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE	EQU		32h
-SET_CURRENT_DIRECTORY								EQU		3Bh
-CREATE_OR_TRUNCATE_FILE								EQU		3Ch
-OPEN_EXISTING_FILE									EQU		3Dh
-CLOSE_FILE											EQU		3Eh
-READ_FROM_FILE_OR_DEVICE							EQU		3Fh
-WRITE_TO_FILE_OR_DEVICE								EQU		40h
-SET_CURRENT_FILE_POSITION							EQU		42h
-GET_CURRENT_DIRECTORY								EQU		47h
-FIND_FIRST_MATCHING_FILE							EQU		4Eh
-FIND_NEXT_MATCHING_FILE								EQU		4Fh
-
-; DOS functions for TSRs
-SET_INTERRUPT_VECTOR								EQU		25h
-GET_INTERRUPT_VECTOR								EQU		35h
+; DOS functions
+WRITE_CHARACTER_TO_STANDARD_OUTPUT					EQU		02h		; DOS 1+
+WRITE_STRING_TO_STANDARD_OUTPUT						EQU		09h		; DOS 1+
+SELECT_DEFAULT_DRIVE								EQU		0Eh		; DOS 1+
+GET_CURRENT_DEFAULT_DRIVE							EQU		19h		; DOS 1+
+SET_INTERRUPT_VECTOR								EQU		25h		; DOS 1+
+GET_DISK_TRANSFER_AREA_ADDRESS						EQU		2Fh		; DOS 2+
+GET_DOS_VERSION										EQU		30h		; DOS 2+
+GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE	EQU		32h		; DOS 2+
+GET_INTERRUPT_VECTOR								EQU		35h		; DOS 2+
+SET_CURRENT_DIRECTORY								EQU		3Bh		; DOS 2+
+CREATE_OR_TRUNCATE_FILE								EQU		3Ch		; DOS 2+
+OPEN_EXISTING_FILE									EQU		3Dh		; DOS 2+
+CLOSE_FILE											EQU		3Eh		; DOS 2+
+READ_FROM_FILE_OR_DEVICE							EQU		3Fh		; DOS 2+
+WRITE_TO_FILE_OR_DEVICE								EQU		40h		; DOS 2+
+SET_CURRENT_FILE_POSITION							EQU		42h		; DOS 2+
+CHECK_IF_BLOCK_DEVICE_REMOTE						EQU		4409h	; DOS 3.1+
+GET_CURRENT_DIRECTORY								EQU		47h		; DOS 2+
+TERMINATE_WITH_RETURN_CODE							EQU		4Ch		; DOS 2+
+FIND_FIRST_MATCHING_FILE							EQU		4Eh		; DOS 2+
+FIND_NEXT_MATCHING_FILE								EQU		4Fh		; DOS 2+
 
 ; DOS errors
+ERR_DOS_FUNCTION_NUMBER_INVALID						EQU		01h
+ERR_DOS_INVALID_DRIVE								EQU		0Fh
 ERR_DOS_DRIVE_NOT_READY								EQU		15h
-
 
 
Index: /trunk/Assembly_Library/Inc/Emulate.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Emulate.inc	(revision 588)
+++ /trunk/Assembly_Library/Inc/Emulate.inc	(revision 589)
@@ -579,5 +579,15 @@
 
 %macro eRCL_IM 2
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+%ifdef USE_386
+	%if %2 = 1
+		adc		%1, %1	; Same size but faster on 386 and 486. Fails if %1 is a memory operand.
+	%else
+		eSHIFT_IM	%1, %2, rcl
+	%endif
+%else
 	eSHIFT_IM	%1, %2, rcl
+%endif
+%endif
 %endmacro
 
Index: /trunk/Assembly_Library/Inc/Math.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Math.inc	(revision 588)
+++ /trunk/Assembly_Library/Inc/Math.inc	(revision 589)
@@ -80,5 +80,5 @@
 .ShiftNextBit:
 	eSHL_IM	ax, 1
-	rcl		dx, 1
+	eRCL_IM	dx, 1
 	loop	.ShiftNextBit
 %endmacro
Index: /trunk/Assembly_Library/Inc/SystemTimer.inc
===================================================================
--- /trunk/Assembly_Library/Inc/SystemTimer.inc	(revision 588)
+++ /trunk/Assembly_Library/Inc/SystemTimer.inc	(revision 589)
@@ -1,4 +1,4 @@
 ; Project name	:	Assembly Library
-; Description	:	System Timer (8254) relates equates and macros.
+; Description	:	System Timer (8254) related equates and macros.
 %ifndef SYSTEMTIMER_INC
 %define SYSTEMTIMER_INC
@@ -34,5 +34,5 @@
 CONTROL_WORD_REGISTER_out				EQU	43h
 
-; Timer 2 is connected to PC Speaker that can be controller from port 61h.
+; Timer 2 is connected to PC Speaker that can be controlled from port 61h.
 SPEAKER_CONTROL_REGISTER				EQU	61h
 FLG_TIMER_2_OUTPUT_in					EQU	(1<<5)	; AT+ only
Index: /trunk/Assembly_Library/Src/Display/DisplayCharOut.asm
===================================================================
--- /trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 589)
@@ -41,6 +41,5 @@
 	cmp		al, ' '							; Printable character?
 	jb		SHORT DisplayCharOut_BiosTeletypeOutput
-	WAIT_RETRACE_IF_NECESSARY_THEN stosw
-	ret
+	JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosw
 
 ALIGN DISPLAY_JUMP_ALIGN
@@ -96,10 +95,9 @@
 	xchg	al, ah				; Swap character and attribute
 	inc		di					; Skip character
-	WAIT_RETRACE_IF_NECESSARY_THEN stosb
-	ret
+	JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosb
 
 ALIGN DISPLAY_JUMP_ALIGN
 DisplayCharOut_Character:
-	WAIT_RETRACE_IF_NECESSARY_THEN stosb
+	CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosb
 	inc		di					; Skip attribute
 	ret
@@ -107,6 +105,5 @@
 ALIGN DISPLAY_JUMP_ALIGN
 DisplayCharOut_CharacterWithAttribute:
-	WAIT_RETRACE_IF_NECESSARY_THEN stosw
-	ret
+	JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosw
 
 
Index: /trunk/Assembly_Library/Src/Display/DisplayFormat.asm
===================================================================
--- /trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 589)
@@ -269,7 +269,8 @@
 	jz		SHORT .CopyWithoutDisplayProcessing
 
-	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
+	CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN rep movsb
 	dec		di					; Point to preceeding character instead of attribute
 	ret
+
 ALIGN DISPLAY_JUMP_ALIGN
 .CopyWithoutDisplayProcessing:
Index: /trunk/Assembly_Library/Src/Display/DisplayPage.asm
===================================================================
--- /trunk/Assembly_Library/Src/Display/DisplayPage.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Display/DisplayPage.asm	(revision 589)
@@ -43,8 +43,5 @@
 %ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
 	%define EXCLUDE
-	%ifdef MODULE_HOTKEYS
-		%undef EXCLUDE
-	%endif
-	%ifdef MODULE_BOOT_MENU
+	%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 		%undef EXCLUDE
 	%endif
Index: /trunk/Assembly_Library/Src/Display/DisplayPrint.asm
===================================================================
--- /trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 589)
@@ -296,8 +296,5 @@
 		%undef EXCLUDE
 	%endif
-	%ifdef MODULE_HOTKEYS
-		%undef EXCLUDE
-	%endif
-	%ifdef MODULE_BOOT_MENU
+	%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 		%undef EXCLUDE
 	%endif
Index: /trunk/Assembly_Library/Src/File/Drive.asm
===================================================================
--- /trunk/Assembly_Library/Src/File/Drive.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/File/Drive.asm	(revision 589)
@@ -86,10 +86,10 @@
 	xchg	dx, ax			; Default drive to DL
 	call	Drive_SetDefaultFromDL
-	eMOVZX	cx, al			; Number of potentially valid drive letters available
-	cmp		cl, 32
-	jb		SHORT .Return
-	mov		cl, 32
-ALIGN JUMP_ALIGN, ret
-.Return:
+	cmp		al, 32			; Number of potentially valid drive letters available
+	jb		SHORT .Below32
+	mov		al, 32
+.Below32:
+	cbw
+	xchg	cx, ax
 	ret
 
@@ -133,6 +133,18 @@
 
 	inc		dx			; Default drive is 00h and first drive is 01h
+	mov		ax, CHECK_IF_BLOCK_DEVICE_REMOTE	; Needs DOS 3.1+
+	mov		bx, dx
+	push	dx
+	int		DOS_INTERRUPT_21h
+	pop		dx
+	jnc		SHORT .DriveIsValid
+	cmp		ax, ERR_DOS_INVALID_DRIVE
+	je		SHORT .DriveIsNotValid
+	; Fall back to old method if ERR_DOS_FUNCTION_NUMBER_INVALID
+
 	mov		ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
 	int		DOS_INTERRUPT_21h
+.DriveIsValid:
+.DriveIsNotValid:
 	dec		dx
 	test	al, al
Index: /trunk/Assembly_Library/Src/Keyboard/Keyboard.asm
===================================================================
--- /trunk/Assembly_Library/Src/Keyboard/Keyboard.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Keyboard/Keyboard.asm	(revision 589)
@@ -291,8 +291,5 @@
 %ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
 	%define EXCLUDE
-	%ifdef MODULE_HOTKEYS
-		%undef EXCLUDE
-	%endif
-	%ifdef MODULE_BOOT_MENU
+	%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 		%undef EXCLUDE
 	%endif
Index: /trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 589)
@@ -162,5 +162,5 @@
 	push	si
 	push	cx
-	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
+	CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN rep movsb
 	pop		cx
 	pop		si
Index: /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 589)
@@ -239,5 +239,5 @@
 ; AppendFileFromDTAinDSSItoOffScreenBuffer
 ;	Parameters:
-;		CX:		Files/directores found
+;		CX:		Files/directories found
 ;		DL:		Zero if root directory selected
 ;		DS:SI:	Ptr to DTA containing file information
Index: /trunk/Assembly_Library/Src/Menu/MenuLoop.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/MenuLoop.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Menu/MenuLoop.asm	(revision 589)
@@ -106,16 +106,7 @@
 %ifndef MENU_NO_ESC
 	cmp		al, ESC
-	je		SHORT .LeaveMenuWithoutSelectingItem
-%endif
-	cmp		al, CR
-	je		SHORT .SelectItem
-
-	test	BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
-	jz		SHORT MenuLoop_ProcessScrollingKeysFromAX
-	ret		; Return with CF cleared since keystroke not processed
-
-%ifndef MENU_NO_ESC
-ALIGN MENU_JUMP_ALIGN
-.LeaveMenuWithoutSelectingItem:
+	jne		SHORT .NotEscape
+
+	; Leave menu without selecting item
 	call	MenuEvent_ExitMenu
 	jnc		SHORT .CancelMenuExit
@@ -128,9 +119,20 @@
 
 ALIGN MENU_JUMP_ALIGN
-.SelectItem:
+.NotEscape:
+	cmp		al, CR
+	jne		SHORT .NotCarriageReturn
+
+	; Select item
 	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	call	MenuEvent_ItemSelectedFromCX
 	stc
-	ret
+.Return:
+	ret
+
+ALIGN MENU_JUMP_ALIGN
+.NotCarriageReturn:
+	test	BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
+	jnz		SHORT .Return	; With CF cleared since keystroke not processed
+	; Fall to MenuLoop_ProcessScrollingKeysFromAX
 
 
@@ -172,8 +174,7 @@
 .ChangeToPreviousPage:
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	xchg	ax, cx
-	neg		ax
-	mov		cx, [bp+MENUINIT.wHighlightedItem]
-	add		cx, ax
+	neg		cx
+	mov		ax, cx
+	add		cx, [bp+MENUINIT.wHighlightedItem]
 	jge		SHORT .MoveHighlightedItemByAX	; No rotation for PgUp
 	; Fall to .SelectFirstItem
@@ -187,7 +188,6 @@
 .ChangeToNextPage:
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	xchg	ax, cx
-	mov		cx, [bp+MENUINIT.wHighlightedItem]
-	add		cx, ax
+	mov		ax, cx
+	add		cx, [bp+MENUINIT.wHighlightedItem]
 	cmp		cx, [bp+MENUINIT.wItems]
 	jb		SHORT .MoveHighlightedItemByAX	; No rotation for PgDn
Index: /trunk/Assembly_Library/Src/Serial/SerialServerScan.asm
===================================================================
--- /trunk/Assembly_Library/Src/Serial/SerialServerScan.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Serial/SerialServerScan.asm	(revision 589)
@@ -46,16 +46,15 @@
 
 		test	dx, dx
-		jnz		short SerialServerScan_CheckForServer_PortAndBaudInDX
+		jnz		SHORT SerialServerScan_CheckForServer_PortAndBaudInDX
 
-		mov		di,.scanPortAddresses-1
-		mov		ch,1			;  tell server that we are scanning
+		mov		di, .scanPortAddresses-1
+		mov		ch, 1			;  tell server that we are scanning
 
 .nextPort:
 		inc		di				; load next port address
-		xor		dh, dh
-		mov		dl,[cs:di]
+		mov		dh, 40h			; Clear DH and make sure CF is set if error
+		mov		dl, [cs:di]
 		eSHL_IM	dx, 2			; shift from one byte to two
-		stc						; setup error code for exit
-		jz		.error
+		jz		SHORT .error
 
 ;
@@ -63,17 +62,17 @@
 ;
 		push	dx
-		add		dl,Serial_UART_lineControl
-		mov		al, 09ah
+		add		dl, Serial_UART_lineControl
+		mov		al, 9Ah
 		out		dx, al
 		in		al, dx
 		pop		dx
-		cmp		al, 09ah
-		jnz		.nextPort
+		cmp		al, 9Ah
+		jne		SHORT .nextPort
 
-		mov		al, 0ch
+		mov		al, 0Ch
 		out		dx, al
 		in		al, dx
-		cmp		al, 0ch
-		jnz		.nextPort
+		cmp		al, 0Ch
+		jne		SHORT .nextPort
 
 ;
@@ -84,22 +83,22 @@
 ; *on the server side* if the client side had a 4x clock multiplier, a 2x clock multiplier, or no clock multiplier.
 ;
-; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0ch (9600 baud), and
+; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0Ch (9600 baud), and
 ;					            04h (28800 baud), 02h (57600 baud), 01h (115200 baud)
 ;
-; Note: hardware baud multipliers (2x, 4x) will impact the final baud rate and are not known at this level
+; Note: hardware baud multipliers (2x, 4x, 8x) will impact the final baud rate and are not known at this level
 ;
-		mov		dh,030h * 2		; multiply by 2 since we are about to divide by 2
-		mov		dl,[cs:di]		; restore single byte port address for scan
+		mov		dh, 30h * 2		; multiply by 2 since we are about to divide by 2
+		mov		dl, [cs:di]		; restore single byte port address for scan
 
 .nextBaud:
-		shr		dh,1
-		jz		.nextPort
-		cmp		dh,6			; skip from 6 to 4, to move from the top of the 9600 baud range
-		jnz		.testBaud		; to the bottom of the 115200 baud range
-		mov		dh,4
+		shr		dh, 1
+		jz		SHORT .nextPort
+		cmp		dh, 6			; skip from 6 to 4, to move from the top of the 9600 baud range
+		jne		SHORT .testBaud	; to the bottom of the 115200 baud range
+		mov		dh, 4
 
 .testBaud:
 		call	SerialServerScan_CheckForServer_PortAndBaudInDX
-		jc		.nextBaud
+		jc		SHORT .nextBaud
 
 .error:
@@ -135,15 +134,11 @@
 SerialServerScan_CheckForServer_PortAndBaudInDX:
 		push	bp				; setup fake SerialServer_Command
-
 		push	dx				; send port baud and rate, returned in inquire packet
 								; (and possibly returned in the drive identification string)
-
 		push	cx				; send number of sectors, and if it is on a scan or not
-
-		mov		bl,SerialServer_Command_Inquire			; protocol command onto stack with bh
+		mov		bl, SerialServer_Command_Inquire		; protocol command onto stack with bh
 		push	bx
 
-		mov		bp,sp
-
+		mov		bp, sp
 		call	SerialServer_SendReceive
 
Index: /trunk/Assembly_Library/Src/Util/Math.asm
===================================================================
--- /trunk/Assembly_Library/Src/Util/Math.asm	(revision 588)
+++ /trunk/Assembly_Library/Src/Util/Math.asm	(revision 589)
@@ -36,4 +36,5 @@
 ALIGN JUMP_ALIGN
 Math_DivQWatSSBPbyCX:
+%if 1
 	xor		dx, dx
 	mov		ax, [bp+6]		; Load highest divident WORD to DX:AX
@@ -53,4 +54,19 @@
 	mov		[bp], ax
 	ret
+%else ; ~1
+; This is about half the size compared to the above code but it's not tested which is why it's commented away.
+	push	di
+	mov		di, 6
+	xor		dx, dx
+.Next:
+	mov		ax, [bp+di]
+	div		cx
+	mov		[bp+di], ax
+	dec		di
+	dec		di
+	jns		.Next
+	pop		di
+	ret
+%endif ; 1
 %endif
 
Index: /trunk/BIOS_Drive_Information_Tool/Src/Bios.asm
===================================================================
--- /trunk/BIOS_Drive_Information_Tool/Src/Bios.asm	(revision 588)
+++ /trunk/BIOS_Drive_Information_Tool/Src/Bios.asm	(revision 589)
@@ -146,13 +146,8 @@
 	mov		bx, 55AAh
 	int		BIOS_DISK_INTERRUPT_13h
-	jc		SHORT .NoEbiosPresent
-	cmp		bx, 0AA55h
-	jne		SHORT .NoEbiosPresent
-	eMOVZX	bx, ah			; Copy version to BX
-	xor		ah, ah
-	ret
-.NoEbiosPresent:
-	mov		ah, RET_HD_INVALID
-	stc
+	jc		SHORT ReturnInvalidErrorCodeInAH	; No EBIOS present
+	xor		bx, 0AA55h
+	jnz		SHORT ReturnInvalidErrorCodeInAH	; No EBIOS present
+	xchg	bl, ah			; Version to BX, BIOS error code to AH
 	ret
 
Index: /trunk/BIOS_Drive_Information_Tool/Src/Main.asm
===================================================================
--- /trunk/BIOS_Drive_Information_Tool/Src/Main.asm	(revision 588)
+++ /trunk/BIOS_Drive_Information_Tool/Src/Main.asm	(revision 589)
@@ -60,10 +60,5 @@
 	mov		si, g_szProgramName
 	call	Print_NullTerminatedStringFromSI
-
-	call	ReadAndDisplayAllHardDrives
-
-	; Exit to DOS
-	mov 	ax, 4C00h			; Exit to DOS
-	int 	21h
+	; Fall to ReadAndDisplayAllHardDrives
 
 
@@ -112,5 +107,5 @@
 	loop	.DisplayNextDriveFromDL
 .NoDrivesAvailable:
-	ret
+	ret		; Exit to DOS
 
 
Index: /trunk/BIOS_Drive_Information_Tool/Src/Print.asm
===================================================================
--- /trunk/BIOS_Drive_Information_Tool/Src/Print.asm	(revision 588)
+++ /trunk/BIOS_Drive_Information_Tool/Src/Print.asm	(revision 589)
@@ -42,8 +42,6 @@
 ;	Parameters:
 ;		AL:		Character to output
-;		DS:		BDA segment (zero)
-;		ES:DI:	Ptr to video memory where to output
-;	Returns:
-;		DI:		Incremented for next character
+;	Returns:
+;		Nothing
 ;	Corrupts registers:
 ;		AX, DX
@@ -51,6 +49,6 @@
 DosCharOut:
 	xchg	dx, ax
-	mov		ah, 02h		; DOS 1+ - WRITE CHARACTER TO STANDARD OUTPUT
-	int		21h			; Call DOS
+	mov		ah, WRITE_CHARACTER_TO_STANDARD_OUTPUT
+	int		DOS_INTERRUPT_21h
 	ret
 
Index: /trunk/Serial_Server/library/Checksum.cpp
===================================================================
--- /trunk/Serial_Server/library/Checksum.cpp	(revision 588)
+++ /trunk/Serial_Server/library/Checksum.cpp	(revision 589)
@@ -3,5 +3,5 @@
 // Project:     XTIDE Universal BIOS, Serial Port Server
 //
-// File:        checksum.cpp - Checksum function and test routines
+// File:        Checksum.cpp - Checksum function and test routines
 
 //
@@ -39,5 +39,5 @@
 //
 
-#include "library.h"
+#include "Library.h"
 
 unsigned short checksum( unsigned short *wbuff, int wlen )
Index: /trunk/Serial_Server/library/File.h
===================================================================
--- /trunk/Serial_Server/library/File.h	(revision 588)
+++ /trunk/Serial_Server/library/File.h	(revision 589)
@@ -3,5 +3,5 @@
 // Project:     XTIDE Universal BIOS, Serial Port Server
 //
-// File:        file.h - File access via standard "stdio.h" routines
+// File:        File.h - File access via standard "stdio.h" routines
 //
 // Routines for accessing the file system using generic routines, which
Index: /trunk/Serial_Server/library/FlatImage.h
===================================================================
--- /trunk/Serial_Server/library/FlatImage.h	(revision 588)
+++ /trunk/Serial_Server/library/FlatImage.h	(revision 589)
@@ -22,5 +22,5 @@
 //
 
-#include "library.h"
+#include "Library.h"
 
 class FlatImage : public Image
Index: /trunk/Serial_Server/library/Image.cpp
===================================================================
--- /trunk/Serial_Server/library/Image.cpp	(revision 588)
+++ /trunk/Serial_Server/library/Image.cpp	(revision 589)
@@ -3,5 +3,5 @@
 // Project:     XTIDE Universal BIOS, Serial Port Server
 //
-// File:        image.cpp - Abstract base class for disk image support
+// File:        Image.cpp - Abstract base class for disk image support
 //
 
@@ -22,5 +22,5 @@
 //
 
-#include "library.h"
+#include "Library.h"
 #include <memory.h>
 #include <stdlib.h>
Index: /trunk/Serial_Server/library/Library.h
===================================================================
--- /trunk/Serial_Server/library/Library.h	(revision 588)
+++ /trunk/Serial_Server/library/Library.h	(revision 589)
@@ -3,5 +3,5 @@
 // Project:     XTIDE Universal BIOS, Serial Port Server
 //
-// File:        library.h - Include file for users of the library
+// File:        Library.h - Include file for users of the library
 //
 
@@ -87,5 +87,5 @@
 
 #ifdef WIN32
-#include "../win32/win32serial.h"
+#include "../win32/Win32Serial.h"
 #else
 // there is no standard way to read/write and configure the serial port, OS specific only
@@ -93,7 +93,7 @@
 
 #ifdef WIN32
-#include "../win32/win32file.h"
+#include "../win32/Win32File.h"
 #else
-#include "file.h"
+#include "File.h"
 #endif
 
Index: /trunk/Serial_Server/library/Process.cpp
===================================================================
--- /trunk/Serial_Server/library/Process.cpp	(revision 588)
+++ /trunk/Serial_Server/library/Process.cpp	(revision 589)
@@ -3,5 +3,5 @@
 // Project:     XTIDE Universal BIOS, Serial Port Server
 //
-// File:        process.cpp - Processes commands received over the serial port
+// File:        Process.cpp - Processes commands received over the serial port
 //
 
@@ -22,5 +22,5 @@
 //
 
-#include "library.h"
+#include "Library.h"
 #include <memory.h>
 #include <string.h>
Index: /trunk/Serial_Server/library/Serial.cpp
===================================================================
--- /trunk/Serial_Server/library/Serial.cpp	(revision 588)
+++ /trunk/Serial_Server/library/Serial.cpp	(revision 589)
@@ -22,5 +22,5 @@
 //
 
-#include "library.h"
+#include "Library.h"
 #include <stdlib.h>
 #include <string.h>
Index: /trunk/Serial_Server/makefile
===================================================================
--- /trunk/Serial_Server/makefile	(revision 588)
+++ /trunk/Serial_Server/makefile	(revision 589)
@@ -11,5 +11,5 @@
 #
 
-HEADERS = library/library.h win32/win32file.h win32/win32serial.h library/file.h library/flatimage.h
+HEADERS = library/Library.h win32/Win32File.h win32/Win32Serial.h library/File.h library/FlatImage.h
 
 CXX = cl
@@ -21,18 +21,18 @@
 	@$(CXX) /Febuild/serdrive.exe $(WIN32OBJS)
 
-build/win32.obj:	win32/win32.cpp $(HEADERS)
-	@$(CXX) /c $(CXXFLAGS) win32/win32.cpp /Fobuild/win32.obj
+build/win32.obj:	win32/Win32.cpp $(HEADERS)
+	@$(CXX) /c $(CXXFLAGS) win32/Win32.cpp /Fobuild/win32.obj
 
-build/checksum.obj:	library/checksum.cpp $(HEADERS)
-	@$(CXX) /c $(CXXFLAGS) library/checksum.cpp /Fobuild/checksum.obj
+build/checksum.obj:	library/Checksum.cpp $(HEADERS)
+	@$(CXX) /c $(CXXFLAGS) library/Checksum.cpp /Fobuild/checksum.obj
 
-build/serial.obj:	library/serial.cpp $(HEADERS)
-	@$(CXX) /c $(CXXFLAGS) library/serial.cpp /Fobuild/serial.obj
+build/serial.obj:	library/Serial.cpp $(HEADERS)
+	@$(CXX) /c $(CXXFLAGS) library/Serial.cpp /Fobuild/serial.obj
 
-build/process.obj:	library/process.cpp $(HEADERS)
-	@$(CXX) /c $(CXXFLAGS) library/process.cpp /Fobuild/process.obj
+build/process.obj:	library/Process.cpp $(HEADERS)
+	@$(CXX) /c $(CXXFLAGS) library/Process.cpp /Fobuild/process.obj
 
-build/image.obj:	library/image.cpp $(HEADERS)
-	@$(CXX) /c $(CXXFLAGS) library/image.cpp /Fobuild/image.obj
+build/image.obj:	library/Image.cpp $(HEADERS)
+	@$(CXX) /c $(CXXFLAGS) library/Image.cpp /Fobuild/image.obj
 
 
@@ -46,5 +46,5 @@
 
 
-build/checksum_test.exe:	library/checksum.cpp
-	@$(CXX) /Febuild/checksum_test.exe /Ox library/checksum.cpp /Fobuild/checksum_test.obj -D CHECKSUM_TEST
+build/checksum_test.exe:	library/Checksum.cpp
+	@$(CXX) /Febuild/checksum_test.exe /Ox library/Checksum.cpp /Fobuild/checksum_test.obj -D CHECKSUM_TEST
 
Index: /trunk/Serial_Server/win32/Win32.cpp
===================================================================
--- /trunk/Serial_Server/win32/Win32.cpp	(revision 588)
+++ /trunk/Serial_Server/win32/Win32.cpp	(revision 589)
@@ -30,8 +30,8 @@
 #include <stdarg.h>
 
-#include "../library/library.h"
-#include "../library/flatimage.h"
-
-#include "../../XTIDE_Universal_BIOS/inc/version.inc"
+#include "../library/Library.h"
+#include "../library/FlatImage.h"
+
+#include "../../XTIDE_Universal_BIOS/Inc/Version.inc"
 
 char *bannerStrings[] = {
Index: /trunk/Serial_Server/win32/Win32File.h
===================================================================
--- /trunk/Serial_Server/win32/Win32File.h	(revision 588)
+++ /trunk/Serial_Server/win32/Win32File.h	(revision 589)
@@ -29,5 +29,5 @@
 #include <windows.h>
 #include <stdio.h>
-#include "../library/library.h"
+#include "../library/Library.h"
 
 class FileAccess
Index: /trunk/Serial_Server/win32/Win32Serial.h
===================================================================
--- /trunk/Serial_Server/win32/Win32Serial.h	(revision 588)
+++ /trunk/Serial_Server/win32/Win32Serial.h	(revision 589)
@@ -24,5 +24,5 @@
 #include <stdio.h>
 #include "windows.h"
-#include "../library/library.h"
+#include "../library/Library.h"
 
 #define PIPENAME "\\\\.\\pipe\\xtide"
Index: /trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/BootVars.inc	(revision 589)
@@ -41,5 +41,5 @@
 	.dwPostStack		resb	4		; POST stack pointer when entering INT 19h
 %ifdef MODULE_HOTKEYS
-	.hotkeyVars				resb	HOTKEYVARS_size
+	.hotkeyVars			resb	HOTKEYVARS_size
 %endif
 	.rgDrvDetectInfo:					; Array containing DRVDETECTINFO structs
Index: /trunk/XTIDE_Universal_BIOS/Inc/Controllers/AdvancedID.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/Controllers/AdvancedID.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/Controllers/AdvancedID.inc	(revision 589)
@@ -32,7 +32,7 @@
 ; Vision
 ; QDI Vision Controller Identification nibbles used by hardware so do not modify these
-ID_QD6580_ALTERNATE			EQU		5
-ID_QD6580					EQU		10
-ID_QD6500					EQU		12
+ID_QD6580_ALTERNATE			EQU		80
+ID_QD6580					EQU		160
+ID_QD6500					EQU		192
 
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/Controllers/PDC20x30.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/Controllers/PDC20x30.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/Controllers/PDC20x30.inc	(revision 589)
@@ -2,6 +2,4 @@
 ; Description	:	Promise PDC 20230-C and 20630 VLB IDE controller
 ;					specifications.
-;
-;					Specifications can be found at 
 
 ;
Index: /trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/Controllers/XTCF.inc	(revision 589)
@@ -56,8 +56,8 @@
 ; the mode via a call to Int 13h function 1Eh accordingly (see AH1Eh_XTCF.asm).
 ;
-XTCF_8BIT_PIO_MODE					EQU		0	; XT-CF using 8-bit PIO mode
-XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD	EQU		1	; XT-CF using 8-bit PIO mode, but with 16-bit instructions
-XTCF_16BIT_PIO_WITH_BIU_OFFLOAD		EQU		2	; Lo-tech 8-bit IDE Adapter
-XTCF_DMA_MODE						EQU		3	; XT-CFv3 using DMA
+XTCF_8BIT_PIO_MODE						EQU		0	; XT-CF using 8-bit PIO mode
+XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD		EQU		1	; XT-CF using 8-bit PIO mode, but with 16-bit instructions
+XTCF_16BIT_PIO_MODE_WITH_BIU_OFFLOAD	EQU		2	; Lo-tech 8-bit IDE Adapter
+XTCF_DMA_MODE							EQU		3	; XT-CFv3 using DMA
 
 
Index: /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 589)
@@ -84,5 +84,5 @@
 
 
-	; Flags for DPT_ADVANCED_ATA.bInitError
+	; Flags for DPT.bInitError
 	FLG_INITERROR_FAILED_TO_SELECT_DRIVE				EQU (1<<0)
 	FLG_INITERROR_FAILED_TO_INITIALIZE_CHS_PARAMETERS	EQU (1<<1)
Index: /trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc	(revision 589)
@@ -21,46 +21,4 @@
 %ifndef IDE_8BIT_INC
 %define IDE_8BIT_INC
-
-;--------------------------------------------------------------------
-; UNROLL_SECTORS_IN_CX_TO_DWORDS
-; UNROLL_SECTORS_IN_CX_TO_QWORDS
-; UNROLL_SECTORS_IN_CX_TO_OWORDS
-;	Parameters:
-;		CX:		Number of sectors in block
-;	Returns:
-;		CX:		Number of DWORDs, QWORDs or OWORDs in block
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-%macro UNROLL_SECTORS_IN_CX_TO_DWORDS 0
-%ifdef USE_186
-	shl		cx, 7
-%else
-	xchg	cl, ch		; Sectors to WORDs (SHL CX, 8)
-	shr		cx, 1
-%endif
-%endmacro
-
-%macro UNROLL_SECTORS_IN_CX_TO_QWORDS 0
-%ifdef USE_186
-	shl		cx, 6
-%else
-	UNROLL_SECTORS_IN_CX_TO_DWORDS
-	shr		cx, 1
-%endif
-%endmacro
-
-%macro UNROLL_SECTORS_IN_CX_TO_OWORDS 0
-%ifdef USE_186
-	shl		cx, 5
-%else
-;	UNROLL_SECTORS_IN_CX_TO_QWORDS
-;	shr		cx, 1
-	mov		ch, cl		; 2 bytes shorter but possibly slower
-	mov		cl, 3
-	shr		cx, cl
-%endif
-%endmacro
-
 
 ;--------------------------------------------------------------------
Index: /trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/IdeIO.inc	(revision 589)
@@ -105,3 +105,45 @@
 
 
+;--------------------------------------------------------------------
+; UNROLL_SECTORS_IN_CX_TO_DWORDS
+; UNROLL_SECTORS_IN_CX_TO_QWORDS
+; UNROLL_SECTORS_IN_CX_TO_OWORDS
+;	Parameters:
+;		CX:		Number of sectors in block
+;	Returns:
+;		CX:		Number of DWORDs, QWORDs or OWORDs in block
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+%macro UNROLL_SECTORS_IN_CX_TO_DWORDS 0
+%ifdef USE_186
+	shl		cx, 7
+%else
+	xchg	cl, ch		; Sectors to WORDs (SHL CX, 8)
+	shr		cx, 1
+%endif
+%endmacro
+
+%macro UNROLL_SECTORS_IN_CX_TO_QWORDS 0
+%ifdef USE_186
+	shl		cx, 6
+%else
+	UNROLL_SECTORS_IN_CX_TO_DWORDS
+	shr		cx, 1
+%endif
+%endmacro
+
+%macro UNROLL_SECTORS_IN_CX_TO_OWORDS 0
+%ifdef USE_186
+	shl		cx, 5
+%else
+;	UNROLL_SECTORS_IN_CX_TO_QWORDS
+;	shr		cx, 1
+	mov		ch, cl		; 2 bytes shorter but possibly slower
+	mov		cl, 3
+	shr		cx, cl
+%endif
+%endmacro
+
+
 %endif ; IDE_IO_INC
Index: /trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/ModuleDependency.inc	(revision 589)
@@ -26,5 +26,4 @@
 %endif
 
-
 %ifdef MODULE_SERIAL_FLOPPY
 	%ifndef MODULE_SERIAL
@@ -41,5 +40,4 @@
 %endif
 
-; Include module specific .INC files
 %ifdef MODULE_8BIT_IDE
 	%include "IDE_8bit.inc"			; For IDE 8-bit data port macros
@@ -47,4 +45,7 @@
 
 %ifdef MODULE_ADVANCED_ATA
+	%ifndef USE_386
+		%error "MODULE_ADVANCED_ATA requires USE_386!"
+	%endif
 	%include "AdvancedID.inc"
 	%include "PDC20x30.inc"			; For Promise PDC 20230-C and 20630 controllers
@@ -79,49 +80,49 @@
 ; Included modules for ROMVARS.wFlags
 %ifdef MODULE_8BIT_IDE
-	MAIN_FLG_MODULE_8BIT_IDE	EQU	FLG_ROMVARS_MODULE_8BIT_IDE
+	MAIN_FLG_MODULE_8BIT_IDE			EQU	FLG_ROMVARS_MODULE_8BIT_IDE
 %else
-	MAIN_FLG_MODULE_8BIT_IDE	EQU	0
+	MAIN_FLG_MODULE_8BIT_IDE			EQU	0
 %endif
 
 %ifdef MODULE_ADVANCED_ATA
-	MAIN_FLG_MODULE_ADVANCED_ATA	EQU	FLG_ROMVARS_MODULE_ADVANCED_ATA
+	MAIN_FLG_MODULE_ADVANCED_ATA		EQU	FLG_ROMVARS_MODULE_ADVANCED_ATA
 %else
-	MAIN_FLG_MODULE_ADVANCED_ATA	EQU	0
+	MAIN_FLG_MODULE_ADVANCED_ATA		EQU	0
 %endif
 
 %ifdef MODULE_BOOT_MENU
-	MAIN_FLG_MODULE_BOOT_MENU	EQU	FLG_ROMVARS_MODULE_BOOT_MENU
+	MAIN_FLG_MODULE_BOOT_MENU			EQU	FLG_ROMVARS_MODULE_BOOT_MENU
 %else
-	MAIN_FLG_MODULE_BOOT_MENU	EQU	0
+	MAIN_FLG_MODULE_BOOT_MENU			EQU	0
 %endif
 
 %ifdef MODULE_EBIOS
-	MAIN_FLG_MODULE_EBIOS	EQU	FLG_ROMVARS_MODULE_EBIOS
+	MAIN_FLG_MODULE_EBIOS				EQU	FLG_ROMVARS_MODULE_EBIOS
 %else
-	MAIN_FLG_MODULE_EBIOS	EQU	0
+	MAIN_FLG_MODULE_EBIOS				EQU	0
 %endif
 
 %ifdef MODULE_HOTKEYS
-	MAIN_FLG_MODULE_HOTKEYS	EQU	FLG_ROMVARS_MODULE_HOTKEYS
+	MAIN_FLG_MODULE_HOTKEYS				EQU	FLG_ROMVARS_MODULE_HOTKEYS
 %else
-	MAIN_FLG_MODULE_HOTKEYS	EQU	0
+	MAIN_FLG_MODULE_HOTKEYS				EQU	0
 %endif
 
 %ifdef MODULE_IRQ
-	MAIN_FLG_MODULE_IRQ		EQU	FLG_ROMVARS_MODULE_IRQ
+	MAIN_FLG_MODULE_IRQ					EQU	FLG_ROMVARS_MODULE_IRQ
 %else
-	MAIN_FLG_MODULE_IRQ		EQU	0
+	MAIN_FLG_MODULE_IRQ					EQU	0
 %endif
 
 %ifdef MODULE_SERIAL
-	MAIN_FLG_MODULE_SERIAL	EQU	FLG_ROMVARS_MODULE_SERIAL
+	MAIN_FLG_MODULE_SERIAL				EQU	FLG_ROMVARS_MODULE_SERIAL
 %else
-	MAIN_FLG_MODULE_SERIAL	EQU	0
+	MAIN_FLG_MODULE_SERIAL				EQU	0
 %endif
 
 %ifdef MODULE_SERIAL_FLOPPY
-	MAIN_FLG_MODULE_SERIAL_FLOPPY	EQU	FLG_ROMVARS_MODULE_SERIAL_FLOPPY
+	MAIN_FLG_MODULE_SERIAL_FLOPPY		EQU	FLG_ROMVARS_MODULE_SERIAL_FLOPPY
 %else
-	MAIN_FLG_MODULE_SERIAL_FLOPPY	EQU	0
+	MAIN_FLG_MODULE_SERIAL_FLOPPY		EQU	0
 %endif
 
@@ -145,3 +146,2 @@
 
 MASK_ROMVARS_INCLUDED_MODULES	EQU	MAIN_FLG_MODULE_8BIT_IDE | MAIN_FLG_MODULE_ADVANCED_ATA | MAIN_FLG_MODULE_BOOT_MENU | MAIN_FLG_MODULE_EBIOS | MAIN_FLG_MODULE_HOTKEYS | MAIN_FLG_MODULE_IRQ | MAIN_FLG_MODULE_SERIAL | MAIN_FLG_MODULE_SERIAL_FLOPPY | MAIN_FLG_MODULE_STRINGS_COMPRESSED | MAIN_FLG_MODULE_POWER_MANAGEMENT | MAIN_FLG_MODULE_8BIT_IDE_ADVANCED
-
Index: /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 589)
@@ -132,4 +132,6 @@
 %endif
 
+							alignb	2	; Keep the INTPACK structure and stack pointer WORD aligned
+
 	.intpack				resb	INTPACK_size
 endstruc
Index: /trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 589)
@@ -71,5 +71,6 @@
 												; (Conveniently, this is 8, a fact we exploit when testing the bit)
 
-; Here in case the configuration needs to know functionality is present
+; Here in case the configuration needs to know functionality is present. Note! Changing the order/location of these flags
+; also requires changes elsewhere as they are usually tested using byte-accesses for efficiency.
 FLG_ROMVARS_MODULE_POWER_MANAGEMENT		EQU	(1<<5)
 FLG_ROMVARS_MODULE_8BIT_IDE				EQU	(1<<6)
@@ -146,5 +147,4 @@
 ; Device types for IDEVARS.bDevice
 ; IDE Devices are grouped so device numbers cannot be changed without modifying code elsewhere!
-; (IdeTransfer.asm)
 COUNT_OF_STANDARD_IDE_DEVICES			EQU	2	; 16- and 32-bit controllers
 COUNT_OF_8BIT_IDE_DEVICES				EQU	9
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeCommand.asm	(revision 589)
@@ -33,6 +33,10 @@
 IdeCommand_ResetMasterAndSlaveController:
 	; HSR0: Set_SRST
-	call	AccessDPT_GetDeviceControlByteToAL
-	or		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN	; Set Reset bit
+; Used to be:
+;	call	AccessDPT_GetDeviceControlByteToAL
+;	or		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN	; Set Reset bit
+; Is now:
+	mov		al, FLG_DEVCONTROL_SRST | FLG_DEVCONTROL_nIEN
+; ---
 	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER		DEVICE_CONTROL_REGISTER_out
 	mov		ax, HSR0_RESET_WAIT_US
@@ -40,7 +44,11 @@
 
 	; HSR1: Clear_wait
-	call	AccessDPT_GetDeviceControlByteToAL
-	or		al, FLG_DEVCONTROL_nIEN
-	and		al, ~FLG_DEVCONTROL_SRST						; Clear reset bit
+; Used to be:
+;	call	AccessDPT_GetDeviceControlByteToAL
+;	or		al, FLG_DEVCONTROL_nIEN
+;	and		al, ~FLG_DEVCONTROL_SRST						; Clear reset bit
+; Is now:
+	mov		al, FLG_DEVCONTROL_nIEN
+; ---
 	OUTPUT_AL_TO_IDE_CONTROL_BLOCK_REGISTER		DEVICE_CONTROL_REGISTER_out
 	mov		ax, HSR1_RESET_WAIT_US
@@ -51,4 +59,11 @@
 	jmp		IdeWait_PollStatusFlagInBLwithTimeoutInBH
 
+; *FIXME* AccessDPT_GetDeviceControlByteToAL currently always returns with
+; AL cleared (0) or with only bit 1 set (FLG_DEVCONTROL_nIEN = 2).
+; The commented away instructions above sets FLG_DEVCONTROL_nIEN anyway
+; making the call to AccessDPT_GetDeviceControlByteToAL redundant.
+; I have left this code as is since I don't know if it's a mistake
+; (from all the way back to r150) or if it's coded this way in anticipation
+; of some future changes to AccessDPT_GetDeviceControlByteToAL.
 
 ;--------------------------------------------------------------------
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeDmaBlock.asm	(revision 589)
@@ -94,9 +94,9 @@
 	; When DI is zero only one transfer is required since we've limited the
 	; XT-CFv3 block size to 32k
-	jnc		SHORT .TransferLastDmaPageWithSizeInCX
+	jnc		SHORT StartDMAtransferForXTCFwithDmaModeInBL
 
 	; CF was set, so DI != 0 and we might need one or two transfers
-	cmp		cx, ax									; if we won't cross a physical page boundary...
-	jbe		SHORT .TransferLastDmaPageWithSizeInCX	; ...perform the transfer in one operation
+	cmp		cx, ax											; if we won't cross a physical page boundary...
+	jbe		SHORT StartDMAtransferForXTCFwithDmaModeInBL	; ...perform the transfer in one operation
 
 	; Calculate how much we can transfer on first and second rounds
@@ -108,6 +108,4 @@
 	call	StartDMAtransferForXTCFwithDmaModeInBL
 	pop		cx										; Pop size for second DMA page
-
-.TransferLastDmaPageWithSizeInCX:
 	; Fall to StartDMAtransferForXTCFwithDmaModeInBL
 
@@ -115,5 +113,4 @@
 ;--------------------------------------------------------------------
 ; StartDMAtransferForXTCFwithDmaModeInBL
-; Updated for XT-CFv3, 11-Apr-13
 ;	Parameters:
 ;		BL:		Byte for DMA Mode Register
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdePioBlock.asm	(revision 589)
@@ -29,7 +29,5 @@
 ; --------------------------------------------------------------------------------------------------
 
-
 %ifdef MODULE_8BIT_IDE
-
 ;--------------------------------------------------------------------
 ; IdePioBlock_ReadFromXtideRev1
@@ -57,8 +55,7 @@
 
 ;--------------------------------------------------------------------
+; 8-bit PIO from a single data port.
+;
 ; IdePioBlock_ReadFrom8bitDataPort
-;
-; 8-bit PIO from a single data port.
-;
 ;	Parameters:
 ;		CX:		Block size in 512 byte sectors
@@ -68,5 +65,5 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -87,13 +84,12 @@
 	ret
 %endif
-
-%endif	; MODULE_8BIT_IDE
-
-
-;--------------------------------------------------------------------
+%endif ; MODULE_8BIT_IDE
+
+
+;--------------------------------------------------------------------
+; 16-bit and 32-bit PIO from a single data port.
+;
 ; IdePioBlock_ReadFrom16bitDataPort
-;
-; 16-bit PIO from a single data port.
-;
+; IdePioBlock_ReadFrom32bitDataPort
 ;	Parameters:
 ;		CX:		Block size in 512 byte sectors
@@ -103,10 +99,10 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 IdePioBlock_ReadFrom16bitDataPort:
 %ifdef USE_186
-	xchg	cl, ch	; Sectors to WORDs
+	xchg	cl, ch		; Sectors to WORDs
 	rep insw
 	ret
@@ -126,14 +122,11 @@
 
 ;--------------------------------------------------------------------
+%ifdef MODULE_ADVANCED_ATA
 ALIGN JUMP_ALIGN
 IdePioBlock_ReadFrom32bitDataPort:
-	db		0C1h		; SHL
-	db		0E1h		; CX
-	db		7			; 7 (Sectors to DWORDs)
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Dh			; INSW/INSD
-	ret
-
+	shl		cx, 7		; Sectors to DWORDs
+	rep insd
+	ret
+%endif ; MODULE_ADVANCED_ATA
 
 
@@ -145,5 +138,4 @@
 
 %ifdef MODULE_8BIT_IDE
-
 ;--------------------------------------------------------------------
 ; IdePioBlock_WriteToXtideRev1
@@ -151,5 +143,5 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
+;		DS:SI:	Normalized ptr to buffer containing data
 ;	Returns:
 ;		Nothing
@@ -159,9 +151,6 @@
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteToXtideRev1:
-	push	ds
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
 	mov		bl, 8		; Bit mask for toggling data low/high reg
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .OutswLoop:
@@ -170,5 +159,4 @@
 	%endrep
 	loop	.OutswLoop
-	pop		ds
 	ret
 
@@ -179,16 +167,13 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
+;		DS:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteToXtideRev2:
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
-	push	ds
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .WriteNextQword:
@@ -197,5 +182,4 @@
 	%endrep
 	loop	.WriteNextQword
-	pop		ds
 	ret
 
@@ -206,9 +190,9 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
+;		DS:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -216,5 +200,4 @@
 %ifdef USE_186
 	shl		cx, 9		; Sectors to BYTEs
-	es					; Source is ES segment
 	rep outsb
 	ret
@@ -222,7 +205,4 @@
 %else ; 808x
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
-	push	ds
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .WriteNextQword:
@@ -232,8 +212,6 @@
 	%endrep
 	loop	.WriteNextQword
-	pop		ds
-	ret
-%endif
-
+	ret
+%endif
 %endif ; MODULE_8BIT_IDE
 
@@ -245,9 +223,9 @@
 ;		CX:		Block size in 512-byte sectors
 ;		DX:		IDE Data port address
-;		ES:SI:	Normalized ptr to buffer containing data
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, CX
+;		DS:SI:	Normalized ptr to buffer containing data
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -255,5 +233,4 @@
 %ifdef USE_186
 	xchg	cl, ch		; Sectors to WORDs
-	es					; Source is ES segment
 	rep outsw
 	ret
@@ -261,7 +238,4 @@
 %else ; 808x
 	UNROLL_SECTORS_IN_CX_TO_QWORDS
-	push	ds
-	push	es
-	pop		ds
 ALIGN JUMP_ALIGN
 .WriteNextQword:
@@ -271,17 +245,13 @@
 	%endrep
 	loop	.WriteNextQword
-	pop		ds
-	ret
-%endif
-
-;--------------------------------------------------------------------
+	ret
+%endif
+
+;--------------------------------------------------------------------
+%ifdef MODULE_ADVANCED_ATA
 ALIGN JUMP_ALIGN
 IdePioBlock_WriteTo32bitDataPort:
-	db		0C1h		; SHL
-	db		0E1h		; CX
-	db		7			; 7 (Sectors to DWORDs)
-	es					; Source is ES segment
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Fh			; OUTSW/OUTSD
-	ret
+	shl		cx, 7		; Sectors to DWORDs
+	rep outsd
+	ret
+%endif ; MODULE_ADVANCED_ATA
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 589)
@@ -173,6 +173,9 @@
 	cmp		[bp+PIOVARS.bSectorsLeft], cl
 	jbe		SHORT .WriteLastBlockToDrive
+	push	ds
+	push	es
+	pop		ds
 	call	[bp+PIOVARS.fnXfer]
-
+	pop		ds
 	; Wait until ready for next block and check for errors
 	call	IdeWait_IRQorDRQ					; Wait until ready to transfer
@@ -189,5 +192,9 @@
 	mov		cl, [bp+PIOVARS.bSectorsLeft]		; CH is already zero
 	push	cx
+	push	ds
+	push	es
+	pop		ds
 	call	[bp+PIOVARS.fnXfer]					; Transfer possibly partial block
+	pop		ds
 	jmp		SHORT CheckErrorsAfterTransferringLastBlock
 
@@ -237,5 +244,4 @@
 	; Convert ES:SI to physical address
 %ifdef USE_386
-
 	mov		dx, es
 	xor		ax, ax
@@ -247,52 +253,26 @@
 
 %elifdef USE_186
-						; Bytes	EU Cycles(286)
-	mov		ax, es		; 2		2
-	rol		ax, 4		; 3		9
-	mov		dx, ax		; 2		2
-	and		ax, BYTE 0Fh; 3		3
-	xor		dx, ax		; 2		2
-	add		si, dx		; 2		2
-	adc		al, ah		; 2		2
-	mov		es, ax		; 2		2
-	;------------------------------------
-						; 18	24
+	mov		ax, es
+	rol		ax, 4
+	mov		dx, ax
+	and		ax, 0Fh
+	xor		dx, ax
+	add		si, dx
+	adc		al, ah
+	mov		es, ax
+
 %else ; 808x
-						; Bytes	EU Cycles(808x)
-	mov		al, 4		; 2		4
-	mov		dx, es		; 2		2
-	xchg	cx, ax		; 1		3
-	rol		dx, cl		; 2		24
-	mov		cx, dx		; 2		2
-	xchg	cx, ax		; 1		3
-	and		ax, BYTE 0Fh; 3		4
-	xor		dx, ax		; 2		3
-	add		si, dx		; 2		3
-	adc		al, ah		; 2		3
-	mov		es, ax		; 2		2
-	;------------------------------------
-						; 21	53
-;
-; Judging by the Execution Unit cycle count the above block of code is
-; apparently slower. However, the shifts and rotates in the block below
-; execute faster than the Bus Interface Unit on an 8088 can fetch them,
-; thus causing the EU to starve. The difference in true execution speed
-; (if any) might not be worth the extra 5 bytes.
-; In other words, we could use a real world test here.
-;
-%if 0
-						; Bytes	EU Cycles(808x/286)
-	xor		dx, dx		; 2		3/2
-	mov		ax, es		; 2		2/2
-%rep 4
-	shl		ax, 1		; 8		8/8
-	rcl		dx, 1		; 8		8/8
-%endrep
-	add		si, ax		; 2		3/2
-	adc		dl, dh		; 2		3/2
-	mov		es, dx		; 2		2/2
-	;------------------------------------
-						; 26	29/26
-%endif ; 0
+	mov		al, 4
+	mov		dx, es
+	xchg	cx, ax
+	rol		dx, cl
+	mov		cx, dx
+	xchg	cx, ax
+	and		ax, 0Fh
+	xor		dx, ax
+	add		si, dx
+	adc		al, ah
+	mov		es, ax
+
 %endif
 
@@ -334,7 +314,11 @@
 %ifdef USE_AT		; CF is always clear for XT builds
 	; AH = RET_HD_INVALID (01) if CF set, RET_HD_SUCCESS (00) if not. CF unchanged.
+%ifdef USE_386
+	setc	ah
+%else
 	sbb		ah, ah
 	neg		ah
 %endif
+%endif ; USE_AT
 	ret
 
@@ -345,5 +329,9 @@
 g_rgfnPioRead:
 		dw		IdePioBlock_ReadFrom16bitDataPort	; 0, DEVICE_16BIT_ATA
+%ifdef MODULE_ADVANCED_ATA
 		dw		IdePioBlock_ReadFrom32bitDataPort	; 1, DEVICE_32BIT_ATA
+%elifdef MODULE_8BIT_IDE
+		dw		NULL
+%endif ; MODULE_ADVANCED_ATA
 %ifdef MODULE_8BIT_IDE
 		dw		IdePioBlock_ReadFrom8bitDataPort	; 2, DEVICE_8BIT_ATA
@@ -361,5 +349,9 @@
 g_rgfnPioWrite:
 		dw		IdePioBlock_WriteTo16bitDataPort	; 0, DEVICE_16BIT_ATA
+%ifdef MODULE_ADVANCED_ATA
 		dw		IdePioBlock_WriteTo32bitDataPort	; 1, DEVICE_32BIT_ATA
+%elifdef MODULE_8BIT_IDE
+		dw		NULL
+%endif ; MODULE_ADVANCED_ATA
 %ifdef MODULE_8BIT_IDE
 		dw		IdePioBlock_WriteTo8bitDataPort		; 2, DEVICE_8BIT_ATA
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 589)
@@ -98,5 +98,13 @@
 %endif
 	cld									; String instructions to increment pointers
-	CREATE_FRAME_INTPACK_TO_SSBP	SIZE_OF_IDEPACK_WITHOUT_INTPACK
+	ePUSHA
+	push	ds
+	push	es
+%ifdef USE_386
+;	push	fs
+;	push	gs
+%endif
+	sub		sp, BYTE SIZE_OF_IDEPACK_WITHOUT_INTPACK
+	mov		bp, sp
 	call	RamVars_GetSegmentToDS
 
@@ -297,6 +305,14 @@
 	; on INT 13h to enable interrupts.
 	or		BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
-	mov		sp, bp	; This makes possible to exit anytime, no matter what is on stack
-	RESTORE_FRAME_INTPACK_FROM_SSBP		SIZE_OF_IDEPACK_WITHOUT_INTPACK
+
+	lea		sp, [bp+SIZE_OF_IDEPACK_WITHOUT_INTPACK]
+%ifdef USE_386
+;	pop		gs
+;	pop		fs
+%endif
+	pop		es
+	pop		ds
+	ePOPA
+	iret
 
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1Eh_XTCF.asm	(revision 589)
@@ -152,44 +152,4 @@
 
 
-%if 0
-	; We always need to enable 8-bit mode since 16-bit mode is restored
-	; when controller is reset (AH=00h or 0Dh)
-	ePUSH_T	bx, AH23h_Enable8bitPioMode
-
-	; Convert mode to device type (see XTCF.inc for full details)
-	and		ax, 3
-	jz		SHORT .Set8bitPioMode	; XTCF_8BIT_PIO_MODE = 0
-	dec		ax						; XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD = 1
-	jz		SHORT .Set8bitPioModeWithBIUOffload
-	dec		ax						; XTCF_16BIT_PIO_WITH_BIU_OFFLOAD = 2
-	jz		SHORT .Set16bitPioModeWithBIUOffload
-
-	; XTCF_DMA_MODE = 3
-	mov		BYTE [di+DPT_ATA.bDevice], DEVICE_8BIT_XTCF_DMA
-
-	; DMA transfers have limited block size
-	mov		al, [di+DPT_ATA.bBlockSize]
-	cmp		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jbe		SHORT AH24h_SetBlockSize
-	mov		al, XTCF_DMA_MODE_MAX_BLOCK_SIZE
-	jmp		SHORT AH24h_SetBlockSize
-
-.Set16bitPioModeWithBIUOffload:
-	pop		bx								; Do not enable 8-bit PIO...
-	ePUSH_T	bx, AH23h_Disable8bitPioMode	; ...disable it instead
-	mov		al, DEVICE_8BIT_XTCF_PIO16_WITH_BIU_OFFLOAD
-	SKIP2B	bx
-
-.Set8bitPioMode:
-	mov		al, DEVICE_8BIT_XTCF_PIO8
-	SKIP2B	bx
-
-.Set8bitPioModeWithBIUOffload:
-	mov		al, DEVICE_8BIT_XTCF_PIO8_WITH_BIU_OFFLOAD
-	mov		[di+DPT_ATA.bDevice], al
-	ret
-%endif ; 0
-
-
 ;--------------------------------------------------------------------
 ; AH1Eh_GetCurrentXTCFmodeToAX
@@ -197,5 +157,5 @@
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
 ;	Returns:
-;		AX:		XT-CF mode (XTCF_8BIT_PIO_MODE, XTCF_8BIT_PIO_MODE_WITH_BIU_OFFLOAD, XTCF_16BIT_PIO_WITH_BIU_OFFLOAD or XTCF_DMA_MODE)
+;		AX:		XT-CF mode (see XTCF.inc)
 ;		CF:		Clear
 ;	Corrupts registers:
@@ -208,9 +168,2 @@
 	ret
 
-%if 0
-	mov		al, [di+DPT_ATA.bDevice]
-	shr		al, 1
-	cbw
-	sub		al, XTCF_DEVICE_OFFSET >> 1
-	ret
-%endif ; 0
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 589)
@@ -92,4 +92,6 @@
 	mov		si, FEATURE_ENABLE_8BIT_PIO_TRANSFER_MODE
 	jmp		SHORT AH23h_SetControllerFeatures
+
+%ifdef MODULE_8BIT_IDE_ADVANCED
 AH23h_Disable8bitPioMode:
 	mov		si, FEATURE_DISABLE_8BIT_PIO_TRANSFER_MODE
@@ -97,3 +99,4 @@
 	xor		ah, ah			; Clear error since modern drives might not understand the command and are
 	ret						; always in 16-bit mode anyway
-%endif
+%endif ; MODULE_8BIT_IDE_ADVANCED
+%endif ; MODULE_8BIT_IDE
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm	(revision 589)
@@ -40,5 +40,5 @@
 ;		AH:		Int 13h/40h floppy return status
 ;		AL:		Burst error length if AH returns 11h (we never return error code 11h)
-;				Number of sectors actually read (only valid if CF set for someBIOSes)
+;				Number of sectors actually read (only valid if CF set for some BIOSes)
 ;		CF:		0 if successful, 1 if error
 ;--------------------------------------------------------------------
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm	(revision 589)
@@ -39,5 +39,5 @@
 ;	Returns with INTPACK:
 ;		AH:		Int 13h/40h floppy return status
-;		AL:		Number of sectors actually written (only valid if CF set for someBIOSes)
+;		AL:		Number of sectors actually written (only valid if CF set for some BIOSes)
 ;		CF:		0 if successful, 1 if error
 ;--------------------------------------------------------------------
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 589)
@@ -184,6 +184,6 @@
 
 	; Advanced PIO mode 3 and above
-	mov		dl, [di+DPT_ADVANCED_ATA.bPioMode]
-	or		dl, PIO_FLOW_CONTROL_MODE_xxx
+	mov		dl, PIO_FLOW_CONTROL_MODE_xxx
+	or		dl, [di+DPT_ADVANCED_ATA.bPioMode]
 
 .IordyNotSupported:
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Tools/Address.asm	(revision 589)
@@ -174,13 +174,9 @@
 	; +=sectToSeek-1 (24-bit result)
 	; Max = 16,450,497 + 63 - 1 = 16,450,559 = FB03FFh
-	xor		bh, bh					; Sector number now in BX
+	mov		bh, ch					; Sector number now in BX, CH=zero
 	dec		bx						; sectToSeek-=1
-	add		ax, bx					; Add to loword
-	adc		dl, bh					; Add possible carry to byte2, BH=zero
-
-	; Copy DX:AX to proper return registers
-	xchg	bx, ax					; BL = Sector Number Register (LBA 7...0)
-	mov		cl, bh					; Low Cylinder Register (LBA 15...8)
-	mov		ch, dl					; High Cylinder Register (LBA 23...16)
-	mov		bh, dh					; Drive and Head Register (LBA 27...24)
+	add		bx, ax					; Add loword to BX (BL = Sector Number Register (LBA 7...0))
+	adc		ch, dl					; Add possible carry to byte2 (CH = High Cylinder Register (LBA 23...16))
+	mov		cl, bh					; CL = Low Cylinder Register (LBA 15...8)
+	mov		bh, dh					; BH = Drive and Head Register (LBA 27...24)
 	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm	(revision 589)
@@ -37,15 +37,19 @@
 AdvAtaInit_DetectControllerForIdeBaseInBX:
 	call	Vision_DetectAndReturnIDinAXandPortInDXifControllerPresent
-	jne		SHORT .NoAdvancedControllerForPortBX
+	jnz		SHORT .NoVisionControllerFound
+
 	call	Vision_DoesIdePortInBXbelongToControllerWithIDinAX
-	jne		SHORT .NoAdvancedControllerForPortBX
+	jz		SHORT .AdvancedControllerFoundForPortBX
+
+.NoVisionControllerFound:
 	call	PDC20x30_DetectControllerForIdeBaseInBX
 	jnc		SHORT .NoAdvancedControllerForPortBX
 
-	stc		; Advanced Controller found for port BX
+.AdvancedControllerFoundForPortBX:
+	stc
 	ret
 
 .NoAdvancedControllerForPortBX:
-	xor		ax, ax
+	xor		ax, ax		; Clear ID in AX and CF
 	ret
 
@@ -66,8 +70,13 @@
 AdvAtaInit_GetControllerMaxPioModeToALandMinPioCycleTimeToBX:
 	cmp		ah, ID_QD6580_ALTERNATE
+%ifdef USE_386
+	jae		Vision_GetMaxPioModeToALandMinCycleTimeToBX
+	jmp		PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX
+%else
 	jae		SHORT .Vision
 	jmp		PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX
 .Vision:
 	jmp		Vision_GetMaxPioModeToALandMinCycleTimeToBX
+%endif
 
 
@@ -88,5 +97,5 @@
 	test	ax, ax
 	jz		SHORT .NoAdvancedController	; Return with CF cleared
-	
+
 	cmp		ah, ID_QD6580_ALTERNATE
 	jae		SHORT .Vision
@@ -98,5 +107,5 @@
 
 	call	AdvAtaInit_LoadMasterDPTtoDSSIifSlaveInDSDI
-	call	Vision_InitializeWithIDinAHandConfigInAL
+	call	Vision_InitializeWithIDinAH
 	xor		ax, ax						; Success
 
@@ -116,5 +125,5 @@
 ;				Zero if Slave Drive not present
 ;	Corrupts registers:
-;		AX
+;		AL
 ;--------------------------------------------------------------------
 AdvAtaInit_LoadMasterDPTtoDSSIifSlaveInDSDI:
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/PDC20x30.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/PDC20x30.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/PDC20x30.asm	(revision 589)
@@ -36,9 +36,42 @@
 	mov		dx, bx
 	call	EnablePdcProgrammingMode
-	jz		.ControllerDetected
-	clc
-	ret
-.ControllerDetected:
-	call	GetPdcIDtoAX
+	jnz		SHORT DisablePdcProgrammingMode.Return	; PDC controller not detected
+;	ePUSH_T	ax, DisablePdcProgrammingMode			; Uncomment this if GetPdcIDtoAX needs to be a real function
+	; Fall to GetPdcIDtoAX
+
+;--------------------------------------------------------------------
+; Programming mode must be enabled for this function.
+; This function also enables PDC 20630 extra registers.
+;
+; GetPdcIDtoAX
+;	Parameters:
+;		DX:		IDE Base port
+;	Returns:
+;		AH:		PDC ID
+;	Corrupts registers:
+;		AL, BX
+;--------------------------------------------------------------------
+GetPdcIDtoAX:
+	push	dx
+
+	; Try to enable PDC 20630 extra registers
+	add		dx, BYTE LOW_CYLINDER_REGISTER
+	in		al, dx
+	or		al, FLG_PDCLCR_ENABLE_EXTRA_REGISTERS
+	out		dx, al
+
+	; Try to access PDC 20630 registers to see if they are available
+	; Hopefully this does not cause problems for systems with PDC 20230
+	add		dx, BYTE PDC20630_INDEX_REGISTER - LOW_CYLINDER_REGISTER
+	mov		al, PDCREG7_STATUS	; Try to access PDC 20630 status register
+	out		dx, al
+	xchg	bx, ax
+	in		al, dx				; Does index register contain status register index?
+	cmp		al, bl
+	mov		ah, ID_PDC20630
+	eCMOVNE	ah, ID_PDC20230
+
+	pop		dx
+;	ret							; Uncomment this to make GetPdcIDtoAX a real function
 	; Fall to DisablePdcProgrammingMode
 
@@ -49,5 +82,5 @@
 ;		DX:		Base port
 ;	Returns:
-;		Nothing
+;		CF:		Set
 ;	Corrupts registers:
 ;		AL
@@ -56,6 +89,6 @@
 	add		dx, BYTE HIGH_CYLINDER_REGISTER
 	in		al, dx
-	sub		dx, BYTE HIGH_CYLINDER_REGISTER
-	stc		; Set for PDC20x30_DetectControllerForIdeBaseInBX
+	add		dx, -HIGH_CYLINDER_REGISTER		; Sets CF for PDC20x30_DetectControllerForIdeBaseInBX
+.Return:
 	ret
 
@@ -66,4 +99,5 @@
 ;		DX:		Base port
 ;	Returns:
+;		CF:		Cleared
 ;		ZF:		Set if programming mode enabled
 ;	Corrupts registers:
@@ -72,6 +106,7 @@
 EnablePdcProgrammingMode:
 	; Set bit 7 to sector count register
-	add		dx, BYTE SECTOR_COUNT_REGISTER
-	in		al, dx
+	inc		dx
+	inc		dx
+	in		al, dx	; 1F2h (SECTOR_COUNT_REGISTER)
 	or		al, 80h
 	out		dx, al
@@ -93,38 +128,7 @@
 	; PDC20230C and PDC20630 clears the bit we set at the beginning
 	in		al, dx
-	sub		dx, BYTE SECTOR_COUNT_REGISTER
-	test	al, 80h
-	ret
-
-
-;--------------------------------------------------------------------
-; Programming mode must be enabled for this function.
-; This function also enables PDC 20630 extra registers.
-;
-; GetPdcIDtoAX
-;	Parameters:
-;		DX:		IDE Base port
-;	Returns:
-;		AX:		PDC ID word
-;	Corrupts registers:
-;		BX
-;--------------------------------------------------------------------
-GetPdcIDtoAX:
-	; Try to enable PDC 20630 extra registers
-	add		dx, BYTE LOW_CYLINDER_REGISTER
-	in		al, dx
-	or		al, FLG_PDCLCR_ENABLE_EXTRA_REGISTERS
-	out		dx, al
-
-	; Try to access PDC 20630 registers to see if they are available
-	; Hopefully this does not cause problems for systems with PDC 20230
-	add		dx, BYTE PDC20630_INDEX_REGISTER - LOW_CYLINDER_REGISTER
-	mov		al, PDCREG7_STATUS	; Try to access PDC 20630 status register
-	out		dx, al
-	xchg	bx, ax
-	in		al, dx				; Does index register contain status register index?
-	cmp		al, bl
-	mov		ah, ID_PDC20630
-	eCMOVNE	ah, ID_PDC20230
+	dec		dx
+	dec		dx		; Base port
+	test	al, 80h	; Clears CF
 	ret
 
@@ -145,9 +149,9 @@
 PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX:
 	cmp		ah, ID_PDC20630
-	je		SHORT .return		; No need to limit anything
+	je		SHORT .Return		; No need to limit anything
 	mov		ax, 2				; Limit PIO to 2 for ID_PDC20230
 	mov		bx, PIO_2_MIN_CYCLE_TIME_NS
 	stc
-.return:
+.Return:
 	ret
 
@@ -165,7 +169,15 @@
 ;--------------------------------------------------------------------
 PDC20x30_InitializeForDPTinDSDI:
+%ifdef USE_386
+	xor		ch, ch
+	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
+	setnz	cl
+%else
 	xor		cx, cx
 	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
-	eCSETNZ	cl
+	jz		SHORT .NotSlave
+	inc		cx
+.NotSlave:
+%endif
 
 	mov		dx, [di+DPT.wBasePort]
@@ -173,7 +185,7 @@
 	call	SetSpeedForDriveInCX
 	cmp		BYTE [di+DPT_ADVANCED_ATA.wControllerID+1], ID_PDC20630
-	jne		.initializationCompleted
+	jne		SHORT .InitializationCompleted
 	call	SetPdc20630SpeedForDriveInCX
-.initializationCompleted:
+.InitializationCompleted:
 	mov		dx, [di+DPT.wBasePort]
 	call	DisablePdcProgrammingMode
@@ -201,15 +213,17 @@
 	mov		bh, ~MASK_PDCSCR_DEV1SPEED	; Assume slave
 	inc		cx
-	loop	.setSpeed
+	loop	.SetSpeed
 	eSHL_IM	bl, POS_PDCSCR_DEV0SPEED
 	mov		bh, ~MASK_PDCSCR_DEV0SPEED
-.setSpeed:
+.SetSpeed:
 	in		al, dx
 	and		al, bh
 	or		al, bl
 	cmp		bl, 7
-	jb		SHORT OutputNewValue
+	jb		SHORT .OutputNewValue
 	or		al, FLG_PDCSCR_UNKNOWN_BIT7	; Flag for PIO 2 and above?
-	jmp		SHORT OutputNewValue
+.OutputNewValue:
+	out		dx, al
+	ret
 
 .rgbPioModeToPDCspeedValue:
@@ -228,20 +242,18 @@
 ;		DX:		Low Cylinder Register
 ;	Corrupts registers:
-;		AX, CX
+;		AX
 ;--------------------------------------------------------------------
 SetPdc20630SpeedForDriveInCX:
 	inc		dx		; LOW_CYLINDER_REGISTER
-	mov		ah, FLG_PDCLCR_DEV0SPEED_BIT4 | FLG_PDCLCR_DEV0IORDY
-	shr		ah, cl
-	in		al, dx
-	not		ah
+	mov		ah, ~(FLG_PDCLCR_DEV0SPEED_BIT4 | FLG_PDCLCR_DEV0IORDY)
+	ror		ah, cl
+	in		al, dx
 	and		al, ah	; Clear drive specific bits
 	cmp		BYTE [di+DPT_ADVANCED_ATA.bPioMode], 2
-	jbe		.clearBitsOnly
+	jbe		.ClearBitsOnly
 	not		ah
 	or		al, ah
-.clearBitsOnly:
-OutputNewValue:
-	out		dx, al
-	ret
-
+.ClearBitsOnly:
+	out		dx, al
+	ret
+
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/Vision.asm	(revision 589)
@@ -29,5 +29,5 @@
 ;		AX:		ID WORD specific for QDI Vision Controllers
 ;				(AL = QD65xx Config Register contents)
-;				(AH = QDI Vision Controller ID (bits 4...7))
+;				(AH = QDI Vision Controller ID)
 ;		DX:		Controller port (not IDE port)
 ;		ZF:		Set if controller found
@@ -46,8 +46,8 @@
 	; from Axh to Bxh.
 	call	IsConfigRegisterWithIDinAL
-	je		SHORT VisionControllerDetected
+	je		SHORT VisionControllerDetected.Return
 
 	; Check QD65xx alternative base port
-	or		dl, QD65XX_ALTERNATIVE_BASE_PORT
+	mov		dl, QD65XX_ALTERNATIVE_BASE_PORT
 	in		al, QD65XX_ALTERNATIVE_BASE_PORT + QD65XX_CONFIG_REGISTER_in
 %endif ; DANGEROUS_DETECTION
@@ -68,11 +68,12 @@
 	mov		ah, al
 	and		al, MASK_QDCONFIG_CONTROLLER_ID
-	cmp		al, ID_QD6500 << 4
+	cmp		al, ID_QD6500
 	je		SHORT VisionControllerDetected
-	cmp		al, ID_QD6580 << 4
+	cmp		al, ID_QD6580
 	je		SHORT VisionControllerDetected
-	cmp		al, ID_QD6580_ALTERNATE << 4
+	cmp		al, ID_QD6580_ALTERNATE
 VisionControllerDetected:
 	xchg	ah, al
+.Return:
 	ret
 
@@ -82,5 +83,5 @@
 ;	Parameters:
 ;		AL:		QD65xx Config Register contents
-;		AH:		QDI Vision Controller ID (bits 4...7)
+;		AH:		QDI Vision Controller ID
 ;		BX:		IDE Base port to check
 ;		DX:		Vision Controller port
@@ -92,5 +93,5 @@
 ;--------------------------------------------------------------------
 Vision_DoesIdePortInBXbelongToControllerWithIDinAX:
-	cmp		ah, ID_QD6500 << 4
+	cmp		ah, ID_QD6500
 	je		SHORT .DoesIdePortInDXbelongToQD6500
 
@@ -128,5 +129,5 @@
 ;	Parameters:
 ;		AL:		QD65xx Config Register contents
-;		AH:		QDI Vision Controller ID (bits 4...7)
+;		AH:		QDI Vision Controller ID
 ;	Returns:
 ;		AL:		Max supported PIO mode
@@ -139,5 +140,5 @@
 ;--------------------------------------------------------------------
 Vision_GetMaxPioModeToALandMinCycleTimeToBX:
-	cmp		ah, ID_QD6500 << 4
+	cmp		ah, ID_QD6500
 	jne		SHORT .NoNeedToLimitForQD6580
 
@@ -149,8 +150,7 @@
 
 ;--------------------------------------------------------------------
-; Vision_InitializeWithIDinAHandConfigInAL
-;	Parameters:
-;		AL:		QD65xx Config Register contents
-;		AH:		QDI Vision Controller ID (bits 4...7)
+; Vision_InitializeWithIDinAH
+;	Parameters:
+;		AH:		QDI Vision Controller ID
 ;		DS:DI:	Ptr to DPT for Single or Slave Drive
 ;		SI:		Offset to Master DPT if Slave Drive present
@@ -162,7 +162,7 @@
 ;		AX, BX, CX, DX, BP
 ;--------------------------------------------------------------------
-Vision_InitializeWithIDinAHandConfigInAL:
+Vision_InitializeWithIDinAH:
 	; QD6580 has a Control Register that needs to be programmed
-	cmp		ah, ID_QD6500 << 4
+	cmp		ah, ID_QD6500
 	mov		dx, [di+DPT_ADVANCED_ATA.wControllerBasePort]
 	mov		bp, QD6500_MAX_ACTIVE_TIME_CLOCKS | (QD6500_MIN_ACTIVE_TIME_CLOCKS << 8)	; Assume QD6500
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 589)
@@ -81,5 +81,5 @@
 	mov		al, [cs:ROMVARS.wFlags]			; Configurator set to always scan?
 	or		al, [es:BDA.bKBFlgs1]			; Or, did the user hold down the ALT key?
-	and		al, 8							; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_ALWAYSDETECT
+	and		al, 8							; 8 = alt key depressed, same as FLG_ROMVARS_SERIAL_SCANDETECT
 	jnz		.DriveDetectLoop
 %endif ; MODULE_SERIAL
@@ -135,5 +135,5 @@
 
 	shr		ch, 1							; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
-	rcl		al, 1							; starting drive number in upper 7 bits, number of drives in low bit
+	eRCL_IM	al, 1							; starting drive number in upper 7 bits, number of drives in low bit
 .NoFloppies:
 	mov		[RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 589)
@@ -90,6 +90,5 @@
 %ifdef MODULE_SERIAL
 	cmp		dh, DEVICE_SERIAL_PORT			; Check if this is a serial device
-
-	jnz		.pushAndPrint					; CX = string to print, AX = port address, DX won't be used
+	jne		SHORT .pushAndPrint				; CX = string to print, AX = port address, DX won't be used
 
 	mov		cl, (g_szDetectCOM-$$) & 0xff	; Setup print string for COM ports
@@ -106,21 +105,21 @@
 
 	test	dl, dl							; Check if serial port "Auto"
-	jz		.pushAndPrintSerial				; CX = string to print, AX and DX won't be used
+	jz		SHORT .pushAndPrintSerial		; CX = string to print, AX and DX won't be used
 
 	mov		cl, (g_szDetectCOMLarge-$$) & 0xff	; Setup secondary print string for "COMn/xx.yK"
 
-	mov		al,ah							; baud rate divisor to AL
+	mov		al, ah							; baud rate divisor to AL
 	cbw										; clear AH, AL will always be less than 128
-	xchg	si,ax							; move AX to SI for divide
-	mov		ax,1152							; baud rate to display is 115200/divisor, the "00" is handled
+	xchg	si, ax							; move AX to SI for divide
+	mov		ax, 1152						; baud rate to display is 115200/divisor, the "00" is handled
 											; in the print strings
 	cwd										; clear top 16-bits of dividend
 	div		si								; and divide...  Now AX = baud rate/100, DX = 0 (always a clean divide)
 
-	mov		si,10							; Now separate the whole portion from the fractional for "K" display
+	mov		si, 10							; Now separate the whole portion from the fractional for "K" display
 	div		si								; and divide...  Now AX = baud rate/1000, DX = low order digit
 
-	cmp		ax,si							; < 10: "2400", "9600", etc.; >= 10: "19.2K", "38.4K", etc.
-	jae		.pushAndPrintSerial
+	cmp		ax, si							; < 10: "2400", "9600", etc.; >= 10: "19.2K", "38.4K", etc.
+	jae		SHORT .pushAndPrintSerial
 
 	mov		cl, (g_szDetectCOMSmall-$$) & 0xff	; Setup secondary print string for "COMn/XXy00"
@@ -150,8 +149,8 @@
 DetectPrint_DriveNameFromDrvDetectInfoInESBX:
 	push	bp
-	mov		bp,sp
-	lea		si,[bx+DRVDETECTINFO.szDrvName]
+	mov		bp, sp
+	lea		si, [bx+DRVDETECTINFO.szDrvName]
 	push	si
-	mov		si,g_szDriveName
+	mov		si, g_szDriveName
 	jmp		SHORT DetectPrint_FormatCSSIfromParamsInSSBP
 
@@ -276,5 +275,5 @@
 ;
 	push	bp
-	mov		bp,sp
+	mov		bp, sp
 	; Fall to DetectPrint_FormatCSSIfromParamsInSSBP
 
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/Interrupts.asm	(revision 589)
@@ -240,7 +240,6 @@
 	push	cx
 	xchg	ax, cx				; IRQ index to CL
-	mov		ch, 1				; Load 1 to be shifted
-	shl		ch, cl				; Shift bit to correct position
-	not		ch					; Invert to create bit mask for clearing
+	mov		ch, ~1				; Load bit mask to be rotated
+	rol		ch, cl				; Rotate mask to correct position for clearing
 	in		al, dx				; Read Interrupt Mask Register
 	and		al, ch				; Clear wanted bit
Index: /trunk/XTIDE_Universal_BIOS/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Main.asm	(revision 589)
@@ -117,5 +117,5 @@
 
 %ifdef MODULE_SERIAL
-	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,		db	DEVICE_SERIAL_PORT
+	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,	db	DEVICE_SERIAL_PORT
 %endif
 %else
@@ -134,26 +134,39 @@
 	at	ROMVARS.bIdleTimeout,	db	0						; Standby timer disabled by default
 
-%ifdef MODULE_8BIT_IDE_ADVANCED
-	at	ROMVARS.ideVars0+IDEVARS.wBasePort,				dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
-	at	ROMVARS.ideVars0+IDEVARS.bDevice,				db	DEVICE_8BIT_XTCF_PIO8
+%ifndef MODULE_8BIT_IDE
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_ATA_PRIMARY_PORT 		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_PRIMARY_PORTCTRL 	; Controller Control Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
+%elifdef MODULE_8BIT_IDE_ADVANCED
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_8BIT_XTCF_PIO8
 %else
-	at	ROMVARS.ideVars0+IDEVARS.wBasePort,				dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
-	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,		dw	DEVICE_XTIDE_DEFAULT_PORTCTRL	; Controller Control Block base port
-	at	ROMVARS.ideVars0+IDEVARS.bDevice,				db	DEVICE_8BIT_XTIDE_REV1
+	at	ROMVARS.ideVars0+IDEVARS.wBasePort,			dw	DEVICE_XTIDE_DEFAULT_PORT		; Controller Command Block base port
+	at	ROMVARS.ideVars0+IDEVARS.wControlBlockPort,	dw	DEVICE_XTIDE_DEFAULT_PORTCTRL	; Controller Control Block base port
+	at	ROMVARS.ideVars0+IDEVARS.bDevice,			db	DEVICE_8BIT_XTIDE_REV1
 %endif
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars0+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars1+IDEVARS.wBasePort,			dw	DEVICE_ATA_SECONDARY_PORT
+	at	ROMVARS.ideVars1+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_SECONDARY_PORTCTRL
+	at	ROMVARS.ideVars1+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars1+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars2+IDEVARS.wBasePort,			dw	DEVICE_ATA_TERTIARY_PORT
+	at	ROMVARS.ideVars2+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_TERTIARY_PORTCTRL
+	at	ROMVARS.ideVars2+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
 	at	ROMVARS.ideVars2+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars2+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
+	at	ROMVARS.ideVars3+IDEVARS.wBasePort,			dw	DEVICE_ATA_QUATERNARY_PORT
+	at	ROMVARS.ideVars3+IDEVARS.wControlBlockPort,	dw	DEVICE_ATA_QUATERNARY_PORTCTRL
+	at	ROMVARS.ideVars3+IDEVARS.bDevice,			db	DEVICE_16BIT_ATA
 	at	ROMVARS.ideVars3+IDEVARS.drvParamsMaster+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 	at	ROMVARS.ideVars3+IDEVARS.drvParamsSlave+DRVPARAMS.wFlags,	db	DISABLE_WRITE_CACHE | FLG_DRVPARAMS_BLOCKMODE | (TRANSLATEMODE_AUTO<<TRANSLATEMODE_FIELD_POSITION)
 
 %ifdef MODULE_SERIAL
-	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,		db	DEVICE_SERIAL_PORT
+	at	ROMVARS.ideVarsSerialAuto+IDEVARS.bDevice,	db	DEVICE_SERIAL_PORT
 %endif
 %endif
@@ -286,2 +299,15 @@
 	%include "AH41h_CheckIfExtensionsPresent.asm"
 %endif
+
+
+; Although it's very unlikely to happen, we give warnings for builds that cannot be automatically checksummed due to the size being too large.
+; In some cases it's theoretically possible to checksum the build anyway (manually) which is why these are warnings and not errors.
+%if BIOS_SIZE = 8192				; A small build, possibly a candidate for the ROM socket on a 3Com 3C503 card.
+	%if ($-$$) <= BIOS_SIZE			; Only give warnings when the problem isn't obvious anyway.
+		%if ($-$$) > BIOS_SIZE - 3
+			%warning "This build is too large to be auto-checksummed!"
+		%endif
+	%endif
+%elif ($-$$) = BIOS_SIZE			; A large build.
+	%warning "This build is too large to be auto-checksummed!"
+%endif
Index: /trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrint.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Menus/BootMenu/BootMenuPrint.asm	(revision 589)
@@ -39,20 +39,20 @@
 	mov		si, g_szRomBootDash						; Standard "Rom Boot" but with a "-" at the front
 	mov		al, 20h									; The space between "Rom" and "Boot"
-	jnc		.ROMBoot								; display "Rom Boot" option for last entry
+	jnc		SHORT .ROMBoot							; display "Rom Boot" option for last entry
 
 	call	FindDPT_ForDriveNumberInDL
-	jc		.notOurs
+	jc		SHORT .notOurs
 
 	call	DriveDetectInfo_ConvertDPTtoBX
 	mov		si, g_szDriveNumBOOTNFO					; special g_szDriveNum that prints from BDA
-	jmp		.go
+	jmp		SHORT .go
 
 .notOurs:
-	mov		si,g_szDriveNum
-	mov		bx,g_szForeignHD						; assume a hard disk for the moment
+	mov		si, g_szDriveNum
+	mov		bx, g_szForeignHD						; assume a hard disk for the moment
 
 	test	dl, dl
-	js		.go
-	mov		bl,((g_szFloppyDrv)-$$ & 0xff)			; and revisit the earlier assumption...
+	js		SHORT .go
+	mov		bl, ((g_szFloppyDrv)-$$ & 0xff)			; and revisit the earlier assumption...
 
 .go:
@@ -60,8 +60,6 @@
 	call	DriveXlate_ToOrBack
 
-	test	dl, 0f0h								; if there is a character in the upper nibble
-	jnz		.noSpace
-	dec		si										; backup a character to a leading space
-.noSpace:
+	cmp		dl, 10h									; Check if there is a character in the upper nibble
+	sbb		si, 0									; If not, backup a character to a leading space
 
 	push	dx										; translated drive number
@@ -86,5 +84,5 @@
 ;--------------------------------------------------------------------
 BootMenuPrint_TitleStrings:
-	xor		di,di						; Null character will be eaten
+	xor		di, di						; Null character will be eaten
 	mov		si, g_szBootMenuTitle
 	jmp		DetectPrint_RomFoundAtSegment.BootMenuEntry
@@ -105,5 +103,5 @@
 
 	call	BootMenu_GetDriveToDXforMenuitemInCX
-	jnc		BootMenuEvent_Completed						; nothing to display if "Rom Boot" option
+	jnc		SHORT BootMenuEvent_Completed				; nothing to display if "Rom Boot" option
 
 	push	bp
@@ -116,9 +114,9 @@
 	inc		dl											; are we a hard disk?
 	dec		dl											; inc/dec will set SF, without modifying CF or DL
-	js		.HardDiskRefreshInformation
-
-	jnc		.ours										; Based on CF from FindDPT_ForDriveNumberInDL above
+	js		SHORT .HardDiskRefreshInformation
+
+	jnc		SHORT .ours									; Based on CF from FindDPT_ForDriveNumberInDL above
 	call	FloppyDrive_GetType							; Get Floppy Drive type to BX
-	jmp		.around
+	jmp		SHORT .around
 .ours:
 	call	AH8h_GetDriveParameters
@@ -132,5 +130,4 @@
 	cmp		bl, FLOPPY_TYPE_35_ED
 	ja		SHORT .PushAXAndOutput
-
 	; Fall to .PrintKnownFloppyType
 
@@ -162,5 +159,5 @@
 	mov		al, (g_szFddThreeHalf - $$) & 0xff
 	cmp		bl, FLOPPY_TYPE_525_HD
-	ja		.ThreeHalf
+	ja		SHORT .ThreeHalf
 	mov		al, (g_szFddFiveQuarter - $$) & 0xff
 .ThreeHalf:
@@ -168,5 +165,5 @@
 
 	xor		bh, bh
-	mov		al,FloppyTypes.rgbCapacityMultiplier
+	mov		al, FloppyTypes.rgbCapacityMultiplier
 	mul		BYTE [cs:bx+FloppyTypes.rgbCapacity - 1]	; -1 since 0 is handled above and not in the table
 
@@ -184,16 +181,35 @@
 ;	Parameters:
 ;		DS:		RAMVARS segment
+;		DI:		Zero if foreign drive
+;				Offset to DPT if our drive
+;		CF:		Set if foreign drive
+;				Clear if our drive
 ;	Returns:
 ;		CF:		Set since menu event was handled successfully
 ;	Corrupts registers:
-;		BX, CX, DX, SI, DI, ES
+;		AX, BX, CX, DX, SI, DI, ES
 ;--------------------------------------------------------------------
 .HardDiskRefreshInformation:
-	jc		.HardDiskMenuitemInfoForForeignDrive		; Based on CF from FindDPT_ForDriveNumberInDL (way) above
+	jc		SHORT .HardDiskMenuitemInfoForForeignDrive	; Based on CF from FindDPT_ForDriveNumberInDL (way) above
 
 .HardDiskMenuitemInfoForOurDrive:
 	ePUSH_T ax, g_szInformation							; Add substring for our hard disk information
-	call	GetTotalSectorCount
-	jmp		.ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
+
+%ifdef MODULE_EBIOS
+	ePUSH_T ax, .ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
+	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA
+%ifdef USE_386
+	jnz		AccessDPT_GetLbaSectorCountToBXDXAX
+	jmp		AH15h_GetSectorCountToBXDXAX
+%else ; ~USE_386
+	jz		SHORT .NoLBA
+	jmp		AccessDPT_GetLbaSectorCountToBXDXAX
+.NoLBA:
+	jmp		AH15h_GetSectorCountToBXDXAX
+%endif
+%else ; ~MODULE_EBIOS
+	call	AH15h_GetSectorCountToBXDXAX
+	jmp		SHORT .ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
+%endif ; MODULE_EBIOS
 
 .HardDiskMenuitemInfoForForeignDrive:
@@ -226,18 +242,2 @@
 	db		2880  / FloppyTypes.rgbCapacityMultiplier    ;  type 5
 	db		2880  / FloppyTypes.rgbCapacityMultiplier    ;  type 6
-
-
-;--------------------------------------------------------------------
-; GetTotalSectorCount
-;	Parameters:
-;		DS:DI:		DPT Pointer
-;	Returns:
-;		BX:DX:AX:	48-bit sector count
-;	Corrupts registers:
-;		CX
-;--------------------------------------------------------------------
-%ifdef MODULE_EBIOS
-GetTotalSectorCount		EQU		AccessDPT_GetLbaSectorCountToBXDXAX
-%else
-GetTotalSectorCount		EQU		AH15h_GetSectorCountToBXDXAX
-%endif
Index: /trunk/XTIDE_Universal_BIOS/Src/Strings.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 589)
@@ -136,8 +136,11 @@
 g_szDeviceTypeValues:
 g_szDeviceTypeValues_16bit:			db	" 16",NULL
+%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_32bit:			db	" 32",NULL
+%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_8bit:			db	"  8",NULL
 g_szDeviceTypeValues_XTIDEr1:		db	"D8 ",NULL	; Dual 8-bit
 g_szDeviceTypeValues_XTIDEr2:		db	"X8 ",NULL	; A0<->A3 swapped 8-bit
+%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_XTCFpio8:		db	"T8 ",NULL	; True 8-bit
 g_szDeviceTypeValues_XTCFpio8BIU:	db	"T8B",NULL
@@ -146,7 +149,13 @@
 g_szDeviceTypeValues_JrIde:			db	"M8 ",NULL	; Memory Mapped 8-bit
 g_szDeviceTypeValues_ADP50L:		db	"M8 ",NULL	; Memory Mapped 8-bit
+%ifdef MODULE_SERIAL
 g_szDeviceTypeValues_Serial:		db	"SER",NULL
-
-g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
+%endif ; MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
+g_szDeviceTypeValues_Displacement equ 3		; 3 compressed, 4 uncompressed
+;g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
 ;
 ; Ensure that device type strings are correctly spaced in memory
@@ -156,7 +165,13 @@
 		%error "g_szDeviceTypeValues Displacement Incorrect 1"
 	%endif
+
+	%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_32bit <> g_szDeviceTypeValues_16bit + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 2"
 	%endif
+
+	%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_8bit <> g_szDeviceTypeValues_32bit + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 3"
@@ -168,4 +183,7 @@
 		%error "g_szDeviceTypeValues Displacement Incorrect 5"
 	%endif
+
+	%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_XTCFpio8 <> g_szDeviceTypeValues_XTIDEr2 + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 6"
@@ -186,7 +204,16 @@
 		%error "g_szDeviceTypeValues Displacement Incorrect 11"
 	%endif
+
+	%ifdef MODULE_SERIAL
+
 	%if g_szDeviceTypeValues_Serial <> g_szDeviceTypeValues_ADP50L + g_szDeviceTypeValues_Displacement
 		%error "g_szDeviceTypeValues Displacement Incorrect 12"
 	%endif
+
+	%endif ; MODULE_SERIAL
+	%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+	%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+	%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %endif
 
Index: /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 589)
@@ -257,8 +257,10 @@
                            			  db	 20h,  2bh,  0fh          ; compressed
 
+%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_32bit:			; db	" 32",NULL
                            			; db	 20h,  33h,  32h,  00h    ; uncompressed
                            			  db	 20h,  2dh,  0ch          ; compressed
 
+%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_8bit:			; db	"  8",NULL
                           			; db	 20h,  20h,  38h,  00h    ; uncompressed
@@ -273,4 +275,5 @@
                              		  db	 5eh,  30h,  00h          ; compressed
 
+%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
 g_szDeviceTypeValues_XTCFpio8:		; db	"T8 ",NULL	; True 8-bit
                               		; db	 54h,  38h,  20h,  00h    ; uncompressed
@@ -297,10 +300,16 @@
                             		  db	 53h,  30h,  00h          ; compressed
 
+%ifdef MODULE_SERIAL
 g_szDeviceTypeValues_Serial:		; db	"SER",NULL
                             		; db	 53h,  45h,  52h,  00h    ; uncompressed
                             		  db	 59h,  4bh,  98h          ; compressed
 
-
-g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
+%endif ; MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
+g_szDeviceTypeValues_Displacement equ 3		; 3 compressed, 4 uncompressed
+;g_szDeviceTypeValues_Displacement equ (g_szDeviceTypeValues_32bit - g_szDeviceTypeValues)
 ;
 ; Ensure that device type strings are correctly spaced in memory
@@ -310,7 +319,13 @@
 %error "g_szDeviceTypeValues Displacement Incorrect 1"
 %endif
+
+%ifdef MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %if g_szDeviceTypeValues_32bit <> g_szDeviceTypeValues_16bit + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 2"
 %endif
+
+%ifdef MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %if g_szDeviceTypeValues_8bit <> g_szDeviceTypeValues_32bit + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 3"
@@ -322,4 +337,7 @@
 %error "g_szDeviceTypeValues Displacement Incorrect 5"
 %endif
+
+%ifdef MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %if g_szDeviceTypeValues_XTCFpio8 <> g_szDeviceTypeValues_XTIDEr2 + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 6"
@@ -340,7 +358,16 @@
 %error "g_szDeviceTypeValues Displacement Incorrect 11"
 %endif
+
+%ifdef MODULE_SERIAL
+
 %if g_szDeviceTypeValues_Serial <> g_szDeviceTypeValues_ADP50L + g_szDeviceTypeValues_Displacement
 %error "g_szDeviceTypeValues Displacement Incorrect 12"
 %endif
+
+%endif ; MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+%endif ; MODULE_ADVANCED_ATA OR MODULE_8BIT_IDE OR MODULE_8BIT_IDE_ADVANCED OR MODULE_SERIAL
+
 %endif
 
@@ -567,38 +594,38 @@
 
 ;; translated usage stats
-;; 172:2
-;; 47:2
-;; 171:2
-;; 46:3
-;; 48:2
-;; 181:1
-;; 200:1
-;; 54:2
-;; 45:2
-;; 49:2
 ;; 34:3
 ;; 179:8
-;; 56:8
+;; 46:3
+;; 44:1
+;; 200:1
+;; 48:2
+;; 175:1
+;; 171:2
+;; 51:3
+;; 50:2
 ;; 33:1
 ;; 53:2
+;; 45:2
+;; 47:2
+;; 172:2
+;; 56:8
 ;; 32:34
-;; 175:1
-;; 44:1
-;; 50:2
-;; 51:3
+;; 181:1
+;; 54:2
+;; 49:2
 ;; total translated: 20
 
 ;; format usage stats
-;; z:2
+;; 5-x:1
+;; 2-u:1
+;; s:14
 ;; nl:12
-;; u:6
-;; 5-x:1
-;; c:13
 ;; A:4
-;; s:14
 ;; 5-u:2
 ;; x:5
-;; 2-u:1
 ;; 2-I:1
+;; z:2
+;; u:6
+;; c:13
 ;; total format: 11
 
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 589)
@@ -62,5 +62,5 @@
 
 	jnz		SHORT .EnableDeviceIrq
-	or		al, FLG_DEVCONTROL_nIEN	; Disable IRQ
+	mov		al, FLG_DEVCONTROL_nIEN	; Disable IRQ
 .EnableDeviceIrq:
 %else
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CompatibleDPT.asm	(revision 589)
@@ -231,13 +231,15 @@
 
 	xor		dl, dl							; Clear DL for checksum
+	push	bp
+	mov		bp, StoswThenAddALandAHtoDL
 
 	; DPTE.wBasePort
 	mov		ax, [si+DPT.wBasePort]
-	call	StoswThenAddALandAHtoDL			; Bytes 0 and 1
+	call	bp								; Bytes 0 and 1
 
 	; DPTE.wControlBlockPort
 	eMOVZX	bx, [si+DPT.bIdevarsOffset]
 	mov		ax, [cs:bx+IDEVARS.wControlBlockPort]
-	call	StoswThenAddALandAHtoDL			; Bytes 2 and 3
+	call	bp								; Bytes 2 and 3
 
 	; DPTE.bDrvnhead and DPTE.bBiosVendor
@@ -245,14 +247,14 @@
 	call	AccessDPT_GetDriveSelectByteToAL
 	xchg	si, di
-	call	StoswThenAddALandAHtoDL			; Bytes 4 and 5
+	call	bp								; Bytes 4 and 5
 
 	; DPTE.bIRQ and DPTE.bBlockSize
 	mov		al, [cs:bx+IDEVARS.bIRQ]		; No way to define that we might not use IRQ
-	mov		ah, [si+DPT_ATA.bBlockSize]
-	cmp		ah, 1
-	jbe		SHORT .DoNotSetBlockModeFlag
+	mov		ah, [si+DPT_ATA.bBlockSize]		; DPT_ATA.bBlockSize must never be zero!
+	sahf									; Only block size = 1 sets CF
+	jc		SHORT .DoNotSetBlockModeFlag
 	or		cl, FLG_BLOCK_MODE_ENABLED
 .DoNotSetBlockModeFlag:
-	call	StoswThenAddALandAHtoDL			; Bytes 6 and 7
+	call	bp								; Bytes 6 and 7
 
 	; DPTE.bDmaChannelAndType and DPTE.bPioMode
@@ -266,5 +268,5 @@
 	sbb		cl, -1	; FLG_FAST_PIO_ENABLED (if .wControllerID > 0)
 .DoNotSetFastPioFlag:
-	call	StoswThenAddALandAHtoDL			; Bytes 8 and 9
+	call	bp								; Bytes 8 and 9
 %endif
 
@@ -279,5 +281,6 @@
 .NoChsTranslationOrBitShiftTranslationSet:
 	xchg	ax, cx
-	call	StoswThenAddALandAHtoDL			; Bytes 10 and 11
+	call	bp								; Bytes 10 and 11
+	pop		bp
 
 	; DPTE.wReserved (must be zero)
Index: /trunk/XTIDE_Universal_BIOS/makefile
===================================================================
--- /trunk/XTIDE_Universal_BIOS/makefile	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS/makefile	(revision 589)
@@ -18,5 +18,5 @@
 # MODULE_8BIT_IDE             Support for 8-BIT IDE cards like XTIDE                               #
 # MODULE_8BIT_IDE_ADVANCED    Support for memory mapped and DMA based cards like JRIDE and XTCF    #
-# MODULE_ADVANCED_ATA         Native support for some VLB IDE controllers                          #
+# MODULE_ADVANCED_ATA         Native support for some VLB IDE controllers (requires USE_386)       #
 # MODULE_COMPATIBLE_TABLES    Support for ill behaving software that tries to access DPT directly  #
 # MODULE_BOOT_MENU            Boot Menu for selection of drive to boot from                        #
@@ -108,5 +108,5 @@
 DEFINES_XT = $(DEFINES_COMMON) ELIMINATE_CGA_SNOW MODULE_8BIT_IDE_ADVANCED
 DEFINES_XTPLUS = $(DEFINES_XT) USE_186
-DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 MODULE_IRQ MODULE_ADVANCED_ATA MODULE_COMPATIBLE_TABLES
+DEFINES_AT = $(DEFINES_COMMON) USE_AT USE_286 MODULE_IRQ MODULE_COMPATIBLE_TABLES
 
 DEFINES_XT_LARGE = $(DEFINES_XT) $(DEFINES_COMMON_LARGE)
@@ -115,5 +115,5 @@
 
 DEFINES_XT_TINY = MODULE_STRINGS_COMPRESSED MODULE_8BIT_IDE NO_ATAID_VALIDATION
-DEFINES_386_8K = $(DEFINES_AT) USE_386
+DEFINES_386_8K = $(DEFINES_AT) USE_386 MODULE_ADVANCED_ATA
 
 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
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm	(revision 589)
@@ -75,6 +75,6 @@
 
 	cmp		dx, MAX_EEPROM_SIZE_IN_BYTES >> 16
+	jb		SHORT .FileNotTooBig
 	ja		SHORT .FileTooBig
-	jb		SHORT .FileNotTooBig
 	cmp		ax, MAX_EEPROM_SIZE_IN_BYTES & 0FFFFh
 	ja		SHORT .FileTooBig
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 589)
@@ -214,13 +214,28 @@
 	call	Buffers_GetFileBufferToESDI
 	call	EEPROM_GetXtideUniversalBiosSizeFromESDItoDXCX
-	dec		cx				; Leave space for checksum byte
-	xor		ax, ax
-ALIGN JUMP_ALIGN
+
+; Compatibility fix for 3Com 3C503 cards where the ASIC returns 8080h as the last two bytes of the ROM.
+
+	; Assume the BIOS size is not 8K, ie generate a normal checksum.
+	dec		cx
+	mov		ax, 100h
+	cmp		cx, 8192 - 1
+	jne		SHORT .BiosSizeIsNot8K
+	; The BIOS size is 8K and therefore a potential candidate for a 3Com 3C503 card.
+	dec		cx
+	dec		cx
+	mov		ah, 3
+ALIGN JUMP_ALIGN
+.BiosSizeIsNot8K:
 .SumNextByte:
 	add		al, [es:di]
+.NextChecksumByte:
 	inc		di
 	loop	.SumNextByte
 	neg		al
 	mov		[es:di], al
+	inc		cx
+	dec		ah
+	jnz		SHORT .NextChecksumByte
 
 	pop		dx
@@ -271,19 +286,20 @@
 ;		ES:DI:	Ptr to file buffer
 ;	Corrupts registers:
-;		AX
+;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 Buffers_GetIdeControllerCountToCX:
-	call	Buffers_GetFileBufferToESDI
-	mov		al, [es:di+ROMVARS.bIdeCnt]
-
-	; Limit controller count for lite mode
+	xor		cx, cx
+	call	Buffers_GetFileBufferToESDI
+	or		cl, [es:di+ROMVARS.bIdeCnt]
+	jnz		SHORT .LimitControllerCountForLiteMode
+	inc		cx				; Make sure there is at least one controller
+
+.LimitControllerCountForLiteMode:
 	test	BYTE [es:di+ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
 	jnz		SHORT .ReturnControllerCountInCX
-	MIN_U	al, MAX_LITE_MODE_CONTROLLERS
+	MIN_U	cl, MAX_LITE_MODE_CONTROLLERS
 
 .ReturnControllerCountInCX:
-	cbw		; A maximum of 127 controllers should be sufficient
-	xchg	cx, ax
 	ret
 
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm	(revision 589)
@@ -81,4 +81,5 @@
 	mov		cl, dl
 	eSHL_IM	ch, 1
+	eRCL_IM	dl, 1
 	ret
 
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/IdeAutodetect.asm	(revision 589)
@@ -56,5 +56,5 @@
 DetectMemoryMappedDeviceFromSegmentDX:
 	; *** 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
+	test	BYTE [di+ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE_ADVANCED
 	stc
 	jz		SHORT .NoIdeDeviceFound
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm	(revision 589)
@@ -76,19 +76,29 @@
 ALIGN JUMP_ALIGN
 Main_Start:
+	mov		ah, GET_DOS_VERSION
+	int		DOS_INTERRUPT_21h
+	cmp		al, 2
+	jae		SHORT .DosVersionIsOK
+	mov		dx, g_s$NotMinimumDosVersion
+	mov		ah, WRITE_STRING_TO_STANDARD_OUTPUT
+	int		DOS_INTERRUPT_21h
+	ret
+.DosVersionIsOK:
+
 	mov		ax, SCREEN_BACKGROUND_CHARACTER_AND_ATTRIBUTE
-	call	InitializeScreenWithBackgroudCharAndAttrInAX
+	call	InitializeScreenWithBackgroundCharAndAttrInAX
 
 	call	Main_InitializeCfgVars
 	call	MenuEvents_DisplayMenu
 	mov		ax, DOS_BACKGROUND_CHARACTER_AND_ATTRIBUTE
-	call	InitializeScreenWithBackgroudCharAndAttrInAX
+	call	InitializeScreenWithBackgroundCharAndAttrInAX
 
 	; Exit to DOS
-	mov 	ax, 4C00h			; Exit to DOS
-	int 	21h
+	mov 	ax, TERMINATE_WITH_RETURN_CODE<<8		; Errorlevel 0 in AL
+	int		DOS_INTERRUPT_21h
 
 
 ;--------------------------------------------------------------------
-; InitializeScreenWithBackgroudCharAndAttrInAX
+; InitializeScreenWithBackgroundCharAndAttrInAX
 ;	Parameters:
 ;		AL:		Background character
@@ -100,5 +110,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-InitializeScreenWithBackgroudCharAndAttrInAX:
+InitializeScreenWithBackgroundCharAndAttrInAX:
 	xchg	dx, ax
 	CALL_DISPLAY_LIBRARY InitializeDisplayContext	; Reset cursor etc
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuitemPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuitemPrint.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuitemPrint.asm	(revision 589)
@@ -156,4 +156,5 @@
 ; MenuitemPrint_WriteLookupValueStringToBufferInESDIfromUnshiftedItemInDSSI
 ; MenuitemPrint_WriteLookupValueStringToBufferInESDIfromShiftedItemInDSSI
+; MenuitemPrint_WriteLookupValueStringToBufferInESDIfromRawItemInDSSI
 ;	Parameters:
 ;		DS:SI:	Ptr to MENUITEM
@@ -177,5 +178,5 @@
 
 ;--------------------------------------------------------------------
-; MenuitemPrint_WriteLookupValueStringToBufferInESDIfromItemInDSSI
+; PrintLookupValueFromAXtoBufferInESDI
 ;	Parameters:
 ;		AX:		Value to print
@@ -190,12 +191,12 @@
 PrintLookupValueFromAXtoBufferInESDI:
 	push	si
-	test	byte [si+MENUITEM.bFlags], FLG_MENUITEM_CHOICESTRINGS
-	jnz		.lookupChoice
+	test	BYTE [si+MENUITEM.bFlags], FLG_MENUITEM_CHOICESTRINGS
+	jnz		SHORT .LookupChoice
 
 	add		ax, [si+MENUITEM.itemValue+ITEM_VALUE.rgszValueToStringLookup]
 	xchg	bx, ax
-.found:
+.Found:
 	mov		si, [bx]
-.errorReturn:
+.ErrorReturn:
 	call	String_CopyDSSItoESDIandGetLengthToCX
 	pop		si
@@ -212,20 +213,20 @@
 ; value could be zero, we don't use the .rgwChoiceToValueLookup array to find the end.
 ;
-.lookupChoice:
-	mov		bx,[si+MENUITEM.itemValue+ITEM_VALUE.rgszChoiceToStringLookup]
-	mov		si,[si+MENUITEM.itemValue+ITEM_VALUE.rgwChoiceToValueLookup]
-
-.wordLoop:
-	cmp		ax,[si]
-	jz		.found
+.LookupChoice:
+	mov		bx, [si+MENUITEM.itemValue+ITEM_VALUE.rgszChoiceToStringLookup]
+	mov		si, [si+MENUITEM.itemValue+ITEM_VALUE.rgwChoiceToValueLookup]
+
+.WordLoop:
+	cmp		ax, [si]
+	je		SHORT .Found
 	inc		bx
 	inc		bx
 	inc		si
 	inc		si
-	cmp		word [bx],0
-	jnz		.wordLoop
-
-	mov		si,g_szValueUnknownError
-	jmp		.errorReturn
+	cmp		WORD [bx], 0
+	jne		SHORT .WordLoop
+
+	mov		si, g_szValueUnknownError
+	jmp		SHORT .ErrorReturn
 
 ;--------------------------------------------------------------------
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/ConfigurationMenu.asm	(revision 589)
@@ -177,5 +177,6 @@
 		%assign i i+1
 	%endrep
-	;	dw	NULL	; Is this needed? *FIXME*
+		dw	NULL
+
 
 ; Section containing code
@@ -285,5 +286,5 @@
 	call	Buffers_GetRomvarsFlagsToAX
 	mov		bx, g_MenuitemConfigurationIdleTimeout
-	test	ax, FLG_ROMVARS_MODULE_POWER_MANAGEMENT
+	test	al, FLG_ROMVARS_MODULE_POWER_MANAGEMENT
 	jz		SHORT .DisableMenuitemFromCSBX
 	; Fall to .EnableMenuitemFromCSBX
@@ -393,7 +394,5 @@
 	push	es
 	pop		ds
-	xor		ch, ch						; clearing high order of CX and notification flag
-	mov		dx, cx						; (probably unnecessary, CX should be less than 127, but just to be sure)
-	jcxz	.done						; probably unnecessary, but make sure there is at least one controller
+	mov		dx, cx						; Controller count to DL (will always be at least 1) while also clearing notification flag in DH
 
 	lea		bx, [di+ROMVARS.ideVars0]	; add in offset of first idevars
@@ -404,12 +403,11 @@
 	xor		ax, ax						; first non-serial found
 	mov		cl, dl						; idevars count
-	xor		ch, ch
 
 .loop:
-	cmp		byte [di+IDEVARS.bDevice], DEVICE_SERIAL_PORT
-	jnz		.notSerial
+	cmp		BYTE [di+IDEVARS.bDevice], DEVICE_SERIAL_PORT
+	jne		SHORT .notSerial
 
 	test	si, si						; record the first serial controller that we find
-	jnz		.next
+	jnz		SHORT .next
 	mov		si, di
 	SKIP2B	f
@@ -423,7 +421,7 @@
 
 	test	si, si						; no serial drives, nothing to do
-	jz		.done
+	jz		SHORT .done
 	cmp		si, ax						; serial port is already later on the list than any other controllers
-	ja		.done						; (also takes care of the case where there are no other controllers)
+	ja		SHORT .done					; (also takes care of the case where there are no other controllers)
 
 ;
@@ -438,9 +436,14 @@
 	mov		di, sp
 
-	mov		cx, IDEVARS_size
 	push	ss
 	pop		es
 
+%if IDEVARS_size & 1
+	mov		cl, IDEVARS_size
 	rep	movsb
+%else
+	mov		cl, IDEVARS_size / 2
+	rep movsw
+%endif
 
 	lea		di, [si-IDEVARS_size]		; move up all the idevars below the serial, by one slot
@@ -457,8 +460,13 @@
 	push	ss
 	pop		ds
-	mov		cx, IDEVARS_size
 	; di is already at last IDEVARS position
 
+%if IDEVARS_size & 1
+	mov		cl, IDEVARS_size
 	rep	movsb
+%else
+	mov		cl, IDEVARS_size / 2
+	rep movsw
+%endif
 
 	add		sp, IDEVARS_size
@@ -469,5 +477,5 @@
 	mov		dh, 1						; set flag that we have done a relocation
 
-	jmp		.outerLoop
+	jmp		SHORT .outerLoop
 
 .done:
@@ -478,5 +486,5 @@
 
 	test	dh, dh
-	jz		.noWorkDone
+	jz		SHORT .noWorkDone
 
 	mov		dx, g_szSerialMoved
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm	(revision 589)
@@ -328,6 +328,6 @@
 	call	.GetSelectedEepromSizeInWordsToAX
 	xor		dx, dx
-	shl		ax, 1		; Size in bytes to...
-	rcl		dx, 1		; ...DX:AX
+	eSHL_IM	ax, 1		; Size in bytes to...
+	eRCL_IM	dx, 1		; ...DX:AX
 
 	cmp		WORD [si+FLASHVARS.wEepromPageSize], BYTE 1
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/IdeControllerMenu.asm	(revision 589)
@@ -571,8 +571,4 @@
 
 
-;
-; No change to Device byte, but use this opportunity to change defaults stored in wPort and wPortCtrl if we are
-; changing in/out of a Serial device (since we use these bytes in radically different ways).
-;
 ALIGN JUMP_ALIGN
 IdeControllerMenu_WriteDevice:
@@ -581,10 +577,71 @@
 	push	ax
 
+	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
+
 	; 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
+	shl		al, 1								; Selection to device code
+
+	; Restore ports and other stuff to default values
+	jz		SHORT .StandardIdeDevice			; DEVICE_16BIT_ATA
+
+	cmp		al, DEVICE_8BIT_ATA
+	ja		SHORT .NotStandardIdeDevice
+	jb		SHORT .AdvancedAtaDevice			; DEVICE_32BIT_ATA
+	test	BYTE [es:ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE
+	jmp		SHORT .CheckZF
+
+.AdvancedAtaDevice:
+	test	BYTE [es:ROMVARS.wFlags+1], FLG_ROMVARS_MODULE_ADVANCED_ATA >> 8
+.CheckZF:
+	jz		SHORT .SupportForDeviceNotAvailable
+
+	; Standard ATA controllers, including 8-bit mode
+.StandardIdeDevice:
+	lea		ax, [di-ROMVARS.ideVars0+IDEVARS.wBasePort]
+	mov		bl, IDEVARS_size
+	div		bl
+	mov		bx, .rgbLowByteOfStdIdeInterfacePorts
+	xlat
+	mov		ah, 1								; DEVICE_ATA_*_PORT >> 8
+	mov		bh, 3								; DEVICE_ATA_*_PORTCTRL >> 8
+	mov		bl, al
+	jmp		SHORT .WriteNonSerial
+
+.rgbLowByteOfStdIdeInterfacePorts:				; Defaults for 16-bit and better ATA devices
+	db		DEVICE_ATA_PRIMARY_PORT		& 0FFh
+	db		DEVICE_ATA_SECONDARY_PORT	& 0FFh
+	db		DEVICE_ATA_TERTIARY_PORT	& 0FFh
+	db		DEVICE_ATA_QUATERNARY_PORT	& 0FFh
+
+.NotStandardIdeDevice:
 	cmp		al, DEVICE_SERIAL_PORT
-	je		SHORT .ChangingToSerial
+	jb		SHORT .NotSerialDevice
+	test	BYTE [es:ROMVARS.wFlags+1], FLG_ROMVARS_MODULE_SERIAL >> 8
+	jnz		SHORT .ChangingToSerial
+
+.SupportForDeviceNotAvailable:
+	push	dx
+	mov		dx, g_szUnsupportedDevice
+	call	Dialogs_DisplayErrorFromCSDX
+	pop		dx
+
+	; Restore device type to the previous value
+	pop		ax									; Get choice index from stack
+	mov		al, bl								; Previous device type to AL
+	shr		al, 1								; Device code to choice index
+	jmp		SHORT .DoneWithNoChangeOfDevice
+
+.NotSerialDevice:
+	; Remaining device types all require MODULE_8BIT_IDE or MODULE_8BIT_IDE_ADVANCED
+	test	BYTE [es:ROMVARS.wFlags], FLG_ROMVARS_MODULE_8BIT_IDE | FLG_ROMVARS_MODULE_8BIT_IDE_ADVANCED
+	jz		SHORT .SupportForDeviceNotAvailable
+
+	; We know MODULE_8BIT_IDE is included
+	lahf	; Save the PF
+	cmp		al, DEVICE_8BIT_XTIDE_REV2
+	jbe		SHORT .ChangingToXTIDEorXTCF
+	sahf	; Restore the PF
+	jpo		SHORT .SupportForDeviceNotAvailable	; Jump if no MODULE_8BIT_IDE_ADVANCED
 	cmp		al, DEVICE_8BIT_JRIDE_ISA
 	je		SHORT .ChangingToJrIdeIsa
@@ -592,10 +649,5 @@
 	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
-
+.ChangingToXTIDEorXTCF:
 	mov		ax, DEVICE_XTIDE_DEFAULT_PORT		; Defaults for 8-bit XTIDE and XT-CF devices
 	mov		bx, DEVICE_XTIDE_DEFAULT_PORTCTRL
@@ -631,4 +683,5 @@
 .Done:
 	pop		ax
+.DoneWithNoChangeOfDevice:
 	pop		di			; IDEVARS.bDevice
 	pop		bx
Index: /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm	(revision 588)
+++ /trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm	(revision 589)
@@ -21,7 +21,10 @@
 SECTION .data
 
+; DOS version check
+g_s$NotMinimumDosVersion:			db	LF,"This program requires DOS version 2 or higher.",LF,"$"
+
 ; Menu title
 g_szProgramTitle:					db	"Configuration and Flashing program for XTIDE Universal BIOS v2.0.0.",LF,CR,NULL
-g_szXtideUniversalBiosSignature:	db	"XTIDE205",NULL
+g_szXtideUniversalBiosSignature:	db	FLASH_SIGNATURE,NULL
 g_szBiosIsNotLoaded:				db	"BIOS is not loaded!",NULL
 g_szEEPROM:							db	"EEPROM",NULL
@@ -134,5 +137,5 @@
 						db	" Conventional memory. This makes it possible to use ROM BASIC and other software that requires"
 						db	" the interrupt vectors where XTIDE Universal BIOS parameters would be stored in Lite mode.",LF,LF
-						db	"Lite mode supports only one IDE controller (2 drives) and stores parameters to the top of the interrupt vectors"
+						db	"Lite mode supports only 2 IDE controllers (4 drives) and stores parameters to the top of the interrupt vectors"
 						db	" (30:0h) so no Conventional memory needs to be reserved. Lite mode cannot be used if some software requires"
 						db	" the top of interrupt vectors. Usually this is not a problem since only IBM ROM BASIC uses them.",LF,LF
@@ -221,4 +224,6 @@
 g_szDlgIdeEnIRQ:			db	"Enable interrupt?",NULL
 g_szDlgIdeIRQ:				db	"Enter IRQ channel (2...7 for 8-bit controllers, 2...15 for any other controller).",NULL
+g_szUnsupportedDevice:		db	"There is no support for this device type in the currently loaded BIOS."
+							db	" You must load a BIOS built with the proper module included to be able to use this type of device.",NULL
 
 g_szNfoIdeBackToCfgMenu:	db	"Back to XTIDE Universal BIOS Configuration Menu.",NULL
@@ -275,7 +280,7 @@
 							db	"XTIDE rev 1",LF
 							db	"XTIDE rev 2 or modded rev 1",LF
-							db	"XT-CF (PIO8)",LF
-							db	"XT-CF (PIO8 w/BIU offload)",LF
-							db	"XT-CF (PIO16 w/BIU offload)",LF
+							db	"XT-CF PIO8",LF
+							db	"XT-CF PIO8 (BIU offload)",LF
+							db	"XT-CF PIO16 (BIU offload)",LF
 							db	"XT-CF DMA (v3 only)",LF
 							db	"JR-IDE/ISA",LF
