Index: trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Inc/CustomDPT.inc	(revision 150)
@@ -5,72 +5,55 @@
 %define CUSTOMDPT_INC
 
+; Base DPT for all device types
+struc DPT	; 8 bytes
+	; General Disk Parameter Table related
+	.wFlags						resb	2
+	.bIdevarsOffset				resb	1	; Offset to IDEVARS for this drive
 
-; Base Disk Parameter Table for all hard disk drives.
-; DPT might have extensions for specific functions.
-struc DPT
-	; General Disk Parameter Table related
-	.bSize		resb	1	; Size of DPT (with extensions) in bytes
-	.wDrvNumAndFlags:
-	.bDrvNum	resb	1	; Drive number
-	.bFlags		resb	1	; DPT and Drive related flags
-	.bReset		resb	1	; Drive reset status (for debugging)
-	.bIdeOff	resb	1	; Offset to IDEVARS for this drive
+	; L-CHS to P-CHS and L-CHS to LBA28 conversion related
+	.bLchsHeads					resb	1	; Number of L-CHS Heads (1...255)
 
-	; Lookup values for L-CHS to P-CHS and L-CHS to LBA28 conversions
-	.bShLtoP	resb	1	; Bit shift count for L-CHS to P-CHS conversion
-	.wLHeads	resb	2	; Number of L-CHS Heads (1...256)
-
-	; IDE related
-	.wPCyls		resb	2	; Number of P-CHS (IDE) Cylinders (1...16383)
-	.wHeadsAndSectors:
-	.bPHeads	resb	1	; Number of P-CHS (IDE) Heads (1...16)
-	.bPSect		resb	1	; Number of P-CHS (IDE) Sectors per Track (1...63)
-	.bDrvSel	resb	1	; Drive Selection byte for Device/Head Register
-	.bDrvCtrl	resb	1	; Drive Control byte for Device Control Register
-
-	; Related to Block Mode transfers.
-	; Block size is specified in sectors (1, 2, 4, 8, 16, 32, 64 or 128).
-	.wSetAndMaxBlock:
-	.bSetBlock	resb	1	; Currect block size (at least 1)
-	.bMaxBlock	resb	1	; Maximum block size, 0 = block mode not supported
+	; IDE Drive related
+	.wPchsCylinders				resb	2	; Number of P-CHS (IDE) Cylinders (1...16383)
+	.wPchsHeadsAndSectors:
+	.bPchsHeads					resb	1	; Number of P-CHS (IDE) Heads (1...16)
+	.bPchsSectors				resb	1	; Number of P-CHS (IDE) Sectors per Track (1...63)
 endstruc
 
-; Bit definitions for DPT.bFlags
-MASK_DPT_ADDR		EQU		110b	; Bits 1..2, Addressing Mode
-FLG_DPT_EBIOS		EQU		(1<<0)	; EBIOS functions supported for this drive
-FLG_DPT_FIRSTPART	EQU		(1<<3)	; First BIOS Partition of the drive (drive reset allowed)
-FLG_DPT_PARTITION	EQU		(1<<4)	; BIOS Partition
-FLG_DPT_USERCHS		EQU		(1<<5)	; User has specified P-CHS parameters
+; DPT for ATA devices
+struc DPT_ATA	; 8 + 2 bytes = 10 bytes
+	.dpt						resb	DPT_size
 
-; Values for different addressing modes (MASK_DPT_ADDR for DPT.bFlags)
-ADDR_DPT_LCHS		EQU		0		; L-CHS Addressing Mode (NORMAL in many other BIOSes)
-ADDR_DPT_PCHS		EQU		1		; P-CHS Addressing Mode (LARGE in many other BIOSes)
-ADDR_DPT_LBA28		EQU		2		; 28-bit LBA Addressing Mode
-ADDR_DPT_LBA48		EQU		3		; 48-bit LBA Addressing Mode
+	; Block size is specified in sectors (1, 2, 4, 8, 16, 32 or 64).
+	; 128 is not allowed to prevent offset overflow during data transfer.
+	.wSetAndMaxBlock:
+	.bSetBlock					resb	1	; Current block size (at least 1)
+	.bMaxBlock					resb	1	; Maximum block size, 0 = block mode not supported
+endstruc
 
