Index: /trunk/Assembly_Library/Inc/Debug.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Debug.inc	(revision 44)
+++ /trunk/Assembly_Library/Inc/Debug.inc	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	8.8.2010
-; Last update	:	8.8.2010
+; Last update	:	29.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Debugging macros.
@@ -20,4 +20,5 @@
 ;--------------------------------------------------------------------
 %macro DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY 2
+	pushf
 	push	di
 	push	bx
@@ -33,4 +34,5 @@
 	pop		bx
 	pop		di
+	popf
 %endmacro
 
@@ -46,4 +48,5 @@
 ;--------------------------------------------------------------------
 %macro DISPLAY_DEBUG_CHARACTER_AND_WAIT_ANY_KEY 1
+	pushf
 	push	di
 	push	ax
@@ -56,4 +59,5 @@
 	pop		ax
 	pop		di
+	popf
 %endmacro
 
@@ -69,4 +73,5 @@
 ;--------------------------------------------------------------------
 %macro DISPLAY_DEBUG_CHARACTER 1
+	pushf
 	push	di
 	push	ax
@@ -75,4 +80,5 @@
 	pop		ax
 	pop		di
+	popf
 %endmacro
 
Index: /trunk/Assembly_Library/Inc/Dialog.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Dialog.inc	(revision 44)
+++ /trunk/Assembly_Library/Inc/Dialog.inc	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.9.2010
-; Last update	:	15.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for Menu library dialogs.
@@ -75,4 +75,8 @@
 
 
+; Progress bar dialog
+PROGRESS_COMPLETE_CHARACTER			EQU		BLOCK_FULL_FOREGROUND
+PROGRESS_INCOMPLETE_CHARACTER		EQU		BLOCK_MOSTLY_BACKGROUND
+
 ; File dialog
 FILENAME_BUFFER_SIZE				EQU		14	; 8+1+3+NULL+alignment
Index: /trunk/Assembly_Library/Inc/Display.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Display.inc	(revision 44)
+++ /trunk/Assembly_Library/Inc/Display.inc	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	AssemblyLibrary
 ; Created date	:	25.6.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Defines for display library.
@@ -40,5 +40,5 @@
 
 	.SetCharacterPointerFromBXAX					resb	2
-	.SetCharOutputFunctionFromAXwithAttribFlagInDL	resb	2
+	.SetCharOutputFunctionFromAXwithAttribFlagInBL	resb	2
 	.SetCharacterOutputParameterFromAX				resb	2
 	.SetCharacterAttributeFromAL					resb	2
Index: /trunk/Assembly_Library/Inc/Menu.inc
===================================================================
--- /trunk/Assembly_Library/Inc/Menu.inc	(revision 44)
+++ /trunk/Assembly_Library/Inc/Menu.inc	(revision 45)
@@ -107,5 +107,5 @@
 
 	.bFlags							resb	1	; Menu flags
-	.bLastSecondPrinted				resb	1	; To minimize CGA snow when using timeouts
+									resb	1
 	.wTimeoutCounter				resb	2
 
Index: /trunk/Assembly_Library/Src/AssemblyLibrary.asm
===================================================================
--- /trunk/Assembly_Library/Src/AssemblyLibrary.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/AssemblyLibrary.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.9.2010
-; Last update	:	15.9.2010
+; Last update	:	29.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Assembly Library main file. This is the only file that
@@ -71,3 +71,4 @@
 	%include "Memory.asm"
 	%include "Size.asm"
+	%include "Sort.asm"
 %endif
Index: /trunk/Assembly_Library/Src/Display/Display.asm
===================================================================
--- /trunk/Assembly_Library/Src/Display/Display.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Display/Display.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	2.7.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Display Library functions for CALL_DISPLAY_LIBRARY macro
@@ -68,5 +68,5 @@
 
 	at	DISPLAY_LIB.SetCharacterPointerFromBXAX,					dw	DisplayContext_SetCharacterPointerFromBXAX
-	at	DISPLAY_LIB.SetCharOutputFunctionFromAXwithAttribFlagInDL,	dw	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL
+	at	DISPLAY_LIB.SetCharOutputFunctionFromAXwithAttribFlagInBL,	dw	DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
 	at	DISPLAY_LIB.SetCharacterOutputParameterFromAX,				dw	DisplayContext_SetCharacterOutputParameterFromAX
 	at	DISPLAY_LIB.SetCharacterAttributeFromAL,					dw	DisplayContext_SetCharacterAttributeFromAL
