GP32 Converting (u8*) To (u16*)


Blah

Wanna Be Programmer
Joined
Dec 18, 2003
Messages
3,253
Age
34
Location
Oregon, USA
Website
Visit site
gp_uncompressZDA returns 8bit data, but gp_drawSprite needs 16bit data. What I'm doing is trying to draw a sprite from a .bin file inside a ZDA which has been converted to an .h included in the file :ph34r: It all works except for the gp_drawSprite which gives a "incompatible pointer type" error. I can read a text file out of it though because gp_drawString takes chars. So thats not the problem.

Here's my code. Actually its a hacked up zdaread.c
Code:
#include "gp32.h"
#include "zda.h"
#include "data.h"

unsigned short gp_colorRGB24to16( unsigned char R, unsigned char G, unsigned char B )
{
return ((R >> 3) << 11) | ((G >> 3) << 6) | ((B >> 3) << 1);
}
int main() {

  //DIR dir_struct;
  //int dir_entrys;
  int x,err;
  unsigned short *framebuffer1;
  framebuffer1 = (unsigned short*) FRAMEBUFFER1;
  gp_setCpuspeed(133);
  gp_initFramebuffer(framebuffer1,16,85);
  gp_clearFramebuffer16(framebuffer1,0xFFFF);


   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   // USING NEW ZDA FORMAT WITH HEADER
   // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   //
   // I compressed 3 files to the datah.zda file
   // Makefile, README.TXT, zda_compressor.c
   // You no longer need to know size or offset position

   { char header_12bytes[12];  // The ZDA header is always 12 Bytes big
     char *full_header;        // The full headersize depend on content
     char *compressed;
     char *uncompressed;
     int  real_headersize;
     int  usize,csize,offset,err;

     memcpy(header_12bytes,data,12);
     real_headersize=gp_zda_headersize(header_12bytes);      // calculate the real headersize
     full_header = (char*) malloc(real_headersize);          // malloc space for full header
     memcpy(full_header,data,real_headersize);
     
     csize  = gp_zda_csize (full_header, "1.bin");     // get compressed   size of file README.TXT
     usize  = gp_zda_usize (full_header, "1.bin");     // get uncompressed size of file README.TXT
     offset = gp_zda_offset(full_header, "1.bin");     // get the offset for file README.TXT, counting from file beginning

     compressed   = (char*) malloc(csize);  // temp buffer for compressed file
     uncompressed = (char*) malloc(usize);  // buffer for uncompressed data
     memcpy(compressed,data+offset,csize);
     gp_drawString(10,100,26,"Uncompressing file ...   ",0xF800,framebuffer1);
     err = gp_uncompressZDA((u8*)uncompressed, &usize, (u8*)compressed, csize ); // uncompress
     unsigned short color;
     color = gp_colorRGB24to16(97,68,43);
     gp_drawSpriteHT (uncompressed,0,0,framebuffer1,color);

     // free all memory
     free (full_header);
     free (compressed);
     free (uncompressed);
   }



while (1) { if ( gp_getButton()&BUTTON_A) gp_Reset();  }
}
 
I think all you need to do is change the pointer type when calling the sprite routine. Like this

gp_drawSpriteHT ((unsigned short*)uncompressed,0,0,framebuffer1,color);

Or something like that, I can never remember where there "*" thing goes :)
 
Hmm...I found out the problem, and thats not it. By defualt, Mirkos sdk starts in BLU+ mode. If you hold down L, it starts in regular mode. Now it works. But how do you disable this? As in make it automatically start in regular mode.

edit:
...gp_drawSpriteHT ((unsigned short*)uncompressed,0,0,framebuffer1,color);
...

Yeah, I just figured that bit out, but still wondering about the BLU+ thing.
 
Blah posted on Apr 29 2005 at 06:49 AM said:
Hmm...I found out the problem, and thats not it. By defualt, Mirkos sdk starts in BLU+ mode. If you hold down L, it starts in regular mode. Now it works. But how do you disable this? As in make it automatically start in regular mode.
Man... I suppose, that for the MirkoSDK next version Mr. Mirko will change this thing so the programs will initiate in BLU mode due to the great number of sold units of this one model in comparison with blu+ that form a minority.
 
Last edited by a moderator:
Actually, I figured out that Mirko's code trys to detect what type you have. It detects mine as a BLU+ unless override it by holding L (if it detects a BLU+ as a non BLU+, you need to hold R). If I changed my firmware to anything else than the default, the autodetection would work. So I'm gonna recompile the BLU+ clockspeed tester to ONLY work on BLU+ and that'll fix the problems I noticed with that.
 
Back
Top