-; Bit definitions for DPT.bReset (inverted)
-FLG_RESET_nDRDY			EQU		(1<<0)	; Drive ready to accept commands
-FLG_RESET_nINITPRMS		EQU		(1<<1)	; Initialize Device Parameters successfull
-FLG_RESET_nRECALIBRATE	EQU		(1<<2)	; Recalibrate successfull
-FLG_RESET_nSETBLOCK		EQU		(1<<3)	; Initialize Block Mode successfull
-MASK_RESET_ALL			EQU		(FLG_RESET_nDRDY | FLG_RESET_nINITPRMS | FLG_RESET_nRECALIBRATE | FLG_RESET_nSETBLOCK)
+LARGEST_DPT_SIZE				EQU		DPT_ATA_size
 
 
-; Extended DPT for XTIDE Universal BIOS partitioned drive.
-; This struct cannot exist with EDPT (EBIOS support).
-struc PART_DPT
-	.dpt		resb	DPT_size
-	.dwStartLBA:
-	.twStartLBA	resb	6	; Starting 28- or 48-bit LBA for BIOS partition
-endstruc
+; Bit definitions for DPT.wFlags
+MASK_DPT_CHS_SHIFT_COUNT		EQU	(7<<0)	; Bits 0...3, P-CHS to L-CHS bit shift count (0...4)
+FLG_DPT_SLAVE					EQU	FLG_DRVNHEAD_DRV	; (1<<4), Drive is slave drive
+MASK_DPT_ADDRESSING_MODE		EQU	(3<<5)	; Bits 5..6, Addressing Mode (bit 6 == FLG_DRVNHEAD_LBA)
+FLG_DPT_ENABLE_IRQ				EQU	(1<<7)
+FLG_DPT_REVERSED_A0_AND_A3		EQU	(1<<8)	; XTIDE mod, Address lines 0 and 3 reversed
+FLG_DPT_SERIAL_DEVICE			EQU	(1<<9)	; Serial Port Device
+FLG_DPT_BLOCK_MODE_SUPPORTED	EQU	(1<<10)	; Use block transfer commands
 
+FLG_DPT_RESET_nDRDY				EQU	(1<<12)	; Drive ready to accept commands
+FLG_DPT_RESET_nINITPRMS			EQU	(1<<13)	; Initialize Device Parameters successfull
+FLG_DPT_RESET_nRECALIBRATE		EQU	(1<<14)	; Recalibrate successfull
+FLG_DPT_RESET_nSETBLOCK			EQU	(1<<15)	; Initialize Block Mode successfull
+MASK_DPT_RESET					EQU	0F000h
 
