Coding Struggles

Discussion in 'Wii - Hacking' started by nano351, Jan 21, 2011.

Jan 21, 2011

Coding Struggles by nano351 at 10:46 PM (607 Views / 0 Likes) 3 replies

  1. nano351
    OP

    Member nano351 GBAtemp Regular

    Joined:
    Jun 6, 2009
    Messages:
    259
    Country:
    United States
    Alright, so I've only recently started to mess around with programming for the wii and was working on a modification of SNEEK+DI to add cover display to the DI menu.

    I started working on some code to load BMP files into memory since I've dealt with that elsewhere and the file format for them is pretty simple. But the wii seems to hang on my call to malloca to create space in memory to store the image data converted to the right format to display later in my code. The big problem is I don't own any of the special hardware needed to debug on the wii so it's quite frustrating [​IMG]

    the changed code in ES module is here: http://www.mediafire.com/?n1gr093tvrdzn58 It's modified from r144

    and the troublesome code where the hang happens in image.c:
    CODEImageStruct* LoadBMP(u8* rawData, u32 size){
    ÂÂÂÂif (size < sizeof(bmpfile_magic) + sizeof(bmpfile_header) + sizeof(bmp_dib_v3_header_t))
    ÂÂÂÂÂÂÂÂreturn NULL;
    ÂÂÂÂbmpfile_header* bmpHeader = (bmpfile_header*) &rawData[sizeof(bmpfile_magic)];
    ÂÂÂÂbmp_dib_v3_header_t* dibHeader = (bmp_dib_v3_header_t*) &rawData[sizeof(bmpfile_magic) + sizeof(bmpfile_header)];
    ÂÂÂÂif (dibHeader->header_sz != sizeof(bmp_dib_v3_header_t))
    ÂÂÂÂÂÂÂÂreturn NULL; //wrong header type
    ÂÂÂÂif (dibHeader->nplanes != 1)
    ÂÂÂÂÂÂÂÂreturn NULL; //must only use 1 plane
    ÂÂÂÂif (dibHeader->compress_type != BI_RGB)
    ÂÂÂÂÂÂÂÂreturn NULL; //must be uncompressed
    ÂÂÂÂs32 width, height;
    ÂÂÂÂu8* imageData = bmpHeader->bmp_offset + rawData;
    ÂÂÂÂwidth = dibHeader->width;
    ÂÂÂÂif (width % 2)
    ÂÂÂÂÂÂÂÂwidth += 1;
    ÂÂÂÂu32 halfWidth = width / 2;
    ÂÂÂÂheight = dibHeader->height;
    ÂÂÂÂImageStruct* image = (ImageStruct*)malloc(sizeof(ImageStruct) + halfWidth * height * sizeof(u32)); //i think it's hanging on this allocation but I don't know why
    ÂÂÂÂimage->width = width;
    ÂÂÂÂimage->height = height;
    ÂÂÂÂswitch (dibHeader->bitspp){
    ÂÂÂÂÂÂÂÂcase 24:
    ÂÂÂÂÂÂÂÂ{
    ÂÂÂÂÂÂÂÂÂÂÂÂs32 x, y;
    ÂÂÂÂÂÂÂÂÂÂÂÂu32 iy, ix;
    ÂÂÂÂÂÂÂÂÂÂÂÂu32 bytesPerLine = width * 3;
    ÂÂÂÂÂÂÂÂÂÂÂÂbytesPerLine += bytesPerLine % 4;
    ÂÂÂÂÂÂÂÂÂÂÂÂiy = 0;
    ÂÂÂÂÂÂÂÂÂÂÂÂfor (y = height - 1; y >= 0; y--){
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂix = 0;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂfor (x = 0; x < width; x += 2){
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂu8* pixel1Data = &imageData[y * bytesPerLine + x * 3];
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂu8* pixel2Data;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂif (x + 1 != dibHeader->width)
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpixel2Data = &imageData[y * bytesPerLine + (x + 1) * 3];
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂelse
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂpixel2Data = pixel1Data;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂimage->imageData[iy * halfWidth + ix] = RGBtoYCbYCr(pixel1Data[2],pixel1Data[1],pixel1Data[0],pixel2Data[2],pixel2Data[1],pixel2Data[0]);
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂix++;
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ}
    ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂiy++;
    ÂÂÂÂÂÂÂÂÂÂÂÂ}
    ÂÂÂÂÂÂÂÂ} break;
    ÂÂÂÂÂÂÂÂdefault: //unsupported colordepth
    ÂÂÂÂÂÂÂÂÂÂÂÂfree(image);
    ÂÂÂÂÂÂÂÂÂÂÂÂimage = NULL;
    ÂÂÂÂÂÂÂÂÂÂÂÂbreak;
    ÂÂÂÂ}
    ÂÂÂÂreturn image;
    }

    Any help would be appreciated.
     
  2. giantpune

    Member giantpune GBAtemp Addict

    Joined:
    Apr 10, 2009
    Messages:
    2,860
    Country:
    United States
    look how sneek works. if malloca() fails, it panics and hangs. this is code running in the tiny space used for IOS. it is not designed to handle huge memory crap. it needs to use as little memory as possible.
     
  3. nano351
    OP

    Member nano351 GBAtemp Regular

    Joined:
    Jun 6, 2009
    Messages:
    259
    Country:
    United States
    Oh, I see. Any idea on about how much memory sneek has access to?

    edit:
    I looked at wiibrew and saw this, "The IOS Heap range is usually 0x933E0000 – 0x93400000". So, SNEEK only has 0x20000 bytes to work with? And I'd guess that it shares that with whatever IOS is loaded as well.
     
  4. lulwut

    Member lulwut GBAtemp Fan

    Joined:
    Mar 19, 2010
    Messages:
    331
    Country:
    Japan
    /me facepalms
    when sneek is running, ios isn't running >_>
    also 131072 bytes, or 128kb is the ios memory.

    also, altho this might be possible by doing a allocation in mem1 or low mem2 ; its potential unsafe as you might end up overwriting the loaded app (which is system menu im guessing?)
     

Share This Page