Index: /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Inc/RamVars.inc	(revision 262)
@@ -10,8 +10,4 @@
 ; Variables for translating drive numbers.
 struc XLATEVARS
-	.wFDandHDswap:
-	.bFDSwap			resb	1	; Floppy Drive to swap to 00h and vice versa
-	.bHDSwap			resb	1	; Hard Drive to swap to 80h and vice versa
-	.bXlatedDrv			resb	1	; Drive number after translation
 %ifdef MODULE_SERIAL_FLOPPY
 	.bFlopCreateCnt:
@@ -23,4 +19,8 @@
 						resb	1	; alignment
 %endif
+	.bXlatedDrv			resb	1	; Drive number after translation
+	.wFDandHDswap:
+	.bFDSwap			resb	1	; Floppy Drive to swap to 00h and vice versa
+	.bHDSwap			resb	1	; Hard Drive to swap to 80h and vice versa
 endstruc
 
@@ -36,4 +36,6 @@
 	.wDrvCntAndFirst:
 	.bFirstDrv			resb	1	; Number of first drive for this BIOS
+	.wDrvCntAndFlopCnt:				; Both the hard disk and floppy counts in one word
+									; (yes, misaligned, but it is only used this way during initialization)
 	.bDrvCnt			resb	1	; Number of drives handled by this BIOS
 
@@ -41,4 +43,12 @@
 	.xlateVars		resb	XLATEVARS_size
 endstruc
+
+%ifdef MODULE_SERIAL_FLOPPY
+  %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+	%if RAMVARS.xlateVars != RAMVARS.bDrvCnt+1 || XLATEVARS.bFlopCreateCnt != 0
+		%error "bFlopCreateCnt needs to be the first thing in XLATEVARS, and .xlateVars needs to come immediately after .bDrvCnt.  In at least one place, we read .wDrvCntAndFlopCnt to get both counts in one fetch"
+	%endif
+  %endif
+%endif
 
 RAMVARS_SIGNATURE		EQU	"Xu"	; RAMVARS signature for .wSignature
Index: /trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Boot/BootMenuPrint.asm	(revision 262)
@@ -23,5 +23,5 @@
 	mov		bp, sp
 
-	call	RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber
+	call	FindDPT_ForDriveNumberInDL
 	jc		.notOurs
 
@@ -111,12 +111,11 @@
 	mov		si, g_szCapacity							; Setup print string now, carries through to print call
 
-	xor		di, di										; Zero DI for checks for our drive later on
-	call	RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber
-
-	test	dl, dl										; are we a hard disk?
-	js		BootMenuPrint_HardDiskRefreshInformation	
-
-	test	di, di
-	jnz		.ours										; Based on CF from RamVars_IsDriveHandledByThisBIOS above
+	call	FindDPT_ForDriveNumberInDL
+
+	inc		dl											; are we a hard disk?
+	dec		dl											; inc/dec will set SF, without modifying CF or DL
+	js		.HardDiskRefreshInformation	
+
+	jnc		.ours										; Based on CF from FindDPT_ForDriveNumberInDL above
 	call	FloppyDrive_GetType							; Get Floppy Drive type to BX
 	jmp		.around
@@ -190,11 +189,10 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-BootMenuPrint_HardDiskRefreshInformation:		
-	test	di, di
-	jz		.HardDiskMenuitemInfoForForeignDrive		
+.HardDiskRefreshInformation:		
+	jc		.HardDiskMenuitemInfoForForeignDrive		; Based on CF from FindDPT_ForDriveNumberInDL (way) above
 
 .HardDiskMenuitemInfoForOurDrive:
-	ePUSH_T ax, g_szInformation						; Add substring for our hard disk information
-	call	BootMenuInfo_GetTotalSectorCount		; Get Total LBA Size
+	ePUSH_T ax, g_szInformation							; Add substring for our hard disk information
+	call	BootMenuInfo_GetTotalSectorCount			; Get Total LBA Size
 	jmp		.ConvertSectorCountInBXDXAXtoSizeAndPushForFormat
 		
Index: /trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Device/Serial/SerialCommand.asm	(revision 262)
@@ -639,5 +639,5 @@
 		pop		si
 %ifdef MODULE_SERIAL_FLOPPY
-		jc		.founddpt
+		jnc		.founddpt
 ;
 ; If not found above with FindDPT_ToDSDIforSerialDevice, DI will point to the DPT after the last hard disk DPT
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm	(revision 262)
@@ -26,11 +26,25 @@
 
 	call	RamVars_GetSegmentToDS