-; Extended DPT for EBIOS support.
-; This struct cannot exist with PDPT (XTIDE Universal BIOS partitioned drive).
-struc EBDPT
-	.dpt		resb	DPT_size
-	.dwCapacity:
-	.twCapacity	resb	6	; Total drive capacity in sectors
-endstruc
+; Addressing modes for DPT.wFlags
+ADDRESSING_MODE_FIELD_POSITION	EQU		5
+ADDRESSING_MODE_LCHS			EQU		0	; L-CHS Addressing Mode (NORMAL in many other BIOSes)
+ADDRESSING_MODE_PCHS			EQU		1	; P-CHS Addressing Mode (LARGE in many other BIOSes)
+ADDRESSING_MODE_LBA28			EQU		2	; 28-bit LBA Addressing Mode
+ADDRESSING_MODE_LBA48			EQU		3	; 48-bit LBA Addressing Mode
 
 
Index: trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc	(revision 150)
+++ trunk/XTIDE_Universal_BIOS/Inc/DeviceIDE.inc	(revision 150)
@@ -0,0 +1,18 @@
+; Project name	:	XTIDE Universal BIOS
+; Description	:	Device specific equates for IDE drives.
+%ifndef DEVICEIDE_INC
+%define DEVICEIDE_INC
+
+; Reset delays
+HSR0_RESET_WAIT_US		EQU		5		; Delay at least 5us
+HSR1_RESET_WAIT_US		EQU		2000	; Delay at least 2ms
+
+; Polling timeout delays (system timer ticks, 1 tick = 54.9 ms)
+TIMEOUT_BSY				EQU		(2000/55)	; 2000 ms
+TIMEOUT_DRDY			EQU		(2000/55)	; 2000 ms
+TIMEOUT_DRQ				EQU		255			;   14 s (some CF cards occasionally have long write delays)
+TIMEOUT_IDENTIFY_DEVICE	EQU		(500/55)	;  500 ms
+TIMEOUT_MOTOR_STARTUP	EQU		(10000/55)	;   10 s
+
+
+%endif ; DEVICEIDE_INC
Index: trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Inc/IDE_8bit.inc	(revision 150)
@@ -1,39 +1,7 @@
-; File name		:	IDE_8bit.inc
-; Project name	:	IDE BIOS
-; Created date	:	4.4.2010
-; Last update	:	13.4.2010
-; Author		:	Tomi Tilli
+; Project name	:	XTIDE Universal BIOS
 ; Description	:	Macros for accessing data port(s) on 8-bit
 ;					IDE controllers.
 %ifndef IDE_8BIT_INC
 %define IDE_8BIT_INC
-
-;--------------------------------------------------------------------
-; Emulates REP INSW for XTIDE dual (8-bit) data port.
-;
-; eREP_DUAL_BYTE_PORT_INSW
-;	Parameters:
-;		CX:		Loop count
-;		DX:		Port address (must be IDE Data Register)
-;		ES:DI:	Ptr to destination buffer
-;	Returns:
-;		CX:		Zero
-;		DI:		Incremented/decremented
-;	Corrupts registers:
-;		AX, FLAGS
-;--------------------------------------------------------------------
-%macro eREP_DUAL_BYTE_PORT_INSW 0
-	push	bx
-	times 2	shr	cx, 1			; Loop unrolling
-	mov		bx, 8				; Bit mask for toggling data low/high reg
-ALIGN JUMP_ALIGN
-%%InswLoop:
-	eDUAL_BYTE_PORT_INSW
-	eDUAL_BYTE_PORT_INSW
-	eDUAL_BYTE_PORT_INSW
-	eDUAL_BYTE_PORT_INSW
-	loop	%%InswLoop
-	pop		bx
-%endmacro
 
 ;--------------------------------------------------------------------
@@ -66,35 +34,4 @@
 %endmacro
 
-
-;--------------------------------------------------------------------
-; Emulates REP OUTSW for XTIDE dual (8-bit) data port.
-;
-; eREP_DUAL_BYTE_PORT_OUTSW
-;	Parameters:
-;		CX:		Loop count
-;		DX:		Port address (must be IDE Data Register)
-;		ES:SI:	Ptr to source buffer
-;	Returns:
-;		SI:		Incremented/decremented
-;	Corrupts registers:
-;		AX, CX
-;--------------------------------------------------------------------
-%macro eREP_DUAL_BYTE_PORT_OUTSW 0
-	push	ds
-	push	bx
-	times 2	shr	cx, 1			; Loop unrolling
-	mov		bx, 8				; Bit mask for toggling data low/high reg
-	push	es					; Copy ES...
-	pop		ds					; ...to DS
-ALIGN JUMP_ALIGN
-%%OutswLoop:
-	eDUAL_BYTE_PORT_OUTSW
-	eDUAL_BYTE_PORT_OUTSW
-	eDUAL_BYTE_PORT_OUTSW
-	eDUAL_BYTE_PORT_OUTSW
-	loop	%%OutswLoop
-	pop		bx
-	pop		ds
-%endmacro
 
 ;--------------------------------------------------------------------
@@ -130,76 +67,3 @@
 
 
-;--------------------------------------------------------------------
-; Emulates REP INSW for IDE controllers with single 8-bit Data Port.
-;
-; eREP_SINGLE_BYTE_PORT_INSW
-;	Parameters:
-;		CX:		Number of WORDs to transfer
-;		DX:		IDE Data Port address
-;		ES:DI:	Ptr to destination buffer
-;	Returns:
-;		DI:		Incremented/decremented
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-%macro eREP_SINGLE_BYTE_PORT_INSW 0
-%ifdef USE_186	; INS instruction available
-	shl		cx, 1				; WORD count to BYTE count
-	rep insb
-%else			; If 8088/8086
-	shr		cx, 1				; WORD count to DWORD count
-ALIGN JUMP_ALIGN
-%%InsdLoop:
-	in		al, dx
-	stosb						; Store to [ES:DI]
-	in		al, dx
-	stosb
-	in		al, dx
-	stosb
-	in		al, dx
-	stosb
-	loop	%%InsdLoop
-%endif
-%endmacro
-
-
-;--------------------------------------------------------------------
-; Emulates REP OUTSW for IDE controllers with single 8-bit Data Port.
-;
-; eREP_SINGLE_BYTE_PORT_OUTSW
-;	Parameters:
-;		CX:		Number of WORDs to transfer
-;		DX:		IDE Data Port address
-;		ES:SI:	Ptr to source buffer
-;	Returns:
-;		SI:		Incremented/decremented
-;	Corrupts registers:
-;		AL, CX
-;--------------------------------------------------------------------
-%macro eREP_SINGLE_BYTE_PORT_OUTSW 0
-%ifdef USE_186	; OUTS instruction available
-	shl		cx, 1				; WORD count to BYTE count
-	eSEG	es					; Source is ES segment
-	rep outsb
-%else			; If 8088/8086
-	shr		cx, 1				; WORD count to DWORD count
-	push	ds					; Store DS
-	push	es					; Copy ES...
-	pop		ds					; ...to DS
-ALIGN JUMP_ALIGN
-%%OutsdLoop:
-	lodsb						; Load from [DS:SI] to AL
-	out		dx, al
-	lodsb
-	out		dx, al
-	lodsb
-	out		dx, al
-	lodsb
-	out		dx, al
-	loop	%%OutsdLoop
-	pop		ds					; Restore DS
-%endif
-%endmacro
-
-
 %endif ; IDE_8BIT_INC
Index: trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Inc/IdeRegisters.inc	(revision 150)
@@ -1,7 +1,3 @@
-; File name		:	IdeRegisters.inc
-; Project name	:	IDE BIOS
-; Created date	:	23.3.2010
-; Last update	:	23.3.2010
-; Author		:	Tomi Tilli
+; Project name	:	XTIDE Universal BIOS
 ; Description	:	Equates for IDE registers, flags and commands.
 %ifndef IDEREGISTERS_INC
@@ -9,77 +5,78 @@
 
 ; IDE Register offsets from Command Block base port
-REG_IDE_DATA			EQU		0		; Data Register
-REGR_IDE_ERROR			EQU		1		; Error Register
-REGW_IDE_FEAT			EQU		1		; Features Register (ATA1+)
-;REGW_IDE_WRPC			EQU		1		; Write Precompensation Register (obsolete on ATA1+)
-REG_IDE_CNT				EQU		2		; Sector Count Register
-REG_IDE_SECT			EQU		3		; Sector Number Register (LBA 7...0)
-REG_IDE_LBA_LOW			EQU		3		; LBA Low Register
-REG_IDE_LOCYL			EQU		4		; Low Cylinder Register (LBA 15...8)
-REG_IDE_LBA_MID			EQU		4		; LBA Mid Register
-REG_IDE_HICYL			EQU		5		; High Cylinder Register (LBA 23...16)
-REG_IDE_LBA_HIGH		EQU		5		; LBA High Register
-REG_IDE_DRVHD			EQU		6		; Drive and Head Register (LBA 27...24)
-REGR_IDE_ST				EQU		7		; Status Register
-REGW_IDE_CMD			EQU		7		; Command Register
-REG_IDE_HIDATA			EQU		8		; XTIDE Data High Register (actually first Control Block reg)
+DATA_REGISTER					EQU		0
+ERROR_REGISTER_in				EQU		1		; Read only
+FEATURES_REGISTER_out			EQU		1		; Write only, ATA1+
+;WRITE_PRECOMPENSATION_out		EQU		1		; Write only, Obsolete on ATA1+
+SECTOR_COUNT_REGISTER			EQU		2
+SECTOR_NUMBER_REGISTER			EQU		3		; LBA Low Register
+LOW_CYLINDER_REGISTER			EQU		4		; LBA Middle Register
+HIGH_CYLINDER_REGISTER			EQU		5		; LBA High Register
+LBA_LOW_REGISTER				EQU		3		; LBA 7...0, LBA48 31...24
+LBA_MIDDLE_REGISTER				EQU		4		; LBA 15...8, LBA48 39...32
+LBA_HIGH_REGISTER				EQU		5		; LBA 23...16, LBA48 47...40
+DRIVE_AND_HEAD_SELECT_REGISTER	EQU		6		; LBA28 27...24
+STATUS_REGISTER_in				EQU		7		; Read only
+COMMAND_REGISTER_out			EQU		7		; Write only
+XTIDE_DATA_HIGH_REGISTER		EQU		8		; Non-standard (actually first Control Block reg)
 
 ; IDE Register offsets from Control Block base port
 ; (usually Command Block base port + 200h)
-REGR_IDEC_AST			EQU		6		; Alternate Status Register
-REGW_IDEC_CTRL			EQU		6		; Device Control Register
-;REGR_IDEC_ADDR			EQU		7		; Drive Address Register (obsolete on ATA2+)
+ALTERNATE_STATUS_REGISTER_in	EQU		6		; Read only
+DEVICE_CONTROL_REGISTER_out		EQU		6		; Write only
+;DRIVE_ADDRESS_REGISTER			EQU		7		; Obsolete on ATA2+
 
+; Bit mask for XTIDE mod with reversed A0 and A3 address lines
+MASK_A3_AND_A0_ADDRESS_LINES	EQU		((1<<3) | (1<<0))
 
 ; Bit definitions for IDE Error Register
-FLG_IDE_ERR_BBK			EQU		(1<<7)	; Bad Block Detected (reserved on ATA2+, command dependent on ATA4+)
-FLG_IDE_ERR_UNC			EQU		(1<<6)	; Uncorrectable Data Error (command dependent on ATA4+)
-FLG_IDE_ERR_MC			EQU		(1<<5)	; Media Changed (command dependent on ATA4+)
-FLG_IDE_ERR_IDNF		EQU		(1<<4)	; ID Not Found (command dependent on ATA4+)
-FLG_IDE_ERR_MCR			EQU		(1<<3)	; Media Change Request (command dependent on ATA4+)
-FLG_IDE_ERR_ABRT		EQU		(1<<2)	; Command Aborted
-FLG_IDE_ERR_TK0NF		EQU		(1<<1)	; Track 0 Not Found (command dependent on ATA4+)
-FLG_IDE_ERR_AMNF		EQU		(1<<0)	; Address Mark Not Found (command dependent on ATA4+)
+FLG_ERROR_BBK			EQU		(1<<7)	; Bad Block Detected (reserved on ATA2+, command dependent on ATA4+)
+FLG_ERROR_UNC			EQU		(1<<6)	; Uncorrectable Data Error (command dependent on ATA4+)
+FLG_ERROR_MC			EQU		(1<<5)	; Media Changed (command dependent on ATA4+)
+FLG_ERROR_IDNF			EQU		(1<<4)	; ID Not Found (command dependent on ATA4+)
+FLG_ERROR_MCR			EQU		(1<<3)	; Media Change Request (command dependent on ATA4+)
+FLG_ERROR_ABRT			EQU		(1<<2)	; Command Aborted
+FLG_ERROR_TK0NF			EQU		(1<<1)	; Track 0 Not Found (command dependent on ATA4+)
+FLG_ERROR_AMNF			EQU		(1<<0)	; Address Mark Not Found (command dependent on ATA4+)
 
 ; Bit definitions for IDE Drive and Head Select Register
