Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/AccessDPT.asm	(revision 150)
@@ -6,6 +6,57 @@
 
 ;--------------------------------------------------------------------
-; Returns L-CHS values from DPT.
-;
+; AccessDPT_GetDriveSelectByteToAL
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;	Returns:
+;		AL:		Drive Select Byte
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+AccessDPT_GetDriveSelectByteToAL:
+	mov		al, [di+DPT.wFlags]
+	and		al, FLG_DRVNHEAD_LBA | FLG_DRVNHEAD_DRV
+	or		al, MASK_DRVNHEAD_SET	; Bits set to 1 for old drives
+	ret
+
+
+;--------------------------------------------------------------------
+; AccessDPT_GetDeviceControlByteToAL
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;	Returns:
+;		AL:		Device Control Byte
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+AccessDPT_GetDeviceControlByteToAL:
+	xor		al, al
+	test	BYTE [di+DPT.wFlags], FLG_DPT_ENABLE_IRQ
+	jnz		SHORT .EnableDeviceIrq
+	or		al, FLG_DEVCONTROL_nIEN	; Disable IRQ
+.EnableDeviceIrq:
+	ret
+
+
+;--------------------------------------------------------------------
+; AccessDPT_GetAddressingModeForWordLookToBX
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;	Returns:
+;		BX:		Addressing Mode (L-CHS, P-CHS, LBA28, LBA48) shifted for WORD lookup
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+AccessDPT_GetAddressingModeForWordLookToBX:
+	mov		bl, [di+DPT.wFlags]
+	and		bx, BYTE MASK_DPT_ADDRESSING_MODE
+	eSHR_IM	bx, ADDRESSING_MODE_FIELD_POSITION-1
+	ret
+
+
+;--------------------------------------------------------------------
 ; AccessDPT_GetLCHSfromPCHS
 ;	Parameters:
@@ -21,16 +72,15 @@
 AccessDPT_GetLCHSfromPCHS:
 	xchg	ax, cx
-	mov		cl, [di+DPT.bShLtoP]		; Load shift count
-	mov		bx, [di+DPT.wPCyls]			; Load P-CHS cylinders
-	shr		bx, cl						; Shift to L-CHS cylinders
+	mov		cl, [di+DPT.wFlags]
+	and		cl, MASK_DPT_CHS_SHIFT_COUNT	; Load shift count
+	mov		bx, [di+DPT.wPchsCylinders]		; Load P-CHS cylinders
+	shr		bx, cl							; Shift to L-CHS cylinders
 	xchg	cx, ax
-	mov		dx, [di+DPT.wLHeads]		; Load L-CHS heads
-	eMOVZX	ax, BYTE [di+DPT.bPSect]	; Load Sectors per track
+	eMOVZX	dx, BYTE [di+DPT.bLchsHeads]	; Load L-CHS heads
+	eMOVZX	ax, BYTE [di+DPT.bPchsSectors]	; Load Sectors per track
 	ret
 
 
 ;--------------------------------------------------------------------
-; Tests IDEVARS flags for master or slave drive.
-;
 ; AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
 ;	Parameters:
@@ -63,11 +113,9 @@
 ALIGN JUMP_ALIGN
 AccessDPT_GetPointerToDRVPARAMStoCSBX:
-	eMOVZX	bx, [di+DPT.bIdeOff]		; CS:BX points to IDEVARS
-	test	BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_DRV
-	jnz		SHORT .ReturnPointerToSlaveDRVPARAMS
-	add		bx, BYTE IDEVARS.drvParamsMaster
+	eMOVZX	bx, [di+DPT.bIdevarsOffset]			; CS:BX points to IDEVARS
+	add		bx, BYTE IDEVARS.drvParamsMaster	; CS:BX points to Master Drive DRVPARAMS
+	test	BYTE [di+DPT.wFlags], FLG_DPT_SLAVE
+	jz		SHORT .ReturnPointerToDRVPARAMS
+	add		bx, BYTE DRVPARAMS_size				; CS:BX points to Slave Drive DRVPARAMS
+.ReturnPointerToDRVPARAMS:
 	ret
-ALIGN JUMP_ALIGN
-.ReturnPointerToSlaveDRVPARAMS:
-	add		bx, BYTE IDEVARS.drvParamsSlave
-	ret
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 150)
@@ -25,5 +25,5 @@
 ;--------------------------------------------------------------------
 CreateDPT_FromAtaInformation:
-	call	FindDPT_ForNewDrive		; Get new DPT to DS:DI
+	call	FindDPT_ForNewDriveToDSDI
 	; Fall to .InitializeDPT
 
@@ -35,21 +35,15 @@
 ;		CS:BP:	Ptr to IDEVARS for the controller
 ;	Returns:
-;		AX:		Zero
-;	Corrupts registers:
-;		Nothing
+;		Nothing
+;	Corrupts registers:
+;		AX
 ;--------------------------------------------------------------------
 .InitializeDPT:
-	xor		ax, ax
-	mov		BYTE [di+DPT.bSize], DPT_size
-	mov		[di+DPT.wDrvNumAndFlags], ax
-	mov		BYTE [di+DPT.bReset], MASK_RESET_ALL
-	mov		[di+DPT.bIdeOff], bp
-	mov		[di+DPT.bDrvSel], bh
-	; Fall to .StoreDriveControlByte
-
-;--------------------------------------------------------------------
-; .StoreDriveControlByte
-;	Parameters:
-;		AX:		Zero
+	mov		[di+DPT.bIdevarsOffset], bp	; IDEVARS must start in first 256 bytes of ROM
+	; Fall to .StoreDriveSelectAndDriveControlByte
+
+;--------------------------------------------------------------------
+; .StoreDriveSelectAndDriveControlByte
+;	Parameters:
 ;		BH:		Drive Select byte for Drive and Head Register
 ;		DS:DI:	Ptr to Disk Parameter Table
@@ -61,14 +55,12 @@
 ;		AX
 ;--------------------------------------------------------------------
-.StoreDriveControlByte:
-	cmp		BYTE [cs:bp+IDEVARS.bIRQ], al	; Interrupts enabled?
-	jne		SHORT .CheckHeadCount
-	or		al, FLG_IDE_CTRL_nIEN			; Disable interrupts
-.CheckHeadCount:
-	cmp		BYTE [es:si+ATA1.wHeadCnt], 8	; 1...8 heads?
-	jbe		SHORT .StoreDrvCtrlByteToDPT
-	or		al, FLG_IDE_CTRL_O8H			; Over 8 heads (pre-ATA)
-.StoreDrvCtrlByteToDPT:
-	mov		[di+DPT.bDrvCtrl], al
+.StoreDriveSelectAndDriveControlByte:
+	mov		al, bh
+	and		ax, BYTE FLG_DRVNHEAD_DRV		; AL now has Master/Slave bit
+	cmp		[cs:bp+IDEVARS.bIRQ], ah		; Interrupts enabled?
+	jz		SHORT .StoreFlags				;  If not, do not set interrupt flag
+	or		al, FLG_DPT_ENABLE_IRQ
+.StoreFlags:
+	mov		[di+DPT.wFlags], ax
 	; Fall to .StorePCHS
 
@@ -76,5 +68,4 @@
 ; .StorePCHS
 ;	Parameters:
-;		AH:		Zero
 ;		BH:		Drive Select byte for Drive and Head Register
 ;		DS:DI:	Ptr to Disk Parameter Table
@@ -99,9 +90,8 @@
 	mov		ax, [cs:bx+DRVPARAMS.wCylinders]
 	mov		bx, [cs:bx+DRVPARAMS.wHeadsAndSectors]
-	or		BYTE [di+DPT.bFlags], FLG_DPT_USERCHS
 
 .StorePCHStoDPT:
-	mov		[di+DPT.wPCyls], ax
-	mov		[di+DPT.wHeadsAndSectors], bx
+	mov		[di+DPT.wPchsCylinders], ax
+	mov		[di+DPT.wPchsHeadsAndSectors], bx
 	; Fall to .StoreLCHS
 
@@ -129,11 +119,9 @@
 	jmp		SHORT .ShiftLoop
 
