Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 537)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeTransfer.asm	(revision 538)
@@ -78,4 +78,7 @@
 	mov		bx, g_rgfnPioRead
 	call	InitializePiovarsInSSBPwithSectorCountInAH
+%ifdef USE_AT
+	jc		SHORT ReturnWithTransferErrorInAH
+%endif
 
 	; Wait until drive is ready to transfer
@@ -154,4 +157,7 @@
 	mov		bx, g_rgfnPioWrite
 	call	InitializePiovarsInSSBPwithSectorCountInAH
+%ifdef USE_AT
+	jc		SHORT ReturnWithTransferErrorInAH
+%endif
 
 	; Always poll when writing first block (IRQs are generated for following blocks)
@@ -201,7 +207,10 @@
 ;		SS:BP:	Ptr to PIOVARS
 ;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, DX
+;		ES:SI:	Normalized pointer
+;		AH:		INT 13h Error Code (only when CF set)
+;		CF:		Set of failed to normalize pointer (segment overflow)
+;				Cleared if success
+;	Corrupts registers:
+;		AL, BX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -209,4 +218,7 @@
 	; Store sizes and Data Port
 	mov		[bp+PIOVARS.bSectorsLeft], ah
+%ifdef USE_AT
+	xchg	dx, ax
+%endif
 	mov		ax, [di+DPT.wBasePort]
 	mov		[bp+PIOVARS.wDataPort], ax
@@ -280,4 +292,5 @@
 	;------------------------------------
 %endif					; 26	29/26
+	clc
 	ret
 %endif ; MODULE_8BIT_IDE_ADVANCED
@@ -288,13 +301,37 @@
 ; IdeTransfer_NormalizePointerInESSI
 ;	Parameters:
+;		DH:		Number of sectors to transfer (when USE_AT defined)
 ;		ES:SI:	Ptr to be normalized
 ;	Returns:
 ;		ES:SI:	Normalized pointer (SI = 0...15)
+;		AH:		INT 13h Error Code (only when CF set)
+;		CF:		Set of failed to normalize pointer (segment overflow)
+;				Cleared if success
 ;	Corrupts registers:
 ;		AX, DX
 ;--------------------------------------------------------------------
 IdeTransfer_NormalizePointerInESSI:
+; Normalization can cause segment overflow if it is done when not needed
+; (I don't know if any software calls with such seg:off address).
+; This does not apply to XT systems since nothing will write to main BIOS ROM.
+; On AT systems things are quite different, even in protected mode the address
+; is passed in seg:offset form and HMA is accessible in real mode.
+%ifdef USE_AT
+	xor		dl, dl
+	shl		dx, 1
+	dec		dx		; Prevents normalization when bytes + offset will be zero
+	add		dx, si
+	jc		SHORT .NormalizationRequired
+	ret
+.NormalizationRequired:
+%endif ; USE_AT
+
 	NORMALIZE_FAR_POINTER	es, si, ax, dx
-	ret
+%ifdef USE_AT		; CF is always clear for XT builds
+	mov		ah, 0	; Clear AH and preserve CF
+	rcl		ah, 1	; RET_HD_INVALID
+%endif
+	ret
+
 
 
Index: trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 537)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/IDE/JrIdeTransfer.asm	(revision 538)
@@ -53,6 +53,6 @@
 	xor		ax, ax
 	mov		[bp+MEMPIOVARS.bSectorsDone], al
-	mov		al, [bp+IDEPACK.bSectorCount]
-	mov		[bp+MEMPIOVARS.bSectorsLeft], al
+	mov		dh, [bp+IDEPACK.bSectorCount]
+	mov		[bp+MEMPIOVARS.bSectorsLeft], dh
 	mov		al, [di+DPT_ATA.bBlockSize]
 	mov		[bp+MEMPIOVARS.wSectorsInBlock], ax
@@ -62,4 +62,7 @@
 	; Normalize pointer
 	call	IdeTransfer_NormalizePointerInESSI
+%ifdef USE_AT
+	jc		SHORT ReturnWithMemoryIOtransferErrorInAH
+%endif
 
 	; Get far pointer to Sector Access Window
Index: trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm	(revision 537)
+++ trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm	(revision 538)
@@ -62,5 +62,14 @@
 .readOrWrite:
 		mov		[bp+IDEPACK.bFeatures],ah		; store protocol command
+%ifdef USE_AT
+		mov		dh, [bp+IDEPACK.bSectorCount]
+%endif
 		call	IdeTransfer_NormalizePointerInESSI
+%ifdef USE_AT
+		jnc		SHORT .PointerNormalizationWasSuccessfull
+		xor		cx, cx			; Nothing transferred
+		jmp		SerialCommand_ReturnError
+.PointerNormalizationWasSuccessfull:
+%endif
 
 		mov		dx, [di+DPT_SERIAL.wSerialPortAndBaud]