-FLG_IDE_DRVHD_LBA		EQU		(1<<6)	; LBA Addressing enabled (instead of CHS)
-FLG_IDE_DRVHD_DRV		EQU		(1<<4)	; Drive Select (0=Master, 1=Slave)
-MASK_IDE_DRVHD_HEAD		EQU		0Fh		; Head select bits (bits 0...3)
-MASK_IDE_DRVHD_SET		EQU		0A0h	; Bits that must be set to 1 on ATA1 (reserved on ATA2+)
+FLG_DRVNHEAD_LBA		EQU		(1<<6)	; LBA Addressing enabled (instead of CHS)
+FLG_DRVNHEAD_DRV		EQU		(1<<4)	; Drive Select (0=Master, 1=Slave)
+MASK_DRVNHEAD_HEAD		EQU		0Fh		; Head select bits (bits 0...3)
+MASK_DRVNHEAD_SET		EQU		0A0h	; Bits that must be set to 1 on ATA1 (reserved on ATA2+)
 
 ; Bit definitions for IDE Status Register
-FLG_IDE_ST_BSY			EQU		(1<<7)	; Busy (other flags undefined when set)
-FLG_IDE_ST_DRDY			EQU		(1<<6)	; Device Ready
-FLG_IDE_ST_DF			EQU		(1<<5)	; Device Fault (command dependent on ATA4+)
-FLG_IDE_ST_DSC			EQU		(1<<4)	; Device Seek Complete (command dependent on ATA4+)
-FLG_IDE_ST_DRQ			EQU		(1<<3)	; Data Request
-FLG_IDE_ST_CORR			EQU		(1<<2)	; Corrected Data (obsolete on ATA4+)
-FLG_IDE_ST_IDX			EQU		(1<<1)	; Index (vendor specific on ATA2+, obsolete on ATA4+)
-FLG_IDE_ST_ERR			EQU		(1<<0)	; Error
+FLG_STATUS_BSY			EQU		(1<<7)	; Busy (other flags undefined when set)
+FLG_STATUS_DRDY			EQU		(1<<6)	; Device Ready
+FLG_STATUS_DF			EQU		(1<<5)	; Device Fault (command dependent on ATA4+)
+FLG_STATUS_DSC			EQU		(1<<4)	; Device Seek Complete (command dependent on ATA4+)
+FLG_STATUS_DRQ			EQU		(1<<3)	; Data Request
+FLG_STATUS_CORR			EQU		(1<<2)	; Corrected Data (obsolete on ATA4+)
+FLG_STATUS_IDX			EQU		(1<<1)	; Index (vendor specific on ATA2+, obsolete on ATA4+)
+FLG_STATUS_ERR			EQU		(1<<0)	; Error
 
 ; Bit definitions for IDE Device Control Register
 ; Bit 0 must be zero, unlisted bits are reserved.
-FLG_IDE_CTRL_O8H		EQU		(1<<3)	; Drive has more than 8 heads (pre-ATA only, 1 on ATA1, reserved on ATA2+)
-FLG_IDE_CTRL_SRST		EQU		(1<<2)	; Software Reset
-FLG_IDE_CTRL_nIEN		EQU		(1<<1)	; Negated Interrupt Enable (IRQ disabled when set)
-
+FLG_DEVCONTROL_HOB		EQU		(1<<7)	; High Order Byte (ATA6+)
+;FLG_DEVCONTROL_O8H		EQU		(1<<3)	; Drive has more than 8 heads (pre-ATA only, 1 on ATA1, reserved on ATA2+)
+FLG_DEVCONTROL_SRST		EQU		(1<<2)	; Software Reset
+FLG_DEVCONTROL_nIEN		EQU		(1<<1)	; Negated Interrupt Enable (IRQ disabled when set)
 
 ; Commands for IDE Controller
