Jump to content

  •  

  • iBotModz CBox


    Photo

    C/C++ help


    • Please log in to reply
    4 replies to this topic

    #1 miinaturvat

    miinaturvat

      miiinaturvat

    • Donors+

    • 927 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Dragon Shores!

    Posted 27 March 2009 - 10:25 AM

    I'm doing a bit of programming for the PSP in C/C++, using the pspdev thing for compiling.

    I'm trying to make a function to print in color.

    Basically, I call my function, giving it a string I want to print, and a RGBA (red, green, blue, alpha) hex color code. Then my function should print the message in that color.

    I have some code to do this:

    void	printStuff( long colour, char *message )
    {
    	int r;
    	int g;
    	int b;
    	int a;
    	int c;
    
    	c = colour;
    
    	r = c / 0x01000000;
    	c -= (r * 0x01000000 );
    
    	g = c / 0x00010000;
    	c -= (g * 0x00010000 );
    
    	b = c / 0x00000100;
    	c -= (b * 0x0100 );
    
    	a = c;
    
    
    	pspDebugScreenSetTextColor((a * 0x1000000) + (b * 0x10000) + (g * 0x100) + (r));
    	pspDebugScreenPrintf(message);
    
    }


    In theory, if I use:

    printStuff(0xFF7F0FF, "Hello");

    ...it should print the text "Hello" in orange.

    It compiles fine, and when I do the sums on a calculator, it works fine.

    But when I run it on the PSP, it doesn't work at all...



    I think the problem lies when I'm doing "r = c / 0x01000000 ;", like it can't divide properly or something.

    Does anyone know why this doesn't work?

    Or, can anyone think of a better way of getting r, g, b and a from the color?

    Thanks.

    #2 iKhaosmaster

    iKhaosmaster

      Yawn

    • Members+

    • 1,346 posts
    • Joined: 29-April 08
    • Gender:Male

    Posted 27 March 2009 - 11:41 AM

    I have no idea what to do on this but gabe said something about patching your mainframes before....

    #3 TheEazyB

    TheEazyB

      Corporal Grade 1

    • Donors+

    • 333 posts
    • Joined: 09-June 08
    • Gender:Male

    Posted 26 November 2009 - 02:08 PM

    I have no idea what to do on this but gabe said something about patching your mainframes before....


    lol the statement is justified.

    #4 miinaturvat

    miinaturvat

      miiinaturvat

    • Donors+

    • 927 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Dragon Shores!

    Posted 26 November 2009 - 04:20 PM

    Severe bumpage going on here... :D

    And if anyone actually cares, the devision works strangely on the PSP. The way I did it was as follows:

    void	printHex( unsigned long color, int x1, int y1, char *str)
    {
    	char message[999];
    	unsigned r1;
    	unsigned g1;
    	unsigned b1;
    	unsigned a1;
    	unsigned char r;
    	unsigned char g;
    	unsigned char b;
    	unsigned char a;
    
    	if( strlen( str ) < 800 ) {
    		sprintf( message, "%s", str);
    	} else {
    		sprintf( message, "String too big (%d chars)", strlen(str) );
    	}
    
    	r1 = color & 0xFF000000;
    	g1 = color & 0x00FF0000;
    	b1 = color & 0x0000FF00;
    	a1 = color & 0x000000FF;
    
    	a = (char)(a1);
    	b = (char)(b1 >> <img src='http://www.ibotmodz.net/forum/public/style_emoticons/<#EMO_DIR#>/dirol.gif' class='bbc_emoticon' alt='8)' />;
    	g = (char)(g1 >> 16);
    	r = (char)(r1 >> 24);
    
    	pspDebugScreenSetXY(x1,y1);
    	pspDebugScreenSetTextColor((a * 0x1000000) + (b * 0x10000) + (g * 0x100) + (r));
    	pspDebugScreenPrintf(message);
    }
    
    


    #5 TheEazyB

    TheEazyB

      Corporal Grade 1

    • Donors+

    • 333 posts
    • Joined: 09-June 08
    • Gender:Male

    Posted 27 November 2009 - 12:40 AM

    Oh wow, I'm embarassed. I thought the date was this month :wallbash: