Index: trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm
===================================================================
--- trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/Buffers.asm	(revision 59)
+++ 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
