Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm	(revision 599)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/AdvancedAta/AdvAtaInit.asm	(revision 601)
@@ -36,5 +36,5 @@
 ;--------------------------------------------------------------------
 AdvAtaInit_DetectControllerForIdeBaseInBX:
-	; Detect if system has PCI bus. If it does, we can skip VLB detection. This is
+	; Detect if system has PCI bus. If it does, we can skip VLB detection. This is a
 	; good thing since detecting Vision QD6580 is dangerous since Intel PIIX4 south bridge
 	; mirrors Interrupt Controller registers from Axh to Bxh. This can lead to faulty
@@ -45,7 +45,9 @@
 	push	bx
 	push	di
-	xor		edi, edi		; Some BIOSes require this to be set to zero
-	mov		ax, PCI_INSTALLATION_CHECK
-	int		BIOS_TIME_PCI_PNP_1Ah
+;	xor		edi, edi		; Some BIOSes require this to be set to zero
+	; *FIXME* The above instruction is commented away since RBIL says that this
+	; only applies to software looking for the protected-mode entry point.
+	mov		ax, PCI_INSTALLATION_CHECK	; May corrupt EAX, EBX, ECX, EDX, EDI
+	int		BIOS_TIME_PCI_PNP_INTERRUPT_1Ah
 	pop		di
 	pop		bx
Index: trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 599)
+++ trunk/XTIDE_Universal_BIOS/Src/Initialization/DetectDrives.asm	(revision 601)
@@ -98,5 +98,5 @@
 ; Here we might want to replace BIOS configured drives with the ones we detected.
 ; Primary reason is to support dynamic overlay feature in the future. Second reason
-; is a hack to get Windows 95 load proper IDE drivers.
+; is a hack to get Windows 95 to load its built-in protected mode IDE driver.
 ;
 ; The Windows hack has two parts. First part is to try to alter CMOS address 12h as that
@@ -109,56 +109,55 @@
 
 %ifdef USE_AT	; FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES is for AT builds only
-
-	%ifdef MODULE_WIN95_CMOS_HACK
-		mov		dl, HARD_DISK_TYPES
-		call	CMOS_ReadFromIndexInDLtoAL
-		test	al, 0F0h
-		jnz		SHORT .ClearBdaDriveCount		; CMOS byte 12h is ready for Windows 95
-		call	CMOS_Verify10hTo2Dh				; Can we modify CMOS?
-		jnz		SHORT .ClearBdaDriveCount		; Unsupported BIOS, use plan B
-
-		; Now we can alter CMOS location 12h. Award BIOS locks if we set drive 0 type to Fh
-		; (but accept changes to drive type 1). Windows 95 requires that the drive 0 type is
-		; non zero and ignores drive 1 type. So if we only set drive 1, then Award BIOS
-		; won't give problems but Windows 95 stays in MS-DOS compatibility mode.
-		;
-		; For Award BIOSes we could set the Drive 0 type to 1 and then clear the BDA drive count.
-		; So essentially we could automatically do what user needs to do manually to get Windows 95
-		; working on Award BIOSes. However, I think that should be left to do manually since
-		; there may be SCSI drives on the system or FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES could
-		; be intentionally cleared and forcing the dummy drive might cause only trouble.
-
-		; Try to detect Award BIOS (Seems to work on a tested 128k BIOS so hopefully
-		; there will be no need to scan E000h segment)
-		mov		cx, 65536 - 4
-		mov		eax, 'Awar'		; Four characters should be enough
-		mov		di, 0F000h		; Scan 64k starting from segment F000h
-		mov		fs, di			; No need to preserve FS since we set it to zero soon when we boot
-		xor		di, di
-	.ScanNextCharacters:
-		cmp		[fs:di], eax
-		je		SHORT .ClearBdaDriveCount	; Award detected, cannot modify CMOS
-		inc		di				; Increment offset by one character (not four)
-		loop	.ScanNextCharacters
-
-		; Now it should be safe to write
-		mov		dl, HARD_DISK_TYPES
-		mov		al, 0F0h	; Drive 0 type 16...47 (supposed to be defined elsewhere in the CMOS)
-		call	CMOS_WriteALtoIndexInDL
-		call	CMOS_StoreNewChecksumFor10hto2Dh
+%ifdef MODULE_WIN95_CMOS_HACK
+	mov		dl, HARD_DISK_TYPES
+	call	CMOS_ReadFromIndexInDLtoAL
+	test	al, 0F0h
+	jnz		SHORT .ClearBdaDriveCount		; CMOS byte 12h is ready for Windows 95
+	call	CMOS_Verify10hTo2Dh				; Can we modify CMOS?
+	jnz		SHORT .ClearBdaDriveCount		; Unsupported BIOS, use plan B
+
+	; Now we can alter CMOS location 12h. Award BIOS locks if we set drive 0 type to Fh
+	; (but accept changes to drive type 1). Windows 95 requires that the drive 0 type is
+	; non zero and ignores drive 1 type. So if we only set drive 1, then Award BIOS
+	; won't give problems but Windows 95 stays in MS-DOS compatibility mode.
+	;
+	; For Award BIOSes we could set the Drive 0 type to 1 and then clear the BDA drive count.
+	; So essentially we could automatically do what user needs to do manually to get Windows 95
+	; working on Award BIOSes. However, I think that should be left to do manually since
+	; there may be SCSI drives on the system or FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES could
+	; be intentionally cleared and forcing the dummy drive might cause only trouble.
+
+	; Try to detect Award BIOS (Seems to work on a tested 128k BIOS so hopefully
+	; there will be no need to scan E000h segment)
+	mov		cx, 65536 - 4
+	mov		eax, 'Awar'						; Four characters should be enough
+	mov		di, 0F000h						; Scan 64k starting from segment F000h
+	mov		fs, di							; No need to preserve FS since we set it to zero soon when we boot
+	xor		di, di
+.ScanNextCharacters:
+	cmp		[fs:di], eax
+	je		SHORT .ClearBdaDriveCount		; Award detected, cannot modify CMOS
+	inc		di								; Increment offset by one character (not four)
+	loop	.ScanNextCharacters
+
+	; Now it should be safe to write
+	mov		dl, HARD_DISK_TYPES
+	mov		al, 0F0h						; Drive 0 type 16...47 (supposed to be defined elsewhere in the CMOS)
+	call	CMOS_WriteALtoIndexInDL
+	call	CMOS_StoreNewChecksumFor10hto2Dh
 .ClearBdaDriveCount:
-	%endif	; MODULE_WIN95_CMOS_HACK
+%endif ; MODULE_WIN95_CMOS_HACK
 
 	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_IGNORE_MOTHERBOARD_DRIVES
 	jz		SHORT .ContinueInitialization
-	mov		BYTE [es:BDA.bHDCount], 0	; Set hard disk count to zero
+	mov		BYTE [es:BDA.bHDCount], 0		; Set hard disk count to zero
 .ContinueInitialization:
-%endif
-
-	mov		cx, [RAMVARS.wDrvCntAndFlopCnt]		; Our count of hard disks
+%endif ; USE_AT
+
+	mov		cx, [RAMVARS.wDrvCntAndFlopCnt]	; Our count of hard disks
 	mov		al, [es:BDA.bHDCount]
-	add		[es:BDA.bHDCount], cl		; Add our drives to the system count
-	or		al, 80h						; Or in hard disk flag
-	mov		[RAMVARS.bFirstDrv], al		; Store first drive number
+	add		[es:BDA.bHDCount], cl			; Add our drives to the system count
+	or		al, 80h							; Or in hard disk flag
+	mov		[RAMVARS.bFirstDrv], al			; Store first drive number
 
 .AddFloppies:
@@ -170,5 +169,5 @@
 	dec		ch
 	mov		al, ch
-	js		.NoFloppies						; if no drives are present, we store 0ffh
+	js		SHORT .NoFloppies				; If no drives are present, we store 0FFh
 
 	call	FloppyDrive_GetCountFromBIOS_or_BDA
@@ -242,5 +241,5 @@
 ;--------------------------------------------------------------------
 .ReadAtaInfoFromHardDisk:
-	mov		si, BOOTVARS.rgbAtaInfo		; ES:SI now points to ATA info location
+	mov		si, BOOTVARS.rgbAtaInfo			; ES:SI now points to ATA info location
 	push	es
 	push	si
@@ -255,6 +254,6 @@
 	; Fall to .ReadAtapiInfoFromDrive
 
-.ReadAtapiInfoFromDrive:				; Not yet implemented
-	;call	ReadAtapiInfoFromDrive		; Assume CD-ROM
+.ReadAtapiInfoFromDrive:					; Not yet implemented
+	;call	ReadAtapiInfoFromDrive			; Assume CD-ROM
 	;jnc	SHORT _CreateBiosTablesForCDROM
 
