Index: trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 32)
+++ trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm	(revision 33)
@@ -2,5 +2,5 @@
 ; Project name	:	IDE BIOS
 ; Created date	:	14.3.2010
-; Last update	:	3.8.2010
+; Last update	:	23.8.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for accessings RAMVARS.
@@ -23,13 +23,10 @@
 ALIGN JUMP_ALIGN
 RamVars_Initialize:
-	call	RamVars_StealBaseMemory	; Get RAMVARS segment to DS even if no stealing
-	call	RamVars_ClearToZero
+	call	.StealMemoryForRAMVARS	; Get RAMVARS segment to DS even if no stealing
+	call	.ClearRamvarsFromDS
 	jmp		DriveXlate_Reset
 
-
-;--------------------------------------------------------------------
-; Steals base memory to be used for RAMVARS.
-;
-; RamVars_StealBaseMemory
+;--------------------------------------------------------------------
+; .StealMemoryForRAMVARS
 ;	Parameters:
 ;		Nothing
@@ -40,57 +37,18 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-RamVars_StealBaseMemory:
+.StealMemoryForRAMVARS:
 	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
-	jz		SHORT RamVars_GetSegmentToDS	; No need to steal
-
-	LOAD_BDA_SEGMENT_TO	ds, ax				; Zero AX
+	jz		SHORT RamVars_GetSegmentToDS
+
+	LOAD_BDA_SEGMENT_TO	ds, ax		; Zero AX
 	mov		al, [cs:ROMVARS.bStealSize]
-	sub		[BDA.wBaseMem], ax				; Steal one or more kilobytes
-	mov		ax, [BDA.wBaseMem]				; Load base memory left
-	eSHL_IM	ax, 6							; Shift for segment address
-	mov		ds, ax							; Copy RAMVARS segment to DS
-	ret
-
-
-;--------------------------------------------------------------------
-; Returns segment to RAMVARS.
-; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
-; or at the top of system base RAM.
-;
-; RamVars_GetSegmentToDS
-;	Parameters:
-;		Nothing
-;	Returns:
-;		DS:		RAMVARS segment
-;	Corrupts registers:
-;		DI
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-RamVars_GetSegmentToDS:
-	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
-	jnz		SHORT RamVars_GetStolenSegmentToDS
-	mov		di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
-	mov		ds, di
-	ret
-
-ALIGN JUMP_ALIGN
-RamVars_GetStolenSegmentToDS:
-	LOAD_BDA_SEGMENT_TO	ds, di
-	mov		di, [BDA.wBaseMem]		; Load available base memory size in kB
-	eSHL_IM	di, 6					; Segment to first stolen kB
-ALIGN JUMP_ALIGN
-.LoopStolenKBs:
-	mov		ds, di					; EBDA segment to DS
-	add		di, BYTE 64				; DI to next stolen kB
-	cmp		WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
-	jne		SHORT .LoopStolenKBs	; Loop until sign found (always found eventually)
-	ret
-
-
-;--------------------------------------------------------------------
-; Clears RAMVARS variables to zero.
-; FULLRAMVARS sign will be saved if available.
-;
-; RamVars_ClearToZero
+	sub		[BDA.wBaseMem], ax
+	mov		ax, [BDA.wBaseMem]
+	eSHL_IM	ax, 6					; Segment to first stolen kB (*=40h)
+	mov		ds, ax
+	ret
+
+;--------------------------------------------------------------------
+; .ClearRamvarsFromDS
 ;	Parameters:
 ;		DS:		RAMVARS segment
@@ -101,5 +59,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-RamVars_ClearToZero:
+.ClearRamvarsFromDS:
 	call	FindDPT_PointToFirstDPT	; Get RAMVARS/FULLRAMVARS size to DI
 	mov		cx, di					; Copy byte count to CX
@@ -110,4 +68,39 @@
 	rep stosb
 	mov		WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
+	ret
+
+
+;--------------------------------------------------------------------
+; Returns segment to RAMVARS.
+; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
+; or at the top of system base RAM.
+;
+; RamVars_GetSegmentToDS
+;	Parameters:
+;		Nothing
+;	Returns:
+;		DS:		RAMVARS segment
+;	Corrupts registers:
+;		DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+RamVars_GetSegmentToDS:
+	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
+	jnz		SHORT .GetStolenSegmentToDS
+	mov		di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
+	mov		ds, di
+	ret
+
+ALIGN JUMP_ALIGN
+.GetStolenSegmentToDS:
+	LOAD_BDA_SEGMENT_TO	ds, di
+	mov		di, [BDA.wBaseMem]		; Load available base memory size in kB
+	eSHL_IM	di, 6					; Segment to first stolen kB (*=40h)
+ALIGN JUMP_ALIGN
+.LoopStolenKBs:
+	mov		ds, di					; EBDA segment to DS
+	add		di, BYTE 64				; DI to next stolen kB
+	cmp		WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
+	jne		SHORT .LoopStolenKBs	; Loop until sign found (always found eventually)
 	ret
 
@@ -234,2 +227,22 @@
 	and		dl, 7Fh						; Clear HD bit for drive count
 	ret
+
+
+;--------------------------------------------------------------------
+; RamVars_GetIdeControllerCountToCX
+;	Parameters:
+;		Nothing
+;	Returns:
+;		CX:		Number of IDE controllers to handle
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------	
+ALIGN JUMP_ALIGN
+RamVars_GetIdeControllerCountToCX:
+	mov		cx, 1					; Assume lite mode (one controller)
+	test	BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
+	jz		SHORT .Return
+	mov		cl, [cs:ROMVARS.bIdeCnt]
+ALIGN JUMP_ALIGN, ret
+.Return:
+	ret
