Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 150)
@@ -22,5 +22,6 @@
 Int13h_DiskFunctionsHandler:
 	sti									; Enable interrupts
-	SAVE_AND_GET_INTPACK_TO_SSBP
+	cld									; String instructions to increment pointers
+	SAVE_AND_GET_INTPACK_WITH_EXTRA_WORDS_TO_SSBP EXTRA_WORDS_TO_RESERVE_FOR_INTPACK
 
 	call	RamVars_GetSegmentToDS
@@ -46,5 +47,5 @@
 ;		DL:		Translated drive number
 ;		DS:		RAMVARS segment
-;		SS:BP:	Ptr to INTPACK
+;		SS:BP:	Ptr to IDEPACK
 ;		BX, DI:	Corrupted on Int13h_DiskFunctionsHandler
 ;		Other:	Function specific INT 13h parameters 
@@ -58,11 +59,11 @@
 Int13h_DirectCallToAnotherBios:
 	call	ExchangeCurrentInt13hHandlerWithOldInt13hHandler
-	mov		bx, [bp+INTPACK.bx]
-	mov		di, [bp+INTPACK.di]
-	mov		ds, [bp+INTPACK.ds]
-	push	WORD [bp+INTPACK.flags]
+	mov		bx, [bp+IDEPACK.intpack+INTPACK.bx]
+	mov		di, [bp+IDEPACK.intpack+INTPACK.di]
+	mov		ds, [bp+IDEPACK.intpack+INTPACK.ds]
+	push	WORD [bp+IDEPACK.intpack+INTPACK.flags]
 	popf
 	push	bp
-	mov		bp, [bp+INTPACK.bp]
+	mov		bp, [bp+IDEPACK.intpack+INTPACK.bp]
 	int		BIOS_DISK_INTERRUPT_13h	; Can safely do as much recursion as it wants
 
@@ -70,21 +71,21 @@
 	pop		bp	; Standard INT 13h functions never uses BP as return register
 %ifdef USE_386
-	mov		[bp+INTPACK.gs], gs
-	mov		[bp+INTPACK.fs], fs
+	mov		[bp+IDEPACK.intpack+INTPACK.gs], gs
+	mov		[bp+IDEPACK.intpack+INTPACK.fs], fs
 %endif
-	mov		[bp+INTPACK.es], es
-	mov		[bp+INTPACK.ds], ds
-	mov		[bp+INTPACK.di], di
-	mov		[bp+INTPACK.si], si
-	mov		[bp+INTPACK.bx], bx
-	mov		[bp+INTPACK.dh], dh
-	mov		[bp+INTPACK.cx], cx
-	mov		[bp+INTPACK.ax], ax
+	mov		[bp+IDEPACK.intpack+INTPACK.es], es
+	mov		[bp+IDEPACK.intpack+INTPACK.ds], ds
+	mov		[bp+IDEPACK.intpack+INTPACK.di], di
+	mov		[bp+IDEPACK.intpack+INTPACK.si], si
+	mov		[bp+IDEPACK.intpack+INTPACK.bx], bx
+	mov		[bp+IDEPACK.intpack+INTPACK.dh], dh
+	mov		[bp+IDEPACK.intpack+INTPACK.cx], cx
+	mov		[bp+IDEPACK.intpack+INTPACK.ax], ax
 	pushf
-	pop		WORD [bp+INTPACK.flags]
+	pop		WORD [bp+IDEPACK.intpack+INTPACK.flags]
 	call	RamVars_GetSegmentToDS
 	cmp		dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]
 	je		SHORT .ExchangeInt13hHandlers
-	mov		[bp+INTPACK.dl], dl		; Something is returned in DL
+	mov		[bp+IDEPACK.intpack+INTPACK.dl], dl		; Something is returned in DL
 ALIGN JUMP_ALIGN
 .ExchangeInt13hHandlers:
@@ -98,5 +99,5 @@
 ;	Parameters:
 ;		AH:		BIOS Error code
-;		SS:BP:	Ptr to INTPACK
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		All registers are loaded from INTPACK
@@ -104,9 +105,9 @@
 ALIGN JUMP_ALIGN
 Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
-	call	HError_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
+	call	Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
 Int13h_ReturnFromHandlerWithoutStoringErrorCode:
-	or		WORD [bp+INTPACK.flags], FLG_FLAGS_IF	; Return with interrupts enabled
+	or		WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF	; Return with interrupts enabled
 	mov		sp, bp									; Now we can exit anytime
-	RESTORE_INTPACK_FROM_SSBP
+	RESTORE_INTPACK_WITH_EXTRA_WORDS_FROM_SSBP EXTRA_WORDS_TO_RESERVE_FOR_INTPACK
 
 
@@ -146,4 +147,5 @@
 	LOAD_BDA_SEGMENT_TO	es, di
 	mov		di, [RAMVARS.fpOldI13h]
+	cli
 	xchg	di, [es:BIOS_DISK_INTERRUPT_13h*4]
 	mov		[RAMVARS.fpOldI13h], di
@@ -152,4 +154,34 @@
 	mov		[RAMVARS.fpOldI13h+2], di
 	pop		es
+	sti
+	ret
+
+
+;--------------------------------------------------------------------
+; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
+; Int13h_SetErrorCodeToIntpackInSSBPfromAH
+;	Parameters:
+;		AH:		BIOS error code (00h = no error)
+;		SS:BP:	Ptr to IDEPACK
+;	Returns:
+;		SS:BP:	Ptr to IDEPACK with error condition set
+;	Corrupts registers:
+;		DS, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
+	; Store error code to BDA
+	LOAD_BDA_SEGMENT_TO	ds, di
+	mov		[BDA.bHDLastSt], ah
+
+	; Store error code to INTPACK
+Int13h_SetErrorCodeToIntpackInSSBPfromAH:
+	mov		[bp+IDEPACK.intpack+INTPACK.ah], ah
+	test	ah, ah
+	jnz		SHORT .SetCFtoIntpack
+	and		BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
+	ret
+.SetCFtoIntpack:
+	or		BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
 	ret
 
@@ -224,16 +256,20 @@
 ;	dw	Int13h_UnsupportedFunction						; 3Fh, 
 ;	dw	Int13h_UnsupportedFunction						; 40h, 