-.LimitHeadsTo255:
-	test	bh, bh						; 256 heads?
-	jz		SHORT .StoreLCHStoDPT		;  If less, no correction needed
-	dec		bx							; Limit to 255 heads since DOS does not support 256 heads
-.StoreLCHStoDPT:
-	mov		[di+DPT.bShLtoP], cl
-	mov		[di+DPT.wLHeads], bx
+.LimitHeadsTo255:						; DOS does not support drives with 256 heads
+	rcr		bh, 1						; Set CF if 256 heads
+	sbb		bl, 0						; Decrement to 255 if 256 heads
+	or		[di+DPT.wFlags], cl
+	mov		[di+DPT.bLchsHeads], bl
 	; Fall to .StoreAddressing
 
@@ -146,22 +134,27 @@
 ;		Nothing
 ;	Corrupts registers:
-;		Nothing
+;		AX, BX
 ;--------------------------------------------------------------------
 .StoreAddressing:
-	cmp		WORD [di+DPT.wPCyls], 1024		; L-CHS possible? (no translation needed)
-	jbe		SHORT .StoreBlockMode			;  If so, nothing needs to be changed
-	test	BYTE [di+DPT.bFlags], FLG_DPT_USERCHS
-	jnz		SHORT .StorePCHSaddressing		; Use user defined P-CHS
+	; Check if L-CHS addressing should be used
+	cmp		WORD [di+DPT.wPchsCylinders], 1024	; L-CHS possible? (no translation needed)
+	jbe		SHORT .StoreBlockMode				;  If so, nothing needs to be changed
+
+	; Check if P-CHS addressing should be used
+	mov		al, FLG_DRVPARAMS_USERCHS			; User specified CHS?
+	call	AccessDPT_TestIdeVarsFlagsForMasterOrSlaveDrive
+	jnz		SHORT .StorePCHSaddressing
 	test	WORD [es:si+ATA1.wCaps], A2_wCaps_LBA
-	jz		SHORT .StorePCHSaddressing		; Use P-CHS since LBA not supported
+	jz		SHORT .StorePCHSaddressing			; Use P-CHS since LBA not supported
+
+	; LBA needs to be used. Check if 48-bit LBA is supported
 	test	WORD [es:si+ATA6.wSetSup83], A6_wSetSup83_LBA48
-	jz		SHORT .StoreLBA28addressing		; Use LBA-28 since LBA-48 not supported
-	or		BYTE [di+DPT.bFlags], ADDR_DPT_LBA48<<1
+	jz		SHORT .StoreLBA28addressing			; Use LBA-28 since LBA-48 not supported
+	or		BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA48<<ADDRESSING_MODE_FIELD_POSITION
 .StoreLBA28addressing:
-	or		BYTE [di+DPT.bFlags], ADDR_DPT_LBA28<<1
-	or		BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_LBA
+	or		BYTE [di+DPT.wFlags], ADDRESSING_MODE_LBA28<<ADDRESSING_MODE_FIELD_POSITION
 	jmp		SHORT .StoreBlockMode
 .StorePCHSaddressing:
-	or		BYTE [di+DPT.bFlags], ADDR_DPT_PCHS<<1
+	or		BYTE [di+DPT.wFlags], ADDRESSING_MODE_PCHS<<ADDRESSING_MODE_FIELD_POSITION
 	; Fall to .StoreBlockMode
 
@@ -174,44 +167,25 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX
+;		Nothing
 ;--------------------------------------------------------------------
 .StoreBlockMode:
-	mov		al, 1						; Minimum block size is 1 sector
-	mov		ah, [es:si+ATA1.bBlckSize]	; Load max block size in sectors
-	mov		[di+DPT.wSetAndMaxBlock], ax
-	; Fall to .StoreEBIOSSupport
-
-;--------------------------------------------------------------------
-; .StoreEBIOSSupport
-;	Parameters:
-;		DS:DI:	Ptr to Disk Parameter Table
-;		ES:SI:	Ptr to 512-byte ATA information read from the drive
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		AX, BX, DX
-;--------------------------------------------------------------------
-.StoreEBIOSSupport:
-	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
-	jz		SHORT .StoreDriveNumberAndUpdateDriveCount	; No EBIOS support since small DPTs needed
-
-	mov		bl, [di+DPT.bFlags]
-	and		bx, BYTE MASK_DPT_ADDR						; Addressing mode
-	jmp		[cs:bx+.rgwAddrJmp]							; Jump to handle addressing mode
-.rgwAddrJmp:
-	dw		.StoreDriveNumberAndUpdateDriveCount		; ADDR_DPT_LCHS
-	dw		.StoreDriveNumberAndUpdateDriveCount		; ADDR_DPT_PCHS
-	dw		.SupportForLBA28							; ADDR_DPT_LBA28
-	dw		.SupportForLBA48							; ADDR_DPT_LBA48
-
-.SupportForLBA28:
-	sub		BYTE [di+DPT.bSize], 2		; Only 4 bytes for sector count
-.SupportForLBA48:
-	add		BYTE [di+DPT.bSize], EBDPT_size - DPT_size
-	or		BYTE [di+DPT.bFlags], FLG_DPT_EBIOS
-	call	AtaID_GetTotalSectorCount
-	mov		[di+EBDPT.twCapacity], ax
-	mov		[di+EBDPT.twCapacity+2], dx
-	mov		[di+EBDPT.twCapacity+4], bx
+	cmp		BYTE [es:si+ATA1.bBlckSize], 1	; Max block size in sectors
+	jbe		SHORT .BlockModeTransfersNotSupported
+	or		WORD [di+DPT.wFlags], FLG_DPT_BLOCK_MODE_SUPPORTED
+.BlockModeTransfersNotSupported:
+	; Fall to .StoreDeviceSpecificParameters
+
+;--------------------------------------------------------------------
+; .StoreDeviceSpecificParameters
+;	Parameters:
+;		DS:DI:	Ptr to Disk Parameter Table
+;		ES:SI:	Ptr to 512-byte ATA information read from the drive
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, DX
+;--------------------------------------------------------------------
+.StoreDeviceSpecificParameters:
+	call	Device_FinalizeDPT
 	; Fall to .StoreDriveNumberAndUpdateDriveCount
 
@@ -230,18 +204,14 @@
 ;--------------------------------------------------------------------
 .StoreDriveNumberAndUpdateDriveCount:
-	; Make sure that more drives can be accepted
-	mov		dl, [es:BDA.bHDCount]	; Load number of hard disks
-	test	dl, dl					; Hard disks at maximum?
-	stc								; Assume error
-	js		SHORT .TooManyDrives	;  If so, return
-
-	; Store drive number to DPT
-	or		dl, 80h					; Set bit 7 since hard disk
-	mov		[di+DPT.bDrvNum], dl	; Store drive number
-
-	; Update BDA and RAMVARS
-	inc		BYTE [es:BDA.bHDCount]	; Increment drive count to BDA
-	call	RamVars_IncrementHardDiskCount
+	mov		dl, [es:BDA.bHDCount]
+	or		dl, 80h						; Set bit 7 since hard disk
+
+	inc		BYTE [RAMVARS.bDrvCnt]		; Increment drive count to RAMVARS
+	inc		BYTE [es:BDA.bHDCount]		; Increment drive count to BDA
+
+	cmp		BYTE [RAMVARS.bFirstDrv], 0	; First drive set?
+	ja		SHORT .AllDone				;  If so, return
+	mov		[RAMVARS.bFirstDrv], dl		; Store first drive number
+.AllDone:
 	clc
-.TooManyDrives:
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm	(revision 150)
@@ -1,7 +1,3 @@
-; File name		:	FindDPT.asm
-; Project name	:	IDE BIOS
-; Created date	:	14.3.2010
-; Last update	:	12.4.2010
-; Author		:	Tomi Tilli
+; Project name	:	XTIDE Universal BIOS
 ; Description	:	Functions for finding Disk Parameter Table.
 
@@ -12,5 +8,5 @@
 ; Finds pointer to first unused Disk Parameter Table.
 ;
-; FindDPT_ForNewDrive
+; FindDPT_ForNewDriveToDSDI
 ;	Parameters:
 ;		DS:		RAMVARS segment