-;HCMD_RECALIBRATE		EQU		10h		; Recalibrate
-HCMD_READ_SECT			EQU		20h		; Read Sectors (with retries)
-HCMD_WRITE_SECT			EQU		30h		; Write Sectors (with retries)
-HCMD_VERIFY_SECT		EQU		40h		; Read Verify Sectors (with retries)
-;HCMD_FORMAT			EQU		50h		; Format track
-HCMD_SEEK				EQU		70h		; Seek
-;HCMD_DIAGNOSTIC		EQU		90h		; Execute Device Diagnostic
-HCMD_INIT_DEV			EQU		91h		; Initialize Device Parameters
-HCMD_READ_MUL			EQU		0C4h	; Read Multiple (=block)
-HCMD_WRITE_MUL			EQU		0C5h	; Write Multiple (=block)
-HCMD_SET_MUL			EQU		0C6h	; Set Multiple Mode (=block size)
-HCMD_ID_DEV				EQU		0ECh	; Identify Device
-HCMD_SET_FEAT			EQU		0EFh	; Set Features
-
-; Set Features subcommands
-HFEAT_SET_XFER_MODE		EQU		03h		; Set transfer mode based on value in Sector Count register
+COMMAND_READ_SECTORS					EQU		20h
+COMMAND_READ_SECTORS_EXT				EQU		24h		; LBA48
+COMMAND_WRITE_SECTORS					EQU		30h
+COMMAND_WRITE_SECTORS_EXT				EQU		34h		; LBA48
+COMMAND_VERIFY_SECTORS					EQU		40h
+COMMAND_VERIFY_SECTORS_EXT				EQU		42h		; LBA48
+COMMAND_SEEK							EQU		70h
+COMMAND_INITIALIZE_DEVICE_PARAMETERS	EQU		91h
+COMMAND_SET_MULTIPLE_MODE				EQU		0C6h	; Block mode
+COMMAND_READ_MULTIPLE					EQU		0C4h	; Block mode
+COMMAND_READ_MULTIPLE_EXT				EQU		29h		; LBA48, Block mode
+COMMAND_WRITE_MULTIPLE					EQU		0C5h	; Block mode
+COMMAND_WRITE_MULTIPLE_EXT				EQU		39h		; LBA48, Block mode
+COMMAND_IDENTIFY_DEVICE					EQU		0ECh
+COMMAND_SET_FEATURES					EQU		0EFh
 
 
Index: trunk/XTIDE_Universal_BIOS/Inc/Int13h.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/Int13h.inc	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Inc/Int13h.inc	(revision 150)
@@ -1,7 +1,3 @@
-; File name		:	Int13h.inc
-; Project name	:	IDE BIOS
-; Created date	:	23.3.2010
-; Last update	:	29.7.2010
-; Author		:	Tomi Tilli
+; Project name	:	XTIDE Universal BIOS
 ; Description	:	Equates used in INT 13h functions.
 %ifndef INT13H_INC
@@ -40,14 +36,4 @@
 
 
-; Timeout values for IDE controller timeout
-; 255 is the maximum value. Zero means immediate timeout.
-B_TIMEOUT_BSY			EQU		(1000/55)	; 1000 ms
-B_TIMEOUT_RDY			EQU		(1000/55)	; 1000 ms
-B_TIMEOUT_DRQ			EQU		255			;   14 s (some CF cards occasionally have long write delays)
-B_TIMEOUT_DRVINFO		EQU		(500/55)	;  500 ms
-B_TIMEOUT_RESET			EQU		255			;   14 s
-
-
-
 ; Floppy Drive types returned by INT 13h, AH=08h
 FLOPPY_TYPE_525_OR_35_DD	EQU	0
@@ -59,3 +45,8 @@
 
 
+MAX_SUPPORTED_BLOCK_SIZE_IN_SECTORS		EQU		64
+
+%define TIMEOUT_AND_STATUS_TO_WAIT(timeout, status)		(((timeout)<<8) | (status))
+
+
 %endif ; INT13H_INC
Index: trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 150)
@@ -5,5 +5,5 @@
 
 ; Segment when RAMVARS is stored to top of interrupt vectors.
-SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS		EQU		30h
+LITE_MODE_RAMVARS_SEGMENT	EQU		30h
 
 
@@ -21,6 +21,7 @@
 struc RAMVARS
 	.fpOldI13h			resb	4	; Far pointer to old INT 13h handler
-	.wIdeBase			resb	2	; Base port address for currently handled controller
 	.wTimeoutCounter	resb	2
+	.pInServiceDPT		resb	2	; Ptr to DPT for drive waiting for interrupt
+	.wSignature			resb	2	; Sign for finding stolen 1 kiB
 
 	.wDrvCntAndFirst:
@@ -32,11 +33,37 @@
 endstruc
 
-; Full mode RAM variables.
-struc FULLRAMVARS
-	.ramVars			resb	RAMVARS_size
-	.wSign				resb	2		; FULLRAMVARS signature for finding segment
+RAMVARS_SIGNATURE		EQU	"Xu"	; RAMVARS signature for .wSignature
+
+
+struc IDEPACK
+	.bDrvAndHead			resb	1	; LBA28 27...24
+	.bFeatures				resb	1
+
+	.wSectorCountAndLbaLow:
+	.bSectorCount			resb	1
+	.bSectorNumber:
+	.bLbaLow				resb	1	; LBA 7...0
+
+	.wCylinder:
+	.wLbaMiddleAndHigh:
+	.bLbaMiddle				resb	1	; LBA 15...8
+	.bLbaHigh				resb	1	; LBA 23...16
+
+	.bCommand				resb	1
+	.bDeviceControl			resb	1	; Offset 7 shared with PIOVARS
+
+	; Parameters for 48-bit LBA
+	.wSectorCountHighAndLbaLowExt:
+	.bSectorCountHighExt	resb	1	; LBA48 Sector Count 15...8
+	.bLbaLowExt				resb	1	; LBA48 31...24
+
+	.wLbaMiddleAndHighExt:
+	.bLbaMiddleExt			resb	1	; LBA48 39...32
+	.bLbaHighExt			resb	1	; LBA48 47...40
+
+	.intpack				resb	INTPACK_size
 endstruc
 
-W_SIGN_FULLRAMVARS		EQU	"fR"		; FULLRAMVARS signature
+EXTRA_WORDS_TO_RESERVE_FOR_INTPACK	EQU	((IDEPACK_size - INTPACK_size) / 2)
 
 
Index: trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc
===================================================================
--- trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Inc/RomVars.inc	(revision 150)
@@ -41,5 +41,5 @@
 	.wPort				resb	2	; IDE Base Port for Command Block (usual) Registers
 	.wPortCtrl			resb	2	; IDE Base Port for Control Block Registers
-	.bBusType			resb	1	; Bus type
+	.bDevice			resb	1	; Device type
 	.bIRQ				resb	1	; Interrupt Request Number
 	.drvParamsMaster	resb	DRVPARAMS_size
@@ -47,9 +47,11 @@
 endstruc
 
-; Bus types for IDEVARS.bBusType
-BUS_TYPE_8_DUAL			EQU	(0<<1)	; XTIDE transfers with two 8-bit data ports
-BUS_TYPE_16				EQU	(1<<1)	; Normal 16-bit AT-IDE transfers
-BUS_TYPE_32				EQU	(2<<1)	; 32-bit VLB and PCI transfers
-BUS_TYPE_8_SINGLE		EQU	(3<<1)	; 8-bit transfers with single 8-bit data port
+; Device types for IDEVARS.bDeviceType
+DEVICE_8BIT_DUAL_PORT_XTIDE				EQU	(0<<1)
+DEVICE_XTIDE_WITH_REVERSED_A3_AND_A0	EQU	(1<<1)
+DEVICE_8BIT_SINGLE_PORT					EQU	(2<<1)
+DEVICE_16BIT_ATA						EQU	(3<<1)
+DEVICE_32BIT_ATA						EQU	(4<<1)
+DEVICE_SERIAL_PORT						EQU	(5<<1)
 
 