Index: /trunk/Assembly_Library/Src/Display/DisplayContext.asm
===================================================================
--- /trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Display/DisplayContext.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.6.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing display context.
@@ -153,21 +153,18 @@
 
 ;--------------------------------------------------------------------
-; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL
+; DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL
 ;	Parameters:
 ;		AX:		Offset to character output function
-;		DL:		Attribute Flag
-;		DS:		BDA segment (zero)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInDL:
+;		BL:		Attribute Flag
+;		DS:		BDA segment (zero)
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayContext_SetCharOutputFunctionFromAXwithAttribFlagInBL:
 	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.fnCharOut], ax
-	and		BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], ~FLG_CONTEXT_ATTRIBUTES
-	mov		al, dl
-	and		al, FLG_CONTEXT_ATTRIBUTES
-	or		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], al
+	mov		[VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], bl
 	ret
 
Index: /trunk/Assembly_Library/Src/LibraryTests.asm
===================================================================
--- /trunk/Assembly_Library/Src/LibraryTests.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/LibraryTests.asm	(revision 45)
@@ -33,7 +33,8 @@
 	CALL_DISPLAY_LIBRARY ClearScreen
 
-	call	LibraryTests_ForDisplayLibrary
+	call	LibraryTests_Sort
+	;call	LibraryTests_ForDisplayLibrary
 	;call	LibraryTests_ForKeyboardLibrary
-	call	LibraryTests_ForMenuLibrary
+	;call	LibraryTests_ForMenuLibrary
 
 	; Exit to DOS
@@ -254,7 +255,7 @@
 	mov		ax, si
 	CALL_DISPLAY_LIBRARY SetCharacterPointerFromBXAX
-	mov		dl, ATTRIBUTES_NOT_USED
+	mov		bl, ATTRIBUTES_NOT_USED
 	mov		ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
-	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
 	lea		ax, [si+STRING_BUFFER_SIZE]
 	CALL_DISPLAY_LIBRARY SetCharacterOutputParameterFromAX
@@ -551,5 +552,56 @@
 .szRepeat:
 	db	"Repeating character '-':                   %A%t",LF,CR,NULL
-		
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+LibraryTests_Sort:
+	call	.PrintWords
+	push	cs
+	pop		ds
+	mov		si, .rgwItems
+	mov		dx, 7
+	mov		cx, 2
+	mov		bx, .Comparator
+	call	Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX
+	call	.PrintWords
+	ret
+
+
+.Comparator:
+	push	ax
+	mov		ax, [si]
+	;DISPLAY_DEBUG_CHARACTER 'I'
+	;DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY ax, 10
+	;DISPLAY_DEBUG_CHARACTER ','
+	;DISPLAY_DEBUG_WORD_AND_WAIT_ANY_KEY [es:di], 10
+	;DISPLAY_DEBUG_CHARACTER ' '
+	cmp		ax, [es:di]
+	pop		ax
+	ret
+
+.PrintWords:
+	CALL_DISPLAY_LIBRARY PrintNewlineCharacters
+	mov		cx, 7
+	push	cs
+	pop		ds
+	mov		si, .rgwItems
+	mov		bx, 10
+.Loop:
+	lodsw
+	CALL_DISPLAY_LIBRARY PrintSignedWordFromAXWithBaseInBX
+	CALL_DISPLAY_LIBRARY PrintNewlineCharacters
+	loop	.Loop
+	ret
+
+
+.rgwItems:
+	dw		435
+	dw		-31551
+	dw		345
+	dw		0
+	dw		-18
+	dw		23
+	dw		435
+
 
 
Index: /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	6.9.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays file dialog.
@@ -253,7 +253,7 @@
 	xchg	ax, cx
 	CALL_DISPLAY_LIBRARY SetCharacterPointerFromBXAX
-	mov		dl, ATTRIBUTES_NOT_USED
+	mov		bl, ATTRIBUTES_NOT_USED
 	mov		ax, BUFFER_OUTPUT_WITH_CHAR_ONLY
-	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
 
 	call	.FormatFileOrDirectoryToBufferFromDTAinDSSI