@@ -18,86 +14,11 @@
 ;		DS:DI:	Ptr to first unused DPT
 ;	Corrupts registers:
-;		Nothing
+;		DL
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-FindDPT_ForNewDrive:
-	push	si
-	mov		si, FindDPT_ReturnWrongDPT
-	jmp		SHORT FindDPT_StartIterationAndReturnAfterDone
-
-
-;--------------------------------------------------------------------
-; Finds Disk Parameter Table for
-; Master or Slave drive at wanted port.
-;
-; FindDPT_ForIdeSlaveAtPort
-; FindDPT_ForIdeMasterAtPort
-;	Parameters:
-;		DX:		IDE Base Port address
-;		DS:		RAMVARS segment
-;	Returns:
-;		DL:		Drive number (if DPT found)
-;		DS:DI:	Ptr to DPT
-;		CF:		Set if wanted DPT found
-;				Cleared if DPT not found
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-FindDPT_ForIdeSlaveAtPort:
-	push	si
-	mov		si, FindDPT_IterateToSlaveAtPortCallback
-	jmp		SHORT FindDPT_StartIterationAndReturnAfterDone
-
-ALIGN JUMP_ALIGN
-FindDPT_ForIdeMasterAtPort:
-	push	si
-	mov		si, FindDPT_IterateToMasterAtPortCallback
-	jmp		SHORT FindDPT_StartIterationAndReturnAfterDone
-
-;--------------------------------------------------------------------
-; Iteration callback for finding DPT using
-; IDE base port for Master or Slave drive.
-;
-; FindDPT_IterateToSlaveAtPortCallback
-; FindDPT_IterateToMasterAtPortCallback
-;	Parameters:
-;		DX:		IDE Base Port address
-;		DS:DI:	Ptr to DPT to examine
-;	Returns:
-;		DL:		Drive number if correct DPT
-;		CF:		Set if wanted DPT found
-;				Cleared if wrong DPT
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-FindDPT_IterateToSlaveAtPortCallback:
-	test	BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_DRV
-	jnz		SHORT FindDPT_IterateToMasterOrSlaveAtPortCallback
-	jmp		SHORT FindDPT_ReturnWrongDPT	; Return if master drive
-
-ALIGN JUMP_ALIGN
-FindDPT_IterateToMasterAtPortCallback:
-	test	BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_DRV
-	jnz		SHORT FindDPT_ReturnWrongDPT	; Return if slave drive
-
-	; If BIOS partitioned, ignore all but first partition
-ALIGN JUMP_ALIGN
-FindDPT_IterateToMasterOrSlaveAtPortCallback:
-	test	BYTE [di+DPT.bFlags], FLG_DPT_PARTITION
-	jz		SHORT .CompareBasePortAddress
-	test	BYTE [di+DPT.bFlags], FLG_DPT_FIRSTPART
-	jz		SHORT FindDPT_ReturnWrongDPT
-ALIGN JUMP_ALIGN
-.CompareBasePortAddress:
-	push	bx
-	eMOVZX	bx, BYTE [di+DPT.bIdeOff]		; CS:BX now points to IDEVARS
-	cmp		dx, [cs:bx+IDEVARS.wPort]		; Wanted port?
-	pop		bx
-	jne		SHORT FindDPT_ReturnWrongDPT
-	mov		dl, [di+DPT.bDrvNum]			; Load drive number
-	stc										; Set CF since wanted DPT
-	ret
+FindDPT_ForNewDriveToDSDI:
+	mov		dl, [RAMVARS.bFirstDrv]
+	add		dl, [RAMVARS.bDrvCnt]
+	; Fall to FindDPT_ForDriveNumber
 
 
@@ -112,6 +33,4 @@
 ;	Returns:
 ;		DS:DI:	Ptr to DPT
-;		CF:		Set if wanted DPT found
-;				Cleared if DPT not found
 ;	Corrupts registers:
 ;		Nothing
@@ -119,19 +38,57 @@
 ALIGN JUMP_ALIGN
 FindDPT_ForDriveNumber:
-	push	si
-	mov		si, FindDPT_IterateToDriveNumberCallback
-FindDPT_StartIterationAndReturnAfterDone:
-	call	FindDPT_IterateAllDPTs
-	pop		si
+	push	dx
+	push	ax
+
+	mov		al, LARGEST_DPT_SIZE
+	sub		dl, [RAMVARS.bFirstDrv]
+	mul		dl
+	add		ax, BYTE RAMVARS_size
+	xchg	di, ax
+
+	pop		ax
+	pop		dx
 	ret
 
+
 ;--------------------------------------------------------------------
-; Iteration callback for finding DPT for drive number.
+; Finds Disk Parameter Table for
+; Master or Slave drive at wanted port.
 ;
-; FindDPT_IterateToDriveNumberCallback
+; FindDPT_ToDSDIForIdeMasterAtPortDX
+; FindDPT_ToDSDIForIdeSlaveAtPortDX
 ;	Parameters:
-;		DL:		Drive number to search for
+;		DX:		IDE Base Port address
+;		DS:		RAMVARS segment
+;	Returns:
+;		DL:		Drive number (if DPT found)
+;		DS:DI:	Ptr to DPT
+;		CF:		Set if wanted DPT found
+;				Cleared if DPT not found
+;	Corrupts registers:
+;		SI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+FindDPT_ToDSDIForIdeMasterAtPortDX:
+	mov		si, FindDPT_IterateToMasterAtPortCallback
+	jmp		SHORT IterateAllDPTs
+
+ALIGN JUMP_ALIGN
+FindDPT_ToDSDIForIdeSlaveAtPortDX:
+	mov		si, FindDPT_IterateToSlaveAtPortCallback
+	jmp		SHORT IterateAllDPTs
+
+;--------------------------------------------------------------------
+; Iteration callback for finding DPT using
+; IDE base port for Master or Slave drive.
+;
+; FindDPT_IterateToSlaveAtPortCallback
+; FindDPT_IterateToMasterAtPortCallback
+;	Parameters:
+;		CH:		Drive number
+;		DX:		IDE Base Port address
 ;		DS:DI:	Ptr to DPT to examine
 ;	Returns:
+;		DL:		Drive number if correct DPT
 ;		CF:		Set if wanted DPT found
 ;				Cleared if wrong DPT
@@ -140,18 +97,25 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-FindDPT_IterateToDriveNumberCallback:
-	cmp		dl, [di+DPT.bDrvNum]			; Wanted DPT found?
-	je		SHORT FindDPT_RightDriveNumber	;  If so, return
-FindDPT_ReturnWrongDPT:
-	clc										; Clear CF since wrong DPT
+FindDPT_IterateToSlaveAtPortCallback:
+	test	BYTE [di+DPT.wFlags], FLG_DPT_SLAVE	; Clears CF
+	jnz		SHORT CompareBasePortAddress
+	ret		; Wrong DPT
+
+ALIGN JUMP_ALIGN
+FindDPT_IterateToMasterAtPortCallback:
+	test	BYTE [di+DPT.wFlags], FLG_DPT_SLAVE
+	jnz		SHORT ReturnWrongDPT				; Return if slave drive
+
+CompareBasePortAddress:
+	push	bx
+	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]	; CS:BX now points to IDEVARS
+	cmp		dx, [cs:bx+IDEVARS.wPort]			; Wanted port?
+	pop		bx
+	jne		SHORT ReturnWrongDPT
+	mov		dl, ch								; Return drive number in DL
+	stc											; Set CF since wanted DPT
 	ret
-ALIGN JUMP_ALIGN
-FindDPT_RightDriveNumber:
-	push	bx
-	eMOVZX	bx, BYTE [di+DPT.bIdeOff]		; CS:BX now points to IDEVARS
-	mov		bx, [cs:bx+IDEVARS.wPort]		; Load IDE Base Port address...
-	mov		[RAMVARS.wIdeBase], bx			; ...and store it to RAMVARS
-	pop		bx
-	stc
+ReturnWrongDPT:
+	clc											; Clear CF since wrong DPT
 	ret
 
@@ -160,5 +124,5 @@
 ; Iterates all Disk Parameter Tables.
 ;
