-- RopeEditingBLTImpl.Mesa
-- written by Bill Paxton,  March 1981
-- last edit by Paxton, 10-Feb-82  9:13:35


DIRECTORY
	Environment,
	ByteBlt,
	Rope,
	RopeEditingBLT;

RopeEditingBLTImpl: PROGRAM
   IMPORTS ByteBlt
   EXPORTS RopeEditingBLT =
BEGIN OPEN RopeEditingBLT;

ArrayToArrayBlt: PUBLIC PROC [
	from: REF READONLY CharsArray, fromLoc: NAT,
	to: REF CharsArray, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc], from:[from,fromLoc], nBytes:nLeft]};

ArrayToTextBlt: PUBLIC PROC [
	from: REF READONLY CharsArray, fromLoc: NAT,
	to: Text, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc+TextCharOffset],
		from:[from,fromLoc], nBytes:nLeft]};

ArrayToStringBlt: PUBLIC PROC [
	from: REF READONLY CharsArray, fromLoc: NAT,
	to: String, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc+StringCharOffset],
		from:[from,fromLoc], nBytes:nLeft]};

TextToArrayBlt: PUBLIC PROC [
	from: Text, fromLoc: NAT,
	to: REF CharsArray, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc],
		from:[from,fromLoc+TextCharOffset], nBytes:nLeft]};

StringToArrayBlt: PUBLIC PROC [
	from: REF READONLY TEXT, fromLoc: NAT,
	to: REF CharsArray, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc],
		from:[from,fromLoc+StringCharOffset], nBytes:nLeft]};

TextToTextBlt: PUBLIC PROC [
	from: Text, fromLoc: NAT,
	to: Text, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc+TextCharOffset],
		from:[from,fromLoc+TextCharOffset], nBytes:nLeft]};

TextToStringBlt: PUBLIC PROC [
	from: Text, fromLoc: NAT,
	to: String, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc+StringCharOffset],
		from:[from,fromLoc+TextCharOffset], nBytes:nLeft]};

StringToStringBlt: PUBLIC PROC [
	from: REF READONLY TEXT, fromLoc: NAT,
	to: String, toLoc: NAT,
	nChars: NAT] = {
	nLeft: NAT;
	IF nChars=0 THEN RETURN;
	nLeft ← nChars-1;
	to[toLoc+nLeft] ← from[fromLoc+nLeft]; -- bounds check
	MyByteBlt[to:[to,toLoc+StringCharOffset],
		from:[from,fromLoc+StringCharOffset], nBytes:nLeft]};

ByteBlock: TYPE = RECORD [block: REF ANY, startIndex: NAT];
ROByteBlock: TYPE = RECORD [block: REF READONLY ANY, startIndex: NAT];
StringCharOffset: NAT = SIZE[TEXT[0]]*2;
TextCharOffset: NAT = SIZE[Rope.TextRep[0]]*2;

MyByteBlt: PROC [to: ByteBlock, from: ROByteBlock, nBytes: NAT] = INLINE {
	eTo, eFrom: Environment.Block;
	IF nBytes=0 THEN RETURN;
	eTo.blockPointer ← LOOPHOLE[to.block];
	eFrom.blockPointer ← LOOPHOLE[from.block];
	eTo.startIndex ← to.startIndex;
	eFrom.startIndex ← from.startIndex;
	eTo.stopIndexPlusOne ← to.startIndex+nBytes;
	eFrom.stopIndexPlusOne ← from.startIndex+nBytes;
	[] ← ByteBlt.ByteBlt[eTo,eFrom]};

-- ***** Initialization

Start: PUBLIC PROC = {
	};

END.