Index: /trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Menu/Dialog/DialogProgress.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	15.8.2010
-; Last update	:	16.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Displays progress bar dialog and starts progress task.
@@ -167,5 +167,5 @@
 	jcxz	.DrawEmptyCharsOnly
 
-	mov		al, SCROLL_THUMB_CHARACTER
+	mov		al, PROGRESS_COMPLETE_CHARACTER
 	CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
 
@@ -173,5 +173,5 @@
 	mov		cx, dx
 	jcxz	.NothingLeftToDraw
-	mov		al, SCROLL_TRACK_CHARACTER
+	mov		al, PROGRESS_INCOMPLETE_CHARACTER
 	CALL_DISPLAY_LIBRARY PrintRepeatedCharacterFromALwithCountInCX
 
Index: /trunk/Assembly_Library/Src/Menu/MenuBorders.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/MenuBorders.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Menu/MenuBorders.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	14.7.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing menu borders.
@@ -45,11 +45,11 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, DX, SI, DI
+;		AX, BX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 MenuBorders_AdjustDisplayContextForDrawingBorders:
-	mov		dl, ATTRIBUTES_ARE_USED
+	mov		bl, ATTRIBUTES_ARE_USED
 	mov		ax, MenuCharOut_MenuBorderTeletypeOutputWithAttribute
-	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
 
 	mov		ax, bp
@@ -269,9 +269,9 @@
 	call	MenuAttribute_SetToDisplayContextFromTypeInSI
 
-	push	dx
-	mov		dl, ATTRIBUTES_ARE_USED
+	push	bx
+	mov		bl, ATTRIBUTES_ARE_USED
 	mov		ax, FAST_OUTPUT_WITH_ATTRIBUTE_ONLY
-	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
-	pop		dx
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
+	pop		bx
 
 	call	PrintMultipleBorderCharactersFromAL	; AL does not matter
Index: /trunk/Assembly_Library/Src/Menu/MenuText.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/MenuText.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Menu/MenuText.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	21.7.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for drawing menu texts by the user.
@@ -218,11 +218,11 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, DX, SI, DI
+;		AX, BX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
 AdjustDisplayContextForDrawingTexts:
-	mov		dl, ATTRIBUTES_ARE_USED
+	mov		bl, ATTRIBUTES_ARE_USED
 	mov		ax, MenuCharOut_MenuTextTeletypeOutputWithAttribute
-	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInDL
+	CALL_DISPLAY_LIBRARY SetCharOutputFunctionFromAXwithAttribFlagInBL
 
 	mov		ax, bp
Index: /trunk/Assembly_Library/Src/Menu/MenuTime.asm
===================================================================
--- /trunk/Assembly_Library/Src/Menu/MenuTime.asm	(revision 44)
+++ /trunk/Assembly_Library/Src/Menu/MenuTime.asm	(revision 45)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	25.7.2010
-; Last update	:	27.9.2010
+; Last update	:	28.9.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Menu timeouts other time related functions.
@@ -56,21 +56,15 @@
 ALIGN JUMP_ALIGN
 MenuTime_UpdateSelectionTimeout:
-	cmp		WORD [bp+MENUINIT.wTimeoutTicks], BYTE 0
-	je		SHORT .ReturnSinceTimeoutDisabled	; CF cleared
 	push	ds
 
-	call	GetSecondsUntilTimeoutToAXandPtrToTimeoutCounterToDSBX
-	cmp		al, [bp+MENU.bLastSecondPrinted]
-	je		SHORT .SetCFifTimeoutAndReturn
-	mov		[bp+MENU.bLastSecondPrinted], al
-	call	DrawTimeoutInAXoverMenuBorders
+	call	MenuTime_DrawWithoutUpdating
+	jnc		SHORT .TimeoutDisabled
+	call	PointDSBXtoTimeoutCounter
+	call	TimerTicks_SetCarryIfTimeoutFromDSBX
 
 ALIGN JUMP_ALIGN
-.SetCFifTimeoutAndReturn:
-	call	TimerTicks_SetCarryIfTimeoutFromDSBX
+.TimeoutDisabled:
 	pop		ds
-.ReturnSinceTimeoutDisabled:
 	ret
-
 
 ;--------------------------------------------------------------------
@@ -79,5 +73,6 @@
 ;		SS:BP:	Ptr to MENU
 ;	Returns:
-;		Nothing
+;		CF:		Set if timeout enabled
+;				Cleared if timeout disabled
 ;	Corrupts registers:
 ;		AX, BX, CX, DX, SI, DI
@@ -86,12 +81,34 @@
 MenuTime_DrawWithoutUpdating:
 	cmp		WORD [bp+MENUINIT.wTimeoutTicks], BYTE 0
-	je		SHORT .ReturnSinceTimeoutDisabled
+	je		SHORT .ReturnSinceTimeoutDisabled	; Clear CF
 
 	push	ds
-	call	GetSecondsUntilTimeoutToAXandPtrToTimeoutCounterToDSBX
+	call	GetSecondsLeftUntilTimeoutToAXandCounterToDSBX
 	call	DrawTimeoutInAXoverMenuBorders
 	pop		ds
+	stc
+ALIGN JUMP_ALIGN, ret
 .ReturnSinceTimeoutDisabled:
 	ret
+
+
+;--------------------------------------------------------------------
+; GetSecondsLeftUntilTimeoutToAXandCounterToDSBX
+;	Parameters
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		AX:		Seconds until timeout
+;		DS:BX:	Ptr to timeout counter
+;	Corrupts registers:
+;		AX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+GetSecondsLeftUntilTimeoutToAXandCounterToDSBX:
+	call	PointDSBXtoTimeoutCounter
+	call	TimerTicks_GetElapsedToAXfromDSBX
+	neg		ax			; Negate since DS:BX points to end time
+	MAX_S	ax, 0		; Set to zero if overflow
+	xchg	dx, ax
+	jmp		TimerTicks_GetSecondsToAXfromTicksInDX
 
 
@@ -111,24 +128,4 @@
 	lea		bx, [bp+MENU.wTimeoutCounter]
 	ret
-
-
-;--------------------------------------------------------------------
-; GetSecondsUntilTimeoutToAXandPtrToTimeoutCounterToDSBX
-;	Parameters
-;		SS:BP:	Ptr to MENU
-;	Returns:
-;		AX:		Seconds until timeout
-;		DS:BX:	Ptr to timeout counter
-;	Corrupts registers:
-;		AX, CX, DX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-GetSecondsUntilTimeoutToAXandPtrToTimeoutCounterToDSBX:
-	call	PointDSBXtoTimeoutCounter
-	call	TimerTicks_GetElapsedToAXfromDSBX
-	neg		ax			; Negate since DS:BX points to end time
-	MAX_S	ax, 0		; Set to zero if overflow
-	xchg	dx, ax
-	jmp		TimerTicks_GetSecondsToAXfromTicksInDX
 
 
@@ -173,4 +170,5 @@
 	pop		bp
 
+	; Draw right border with normal border color
 	mov		al, DOUBLE_RIGHT_HORIZONTAL_TO_SINGLE_VERTICAL
 	jmp		MenuBorders_PrintSingleBorderCharacterFromAL
@@ -178,5 +176,5 @@
 	db		DOUBLE_BOTTOM_LEFT_CORNER
 	db		DOUBLE_LEFT_HORIZONTAL_TO_SINGLE_VERTICAL
-	db		"%AAutoselection in %2-ds",NULL
+	db		"%AAutoselection in %2-us",NULL
 
 ;--------------------------------------------------------------------