-;	dw	Int13h_UnsupportedFunction						; 41h, Check if Extensions Present (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 42h, Extended Read Sectors (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 43h, Extended Write Sectors (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 44h, Extended Verify Sectors (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 45h, Lock and Unlock Drive (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 46h, Eject Media Request (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 47h, Extended Seek (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 48h, Get Extended Drive Parameters (EBIOS)
-;	dw	Int13h_UnsupportedFunction						; 49h, Get Extended Disk Change Status (EBIOS)
+;	dw	Int13h_UnsupportedFunction						; 41h, Check if Extensions Present (EBIOS)*
+;	dw	Int13h_UnsupportedFunction						; 42h, Extended Read Sectors (EBIOS)*
+;	dw	Int13h_UnsupportedFunction						; 43h, Extended Write Sectors (EBIOS)*
+;	dw	Int13h_UnsupportedFunction						; 44h, Extended Verify Sectors (EBIOS)*
+;	dw	Int13h_UnsupportedFunction						; 45h, Lock and Unlock Drive (EBIOS)***
+;	dw	Int13h_UnsupportedFunction						; 46h, Eject Media Request (EBIOS)***
+;	dw	Int13h_UnsupportedFunction						; 47h, Extended Seek (EBIOS)*
+;	dw	Int13h_UnsupportedFunction						; 48h, Get Extended Drive Parameters (EBIOS)*
+;	dw	Int13h_UnsupportedFunction						; 49h, Get Extended Disk Change Status (EBIOS)***
 ;	dw	Int13h_UnsupportedFunction						; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
 ;	dw	Int13h_UnsupportedFunction						; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
 ;	dw	Int13h_UnsupportedFunction						; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
 ;	dw	Int13h_UnsupportedFunction						; 4Dh, Return Boot Catalog (Bootable CD-ROM)
-;	dw	Int13h_UnsupportedFunction						; 4Eh, Set Hardware Configuration (EBIOS)
+;	dw	Int13h_UnsupportedFunction						; 4Eh, Set Hardware Configuration (EBIOS)**
+;
+;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
+;  ** = Enhanced Disk Drive (EDD) Support
+; *** = Drive Locking and Ejecting Support
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 150)
@@ -13,6 +13,6 @@
 ;				If bit 7 is set all hard disks and floppy disks reset.
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status (from drive requested in DL)
 ;		CF:		0 if succesfull, 1 if error
@@ -89,12 +89,13 @@
 
 ;--------------------------------------------------------------------
-; ResetHardDisksHandledByOurBIOS
+; AH0h_ResetHardDisksHandledByOurBIOS
 ;	Parameters:
 ;		BL:		Requested drive (DL when entering AH=00h)
 ;		DS:		RAMVARS segment
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		BH:		Error code from requested drive (if available)
 ;	Corrupts registers:
-;		AX, CX, DX, DI
+;		AX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -103,5 +104,5 @@
 	test	dh, dh
 	jz		SHORT .AllDrivesReset		; Return if no drives
-	mov		dl, [RAMVARS.bFirstDrv]		; Load number of first our drive
+	mov		dl, [RAMVARS.bFirstDrv]		; Load number of our first drive
 	add		dh, dl						; DH = one past last drive to reset
 ALIGN JUMP_ALIGN
@@ -132,13 +133,37 @@
 .BackupErrorCodeFromMasterOrSlaveToBH:
 	call	BackupErrorCodeFromTheRequestedDriveToBH
-	mov		cx, [RAMVARS.wIdeBase]		; Load base port for resetted drive
-
+	call	GetBasePortToCX				; Load base port for resetted drive
+	push	cx
 	inc		dx							; DL to next drive
-	call	FindDPT_ForDriveNumber		; Get DPT to DS:DI, store port to RAMVARS
-	jnc		SHORT .NoMoreDrivesOrNoSlaveDrive
-	cmp		cx, [RAMVARS.wIdeBase]		; Next drive is from same controller?
+	call	GetBasePortToCX
+	pop		di
+	cmp		cx, di						; Next drive is from same controller?
 	je		SHORT BackupErrorCodeFromTheRequestedDriveToBH
 .NoMoreDrivesOrNoSlaveDrive:
 	dec		dx
+	ret
+
+;--------------------------------------------------------------------
+; GetBasePortToCX
+;	Parameters:
+;		DL:		Drive number
+;		DS:		RAMVARS segment
+;	Returns:
+;		CX:		Base port address
+;		CF:		Set if valid drive number
+;				Cleared if invalid drive number
+;	Corrupts registers:
+;		DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+GetBasePortToCX:
+	xchg	cx, bx
+	xor		bx, bx
+	call	FindDPT_ForDriveNumber
+	jnc		SHORT .DptNotFound
+	mov		bl, [di+DPT.bIdevarsOffset]
+	mov		bx, [cs:bx+IDEVARS.wPort]
+.DptNotFound:
+	xchg	bx, cx
 	ret
 
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH10h_HReady.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH10h_HReady.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH10h_HReady.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
@@ -19,5 +19,9 @@
 ALIGN JUMP_ALIGN
 AH10h_HandlerForCheckDriveReady:
-	call	HStatus_WaitRdyDefTime
-	xor		ah, ah
+%ifdef USE_186
+	push	Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	jmp		Device_SelectDrive
+%else
+	call	Device_SelectDrive
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH11h_HRecal.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH11h_HRecal.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH11h_HRecal.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
+;	Returns with INTPACK:
 ;		AH:		BIOS Error code
 ;		CF:		0 if succesfull, 1 if error
@@ -32,4 +32,5 @@
 ;	Parameters:
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
 ;	Returns:
 ;		AH:		BIOS Error code
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH15h_HSize.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH15h_HSize.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH15h_HSize.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Returns with INTPACK:
 ;		If succesfull:
 ;			AH:		3 (Hard disk accessible)
@@ -25,10 +25,45 @@
 ALIGN JUMP_ALIGN
 AH15h_HandlerForReadDiskDriveSize:
-	call	HCapacity_GetSectorCountFromOurAH08h		; Sector count to DX:AX
-	mov		[bp+INTPACK.cx], dx							; HIWORD to CX
-	mov		[bp+INTPACK.dx], ax							; LOWORD to DX
+	call	AH15h_GetSectorCountToDXAX
+	mov		[bp+IDEPACK.intpack+INTPACK.cx], dx			; HIWORD to CX
+	mov		[bp+IDEPACK.intpack+INTPACK.dx], ax			; LOWORD to DX
 
 	xor		ah, ah
-	call	HError_SetErrorCodeToIntpackInSSBPfromAH	; Store success to BDA and CF
-	mov		BYTE [bp+INTPACK.ah], 3						; Type code = Hard disk
+	call	Int13h_SetErrorCodeToIntpackInSSBPfromAH	; Store success to BDA and CF
+	mov		BYTE [bp+IDEPACK.intpack+INTPACK.ah], 3		; Type code = Hard disk
 	jmp		Int13h_ReturnFromHandlerWithoutStoringErrorCode
+
+
+;--------------------------------------------------------------------
+; AH15h_GetSectorCountFromForeignDriveToDXAX:
+; AH15h_GetSectorCountToDXAX:
+;	Parameters:
+;		DL:		Drive number
+;		DS:		RAMVARS segment
+;		DS:DI:	Ptr to DPT (AH15h_GetSectorCount only)
+;	Returns:
+;		DX:AX:	Total sector count
+;		BX:		Zero
+;	Corrupts registers:
+;		CX
+;--------------------------------------------------------------------
+AH15h_GetSectorCountFromForeignDriveToDXAX:
+	mov		ah, GET_DRIVE_PARAMETERS
+	call	Int13h_CallPreviousInt13hHandler
+	jmp		SHORT ConvertAH08hReturnValuesToSectorCount
+
+ALIGN JUMP_ALIGN
+AH15h_GetSectorCountToDXAX:
+	call	AH8h_GetDriveParameters
+	; Fall to ConvertAH08hReturnValuesToSectorCount
+
+ConvertAH08hReturnValuesToSectorCount:
+	call	HAddress_ExtractLCHSparametersFromOldInt13hAddress
+	xor		ax, ax			; Zero AX
+	inc		cx				; Max cylinder number to cylinder count
+	xchg	al, bh			; AX=Max head number, BX=Sectors per track
+	inc		ax				; AX=Head count
+	mul		bx				; AX=Head count * Sectors per track
+	mul		cx				; DX:AX = Total sector count
+	xor		bx, bx			; Zero BX for 48-bit sector count (and clear CF)
+	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1h_HStatus.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1h_HStatus.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH1h_HStatus.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
+;	Returns with INTPACK:
 ;		AH:		Int 13h floppy return status
 ;		CF:		0 if AH = RET_HD_SUCCESS, 1 otherwise (error)
@@ -21,4 +21,4 @@
 	LOAD_BDA_SEGMENT_TO	ds, ax, !
 	xchg	ah, [BDA.bHDLastSt]		; Load and clear last error
-	call	HError_SetErrorCodeToIntpackInSSBPfromAH
+	call	Int13h_SetErrorCodeToIntpackInSSBPfromAH
 	jmp		Int13h_ReturnFromHandlerWithoutStoringErrorCode
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH23h_HFeatures.asm	(revision 150)
@@ -14,13 +14,13 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Parameters on INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Parameters on INTPACK:
 ;		AL:		Feature Number (parameter to Features Register = subcommand)
-;	(Parameter registers are undocumented, there are specific for this BIOS):
-;		BH:		Parameter to Sector Count Register (subcommand specific)
-;		BL:		Parameter to Sector Number Register (subcommand specific)
-;		CL:		Parameter to Low Cylinder Register (subcommand specific)
-;		CH:		Parameter to High Cylinder Register (subcommand specific)
-;	Returns with INTPACK in SS:BP:
+;	(Parameter registers are undocumented, these are specific for this BIOS):
+;		BL:		Parameter to Sector Count Register (subcommand specific)
+;		BH:		Parameter to LBA Low / Sector Number Register (subcommand specific)
+;		CL:		Parameter to LBA Middle / Cylinder Low Register (subcommand specific)
+;		CH:		Parameter to LBA High / Cylinder High Register (subcommand specific)
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
@@ -28,4 +28,6 @@
 ALIGN JUMP_ALIGN
 AH23h_HandlerForSetControllerFeatures:
+	xchg	si, ax		; SI = Feature Number
+	mov		dx, [bp+IDEPACK.intpack+INTPACK.bx]
 %ifndef USE_186
 	call	AH23h_SetControllerFeatures
@@ -40,44 +42,20 @@
 ; AH23h_SetControllerFeatures
 ;	Parameters:
-;		AL:		Feature Number (parameter to Features Register = subcommand)
-;		BH:		Parameter to Sector Count Register (subcommand specific)
-;		BL:		Parameter to Sector Number Register (subcommand specific)
-;		CL:		Parameter to Low Cylinder Register (subcommand specific)
-;		CH:		Parameter to High Cylinder Register (subcommand specific)
+;		DL:		Parameter to Sector Count Register (subcommand specific)
+;		DH:		Parameter to LBA Low / Sector Number Register (subcommand specific)
+;		CL:		Parameter to LBA Middle / Cylinder Low Register (subcommand specific)
+;		CH:		Parameter to LBA High / Cylinder High Register (subcommand specific)
+;		SI:		Feature Number (parameter to Features Register = subcommand)
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
 ;	Corrupts registers:
-;		AX, BX, CX, DX, SI
+;		AL, BX, CX, DX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 AH23h_SetControllerFeatures:
-	; Backup AL and BH to SI
-	mov		ah, bh
-	xchg	si, ax
-
-	; Select Master or Slave and wait until ready
-	call	HDrvSel_SelectDriveAndDisableIRQ
-	jc		SHORT .ReturnWithErrorCodeInAH
-
-	; Output Feature Number
-	mov		ax, si						; Feature number to AL
-	mov		dx, [RAMVARS.wIdeBase]		; Load base port address
-	inc		dx							; REGW_IDE_FEAT
-	out		dx, al
-
-	; Output parameters to Sector Number Register and Cylinder Registers
-	xor		bh, bh						; Zero head number
-	dec		dx							; Back to base port address
-	call	HCommand_OutputTranslatedLCHSaddress
-
-	; Output parameter to Sector Count Register and command
-	xchg	ax, si						; Sector Count Reg param to AH
-	mov		al, ah						; Sector Count Reg param to AL
-	mov		ah, HCMD_SET_FEAT			; Load Set Features command to AH
-	call	HCommand_OutputSectorCountAndCommand
-
-	jmp		HStatus_WaitBsyDefTime		; Wait until drive ready
-.ReturnWithErrorCodeInAH:
-	ret
+	mov		al, COMMAND_SET_FEATURES
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
+	jmp		Idepack_StoreNonExtParametersAndIssueCommandFromAL
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH24h_HSetBlocks.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH24h_HSetBlocks.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH24h_HSetBlocks.asm	(revision 150)
@@ -13,8 +13,8 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Parameters on INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Parameters on INTPACK:
 ;		AL:		Number of Sectors per Block (1, 2, 4, 8, 16, 32, 64 or 128)
-;	Returns with INTPACK in SS:BP:
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
@@ -22,4 +22,12 @@
 ALIGN JUMP_ALIGN
 AH24h_HandlerForSetMultipleBlocks:
+	test	WORD [di+DPT.wFlags], FLG_DPT_BLOCK_MODE_SUPPORTED
+	jnz		SHORT .TryToSetBlockMode
+	stc
+	mov		ah, RET_HD_INVALID
+	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+
+ALIGN JUMP_ALIGN
+.TryToSetBlockMode:
 %ifndef USE_186
 	call	AH24h_SetBlockSize
@@ -32,10 +40,9 @@
 
 ;--------------------------------------------------------------------
-; Sets block size for block mode transfers.
-;
 ; AH24h_SetBlockSize
 ;	Parameters:
 ;		AL:		Number of Sectors per Block (1, 2, 4, 8, 16, 32, 64 or 128)
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		AH:		Int 13h return status
@@ -46,24 +53,17 @@
 ALIGN JUMP_ALIGN
 AH24h_SetBlockSize:
-	; Select Master or Slave and wait until ready
-	mov		bl, al								; Backup block size
-	call	HDrvSel_SelectDriveAndDisableIRQ	; Select drive and wait until ready
-	jc		SHORT .ReturnWithErrorCodeInAH		; Return if error
-
-	; Output block size and command
-	mov		al, bl								; Restore block size to AL
-	mov		ah, HCMD_SET_MUL					; Load command to AH
-	mov		dx, [RAMVARS.wIdeBase]				; Load base port address
-	add		dx, BYTE REG_IDE_CNT
-	call	HCommand_OutputSectorCountAndCommand
-	call	HStatus_WaitBsyDefTime				; Wait until drive not busy
+	MIN_U	al, MAX_SUPPORTED_BLOCK_SIZE_IN_SECTORS
+	push	ax
+	xchg	dx, ax			; DL = Block size (Sector Count Register)
+	mov		al, COMMAND_SET_MULTIPLE_MODE
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRDY, FLG_STATUS_DRDY)
+	call	Idepack_StoreNonExtParametersAndIssueCommandFromAL
+	pop		bx
 	jc		SHORT .DisableBlockMode
 
 	; Store new block size to DPT and return
-	mov		[di+DPT.bSetBlock], bl				; Store new block size
-	xor		ah, ah								; Zero AH and CF since success
+	mov		[di+DPT_ATA.bSetBlock], bl				; Store new block size
 	ret
 .DisableBlockMode:
-	mov		BYTE [di+DPT.bSetBlock], 1			; Disable block mode
-.ReturnWithErrorCodeInAH:
+	mov		BYTE [di+DPT_ATA.bSetBlock], 1			; Disable block mode
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH25h_HDrvID.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH25h_HDrvID.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH25h_HDrvID.asm	(revision 150)
@@ -13,8 +13,8 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Parameters on INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Parameters on INTPACK:
 ;		ES:BX:	Ptr to buffer to receive 512-byte drive information
-;	Returns with INTPACK in SS:BP:
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
@@ -22,77 +22,13 @@
 ALIGN JUMP_ALIGN
 AH25h_HandlerForGetDriveInformation:
-	; Wait until previously selected drive is ready
-	call	HDrvSel_SelectDriveAndDisableIRQ
-	jc		SHORT .ReturnWithErrorCodeInAH		; Return if error
+	push	bp
 
-	; Get drive information
-	mov		bx, [bp+INTPACK.bx]
-	call	HPIO_NormalizeDataPointer
-	push	bx
-	mov		dx, [RAMVARS.wIdeBase]		; Load base port address
-	eMOVZX	bx, BYTE [di+DPT.bIdeOff]	; Load offset to IDEVARS
-	mov		bl, [cs:bx+IDEVARS.bBusType]; Load bus type to BL
-	mov		bh, [di+DPT.bDrvSel]		; Load drive sel byte to BH
-	pop		di							; Pop buffer offset to DI
-	call	AH25h_GetDriveInfo			; Get drive information
-.ReturnWithErrorCodeInAH:
+	mov		si, [bp+IDEPACK.intpack+INTPACK.bx]
+	call	AccessDPT_GetDriveSelectByteToAL
+	mov		bh, al
+	eMOVZX	ax, BYTE [di+DPT.bIdevarsOffset]
+	xchg	bp, ax
+	call	Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
+
+	pop		bp
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
-
-
-;--------------------------------------------------------------------
-; Gets drive information using Identify Device command.
-;
-; AH25h_GetDriveInfo
-;	Parameters:
-;		BH:		Drive Select byte for Drive and Head Select Register
-;		BL:		Bus type
-;		DX:		IDE Controller base port address
-;		DS:		Segment to RAMVARS
-;		ES:DI:	Ptr to buffer to receive 512 byte drive information
-;	Returns:
-;		AH:		Int 13h return status (will be stored to BDA)
-;		CF:		0 if succesfull, 1 if error
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AH25h_GetDriveInfo:
-	push	di
-	push	dx
-	push	bx
-
-	; Select Master or Slave drive.
-	; DO NOT WAIT UNTIL CURRENTLY SELECTED IS READY!
-	; It makes slave drive detection impossible if master is not present.
-	mov		[RAMVARS.wIdeBase], dx		; Store IDE Base port to RAMVARS
-	add		dx, BYTE REG_IDE_DRVHD		; DX to Drive and Head Sel Register
-	mov		al, bh						; Drive Select byte to AL
-	out		dx, al						; Select Master or Slave drive
-	sub		dx, BYTE REG_IDE_DRVHD		; Back to IDE Base port
-
-	; Wait until ready to accept commands
-	xor		bh, bh						; BX now contains bus type
-	mov		cl, B_TIMEOUT_DRVINFO		; Load short timeout
-	cmp		[RAMVARS.bDrvCnt], bh		; Detecting first drive?
-	eCMOVE	cl, B_TIMEOUT_RESET			;  If so, load long timeout
-	call	HStatus_WaitRdy				; Wait until ready to accept commands
-	jc		SHORT .ReturnWithErrorCodeInAH
-
-	; Output command
-	mov		al, HCMD_ID_DEV				; Load Identify Device command to AL
-	out		dx, al						; Output command
-	call	HStatus_WaitDrqDefTime		; Wait until ready to transfer (no IRQ!)
-	jc		SHORT .ReturnWithErrorCodeInAH
-
-	; Transfer data
-	sub		dx, BYTE REGR_IDE_ST		; DX to IDE Data Reg
-	mov		cx, 256						; Transfer 256 words (single sector)
-	cld									; INSW to increment DI
-	call	[cs:bx+g_rgfnPioRead]		; Read ID sector
-	call	HStatus_WaitRdyDefTime		; Wait until drive ready
-
-.ReturnWithErrorCodeInAH:
-	pop		bx
-	pop		dx
-	pop		di
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH2h_HRead.asm	(revision 150)
@@ -13,7 +13,7 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Parameters on INTPACK in SS:BP:
-;		AL:		Number of sectors to read (1...255)
+;		SS:BP:	Ptr to IDEPACK
+;	Parameters on INTPACK:
+;		AL:		Number of sectors to read (1...255, 0=256)
 ;		CH:		Cylinder number, bits 7...0
 ;		CL:		Bits 7...6: Cylinder number bits 9 and 8
@@ -21,5 +21,5 @@
 ;		DH:		Starting head number (0...255)
 ;		ES:BX:	Pointer to buffer recieving data
-;	Returns with INTPACK in SS:BP:
+;	Returns with INTPACK:
 ;		AH:		Int 13h/40h floppy return status
 ;		AL:		Burst error length if AH returns 11h, undefined otherwise
@@ -28,22 +28,14 @@
 ALIGN JUMP_ALIGN
 AH2h_HandlerForReadDiskSectors:
-	test	al, al						; Invalid sector count?
-	jz		SHORT AH2h_ZeroCntErr		;  If so, return with error
-
-	; Select sector or block mode command
-	mov		ah, HCMD_READ_SECT			; Load sector mode command
-	cmp		BYTE [di+DPT.bSetBlock], 1	; Block mode enabled?
-	eCMOVA	ah, HCMD_READ_MUL			; Load block mode command
-
-	; Transfer data
-	call	HCommand_OutputCountAndLCHSandCommand
-	jc		SHORT .ReturnWithErrorCodeInAH
-	mov		bx, [bp+INTPACK.bx]
-	call	HPIO_ReadBlock				; Read data from IDE-controller
-.ReturnWithErrorCodeInAH:
+	mov		ah, COMMAND_READ_SECTORS	; Load sector mode command
+	test	WORD [di+DPT.wFlags], FLG_DPT_BLOCK_MODE_SUPPORTED
+	eCMOVNZ	ah, COMMAND_READ_MULTIPLE	; Load block mode command
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
+	mov		si, [bp+IDEPACK.intpack+INTPACK.bx]
+%ifdef USE_186
+	push	Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	jmp		Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
+%else
+	call	Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
-
-; Invalid sector count (also for AH=3h and AH=4h)
-AH2h_ZeroCntErr:
-	mov		ah, RET_HD_INVALID			; Invalid value passed
-	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH3h_HWrite.asm	(revision 150)
@@ -13,6 +13,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Parameters on INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
+;	Parameters on INTPACK:
 ;		AL:		Number of sectors to write
 ;		CH:		Cylinder number, bits 7...0
@@ -21,5 +21,5 @@
 ;		DH:		Starting head number (0...255)
 ;		ES:BX:	Pointer to source data
-;	Returns with INTPACK in SS:BP:
+;	Returns with INTPACK:
 ;		AH:		Int 13h/40h floppy return status
 ;		CF:		0 if successfull, 1 if error
@@ -27,17 +27,15 @@
 ALIGN JUMP_ALIGN
 AH3h_HandlerForWriteDiskSectors:
-	test	al, al						; Invalid sector count?
-	jz		SHORT AH2h_ZeroCntErr		;  If so, return with error
-
-	; Select sector or block mode command
-	mov		ah, HCMD_WRITE_SECT			; Load sector mode command
-	cmp		BYTE [di+DPT.bSetBlock], 1	; Block mode enabled?
-	eCMOVA	ah, HCMD_WRITE_MUL			; Load block mode command
-
-	; Transfer data
-	call	HCommand_OutputCountAndLCHSandCommand
-	jc		SHORT .ReturnWithErrorCodeInAH
-	mov		bx, [bp+INTPACK.bx]
-	call	HPIO_WriteBlock				; Write data to IDE-controller
-.ReturnWithErrorCodeInAH:
+	; Prepare parameters
+	mov		ah, COMMAND_WRITE_SECTORS	; Load sector mode command
+	test	WORD [di+DPT.wFlags], FLG_DPT_BLOCK_MODE_SUPPORTED
+	eCMOVNZ	ah, COMMAND_WRITE_MULTIPLE	; Load block mode command
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRQ)
+	mov		si, [bp+IDEPACK.intpack+INTPACK.bx]
+%ifdef USE_186
+	push	Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	jmp		Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
+%else
+	call	Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH4h_HVerify.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH4h_HVerify.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH4h_HVerify.asm	(revision 150)
@@ -26,12 +26,11 @@
 ALIGN JUMP_ALIGN
 AH4h_HandlerForVerifyDiskSectors:
-	test	al, al						; Invalid sector count?
-	jz		SHORT AH2h_ZeroCntErr		;  If so, return with error
-
-	mov		ah, HCMD_VERIFY_SECT		; Load command to AH
-	call	HCommand_OutputCountAndLCHSandCommand
-	jc		SHORT .ReturnWithErrorCodeInAH
-	mov		bx, di						; DS:BX now points to DPT
-	call	HStatus_WaitIrqOrRdy		; Wait for IRQ or RDY
-.ReturnWithErrorCodeInAH:
+	mov		ah, COMMAND_WRITE_SECTORS
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
+%ifdef USE_186
+	push	Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+	jmp		Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
+%else
+	call	Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
 	jmp		Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
+%endif
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Returns with INTPACK:
 ;		CH:		Maximum cylinder number, bits 7...0
 ;		CL:		Bits 7...6: Cylinder number bits 9...8
@@ -34,6 +34,6 @@
 	call	RamVars_GetCountOfKnownDrivesToDL
 .ReturnAfterStoringValuesToIntpack:
-	mov		[bp+INTPACK.cx], cx
-	mov		[bp+INTPACK.dx], dx
+	mov		[bp+IDEPACK.intpack+INTPACK.cx], cx
+	mov		[bp+IDEPACK.intpack+INTPACK.dx], dx
 	xor		ah, ah
 .ReturnErrorFromPreviousInt13hHandler:
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH9h_HInit.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
@@ -34,4 +34,5 @@
 ;	Parameters:
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		AH:		Int 13h return status
@@ -45,26 +46,27 @@
 
 	; Try to select drive and wait until ready
-	or		BYTE [di+DPT.bReset], MASK_RESET_ALL		; Everything uninitialized
-	call	HDrvSel_SelectDriveAndDisableIRQ
+	or		WORD [di+DPT.wFlags], MASK_DPT_RESET		; Everything uninitialized
+	call	AccessDPT_GetDriveSelectByteToAL
+	mov		[bp+IDEPACK.bDrvAndHead], al
+	call	Device_SelectDrive
 	jc		SHORT .ReturnNotSuccessfull
-	and		BYTE [di+DPT.bReset], ~FLG_RESET_nDRDY		; Clear since success
+	and		WORD [di+DPT.wFlags], ~FLG_DPT_RESET_nDRDY	; Clear since success
 
 	; Initialize CHS parameters if LBA is not used
-	call	AH9h_InitializeDeviceParameters
+	call	InitializeDeviceParameters
 	jc		SHORT .RecalibrateDrive
-	and		BYTE [di+DPT.bReset], ~FLG_RESET_nINITPRMS
+	and		WORD [di+DPT.wFlags], ~FLG_DPT_RESET_nINITPRMS
 
 	; Recalibrate drive by seeking to cylinder 0
-ALIGN JUMP_ALIGN
 .RecalibrateDrive:
 	call	AH11h_RecalibrateDrive
 	jc		SHORT .InitializeBlockMode
-	and		BYTE [di+DPT.bReset], ~FLG_RESET_nRECALIBRATE
+	and		WORD [di+DPT.wFlags], ~FLG_DPT_RESET_nRECALIBRATE
 
 	; Initialize block mode transfers
 .InitializeBlockMode:
-	call	AH9h_InitializeBlockMode
+	call	InitializeBlockMode
 	jc		SHORT .ReturnNotSuccessfull
-	and		BYTE [di+DPT.bReset], ~FLG_RESET_nSETBLOCK	; Keeps CF clear
+	and		WORD [di+DPT.wFlags], ~FLG_DPT_RESET_nSETBLOCK	; Keeps CF clear
 
 .ReturnNotSuccessfull:
@@ -74,45 +76,8 @@
 
 ;--------------------------------------------------------------------
-; Sends Initialize Device Parameters command to IDE Hard Disk.
-; Initialization is used to initialize logical CHS parameters. Drives
-; may not support all CHS values.
-; This command is only supported by drives that supports CHS addressing.
-;
-; AH9h_InitializeDeviceParameters
+; InitializeDeviceParameters
 ;	Parameters:
-;		DS:DI:	Ptr to DPT
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		Cleared if succesfull
-;				Set if any error
-;	Corrupts registers:
-;		AL, BX, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AH9h_InitializeDeviceParameters:
-	; No need to initialize CHS parameters if LBA mode enabled
-	test	BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_LBA	; Clears CF
-	jnz		SHORT .Return
-
-	push	dx
-	mov		bh, [di+DPT.bPHeads]
-	dec		bh						; Max head number
-	mov		dx, [RAMVARS.wIdeBase]
-	call	HCommand_OutputTranslatedLCHSaddress
-	mov		ah, HCMD_INIT_DEV
-	mov		al, [di+DPT.bPSect]		; Sectors per track
-	call	HCommand_OutputSectorCountAndCommand
-	call	HStatus_WaitBsyDefTime	; Wait until drive ready (DRDY won't be set!)
-	pop		dx
-.Return:
-	ret
-
-
-;--------------------------------------------------------------------
-; Initializes block mode transfers.
-;
-; AH9h_InitializeBlockMode
-;	Parameters:
-;		DS:DI:	Ptr to DPT
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		AH:		BIOS Error code
@@ -123,12 +88,36 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-AH9h_InitializeBlockMode:
-	mov		ax, FLG_DRVPARAMS_BLOCKMODE
-	call	AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
-	jz		SHORT .Return				; Block mode disabled (CF cleared)
-	eMOVZX	ax, BYTE [di+DPT.bMaxBlock]	; Load max block size, zero AH
-	test	al, al						; Block mode supported? (clears CF)
-	jz		SHORT .Return				;  If not, return
+InitializeDeviceParameters:
+	; No need to initialize CHS parameters if LBA mode enabled
+	test	BYTE [di+DPT.wFlags], FLG_DRVNHEAD_LBA	; Clear CF
+	jnz		SHORT ReturnSuccessSinceInitializationNotNeeded
+
+	; Initialize Locigal Sectors per Track and Max Head number
+	mov		ah, [di+DPT.bPchsHeads]
+	dec		ah							; Max Head number
+	mov		dl, [di+DPT.bPchsSectors]	; Sectors per Track
+	mov		al, COMMAND_INITIALIZE_DEVICE_PARAMETERS
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_BSY, FLG_STATUS_BSY)
+	jmp		Idepack_StoreNonExtParametersAndIssueCommandFromAL
+
+
+;--------------------------------------------------------------------
+; InitializeBlockMode
+;	Parameters:
+;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;	Returns:
+;		AH:		BIOS Error code
+;		CF:		Cleared if succesfull
+;				Set if any error
+;	Corrupts registers:
+;		AL, BX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+InitializeBlockMode:
+	test	WORD [di+DPT.wFlags], FLG_DPT_BLOCK_MODE_SUPPORTED	; Clear CF
+	jz		SHORT ReturnSuccessSinceInitializationNotNeeded
+
+	mov		al, [di+DPT_ATA.bMaxBlock]	; Load max block size, zero AH
 	jmp		AH24h_SetBlockSize
-.Return:
+ReturnSuccessSinceInitializationNotNeeded:
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHCh_HSeek.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHCh_HSeek.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHCh_HSeek.asm	(revision 150)
@@ -13,11 +13,11 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Parameters on INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
+;	Parameters on INTPACK:
 ;		CH:		Cylinder number, bits 7...0
 ;		CL:		Bits 7...6: Cylinder number bits 9 and 8
 ;				Bits 5...0:	Starting sector number (1...63)
 ;		DH:		Starting head number (0...255)
-;	Returns with INTPACK in SS:BP:
+;	Returns with INTPACK:
 ;		AH:		BIOS Error code
 ;		CF:		0 if succesfull, 1 if error
@@ -33,5 +33,4 @@
 %endif
 
-
 ;--------------------------------------------------------------------
 ; AHCh_SeekToCylinder
@@ -42,4 +41,5 @@
 ;		DH:		Starting head number (0...255)
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
+;		SS:BP:	Ptr to IDEREGS_AND_INTPACK
 ;	Returns:
 ;		AH:		BIOS Error code
@@ -49,9 +49,5 @@
 ;--------------------------------------------------------------------
 AHCh_SeekToCylinder:
-	mov		ax, HCMD_SEEK<<8			; Load cmd to AH, AL=zero sector cnt
-	call	HCommand_OutputCountAndLCHSandCommand
-	jc		SHORT .ReturnWithErrorCodeInAH
-	mov		bx, di						; DS:BX now points to DPT
-	jmp		HStatus_WaitIrqOrRdy		; Wait for IRQ or RDY
-.ReturnWithErrorCodeInAH:
-	ret
+	mov		ah, COMMAND_SEEK
+	mov		bx, TIMEOUT_AND_STATUS_TO_WAIT(TIMEOUT_DRQ, FLG_STATUS_DRDY)
+	jmp		Idepack_TranslateOldInt13hAddressAndIssueCommandFromAH
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 150)
@@ -12,6 +12,6 @@
 ;		DL:		Translated Drive number
 ;		DS:DI:	Ptr to DPT (in RAMVARS segment)
-;		SS:BP:	Ptr to INTPACK
-;	Returns with INTPACK in SS:BP:
+;		SS:BP:	Ptr to IDEPACK
+;	Returns with INTPACK:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
@@ -35,9 +35,10 @@
 ;		DL:		Drive number
 ;		DS:		RAMVARS segment
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		AH:		Int 13h return status
 ;		CF:		0 if succesfull, 1 if error
 ;	Corrupts registers:
-;		AL, CX, DI
+;		AL, CX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -48,11 +49,12 @@
 	call	FindDPT_ForDriveNumber		; DS:DI now points to DPT
 	call	Interrupts_UnmaskInterruptControllerForDriveInDSDI
-	call	AHDh_ResetMasterAndSlave
+	call	Device_ResetMasterAndSlaveController
 	;jc		SHORT .ReturnError			; CF would be set if slave drive present without master
 										; (error register has special values after reset)
 
 	; Initialize Master and Slave drives
-	mov		dx, [RAMVARS.wIdeBase]		; Load base port address
-	call	AHDh_InitializeMasterAndSlave
+	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]
+	mov		dx, [cs:bx+IDEVARS.wPort]
+	call	InitializeMasterAndSlaveDriveFromPortInDX
 
 	pop		bx
@@ -62,44 +64,8 @@
 
 ;--------------------------------------------------------------------
-; Resets Master and Slave drives at wanted port.
-; Both IDE drives will be reset. It is not possible to reset
-; Master or Slave only.
-;
-; AHDh_ResetMasterAndSlave
-;	Parameters:
-;		DS:DI:	Ptr to DPT for Master or Slave drive
-;	Returns:
-;		CF:		0 if reset succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AX, BX, CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AHDh_ResetMasterAndSlave:
-	; Reset controller
-	; HSR0: Set_SRST
-	mov		al, [di+DPT.bDrvCtrl]		; Load value for ACR
-	or		al, FLG_IDE_CTRL_SRST		; Set Reset bit
-	call	HDrvSel_OutputDeviceControlByte
-	mov		ax, 5						; Delay at least 5us
-	call	HTimer_DelayMicrosecondsFromAX
-
-	; HSR1: Clear_wait
-	mov		al, [di+DPT.bDrvCtrl]		; Load value for ACR
-	out		dx, al						; End Reset
-	mov		ax, 2000					; Delay at least 2ms
-	call	HTimer_DelayMicrosecondsFromAX
-
-	; HSR2: Check_status
-	mov		cl, B_TIMEOUT_RESET			; Reset timeout delay
-	jmp		HStatus_WaitBsy
-
-
-;--------------------------------------------------------------------
-; Initializes Master and Slave drive.
-;
-; AHDh_InitializeMasterAndSlave
+; InitializeMasterAndSlaveDriveFromPortInDX
 ;	Parameters:
 ;		DX:		IDE Base Port address
+;		SS:BP:	Ptr to IDEPACK
 ;	Returns:
 ;		AH:		Error code
@@ -107,11 +73,11 @@
 ;				1 if any error
 ;	Corrupts registers:
-;		AL, BX, CX, DX, DI
+;		AL, BX, CX, DX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-AHDh_InitializeMasterAndSlave:
+InitializeMasterAndSlaveDriveFromPortInDX:
 	push	dx							; Store base port address
 	xor		cx, cx						; Assume no errors
-	call	FindDPT_ForIdeMasterAtPort
+	call	FindDPT_ToDSDIForIdeMasterAtPortDX
 	jnc		SHORT .InitializeSlave		; Master drive not present
 	call	AH9h_InitializeDriveForUse
@@ -119,5 +85,5 @@
 .InitializeSlave:
 	pop		dx							; Restore base port address
-	call	FindDPT_ForIdeSlaveAtPort
+	call	FindDPT_ToDSDIForIdeSlaveAtPortDX
 	jnc		SHORT .CombineErrors		; Slave drive not present
 	call	AH9h_InitializeDriveForUse
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HAddress.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HAddress.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HAddress.asm	(revision 150)
@@ -1,7 +1,3 @@
-; File name		:	HAddress.asm
-; Project name	:	IDE BIOS
-; Created date	:	11.3.2010
-; Last update	:	4.4.2010
-; Author		:	Tomi Tilli
+; Project name	:	XTIDE Universal BIOS
 ; Description	:	Functions for address translations.
 
@@ -9,9 +5,15 @@
 SECTION .text
 
+; Jump table for conversion functions
+ALIGN WORD_ALIGN
+g_rgfnAddressTranslation:
+	dw		DoNotConvertLCHS					; 0, ADDR_DPT_LCHS
+	dw		ConvertLCHStoPCHS					; 1, ADDR_DPT_PCHS
+	dw		ConvertLCHStoLBARegisterValues		; 2, ADDR_DPT_LBA28
+	dw		ConvertLCHStoLBARegisterValues		; 3, ADDR_DPT_LBA48
+
+
 ;--------------------------------------------------------------------
-; Outputs sector count, L-CHS address and command to IDE registers.
-; This function does not wait until command has been completed.
-;
-; HAddress_ConvertParamsFromBiosLCHStoIDE
+; HAddress_OldInt13hAddressToIdeAddress
 ;	Parameters:
 ;		CH:		Cylinder number, bits 7...0
@@ -28,22 +30,12 @@
 ;		AX, DX
 ;--------------------------------------------------------------------
-ALIGN WORD_ALIGN
-g_rgfnAddressTranslation:
-	dw		HAddress_DoNotConvertLCHS					; 0, ADDR_DPT_LCHS
-	dw		HAddress_ConvertLCHStoPCHS					; 1, ADDR_DPT_PCHS
-	dw		HAddress_ConvertLCHStoLBARegisterValues		; 2, ADDR_DPT_LBA28
-	dw		HAddress_ConvertLCHStoLBARegisterValues		; 3, ADDR_DPT_LBA48
-
 ALIGN JUMP_ALIGN
-HAddress_ConvertParamsFromBiosLCHStoIDE:
-	mov		bl, [di+DPT.bFlags]
-	and		bx, BYTE MASK_DPT_ADDR						; Addressing mode to BX
+HAddress_OldInt13hAddressToIdeAddress:
+	call	AccessDPT_GetAddressingModeForWordLookToBX
 	push	WORD [cs:bx+g_rgfnAddressTranslation]		; Push return address
-	; Fall to HAddress_ExtractLCHSFromBiosParams
+	; Fall to HAddress_ExtractLCHSparametersFromOldInt13hAddress
 
 ;---------------------------------------------------------------------
-; Extracts L-CHS parameters from BIOS function parameters.
-;
-; HAddress_ExtractLCHSFromBiosParams:
+; HAddress_ExtractLCHSparametersFromOldInt13hAddress
 ;	Parameters:
 ;		CH:		Cylinder number, bits 7...0
@@ -58,6 +50,5 @@
 ;		Nothing
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HAddress_ExtractLCHSFromBiosParams:
+HAddress_ExtractLCHSparametersFromOldInt13hAddress:
 	mov		bl, cl				; Copy sector number...
 	and		bl, 3Fh				; ...and limit to 1...63
@@ -70,5 +61,5 @@
 
 ;---------------------------------------------------------------------
-; Converts BIOS LCHS parameters to IDE P-CHS parameters.
+; Converts LCHS parameters to IDE P-CHS parameters.
 ; PCylinder	= (LCylinder << n) + (LHead / PHeadCount)
 ; PHead		= LHead % PHeadCount
@@ -89,8 +80,8 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-HAddress_ConvertLCHStoPCHS:
+ConvertLCHStoPCHS:
 	; LHead / PHeadCount and LHead % PHeadCount
 	eMOVZX	ax, bh					; Copy L-CHS Head number to AX
-	div		BYTE [di+DPT.bPHeads]	; AL = LHead / PHeadCount, AH = LHead % PHeadCount
+	div		BYTE [di+DPT.bPchsHeads]; AL = LHead / PHeadCount, AH = LHead % PHeadCount
 	mov		bh, ah					; Copy P-CHS Head number to BH
 	xor		ah, ah					; AX = LHead / PHeadCount
@@ -98,10 +89,10 @@
 	; (LCylinder << n) + (LHead / PHeadCount)
 	mov		dx, cx					; Copy L-CHS Cylinder number to DX
-	mov		cl, [di+DPT.bShLtoP]	; Load shift count
+	mov		cl, [di+DPT.wFlags]		; Load shift count
+	and		cl, MASK_DPT_CHS_SHIFT_COUNT
 	shl		dx, cl					; DX = LCylinder << n
 	add		ax, dx					; AX = P-CHS Cylinder number
 	mov		cx, ax					; Copy P-CHS Cylinder number to CX
-ALIGN JUMP_ALIGN
-HAddress_DoNotConvertLCHS:
+DoNotConvertLCHS:
 	ret
 
@@ -109,8 +100,11 @@
 ;---------------------------------------------------------------------
 ; Converts LCHS parameters to 28-bit LBA address.
+; Only 24-bits are used since LHCS to LBA28 conversion has 8.4GB limit.
+; LBA = ((cylToSeek*headsPerCyl+headToSeek)*sectPerTrack)+sectToSeek-1
+;
 ; Returned address is in same registers that
 ; HAddress_DoNotConvertLCHS and HAddress_ConvertLCHStoPCHS returns.
 ;
-; HAddress_ConvertLCHStoLBARegisterValues:
+; ConvertLCHStoLBARegisterValues:
 ;	Parameters:
 ;		BL:		Sector number (1...63)
@@ -127,33 +121,9 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-HAddress_ConvertLCHStoLBARegisterValues:
-	call	HAddress_ConvertLCHStoLBA28
-	mov		bl, al					; Sector Number Register (LBA 7...0)
-	mov		cl, ah					; 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)
-	ret
-
-;---------------------------------------------------------------------
-; Converts LCHS parameters to 28-bit LBA address.
-; Only 24-bits are used since LHCS to LBA28 conversion has 8.4GB limit.
-; LBA = ((cylToSeek*headsPerCyl+headToSeek)*sectPerTrack)+sectToSeek-1
-;
-; HAddress_ConvertLCHStoLBA28:
-;	Parameters:
-;		BL:		Sector number (1...63)
-;		BH:		Head number (0...255)
-;		CX:		Cylinder number (0...1023)
-;		DS:DI:	Ptr to Disk Parameter Table
-;	Returns:
-;		DX:AX:	28-bit LBA address (DH is always zero)
-;	Corrupts registers:
-;		BX, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HAddress_ConvertLCHStoLBA28:
+ConvertLCHStoLBARegisterValues:
 	; cylToSeek*headsPerCyl (18-bit result)
 	mov		ax, cx					; Copy Cylinder number to AX
-	mul		WORD [di+DPT.wLHeads]	; DX:AX = cylToSeek*headsPerCyl
+	eMOVZX	dx, BYTE [di+DPT.bLchsHeads]
+	mul		dx						; DX:AX = cylToSeek*headsPerCyl
 
 	; +=headToSeek (18-bit result)
@@ -163,5 +133,5 @@
 
 	; *=sectPerTrack (18-bit by 6-bit multiplication with 24-bit result)
-	eMOVZX	cx, BYTE [di+DPT.bPSect]; Load Sectors per Track
+	eMOVZX	cx, BYTE [di+DPT.bPchsSectors]	; Load Sectors per Track
 	xchg	ax, dx					; Hiword to AX, loword to DX
 	mul		cl						; AX = hiword * Sectors per Track
@@ -176,3 +146,9 @@
 	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)
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCapacity.asm	(revision 148)
+++ 	(revision )
@@ -1,42 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Functions for hard disk capacity calculations.
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; Calculates sector count from L-CHS values returned by INT 13h, AH=08h.
-;
-; HCapacity_GetSectorCountFromForeignAH08h:
-; HCapacity_GetSectorCountFromOurAH08h:
-;	Parameters:
-;		DL:		Drive number
-;		DS:		RAMVARS segment
-;		DS:DI:	Ptr to DPT (HCapacity_GetSectorCountFromOurAH08h)
-;	Returns:
-;		DX:AX:	Total sector count
-;		BX:		Zero
-;	Corrupts registers:
-;		CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HCapacity_GetSectorCountFromForeignAH08h:
-	mov		ah, GET_DRIVE_PARAMETERS
-	call	Int13h_CallPreviousInt13hHandler
-	jmp		SHORT ConvertAH08hReturnValuesToSectorCount
-
-ALIGN JUMP_ALIGN
-HCapacity_GetSectorCountFromOurAH08h:
-	call	AH8h_GetDriveParameters
-	; Fall to ConvertAH08hReturnValuesToSectorCount
-
-ConvertAH08hReturnValuesToSectorCount:
-	call	HAddress_ExtractLCHSFromBiosParams
-	xor		ax, ax			; Zero AX
-	inc		cx				; Max cylinder number to cylinder count
-	xchg	al, bh			; AX=Max head number, BX=Sectors per track
-	inc		ax				; AX=Head count
-	mul		bx				; AX=Head count * Sectors per track
-	mul		cx				; DX:AX = Total sector count
-	xor		bx, bx			; Zero BX for 48-bit sector count (and clear CF)
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCommand.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HCommand.asm	(revision 148)
+++ 	(revision )
@@ -1,111 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Functions for outputting IDE commands and parameters.
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; Outputs sector count, L-CHS address and command to IDE registers.
-; This function does not wait until command has been completed.
-;
-; HCommand_OutputCountAndLCHSandCommand
-;	Parameters:
-;		AH:		Seek or data transfer command
-;		AL:		Sector count (1...255, 0=256)
-;		CH:		Cylinder number, bits 7...0
-;		CL:		Bits 7...6: Cylinder number bits 9 and 8
-;				Bits 5...0:	Starting sector number (1...63)
-;		DH:		Starting head number (0...255)
-;		DS:DI:	Ptr to DPT
-;	Returns:
-;		AH:		BIOS Error code (if error)
-;		CF:		0 if succesfull
-;				1 if any error
-;	Corrupts registers:
-;		CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HCommand_OutputCountAndLCHSandCommand:
-	push	bx
-	push	ax										; Store sector count and command
-	call	HDrvSel_SelectDriveForDataTransfer
-	jc		SHORT .ReturnError
-	call	HIRQ_ClearTaskFlag
-	call	HAddress_ConvertParamsFromBiosLCHStoIDE
-	mov		dx, [RAMVARS.wIdeBase]					; Load IDE Base Port address
-	call	HCommand_OutputTranslatedLCHSaddress	; DX to Sector count register
-	pop		ax										; Restore sector count and command
-	call	HCommand_OutputSectorCountAndCommand
-
-	clc												; Clear CF since success
-	pop		bx
-	ret
-.ReturnError:
-	pop		bx										; Discard pushed AX
-	pop		bx
-	ret
-
-
-;--------------------------------------------------------------------
-; Outputs L-CHS address that has been translated P-CHS or LBA28
-; when necessary.
-;
-; HCommand_OutputTranslatedLCHSaddress
-;	Parameters:
-;		BL:		LBA Low Register / Sector Number Register (LBA 7...0)
-;		CL:		LBA Mid Register / Low Cylinder Register (LBA 15...8)
-;		CH:		LBA High Register / High Cylinder Register (LBA 23...16)
-;		BH:		Drive and Head Register (LBA 27...24)
-;		DX:		IDE Base Port address
-;		DS:DI:	Ptr to DPT
-;	Returns:
-;		DX:		IDE Sector Count Register address
-;	Corrupts registers:
-;		AX, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HCommand_OutputTranslatedLCHSaddress:
-	add		dx, BYTE REG_IDE_LBA_LOW
-	mov		al, bl
-	out		dx, al						; Output LBA 7...0
-
-	; Some (VLB) controllers fail to accept WORD write to cylinder
-	; registers so we must output two bytes instead.
-	inc		dx							; REG_IDE_LBA_MID
-	mov		al, cl
-	out		dx, al						; Output LBA 8...15
-
-	inc		dx							; REG_IDE_LBA_HIGH
-	mov		al, ch
-	out		dx, al						; Output LBA 16...23
-
-	inc		dx							; REG_IDE_DRVHD
-	mov		al, [di+DPT.bDrvSel]		; Load other bits for Drive and Head Register
-	or		al, bh
-	out		dx, al						; Output LBA 27...24
-
-	sub		dx, BYTE REG_IDE_DRVHD-REG_IDE_CNT
-	ret
-
-
-;--------------------------------------------------------------------
-; Outputs sector count and seek or data transfer command.
-;
-; HCommand_OutputSectorCountAndCommand
-;	Parameters:
-;		AH:		Seek or data transfer command
-;		AL:		Sector count (1...255, 0=256)
-;		DX:		IDE Sector Count Register address
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AH, DX
-;--------------------------------------------------------------------	
-ALIGN JUMP_ALIGN
-HCommand_OutputSectorCountAndCommand:
-	out		dx, al						; Output sector count
-	add		dx, BYTE REGW_IDE_CMD-REG_IDE_CNT
-	xchg	al, ah						; AL=Command, AH=Sector count
-	out		dx, al
-	mov		al, ah						; Restore sector count to AL
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HDrvSel.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HDrvSel.asm	(revision 148)
+++ 	(revision )
@@ -1,107 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Functions for selecting Master or Slave drive.
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; Selects Master or Slave drive and disables interrupts. Interrupts should
-; be disabled for commands that do not transfer data.
-; This function returns after drive is ready to accept commands.
-;
-; HDrvSel_SelectDriveAndDisableIRQ
-;	Parameters:
-;		DS:DI:	Ptr to DPT
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if drive selected successfully
-;				1 if any error
-;	Corrupts registers:
-;		AL
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HDrvSel_SelectDriveAndDisableIRQ:
-	push	bx
-	mov		al, [di+DPT.bDrvCtrl]	; Load Device Control Byte
-	or		al, FLG_IDE_CTRL_nIEN	; Disable interrupts
-	call	HDrvSel_SelectDriveAndSetControlByte
-	pop		bx
-	ret
-
-
-;--------------------------------------------------------------------
-; Selects Master or Slave drive for transferring data.
-; This means that interrupts will be enabled if so configured in
-; IDEVARS. This function returns after drive is ready to accept commands.
-;
-; HDrvSel_SelectDriveForDataTransfer
-;	Parameters:
-;		DS:DI:	Ptr to DPT
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if drive selected successfully
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HDrvSel_SelectDriveForDataTransfer:
-	mov		al, [di+DPT.bDrvCtrl]			; Load Device Control Byte
-	; Fall to HDrvSel_SelectDriveAndSetControlByte
-
-;--------------------------------------------------------------------
-; Selects Master or Slave drive.
-; Device Control Byte can be used to enable or disable interrupts.
-; This function returns only after drive is ready to accept commands.
-;
-; HDrvSel_SelectDriveAndSetControlByte
-;	Parameters:
-;		AL:		Device Control Byte (to enable/disable interrupts)
-;		DS:DI:	Ptr to DPT
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if drive selected successfully
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX
-;--------------------------------------------------------------------
-;ALIGN JUMP_ALIGN
-HDrvSel_SelectDriveAndSetControlByte:
-	push	dx
-	push	cx
-
-	; Output Device Control Register to enable/disable interrupts
-	call	HDrvSel_OutputDeviceControlByte
-
-	; Select Master or Slave drive
-	mov		dx, [RAMVARS.wIdeBase]
-	add		dx, BYTE REG_IDE_DRVHD
-	mov		al, [di+DPT.bDrvSel]			; Load Master/Slave selection byte
-	out		dx, al							; Select drive
-
-	; Wait until drive is ready to accept commands
-	call	HStatus_WaitRdyDefTime
-	pop		cx
-	pop		dx
-	ret
-
-
-;--------------------------------------------------------------------
-; Outputs Device Control Byte to Device Control Register.
-;
-; HDrvSel_OutputDeviceControlByte
-;	Parameters:
-;		AL:		Device Control Byte
-;		DS:DI:	Ptr to Disk Parameter Table
-;	Returns:
-;		DX:		Device Control Register address
-;	Corrupts registers:
-;		BX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HDrvSel_OutputDeviceControlByte:
-	eMOVZX	bx, BYTE [di+DPT.bIdeOff]		; CS:BX now points to IDEVARS
-	mov		dx, [cs:bx+IDEVARS.wPortCtrl]	; Load Control Block base address
-	add		dx, BYTE REGW_IDEC_CTRL			; Add offset to Device Control Register
-	out		dx, al							; Output Device Control byte
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HError.asm	(revision 148)
+++ 	(revision )
@@ -1,170 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Error checking functions for BIOS Hard disk functions.
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; HError_GetErrorCodeToAHforTimeoutWhenPolling
-;	Parameters:
-;		DS:		RAMVARS segment
-;	Returns:
-;		AH:		BIOS error code
-;		CF:		Set if error
-;				Cleared if no error
-;	Corrupts registers:
-;		AL
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HError_GetErrorCodeToAHforTimeoutWhenPolling:
-	call	HError_GetErrorCodeToAHafterPolling
-	jc		SHORT .ReturnErrorCodeInAH
-	mov		ah, RET_HD_TIMEOUT			; Force timeout since no actual error...
-	stc									; ...but wanted bit was never set
-.ReturnErrorCodeInAH:
-	ret
-
-
-;--------------------------------------------------------------------
-; HError_GetErrorCodeToAHafterPolling
-;	Parameters:
-;		DS:		RAMVARS segment
-;	Returns:
-;		AH:		BIOS error code
-;		CF:		Set if error
-;				Cleared if no error
-;	Corrupts registers:
-;		AL
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HError_GetErrorCodeToAHafterPolling:
-%ifndef USE_186
-	call	HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
-	jmp		SHORT GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
-%else
-	push	GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
-	; Fall through to HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
-%endif
-
-
-;--------------------------------------------------------------------
-; HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
-;	Parameters:
-;		DS:		RAMVARS segment
-;	Returns:
-;		AL:		IDE Status Register contents
-;		AH:		IDE Error Register contents
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA:
-	push	ds
-	push	dx
-
-	mov		dx, [RAMVARS.wIdeBase]		; Load IDE base port address
-	inc		dx							; Increment to Error Register
-	in		al, dx						; Read Error Register...
-	mov		ah, al						; ...and copy it to AH
-	add		dx, BYTE REGR_IDE_ST - REGR_IDE_ERROR
-	in		al, dx						; Read Status Register to AL
-
-	LOAD_BDA_SEGMENT_TO	ds, dx
-	mov		[HDBDA.wHDStAndErr], ax
-
-	pop		dx
-	pop		ds
-	ret
-
-
-;--------------------------------------------------------------------
-; GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX
-;	Parameters:
-;		AL:		IDE Status Register contents
-;		AH:		IDE Error Register contents
-;	Returns:
-;		AH:		BIOS INT 13h error code
-;		CF:		Set if error
-;				Cleared if no error
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-GetBiosErrorCodeToAHfromStatusAndErrorRegistersInAX:
-	test	al, FLG_IDE_ST_BSY
-	jz		SHORT .CheckErrorBitsFromStatusRegisterInAL
-	mov		ah, RET_HD_TIMEOUT
-	jmp		SHORT .ReturnBiosErrorCodeInAH
-
-ALIGN JUMP_ALIGN
-.CheckErrorBitsFromStatusRegisterInAL:
-	test	al, FLG_IDE_ST_DF | FLG_IDE_ST_CORR | FLG_IDE_ST_ERR
-	jnz		SHORT .ProcessErrorFromStatusRegisterInAL
-	xor		ah, ah					; No errors, zero AH and CF
-	ret
-
-.ProcessErrorFromStatusRegisterInAL:
-	test	al, FLG_IDE_ST_ERR		; Error specified in Error register?
-	jnz		SHORT .ConvertBiosErrorToAHfromErrorRegisterInAH
-	mov		ah, RET_HD_ECC			; Assume ECC corrected error
-	test	al, FLG_IDE_ST_CORR		; ECC corrected error?
-	jnz		SHORT .ReturnBiosErrorCodeInAH
-	mov		ah, RET_HD_CONTROLLER	; Must be Device Fault
-	jmp		SHORT .ReturnBiosErrorCodeInAH
-
-.ConvertBiosErrorToAHfromErrorRegisterInAH:
-	push	bx
-	mov		bx, .rgbRetCodeLookup
-.ErrorBitLoop:
-	rcr		ah, 1					; Set CF if error bit set
-	jc		SHORT .LookupErrorCode
-	inc		bx
-	cmp		bx, .rgbRetCodeLookup + 8
-	jb		SHORT .ErrorBitLoop		; Loop until all bits checked
-.LookupErrorCode:
-	mov		ah, [cs:bx+.rgbRetCodeLookup]
-	pop		bx
-
-.ReturnBiosErrorCodeInAH:
-	stc								; Set CF since error
-	ret
-
-.rgbRetCodeLookup:
-	db	RET_HD_ADDRMARK		; Bit0=AMNF, Address Mark Not Found
-	db	RET_HD_SEEK_FAIL	; Bit1=TK0NF, Track 0 Not Found
-	db	RET_HD_INVALID		; Bit2=ABRT, Aborted Command
-	db	RET_HD_NOTLOCKED	; Bit3=MCR, Media Change Requested
-	db	RET_HD_NOT_FOUND	; Bit4=IDNF, ID Not Found
-	db	RET_HD_LOCKED		; Bit5=MC, Media Changed
-	db	RET_HD_UNCORRECC	; Bit6=UNC, Uncorrectable Data Error
-	db	RET_HD_BADSECTOR	; Bit7=BBK, Bad Block Detected
-	db	RET_HD_STATUSERR	; When Error Register is zero
-
-
-;--------------------------------------------------------------------
-; HError_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
-; HError_SetErrorCodeToIntpackInSSBPfromAH
-;	Parameters:
-;		AH:		BIOS error code (00h = no error)
-;		SS:BP:	Ptr to INTPACK
-;	Returns:
-;		SS:BP:	Ptr to INTPACK with error condition set
-;	Corrupts registers:
-;		DS, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HError_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
-	; Store error code to BDA
-	LOAD_BDA_SEGMENT_TO	ds, di
-	mov		[BDA.bHDLastSt], ah
-
-	; Store error code to INTPACK
-HError_SetErrorCodeToIntpackInSSBPfromAH:
-	mov		[bp+INTPACK.ah], ah
-	test	ah, ah
-	jnz		SHORT .SetCFtoIntpack
-	and		BYTE [bp+INTPACK.flags], ~FLG_FLAGS_CF
-	ret
-.SetCFtoIntpack:
-	or		BYTE [bp+INTPACK.flags], FLG_FLAGS_CF
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HIRQ.asm	(revision 148)
+++ 	(revision )
@@ -1,141 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	Interrupt handling related functions.
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; HIRQ_WaitForIRQ
-;	Parameters:
-;		DS:BX:	Ptr to DPT
-;	Returns:
-;		CF:		Set if wait done by operating system
-;				Cleared if BIOS must perform task flag polling
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HIRQ_WaitForIRQ:
-	test	BYTE [bx+DPT.bDrvCtrl], FLG_IDE_CTRL_nIEN	; Clears CF
-	jz		SHORT .NotifyOperatingSystemAboutWaitingForIRQ
-	ret		; Go to poll status register
-
-;--------------------------------------------------------------------
-; .NotifyOperatingSystemAboutWaitingForIRQ
-;	Parameters:
-;		Nothing
-;	Returns:
-;		CF:		Set if wait done by operating system
-;				Cleared if BIOS must perform task flag polling
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.NotifyOperatingSystemAboutWaitingForIRQ:
-	push	ds
-
-	LOAD_BDA_SEGMENT_TO	ds, ax, !		; Zero AX
-	mov		ah, OS_HOOK_DEVICE_BUSY		; Hard disk busy (AX=9000h)
-	cli									; Disable interrupts
-	cmp		al, [BDA.bHDTaskFlg]		; Task flag already set?
-	jc		SHORT .ReturnFromWaitNotify	;  If so, skip OS notification
-	int		BIOS_SYSTEM_INTERRUPT_15h	; OS hook, device busy
-	jnc		SHORT .ReturnFromWaitNotify	; CF cleared, BIOS handles waiting
-
-	; Make sure that OS hooks are supported, otherwise the CF means unsupported function
-	test	ah, ah						; OS hook supported? (clears CF)
-	jnz		SHORT .ReturnFromWaitNotify	; AH has error, BIOS must do the wait
-	stc									; Set CF since wait done by OS
-.ReturnFromWaitNotify:
-	pop		ds
-	sti									; Enable interrupts
-	ret
-
-
-;--------------------------------------------------------------------
-; Clears task (interrupt) flag from BIOS Data Area.
-;
-; HIRQ_ClearTaskFlag
-;	Parameters:
-;		Nothing
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HIRQ_ClearTaskFlag:
-	push	ds
-	LOAD_BDA_SEGMENT_TO	ds, ax, !		; Also zero AX
-	mov		[BDA.bHDTaskFlg], al
-	pop		ds
-	ret
-
-
-;--------------------------------------------------------------------
-; IDE Interrupt Service Routines.
-;
-; HIRQ_InterruptServiceRoutineForIrqs2to7
-; HIRQ_InterruptServiceRoutineForIrqs8to15
-;	Parameters:
-;		Nothing
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HIRQ_InterruptServiceRoutineForIrqs2to7:
-	push	ax
-	call	AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
-
-	mov		al, CMD_END_OF_INTERRUPT
-	jmp		SHORT AcknowledgeMasterInterruptController
-
-
-ALIGN JUMP_ALIGN
-HIRQ_InterruptServiceRoutineForIrqs8to15:
-	push	ax
-	call	AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
-
-	mov		al, CMD_END_OF_INTERRUPT	; Load EOI command to AL
-	out		WPORT_8259SL_COMMAND, al	; Acknowledge Slave 8259
-AcknowledgeMasterInterruptController:
-	out		WPORT_8259MA_COMMAND, al	; Acknowledge Master 8259
-
-	; Issue Int 15h, function AX=9100h (Interrupt ready)
-	mov		ax, OS_HOOK_DEVICE_POST<<8	; Interrupt ready, device 0 (HD)
-	int		BIOS_SYSTEM_INTERRUPT_15h
-
-	pop		ax							; Restore AX
-	iret
-
-;--------------------------------------------------------------------
-; Acknowledges IDE interrupt by reading status register and
-; stores Status and Error Registers to BDA. Task flag in BDA will
-; also be set.
-;
-; AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA
-;	Parameters:
-;		Nothing
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-AcknowledgeIdeInterruptAndStoreStatusAndErrorRegistersToBDA:
-	push	ds
-	push	di
-
-	; Reading Status Register acknowledges IDE interrupt
-	call	RamVars_GetSegmentToDS
-	call	HError_GetStatusAndErrorRegistersToAXandStoreThemToBDA
-
-	; Set Task Flag
-	LOAD_BDA_SEGMENT_TO	ds, ax
-	mov		BYTE [BDA.bHDTaskFlg], 0FFh		; Set task flag
-
-	pop		di
-	pop		ds
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HPIO.asm	(revision 148)
+++ 	(revision )
@@ -1,291 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	PIO transfer functions.
-
-; Structure containing variables for PIO transfer functions
-struc PIOVARS, -6
-	.fnXfer			resb	2	; Offset to transfer function
-	.wBlockSize		resb	2	; Block size in WORDs
-	.wWordsLeft		resb	2	; Number of WORDs left to transfer
-								; (full sectors, can be partial block)
-endstruc
-
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; Reads sectors from hard disk using PIO transfer mode.
-;
-; HPIO_ReadBlock
-;	Parameters:
-;		AL:		Number of sectors to read (1...255)
-;		ES:BX:	Pointer to buffer to recieve data
-;		DS:DI:	Ptr to Disk Parameter Table
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if transfer succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX, CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HPIO_ReadBlock:
-	push	es
-
-	; Create PIOVARS to stack
-	eENTER	PIOVARS_size, 0
-
-	push	si
-	mov		si, g_rgfnPioRead				; Offset to read function lookup
-	call	HPIO_InitializePIOVARS			; Store word count and block size
-	pop		si
-
-	; Start to read data
-	xchg	bx, di							; DS:BX points DPT, ES:DI points buffer
-	mov		dx, [RAMVARS.wIdeBase]			; Load IDE Base Port address
-	call	HPIO_ReadFromDrive
-
-	; Destroy stack frame
-	eLEAVE
-	mov		di, bx							; Restore DI
-	pop		es
-	ret
-
-
-;--------------------------------------------------------------------
-; Initializes PIOVARS members.
-;
-; HPIO_InitializePIOVARS
-;	Parameters:
-;		AL:		Number of sectors to transfer (1...255)
-;		SI:		Offset to transfer function lookup table
-;		DS:DI:	Ptr to Disk Parameter Table
-;		ES:BX:	Ptr to source or destination data buffer
-;		SS:BP:	Ptr to PIOVARS
-;	Returns:
-;		ES:BX:	Normalized pointer to data buffer
-;	Corrupts registers:
-;		AX, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HPIO_InitializePIOVARS:
-	; Store number of WORDs to transfer
-	mov		ah, al								; Number of WORDs to transfer...
-	xor		al, al								; ...to AX
-	mov		[bp+PIOVARS.wWordsLeft], ax			; Store WORD count
-
-	; Store block size in WORDs
-	mov		ah, [di+DPT.bSetBlock]				; AX = block size in WORDs
-	mov		[bp+PIOVARS.wBlockSize], ax			; Store block size
-
-	; Get transfer function based on bus type
-	xchg	ax, bx								; Backup BX
-	eMOVZX	bx, BYTE [di+DPT.bIdeOff]			; CS:BX now points to IDEVARS
-	mov		bl, BYTE [cs:bx+IDEVARS.bBusType]	; Load bus type to BX
-	mov		bx, [cs:bx+si]						; Load offset to transfer function
-	mov		[bp+PIOVARS.fnXfer], bx				; Store offset to transfer function
-	xchg	bx, ax
-	; Fall to HPIO_NormalizeDataPointer
-
-;--------------------------------------------------------------------
-; Normalizes far pointers so that offset overflows won't happen
-; when transferring data using PIO.
-;
-; HPIO_NormalizeDataPointer
-;	Parameters:
-;		ES:BX:	Ptr to source or destination data buffer
-;	Returns:
-;		ES:BX:	Normalized pointer to data buffer
-;	Corrupts registers:
-;		AX, CX
-;--------------------------------------------------------------------
-;ALIGN JUMP_ALIGN
-HPIO_NormalizeDataPointer:
-	NORMALIZE_FAR_POINTER es, bx, ax, cx
-	ret
-
-
-;--------------------------------------------------------------------
-; Reads blocks using PIO transfers.
-;
-; HPIO_ReadFromDrive
-;	Parameters:
-;		DX:		IDE Data port address
-;		DS:BX:	Ptr to DPT (in RAMVARS segment)
-;		ES:DI:	Normalized ptr to buffer to recieve data
-;		SS:BP:	Ptr to PIOVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if transfer succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, CX, DX, DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HPIO_ReadFromDrive:
-	cld									; INS to increment DI
-ALIGN JUMP_ALIGN
-.BlockLoop:
-	call	HStatus_WaitIrqOrDrq		; Wait until ready to transfer
-	jc		SHORT HPIO_WriteToDrive.RetError	; Return if error (code in AH)
-	mov		cx, [bp+PIOVARS.wBlockSize]	; Load block size
-	sub		[bp+PIOVARS.wWordsLeft], cx	; Transferring last (possibly partial) block?
-	jbe		SHORT .XferLastBlock		;  If so, jump to transfer
-	call	[bp+PIOVARS.fnXfer]			; Transfer full block
-	jmp		SHORT .BlockLoop			; Loop while blocks left
-ALIGN JUMP_ALIGN
-.XferLastBlock:
-	add		cx, [bp+PIOVARS.wWordsLeft]	; CX to partial block size
-	call	[bp+PIOVARS.fnXfer]			; Transfer possibly partial block
-	jmp		HStatus_WaitBsyDefTime		; Check for errors
-
-
-;--------------------------------------------------------------------
-; Writes sectors to hard disk using PIO transfer mode.
-;
-; HPIO_WriteBlock
-;	Parameters:
-;		AL:		Number of sectors to write (1...255)
-;		ES:BX:	Pointer to buffer containing data
-;		DS:DI:	Ptr to Disk Parameter Table
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if transfer successfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX, CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HPIO_WriteBlock:
-	push	es
-	push	si
-
-	; Create PIOVARS to stack
-	eENTER	PIOVARS_size, 0
-
-	mov		si, g_rgfnPioWrite				; Offset to write function lookup
-	call	HPIO_InitializePIOVARS			; Store word count and block size
-
-	; Prepare pointers and start transfer
-	mov		si, bx							; ES:SI now points source buffer
-	mov		bx, di							; DS:BX now points DPT
-	call	HPIO_WriteToDrive
-
-	; Destroy stack frame
-	eLEAVE
-
-	pop		si
-	pop		es
-	ret
-
-
-;--------------------------------------------------------------------
-; Writes blocks using PIO transfers.
-;
-; HPIO_WriteToDrive
-;	Parameters:
-;		DS:BX:	Ptr to DPT (in RAMVARS segment)
-;		ES:SI:	Normalized ptr to buffer containing data
-;		SS:BP:	Ptr to PIOVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if transfer succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, CX, DX, SI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HPIO_WriteToDrive:
-	cld										; OUTS to increment SI
-	call	HStatus_WaitDrqDefTime			; Always poll DRQ for first block, get status reg to DX
-	jc		SHORT .RetError					; Return if error (code in AH)
-	sub		dx, BYTE REGR_IDE_ST			; DX to Data Port address
-ALIGN JUMP_ALIGN
-.BlockLoop:
-	mov		cx, [bp+PIOVARS.wBlockSize]		; Load block size
-	sub		[bp+PIOVARS.wWordsLeft], cx		; Transferring last (possibly partial) block?
-	jbe		SHORT .XferLastBlock			;  If so, jump to transfer
-	call	[bp+PIOVARS.fnXfer]				; Transfer full block
-	call	HStatus_WaitIrqOrDrq			; Wait until ready to transfer
-	jnc		SHORT .BlockLoop				; If no error, loop while blocks left
-.RetError:
-	ret										; This ret is shared with HPIO_ReadFromDrive
-ALIGN JUMP_ALIGN
-.XferLastBlock:
-	add		cx, [bp+PIOVARS.wWordsLeft]		; CX to partial block size
-	call	[bp+PIOVARS.fnXfer]				; Transfer possibly partial block
-	jmp		HStatus_WaitIrqOrRdy			; Check for errors
-
-
-;--------------------------------------------------------------------
-; Bus specific transfer functions and lookup table.
-;
-; HPIO_DualByteRead		Dual port 8-bit XTIDE PIO read transfer
-; HPIO_WordRead			Normal 16-bit IDE PIO read transfer
-; HPIO_DualByteWrite	Dual port 8-bit XTIDE PIO write transfer
-; HPIO_WordWrite		Normal 16-bit IDE PIO write transfer
-;	Parameters:
-;		CX:		Block size in WORDs
-;		DX:		IDE Data port address
-;		ES:DI:	Normalized ptr to buffer to recieve data (read only)
-;		ES:SI:	Normalized ptr to buffer containing data (write only)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HPIO_DualByteRead:
-	eREP_DUAL_BYTE_PORT_INSW
-	ret
-ALIGN JUMP_ALIGN
-HPIO_WordRead:
-	rep
-	db		6Dh			; INSW
-	ret
-ALIGN JUMP_ALIGN
-HPIO_DWordRead:
-	shr		cx, 1		; WORD count to DWORD count
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Dh			; INSW/INSD
-	ret
-ALIGN JUMP_ALIGN
-HPIO_SingleByteRead:
-	eREP_SINGLE_BYTE_PORT_INSW
-	ret
-
-ALIGN JUMP_ALIGN
-HPIO_DualByteWrite:
-	eREP_DUAL_BYTE_PORT_OUTSW
-	ret
-ALIGN JUMP_ALIGN
-HPIO_WordWrite:
-	eSEG	es			; Source is ES segment
-	rep
-	db		6Fh			; OUTSW
-	ret
-ALIGN JUMP_ALIGN
-HPIO_DWordWrite:
-	shr		cx, 1		; WORD count to DWORD count
-	eSEG	es			; Source is ES segment
-	rep
-	db		66h			; Override operand size to 32-bit
-	db		6Fh			; OUTSW/OUTSD
-	ret
-ALIGN JUMP_ALIGN
-HPIO_SingleByteWrite:
-	eREP_SINGLE_BYTE_PORT_OUTSW
-	ret
-
-ALIGN WORD_ALIGN
-g_rgfnPioRead:
-	dw		HPIO_DualByteRead		; 8-bit dual port reads
-	dw		HPIO_WordRead			; 16-bit reads
-	dw		HPIO_DWordRead			; 32-bit reads
-	dw		HPIO_SingleByteRead		; 8-bit single port reads
-g_rgfnPioWrite:
-	dw		HPIO_DualByteWrite		; 8-bit dual port writes
-	dw		HPIO_WordWrite			; 16-bit writes
-	dw		HPIO_DWordWrite			; 32-bit writes
-	dw		HPIO_SingleByteWrite	; 8-bit single port writes
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HStatus.asm	(revision 148)
+++ 	(revision )
@@ -1,220 +1,0 @@
-; Project name	:	XTIDE Universal BIOS
-; Description	:	IDE Status Register polling functions.
-
-; Section containing code
-SECTION .text
-
-;--------------------------------------------------------------------
-; Waits Hard Disk IRQ when not transferring data.
-; If interrupts are disabled, RDY flag is polled.
-;
-; HStatus_WaitIrqOrRdy
-;	Parameters:
-;		DS:BX:	Ptr to DPT
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if wait succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_WaitIrqOrRdy:
-	call	HIRQ_WaitForIRQ			; For OS hook (we still need error processing)
-	jnc		SHORT .PollRdySinceNoWaitingOnOsHook
-	jmp		HError_GetErrorCodeToAHafterPolling
-
-ALIGN JUMP_ALIGN
-.PollRdySinceNoWaitingOnOsHook:
-	mov		cl, B_TIMEOUT_DRQ				; Load DRQ (not RDY) timeout
-	jmp		SHORT HStatus_WaitRdy			; Jump to poll RDY
-
-
-;--------------------------------------------------------------------
-; Waits until Hard Disk is ready to transfer data.
-;
-; HStatus_WaitIrqOrDrq
-;	Parameters:
-;		DS:BX:	Ptr to DPT (in RAMVARS segment)
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		0 if wait succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_WaitIrqOrDrq:
-	call	HIRQ_WaitForIRQ
-	jnc		SHORT .PollDrqSinceNoWaitingOnOsHook
-	jmp		HError_GetErrorCodeToAHafterPolling
-
-ALIGN JUMP_ALIGN
-.PollDrqSinceNoWaitingOnOsHook:
-	push	dx
-	push	cx
-	call	HStatus_WaitDrqDefTime
-	pop		cx
-	pop		dx
-	ret
-
-
-;--------------------------------------------------------------------
-; Waits until busy flag is cleared from selected Hard Disk drive.
-;
-; HStatus_WaitBsyDefTime	Uses default timeout
-; HStatus_WaitBsy			Uses user defined timeout
-; HStatus_WaitBsyBase		Uses user base port address and timeout
-;	Parameters:
-;		CL:		Timeout value in system timer ticks (not HStatus_WaitBsyDefTime)
-;		DX:		IDE Base port address (HUtil_WaitBsyBase only)
-;		DS:		Segment to RAMVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		DX:		IDE Status Register Address
-;		CF:		0 if wait succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_WaitBsyDefTime:
-	mov		cl, B_TIMEOUT_BSY			; Load timeout value
-ALIGN JUMP_ALIGN
-HStatus_WaitBsy:
-	mov		dx, [RAMVARS.wIdeBase]		; Load offset to base port
-ALIGN JUMP_ALIGN
-HStatus_WaitBsyBase:
-	add		dx, BYTE REGR_IDE_ST		; Add offset to status reg
-	jmp		SHORT HStatus_PollBsy		; Wait until not busy
-
-
-;--------------------------------------------------------------------
-; Waits until Hard Disk is ready to accept commands.
-;
-; HStatus_WaitRdyDefTime	Uses default timeout
-; HStatus_WaitRdy			Uses user defined timeout
-; HStatus_WaitRdyBase		Uses user base port address and timeout
-;	Parameters:
-;		CL:		Timeout value in system timer ticks (not HStatus_WaitRdyDefTime)
-;		DX:		IDE Base port address (HStatus_WaitRdyBase only)
-;		DS:		Segment to RAMVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		DX:		IDE Status Register Address
-;		CF:		0 if wait succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_WaitRdyDefTime:
-	mov		cl, B_TIMEOUT_RDY			; Load timeout value
-ALIGN JUMP_ALIGN
-HStatus_WaitRdy:
-	mov		dx, [RAMVARS.wIdeBase]		; Load offset to base port
-ALIGN JUMP_ALIGN
-HStatus_WaitRdyBase:
-	add		dx, BYTE REGR_IDE_ST		; Add offset to status reg
-	mov		ah, FLG_IDE_ST_DRDY			; Flag to poll
-	jmp		SHORT HStatus_PollBsyAndFlg	; Wait until flag set
-
-
-;--------------------------------------------------------------------
-; Waits until Hard Disk is ready to transfer data.
-; Note! This function polls DRQ even if interrupts are enabled!
-;
-; HStatus_WaitDrqDefTime	Uses default timeout
-; HStatus_WaitDrq			Uses user defined timeout
-; HStatus_WaitDrqBase		Uses user base port address and timeout
-;	Parameters:
-;		CL:		Timeout value in system timer ticks (not HStatus_WaitDrqDefTime)
-;		DX:		IDE Base port address (HStatus_WaitDrqBase only)
-;		DS:		Segment to RAMVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		DX:		IDE Status Register Address
-;		CF:		0 if wait succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_WaitDrqDefTime:
-	mov		cl, B_TIMEOUT_DRQ			; Load timeout value
-ALIGN JUMP_ALIGN
-HStatus_WaitDrq:
-	mov		dx, [RAMVARS.wIdeBase]		; Load offset to base port
-ALIGN JUMP_ALIGN
-HStatus_WaitDrqBase:
-	add		dx, BYTE REGR_IDE_ST		; Add offset to status reg
-	mov		ah, FLG_IDE_ST_DRQ			; Flag to poll
-	; Fall to HStatus_PollBsyAndFlg
-
-;--------------------------------------------------------------------
-; IDE Status register polling.
-; This function first waits until controller is not busy.
-; When not busy, IDE Status Register is polled until wanted flag is set.
-;
-; HStatus_PollBusyAndFlg
-;	Parameters:
-;		AH:		Status Register Flag to poll (until set) when not busy
-;		CL:		Timeout value in system timer ticks
-;		DX:		IDE Status Register Address
-;		DS:		Segment to RAMVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		Clear if wait completed successfully (no errors)
-;				Set if any error
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_PollBsyAndFlg:
-	call	HTimer_InitializeTimeoutWithTicksInCL	; Initialize timeout counter
-	in		al, dx									; Discard contents for first read
-													; (should read Alternate Status Register)
-ALIGN JUMP_ALIGN
-.PollLoop:
-	in		al, dx									; Load IDE Status Register
-	test	al, FLG_IDE_ST_BSY						; Controller busy?
-	jnz		SHORT .UpdateTimeout					;  If so, jump to timeout update
-	test	al, ah									; Test secondary flag
-	jnz		SHORT GetErrorCodeFromPollingToAH		; If set, break loop
-ALIGN JUMP_ALIGN
-.UpdateTimeout:
-	call	HTimer_SetCFifTimeout
-	jnc		SHORT .PollLoop							; Loop if time left
-	jmp		HError_GetErrorCodeToAHforTimeoutWhenPolling
-
-;--------------------------------------------------------------------
-; IDE Status register polling.
-; This function waits until controller is not busy.
-;
-; HStatus_PollBsy
-;	Parameters:
-;		CL:		Timeout value in system timer ticks
-;		DX:		IDE Status Register Address
-;		DS:		Segment to RAMVARS
-;	Returns:
-;		AH:		BIOS Error code
-;		CF:		Clear if wait completed successfully (no errors)
-;				Set if any error
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-HStatus_PollBsy:
-	call	HTimer_InitializeTimeoutWithTicksInCL	; Initialize timeout counter
-	in		al, dx									; Discard contents for first read
-													; (should read Alternate Status Register)
-ALIGN JUMP_ALIGN
-.PollLoop:
-	in		al, dx									; Load IDE Status Reg
-	test	al, FLG_IDE_ST_BSY						; Controller busy?
-	jz		SHORT GetErrorCodeFromPollingToAH		;  If not, jump to check errors
-	call	HTimer_SetCFifTimeout					; Update timeout counter
-	jnc		SHORT .PollLoop							; Loop if time left (sets CF on timeout)
-ALIGN JUMP_ALIGN
-GetErrorCodeFromPollingToAH:
-	jmp		HError_GetErrorCodeToAHafterPolling
Index: trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HTimer.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HTimer.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/Common/HTimer.asm	(revision 150)
@@ -6,7 +6,7 @@
 
 ;--------------------------------------------------------------------
-; HTimer_InitializeTimeoutWithTicksInCL
+; HTimer_InitializeTimeoutWithTicksInCX
 ;	Parameters:
-;		CL:		Timeout value in system timer ticks
+;		CX:		Timeout value in system timer ticks
 ;		DS:		Segment to RAMVARS
 ;	Returns:
@@ -16,6 +16,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-HTimer_InitializeTimeoutWithTicksInCL:
-	xor		ch, ch							; Timeout ticks now in CX
+HTimer_InitializeTimeoutWithTicksInCX:
 	mov		[RAMVARS.wTimeoutCounter], cx	; Store timeout ticks
 	call	ReadTimeFromBdaToCX
@@ -55,5 +54,5 @@
 HTimer_DelayMicrosecondsFromAX:
 %ifndef USE_AT
-	mov		ax, 1
+	mov		ax, 2
 	; Fall to Delay_TimerTicksFromAX
 %else
