Index: /trunk/Assembly_Library/Inc/File.inc
===================================================================
--- /trunk/Assembly_Library/Inc/File.inc	(revision 65)
+++ /trunk/Assembly_Library/Inc/File.inc	(revision 66)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	8.10.2010
-; Last update	:	10.10.2010
+; Last update	:	6.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	File library defines.
@@ -31,3 +31,7 @@
 
 
+; Max number of bytes to read/write per DOS call when transferring DX:CX bytes
+SPLIT_SIZE_FOR_LARGE_TRANSFERS	EQU		(32<<10)
+
+
 %endif ; FILE_INC
Index: /trunk/Assembly_Library/Src/File/FileIO.asm
===================================================================
--- /trunk/Assembly_Library/Src/File/FileIO.asm	(revision 65)
+++ /trunk/Assembly_Library/Src/File/FileIO.asm	(revision 66)
@@ -2,5 +2,5 @@
 ; Project name	:	Assembly Library
 ; Created date	:	1.9.2010
-; Last update	:	10.10.2010
+; Last update	:	6.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for file access.
@@ -49,4 +49,25 @@
 	ret
 
+
+;--------------------------------------------------------------------
+; FileIO_ReadDXCXbytesToDSSIusingHandleFromBX
+;	Parameters:
+;		BX:		File handle
+;		DX:CX:	Number of bytes to read
+;		DS:SI:	Ptr to destination buffer
+;	Returns:
+;		AX:		DOS error code if CF set
+;		CF:		Clear if successfull
+;				Set if error
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+FileIO_ReadDXCXbytesToDSSIusingHandleFromBX:
+	push	bp
+	mov		bp, FileIO_ReadCXbytesToDSSIusingHandleFromBX
+	call	SplitLargeReadOrWritesToSmallerBlocks
+	pop		bp
+	ret
 
 ;--------------------------------------------------------------------
@@ -77,4 +98,25 @@
 
 ;--------------------------------------------------------------------
+; FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX
+;	Parameters:
+;		BX:		File handle
+;		DX:CX:	Number of bytes to write
+;		DS:SI:	Ptr to source buffer
+;	Returns:
+;		AX:		DOS error code if CF set
+;		CF:		Clear if successfull
+;				Set if error
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+FileIO_WriteDXCXbytesFromDSSIusingHandleFromBX:
+	push	bp
+	mov		bp, FileIO_WriteCXbytesFromDSSIusingHandleFromBX
+	call	SplitLargeReadOrWritesToSmallerBlocks
+	pop		bp
+	ret
+
+;--------------------------------------------------------------------
 ; File position is updated so next write will start where
 ; previous write stopped.
@@ -100,4 +142,56 @@
 	xchg	si, dx
 	ret
+
+
+;--------------------------------------------------------------------
+; SplitLargeReadOrWritesToSmallerBlocks
+;	Parameters:
+;		BX:		File handle
+;		BP:		Ptr to transfer function
+;		DX:CX:	Number of bytes to transfer
+;		DS:SI:	Ptr to transfer buffer
+;	Returns:
+;		AX:		DOS error code if CF set
+;		CF:		Clear if successfull
+;				Set if error
+;	Corrupts registers:
+;		AX
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+SplitLargeReadOrWritesToSmallerBlocks:
+	push	ds
+	push	si
+	push	dx
+	push	cx
+
+	xchg	ax, cx					; DX:AX now holds bytes to transfer
+	mov		cx, SPLIT_SIZE_FOR_LARGE_TRANSFERS
+	div		cx						; AX = Number of full transfers
+	push	dx						; Bytes for last transfer
+	test	ax, ax
+	jz		SHORT .TransferRemainingBytes
+	xchg	dx, ax					; DX = Number of full transfers
+
+ALIGN JUMP_ALIGN
+.TransferNextBytes:
+	call	Registers_NormalizeDSSI
+	call	bp						; Transfer function
+	jc		SHORT .ErrorOccurredDuringTransfer
+	dec		dx
+	jnz		SHORT .TransferNextBytes
+.TransferRemainingBytes:
+	pop		cx						; CX = Bytes for last transfer
+	jcxz	.ReturnErrorCodeInAX	; No remaining bytes
+	call	Registers_NormalizeDSSI
+	call	bp
+.ReturnErrorCodeInAX:
+	pop		cx
+	pop		dx
+	pop		si
+	pop		ds
+	ret
+.ErrorOccurredDuringTransfer:
+	pop		cx						; Remove bytes for last transfer
+	jmp		SHORT .ReturnErrorCodeInAX
 
 
Index: /trunk/Assembly_Library/Src/Util/Registers.asm
===================================================================
--- /trunk/Assembly_Library/Src/Util/Registers.asm	(revision 65)
+++ /trunk/Assembly_Library/Src/Util/Registers.asm	(revision 66)
@@ -2,10 +2,60 @@
 ; Project name	:	Assembly Library
 ; Created date	:	24.10.2010
-; Last update	:	24.10.2010
+; Last update	:	6.12.2010
 ; Author		:	Tomi Tilli
 ; Description	:	Functions for register operations.
 
+;--------------------------------------------------------------------
+; NORMALIZE_FAR_POINTER
+;	Parameters:
+;		%1:%2:		Far pointer to normalize
+;		%3:			Scratch register
+;		%4:			Scratch register
+;	Returns:
+;		%1:%2:		Normalized far pointer
+;	Corrupts registers:
+;		%3, %4
+;--------------------------------------------------------------------
+%macro NORMALIZE_FAR_POINTER 4
+	mov		%4, %2				; Copy offset to scratch reg
+	and		%2, BYTE 0Fh		; Clear offset bits 15...4
+	eSHR_IM	%4, 4				; Divide offset by 16
+	mov		%3, %1				; Copy segment to scratch reg
+	add		%3, %4				; Add shifted offset to segment
+	mov		%1, %3				; Set normalized segment
+%endmacro
+
+
 ; Section containing code
 SECTION .text
+
+;--------------------------------------------------------------------
+; Registers_NormalizeDSSI
+; Registers_NormalizeESDI
+;	Parameters
+;		DS:SI or ES:DI:	Ptr to normalize
+;	Returns:
+;		DS:SI or ES:DI:	Normalized pointer
+;	Corrupts registers:
+;		Nothing
+;--------------------------------------------------------------------
+ALIGN JUMP_ALIGN
+Registers_NormalizeDSSI:
+	push	dx
+	push	ax
+	NORMALIZE_FAR_POINTER ds, si, ax, dx
+	pop		ax
+	pop		dx
+	ret
+
+ALIGN JUMP_ALIGN
+Registers_NormalizeESDI:
+	push	dx
+	push	ax
+	NORMALIZE_FAR_POINTER es, di, ax, dx
+	pop		ax
+	pop		dx
+	ret
+
 
 ;--------------------------------------------------------------------
@@ -85,7 +135,2 @@
 	pop		ax
 	ret
-
-	
-ALIGN JUMP_ALIGN
-Registers_SetCFifCXisZero:
-	