+		
 	call	DriveXlate_ToOrBack
 	mov		[RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
-	call	RamVars_IsFunctionHandledByThisBIOS
-	jc		SHORT Int13h_DirectCallToAnotherBios
-
-	call	FindDPT_ForDriveNumber		; DS:DI now points to DPT
-
+		
+	call	FindDPT_ForDriveNumberInDL				; DS:DI points to our DPT, or NULL if not our drive
+	jnc		SHORT .OurFunction						; DPT found, this is one of our drives, and thus our function
+
+	cmp		ah, 0
+	jz		short .OurFunction						; we handle all function 0h requests (resets)
+	cmp		ah, 8
+%ifdef MODULE_SERIAL_FLOPPY
+	jnz		SHORT Int13h_DirectCallToAnotherBios	; we handle all traffic for function 08h, 
+													; as we need to wrap both hard disk and floppy drive counts
+%else
+	jz		SHORT .WeHandleTheFunction				; we handle all *hard disk* (only) traffic for function 08h, 
+													; as we need to wrap the hard disk drive count
+	test	dl, dl
+	jns		SHORT Int13h_DirectCallToAnotherBios
+%endif		
+				
+.OurFunction:	
 	; Jump to correct BIOS function
 	eMOVZX	bx, ah
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH0h_HReset.asm	(revision 262)
@@ -121,6 +121,6 @@
 GetDriveNumberForForeignBiosesToDL:
 	mov		dl, bl
-	call	RamVars_IsDriveHandledByThisBIOS
-	jc		SHORT .Return				; Return what was in BL unmodified
+	test	di, di
+	jz		SHORT .Return				; Return what was in BL unmodified
 	mov		dl, 80h
 .Return:
@@ -141,69 +141,29 @@
 ALIGN JUMP_ALIGN
 AH0h_ResetHardDisksHandledByOurBIOS:
-	mov		dx, [RAMVARS.wDrvCntAndFirst]	; DL = drive number, DH = drive count
-	test	dh, dh
-	jz		SHORT .AllDrivesReset		; Return if no drives
-	add		dh, dl						; DH = one past last drive to reset
-ALIGN JUMP_ALIGN
-.DriveResetLoop:
-	call	AHDh_ResetDrive
-	call	.BackupErrorCodeFromMasterOrSlaveToBH
-	inc		dx
-	cmp		dl, dh						; All done?
-	jb		SHORT .DriveResetLoop		;  If not, reset next drive
-.AllDrivesReset:
+	mov		bl, [di+DPT.bIdevarsOffset]					; replace drive number with Idevars pointer for comparisons
+	mov		cl, [cs:ROMVARS.bIdeCnt]					; get count of ide controllers
+	mov		ch, 0										
+	mov		dl, 0										; starting Idevars offset
+	mov		si, IterateFindFirstDPTforIdevars			; iteration routine
+.loop:
+	call	IterateAllDPTs								; look for the first drive on this controller, if any
+	jc		.notFound
+	call	AHDh_ResetDrive								; reset master and slave on that controller
+	call	BackupErrorCodeFromTheRequestedDriveToBH	; save error code if same controller as initial request
+.notFound:
+	add		dl, IDEVARS_size							; move pointer forward
+	loop	.loop										; and repeat
 	ret
 
-				
 ;--------------------------------------------------------------------
-; .BackupErrorCodeFromMasterOrSlaveToBH
-;	Parameters:
-;		AH:		Error code for drive DL reset
-;		BL:		Requested drive (DL when entering AH=00h)
-;		DL:		Drive just resetted
-;		DS:		RAMVARS segment
-;	Returns:
-;		BH:		Backuped error code
-;		DL:		Incremented if next drive is slave drive
-;				(=already resetted)
-;	Corrupts registers:
-;		CX, DI
+; Iteration routine for AH0h_ResetHardDisksHandledByOurBIOS, 
+; for use with IterateAllDPTs
+; 
+; Returns when DPT is found on the controller with Idevars offset in DL
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.BackupErrorCodeFromMasterOrSlaveToBH:
-	call	BackupErrorCodeFromTheRequestedDriveToBH
-	call	GetBasePortToCX				; Load base port for resetted drive
-	push	cx
-	inc		dx							; DL to next drive
-	call	GetBasePortToCX
-	pop		di
-	cmp		cx, di						; Next drive is from same controller?
-	je		SHORT BackupErrorCodeFromTheRequestedDriveToBH
-.NoMoreDrivesOrNoSlaveDrive:
-	dec		dx
+IterateFindFirstDPTforIdevars:		
+	cmp		dl, [di+DPT.bIdevarsOffset]			; Clears CF if matched
+	jz		.done
+	stc											; Set CF for not found
+.done:	
 	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
-	mov		bl, [di+DPT.bIdevarsOffset]
-	mov		bx, [cs:bx+IDEVARS.wPort]
-	xchg	bx, cx
-	ret
-
-
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AH8h_HParams.asm	(revision 262)
@@ -25,7 +25,6 @@
 ;--------------------------------------------------------------------
 AH8h_HandlerForReadDiskDriveParameters:
-
-	call	RamVars_IsDriveHandledByThisBIOS
-	jnc		SHORT .OurDrive
+	test	di,di
+	jnz		SHORT .OurDrive
 
 	call	Int13h_CallPreviousInt13hHandler
Index: /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h/AHDh_HReset.asm	(revision 262)
@@ -40,5 +40,5 @@
 ;		CF:		0 if succesfull, 1 if error
 ;	Corrupts registers:
-;		AL, CX, SI, DI
+;		AL, CX, SI
 ;--------------------------------------------------------------------
 ;ALIGN JUMP_ALIGN
@@ -46,52 +46,42 @@
 	push	dx
 	push	bx
+	push	di
 
-	call	FindDPT_ForDriveNumber		; DS:DI now points to DPT
 	call	Interrupts_UnmaskInterruptControllerForDriveInDSDI
 	call	Device_ResetMasterAndSlaveController
-	;jc		SHORT .ReturnError			; CF would be set if slave drive present without master
-										; (error register has special values after reset)
+	;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
-	eMOVZX	bx, BYTE [di+DPT.bIdevarsOffset]
-	mov		dx, [cs:bx+IDEVARS.wPort]
-	call	InitializeMasterAndSlaveDriveFromPortInDX
+	mov		al, [di+DPT.bIdevarsOffset]			; pointer to controller we are looking to reset
+	mov		ah, 0								; initialize error code, assume success
+		
+	mov		si, IterateAndResetDrives
+	call	IterateAllDPTs
 
+	shr		ah, 1								; Move error code and CF into proper position
+
+	pop		di
 	pop		bx
 	pop		dx
 	ret
 
-
 ;--------------------------------------------------------------------
-; InitializeMasterAndSlaveDriveFromPortInDX
-;	Parameters:
-;		DX:		IDE Base Port address
-;		SS:BP:	Ptr to IDEPACK
-;	Returns:
-;		AH:		Error code
-;		CF:		0 if initialization succesfull
-;				1 if any error
-;	Corrupts registers:
-;		AL, BX, CX, DX, SI, DI
+; IterateAndResetDrives: Iteration routine for use with IterateAllDPTs.
+;
+; When a drive on the controller is found, it is reset, and the error code 
+; merged into overall error code for this controller.  Master will be reset
+; first.  Note that the iteration will go until the end of the DPT list.
 ;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-InitializeMasterAndSlaveDriveFromPortInDX:
-	push	dx							; Store base port address
-	xor		cx, cx						; Assume no errors
-	FindDPT_ToDSDIForIdeMasterAtPortDX
-	jnc		SHORT .InitializeSlave		; Master drive not present
-	call	AH9h_InitializeDriveForUse
-	mov		cl, ah						; Copy error code to CL
-.InitializeSlave:
-	pop		dx							; Restore base port address
-	FindDPT_ToDSDIForIdeSlaveAtPortDX
-	jnc		SHORT .CombineErrors		; Slave drive not present
-	call	AH9h_InitializeDriveForUse
-	mov		ch, ah						; Copy error code to CH
-.CombineErrors:
-	or		cl, ch						; OR error codes, clear CF
-	jz		SHORT .Return
-	mov		ah, RET_HD_RESETFAIL		; Load Reset Failed error code
-	stc
-.Return:
+IterateAndResetDrives:
+	cmp		al, [di+DPT.bIdevarsOffset]			; The right controller?
+	jnz		.done
+	push	ax
+	call	AH9h_InitializeDriveForUse			; Reset Master and Slave (Master will come first in DPT list)
+	pop		ax		
+	jc		.done
+	or		ah, (RET_HD_RESETFAIL << 1) | 1		; OR in Reset Failed error code and CF, will SHR into position later
+.done:
+	stc											; From IterateAllDPTs perspective, the DPT is never found
 	ret
+		
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 262)
@@ -37,5 +37,5 @@
 
 %ifdef MODULE_SERIAL
-	jcxz	.done							; Set to zero on .ideVarsSerialAuto iteration (if any)
+	jcxz	.AddHardDisks					; Set to zero on .ideVarsSerialAuto iteration (if any)
 %endif
 
@@ -48,5 +48,5 @@
 ;
 	call	FindDPT_ToDSDIforSerialDevice
-	jc		.done
+	jnc		.AddHardDisks
 
 	mov		bp, ROMVARS.ideVarsSerialAuto	; Point to our special IDEVARS structure, just for serial scans
@@ -58,14 +58,29 @@
 %endif
 
-.done:	
-%ifdef MODULE_SERIAL_FLOPPY
+.AddHardDisks:
 ;----------------------------------------------------------------------
 ;
-; Add in any emulated serial floppy drives.
-;
-	mov		al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
-	dec		al
-	mov		cl, al
-	js		.NoFloppies						; if no drives are present, we store 0ffh
+; Add in hard disks to BDA, finalize our Count and First variables
+;
+	mov		cx, [RAMVARS.wDrvCntAndFlopCnt]		; Our count of hard disks
+	test	cl, cl
+	jz		.AddFloppies				; If none, nothing more to do
+
+	mov		al, [es:BDA.bHDCount]
+	add		cl, al						; Add our drives to the system count
+	mov		[es:BDA.bHDCount], cl		
+	or		al, 80h						; Or in hard disk flag		
+	mov		[RAMVARS.bFirstDrv], al		; Store first drive number		
+
+
+.AddFloppies:		
+;%ifdef MODULE_SERIAL_FLOPPY		
+;----------------------------------------------------------------------
+;
+; Add in any emulated serial floppy drives, finalize our packed Count and First variables
+;
+	dec		ch
+	mov		al, ch
+	js		.NoFloppies						; if no drives are present, we store 0ffh		
 
 	call	FloppyDrive_GetCountFromBIOS_or_BDA
@@ -73,5 +88,5 @@
 	push	ax
 
-	add		al, cl							; Add our drives to existing drive count
+	add		al, ch							; Add our drives to existing drive count
 	cmp		al, 3							; For BDA, max out at 4 drives (ours is zero based)
 	jl		.MaxBDAFloppiesExceeded
@@ -92,9 +107,9 @@
 	pop		ax
 
-	shr		cl, 1							; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
+	shr		ch, 1							; number of drives, 1 or 2 only, to CF flag (clear=1, set=2)
 	rcl		al, 1							; starting drive number in upper 7 bits, number of drives in low bit
 .NoFloppies:	
 	mov		[RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst], al
-%endif
+;%endif
 		
 	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectPrint.asm	(revision 262)
@@ -43,5 +43,7 @@
 	mov		dx, [cs:bp+IDEVARS.bDevice-1]   ; for Serial: AL=port address>>2, AH=baud rate
 											;			  DL=COM number character, DH=.bDevice
-
+		
+	mov		si, g_szDetectOuter				; Load SI with default wrapper string "IDE %s at %s: "
+		
 	push	bp								; setup stack for call to
 	mov		bp, sp							; BootMenuPrint_FormatCSSIfromParamsInSSBP
@@ -72,5 +74,5 @@
 
 	test	dl, dl							; Check if serial port "Auto"
-	jz		.pushAndPrint					; CX = string to print, AX and DX won't be used
+	jz		.pushAndPrintSerial				; CX = string to print, AX and DX won't be used
 
 	mov		cl, (g_szDetectCOMLarge-$$) & 0xff	; Setup secondary print string for "COMn/xx.yK"
@@ -88,7 +90,10 @@
 
 	cmp		ax,si							; < 10: "2400", "9600", etc.; >= 10: "19.2K", "38.4K", etc.
-	jae		.pushAndPrint
+	jae		.pushAndPrintSerial
 
 	mov		cl, (g_szDetectCOMSmall-$$) & 0xff	; Setup secondary print string for "COMn/XXy00"
+
+.pushAndPrintSerial:	
+	mov		si, g_szDetectOuterSerial		; Finally load SI with wrapper string "Serial %s on %s: "		
 
 .pushAndPrint:
@@ -96,6 +101,4 @@
 	push	ax								; Push high order digits, or port address, or N/A
 	push	dx								; Push low order digit, or N/A
-
-	mov		si, g_szDetectOuter				; Finally load SI with wrapper string "IDE %s at %s: "
 
 	jmp		short DetectPrint_BootMenuPrint_FormatCSSIfromParamsInSSBP_Relay
Index: /trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Initialization/Initialize.asm	(revision 262)
@@ -72,5 +72,5 @@
 .StoreDptPointersToIntVectors:
 	mov		dl, 80h
-	call	RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber   ; DPT to DS:DI
+	call	FindDPT_ForDriveNumberInDL   ; DPT to DS:DI
 	jc		SHORT .FindForDrive81h	; Store nothing if not our drive
 	mov		[es:HD0_DPT_POINTER_41h*4], di
@@ -78,5 +78,5 @@
 .FindForDrive81h:
 	inc		dx
-	call	RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber
+	call	FindDPT_ForDriveNumberInDL
 	jc		SHORT .ResetDetectedDrives
 	mov		[es:HD1_DPT_POINTER_46h*4], di
Index: /trunk/XTIDE_Universal_BIOS/Src/Strings.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/Strings.asm	(revision 262)
@@ -17,7 +17,8 @@
 g_szDetectSlave:		db	"Slave ",NULL
 g_szDetectOuter:		db	"IDE %s at %s: ",NULL
+g_szDetectOuterSerial:	db	"Serial %s on %s: ",NULL		
 g_szDetectPort:			db	"%x",NULL					   	; IDE Master at 1F0h:
 g_szDetectCOM:			db  "COM%c%s",NULL
-g_szDetectCOMAuto:		db	" Auto",NULL
+g_szDetectCOMAuto:		db	" Detect",NULL
 g_szDetectCOMSmall:		db	"/%u%u00",NULL					; IDE Master at COM1/9600:
 g_szDetectEnd:
@@ -70,24 +71,4 @@
 	db	"Addr.",SINGLE_VERTICAL,"Block",SINGLE_VERTICAL,"Bus",SINGLE_VERTICAL,  "IRQ",SINGLE_VERTICAL,"Reset",LF,CR
 	db	   "%s",SINGLE_VERTICAL, "%5-u",SINGLE_VERTICAL, "%s",SINGLE_VERTICAL," %2-I",SINGLE_VERTICAL,"%5-x" ,NULL
-
-; Boot Menu Floppy Disk strings
-;
-; The following strings are used by BootMenuPrint_RefreshInformation
-; To support optimizations in that code, these strings must start on the same 256 byte page,
-; which is checked at assembly time below.
-;
-g_szFddStart:
-g_szFddUnknown:	db	"Unknown",NULL
-g_szFddSizeOr:	db	"5",ONE_QUARTER,QUOTATION_MARK," or 3",ONE_HALF,QUOTATION_MARK," DD",NULL
-g_szFddSize:	db	"%s",QUOTATION_MARK,", %u kiB",NULL	; 3½", 1440 kiB
-g_szFddThreeHalf:		db  "3",ONE_HALF,NULL
-g_szFddEnd:
-g_szFddFiveQuarter:		db  "5",ONE_QUARTER,NULL
-
-%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
-	%if ((g_szFddStart-$$) & 0xff00) <> ((g_szFddEnd-$$) & 0xff00)
-		%error "g_szFdd* strings must start on the same 256 byte page, required by the BootMenuPrint_RefreshInformation routines for floppy drives.  Please move this block up or down within strings.asm"
-	%endif
-%endif
 
 g_szAddressingModes:
@@ -151,4 +132,23 @@
 g_szDashForZero:		db		"- ",NULL
 
+; Boot Menu Floppy Disk strings
+;
+; The following strings are used by BootMenuPrint_RefreshInformation
+; To support optimizations in that code, these strings must start on the same 256 byte page,
+; which is checked at assembly time below.
+;
+g_szFddStart:
+g_szFddUnknown:	db	"Unknown",NULL
+g_szFddSizeOr:	db	"5",ONE_QUARTER,QUOTATION_MARK," or 3",ONE_HALF,QUOTATION_MARK," DD",NULL
+g_szFddSize:	db	"%s",QUOTATION_MARK,", %u kiB",NULL	; 3½", 1440 kiB
+g_szFddThreeHalf:		db  "3",ONE_HALF,NULL
+g_szFddEnd:
+g_szFddFiveQuarter:		db  "5",ONE_QUARTER,NULL
+
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+	%if ((g_szFddStart-$$) & 0xff00) <> ((g_szFddEnd-$$) & 0xff00)
+		%error "g_szFdd* strings must start on the same 256 byte page, required by the BootMenuPrint_RefreshInformation routines for floppy drives.  Please move this block up or down within strings.asm"
+	%endif
+%endif
 
 ;------------------------------------------------------------------------------------------
Index: /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/StringsCompressed.asm	(revision 262)
@@ -34,4 +34,8 @@
                 		  db	 4fh,  4ah, 0cbh,  3eh,  20h,  67h, 0fah,  3eh,  40h,  00h                                  ; compressed
 
+g_szDetectOuterSerial:	; db	"Serial %s on %s: ",NULL		
+                      	; db	 53h,  65h,  72h,  69h,  61h,  6ch,  20h,  25h,  73h,  20h,  6fh,  6eh,  20h,  25h,  73h,  3ah,  20h,  00h    ; uncompressed
+                      	  db	 59h,  6bh,  78h,  6fh,  67h, 0f2h,  3eh,  20h,  75h, 0f4h,  3eh,  40h,  00h                                  ; compressed
+
 g_szDetectPort:			; db	"%x",NULL					   	; IDE Master at 1F0h:
                			; db	 25h,  78h,  00h    ; uncompressed
@@ -42,7 +46,7 @@
               			  db   49h,  55h,  53h,  35h,  1eh                      ; compressed
 
-g_szDetectCOMAuto:		; db	" Auto",NULL
-                  		; db	 20h,  41h,  75h,  74h,  6fh,  00h    ; uncompressed
-                  		  db	 20h,  47h,  7bh,  7ah, 0b5h          ; compressed
+g_szDetectCOMAuto:		; db	" Detect",NULL
+                  		; db	 20h,  44h,  65h,  74h,  65h,  63h,  74h,  00h    ; uncompressed
+                  		  db	 20h,  4ah,  6bh,  7ah,  6bh,  69h, 0bah          ; compressed
 
 g_szDetectCOMSmall:		; db	"/%u%u00",NULL					; IDE Master at COM1/9600:
@@ -157,4 +161,100 @@
 
 
+g_szAddressingModes:
+g_szLCHS:		; db	"L-CHS",NULL
+         		; db	 4ch,  2dh,  43h,  48h,  53h,  00h    ; uncompressed
+         		  db	 52h,  28h,  49h,  4eh,  99h          ; compressed
+
+g_szPCHS:		; db	"P-CHS",NULL
+         		; db	 50h,  2dh,  43h,  48h,  53h,  00h    ; uncompressed
+         		  db	 56h,  28h,  49h,  4eh,  99h          ; compressed
+
+g_szLBA28:		; db	"LBA28",NULL
+          		; db	 4ch,  42h,  41h,  32h,  38h,  00h    ; uncompressed
+          		  db	 52h,  48h,  47h,  2ch,  11h          ; compressed
+
+g_szLBA48:		; db	"LBA48",NULL
+          		; db	 4ch,  42h,  41h,  34h,  38h,  00h    ; uncompressed
+          		  db	 52h,  48h,  47h,  2eh,  11h          ; compressed
+
+g_szAddressingModes_Displacement equ (g_szPCHS - g_szAddressingModes)
+;
+; Ensure that addressing modes are correctly spaced in memory
+;
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+%if g_szLCHS <> g_szAddressingModes
+%error "g_szAddressingModes Displacement Incorrect 1"
+%endif
+%if g_szPCHS <> g_szLCHS + g_szAddressingModes_Displacement
+%error "g_szAddressingModes Displacement Incorrect 2"
+%endif
+%if g_szLBA28 <> g_szPCHS + g_szAddressingModes_Displacement
+%error "g_szAddressingModes Displacement Incorrect 3"
+%endif
+%if g_szLBA48 <> g_szLBA28 + g_szAddressingModes_Displacement
+%error "g_szAddressingModes Displacement Incorrect 4"
+%endif
+%endif
+
+g_szBusTypeValues:
+g_szBusTypeValues_8Dual:		; db		"D8 ",NULL
+                        		; db		 44h,  38h,  20h,  00h    ; uncompressed
+                        		  db		 4ah,  31h,  00h          ; compressed
+
+g_szBusTypeValues_8Reversed:	; db		"X8 ",NULL
+                            	; db		 58h,  38h,  20h,  00h    ; uncompressed
+                            	  db		 5eh,  31h,  00h          ; compressed
+
+g_szBusTypeValues_8Single:		; db		"S8 ",NULL
+                          		; db		 53h,  38h,  20h,  00h    ; uncompressed
+                          		  db		 59h,  31h,  00h          ; compressed
+
+g_szBusTypeValues_16:			; db		" 16",NULL
+                     			; db		 20h,  31h,  36h,  00h    ; uncompressed
+                     			  db		 20h,  2bh,  10h          ; compressed
+
+g_szBusTypeValues_32:			; db		" 32",NULL
+                     			; db		 20h,  33h,  32h,  00h    ; uncompressed
+                     			  db		 20h,  2dh,  0ch          ; compressed
+
+g_szBusTypeValues_Serial:		; db		"SER",NULL
+                         		; db		 53h,  45h,  52h,  00h    ; uncompressed
+                         		  db		 59h,  4bh,  98h          ; compressed
+
+g_szBusTypeValues_Displacement equ (g_szBusTypeValues_8Reversed - g_szBusTypeValues)
+;
+; Ensure that bus type strings are correctly spaced in memory
+;
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+%if g_szBusTypeValues_8Dual <> g_szBusTypeValues
+%error "g_szBusTypeValues Displacement Incorrect 1"
+%endif
+%if g_szBusTypeValues_8Reversed <> g_szBusTypeValues + g_szBusTypeValues_Displacement
+%error "g_szBusTypeValues Displacement Incorrect 2"
+%endif
+%if g_szBusTypeValues_8Single <> g_szBusTypeValues_8Reversed + g_szBusTypeValues_Displacement
+%error "g_szBusTypeValues Displacement Incorrect 3"
+%endif
+%if g_szBusTypeValues_16 <> g_szBusTypeValues_8Single + g_szBusTypeValues_Displacement
+%error "g_szBusTypeValues Displacement Incorrect 4"
+%endif
+%if g_szBusTypeValues_32 <> g_szBusTypeValues_16 + g_szBusTypeValues_Displacement
+%error "g_szBusTypeValues Displacement Incorrect 5"
+%endif
+%if g_szBusTypeValues_Serial <> g_szBusTypeValues_32 + g_szBusTypeValues_Displacement
+%error "g_szBusTypeValues Displacement Incorrect 6"
+%endif
+%endif
+
+g_szSelectionTimeout:	; db		DOUBLE_BOTTOM_LEFT_CORNER,DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL,"%ASelection in %2-u s",NULL
+                     	; db		0c8h, 0b5h,  25h,  41h,  53h,  65h,  6ch,  65h,  63h,  74h,  69h,  6fh,  6eh,  20h,  69h,  6eh,  20h,  25h,  32h,  2dh,  75h,  20h,  73h,  00h    ; uncompressed
+                     	  db		 32h,  33h,  3dh,  59h,  6bh,  72h,  6bh,  69h,  7ah,  6fh,  75h, 0f4h,  6fh, 0f4h,  3ch,  20h, 0b9h                                              ; compressed
+
+
+g_szDashForZero:		; db		"- ",NULL
+                		; db		 2dh,  20h,  00h    ; uncompressed
+                		  db		 28h,  00h          ; compressed
+
+
 ; Boot Menu Floppy Disk strings
 ;
@@ -191,101 +291,4 @@
 %endif
 %endif
-
-g_szAddressingModes:
-g_szLCHS:		; db	"L-CHS",NULL
-         		; db	 4ch,  2dh,  43h,  48h,  53h,  00h    ; uncompressed
-         		  db	 52h,  28h,  49h,  4eh,  99h          ; compressed
-
-g_szPCHS:		; db	"P-CHS",NULL
-         		; db	 50h,  2dh,  43h,  48h,  53h,  00h    ; uncompressed
-         		  db	 56h,  28h,  49h,  4eh,  99h          ; compressed
-
-g_szLBA28:		; db	"LBA28",NULL
-          		; db	 4ch,  42h,  41h,  32h,  38h,  00h    ; uncompressed
-          		  db	 52h,  48h,  47h,  2ch,  11h          ; compressed
-
-g_szLBA48:		; db	"LBA48",NULL
-          		; db	 4ch,  42h,  41h,  34h,  38h,  00h    ; uncompressed
-          		  db	 52h,  48h,  47h,  2eh,  11h          ; compressed
-
-g_szAddressingModes_Displacement equ (g_szPCHS - g_szAddressingModes)
-;
-; Ensure that addressing modes are correctly spaced in memory
-;
-%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
-%if g_szLCHS <> g_szAddressingModes
-%error "g_szAddressingModes Displacement Incorrect 1"
-%endif
-%if g_szPCHS <> g_szLCHS + g_szAddressingModes_Displacement
-%error "g_szAddressingModes Displacement Incorrect 2"
-%endif
-%if g_szLBA28 <> g_szPCHS + g_szAddressingModes_Displacement
-%error "g_szAddressingModes Displacement Incorrect 3"
-%endif
-%if g_szLBA48 <> g_szLBA28 + g_szAddressingModes_Displacement
-%error "g_szAddressingModes Displacement Incorrect 4"
-%endif
-%endif
-
-g_szBusTypeValues:
-g_szBusTypeValues_8Dual:		; db		"D8 ",NULL
-                        		; db		 44h,  38h,  20h,  00h    ; uncompressed
-                        		  db		 4ah,  31h,  00h          ; compressed
-
-g_szBusTypeValues_8Reversed:	; db		"X8 ",NULL
-                            	; db		 58h,  38h,  20h,  00h    ; uncompressed
-                            	  db		 5eh,  31h,  00h          ; compressed
-
-g_szBusTypeValues_8Single:		; db		"S8 ",NULL
-                          		; db		 53h,  38h,  20h,  00h    ; uncompressed
-                          		  db		 59h,  31h,  00h          ; compressed
-
-g_szBusTypeValues_16:			; db		" 16",NULL
-                     			; db		 20h,  31h,  36h,  00h    ; uncompressed
-                     			  db		 20h,  2bh,  10h          ; compressed
-
-g_szBusTypeValues_32:			; db		" 32",NULL
-                     			; db		 20h,  33h,  32h,  00h    ; uncompressed
-                     			  db		 20h,  2dh,  0ch          ; compressed
-
-g_szBusTypeValues_Serial:		; db		"SER",NULL
-                         		; db		 53h,  45h,  52h,  00h    ; uncompressed
-                         		  db		 59h,  4bh,  98h          ; compressed
-
-g_szBusTypeValues_Displacement equ (g_szBusTypeValues_8Reversed - g_szBusTypeValues)
-;
-; Ensure that bus type strings are correctly spaced in memory
-;
-%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
-%if g_szBusTypeValues_8Dual <> g_szBusTypeValues
-%error "g_szBusTypeValues Displacement Incorrect 1"
-%endif
-%if g_szBusTypeValues_8Reversed <> g_szBusTypeValues + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 2"
-%endif
-%if g_szBusTypeValues_8Single <> g_szBusTypeValues_8Reversed + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 3"
-%endif
-%if g_szBusTypeValues_16 <> g_szBusTypeValues_8Single + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 4"
-%endif
-%if g_szBusTypeValues_32 <> g_szBusTypeValues_16 + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 5"
-%endif
-%if g_szBusTypeValues_Serial <> g_szBusTypeValues_32 + g_szBusTypeValues_Displacement
-%error "g_szBusTypeValues Displacement Incorrect 6"
-%endif
-%endif
-
-g_szSelectionTimeout:	; db		DOUBLE_BOTTOM_LEFT_CORNER,DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL,"%ASelection in %2-u s",NULL
-                     	; db		0c8h, 0b5h,  25h,  41h,  53h,  65h,  6ch,  65h,  63h,  74h,  69h,  6fh,  6eh,  20h,  69h,  6eh,  20h,  25h,  32h,  2dh,  75h,  20h,  73h,  00h    ; uncompressed
-                     	  db		 32h,  33h,  3dh,  59h,  6bh,  72h,  6bh,  69h,  7ah,  6fh,  75h, 0f4h,  6fh, 0f4h,  3ch,  20h, 0b9h                                              ; compressed
-
-
-g_szDashForZero:		; db		"- ",NULL
-                		; db		 2dh,  20h,  00h    ; uncompressed
-                		  db		 28h,  00h          ; compressed
-
-
 
 ;------------------------------------------------------------------------------------------
