[Lazarus] Mac OS X : Reading/Writing files under both Intel and PowerPC

Brad Campbell brad at wasp.net.au
Sat Sep 27 12:24:00 CEST 2008


dominique at savagesoftware.com.au wrote:
> Hey that's great, I think this is exactly the sort of thing I'm looking
> for.
> 
> Only thing is that in my case since all the existing game files are little
> endian, so it looks like I'll need to reverse the code.
> 

Here's how I'm doing it in one application. It's kinda messy I guess but works for me.

function  TLoader.Load_Binary(Name : String) : Boolean;
Var
	InFile : File of Cardinal;
	Ptr : Cardinal;
Begin
Assign(InFile, Name);
try
	Reset(InFile,4);
	BlockRead(InFile,PRam[0],8192,Ptr);
{$IFDEF ENDIAN_BIG}
		Inc(Ptr);
		While Ptr > 0 do
			Begin
			Dec(Ptr);
			PRam[Ptr] := SwapEndian(PRam[Ptr]);
			End;
{$ENDIF}
	Result := True;
except
	Result := False;
	Exit;
End;
End;

-- 
Dolphins are so intelligent that within a few weeks they can
train Americans to stand at the edge of the pool and throw them
fish.



More information about the Lazarus mailing list