-; FindDPT_IterateAllDPTs
+; IterateAllDPTs
 ;	Parameters:
 ;		BX,DX:	Parameters to callback function
@@ -170,26 +134,24 @@
 ;				Cleared if DPT not found
 ;	Corrupts registers:
-;		Nothing, unless corrupted by callback function
+;		Nothing unless corrupted by callback function
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-FindDPT_IterateAllDPTs:
-	push	ax
+IterateAllDPTs:
 	push	cx
+	mov		cx, [RAMVARS.wDrvCntAndFirst]
+	jcxz	.AllDptsIterated			; Return if no drives
 	call	FindDPT_PointToFirstDPT		; Point DS:DI to first DPT
-	eMOVZX	cx, BYTE [RAMVARS.bDrvCnt]	; Load number of drives
-	xor		ax, ax						; Zero AX for DPT size and clear CF
-	jcxz	.Return						; Return if no drives
 ALIGN JUMP_ALIGN
 .LoopWhileDPTsLeft:
 	call	si							; Is wanted DPT?
-	jc		SHORT .Return				;  If so, return
-	mov		al, [di+DPT.bSize]			; Load DPT size to AX
-	add		di, ax						; Point to next DPT
-	loop	.LoopWhileDPTsLeft			; Check next DPT
+	jc		SHORT .AllDptsIterated		;  If so, return
+	inc		ch							; Increment drive number
+	add		di, BYTE LARGEST_DPT_SIZE	; Point to next DPT
+	dec		cl							; Decrement drives left
+	jnz		SHORT .LoopWhileDPTsLeft
 	clc									; Clear CF since DPT not found
 ALIGN JUMP_ALIGN
-.Return:
+.AllDptsIterated:
 	pop		cx
-	pop		ax
 	ret
 
@@ -209,8 +171,3 @@
 FindDPT_PointToFirstDPT:
 	mov		di, RAMVARS_size
-	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
-	jz		SHORT .Return							; RAMVARS used (top of interrupt vectors)
-	add		di, BYTE FULLRAMVARS_size-RAMVARS_size	; FULLRAMVARS used (top of base memory)
-ALIGN JUMP_ALIGN
-.Return:
 	ret
Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 148)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 150)
@@ -40,6 +40,6 @@
 	eSHL_IM	ax, 6						; Segment to first stolen kB (*=40h)
 	mov		ds, ax
-	mov		WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
-	; Fall to .InitializeRamvarsFromDS
+	mov		WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
+	; Fall to .InitializeRamvars
 
 ;--------------------------------------------------------------------
@@ -59,4 +59,5 @@
 	pop		es
 	call	Memory_ZeroESDIwithSizeInCX
+	mov		WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
 	; Fall to .InitializeDriveTranslationAndReturn
 
@@ -92,5 +93,5 @@
 	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
 	jnz		SHORT .GetStolenSegmentToDS
-	mov		di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
+	mov		di, LITE_MODE_RAMVARS_SEGMENT
 	mov		ds, di
 	ret
@@ -105,5 +106,5 @@
 	mov		ds, di					; EBDA segment to DS
 	add		di, BYTE 64				; DI to next stolen kB
-	cmp		WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
+	cmp		WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
 	jne		SHORT .LoopStolenKBs	; Loop until sign found (always found eventually)
 	ret
@@ -167,23 +168,4 @@
 
 ;--------------------------------------------------------------------
-; RamVars_IncrementHardDiskCount
-;	Parameters:
-;		DL:		Drive number for new drive
-;		DS:		RAMVARS segment
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-RamVars_IncrementHardDiskCount:
-	inc		BYTE [RAMVARS.bDrvCnt]		; Increment drive count to RAMVARS
-	cmp		BYTE [RAMVARS.bFirstDrv], 0	; First drive set?
-	ja		SHORT .Return				;  If so, return
-	mov		[RAMVARS.bFirstDrv], dl		; Store first drive number
-.Return:
-	ret
-
-
-;--------------------------------------------------------------------
 ; RamVars_GetHardDiskCountFromBDAtoCX
 ;	Parameters:
