[RESOLVED] Endian Switching and Structs on Wii?
Posted: Thu Jun 24, 2010 8:18 pm
Hello, yet again.
I have a few questions and problems with this.
I'm porting my engine (as it is so far) to my Wii, and I've encountered some errors.
If I use structs like I normally do, it throws some errors at me.
For example:
And here is where I'm calling it.
Line 137:
Line 146:
I can't use sizeof() like I normally would in replace of 8 because it doesn't work...
So, instead, I called my map header like this:
Now, this is okay because it compliles and running it on my Wii, I get this output.
So if anyone knows how I would go about that, please let me know.
Next what I would do, is read in my map data, however, this has some problems.
Here is my output:
Line 154:
Line 155:
Basically, that's because there is no struct I can pull MapData from.
So sizeof() wont work... and I can't do line 155 either because of it.
So this is an issue I really need to get over, otherwise I wont be able to read in my map data.
And after this, how would I switch the endian of what I read in from the map data.
This is where I read it in:
Here is the map data struct again.
And this is how I would normally call it in my code:
I switch my other endians with these functions:
But how would I do it for my map data?
Thanks guys,
LeonBlade
I have a few questions and problems with this.
I'm porting my engine (as it is so far) to my Wii, and I've encountered some errors.
If I use structs like I normally do, it throws some errors at me.
For example:
Here are my structs:Output Log wrote: file.c: In function 'main':
file.c:137: error: 'MapHeader' undeclared (first use in this function)
file.c:137: error: (Each undeclared identifier is reported only once
file.c:137: error: for each function it appears in.)
file.c:137: error: expected ';' before 'mapHeader'
file.c:146: error: 'mapHeader' undeclared (first use in this function)
Code: Select all
struct MapHeader
{
unsigned int fileLength;
unsigned short tilesX;
unsigned short tilesY;
};
struct MapData
{
unsigned char tileData[4];
};
Line 137:
Code: Select all
MapHeader mapHeader;
Code: Select all
memset(&mapHeader, 0, 8);
So, instead, I called my map header like this:
Code: Select all
struct MapHeader
{
unsigned int fileLength;
unsigned short tilesX;
unsigned short tilesY;
} mapHeader;
Which works just fine, but I'd like to just have my struct like I normally do, and create an instance of it.Wii Output wrote: BBE Map File Reader
File length: 636 bytes
Tiles X: 12
Tiles Y: 13
So if anyone knows how I would go about that, please let me know.
Next what I would do, is read in my map data, however, this has some problems.
Here is my output:
This is my code for those lines.Output log wrote: file.c: In function 'main':
file.c:154: error: 'MapData' undeclared (first use in this function)
file.c:154: error: (Each undeclared identifier is reported only once
file.c:154: error: for each function it appears in.)
file.c:155: error: expected expression before ')' token
Line 154:
Code: Select all
unsigned int tileBufSize = tileCount * sizeof(MapData);
Code: Select all
mapData = (MapData*)malloc(tileBufSize);
So sizeof() wont work... and I can't do line 155 either because of it.
So this is an issue I really need to get over, otherwise I wont be able to read in my map data.
And after this, how would I switch the endian of what I read in from the map data.
This is where I read it in:
Code: Select all
unsigned int tileCount = mapHeader.tilesX * mapHeader.tilesY;
unsigned int tileBufSize = tileCount * sizeof(MapData);
mapData = (MapData*)malloc(tileBufSize);
fread(mapData, tileBufSize, 1, file);
Code: Select all
struct MapData
{
unsigned char tileData[4];
}
Code: Select all
MapData * mapData;
Code: Select all
unsigned int swapEndianUI(unsigned int ui)
{
ui = (ui >> 24) |
((ui << 8) & 0x00FF0000) |
((ui >> 8) & 0x0000FF00) |
(ui << 24);
return ui;
}
unsigned short swapEndianUS(unsigned short us)
{
us = (us >> 8) |
(us << 8);
return us;
}
Thanks guys,
LeonBlade