Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/BiosFile.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Univeral BIOS Configurator v2
 ; Created date	:	10.10.2010
-; Last update	:	24.10.2010
+; Last update	:	30.11.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for loading and saving BIOS image file.
@@ -163,5 +163,6 @@
 	call	Buffers_GetFileBufferToESDI
 	call	Registers_CopyESDItoDSSI
-	mov		cx, [cs:g_cfgVars+CFGVARS.wImageSize]
+	mov		cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
+	shl		cx, 1
 	call	FileIO_WriteCXbytesFromDSSIusingHandleFromBX
 	jc		SHORT .DisplayErrorMessage
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Universal BIOS Configurator v2
 ; Created date	:	6.10.2010
-; Last update	:	19.11.2010
+; Last update	:	5.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for accessing file and flash buffers.
@@ -41,9 +41,15 @@
 
 	call	Buffers_GetFileBufferToESDI
-	jmp		SHORT Buffers_IsXtideUniversalBiosSignatureInESDI
+	call	Buffers_IsXtideUniversalBiosSignatureInESDI
+	jnz		SHORT .NoFileOrBiosLoaded
+	jmp		SHORT .IsSupportedVersionOfXtideUniversalBiosLoaded
 .NoFileOrBiosLoaded:
 	or		cl, 1		; Clear ZF
 	ret
 
+
+ALIGN JUMP_ALIGN
+.IsSupportedVersionOfXtideUniversalBiosLoaded:
+	
 
 ;--------------------------------------------------------------------
@@ -79,5 +85,5 @@
 ;		Nothing
 ;	Corrupts registers:
-;		AX, BX, CX, DX
+;		AX, CX
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
@@ -85,75 +91,8 @@
 	and		WORD [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED)
 	or		WORD [cs:g_cfgVars+CFGVARS.wFlags], ax
-	; Fall to .AdjustBiosImageSizeToSupportedEepromSize
-
-;--------------------------------------------------------------------
-; .AdjustBiosImageSizeInCXtoSupportedEepromSize
-;	Parameters:
-;		CX:		Size of loaded BIOS image
-;	Returns:
-;		CX:		Size of BIOS image (and EEPROM required)
-;	Corrupts registers:
-;		AX, BX, DX
-;--------------------------------------------------------------------
-.AdjustBiosImageSizeInCXtoSupportedEepromSize:
-	mov		bx, .rgwSupportedEepromSizes
-	mov		dx, NUMBER_OF_SUPPORTED_EEPROM_SIZES-1
-ALIGN JUMP_ALIGN
-.CheckNextEepromSize:
-	cmp		cx, [cs:bx]
-	je		SHORT .StoreImageSizeFromCX
-	jb		SHORT .AppendZeroesToTheEndOfBuffer
-	inc		bx
-	inc		bx
-	dec		dx
-	jnz		SHORT .CheckNextEepromSize
-	xor		cx, cx
-	jmp		SHORT .StoreImageSizeFromCX	; 0 = 65536
-ALIGN WORD_ALIGN
-.rgwSupportedEepromSizes:
-	dw		4<<10
-	dw		8<<10
-	dw		16<<10
-	dw		32<<10
-
-;--------------------------------------------------------------------
-; .AppendZeroesToTheEndOfBuffer
-;	Parameters:
-;		CX:		Size of loaded BIOS image
-;		CS:BX:	Ptr to EEPROM size
-;	Returns:
-;		CX:		EEPROM size
-;	Corrupts registers:
-;		AX
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.AppendZeroesToTheEndOfBuffer:
-	push	es
-	push	di
-
-	call	Buffers_GetFileBufferToESDI
-	mov		ax, [cs:bx]
-	sub		ax, cx			; AX = zeroes to append
-	xchg	ax, cx			; AX = BIOS image size, CX = zeroes to append
-	add		di, ax
-	call	Memory_ZeroESDIwithSizeInCX
-	mov		cx, [cs:bx]
-
-	pop		di
-	pop		es
-	; Fall to .StoreImageSizeFromCX
-
-;--------------------------------------------------------------------
-; .StoreImageSizeFromCX
-;	Parameters:
-;		CX:		Size of BIOS image (and EEPROM required)
-;	Returns:
-;		Nothing
-;	Corrupts registers:
-;		Nothing
-;--------------------------------------------------------------------
-ALIGN JUMP_ALIGN
-.StoreImageSizeFromCX:
-	mov		[cs:g_cfgVars+CFGVARS.wImageSize], cx
+	mov		ax, (64<<10) / 2	; 32768 WORDs
+	shr		cx, 1				; Bytes to WORDs
+	eCMOVZ	cx, ax
+	mov		[cs:g_cfgVars+CFGVARS.wImageSizeInWords], cx
 	ret
 
@@ -204,4 +143,35 @@
 
 ;--------------------------------------------------------------------
+; Buffers_AppendZeroesIfNeeded
+;	Parameters:
+;		Nothing
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, CX, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Buffers_AppendZeroesIfNeeded:
+	push	es
+
+	eMOVZX	di, BYTE [cs:g_cfgVars+CFGVARS.bEepromType]
+	mov		cx, [cs:di+g_rgwEepromTypeToSizeInWords]
+	sub		cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]	; CX = WORDs to append
+	jle		SHORT .NoNeedToAppendZeroes
+
+	call	Buffers_GetFileBufferToESDI
+	mov		ax, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
+	shl		ax, 1
+	add		di, ax			; ES:DI now point first unused image byte
+	xor		ax, ax
+	cld
+	rep stosw
+ALIGN JUMP_ALIGN
+.NoNeedToAppendZeroes:
+	pop		es
+	ret
+
+
+;--------------------------------------------------------------------
 ; Buffers_GenerateChecksum
 ;	Parameters:
@@ -217,5 +187,6 @@
 
 	call	Buffers_GetFileBufferToESDI
-	mov		cx, [cs:g_cfgVars+CFGVARS.wImageSize]
+	mov		cx, [cs:g_cfgVars+CFGVARS.wImageSizeInWords]
+	shl		cx, 1			; Words to bytes
 	dec		cx				; Leave space for checksum byte
 	xor		ax, ax
@@ -268,4 +239,5 @@
 ;--------------------------------------------------------------------
 ; Buffers_GetFileBufferToESDI
+; Buffers_GetFlashComparisonBufferToESDI
 ; Buffers_GetFileDialogItemBufferToESDI
 ;	Parameters:
@@ -277,4 +249,5 @@
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
+Buffers_GetFlashComparisonBufferToESDI:
 Buffers_GetFileDialogItemBufferToESDI:
 	call	Buffers_GetFileBufferToESDI
@@ -285,4 +258,5 @@
 	pop		di
 	ret
+ALIGN JUMP_ALIGN
 Buffers_GetFileBufferToESDI:
 	mov		di, cs
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Dialogs.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Dialogs.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Dialogs.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Univeral BIOS Configurator v2
 ; Created date	:	10.10.2010
-; Last update	:	19.11.2010
+; Last update	:	2.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for displaying dialogs.
@@ -85,4 +85,5 @@
 ;	Parameters:
 ;		DS:SI:	Ptr to FILE_DIALOG_IO
+;		SS:BP:	Menu handle
 ;	Returns:
 ;		Nothing
@@ -113,5 +114,5 @@
 ; Dialogs_DisplaySaveChangesDialog
 ;	Parameters:
-;		Nothing
+;		SS:BP:	Menu handle
 ;	Returns:
 ;		ZF:		Set if user wants to do the action
@@ -155,4 +156,38 @@
 
 ;--------------------------------------------------------------------
+; Dialogs_DisplayProgressDialogForFlashingWithDialogIoInDSSIandFlashvarsInDSBX
+;	Parameters:
+;		DS:BX:	Ptr to FLASHVARS
+;		DS:SI:	Ptr to PROGRESS_DIALOG_IO
+;		SS:BP:	Menu handle
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, DX, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Dialogs_DisplayProgressDialogForFlashingWithDialogIoInDSSIandFlashvarsInDSBX:
+	call	.InitializeProgressDialogIoInDSSIwithFlashvarsInDSBX
+	mov		dx, ds
+	mov		ax, bx
+	CALL_MENU_LIBRARY StartProgressTaskWithIoInDSSIandParamInDXAX
+	ret
+
+ALIGN JUMP_ALIGN
+.InitializeProgressDialogIoInDSSIwithFlashvarsInDSBX:
+	call	InitializeDialogInputFromDSSI
+	mov		WORD [si+DIALOG_INPUT.fszTitle], g_szEEPROM
+
+	xor		ax, ax
+	mov		[si+PROGRESS_DIALOG_IO.wCurrentProgressValue], ax
+	mov		dx, [bx+FLASHVARS.wPagesToFlash]
+	mov		[si+PROGRESS_DIALOG_IO.wMaxProgressValue], dx
+	mov		[si+PROGRESS_DIALOG_IO.wMinProgressValue], ax
+	mov		WORD [si+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI], Flash_EepromWithFlashvarsInDSSI
+	mov		[si+PROGRESS_DIALOG_IO.fnTaskWithParamInDSSI+2], cs
+	ret
+
+
+;--------------------------------------------------------------------
 ; InitializeDialogInputFromDSSI
 ;	Parameters:
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/EEPROM.asm	(revision 65)
@@ -2,7 +2,28 @@
 ; Project name	:	XTIDE Univeral BIOS Configurator v2
 ; Created date	:	19.4.2010
-; Last update	:	10.10.2010
+; Last update	:	3.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for managing EEPROM contents.
+
+; Section containing initialized data
+SECTION .data
+
+ALIGN WORD_ALIGN
+g_rgwEepromTypeToSizeInWords:
+	dw		(2<<10) / 2		; EEPROM_TYPE.2816_2kiB
+	dw		(8<<10) / 2
+	dw		(32<<10) / 2
+	dw		(64<<10) / 2
+
+g_rgwEepromPageToSizeInBytes:
+	dw		1				; EEPROM_PAGE.1_byte
+	dw		2
+	dw		4
+	dw		8
+	dw		16
+	dw		32
+	dw		64
+
+
 
 ; Section containing code
@@ -134,15 +155,26 @@
 
 ;--------------------------------------------------------------------
-; EEPROM_GetPointerForFlashingToESDI
+; EEPROM_LoadFromRomToRamComparisonBuffer
 ;	Parameters:
 ;		Nothing
 ;	Returns:
-;		ES:DI:	Ptr to EEPROM to be flashed
+;		Nothing
 ;	Corrupts registers:
-;		Nothing
+;		BX, CX, SI, DI
 ;--------------------------------------------------------------------
 ALIGN JUMP_ALIGN
-EEPROM_GetPointerForFlashingToESDI:
-	mov		es, [cs:g_cfgVars+CFGVARS.wEepromSegment]
-	xor		di, di
+EEPROM_LoadFromRomToRamComparisonBuffer:
+	push	es
+	push	ds
+
+	mov		ds, [cs:g_cfgVars+CFGVARS.wEepromSegment]
+	xor		si, si
+	call	Buffers_GetFlashComparisonBufferToESDI
+	eMOVZX	bx, BYTE [cs:g_cfgVars+CFGVARS.bEepromType]
+	mov		cx, [cs:bx+g_rgwEepromTypeToSizeInWords]
+	cld
+	rep movsw
+
+	pop		ds
+	pop		es
 	ret
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Flash.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Flash.asm	(revision 65)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Flash.asm	(revision 65)
@@ -0,0 +1,343 @@
+; File name		:	Flash.asm
+; Project name	:	XTIDE Universal BIOS Configurator v2
+; Created date	:	1.12.2010
+; Last update	:	3.12.2010
+; Author		:	Tomi Tilli
+; Description	:	Functions for flashing the EEPROM.
+
+; Section containing code
+SECTION .text
+
+;--------------------------------------------------------------------
+; Flash_EepromWithFlashvarsInDSSI
+;	Parameters:
+;		DS:SI:	Ptr to FLASHVARS
+;	Returns:
+;		FLASHVARS.flashResult
+;	Corrupts registers:
+;		All, including segments
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Flash_EepromWithFlashvarsInDSSI:
+	mov		[si+FLASHVARS.wProgressUpdateParam], bp	; Store handle to progress DIALOG
+	mov		bp, si									; Flashvars now in SS:BP
+	mov		cx, [bp+FLASHVARS.wPagesToFlash]
+ALIGN JUMP_ALIGN
+.FlashNextPage:
+	call	DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
+	call	Flash_SinglePageWithFlashvarsInSSBP
+	jc		SHORT .PollingError
+	call	AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
+	jne		SHORT .DataVerifyError
+
+	mov		ax, [bp+FLASHVARS.wEepromPageSize]
+	add		[bp+FLASHVARS.fpNextSourcePage], ax
+	add		[bp+FLASHVARS.fpNextComparisonPage], ax
+	add		[bp+FLASHVARS.fpNextDestinationPage], ax
+
+	loop	.FlashNextPage
+	mov		BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.success
+	ret
+
+.PollingError:
+	mov		BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.PollingTimeoutError
+	ret
+.DataVerifyError:
+	mov		BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DataVerifyError
+	ret
+
+
+;--------------------------------------------------------------------
+; Flash_SinglePageWithFlashvarsInSSBP
+;	Parameters:
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		CF:		Set if polling timeout error
+;				Cleared if page written successfully
+;	Corrupts registers:
+;		AX, BX, DX, SI, DI, DS, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Flash_SinglePageWithFlashvarsInSSBP:
+	cld
+	call	AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
+	je		SHORT .NoNeedToFlashThePage	; CF cleared
+
+	push	cx
+	call	.GetSdpCommandFunctionToDXwithFlashvarsInSSBP
+	mov		cx, [bp+FLASHVARS.wEepromPageSize]
+	mov		si, [bp+FLASHVARS.fpNextSourcePage]
+	les		di, [bp+FLASHVARS.fpNextComparisonPage]
+	mov		bx, [bp+FLASHVARS.fpNextDestinationPage]
+	call	WriteAllChangedBytesFromPageToEeprom
+	pop		cx
+.NoNeedToFlashThePage:
+	ret
+
+;--------------------------------------------------------------------
+; .GetSdpCommandFunctionToDXwithFlashvarsInSSBP
+;	Parameters:
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		DX:		Ptr to SDP Command function
+;	Corrupts registers:
+;		BX, SI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.GetSdpCommandFunctionToDXwithFlashvarsInSSBP:
+	eMOVZX	bx, BYTE [bp+FLASHVARS.bEepromSdpCommand]
+	mov		si, [cs:bx+.rgpSdpCommandToEepromTypeLookupTable]
+	mov		bl, [bp+FLASHVARS.bEepromType]
+	mov		dx, [cs:bx+si]
+	ret
+
+ALIGN WORD_ALIGN
+.rgpSdpCommandToEepromTypeLookupTable:
+	dw		.rgfnFlashWithoutSDP					; SDP_COMMAND.none
+	dw		.rgfnEnableSdpAndFlash					; SDP_COMMAND.enable
+	dw		.rgfnDisableSdpAndFlash					; SDP_COMMAND.disable
+.rgfnFlashWithoutSDP:		; SDP_COMMAND.none
+	dw		DoNotWriteAnySdpCommand					; EEPROM_TYPE.2816_2kiB
+	dw		DoNotWriteAnySdpCommand					; EEPROM_TYPE.2864_8kiB
+	dw		DoNotWriteAnySdpCommand					; EEPROM_TYPE.28256_32kiB
+	dw		DoNotWriteAnySdpCommand					; EEPROM_TYPE.28512_64kiB
+.rgfnEnableSdpAndFlash:		; SDP_COMMAND.enable
+	dw		WriteSdpEnableCommandFor2816			; EEPROM_TYPE.2816_2kiB
+	dw		WriteSdpEnableCommandFor2864			; EEPROM_TYPE.2864_8kiB
+	dw		WriteSdpEnableCommandFor28256or28512	; EEPROM_TYPE.28256_32kiB
+	dw		WriteSdpEnableCommandFor28256or28512	; EEPROM_TYPE.28512_64kiB
+.rgfnDisableSdpAndFlash:	; SDP_COMMAND.disable
+	dw		WriteSdpDisableCommandFor2816			; EEPROM_TYPE.2816_2kiB
+	dw		WriteSdpDisableCommandFor2864			; EEPROM_TYPE.2864_8kiB
+	dw		WriteSdpDisableCommandFor28256or28512	; EEPROM_TYPE.28256_32kiB
+	dw		WriteSdpDisableCommandFor28256or28512	; EEPROM_TYPE.28512_64kiB
+
+
+;--------------------------------------------------------------------
+; AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP
+;	Parameters:
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		ZF:		Set if pages are equal
+;				Cleared if pages are not equal
+;	Corrupts registers:
+;		SI, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+AreSourceAndDestinationPagesEqualFromFlashvarsInSSBP:
+	push	cx
+	mov		cx, [bp+FLASHVARS.wEepromPageSize]
+	lds		si, [bp+FLASHVARS.fpNextSourcePage]
+	les		di, [bp+FLASHVARS.fpNextDestinationPage]
+	repe cmpsb
+	pop		cx
+	ret
+
+
+;--------------------------------------------------------------------
+; ENABLE_SDP
+;	Parameters:
+;		%1:		Offset for first command byte
+;		%2:		Offset for second command byte
+;		DS:		Segment to beginning of EEPROM
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+%macro ENABLE_SDP 2
+	mov		BYTE [%1], 0AAh
+	mov		BYTE [%2], 55h
+	mov		BYTE [%1], 0A0h
+%endmacro
+
+;--------------------------------------------------------------------
+; DISABLE_SDP
+;	Parameters:
+;		%1:		Offset for first command byte
+;		%2:		Offset for second command byte
+;		DS:		Segment to beginning of EEPROM
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+%macro DISABLE_SDP 2
+	mov		BYTE [%1], 0AAh
+	mov		BYTE [%2], 55h
+	mov		BYTE [%1], 80h
+	mov		BYTE [%1], 0AAh
+	mov		BYTE [%2], 55h
+	mov		BYTE [%1], 20h
+%endmacro
+
+;--------------------------------------------------------------------
+; SDP Command Functions
+;	Parameters:
+;		DS:		Segment to beginning of EEPROM
+;	Returns:
+;		Nothing but jumps to WriteActualDataByteAfterSdpCommand
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+WriteSdpEnableCommandFor2816:
+	ENABLE_SDP 555h, 2AAh
+	jmp		ReturnFromSdpCommand
+
+ALIGN JUMP_ALIGN
+WriteSdpEnableCommandFor2864:
+	ENABLE_SDP 1555h, 0AAAh
+	jmp		SHORT ReturnFromSdpCommand
+
+ALIGN JUMP_ALIGN
+WriteSdpEnableCommandFor28256or28512:
+	ENABLE_SDP 5555h, 2AAAh
+	jmp		SHORT ReturnFromSdpCommand
+
+
+ALIGN JUMP_ALIGN
+WriteSdpDisableCommandFor2816:
+	DISABLE_SDP 555h, 2AAh
+	jmp		SHORT ReturnFromSdpCommand
+
+ALIGN JUMP_ALIGN
+WriteSdpDisableCommandFor2864:
+	DISABLE_SDP 1555h, 0AAAh
+	jmp		SHORT ReturnFromSdpCommand
+
+ALIGN JUMP_ALIGN
+WriteSdpDisableCommandFor28256or28512:
+	DISABLE_SDP 5555h, 2AAAh
+DoNotWriteAnySdpCommand:
+	jmp		SHORT ReturnFromSdpCommand
+
+
+;--------------------------------------------------------------------
+; WriteNextChangedByteFromPageToEeprom
+;	Parameters:
+;		CX:		Number of bytes left to write
+;		DX:		Offset to SDP command function
+;		BX:		Offset to next destination byte
+;		SI:		Offset to next source byte
+;		ES:DI:	Ptr to next comparison byte
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		CF:		Set if polling timeout error
+;				Cleared if page written successfully
+;	Corrupts registers:
+;		AX, BX, CX, SI, DI, DS, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+WriteAllChangedBytesFromPageToEeprom:
+	mov		ax, [bp+FLASHVARS.fpNextSourcePage+2]		; AX = Source segment
+	mov		ds, [bp+FLASHVARS.fpNextDestinationPage+2]	; DS = EEPROM segment
+	cli						; Disable interrupts
+	jmp		dx				; Write SDP command (once to the beginning of page)
+ALIGN JUMP_ALIGN
+ReturnFromSdpCommand:
+	mov		ds, ax			; DS:SI now points to source byte
+
+ALIGN JUMP_ALIGN
+.WriteActualDataByteAfterSdpCommand:
+	lodsb					; Load source byte to AL
+	scasb					; Compare source byte to comparison byte
+	je		SHORT .NoChangesForThisByte
+
+	mov		ds, [bp+FLASHVARS.fpNextDestinationPage+2]	; DS:BX now points to EEPROM
+	mov		[bx], al		; Write byte to EEPROM
+	mov		ds, [bp+FLASHVARS.fpNextSourcePage+2]		; Restore DS
+	mov		[bp+FLASHVARS.wLastOffsetWritten], bx
+	mov		[bp+FLASHVARS.bLastByteWritten], al
+
+ALIGN JUMP_ALIGN
+.NoChangesForThisByte:
+	inc		bx				; Increment destination offset
+	loop	.WriteActualDataByteAfterSdpCommand
+	sti						; Enable interrupts
+	; Fall to WaitUntilEepromPageWriteHasCompleted
+
+
+;--------------------------------------------------------------------
+; WaitUntilEepromPageWriteHasCompleted
+;	Parameters:
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		CF:		Set if polling timeout error
+;				Cleared if page written successfully
+;	Corrupts registers:
+;		AX, BX, DI, DS, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+WaitUntilEepromPageWriteHasCompleted:
+	call	.InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
+	mov		es, [bp+FLASHVARS.fpNextDestinationPage+2]
+	mov		di, [bp+FLASHVARS.wLastOffsetWritten]
+ALIGN JUMP_ALIGN
+.PollEeprom:
+	call	.HasWriteCycleCompleted
+	je		SHORT .PageWriteCompleted	; CF cleared
+	call	TimerTicks_GetTimeoutTicksLeftToAXfromDSBX
+	jnc		SHORT .PollEeprom
+ALIGN JUMP_ALIGN
+.PageWriteCompleted:
+	ret
+
+;--------------------------------------------------------------------
+; .InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP
+;	Parameters:
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		DS:BX:	Ptr to timeout counter variable
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.InitializeTimeoutCounterForEepromPollingWithFlashvarsInSSBP:
+	push	ss
+	pop		ds
+	lea		bx, [bp+FLASHVARS.wTimeoutCounter]
+	mov		ax, EEPROM_POLLING_TIMEOUT_TICKS
+	jmp		TimerTicks_InitializeTimeoutFromAX
+
+;--------------------------------------------------------------------
+; .HasWriteCycleCompleted
+;	Parameters:
+;		ES:DI:	Ptr to last written byte in EEPROM
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		ZF:		Set if write cycle has completed
+;				Cleared if write cycle in progress
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.HasWriteCycleCompleted:
+	mov		ah, [es:di]		; Load byte from EEPROM
+	mov		al, [bp+FLASHVARS.bLastByteWritten]
+	and		ax, 8080h		; Clear all but bit 7 from both bytes
+	cmp		al, ah			; Set ZF if high bits are the same
+	ret
+
+
+;--------------------------------------------------------------------
+; DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP
+;	Parameters:
+;		CX:		Number of pages left to flash
+;		SS:BP:	Ptr to FLASHVARS
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+DisplayFlashProgressWithPagesLeftInCXandFlashvarsInSSBP:
+	push	bp
+
+	mov		ax, [bp+FLASHVARS.wPagesToFlash]
+	sub		ax, cx
+	mov		bp, [bp+FLASHVARS.wProgressUpdateParam]	; BP now has MENU handle
+	CALL_MENU_LIBRARY SetProgressValueFromAX
+
+	pop		bp
+	ret
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Main.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Univeral BIOS Configurator v2
 ; Created date	:	5.10.2010
-; Last update	:	19.11.2010
+; Last update	:	3.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Program start and exit.			
@@ -33,4 +33,5 @@
 %include "Dialogs.asm"
 %include "EEPROM.asm"
+%include "Flash.asm"
 %include "MenuEvents.asm"
 %include "Menuitem.asm"
@@ -97,5 +98,5 @@
 	at	CFGVARS.wEepromSegment,		dw	DEFAULT_EEPROM_SEGMENT
 	at	CFGVARS.bEepromType,		db	DEFAULT_EEPROM_TYPE
-	at	CFGVARS.bEepromPageSize,	db	DEFAULT_PAGE_SIZE
+	at	CFGVARS.bEepromPage,		db	DEFAULT_PAGE_SIZE
 	at	CFGVARS.bSdpCommand,		db	DEFAULT_SDP_COMMAND
 iend
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuitemPrint.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuitemPrint.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/MenuitemPrint.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Universal BIOS Configurator v2
 ; Created date	:	5.10.2010
-; Last update	:	2.11.2010
+; Last update	:	5.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for printing MENUITEM name and value.
@@ -202,6 +202,8 @@
 	CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX
 
+	call	Menuitem_GetValueToAXfromMenuitemInDSSI
 	mov		bx, 10
-	jmp		SHORT PrintByteOrWordValue
+	CALL_DISPLAY_LIBRARY PrintWordFromAXwithBaseInBX
+	jmp		SHORT FinishPrintingUnsignedOrHexValue
 
 ;--------------------------------------------------------------------
@@ -222,11 +224,11 @@
 	CALL_DISPLAY_LIBRARY PrepareOffScreenBufferInESBXwithLengthInCX
 
+	call	Menuitem_GetValueToAXfromMenuitemInDSSI
 	mov		bx, 16
-PrintByteOrWordValue:
-	push	bx
-	call	Menuitem_GetValueToAXfromMenuitemInDSSI
-	pop		bx
-
 	CALL_DISPLAY_LIBRARY PrintWordFromAXwithBaseInBX
+	mov		al, 'h'
+	CALL_DISPLAY_LIBRARY PrintCharacterFromAL
+ALIGN JUMP_ALIGN
+FinishPrintingUnsignedOrHexValue:
 	CALL_DISPLAY_LIBRARY GetCharacterPointerToBXAX
 	xchg	bx, ax
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Menupages/FlashMenu.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Universal BIOS Configurator v2
 ; Created date	:	19.11.2010
-; Last update	:	19.11.2010
+; Last update	:	5.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	"Flash EEPROM" menu structs and functions.
@@ -78,5 +78,5 @@
 	at	MENUITEM.bFlags,			db	FLG_MENUITEM_PROGRAMVAR | FLG_MENUITEM_BYTEVALUE | FLG_MENUITEM_VISIBLE
 	at	MENUITEM.bType,				db	TYPE_MENUITEM_MULTICHOISE
-	at	MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset,		dw	CFGVARS.bEepromPageSize
+	at	MENUITEM.itemValue + ITEM_VALUE.wRomvarsValueOffset,		dw	CFGVARS.bEepromPage
 	at	MENUITEM.itemValue + ITEM_VALUE.szDialogTitle,				dw	g_szDlgFlashPageSize
 	at	MENUITEM.itemValue + ITEM_VALUE.szMultichoise,				dw	g_szMultichoisePageSize
@@ -137,11 +137,11 @@
 
 g_rgwChoiseToValueLookupForPageSize:
-	dw	EEPROM_PAGE_SIZE.1_byte
-	dw	EEPROM_PAGE_SIZE.2_bytes
-	dw	EEPROM_PAGE_SIZE.4_bytes
-	dw	EEPROM_PAGE_SIZE.8_bytes
-	dw	EEPROM_PAGE_SIZE.16_bytes
-	dw	EEPROM_PAGE_SIZE.32_bytes
-	dw	EEPROM_PAGE_SIZE.64_bytes
+	dw	EEPROM_PAGE.1_byte
+	dw	EEPROM_PAGE.2_bytes
+	dw	EEPROM_PAGE.4_bytes
+	dw	EEPROM_PAGE.8_bytes
+	dw	EEPROM_PAGE.16_bytes
+	dw	EEPROM_PAGE.32_bytes
+	dw	EEPROM_PAGE.64_bytes
 g_rgszValueToStringLookupForPageSize:
 	dw	g_szValueFlash1byte
@@ -185,3 +185,171 @@
 ALIGN JUMP_ALIGN
 StartFlashing:
+	push	es
+	push	ds
+
+	call	.PrepareBuffersForFlashing
+	mov		cx, FLASHVARS_size + PROGRESS_DIALOG_IO_size
+	call	Memory_ReserveCXbytesFromStackToDSSI
+	call	.InitializeFlashvarsFromDSSI
+	mov		bx, si							; DS:BX now points to FLASHVARS
+	add		si, BYTE FLASHVARS_size			; DS:SI now points to PROGRESS_DIALOG_IO
+	call	Dialogs_DisplayProgressDialogForFlashingWithDialogIoInDSSIandFlashvarsInDSBX
+	call	.DisplayFlashingResultsFromFlashvarsInDSBX
+
+	add		sp, BYTE FLASHVARS_size + PROGRESS_DIALOG_IO_size
+	pop		ds
+	pop		es
 	ret
+
+;--------------------------------------------------------------------
+; .PrepareBuffersForFlashing
+;	Parameters:
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, CX, SI, DI
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.PrepareBuffersForFlashing:
+	call	EEPROM_LoadFromRomToRamComparisonBuffer
+	call	Buffers_AppendZeroesIfNeeded
+	test	WORD [cs:g_cfgVars+CFGVARS.wFlags], FLG_CFGVARS_CHECKSUM
+	jz		SHORT .DoNotGenerateChecksumByte
+	jmp		Buffers_GenerateChecksum
+.DoNotGenerateChecksumByte:
+	ret
+
+;--------------------------------------------------------------------
+; .InitializeFlashvarsFromDSSI
+;	Parameters:
+;		DS:SI:	Ptr to FLASHVARS to initialize
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, DX, DI, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.InitializeFlashvarsFromDSSI:
+	call	Buffers_GetFileBufferToESDI
+	mov		[si+FLASHVARS.fpNextSourcePage], di
+	mov		[si+FLASHVARS.fpNextSourcePage+2], es
+
+	call	Buffers_GetFlashComparisonBufferToESDI
+	mov		[si+FLASHVARS.fpNextComparisonPage], di
+	mov		[si+FLASHVARS.fpNextComparisonPage+2], es
+
+	mov		ax, [cs:g_cfgVars+CFGVARS.wEepromSegment]
+	mov		WORD [si+FLASHVARS.fpNextDestinationPage], 0
+	mov		[si+FLASHVARS.fpNextDestinationPage+2], ax
+
+	mov		al, [cs:g_cfgVars+CFGVARS.bEepromType]
+	mov		[si+FLASHVARS.bEepromType], al
+
+	mov		al, [cs:g_cfgVars+CFGVARS.bSdpCommand]
+	mov		[si+FLASHVARS.bEepromSdpCommand], al
+
+	eMOVZX	bx, BYTE [cs:g_cfgVars+CFGVARS.bEepromPage]
+	mov		ax, [cs:bx+g_rgwEepromPageToSizeInBytes]
+	mov		[si+FLASHVARS.wEepromPageSize], ax
+
+	call	.GetNumberOfPagesToFlashToAX
+	mov		[si+FLASHVARS.wPagesToFlash], ax
+	ret
+
+;--------------------------------------------------------------------
+; .GetNumberOfPagesToFlashToAX
+;	Parameters:
+;		DS:SI:	Ptr to FLASHVARS to initialize
+;	Returns:
+;		AX:		Number of pages to flash (0 = 65536)
+;	Corrupts registers:
+;		BX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.GetNumberOfPagesToFlashToAX:
+	eMOVZX	bx, BYTE [si+FLASHVARS.bEepromType]
+	mov		ax, [cs:bx+g_rgwEepromTypeToSizeInWords]
+	xor		dx, dx
+	shl		ax, 1		; Size in bytes to...
+	rcl		dx, 1		; ...DX:AX
+
+	cmp		WORD [si+FLASHVARS.wEepromPageSize], BYTE 1
+	jbe		SHORT .PreventDivideException
+	div		WORD [si+FLASHVARS.wEepromPageSize]
+.PreventDivideException:
+	ret
+
+
+;--------------------------------------------------------------------
+; .DisplayFlashingResultsFromFlashvarsInDSBX
+;	Parameters:
+;		DS:BX:	Ptr to FLASHVARS
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, BX, DX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.DisplayFlashingResultsFromFlashvarsInDSBX:
+	eMOVZX	bx, BYTE [bx+FLASHVARS.flashResult]
+	jmp		[cs:bx+.rgfnFlashResultMessage]
+
+ALIGN WORD_ALIGN
+.rgfnFlashResultMessage:
+	dw		.DisplayFlashSuccessful
+	dw		.DisplayPollingError
+	dw		.DisplayDataVerifyError
+
+
+;--------------------------------------------------------------------
+; .DisplayPollingError
+; .DisplayDataVerifyError
+; .DisplayFlashSuccessful
+;	Parameters:
+;		SS:BP:	Ptr to MENU
+;	Returns:
+;		Nothing
+;	Corrupts registers:
+;		AX, DX, DI, ES
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+.DisplayPollingError:
+	mov		dx, g_szErrEepromPolling
+	jmp		Dialogs_DisplayErrorFromCSDX
+
+ALIGN JUMP_ALIGN
+.DisplayDataVerifyError:
+	mov		dx, g_szErrEepromVerify
+	jmp		Dialogs_DisplayErrorFromCSDX
+
+ALIGN JUMP_ALIGN
+.DisplayFlashSuccessful:
+	call	Buffers_GetFileBufferToESDI
+	cmp		WORD [es:di+ROMVARS.wRomSign], 0AA55h	; PC ROM?
+	je		SHORT .DisplayRebootMessageAndReboot
+	mov		dx, g_szForeignFlash
+	jmp		Dialogs_DisplayNotificationFromCSDX
+ALIGN JUMP_ALIGN
+.DisplayRebootMessageAndReboot:
+	mov		dx, g_szPCFlashSuccessfull
+	call	Dialogs_DisplayNotificationFromCSDX
+	; Fall to .RebootComputer
+
+
+;--------------------------------------------------------------------
+; .RebootComputer
+;	Parameters:
+; 		Nothing
+;	Returns:
+;		Nothing, function never returns
+;	Corrupts registers:
+;		Doesn't matter
+;--------------------------------------------------------------------
+.RebootComputer:
+	mov		al, 0FEh				; System reset (AT+ keyboard controller)
+	out		64h, al					; Reset computer (AT+)
+	nop
+	jmp		WORD 0F000h:0FFF0h		; XT reset
Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm	(revision 63)
+++ trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Strings.asm	(revision 65)
@@ -2,5 +2,5 @@
 ; Project name	:	XTIDE Universal BIOS Configurator v2
 ; Created date	:	5.10.2010
-; Last update	:	19.11.2010
+; Last update	:	5.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	All strings.
@@ -12,5 +12,5 @@
 ; Menu title
 g_szProgramTitle:
-	db	"Configuration and Flashing program for XTIDE Universal BIOS v1.1.4.",LF,CR,NULL
+	db	"Configuration and Flashing program for XTIDE Universal BIOS v1.1.5.",LF,CR,NULL
 g_szXtideUniversalBiosSignature:	db	"XTIDE110",NULL
 g_szBiosIsNotLoaded:				db	"BIOS is not loaded!",NULL
@@ -41,4 +41,13 @@
 g_szErrorDialog:		db	"Error!",NULL
 g_szGenericDialogInfo:	db	"Press ENTER or ESC to close dialog.",NULL
+
+; Flashing related strings
+g_szErrEepromPolling:	db	"Timeout when polling EEPROM.",LF
+						db	"EEPROM was not flashed properly!",NULL
+g_szErrEepromVerify:	db	"EEPROM did not return the same byte that was written.",LF
+						db	"EEPROM was not flashed properly!",NULL
+g_szPCFlashSuccessfull:	db	"EEPROM was written successfully.",LF
+						db	"Press any key to reboot.",NULL
+g_szForeignFlash:		db	"EEPROM was written successfully.",NULL
 
 
@@ -262,5 +271,5 @@
 						db	"32 bytes",LF
 						db	"64 bytes",NULL
-g_szValueFlash1byte:	db	"None",NULL
+g_szValueFlash1byte:	db	"1 byte",NULL
 g_szValueFlash2bytes:	db	"2 bytes",NULL
 g_szValueFlash4bytes:	db	"4 bytes",NULL