Index: /trunk/Assembly_Library/Src/Util/Sort.asm
===================================================================
--- /trunk/Assembly_Library/Src/Util/Sort.asm	(revision 45)
+++ /trunk/Assembly_Library/Src/Util/Sort.asm	(revision 45)
@@ -0,0 +1,287 @@
+; File name		:	Sort.asm
+; Project name	:	Assembly Library
+; Created date	:	28.9.2010
+; Last update	:	29.9.2010
+; Author		:	Tomi Tilli
+; Description	:	Sorting algorithms
+
+; Algorith is from http://www.algolist.net/Algorithms/Sorting/Quicksort
+
+struc QSORT_PARAMS
+	.lpItems		resb	4
+	.tempStruct:
+endstruc
+
+;--------------------------------------------------------------------
+; Prototype for comparator callback function
+;	Parameters:
+;		DS:SI:	Offset to first item to compare
+;		ES:DI:	Offset to second item to compare
+;	Returns:
+;		FLAGS:	Signed comparition between first and second item
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; DialogFile_GetFileNameWithIoInDSSI
+;	Parameters:
+;		DS:SI:	Ptr to FILE_DIALOG_IO
+;		SS:BP:	Ptr to parent MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Sort_ItemsFromDSSIwithCountInDXsizeInCXandComparatorInBX:
+	push	es
+	push	di
+	add		cx, BYTE QSORT_PARAMS_size
+	eENTER_STRUCT cx
+
+	cld
+	sub		cx, BYTE QSORT_PARAMS_size	; Restore CX to item size
+	xor		ax, ax						; Zero for starting index
+	dec		dx							; Count to index of last item
+	mov		[bp+QSORT_PARAMS.lpItems], si
+	mov		[bp+QSORT_PARAMS.lpItems+2], ds
+	call	QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP
+
+	lds		si, [bp+QSORT_PARAMS.lpItems]
+	add		cx, BYTE QSORT_PARAMS_size
+	eLEAVE_STRUCT cx
+	pop		di
+	pop		es
+	ret
+
+
+;--------------------------------------------------------------------
+; QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP
+;	Parameters:
+;		AX:		Index of first item in range
+;		BX:		Comparator function
+;		CX:		Size of struct in bytes
+;		DX:		Index of last (included) item in range
+;		SS:BP:	Ptr to QSORT_PARAMS
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		DS, ES
+;		AX, DX (not for recursion)
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP:
+	push	di
+	push	si
+
+	mov		si, ax			; First index to SI
+	mov		di, dx			; Last index to DI
+	call	ArrangeItemsInRangeAXtoDXusingMiddleItemAsPivot
+
+	; Does left partition need more sorting
+	cmp		si, dx			; if (first index < Index of rightmost unsorted item)
+	jae		SHORT .CheckIfRightPartitionNeedsMoreSorting
+	xchg	ax, si			; AX = first index, SI = Index of leftmost unsorted item
+	call	QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP
+	xchg	ax, si			; AX = Index of leftmost unsorted item
+
+.CheckIfRightPartitionNeedsMoreSorting:
+	cmp		ax, di			; if (Index of leftmost unsorted item < last index)
+	jae		SHORT .SortCompleted
+	mov		dx, di			; DI = Index of leftmost unsorted item
+	call	QuicksortItemsInRangeFromAXtoDXwithQsortParamsInSSBP
+
+ALIGN JUMP_ALIGN
+.SortCompleted:
+	pop		si
+	pop		di
+	ret
+
+
+;--------------------------------------------------------------------
+; ArrangeItemsInRangeAXtoDXusingMiddleItemAsPivot
+;	Parameters:
+;		AX:		Index of first item in range
+;		BX:		Comparator function
+;		CX:		Size of struct in bytes
+;		DX:		Index of last (included) item in range
+;		SS:BP:	Ptr to QSORT_PARAMS
+;	Returns:
+;		AX:		Index of first unsorted item
+;		DX:		Index of last unsorted item
+;	Corrupts registers:
+;		DS, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ArrangeItemsInRangeAXtoDXusingMiddleItemAsPivot:
+	push	di
+	push	si
+
+	call	.GetPivotPointerToESDI
+	call	ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI
+
+	pop		si
+	pop		di
+	ret
+
+ALIGN JUMP_ALIGN
+.GetPivotPointerToESDI:
+	push	ax
+	add		ax, dx
+	shr		ax, 1
+	call	GetItemPointerToDSSIfromIndexInAX
+	pop		ax
+	jmp		Memory_ExchangeDSSIwithESDI
+
+
+;--------------------------------------------------------------------
+; ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI
+;	Parameters:
+;		AX:		Index of first item in range
+;		BX:		Comparator function
+;		CX:		Size of struct in bytes
+;		DX:		Index of last (included) item in range
+;		ES:DI:	Ptr to Pivot item
+;		SS:BP:	Ptr to QSORT_PARAMS
+;	Returns:
+;		AX:		Index of first unsorted item
+;		DX:		Index of last unsorted item
+;	Corrupts registers:
+;		SI, DS
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI:
+	cmp		ax, dx	; while (left <= right)
+	ja		SHORT .BreakLoopSinceAllItemsExamined
+
+	call	GetItemPointerToDSSIfromIndexInAX
+	call	.GetIndexOfLeftmostItemToAXforItemThatIsGreaterThanEqualToPivotInESDI
+
+	call	GetItemPointerToDSSIfromIndexInDX
+	call	.GetIndexOfRightmostItemToDXforItemThatIsGreaterThanPivotInESDI
+
+	cmp		ax, dx	; If (left <= right)
+	ja		SHORT ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI
+	call	SwapItemsFromIndexesAXandDX
+	inc		ax
+	dec		dx
+	jmp		SHORT ArrangeItemsInRangeAXtoDXtoBothSidesOfPivotInESDI
+
+ALIGN JUMP_ALIGN
+.GetIndexOfLeftmostItemToAXforItemThatIsGreaterThanEqualToPivotInESDI:
+	call	bx
+	jge		SHORT .NoNeedToIncrementOrDecrementAnyMore
+	inc		ax				; Increment item index
+	add		si, cx			; Point to next struct
+	jmp		SHORT .GetIndexOfLeftmostItemToAXforItemThatIsGreaterThanEqualToPivotInESDI
+
+ALIGN JUMP_ALIGN
+.GetIndexOfRightmostItemToDXforItemThatIsGreaterThanPivotInESDI:
+	call	bx
+	jle		SHORT .NoNeedToIncrementOrDecrementAnyMore
+	dec		dx
+	sub		si, cx
+	jmp		SHORT .GetIndexOfRightmostItemToDXforItemThatIsGreaterThanPivotInESDI
+
+ALIGN JUMP_ALIGN
+.NoNeedToIncrementOrDecrementAnyMore:
+.BreakLoopSinceAllItemsExamined:
+	ret
+
+
+;--------------------------------------------------------------------
+; SwapItemsFromIndexesAXandDX
+;	Parameters:
+;		AX:		Index of item 1
+;		CX:		Size of struct in bytes
+;		DX:		Index of item 2
+;		SS:BP:	Ptr to QSORT_PARAMS
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		SI, DS
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+SwapItemsFromIndexesAXandDX:
+	push	es
+	push	di
+
+	; Item AX to stack
+	call	.GetPtrToTemporaryStructToESDI
+	call	GetItemPointerToDSSIfromIndexInAX
+	call	.CopyItemFromDSSItoESDI
+
+	; Item DX to Item AX
+	call	Memory_ExchangeDSSIwithESDI
+	call	GetItemPointerToDSSIfromIndexInDX
+	call	.CopyItemFromDSSItoESDI
+
+	; Stack to Item DX
+	call	.GetPtrToTemporaryStructToESDI
+	call	Memory_ExchangeDSSIwithESDI
+	call	.CopyItemFromDSSItoESDI
+
+	pop		di
+	pop		es
+	ret
+
+ALIGN JUMP_ALIGN
+.GetPtrToTemporaryStructToESDI:
+	lea		di, [bp+QSORT_PARAMS.tempStruct]
+	push	ss
+	pop		es
+	ret
+
+ALIGN JUMP_ALIGN
+.CopyItemFromDSSItoESDI:
+	push	si
+	push	cx
+
+	shr		cx, 1			; We want to copy WORDs for performance
+	jcxz	.CopyLastByte
+	rep		movsw
+.CopyLastByte:
+	jnc		SHORT .CopyComplete
+	movsb
+.CopyComplete:
+	pop		cx
+	pop		si
+	ret
+
+
+;--------------------------------------------------------------------
+; GetItemPointerToDSSIfromIndexInDX
+; GetItemPointerToDSSIfromIndexInAX
+;	Parameters:
+;		AX or DX:	Item index
+;		CX:			Size of struct in bytes
+;		SS:BP:		Ptr to QSORT_PARAMS
+;	Returns:
+;		DS:SI:		Ptr to item
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+GetItemPointerToDSSIfromIndexInDX:
+	xchg	ax, dx
+	call	GetItemPointerToDSSIfromIndexInAX
+	xchg	dx, ax
+	ret
+
+ALIGN JUMP_ALIGN
+GetItemPointerToDSSIfromIndexInAX:
+	push	dx
+	push	ax
+
+	mul		cx		; DX:AX = index (AX) * size of struct (CX)
+	lds		si, [bp+QSORT_PARAMS.lpItems]
+	add		si, ax
+
+	pop		ax
+	pop		dx
+	ret
