Assembly and C

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Postby Nyh » Tue Feb 27, 2007 10:31 pm

DrCoolZic wrote:Actually I would like to know if there is a directive that allow to align a varaible declaration.
I pass the address of a buffer declared as

Code: Select all

unsigned char* buffer[7000];

to the DMA chip and for performance reason this is fastest if the address is even.
Is there a way to force the buffer to be word align?


First:
unsigned char* buffer[7000];
defines an array of 7000 pointers to unsigned chars. I think you need a buffer of 7000 chars:
unsigned char buffer[7000];

There is a universal way to force alignment by using a union:

Code: Select all

union
{
  long l;
  void *p;
  char b[7000];
} aligned_buffer;

#define buffer aligned_buffer.b

buffer now starts at the alingment boundary of a long or void* which ever has the most severe alignment restrictions. Doesn't matter on the Atari ST because both of them align on an even boundary.

Hans Wessels

User avatar
DrCoolZic
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2188
Joined: Mon Oct 03, 2005 7:03 pm
Location: France
Contact:

Postby DrCoolZic » Wed Feb 28, 2007 9:04 am

Nyh wrote:First:
unsigned char* buffer[7000];
defines an array of 7000 pointers to unsigned chars. I think you need a buffer of 7000 chars:
unsigned char buffer[7000];
Oops this is a typo

There is a universal way to force alignment by using a union:

Code: Select all

union
{
  long l;
  void *p;
  char b[7000];
} aligned_buffer;

#define buffer aligned_buffer.b

buffer now starts at the alingment boundary of a long or void* which ever has the most severe alignment restrictions. Doesn't matter on the Atari ST because both of them align on an even boundary.

Thank Hans this is clean an easy.

Do you know what is the usage of .cfg file that can be saved and loaded? They are binary and I did not found about their usage in the online help?

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Postby Nyh » Wed Feb 28, 2007 10:05 am

DrCoolZic wrote:Do you know what is the usage of .cfg file that can be saved and loaded? They are binary and I did not found about their usage in the online help?

It is in the online help: Help: Menu: Options: Save''

Saves the current state of the complete development environment, including the open windows and their positions. Only the help windows are closed.

Normally when you leave Pure C the current configuration is stored in PC.CFG. If you are working on multiple projects you can switch between them by saving the .CFG file under the project name and loading the .CFG file of the other project.

Hans Wessels

User avatar
Desty
Atari God
Atari God
Posts: 1957
Joined: Thu Apr 01, 2004 2:36 pm
Location: 53 21N 6 18W
Contact:

Postby Desty » Tue Mar 06, 2007 7:02 pm

Nyh wrote:There is a universal way to force alignment by using a union:

Code: Select all

union
{
  long l;
  void *p;
  char b[7000];
} aligned_buffer;

#define buffer aligned_buffer.b

buffer now starts at the alingment boundary of a long or void* which ever has the most severe alignment restrictions. Doesn't matter on the Atari ST because both of them align on an even boundary.

Wow, nice technique. This is the kind of thing that needs a comment nearby if anyone else is ever going to look at the code ;)
tá'n poc ar buile!

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Postby Nyh » Tue Mar 06, 2007 7:32 pm

Desty wrote:
Nyh wrote:There is a universal way to force alignment by using a union:

Code: Select all

union
{
  long l;
  void *p;
  char b[7000];
} aligned_buffer;

#define buffer aligned_buffer.b

buffer now starts at the alingment boundary of a long or void* which ever has the most severe alignment restrictions. Doesn't matter on the Atari ST because both of them align on an even boundary.

Wow, nice technique. This is the kind of thing that needs a comment nearby if anyone else is ever going to look at the code ;)

Does it? It is at K&R2 page 186.

Hans Wessels


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 2 guests