Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-09

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

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi all,
I need to be able to handle both reading and writing files under i386 and PowerPC via my Mac OS X application.
I can create a Universal Binary, but none of my code is cross CPU ready yet.

1. What should I be aware of?

2. Should I use IFDEF ENDIAN to separate the i386 and PowerPC file system calls for reading and writing?

3. Is there an easy way to detect in my code, if the compiler is compiling for i386 of PowerPC?

Thanks,

Dominique.

Reply by email

Inoussa OUEDRAOGO
to Unknown author

Hi

The unit below, part of WST, implements a reader and a writer that always store and read their content in a big endian fashion. It mostly has no dependency and can be used alone.

https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/wst/trunk/binary_streamer.pas

Best regards.

Inoussa O. 2008/9/25, : > Hi all, > I need to be able to handle both reading and writing files under i386 and > PowerPC via my Mac OS X application. > I can create a Universal Binary, but none of my code is cross CPU ready > yet. > > 1. What should I be aware of? > > 2. Should I use IFDEF ENDIAN to separate the i386 and PowerPC file system > calls for reading and writing? > > 3. Is there an easy way to detect in my code, if the compiler is compiling > for i386 of PowerPC? > > Thanks, > > > Dominique. > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > -- Inoussa O.

Reply by email

Unknown author
to Inoussa OUEDRAOGO

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.

Thanks again,

Dominique.

"Inoussa OUEDRAOGO" wrote 7 lines
Hi The unit below, part of WST, implements a reader and a writer that always store and read their content in a big endian fashion. It mostly has no dependency and can be used alone.

https://lazarus-ccr.svn.sourceforge.net/svnroot/lazarus-ccr/wst/trunk/binary_streamer.pas

Show quoted text 42 lines
Best regards. -- Inoussa O. 2008/9/25, : > Hi all, > I need to be able to handle both reading and writing files under i386 and > PowerPC via my Mac OS X application. > I can create a Universal Binary, but none of my code is cross CPU ready > yet. > > 1. What should I be aware of? > > 2. Should I use IFDEF ENDIAN to separate the i386 and PowerPC file system > calls for reading and writing? > > 3. Is there an easy way to detect in my code, if the compiler is compiling > for i386 of PowerPC? > > Thanks, > > > Dominique. > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > -- Inoussa O. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Brad Campbell
to Unknown author
Show quoted text 6 lines
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.

Reply by email