@@ -421,5 +424,5 @@
 ;; translated usage stats
 ;; 33:1
-;; 32:30
+;; 32:32
 ;; 181:1
 ;; 53:2
@@ -448,5 +451,5 @@
 ;; 5-u:2
 ;; x:7
-;; s:12
+;; s:14
 ;; 5-x:1
 ;; nl:6
@@ -458,5 +461,5 @@
 
 ;; alphabet usage stats
-;; 58,::2
+;; 58,::3
 ;; 59,;:
 ;; 60,<:
@@ -465,8 +468,8 @@
 ;; 63,?:
 ;; 64,@:1
-;; 65,A:4
+;; 65,A:3
 ;; 66,B:9
 ;; 67,C:4
-;; 68,D:10
+;; 68,D:11
 ;; 69,E:3
 ;; 70,F:3
@@ -483,5 +486,5 @@
 ;; 81,Q:1
 ;; 82,R:4
-;; 83,S:6
+;; 83,S:7
 ;; 84,T:
 ;; 85,U:1
@@ -497,25 +500,25 @@
 ;; 95,_:
 ;; 96,`:
-;; 97,a:6
+;; 97,a:7
 ;; 98,b:
-;; 99,c:4
+;; 99,c:5
 ;; 100,d:4
-;; 101,e:9
+;; 101,e:12
 ;; 102,f:2
 ;; 103,g:2
 ;; 104,h:
-;; 105,i:9
+;; 105,i:10
 ;; 106,j:
 ;; 107,k:4
-;; 108,l:4
+;; 108,l:5
 ;; 109,m:1
-;; 110,n:9
+;; 110,n:10
 ;; 111,o:18
 ;; 112,p:3
 ;; 113,q:
-;; 114,r:11
+;; 114,r:12
 ;; 115,s:6
-;; 116,t:11
-;; 117,u:3
+;; 116,t:12
+;; 117,u:2
 ;; 118,v:2
 ;; 119,w:1
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/CreateDPT.asm	(revision 262)
@@ -200,4 +200,8 @@
 	call	Device_FinalizeDPT
 
+;----------------------------------------------------------------------
+; Update drive counts (hard and floppy)
+;----------------------------------------------------------------------	
+		
 %ifdef MODULE_SERIAL_FLOPPY
 ;
@@ -223,31 +227,7 @@
 %endif
 
-	; Fall to .StoreDriveNumberAndUpdateDriveCount
-
-;--------------------------------------------------------------------
-; .StoreDriveNumberAndUpdateDriveCount
-;	Parameters:
-;		DS:DI:	Ptr to Disk Parameter Table
-;		ES:SI:	Ptr to 512-byte ATA information read from the drive
-;		CS:BP:	Ptr to IDEVARS for the controller
-;		ES:		BDA Segment
-;	Returns:
-;		DL:		Drive number for new drive
-;		CF:		Always cleared
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-.StoreDriveNumberAndUpdateDriveCount:
-	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:
+		
+.AllDone:				
 	clc
 	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm	(revision 262)
@@ -6,41 +6,75 @@
 
 ;--------------------------------------------------------------------
-; Finds pointer to first unused Disk Parameter Table.
-;
-; FindDPT_ForNewDriveToDSDI
-;	Parameters:
-;		DS:		RAMVARS segment
-;	Returns:
-;		DS:DI:	Ptr to first unused DPT
-;	Corrupts registers:
-;		DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-FindDPT_ForNewDriveToDSDI:
-	mov		ax, [RAMVARS.wDrvCntAndFirst]
-	add		al, ah
+; Checks if drive is handled by this BIOS, and return DPT pointer.
+;
+; FindDPT_ForDriveNumberInDL		
+;	Parameters:
+;		DL:		Drive number
+;		DS:		RAMVARS segment
+;	Returns:
+;		CF:		Cleared if drive is handled by this BIOS
+;				Set if drive belongs to some other BIOS
+;		DI:		DPT Pointer if drive is handled by this BIOS
+;				Zero if drive belongs to some other BIOS
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+FindDPT_ForDriveNumberInDL:		
+	xchg	di, ax								; Save the contents of AX in DI
+
+; 
+; Check Our Hard Disks
+;
+	mov		ax, [RAMVARS.wDrvCntAndFirst]		; Drive count to AH, First number to AL
+	add		ah, al								; One past last drive to AH
+
 %ifdef MODULE_SERIAL_FLOPPY
-	add		al, [RAMVARS.xlateVars+XLATEVARS.bFlopCreateCnt]
+	cmp		dl, ah								; Above last supported?
+	jae		SHORT .HardDiskNotHandledByThisBIOS
+		
+	cmp		dl, al								; Below first supported?
+	jae		SHORT .CalcDPTForDriveNumber
+
+ALIGN JUMP_ALIGN				
+.HardDiskNotHandledByThisBIOS:	
+;
+; Check Our Floppy Disks
+; 
+	call	RamVars_UnpackFlopCntAndFirstToAL
+	cbw											; normally 0h, could be ffh if no drives present
+	adc		ah, al								; if no drives present, still ffh (ffh + ffh + 1 = ffh)
+	js		SHORT .DiskIsNotHandledByThisBIOS
+	cmp		ah, dl								; Check second drive if two, first drive if only one
+	jz		SHORT .CalcDPTForDriveNumber
+	cmp		al, dl								; Check first drive in all cases, redundant but OK to repeat
+	jnz		SHORT .DiskIsNotHandledByThisBIOS			
+%else
+	cmp		dl, ah								; Above last supported?		
+	jae		SHORT .DiskIsNotHandledByThisBIOS
+		
+	cmp		dl, al								; Below first supported?
+	jb		SHORT .DiskIsNotHandledByThisBIOS			
 %endif
-	xchg	ax, dx
-	; fall-through to FindDPT_ForDriveNumber
+	; fall-through to CalcDPTForDriveNumber
 
 ;--------------------------------------------------------------------
 ; Finds Disk Parameter Table for drive number.
-; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
-;
-; FindDPT_ForDriveNumber
+; Note intended to be called except by FindDPT_ForDriveNumber
+;
+; CalcDPTForDriveNumber
 ;	Parameters:
 ;		DL:		Drive number
 ;		DS:		RAMVARS segment
+;       DI:     Saved copy of AX from entry at FindDPT_ForDriveNumber
 ;	Returns:
 ;		DS:DI:	Ptr to DPT
+;       CF:     Clear
 ;	Corrupts registers:
 ;		Nothing
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-FindDPT_ForDriveNumber:
+.CalcDPTForDriveNumber:
 	push	dx
-	xchg	di, ax	; Save the contents of AX in DI
 
 %ifdef MODULE_SERIAL_FLOPPY
@@ -52,4 +86,6 @@
 	call	RamVars_UnpackFlopCntAndFirstToAL
 	add		dl, ah						; add in end of hard disk DPT list, floppies start immediately after
+		
+ALIGN JUMP_ALIGN				
 .harddisk:
 	sub		dl, al						; subtract off beginning of either hard disk or floppy list (as appropriate)
@@ -57,105 +93,51 @@
 	sub		dl, [RAMVARS.bFirstDrv]		; subtract off beginning of hard disk list
 %endif
-		
+
+.CalcDPTForNewDrive:				
 	mov		al, LARGEST_DPT_SIZE
 		
 	mul		dl
-	add		ax, BYTE RAMVARS_size
-
-	xchg	di, ax						; Restore AX and put result in DI
+	add		ax, BYTE RAMVARS_size		; Clears CF (will not oveflow)
+
 	pop		dx
-		
-	ret
-
-;--------------------------------------------------------------------
-; Consolidator for checking the result from RamVars_IsDriveHandledByThisBIOS
-; and then if it is our drive, getting the DPT with FindDPT_ForDriveNumber
-;
-; RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber
-;	Parameters:
-;		DL:		Drive number
-;		DS:		RAMVARS segment
-;	Returns:
-;		DS:DI:	Ptr to DPT, if it is our drive
-;       CF:     Set if not our drive, clear if it is our drive
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-RamVars_IsDriveHandledByThisBIOS_And_FindDPT_ForDriveNumber:
-	call	RamVars_IsDriveHandledByThisBIOS
-	jnc		FindDPT_ForDriveNumber
-	ret
-
-
-;--------------------------------------------------------------------
-; Finds Disk Parameter Table for
-; Master or Slave drive at wanted port.
-;
-; FindDPT_ToDSDIForIdeMasterAtPortDX
-; FindDPT_ToDSDIForIdeSlaveAtPortDX
-;	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:
-;		SI
-;
-; Converted to macros since there is only once call site for each of these
-;
-;--------------------------------------------------------------------
-	
-%macro FindDPT_ToDSDIForIdeMasterAtPortDX 0
-	mov		si, IterateToMasterAtPortCallback
-	call	IterateAllDPTs
-%endmacro
-
-%macro FindDPT_ToDSDIForIdeSlaveAtPortDX 0
-	mov		si, IterateToSlaveAtPortCallback
-	call	IterateAllDPTs
-%endmacro
-
-		
-;--------------------------------------------------------------------
-; Iteration callback for finding DPT using
-; IDE base port for Master or Slave drive.
-;
-; IterateToSlaveAtPortCallback
-; IterateToMasterAtPortCallback
-;	Parameters:
-;		DX:		IDE Base Port address
-;		DS:DI:	Ptr to DPT to examine
-;	Returns:
-;		CF:		Set if wanted DPT found
-;				Cleared if wrong DPT
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-IterateToSlaveAtPortCallback:
-	test	BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE	; Clears CF
-	jnz		SHORT CompareBasePortAddress
-	ret		; Wrong DPT
-
-ALIGN JUMP_ALIGN
-IterateToMasterAtPortCallback:
-	test	BYTE [di+DPT.bFlagsLow], FLGL_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
-
-ReturnRightDPT:
-	stc											; Set CF since wanted DPT
-	ret
-
+
+	xchg	di, ax						; Restore AX from entry at FindDPT_ForDriveNumber, put DPT pointer in DI
+	ret
+
+ALIGN JUMP_ALIGN		
+.DiskIsNotHandledByThisBIOS:			
+;
+; Drive not found...
+;
+	xor		ax, ax								; Clear DPT pointer
+	stc											; Is not supported by our BIOS		
+		
+	xchg	di, ax								; Restore AX from save at top
+	ret
+
+;--------------------------------------------------------------------
+; Finds pointer to first unused Disk Parameter Table.
+; Should only be used before DetectDrives is complete (not valid after this time).
+;
+; FindDPT_ForNewDriveToDSDI
+;	Parameters:
+;		DS:		RAMVARS segment
+;	Returns:
+;		DS:DI:	Ptr to first unused DPT
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+FindDPT_ForNewDriveToDSDI:
+	push	dx
+		
+%ifdef MODULE_SERIAL_FLOPPY
+	mov		dx, [RAMVARS.wDrvCntAndFlopCnt]
+	add		dl, dh
+%else
+	mov		dl, [RAMVARS.bDrvCnt]
+%endif
+		
+	jmp		short FindDPT_ForDriveNumberInDL.CalcDPTForNewDrive
 
 ;--------------------------------------------------------------------
@@ -165,6 +147,6 @@
 ;       BL:		Bit(s) to test in DPT.bFlagsHigh 
 ;	Returns:
-;		CF:		Set if wanted DPT found
-;				Cleared if wrong DPT
+;		CF:		Clear if wanted DPT found
+;				Set if wrong DPT
 ;	Corrupts registers:
 ;		Nothing
@@ -172,10 +154,8 @@
 ALIGN JUMP_ALIGN
 IterateToDptWithFlagsHighInBL:		
-	test	BYTE [di+DPT.bFlagsHigh], bl		; Clears CF (but we need the clc
-												; below anyway for callers above)
-	jnz		SHORT ReturnRightDPT
-
-ReturnWrongDPT:
-	clc										; Clear CF since wrong DPT
+	test	BYTE [di+DPT.bFlagsHigh], bl		; Clears CF
+	jnz		SHORT .ReturnRightDPT
+	stc
+.ReturnRightDPT:		
 	ret
 
@@ -220,10 +200,11 @@
 ;		AX,BX,DX:	Parameters to callback function
 ;		CS:SI:		Ptr to callback function
+;                   Callback routine should return CF=clear if found
 ;		DS:			RAMVARS segment
 ;	Returns:
 ;		DS:DI:		Ptr to wanted DPT (if found)
 ;					If not found, points to first empty DPT
-;		CF:			Set if wanted DPT found
-;					Cleared if DPT not found, or no DPTs present
+;		CF:			Clear if wanted DPT found
+;					Set if DPT not found, or no DPTs present
 ;	Corrupts registers:
 ;		Nothing unless corrupted by callback function
@@ -238,17 +219,19 @@
 	xor		ch, ch						; Clears CF  
 		
-	jcxz	.AllDptsIterated			; Return if no drives, CF will be clear from xor above
+	jcxz	.NotFound					; Return if no drives
 		
 ALIGN JUMP_ALIGN
 .LoopWhileDPTsLeft:
 	call	si							; Is wanted DPT?
-	jc		SHORT .AllDptsIterated		;  If so, return
-	add		di, BYTE LARGEST_DPT_SIZE	; Point to next DPT, clears CF
+	jnc		SHORT .Found				;  If so, return
+	add		di, BYTE LARGEST_DPT_SIZE	; Point to next DPT
 	loop	.LoopWhileDPTsLeft
-	
-	; fall-through: DPT was not found, CF is already clear from ADD di inside the loop
-		
-ALIGN JUMP_ALIGN
-.AllDptsIterated:
+
+ALIGN JUMP_ALIGN
+.NotFound:
+	stc
+
+ALIGN JUMP_ALIGN
+.Found:
 	pop		cx
 	ret
Index: /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm
===================================================================
--- /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 261)
+++ /trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 262)
@@ -115,88 +115,4 @@
 
 ;--------------------------------------------------------------------
-; Checks if INT 13h function is handled by this BIOS.
-;
-; RamVars_IsFunctionHandledByThisBIOS
-;	Parameters:
-;		AH:		INT 13h function number
-;		DL:		Drive number
-;		DS:		RAMVARS segment
-;	Returns:
-;		CF:		Cleared if function is handled by this BIOS
-;				Set if function belongs to some other BIOS
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-RamVars_IsFunctionHandledByThisBIOS:
-	test	ah, ah			; Reset for all floppy and hard disk drives?
-	jz		SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
-	cmp		ah, 08h
-%ifdef MODULE_SERIAL_FLOPPY
-; we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts
-	je		SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
-%else
-; we handle all *hard disk* traffic for function 08h, as we need to wrap the hard disk drive count
-	je		SHORT RamVars_IsDriveHandledByThisBIOS.IsDriveAHardDisk
-%endif
-;;; fall-through			
-		
-;--------------------------------------------------------------------
-; Checks if drive is handled by this BIOS.
-;
-; RamVars_IsDriveHandledByThisBIOS
-;	Parameters:
-;		DL:		Drive number
-;		DS:		RAMVARS segment
-;	Returns:
-;		CF:		Cleared if drive is handled by this BIOS
-;				Set if drive belongs to some other BIOS
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-RamVars_IsDriveHandledByThisBIOS:
-	push	ax
-
-	mov		ax, [RAMVARS.wDrvCntAndFirst]		; Drive count to AH, First number to AL
-	add		ah, al								; One past last drive to AH
-	cmp		dl, ah								; Above last supported?
-	jae		SHORT .HardDiskIsNotHandledByThisBIOS
-.TestLowLimit:
-	cmp		dl, al								; Below first supported?
-	jae		SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX	; note that CF is clear if the branch is taken
-
-.HardDiskIsNotHandledByThisBIOS:
-%ifdef MODULE_SERIAL_FLOPPY
-	call	RamVars_UnpackFlopCntAndFirstToAL
-	cbw											; normally 0h, could be ffh if no drives present
-	adc		ah, al								; if no drives present, still ffh (ffh + ffh + 1 = ffh)
-	js		SHORT .DiskIsNotHandledByThisBIOS
-	cmp		ah, dl
-	jz		SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
-	cmp		al, dl
-	jz		SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
-.DiskIsNotHandledByThisBIOS:			
-%endif
-
-	stc											; Is not supported by our BIOS
-		
-.CFAlreadyClear_IsHandledByOurBIOS_PopAX:				
-	pop		ax
-.CFAlreadyClear_IsHandledByOurBIOS:	
-	ret
-
-%ifndef MODULE_SERIAL_FLOPPY		
-;
-; Note that we could have just checked for the high order bit in dl, but with the needed STC and jumps, 
-; leveraging the code above resulted in space savings.
-;
-.IsDriveAHardDisk:		
-	push	ax									; match stack at the top of routine
-	mov		al, 80h								; to catch all hard disks, lower limit is 80h vs. bFirstDrv
-	jmp		.TestLowLimit						; and there is no need to test a high limit
-%endif
-
-;--------------------------------------------------------------------
 ; RamVars_GetHardDiskCountFromBDAtoAX
 ;	Parameters:
