;
; mem.s
;
; Operations on memory blocks (TMA)
;
;  1994-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's Sapphire library.
;
; Sapphire is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; Sapphire is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Sapphire.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

;----- Standard header ------------------------------------------------------

		GET	libs:swis
		GET	libs:header

;----- External dependencies ------------------------------------------------
;
; None.

;----- Main code ------------------------------------------------------------

		AREA	|Sapphire$$Code|,CODE,READONLY

; --- mem_set ---
;
; On entry:	R0 == pointer to a block of memory (word-aligned)
;		R1 == size of the block
;		R2 == word value to store in the block
;
; On exit:	--
;
; Use:		Initialises a block by filling every word within it with the
;		same value.  This is normally 0, although maybe MOVS PC,#0
;		might be useful too.

		EXPORT	mem_set
mem_set		ROUT

		STMFD	R13!,{R0-R8,R14}	;Stack registers away

		; --- Set up seed value in lots of registers ---

		MOV	R3,R2
		MOV	R4,R2
		MOV	R5,R2
		MOV	R6,R2
		MOV	R7,R2
		MOV	R8,R2
		MOV	R14,R2

		; --- Do the copy ---

00mem_set	SUBS	R1,R1,#32		;Is there enough for fastblat
		STMGEIA	R0!,{R2-R8,R14}		;Yes -- *blat*
		BGE	%00mem_set

		; --- Now to word blats ---

		ADD	R1,R1,#32		;How much left to do?
01mem_set	SUBS	R1,R1,#4		;Enough for a word?
		STRGE	R14,[R0],#4		;Yes -- store it
		BGE	%01mem_set		;And go round again

		LDMFD	R13!,{R0-R8,PC}^	;Return to caller

		LTORG

;----- That's all folks -----------------------------------------------------

		END
