Index: trunk/Assembly_Library/Inc/CgaSnow.inc
===================================================================
--- trunk/Assembly_Library/Inc/CgaSnow.inc	(revision 588)
+++ trunk/Assembly_Library/Inc/CgaSnow.inc	(revision 589)
@@ -1,7 +1,3 @@
-; File name		:	CgaSnow.inc
-; Project name	:	AssemblyLibrary
-; Created date	:	8.10.2010
-; Last update	:	11.10.2010
-; Author		:	Tomi Tilli
+; Project name	:	Assembly Library
 ; Description	:	Macros for preventing CGA snow.
 %ifndef CGASNOW_INC
@@ -9,5 +5,6 @@
 
 ;--------------------------------------------------------------------
-; WAIT_RETRACE_IF_NECESSARY_THEN
+; CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN
+; JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN
 ;	Parameters:
 ;		%1:		Instruction that accessed CGA memory
@@ -22,5 +19,5 @@
 ;		AX, DX
 ;--------------------------------------------------------------------
-%macro WAIT_RETRACE_IF_NECESSARY_THEN 1
+%macro CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN 1
 %ifdef ELIMINATE_CGA_SNOW
 	%ifidn %1, stosb
@@ -31,5 +28,5 @@
 		call	CgaSnow_RepMovsb
 	%else
-		%error	"Invalid instruction passed to WAIT_RETRACE_IF_NECESSARY_THEN"
+		%error	"Invalid instruction passed to CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN"
 	%endif
 %else	; No CGA snow prevention
@@ -38,4 +35,26 @@
 	%else
 		%1	; Single instruction
+	%endif
+%endif
+%endmacro
+
+%macro JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN 1
+%ifdef ELIMINATE_CGA_SNOW
+	%ifidn %1, stosb
+		jmp		CgaSnow_Stosb
+	%elifidn %1, stosw
+		jmp		CgaSnow_Stosw
+	%elifidn %1, rep movsb
+		jmp		CgaSnow_RepMovsb
+	%else
+		%error	"Invalid instruction passed to JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN"
+	%endif
+%else	; No CGA snow prevention
+	%ifidn %1, rep movsb
+		eSEG_STR rep, es, movsb
+		ret
+	%else
+		%1	; Single instruction
+		ret
 	%endif
 %endif
Index: trunk/Assembly_Library/Inc/DosFunctions.inc
===================================================================
--- trunk/Assembly_Library/Inc/DosFunctions.inc	(revision 588)
+++ trunk/Assembly_Library/Inc/DosFunctions.inc	(revision 589)
@@ -9,27 +9,31 @@
 DOS_TSR_MULTIPLEX_INTERRUPT_2Fh						EQU		2Fh
 
-; DOS drive and file functions
-SELECT_DEFAULT_DRIVE								EQU		0Eh
-GET_CURRENT_DEFAULT_DRIVE							EQU		19h
-GET_DISK_TRANSFER_AREA_ADDRESS						EQU		2Fh
-GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE	EQU		32h
-SET_CURRENT_DIRECTORY								EQU		3Bh
-CREATE_OR_TRUNCATE_FILE								EQU		3Ch
-OPEN_EXISTING_FILE									EQU		3Dh
-CLOSE_FILE											EQU		3Eh
-READ_FROM_FILE_OR_DEVICE							EQU		3Fh
-WRITE_TO_FILE_OR_DEVICE								EQU		40h
-SET_CURRENT_FILE_POSITION							EQU		42h
-GET_CURRENT_DIRECTORY								EQU		47h
-FIND_FIRST_MATCHING_FILE							EQU		4Eh
-FIND_NEXT_MATCHING_FILE								EQU		4Fh
-
-; DOS functions for TSRs
-SET_INTERRUPT_VECTOR								EQU		25h
-GET_INTERRUPT_VECTOR								EQU		35h
+; DOS functions
+WRITE_CHARACTER_TO_STANDARD_OUTPUT					EQU		02h		; DOS 1+
+WRITE_STRING_TO_STANDARD_OUTPUT						EQU		09h		; DOS 1+
+SELECT_DEFAULT_DRIVE								EQU		0Eh		; DOS 1+
+GET_CURRENT_DEFAULT_DRIVE							EQU		19h		; DOS 1+
+SET_INTERRUPT_VECTOR								EQU		25h		; DOS 1+
+GET_DISK_TRANSFER_AREA_ADDRESS						EQU		2Fh		; DOS 2+
+GET_DOS_VERSION										EQU		30h		; DOS 2+
+GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE	EQU		32h		; DOS 2+
+GET_INTERRUPT_VECTOR								EQU		35h		; DOS 2+
+SET_CURRENT_DIRECTORY								EQU		3Bh		; DOS 2+
+CREATE_OR_TRUNCATE_FILE								EQU		3Ch		; DOS 2+
+OPEN_EXISTING_FILE									EQU		3Dh		; DOS 2+
+CLOSE_FILE											EQU		3Eh		; DOS 2+
+READ_FROM_FILE_OR_DEVICE							EQU		3Fh		; DOS 2+
+WRITE_TO_FILE_OR_DEVICE								EQU		40h		; DOS 2+
+SET_CURRENT_FILE_POSITION							EQU		42h		; DOS 2+
+CHECK_IF_BLOCK_DEVICE_REMOTE						EQU		4409h	; DOS 3.1+
+GET_CURRENT_DIRECTORY								EQU		47h		; DOS 2+
+TERMINATE_WITH_RETURN_CODE							EQU		4Ch		; DOS 2+
+FIND_FIRST_MATCHING_FILE							EQU		4Eh		; DOS 2+
+FIND_NEXT_MATCHING_FILE								EQU		4Fh		; DOS 2+
 
 ; DOS errors
+ERR_DOS_FUNCTION_NUMBER_INVALID						EQU		01h
+ERR_DOS_INVALID_DRIVE								EQU		0Fh
 ERR_DOS_DRIVE_NOT_READY								EQU		15h
-
 
 
Index: trunk/Assembly_Library/Inc/Emulate.inc
===================================================================
--- trunk/Assembly_Library/Inc/Emulate.inc	(revision 588)
+++ trunk/Assembly_Library/Inc/Emulate.inc	(revision 589)
@@ -579,5 +579,15 @@
 
 %macro eRCL_IM 2
+%ifndef CHECK_FOR_UNUSED_ENTRYPOINTS
+%ifdef USE_386
+	%if %2 = 1
+		adc		%1, %1	; Same size but faster on 386 and 486. Fails if %1 is a memory operand.
+	%else
+		eSHIFT_IM	%1, %2, rcl
+	%endif
+%else
 	eSHIFT_IM	%1, %2, rcl
+%endif
+%endif
 %endmacro
 
Index: trunk/Assembly_Library/Inc/Math.inc
===================================================================
--- trunk/Assembly_Library/Inc/Math.inc	(revision 588)
+++ trunk/Assembly_Library/Inc/Math.inc	(revision 589)
@@ -80,5 +80,5 @@
 .ShiftNextBit:
 	eSHL_IM	ax, 1
-	rcl		dx, 1
+	eRCL_IM	dx, 1
 	loop	.ShiftNextBit
 %endmacro
Index: trunk/Assembly_Library/Inc/SystemTimer.inc
===================================================================
--- trunk/Assembly_Library/Inc/SystemTimer.inc	(revision 588)
+++ trunk/Assembly_Library/Inc/SystemTimer.inc	(revision 589)
@@ -1,4 +1,4 @@
 ; Project name	:	Assembly Library
-; Description	:	System Timer (8254) relates equates and macros.
+; Description	:	System Timer (8254) related equates and macros.
 %ifndef SYSTEMTIMER_INC
 %define SYSTEMTIMER_INC
@@ -34,5 +34,5 @@
 CONTROL_WORD_REGISTER_out				EQU	43h
 
-; Timer 2 is connected to PC Speaker that can be controller from port 61h.
+; Timer 2 is connected to PC Speaker that can be controlled from port 61h.
 SPEAKER_CONTROL_REGISTER				EQU	61h
 FLG_TIMER_2_OUTPUT_in					EQU	(1<<5)	; AT+ only
Index: trunk/Assembly_Library/Src/Display/DisplayCharOut.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Display/DisplayCharOut.asm	(revision 589)
@@ -41,6 +41,5 @@
 	cmp		al, ' '							; Printable character?
 	jb		SHORT DisplayCharOut_BiosTeletypeOutput
-	WAIT_RETRACE_IF_NECESSARY_THEN stosw
-	ret
+	JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosw
 
 ALIGN DISPLAY_JUMP_ALIGN
@@ -96,10 +95,9 @@
 	xchg	al, ah				; Swap character and attribute
 	inc		di					; Skip character
-	WAIT_RETRACE_IF_NECESSARY_THEN stosb
-	ret
+	JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosb
 
 ALIGN DISPLAY_JUMP_ALIGN
 DisplayCharOut_Character:
-	WAIT_RETRACE_IF_NECESSARY_THEN stosb
+	CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosb
 	inc		di					; Skip attribute
 	ret
@@ -107,6 +105,5 @@
 ALIGN DISPLAY_JUMP_ALIGN
 DisplayCharOut_CharacterWithAttribute:
-	WAIT_RETRACE_IF_NECESSARY_THEN stosw
-	ret
+	JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN stosw
 
 
Index: trunk/Assembly_Library/Src/Display/DisplayFormat.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Display/DisplayFormat.asm	(revision 589)
@@ -269,7 +269,8 @@
 	jz		SHORT .CopyWithoutDisplayProcessing
 
-	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
+	CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN rep movsb
 	dec		di					; Point to preceeding character instead of attribute
 	ret
+
 ALIGN DISPLAY_JUMP_ALIGN
 .CopyWithoutDisplayProcessing:
Index: trunk/Assembly_Library/Src/Display/DisplayPage.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayPage.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Display/DisplayPage.asm	(revision 589)
@@ -43,8 +43,5 @@
 %ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
 	%define EXCLUDE
-	%ifdef MODULE_HOTKEYS
-		%undef EXCLUDE
-	%endif
-	%ifdef MODULE_BOOT_MENU
+	%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 		%undef EXCLUDE
 	%endif
Index: trunk/Assembly_Library/Src/Display/DisplayPrint.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Display/DisplayPrint.asm	(revision 589)
@@ -296,8 +296,5 @@
 		%undef EXCLUDE
 	%endif
-	%ifdef MODULE_HOTKEYS
-		%undef EXCLUDE
-	%endif
-	%ifdef MODULE_BOOT_MENU
+	%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 		%undef EXCLUDE
 	%endif
Index: trunk/Assembly_Library/Src/File/Drive.asm
===================================================================
--- trunk/Assembly_Library/Src/File/Drive.asm	(revision 588)
+++ trunk/Assembly_Library/Src/File/Drive.asm	(revision 589)
@@ -86,10 +86,10 @@
 	xchg	dx, ax			; Default drive to DL
 	call	Drive_SetDefaultFromDL
-	eMOVZX	cx, al			; Number of potentially valid drive letters available
-	cmp		cl, 32
-	jb		SHORT .Return
-	mov		cl, 32
-ALIGN JUMP_ALIGN, ret
-.Return:
+	cmp		al, 32			; Number of potentially valid drive letters available
+	jb		SHORT .Below32
+	mov		al, 32
+.Below32:
+	cbw
+	xchg	cx, ax
 	ret
 
@@ -133,6 +133,18 @@
 
 	inc		dx			; Default drive is 00h and first drive is 01h
+	mov		ax, CHECK_IF_BLOCK_DEVICE_REMOTE	; Needs DOS 3.1+
+	mov		bx, dx
+	push	dx
+	int		DOS_INTERRUPT_21h
+	pop		dx
+	jnc		SHORT .DriveIsValid
+	cmp		ax, ERR_DOS_INVALID_DRIVE
+	je		SHORT .DriveIsNotValid
+	; Fall back to old method if ERR_DOS_FUNCTION_NUMBER_INVALID
+
 	mov		ah, GET_DOS_DRIVE_PARAMETER_BLOCK_FOR_SPECIFIC_DRIVE
 	int		DOS_INTERRUPT_21h
+.DriveIsValid:
+.DriveIsNotValid:
 	dec		dx
 	test	al, al
Index: trunk/Assembly_Library/Src/Keyboard/Keyboard.asm
===================================================================
--- trunk/Assembly_Library/Src/Keyboard/Keyboard.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Keyboard/Keyboard.asm	(revision 589)
@@ -291,8 +291,5 @@
 %ifdef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
 	%define EXCLUDE
-	%ifdef MODULE_HOTKEYS
-		%undef EXCLUDE
-	%endif
-	%ifdef MODULE_BOOT_MENU
+	%ifdef MODULE_HOTKEYS OR MODULE_BOOT_MENU
 		%undef EXCLUDE
 	%endif
Index: trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Menu/CharOutLineSplitter.asm	(revision 589)
@@ -162,5 +162,5 @@
 	push	si
 	push	cx
-	WAIT_RETRACE_IF_NECESSARY_THEN rep movsb
+	CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN rep movsb
 	pop		cx
 	pop		si
Index: trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Menu/Dialog/DialogFile.asm	(revision 589)
@@ -239,5 +239,5 @@
 ; AppendFileFromDTAinDSSItoOffScreenBuffer
 ;	Parameters:
-;		CX:		Files/directores found
+;		CX:		Files/directories found
 ;		DL:		Zero if root directory selected
 ;		DS:SI:	Ptr to DTA containing file information
Index: trunk/Assembly_Library/Src/Menu/MenuLoop.asm
===================================================================
--- trunk/Assembly_Library/Src/Menu/MenuLoop.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Menu/MenuLoop.asm	(revision 589)
@@ -106,16 +106,7 @@
 %ifndef MENU_NO_ESC
 	cmp		al, ESC
-	je		SHORT .LeaveMenuWithoutSelectingItem
-%endif
-	cmp		al, CR
-	je		SHORT .SelectItem
-
-	test	BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
-	jz		SHORT MenuLoop_ProcessScrollingKeysFromAX
-	ret		; Return with CF cleared since keystroke not processed
-
-%ifndef MENU_NO_ESC
-ALIGN MENU_JUMP_ALIGN
-.LeaveMenuWithoutSelectingItem:
+	jne		SHORT .NotEscape
+
+	; Leave menu without selecting item
 	call	MenuEvent_ExitMenu
 	jnc		SHORT .CancelMenuExit
@@ -128,9 +119,20 @@
 
 ALIGN MENU_JUMP_ALIGN
-.SelectItem:
+.NotEscape:
+	cmp		al, CR
+	jne		SHORT .NotCarriageReturn
+
+	; Select item
 	mov		cx, [bp+MENUINIT.wHighlightedItem]
 	call	MenuEvent_ItemSelectedFromCX
 	stc
-	ret
+.Return:
+	ret
+
+ALIGN MENU_JUMP_ALIGN
+.NotCarriageReturn:
+	test	BYTE [bp+MENU.bFlags], FLG_MENU_USER_HANDLES_SCROLLING
+	jnz		SHORT .Return	; With CF cleared since keystroke not processed
+	; Fall to MenuLoop_ProcessScrollingKeysFromAX
 
 
@@ -172,8 +174,7 @@
 .ChangeToPreviousPage:
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	xchg	ax, cx
-	neg		ax
-	mov		cx, [bp+MENUINIT.wHighlightedItem]
-	add		cx, ax
+	neg		cx
+	mov		ax, cx
+	add		cx, [bp+MENUINIT.wHighlightedItem]
 	jge		SHORT .MoveHighlightedItemByAX	; No rotation for PgUp
 	; Fall to .SelectFirstItem
@@ -187,7 +188,6 @@
 .ChangeToNextPage:
 	call	MenuScrollbars_GetMaxVisibleItemsOnPageToCX
-	xchg	ax, cx
-	mov		cx, [bp+MENUINIT.wHighlightedItem]
-	add		cx, ax
+	mov		ax, cx
+	add		cx, [bp+MENUINIT.wHighlightedItem]
 	cmp		cx, [bp+MENUINIT.wItems]
 	jb		SHORT .MoveHighlightedItemByAX	; No rotation for PgDn
Index: trunk/Assembly_Library/Src/Serial/SerialServerScan.asm
===================================================================
--- trunk/Assembly_Library/Src/Serial/SerialServerScan.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Serial/SerialServerScan.asm	(revision 589)
@@ -46,16 +46,15 @@
 
 		test	dx, dx
-		jnz		short SerialServerScan_CheckForServer_PortAndBaudInDX
+		jnz		SHORT SerialServerScan_CheckForServer_PortAndBaudInDX
 
-		mov		di,.scanPortAddresses-1
-		mov		ch,1			;  tell server that we are scanning
+		mov		di, .scanPortAddresses-1
+		mov		ch, 1			;  tell server that we are scanning
 
 .nextPort:
 		inc		di				; load next port address
-		xor		dh, dh
-		mov		dl,[cs:di]
+		mov		dh, 40h			; Clear DH and make sure CF is set if error
+		mov		dl, [cs:di]
 		eSHL_IM	dx, 2			; shift from one byte to two
-		stc						; setup error code for exit
-		jz		.error
+		jz		SHORT .error
 
 ;
@@ -63,17 +62,17 @@
 ;
 		push	dx
-		add		dl,Serial_UART_lineControl
-		mov		al, 09ah
+		add		dl, Serial_UART_lineControl
+		mov		al, 9Ah
 		out		dx, al
 		in		al, dx
 		pop		dx
-		cmp		al, 09ah
-		jnz		.nextPort
+		cmp		al, 9Ah
+		jne		SHORT .nextPort
 
-		mov		al, 0ch
+		mov		al, 0Ch
 		out		dx, al
 		in		al, dx
-		cmp		al, 0ch
-		jnz		.nextPort
+		cmp		al, 0Ch
+		jne		SHORT .nextPort
 
 ;
@@ -84,22 +83,22 @@
 ; *on the server side* if the client side had a 4x clock multiplier, a 2x clock multiplier, or no clock multiplier.
 ;
-; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0ch (9600 baud), and
+; Starting with 30h, that means 30h (2400 baud), 18h (4800 baud), 0Ch (9600 baud), and
 ;					            04h (28800 baud), 02h (57600 baud), 01h (115200 baud)
 ;
-; Note: hardware baud multipliers (2x, 4x) will impact the final baud rate and are not known at this level
+; Note: hardware baud multipliers (2x, 4x, 8x) will impact the final baud rate and are not known at this level
 ;
-		mov		dh,030h * 2		; multiply by 2 since we are about to divide by 2
-		mov		dl,[cs:di]		; restore single byte port address for scan
+		mov		dh, 30h * 2		; multiply by 2 since we are about to divide by 2
+		mov		dl, [cs:di]		; restore single byte port address for scan
 
 .nextBaud:
-		shr		dh,1
-		jz		.nextPort
-		cmp		dh,6			; skip from 6 to 4, to move from the top of the 9600 baud range
-		jnz		.testBaud		; to the bottom of the 115200 baud range
-		mov		dh,4
+		shr		dh, 1
+		jz		SHORT .nextPort
+		cmp		dh, 6			; skip from 6 to 4, to move from the top of the 9600 baud range
+		jne		SHORT .testBaud	; to the bottom of the 115200 baud range
+		mov		dh, 4
 
 .testBaud:
 		call	SerialServerScan_CheckForServer_PortAndBaudInDX
-		jc		.nextBaud
+		jc		SHORT .nextBaud
 
 .error:
@@ -135,15 +134,11 @@
 SerialServerScan_CheckForServer_PortAndBaudInDX:
 		push	bp				; setup fake SerialServer_Command
-
 		push	dx				; send port baud and rate, returned in inquire packet
 								; (and possibly returned in the drive identification string)
-
 		push	cx				; send number of sectors, and if it is on a scan or not
-
-		mov		bl,SerialServer_Command_Inquire			; protocol command onto stack with bh
+		mov		bl, SerialServer_Command_Inquire		; protocol command onto stack with bh
 		push	bx
 
-		mov		bp,sp
-
+		mov		bp, sp
 		call	SerialServer_SendReceive
 
Index: trunk/Assembly_Library/Src/Util/Math.asm
===================================================================
--- trunk/Assembly_Library/Src/Util/Math.asm	(revision 588)
+++ trunk/Assembly_Library/Src/Util/Math.asm	(revision 589)
@@ -36,4 +36,5 @@
 ALIGN JUMP_ALIGN
 Math_DivQWatSSBPbyCX:
+%if 1
 	xor		dx, dx
 	mov		ax, [bp+6]		; Load highest divident WORD to DX:AX
@@ -53,4 +54,19 @@
 	mov		[bp], ax
 	ret
+%else ; ~1
+; This is about half the size compared to the above code but it's not tested which is why it's commented away.
+	push	di
+	mov		di, 6
+	xor		dx, dx
+.Next:
+	mov		ax, [bp+di]
+	div		cx
+	mov		[bp+di], ax
+	dec		di
+	dec		di
+	jns		.Next
+	pop		di
+	ret
+%endif ; 1
 %endif
 
