gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Graphics > What is ALIGN4? (MapEd 095)

#10662 - goro - Thu Sep 11, 2003 6:53 pm

Why does this map editor put ALIGN4 in all the output files?

Can it safely be removed?

Code:
//  File generated by: Map Ed v0.95 Lite

E.g.
// width: 32     height: 32
const u16 maplay1_map[1024]ALIGN4 = {
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0002,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000

#10663 - Nessie - Thu Sep 11, 2003 7:06 pm

You'll typically get faster data access if you know that the data array is aligned to a 2, 4, or 8 byte boundary in memory, the exact alignment depending largely on the processor in question.

Some compilers might automatically make this optimization...some compilers have it as a compile time optimization flag you can set...etc.

Maybe someone else can explain it better than I can, but yeah, it isn't necessary if you could care less about the memory alignment.

#10675 - DekuTree64 - Fri Sep 12, 2003 2:43 am

If you want to, for example DMA in your data 32 bits at a time, but have it defined as a u16 array, you should specifically align it. I had some scrambled graphics from that once. In GCC, use
#define ALIGN4 __attribute__((aligned (4)))
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#10680 - goro - Fri Sep 12, 2003 10:18 am

Lovely. Thanks for that.

So if I add the define I won't get these syntax errors.
Code:
C:/PROJECTS/GBA/5/palOut.h:4: syntax error before `=' token
In file included from C:/PROJECTS/GBA/5/5.cpp:10:


btw -I had to rename the .cpp files to .h because MS Visual Studio refuses to link external files for me :(

Nessie : Could you set MapEd to automatically add the define to the header file.

#10684 - Nessie - Fri Sep 12, 2003 3:51 pm

One thing I've been working on is a customization feature for exporting.

It will let you set the export filenames, default #includes, and probably a few other things....I'll probably set up the array declaration line so that it can be customised however you'd like (palette Array example shown)...you just specify the format similar to how you would with a printf format.

Code:
"const  %dataType%  bg%mapName%Palette[%arraySize%]ALIGN4 = {"
   or
"const  u16  bgPalette[%arraySize%] = \n{"
   or
(insert your own format here)


Would something like this be satisfactory?

#10721 - goro - Sat Sep 13, 2003 10:54 am

Absolutely.

_Also exporting tiles.bmp would be nice too but I feel bad asking for these features because you have already provided an excellent tool to the community.

Thanks for a great tool, Nessie.

#10735 - Nessie - Sat Sep 13, 2003 4:35 pm

Exporting a tiles.bmp would be easy, though there will be something of an issue considering that the tiles will be using 16 colour mode.

Do I let the user pick a single 16 colour palette to draw the .bmp in? Do I let the user pick a 256 colour palette (16 banks of 16 colours) and then export 16 different .bmp's...one for each possible colour combo?

So, because of this single issue, it's not something I'm going to tackle right now (or maybe ever) unless someone wants to pay me to add that feature. :)

Cheers

#10739 - tepples - Sat Sep 13, 2003 6:48 pm

Nessie wrote:
Exporting a tiles.bmp would be easy, though there will be something of an issue considering that the tiles will be using 16 colour mode.

Do I let the user pick a single 16 colour palette to draw the .bmp in?

You could probably let the user choose 16-color output or 256-color output. Some tile converters are happier with one or the other. Either way, if the user asks for 16-color tile data, you could have the program write a 16x16 pixel 256-color "palette.bmp".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#10753 - Nessie - Sun Sep 14, 2003 5:38 pm

Well, I have the export customization done. It's maybe a lot more complex than I had hoped it would be, but it's also pretty dang flexible.

The thing I was hoping though, is if some people could offer to help test it out a bit? (pretty please, heh)

I don't want to put up an official build until it's been reasonably tested. That's not to say that I haven't tested it...actually the opposite is true. It's just that the code is very complex due to the flexibility it allows...that and this code integrates into the export optimizer code which was already extremely complex to being with...

So if you can offer your help, either PM me, email me, post here, blah, blah. It would be most appreciated.

Cheers,
Nessie